upm  0.1.8
Sensor/Actuator repository for libmraa (v0.4.5)
 All Data Structures Files Functions Variables Macros Pages
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 
60 class TH02 {
61  public:
65  TH02 ();
66 
70  ~TH02 ();
71 
75  float getTemperature ();
76 
80  float getHumidity ();
81 
85  bool getStatus ();
86 
90  std::string name()
91  {
92  return m_name;
93  }
94  private:
95  std::string m_name;
96  mraa_i2c_context m_i2Ctx;
97 
98  uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
99  mraa_result_t i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
100  mraa_result_t i2cWriteReg (uint8_t reg, uint8_t data);
101 };
102 
103 }
TH02()
Definition: th02.cxx:42
std::string name()
Definition: th02.h:90
bool getStatus()
Definition: th02.cxx:99
float getHumidity()
Definition: th02.cxx:78
~TH02()
Definition: th02.cxx:52
float getTemperature()
Definition: th02.cxx:57
C++ API for TH02 chip (Temperature and Humidity Sensor Pro)
Definition: th02.h:60