1 /* 2 * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com> 3 * Contributions: Jon Trulson <jtlulson@ics.com> 4 * Copyright (c) 2014 Intel Corporation. 5 * 6 * Credits to Seeed Studeo. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining 9 * a copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sublicense, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be 17 * included in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 */ 27 #pragma once 28 29 #include <string> 30 #include <mraa/i2c.hpp> 31 32 #define TH02_ADDR 0x40 // device address 33 34 #define TH02_REG_STATUS 0x00 35 #define TH02_REG_DATA_H 0x01 36 #define TH02_REG_DATA_L 0x02 37 #define TH02_REG_CONFIG 0x03 38 #define TH02_REG_ID 0x11 39 40 #define TH02_STATUS_RDY_MASK 0x01 41 42 #define TH02_CMD_MEASURE_HUMI 0x01 43 #define TH02_CMD_MEASURE_TEMP 0x11 44 45 namespace upm { 46 47 /** 48 * @brief TH02 Temperature & Humidity Sensor library 49 * @defgroup th02 libupm-th02 50 * @ingroup seeed i2c temp 51 */ 52 /** 53 * @library th02 54 * @sensor th02 55 * @comname TH02 Temperature & Humidity Sensor 56 * @altname Grove Temperature & Humidity Sensor (High-Accuracy & Mini) 57 * @type temp 58 * @man seeed 59 * @web http://www.seeedstudio.com/wiki/Grove_-_Tempture%26Humidity_Sensor_(High-Accuracy_%26Mini)_v1.0 60 * @con i2c 61 * 62 * @brief API for the TH02 Temperature & Humidity Sensor 63 * 64 * This module defines the TH02 interface for libth02 65 * 66 * Note: For use on Intel(R) Edison with an Arduino* breakout board, Intel 67 * Edison must be set to 3 V rather than 5 V. 68 * 69 * @image html th02.jpg 70 * @snippet th02.cxx Interesting 71 */ 72 class TH02 { 73 public: 74 /** 75 * Instantiates a TH02 object 76 */ 77 TH02 (int bus=0, uint8_t addr=TH02_ADDR); 78 79 /** 80 * TH02 object destructor; basically, it closes the I2C connection. 81 */ 82 ~TH02 (); 83 84 /** 85 * Gets the temperature value from the sensor. 86 */ 87 float getTemperature (); 88 89 /** 90 * Gets the humidity value from the sensor. 91 */ 92 float getHumidity (); 93 94 /** 95 * Gets the sensor status. 96 */ 97 bool getStatus (); 98 99 /** 100 * Returns the name of the component 101 */ name()102 std::string name() 103 { 104 return m_name; 105 } 106 107 private: 108 std::string m_name; 109 mraa::I2c m_i2c; 110 uint8_t m_addr; 111 }; 112 113 } 114