upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
htu21d.hpp
1 /*
2  * Author: William Penner <william.penner@intel.com>
3  * Copyright (c) 2014-2017 Intel Corporation.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
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  */
23 
24 #pragma once
25 
26 #include <string>
27 #include <mraa/i2c.hpp>
28 #include <math.h>
29 
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
48 
49 namespace upm {
50 
82 class HTU21D {
83  public:
90  HTU21D (int bus, int devAddr=HTU21D_I2C_ADDRESS);
91 
97  int sampleData(void);
98 
105  float getHumidity(int bSampleData = false);
106 
113  float getTemperature(int bSampleData = false);
114 
123  float getCompRH(int bSampleData = false);
124 
133  float getDewPoint(int bSampleData = false);
134 
145  int getHumidityData(float* fHum, float* fHumTemp, float* fDewPt);
146 
156  int setHeater(int bEnable = false);
157 
163  void resetSensor(void);
164 
171  int testSensor(void);
172 
179  mraa::Result i2cWriteReg (uint8_t reg, uint8_t value);
180 
188  uint16_t i2cReadReg_16 (int reg);
189 
196  uint8_t i2cReadReg_8 (int reg);
197 
198  private:
199 
203  int32_t convertTemp(int32_t regval);
204 
208  int32_t convertRH(int32_t regval);
209 
210  std::string m_name;
211 
212  int m_controlAddr;
213  int m_bus;
214  mraa::I2c m_i2ControlCtx;
215 
216  int32_t m_temperature;
217  int32_t m_humidity;
218 };
219 
220 }
int testSensor(void)
Definition: htu21d.cpp:198
int setHeater(int bEnable=false)
Definition: htu21d.cpp:127
uint8_t i2cReadReg_8(int reg)
Definition: htu21d.cpp:275
float getHumidity(int bSampleData=false)
Definition: htu21d.cpp:103
uint16_t i2cReadReg_16(int reg)
Definition: htu21d.cpp:270
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
float getDewPoint(int bSampleData=false)
Definition: htu21d.cpp:150
API for the HTU21D Temperature & Humidity Sensor.
Definition: htu21d.hpp:82
int sampleData(void)
Definition: htu21d.cpp:80
int getHumidityData(float *fHum, float *fHumTemp, float *fDewPt)
Definition: htu21d.cpp:174
float getCompRH(int bSampleData=false)
Definition: htu21d.cpp:118
float getTemperature(int bSampleData=false)
Definition: htu21d.cpp:94
mraa::Result i2cWriteReg(uint8_t reg, uint8_t value)
Definition: htu21d.cpp:257
HTU21D(int bus, int devAddr=HTU21D_I2C_ADDRESS)
Definition: htu21d.cpp:36
void resetSensor(void)
Definition: htu21d.cpp:54