TI HDC1000 Temperature and Humidity Sensor
Diff: HDC1000.cpp
- Revision:
- 1:f2c04c5b28ab
- Parent:
- 0:1db0d0071723
- Child:
- 2:f574cd898cba
--- a/HDC1000.cpp Mon Apr 17 02:49:07 2017 +0000
+++ b/HDC1000.cpp Mon Apr 17 07:37:19 2017 +0000
@@ -43,6 +43,28 @@
setConfig(conf) ;
}
+float HDC1000::u2f_temp(uint16_t utemp)
+{
+ float ftemp ;
+
+ utemp = (utemp >> 2) & 0x3FFF ;
+ // note: the data sheet suggests to use 0x10000 for denominator
+ // but to allow 100% I chose 0xFFFF instead, I may be wrong
+ ftemp = ((float)(utemp)/ (float)0x3FFF)*165.0 - 40.0 ;
+ return( ftemp ) ;
+}
+
+float HDC1000::u2f_hume(uint16_t uhume)
+{
+ float fhume ;
+ uhume = (uhume>>2) & 0x3FFF ;
+
+ // note: the data sheet suggests to use 0x10000 for denominator
+ // but to allow 100% I chose 0xFFFF instead, I may be wrong
+ fhume = ((float)(uhume) / (float)0x3FFF) * 100.0 ;
+ return( fhume ) ;
+}
+
float HDC1000::readTemperature(void)
{
uint16_t utemp, uhum ;
@@ -62,12 +84,16 @@
printf("Error: unexpected mode %d\n",mode) ;
break ;
}
+
+ printf("utemp = 0x%04X ", utemp) ;
+ ftemp = u2f_temp(utemp) ;
+ /*
+ ltemp = (utemp >> 2) & 0x3FFF ;
+
// note: the data sheet suggests to use 0x10000 for denominator
// but to allow 100% I chose 0xFFFF instead, I may be wrong
- printf("utemp = 0x%04X ", utemp) ;
- ltemp = (utemp >> 2) & 0x3FFF ;
-
ftemp = ((float)(ltemp)/ (float)0x3FFF)*165.0 - 40.0 ;
+ */
return( ftemp ) ;
}
@@ -76,7 +102,7 @@
uint16_t utemp, uhume ;
int mode ;
int32_t lhume ;
- float fhum ;
+ float fhume ;
mode = getMode() ;
switch(mode) {
@@ -90,13 +116,17 @@
printf("Error: unexpected mode %d\n",mode) ;
break ;
}
+
+ printf("uhume = 0x%04X\n", uhume) ;
+ fhume = u2f_hume(uhume) ;
+ /*
+ lhume = (uhume>>2) & 0x3FFF ;
+
// note: the data sheet suggests to use 0x10000 for denominator
// but to allow 100% I chose 0xFFFF instead, I may be wrong
- printf("uhume = 0x%04X\n", uhume) ;
- lhume = (uhume>>2) & 0x3FFF ;
-
fhum = ((float)(lhume) / (float)0x3FFF) * 100.0 ;
- return( fhum ) ;
+ */
+ return( fhume ) ;
}
void HDC1000::readData(float *ftemp, float *fhume)
@@ -104,10 +134,14 @@
uint16_t utemp, uhume ;
getData(&utemp, &uhume) ;
printf("utemp: 0x%04X, uhume: 0x%04X\n", utemp, uhume) ;
+ *ftemp = u2f_temp(utemp) ;
+ *fhume = u2f_hume(uhume) ;
+#if 0
utemp = (utemp >> 2) & 0x3FFF ;
uhume = (uhume >> 2) & 0x3FFF ;
*ftemp = ((float)(utemp)/ (float)0x3FFF)*165.0 - 40.0 ;
*fhume = ((float)(uhume) / (float)0x3FFF) * 100.0 ;
+#endif
}
/* for mode 0 */
uint16_t HDC1000::getTemperature(void)