-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAdafruit_SHTC3.h
134 lines (113 loc) · 4.76 KB
/
Adafruit_SHTC3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*!
* @file Adafruit_SHTC3.h
*
* This is a library for the SHTC3 Digital Humidity & Temp Sensor
*
* Designed specifically to work with the Digital Humidity & Temp Sensor
* -----> https://www.adafruit.com/product/4636
*
* These sensors use I2C to communicate, 2 pins are required to interface
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit andopen-source hardware by purchasing products
* from Adafruit!
*
* Limor Fried/Ladyada (Adafruit Industries).
*
* BSD license, all text above must be included in any redistribution
*/
#ifndef ADAFRUIT_SHTC3_H
#define ADAFRUIT_SHTC3_H
#include "Arduino.h"
#include <Adafruit_I2CDevice.h>
#include <Adafruit_Sensor.h>
#define SHTC3_DEFAULT_ADDR 0x70 /**< SHTC3 I2C Address */
#define SHTC3_NORMAL_MEAS_TFIRST_STRETCH \
0x7CA2 /**< Normal measurement, temp first with Clock Stretch Enabled */
#define SHTC3_LOWPOW_MEAS_TFIRST_STRETCH \
0x6458 /**< Low power measurement, temp first with Clock Stretch Enabled */
#define SHTC3_NORMAL_MEAS_HFIRST_STRETCH \
0x5C24 /**< Normal measurement, hum first with Clock Stretch Enabled */
#define SHTC3_LOWPOW_MEAS_HFIRST_STRETCH \
0x44DE /**< Low power measurement, hum first with Clock Stretch Enabled */
#define SHTC3_NORMAL_MEAS_TFIRST \
0x7866 /**< Normal measurement, temp first with Clock Stretch disabled */
#define SHTC3_LOWPOW_MEAS_TFIRST \
0x609C /**< Low power measurement, temp first with Clock Stretch disabled */
#define SHTC3_NORMAL_MEAS_HFIRST \
0x58E0 /**< Normal measurement, hum first with Clock Stretch disabled */
#define SHTC3_LOWPOW_MEAS_HFIRST \
0x401A /**< Low power measurement, hum first with Clock Stretch disabled */
#define SHTC3_READID 0xEFC8 /**< Read Out of ID Register */
#define SHTC3_SOFTRESET 0x805D /**< Soft Reset */
#define SHTC3_SLEEP 0xB098 /**< Enter sleep mode */
#define SHTC3_WAKEUP 0x3517 /**< Wakeup mode */
class Adafruit_SHTC3;
/**
* @brief Adafruit Unified Sensor interface for the humidity sensor component
* of SHTC3
*
*/
class Adafruit_SHTC3_Humidity : public Adafruit_Sensor {
public:
/** @brief Create an Adafruit_Sensor compatible object for the humidity sensor
@param parent A pointer to the SHTC3 class */
Adafruit_SHTC3_Humidity(Adafruit_SHTC3 *parent) { _theSHTC3 = parent; }
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);
private:
int _sensorID = 0x03C1;
Adafruit_SHTC3 *_theSHTC3 = NULL;
};
/**
* @brief Adafruit Unified Sensor interface for the temperature sensor component
* of SHTC3
*
*/
class Adafruit_SHTC3_Temp : public Adafruit_Sensor {
public:
/** @brief Create an Adafruit_Sensor compatible object for the temp sensor
@param parent A pointer to the SHTC3 class */
Adafruit_SHTC3_Temp(Adafruit_SHTC3 *parent) { _theSHTC3 = parent; }
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);
private:
int _sensorID = 0x0C30;
Adafruit_SHTC3 *_theSHTC3 = NULL;
};
/**
* Driver for the Adafruit SHTC3 Temperature and Humidity breakout board.
*/
class Adafruit_SHTC3 {
public:
Adafruit_SHTC3(void);
~Adafruit_SHTC3(void);
bool begin(TwoWire *theWire = &Wire);
uint16_t readID(void);
void reset(void);
void sleep(bool sleepmode);
void lowPowerMode(bool readmode);
bool getEvent(sensors_event_t *humidity, sensors_event_t *temp);
Adafruit_Sensor *getTemperatureSensor(void);
Adafruit_Sensor *getHumiditySensor(void);
protected:
float _temperature, ///< Last reading's temperature (C)
_humidity; ///< Last reading's humidity (percent)
uint16_t _sensorid_humidity; ///< ID number for humidity
uint16_t _sensorid_temp; ///< ID number for temperature
Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface
Adafruit_SHTC3_Temp *temp_sensor = NULL; ///< Temp sensor data object
Adafruit_SHTC3_Humidity *humidity_sensor =
NULL; ///< Humidity sensor data object
private:
bool _lpMode = false;
bool writeCommand(uint16_t cmd);
bool readCommand(uint16_t command, uint8_t *buffer, uint8_t num_bytes);
friend class Adafruit_SHTC3_Temp; ///< Gives access to private members to
///< Temp data object
friend class Adafruit_SHTC3_Humidity; ///< Gives access to private members to
///< Humidity data object
void fillTempEvent(sensors_event_t *temp, uint32_t timestamp);
void fillHumidityEvent(sensors_event_t *humidity, uint32_t timestamp);
};
#endif