upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
th02.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Credits to Seeed Studeo.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <string>
29 #include <mraa/i2c.h>
30 
31 #define ADDR 0x40 // device address
32 
33 #define REG_STATUS 0x00
34 #define REG_DATA_H 0x01
35 #define REG_DATA_L 0x02
36 #define REG_CONFIG 0x03
37 #define REG_ID 0x11
38 
39 #define STATUS_RDY_MASK 0x01
40 
41 #define CMD_MEASURE_HUMI 0x01
42 #define CMD_MEASURE_TEMP 0x11
43 
44 #define TH02_WR_REG_MODE 0xC0
45 #define TH02_RD_REG_MODE 0x80
46 
47 #define HIGH 1
48 #define LOW 0
49 
50 namespace upm {
51 
75 class TH02 {
76  public:
80  TH02 ();
81 
85  ~TH02 ();
86 
90  float getTemperature ();
91 
95  float getHumidity ();
96 
100  bool getStatus ();
101 
105  std::string name()
106  {
107  return m_name;
108  }
109  private:
110  std::string m_name;
111  mraa_i2c_context m_i2Ctx;
112 
113  uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
114  mraa_result_t i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
115  mraa_result_t i2cWriteReg (uint8_t reg, uint8_t data);
116 };
117 
118 }
TH02()
Definition: th02.cxx:42
std::string name()
Definition: th02.h:105
bool getStatus()
Definition: th02.cxx:99
Definition: a110x.h:29
float getHumidity()
Definition: th02.cxx:78
~TH02()
Definition: th02.cxx:52
float getTemperature()
Definition: th02.cxx:57
C++ API for th02 temperature & humidity sensor library.
Definition: th02.h:75