1
+ /* !
2
+ * @file drvHtu31d.h
3
+ *
4
+ * Device driver for an HTU31D Humidity and Temperature sensor.
5
+ */
6
+
7
+ #ifndef DRV_HTU31D_H
8
+ #define DRV_HTU31D_H
9
+
10
+ #include " drvBase.h"
11
+ #include < Adafruit_HTU31D.h>
12
+
13
+ /* *************************************************************************/
14
+ /* !
15
+ @brief Class that provides a sensor driver for the HTU31D humidity and
16
+ temperature sensor.
17
+ */
18
+ /* *************************************************************************/
19
+ class drvHtu31d : public drvBase {
20
+
21
+ public:
22
+ /* ******************************************************************************/
23
+ /* !
24
+ @brief Constructor for an HTU31D sensor.
25
+ @param i2c
26
+ The I2C interface.
27
+ @param sensorAddress
28
+ 7-bit device address.
29
+ @param mux_channel
30
+ The I2C multiplexer channel.
31
+ @param driver_name
32
+ The name of the driver.
33
+ */
34
+ /* ******************************************************************************/
35
+ drvHtu31d (TwoWire *i2c, uint16_t sensorAddress, uint32_t mux_channel,
36
+ const char *driver_name)
37
+ : drvBase(i2c, sensorAddress, mux_channel, driver_name) {
38
+ // Initialization handled by drvBase constructor
39
+ }
40
+
41
+ /* ******************************************************************************/
42
+ /* !
43
+ @brief Destructor for an HTU31D sensor.
44
+ */
45
+ /* ******************************************************************************/
46
+ ~drvHtu31d () { delete _htu31d; }
47
+
48
+ /* ******************************************************************************/
49
+ /* !
50
+ @brief Initializes the HTU31D sensor and begins I2C.
51
+ @returns True if initialized successfully, False otherwise.
52
+
53
+ */
54
+ /* ******************************************************************************/
55
+ bool begin () {
56
+ // attempt to initialize the HTU31D using the I2C interface
57
+ _htu31d = new Adafruit_HTU31D ();
58
+ return _htu31d->begin (_address, _i2c);
59
+ }
60
+
61
+ /* ******************************************************************************/
62
+ /* !
63
+ @brief Gets the HTU31D's current temperature.
64
+ @param tempEvent
65
+ Pointer to an Adafruit_Sensor event.
66
+ @returns True if the temperature was obtained successfully, False
67
+ otherwise.
68
+ */
69
+ /* ******************************************************************************/
70
+ bool getEventAmbientTemp (sensors_event_t *tempEvent) {
71
+ return _htu31d->getEvent (nullptr , tempEvent);
72
+ }
73
+
74
+ /* ******************************************************************************/
75
+ /* !
76
+ @brief Gets the HTU31D's current humidity.
77
+ @param humidEvent
78
+ Pointer to an Adafruit_Sensor event.
79
+ @returns True if the humidity was obtained successfully, False
80
+ otherwise.
81
+ */
82
+ /* ******************************************************************************/
83
+ bool getEventRelativeHumidity (sensors_event_t *humidEvent) {
84
+ return _htu31d->getEvent (humidEvent, nullptr );
85
+ }
86
+
87
+ protected:
88
+ Adafruit_HTU31D *_htu31d; // /< Pointer to an HTU31D object
89
+ };
90
+ #endif // DRV_HTU31D_H
0 commit comments