BrickUp API Service for Docker version.

TH02_dev.h 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef _TH02_DEV_H
  32. #define _TH02_DEV_H
  33. /****************************************************************************/
  34. /*** Including Files ***/
  35. /****************************************************************************/
  36. #include <Wire.h>
  37. #include <Arduino.h>
  38. /****************************************************************************/
  39. /*** Macro Definitions ***/
  40. /****************************************************************************/
  41. #define TH02_I2C_DEV_ID 0x40
  42. #define REG_STATUS 0x00
  43. #define REG_DATA_H 0x01
  44. #define REG_DATA_L 0x02
  45. #define REG_CONFIG 0x03
  46. #define REG_ID 0x11
  47. #define STATUS_RDY_MASK 0x01 //poll RDY,0 indicate the conversion is done
  48. #define CMD_MEASURE_HUMI 0x01 //perform a humility measurement
  49. #define CMD_MEASURE_TEMP 0x11 //perform a temperature measurement
  50. #define TH02_WR_REG_MODE 0xC0
  51. #define TH02_RD_REG_MODE 0x80
  52. /****************************************************************************/
  53. /*** Class Definition ***/
  54. /****************************************************************************/
  55. class TH02_dev
  56. {
  57. public:
  58. void begin();
  59. uint8_t isAvailable();
  60. float ReadTemperature(void);
  61. float ReadHumidity(void);
  62. private:
  63. void TH02_IIC_WriteCmd(uint8_t u8Cmd);
  64. uint8_t TH02_IIC_ReadReg(uint8_t u8Reg);
  65. void TH02_IIC_WriteReg(uint8_t u8Reg,uint8_t u8Data);
  66. uint16_t TH02_IIC_ReadData(void);
  67. uint16_t TH02_IIC_ReadData2byte(void);
  68. };
  69. extern TH02_dev TH02;
  70. #endif // _TH02_DEV_H