Advertisement
jamrab

TH02_dev.h

Apr 23rd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | None | 0 0
  1. /*
  2.     TH02_dev.h
  3.     Driver for DIGITAL I2C HUMIDITY AND TEMPERATURE SENSOR
  4.  
  5.     Copyright (c) 2014 seeed technology inc.
  6.     Website    : www.seeed.cc
  7.     Author     : Oliver Wang
  8.     Create Time: April 2014
  9.     Change Log :
  10.  
  11.     The MIT License (MIT)
  12.  
  13.     Permission is hereby granted, free of charge, to any person obtaining a copy
  14.     of this software and associated documentation files (the "Software"), to deal
  15.     in the Software without restriction, including without limitation the rights
  16.     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17.     copies of the Software, and to permit persons to whom the Software is
  18.     furnished to do so, subject to the following conditions:
  19.  
  20.     The above copyright notice and this permission notice shall be included in
  21.     all copies or substantial portions of the Software.
  22.  
  23.     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24.     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25.     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26.     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27.     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28.     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29.     THE SOFTWARE.
  30. */
  31.  
  32. #ifndef _TH02_DEV_H
  33. #define _TH02_DEV_H
  34.  
  35. /****************************************************************************/
  36. /***        Including Files                                               ***/
  37. /****************************************************************************/
  38. #include <Wire.h>
  39. #include <Particle.h>
  40.  
  41. /****************************************************************************/
  42. /***        Macro Definitions                                             ***/
  43. /****************************************************************************/
  44. #define TH02_I2C_DEV_ID      0x40
  45. #define REG_STATUS           0x00
  46. #define REG_DATA_H           0x01
  47. #define REG_DATA_L           0x02
  48. #define REG_CONFIG           0x03
  49. #define REG_ID               0x11
  50.  
  51. #define STATUS_RDY_MASK      0x01    //poll RDY,0 indicate the conversion is done
  52.  
  53. #define CMD_MEASURE_HUMI     0x01    //perform a humility measurement
  54. #define CMD_MEASURE_TEMP     0x11    //perform a temperature measurement
  55.  
  56. #define TH02_WR_REG_MODE      0xC0
  57. #define TH02_RD_REG_MODE      0x80
  58. /****************************************************************************/
  59. /***        Class Definition                                              ***/
  60. /****************************************************************************/
  61. class TH02_dev {
  62.   public:
  63.     void begin();
  64.     uint8_t isAvailable();
  65.     float ReadTemperature(void);
  66.     float ReadHumidity(void);
  67.   private:
  68.     void TH02_IIC_WriteCmd(uint8_t u8Cmd);
  69.     uint8_t TH02_IIC_ReadReg(uint8_t u8Reg);
  70.     void TH02_IIC_WriteReg(uint8_t u8Reg, uint8_t u8Data);
  71.     uint16_t TH02_IIC_ReadData(void);
  72.     uint16_t TH02_IIC_ReadData2byte(void);
  73. };
  74. extern TH02_dev TH02;
  75.  
  76. #endif  // _TH02_DEV_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement