Browse Source

htu21d: update to correct code now under MIT license

Signed-off-by: William Penner <william.penner@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
William Penner 10 years ago
parent
commit
ce928907eb
3 changed files with 203 additions and 190 deletions
  1. 20
    13
      examples/htu21d.cxx
  2. 108
    116
      src/htu21d/htu21d.cpp
  3. 75
    61
      src/htu21d/htu21d.h

+ 20
- 13
examples/htu21d.cxx View File

@@ -24,18 +24,19 @@
24 24
 
25 25
 #include <unistd.h>
26 26
 #include <iostream>
27
-#include "htu21d.h"
28 27
 #include <signal.h>
29 28
 
30
-int doWork = 0;
29
+#include "htu21d.h"
30
+
31
+volatile int doWork = 0;
32
+
31 33
 upm::HTU21D *sensor = NULL;
32 34
 
33 35
 void
34 36
 sig_handler(int signo)
35 37
 {
36
-    printf("got signal\n");
37 38
     if (signo == SIGINT) {
38
-        printf("exiting application\n");
39
+        printf("\nCtrl-C received.\n");
39 40
         doWork = 1;
40 41
     }
41 42
 }
@@ -43,24 +44,30 @@ sig_handler(int signo)
43 44
 int
44 45
 main(int argc, char **argv)
