1
+ /* !
2
+ * @file WipperSnapper_I2C_Driver_MS8607.h
3
+ *
4
+ * Device driver for an AHT Humidity and Temperature sensor.
5
+ *
6
+ * Adafruit invests time and resources providing this open source code,
7
+ * please support Adafruit and open-source hardware by purchasing
8
+ * products from Adafruit!
9
+ *
10
+ * Copyright (c) Tyeth Gundry 2023 for Adafruit Industries.
11
+ *
12
+ * MIT license, all text here must be included in any redistribution.
13
+ *
14
+ */
15
+
16
+ #ifndef WipperSnapper_I2C_Driver_MS8607_H
17
+ #define WipperSnapper_I2C_Driver_MS8607_H
18
+
19
+ #include " WipperSnapper_I2C_Driver.h"
20
+ #include < Adafruit_MS8607.h>
21
+
22
+ /* *************************************************************************/
23
+ /* !
24
+ @brief Class that provides a sensor driver for the MS8607 PHT sensor.
25
+ */
26
+ /* *************************************************************************/
27
+ class WipperSnapper_I2C_Driver_MS8607 : public WipperSnapper_I2C_Driver {
28
+
29
+ public:
30
+ /* ******************************************************************************/
31
+ /* !
32
+ @brief Constructor for an MS8607 sensor.
33
+ @param i2c
34
+ The I2C interface.
35
+ @param sensorAddress
36
+ 7-bit device address.
37
+ */
38
+ /* ******************************************************************************/
39
+ WipperSnapper_I2C_Driver_MS8607 (TwoWire *i2c, uint16_t sensorAddress)
40
+ : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
41
+ _i2c = i2c;
42
+ _sensorAddress = sensorAddress;
43
+ }
44
+
45
+ /* ******************************************************************************/
46
+ /* !
47
+ @brief Destructor for an MS8607 sensor.
48
+ */
49
+ /* ******************************************************************************/
50
+ ~WipperSnapper_I2C_Driver_MS8607 () { delete _ms8607; }
51
+
52
+ /* ******************************************************************************/
53
+ /* !
54
+ @brief Initializes the MS8607 sensor and begins I2C.
55
+ @returns True if initialized successfully, False otherwise.
56
+ */
57
+ /* ******************************************************************************/
58
+ bool begin () {
59
+ _ms8607 = new Adafruit_MS8607 ();
60
+ // attempt to initialize MS8607
61
+ if (!_ms8607->begin (_i2c))
62
+ return false ;
63
+
64
+ _ms8607_temp = _ms8607->getTemperatureSensor ();
65
+ _ms8607_humidity = _ms8607->getHumiditySensor ();
66
+ _ms8607_pressure = _ms8607->getPressureSensor ();
67
+ return true ;
68
+ }
69
+
70
+ /* ******************************************************************************/
71
+ /* !
72
+ @brief Gets the MS8607's current temperature.
73
+ @param tempEvent
74
+ Pointer to an Adafruit_Sensor event.
75
+ @returns True if the temperature was obtained successfully, False
76
+ otherwise.
77
+ */
78
+ /* ******************************************************************************/
79
+ bool getEventAmbientTemp (sensors_event_t *tempEvent) {
80
+ if (_ms8607_temp == NULL )
81
+ return false ;
82
+ _ms8607_temp->getEvent (tempEvent);
83
+ return true ;
84
+ }
85
+
86
+ /* ******************************************************************************/
87
+ /* !
88
+ @brief Gets the MS8607's current relative humidity reading.
89
+ @param humidEvent
90
+ Pointer to an Adafruit_Sensor event.
91
+ @returns True if the humidity was obtained successfully, False
92
+ otherwise.
93
+ */
94
+ /* ******************************************************************************/
95
+ bool getEventRelativeHumidity (sensors_event_t *humidEvent) {
96
+ if (_ms8607_humidity == NULL )
97
+ return false ;
98
+ _ms8607_humidity->getEvent (humidEvent);
99
+ return true ;
100
+ }
101
+
102
+ /* ******************************************************************************/
103
+ /* !
104
+ @brief Reads a pressure sensor and converts
105
+ the reading into the expected SI unit.
106
+ @param pressureEvent
107
+ Pointer to an Adafruit_Sensor event.
108
+ @returns True if the sensor event was obtained successfully, False
109
+ otherwise.
110
+ */
111
+ /* ******************************************************************************/
112
+ bool getEventPressure (sensors_event_t *pressureEvent) {
113
+ if (_ms8607_pressure == NULL )
114
+ return false ;
115
+ _ms8607_pressure->getEvent (pressureEvent);
116
+ return true ;
117
+ }
118
+
119
+ protected:
120
+ Adafruit_MS8607 *_ms8607; // /< MS8607 object
121
+ Adafruit_Sensor *_ms8607_temp =
122
+ NULL ; // /< Ptr to an adafruit_sensor representing the temperature
123
+ Adafruit_Sensor *_ms8607_pressure =
124
+ NULL ; // /< Ptr to an adafruit_sensor representing the pressure
125
+ Adafruit_Sensor *_ms8607_humidity =
126
+ NULL ; // /< Ptr to an adafruit_sensor representing the humidity
127
+ };
128
+
129
+ #endif // WipperSnapper_I2C_Driver_MS8607
0 commit comments