45 46
 {
47
+    // Register signal handler
48
+    signal(SIGINT, sig_handler);
49
+
46 50
     //! [Interesting]
47
-    int32_t humidity = 0;
48
-    int32_t temperature = 0;
49
-    int32_t compRH = 0;
51
+    float humidity    = 0.0;
52
+    float temperature = 0.0;
53
+    float compRH      = 0.0;
50 54
 
51 55
     sensor = new upm::HTU21D(0, HTU21D_I2C_ADDRESS);
52 56
 
57
+    sensor->testSensor();
58
+
53 59
     while (!doWork) {
54
-        humidity = sensor->getRHumidity(&temperature);
55
-        compRH = sensor->getCompRH();
60
+        compRH      = sensor->getCompRH(true);
61
+        humidity    = sensor->getHumidity(false);
62
+        temperature = sensor->getTemperature(false);
56 63
 
57 64
         std::cout << "humidity value = " <<
58
-                    (float)humidity / 1000.0 <<
65
+                    humidity <<
59 66
                     ", temperature value = " <<
60
-                    (float)temperature / 1000.0 <<
67
+                    temperature <<
61 68
                     ", compensated RH value = " <<
62
-                    (float)compRH / 1000.0 << std::endl;
63
-        usleep (100000);
69
+                    compRH << std::endl;
70
+        usleep (500000);
64 71
     }
65 72
     //! [Interesting]
66 73
 

+ 108
- 116
src/htu21d/htu21d.cpp View File

@@ -2,23 +2,23 @@
2 2
  * Author: William Penner <william.penner@intel.com>
3 3
  * Copyright (c) 2014 Intel Corporation.
4 4
  *
5
- * This driver supports the HTU21D digital humidity and temperature
6
- * sensor. The datasheet is available from:
7
- * http://www.meas-spec.com/downloads/HTU21D.pdf
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
8 11
  *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
13 14
  *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22 22
  */
23 23
 
24 24
 #include <iostream>
@@ -44,32 +44,38 @@ HTU21D::HTU21D(int bus, int devAddr) {
44 44
     if (ret != MRAA_SUCCESS) {
45 45
         fprintf(stderr, "Error accessing i2c bus\n");
46 46
     }
47
+    resetSensor();
47 48
 }
48 49
 
49 50
 HTU21D::~HTU21D() {
50 51
     mraa_i2c_stop(m_i2ControlCtx);
51 52
 }
52 53
 
54
+int
55
+HTU21D::resetSensor(void)
56
+{
57
+    uint8_t data;
58
+    mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
59
+    mraa_i2c_write (m_i2ControlCtx, &data, 1);
60
+    usleep(20000);
61
+}
62
+
63
+/*
64
+ * Convert register value to degC * 1000
65
+ */
53 66
 int32_t
54
-HTU21D::htu21_temp_ticks_to_millicelsius(int ticks)
67
+HTU21D::convertTemp(int32_t regval)
55 68
 {
56
-    ticks &= ~0x0003; /* clear status bits */
57
-    /*
58
-     * Formula T = -46.85 + 175.72 * ST / 2^16 from datasheet p14,
59
-     * optimized for integer fixed point (3 digits) arithmetic
60
-     */
61
-    return ((21965 * (int32_t)ticks) >> 13) - 46850;
69
+    return ((21965 * (regval & 0xFFFC)) >> 13) - 46850;
62 70
 }
63 71
 
72
+/*
73
+ * Convert register value to %RH * 1000
74
+ */
64 75
 int32_t
65
-HTU21D::htu21_rh_ticks_to_per_cent_mille(int ticks)
76
+HTU21D::convertRH(int regval)
66 77
 {
67
-    ticks &= ~0x0003; /* clear status bits */
68
-    /*
69
-     * Formula RH = -6 + 125 * SRH / 2^16 from datasheet p14,
70
-     * optimized for integer fixed point (3 digits) arithmetic
71
-     */
72
-    return ((15625 * (int32_t)ticks) >> 13) - 6000;
78
+    return ((15625 * (regval & 0xFFFC)) >> 13) - 6000;
73 79
 }
74 80
 
75 81
 int
@@ -77,40 +83,31 @@ HTU21D::sampleData(void)
77 83
 {
78 84
     uint32_t itemp;
79 85
 
80
-    itemp = i2cReadReg_16(HTU21D_T_MEASUREMENT_HM);
81
-    m_temperature = htu21_temp_ticks_to_millicelsius(itemp);
86
+    itemp = i2cReadReg_16(HTU21D_READ_TEMP_HOLD);
87
+    m_temperature = convertTemp(itemp);
82 88
 
83
-    itemp = i2cReadReg_16(HTU21D_RH_MEASUREMENT_HM);
84
-    m_humidity = htu21_rh_ticks_to_per_cent_mille(itemp);
89
+    itemp = i2cReadReg_16(HTU21D_READ_HUMIDITY_HOLD);
90
+    m_humidity = convertRH(itemp);
85 91
 
86 92
     return 0;
87 93
 }
88 94
 
89
-int32_t
90
-HTU21D::getTemperature(void)
91
-{
92
-    return m_temperature;
93
-}
94
-
95
-int32_t
96
-HTU21D::getHumidity(void)
95
+float
96
+HTU21D::getTemperature(int bSampleData)
97 97
 {
98
-    return m_humidity;
98
+    if (bSampleData) {
99
+        sampleData();
100
+    }
101
+    return (float)m_temperature / 1000;
99 102
 }
100 103
 
101
-/*
102
- * This is the primary function to read the data.  It will initiate
103
- * a measurement cycle and will then return both the humidity and
104
- * temperature values.  piTemperature can be NULL.
105
- */
106
-
107
-int32_t
108
-HTU21D::getRHumidity(int32_t* piTemperature)
104
+float
105
+HTU21D::getHumidity(int bSampleData)
109 106
 {
110
-    sampleData();
111
-    if (NULL != piTemperature)
112
-        *piTemperature = m_temperature;
113
-    return m_humidity;
107
+    if (bSampleData) {
108
+        sampleData();
109
+    }
110
+    return (float)m_humidity / 1000;
114 111
 }
115 112
 
116 113
 /*
@@ -119,12 +116,30 @@ HTU21D::getRHumidity(int32_t* piTemperature)
119 116
  * RHcomp = RHactualT + (25 - Tactual) * CoeffTemp
120 117
  * RHcomp is in units of %RH * 1000
121 118
  */
122
-int32_t
123
-HTU21D::getCompRH(void)
119
+float
120
+HTU21D::getCompRH(int bSampleData)
124 121
 {
125
-    return m_humidity + (25000 - m_temperature) * 3 / 20;
122
+	if (bSampleData) {
123
+		sampleData();
124
+	}
125
+	return (float)(m_humidity + (25000 - m_temperature) * 3 / 20) / 1000;
126 126
 }
127 127
 
128
+int
129
+HTU21D::setHeater(int bEnable)
130
+{
131
+	uint8_t userreg;
132
+
133
+	userreg = i2cReadReg_8(HTU21D_READ_USER_REG);
134
+	if (bEnable)
135
+		userreg |= HTU21D_HEATER_ENABLE;
136
+	else
137
+		userreg &= ~HTU21D_HEATER_ENABLE;
138
+	if (i2cWriteReg(HTU21D_WRITE_USER_REG, userreg) < 0)
139
+		return -1;
140
+
141
+	return 0;
142
+}
128 143
 
129 144
 /*
130 145
  * Test function: when reading the HTU21D many times rapidly should
@@ -135,43 +150,50 @@ HTU21D::getCompRH(void)
135 150
 int
136 151
 HTU21D::testSensor(void)
137 152
 {
153
+    int i;
138 154
     int iError = 0;
139
-    int i, j;
140
-    int32_t iTemp, iHum;
141
-    int32_t iTempMax, iTempMin;
142
-    int32_t iHumMax, iHumMin;
143
-    int32_t iHumFirst, iTempFirst;
144
-
145
-    fprintf(stdout, "Executing Sensor Test.\n  Reading registers 100 times to look for operation\n" );
146
-
147
-    iHum = getRHumidity(&iTemp);
148
-    iTempFirst = iTempMax = iTempMin = iTemp;
149
-    iHumFirst  = iHumMax  = iHumMin  = iHum;
150
-
151
-    for (i=0; i < 100; i++) {
152
-        iHum = getRHumidity(&iTemp);
153
-        if (iHum  < iHumMin)  iHumMin  = iHum;
154
-        if (iHum  > iHumMax)  iHumMax  = iHum;
155
-        if (iTemp < iTempMin) iTempMin = iTemp;
156
-        if (iTemp > iTempMax) iTempMax = iTemp;
157
-//        fprintf(stdout, "Temp: %d  Humidity: %d\n", iTemp, iHum);
155
+    float fTemp, fHum;
156
+    float fTempMax, fTempMin;
157
+    float fHumMax, fHumMin;
158
+    float fHumFirst, fTempFirst;
159
+
160
+    fprintf(stdout, "Executing Sensor Test\n" );
161
+
162
+    fHum  = getHumidity(true);
163
+    fTemp = getTemperature(false);
164
+    fTempFirst = fTempMax = fTempMin = fTemp;
165
+    fHumFirst  = fHumMax  = fHumMin  = fHum;
166
+
167
+    // Turn on the heater to make a sensor change
168
+    setHeater(true);
169
+
170
+    // Then sample the sensor a few times
171
+    for (i=0; i < 10; i++) {
172
+        fHum  = getHumidity(true);
173
+        fTemp = getTemperature(false);
174
+        if (fHum  < fHumMin)  fHumMin  = fHum;
175
+        if (fHum  > fHumMax)  fHumMax  = fHum;
176
+        if (fTemp < fTempMin) fTempMin = fTemp;
177
+        if (fTemp > fTempMax) fTempMax = fTemp;
178
+        usleep(50000);
158 179
     }
159 180
 
160
-    if ((iTemp - iTempFirst) <= 0) {
161
-        fprintf(stdout, "! Temperature should have increased, but didn't\n" );
181
+    // Turn off the heater
182
+    setHeater(false);
183
+
184
+    // Now check the results
185
+    if ((fTemp - fTempFirst) <= 0) {
186
+        fprintf(stdout, "  Temperature should have increased, but didn't\n" );
162 187
         iError++;
163 188
     }
164
-
165
-    if (iHumMin == iHumMax) {
166
-        fprintf(stdout, "! Humidity was unchanged - not working?\n" );
189
+    if (fHumMin == fHumMax) {
190
+        fprintf(stdout, "  Humidity reading was unchanged - warning\n" );
167 191
         iError++;
168 192
     }
169
-
170
-    if (iTempMin == iTempMax) {
171
-        fprintf(stdout, "! Temperature was unchanged - not working?\n" );
193
+    if (fTempMin == fTempMax) {
194
+        fprintf(stdout, "  Temperature reading was unchanged - warning\n" );
172 195
         iError++;
173 196
     }
174
-
175 197
     if (iError == 0) {
176 198
         fprintf(stdout, "  Device appears functional\n" );
177 199
     }
@@ -185,42 +207,17 @@ HTU21D::testSensor(void)
185 207
  * Functions to read and write data to the i2c device
186 208
  */
187 209
 
188
-mraa_result_t
189
-HTU21D::i2cReadRegValue(int reg, uint32_t* puint32, int ibytes) {
190
-    uint32_t data = 0;
191
-
192
-    if (ibytes > 4)
193
-        ibytes = 4;
194
-
195
-    mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
196
-    mraa_i2c_write_byte(m_i2ControlCtx, reg);
197
-
198
-    mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
199
-    mraa_i2c_read(m_i2ControlCtx, (uint8_t *)&data, ibytes);
200
-
201
-    fprintf(stdout, "reg data = %08x\n", data);
202
-    *puint32 = be32toh(data) >> ((4-ibytes) * 8);
203
-    fprintf(stdout, "reg return = %08x\n", *puint32);
204
-
205
-    return MRAA_SUCCESS;
206
-}
207
-
208 210
 mraa_result_t
209 211
 HTU21D::i2cWriteReg (uint8_t reg, uint8_t value) {
210 212
     mraa_result_t error = MRAA_SUCCESS;
211 213
 
212 214
     uint8_t data[2] = { reg, value };
213
-    error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
215
+    mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
214 216
     error = mraa_i2c_write (m_i2ControlCtx, data, 2);
215 217
 
216 218
     return error;
217 219
 }
218 220
 
219
-/*
220
- * Function to read 16 bits starting at reg.  This function
221
- * was replaced due to functionality of using read() to
222
- * access i2c data.
223
- */
224 221
 uint16_t
225 222
 HTU21D::i2cReadReg_16 (int reg) {
226 223
     uint16_t data;
@@ -230,11 +227,6 @@ HTU21D::i2cReadReg_16 (int reg) {
230 227
     return data;
231 228
 }
232 229
 
233
-/*
234
- * Function to read 8 bits starting at reg.  This function
235
- * was replaced due to functionality of using read() to
236
- * access i2c data.
237
- */
238 230
 uint8_t
239 231
 HTU21D::i2cReadReg_8 (int reg) {
240 232
     mraa_i2c_address(m_i2ControlCtx, m_controlAddr);

+ 75
- 61
src/htu21d/htu21d.h View File

@@ -2,23 +2,23 @@
2 2
  * Author: William Penner <william.penner@intel.com>
3 3
  * Copyright (c) 2014 Intel Corporation.
4 4
  *
5
- * Based on code adapted from the kernel HTU21 driver and
6
- * code by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
7
- * Copyright (c) 2014 Intel Corporation.
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
13 11
  *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- * GNU General Public License for more details.
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
18 14
  *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22 22
  */
23 23
 
24 24
 #pragma once
@@ -27,12 +27,24 @@
27 27
 #include <mraa/i2c.h>
28 28
 #include <math.h>
29 29
 
30
-#define HTU21D_NAME     "htu21d"
31
-#define HTU21D_I2C_ADDRESS  0x40
32
-
33
-/* HTU21 Commands */
34
-#define HTU21D_T_MEASUREMENT_HM   0xE3
35
-#define HTU21D_RH_MEASUREMENT_HM  0xE5
30
+#define HTU21D_NAME "htu21d"
31
+#define HTU21D_I2C_ADDRESS 0x40
32
+
33
+/* HTU21D Commands */
34
+#define HTU21D_READ_TEMP_HOLD     0xE3
35
+#define HTU21D_READ_HUMIDITY_HOLD 0xE5
36
+#define HTU21D_WRITE_USER_REG     0xE6
37
+#define HTU21D_READ_USER_REG      0xE7
38
+#define HTU21D_SOFT_RESET         0xFE
39
+
40
+/* User Register Bit Definition */
41
+#define HTU21D_DISABLE_OTP        0x02
42
+#define HTU21D_HEATER_ENABLE      0x04
43
+#define HTU21D_END_OF_BATTERY     0x40
44
+#define HTU21D_RESO_RH12_T14      0x00
45
+#define HTU21D_RESO_RH8_T12       0x01
46
+#define HTU21D_RESO_RH10_T13      0x80
47
+#define HTU21D_RESO_RH11_T11      0x81
36 48
 
37 49
 namespace upm {
38 50
 
@@ -48,7 +60,13 @@ namespace upm {
48 60
  * (http://www.meas-spec.com/downloads/HTU21D.pdf)
49 61
  * is a digital humidity sensor with temperature output.
50 62
  * RH will report between 0 and 100% and temperature range is
51
- * -40 to +125 degC
63
+ * -40 to +125 degC.  Note that the getCompRH is the preferred
64
+ * function below (passing true to cause a measurement cycle).  If
65
+ * the actual values used for the compensated ready are necessary, use
66
+ * the getHumidity(false) and getTemperature(false) functions following
67
+ * the getCompRH call.
68
+ * Also note that the sensor should not perform more than a couple of
69
+ * measurements per second to limit the heating of the sensor.
52 70
  *
53 71
  * @ingroup htu21d i2c
54 72
  * @snippet htu21d.cxx Interesting
@@ -63,7 +81,7 @@ class HTU21D {
63 81
          * @param devAddr address of used i2c device
64 82
          * @param mode HTU21D oversampling
65 83
          */
66
-        HTU21D (int bus=0, int devAddr=HTU21D_I2C_ADDRESS);
84
+        HTU21D (int bus, int devAddr=HTU21D_I2C_ADDRESS);
67 85
 
68 86
         /**
69 87
          * HTU21D object destructor, basicaly it close i2c connection.
@@ -76,58 +94,47 @@ class HTU21D {
76 94
          * after this call.
77 95
          */
78 96
         int sampleData(void);
79
-        
80
-        /**
81
-         * Get the current measured humidity [RH * 1000]
82
-         * To convert to Relative Humidity, divide by 1000
83
-         *
84
-         */
85
-        int32_t getHumidity(void);
86 97
 
87 98
         /**
88
-         * Get the humidity cell temperature [degC * 1000]
89
-         * To convert to Temperature, divide by 1000
99
+         * Get the current measured humidity [RH]
90 100
          */
91
-        int32_t getTemperature(void);
92
-        
101
+        float getHumidity(int bSampleData = false);
102
+
93 103
         /**
94
-         * Reads both temperature and humidity together
95
-         * To convert to Relative Humidity, divide by 1000
96
-         * To convert to Temperature, divide by 1000
97
-         *
98
-         * @param pointer to int32_t buffer for temp
104
+         * Get the humidity cell temperature [degC]
99 105
          */
100
-        int32_t getRHumidity(int32_t* iTemperature);
101
-        
106
+        float getTemperature(int bSampleData = false);
107
+
102 108
         /**
103 109
          * Using the current humidity and temperature the function
104 110
          * will calculate the compensated RH using the equation from
105 111
          * the datasheet.
106 112
          */
107
-        int32_t getCompRH(void);
108
-        
113
+        float getCompRH(int bSampleData = true);
114
+
109 115
         /**
110
-         * Function intended to test the device and verify it
111
-         * is correctly operating.
116
+         * Set the heater state.  The heater is used to either test
117
+         * the sensor functionality since the temp should increase
118
+         * 0.5 to 1.5 degC and the humidity should decrease.  The
119
+         * testSensor() function below will use the heater.
112 120
          *
121
+         * @param bEnable Set to non-zero to turn on heater
113 122
          */
114
-        int testSensor(void);
115
-        
123
+         int setHeater(int bEnable = false);
124
+
116 125
         /**
117
-         * Read 1 to 4 bytes from i2c registers
118
-         *
119
-         * @param reg address of a register
120
-         * @param puint32 pointer to buffer for register data
121
-         * @param ibytes number of bytes to be returned
126
+         * Perform a soft RESET of the MPL3115A2 device to ensure
127
+         * it is in a known state.  This function can be used to reset
128
+         * the min/max temperature and pressure values.
122 129
          */
123
-        mraa_result_t i2cReadRegValue (int reg, uint32_t* puint32, int ibytes);
130
+        int resetSensor(void);
124 131
 
125 132
         /**
126
-         * Read two bytes register
133
+         * Function intended to test the device and verify it
134
+         * is correctly operating.
127 135
          *
128
-         * @param reg address of a register
129 136
          */
130
-        uint16_t i2cReadReg_16 (int reg);
137
+        int testSensor(void);
131 138
 
132 139
         /**
133 140
          * Write to one byte register
@@ -137,6 +144,13 @@ class HTU21D {
137 144
          */
138 145
         mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
139 146
 
147
+        /**
148
+         * Read two bytes register
149
+         *
150
+         * @param reg address of a register
151
+         */
152
+        uint16_t i2cReadReg_16 (int reg);
153
+
140 154
         /**
141 155
          * Read one byte register
142 156
          *
@@ -147,21 +161,21 @@ class HTU21D {
147 161
     private:
148 162
 
149 163
         /**
150
-         * Convert temp register to value * 1000
164
+         * Convert temp register to degC * 1000
151 165
          */
152
-        int32_t htu21_temp_ticks_to_millicelsius(int ticks);
166
+        int32_t convertTemp(int32_t regval);
153 167
 
154 168
         /**
155
-         * Convert temp register to value * 1000
169
+         * Convert RH register to %RH * 1000
156 170
          */
157
-        int32_t htu21_rh_ticks_to_per_cent_mille(int ticks);
171
+        int32_t convertRH(int32_t regval);
158 172
 
159 173
         std::string m_name;
160 174
 
161 175
         int m_controlAddr;
162 176
         int m_bus;
163 177
         mraa_i2c_context m_i2ControlCtx;
164
-        
178
+
165 179
         int32_t m_temperature;
166 180
         int32_t m_humidity;
167 181
 };