1
+ /* !
2
+ * @file WipperSnapper_I2C_Driver_MPL115A2.h
3
+ *
4
+ * Device driver for a MPL115A2 pressure sensor breakout.
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_MPL115A2_H
17
+ #define WipperSnapper_I2C_Driver_MPL115A2_H
18
+
19
+ #include " WipperSnapper_I2C_Driver.h"
20
+ #include < Adafruit_MPL115A2.h>
21
+
22
+ /* *************************************************************************/
23
+ /* !
24
+ @brief Class that provides a sensor driver for the MPL115A2 temperature
25
+ and pressure sensor.
26
+ */
27
+ /* *************************************************************************/
28
+ class WipperSnapper_I2C_Driver_MPL115A2 : public WipperSnapper_I2C_Driver {
29
+
30
+ public:
31
+ /* ******************************************************************************/
32
+ /* !
33
+ @brief Constructor for an MPL115A2 sensor.
34
+ @param i2c
35
+ The I2C interface.
36
+ @param sensorAddress
37
+ 7-bit device address.
38
+ */
39
+ /* ******************************************************************************/
40
+ WipperSnapper_I2C_Driver_MPL115A2 (TwoWire *i2c, uint16_t sensorAddress)
41
+ : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
42
+ _i2c = i2c;
43
+ _sensorAddress = sensorAddress;
44
+ }
45
+
46
+ /* ******************************************************************************/
47
+ /* !
48
+ @brief Destructor for an MPL115A2 sensor.
49
+ */
50
+ /* ******************************************************************************/
51
+ ~WipperSnapper_I2C_Driver_MPL115A2 () { delete _mpl115a2; }
52
+
53
+ /* ******************************************************************************/
54
+ /* !
55
+ @brief Initializes the MPL115A2 sensor and begins I2C.
56
+ @returns True if initialized successfully, False otherwise.
57
+ */
58
+ /* ******************************************************************************/
59
+ bool begin () {
60
+ _mpl115a2 = new Adafruit_MPL115A2 ();
61
+ // attempt to initialize MPL115A2
62
+ if (!_mpl115a2->begin (_sensorAddress, _i2c))
63
+ return false ;
64
+ return true ;
65
+ }
66
+
67
+ /* ******************************************************************************/
68
+ /* !
69
+ @brief Gets the MPL115A2's current temperature.
70
+ @param tempEvent
71
+ Pointer to an Adafruit_Sensor event.
72
+ @returns True if the temperature was obtained successfully, False
73
+ otherwise.
74
+ */
75
+ /* ******************************************************************************/
76
+ bool getEventAmbientTemp (sensors_event_t *tempEvent) {
77
+ tempEvent->temperature = _mpl115a2->getTemperature ();
78
+ return true ;
79
+ }
80
+
81
+ /* ******************************************************************************/
82
+ /* !
83
+ @brief Reads a pressure sensor and converts
84
+ the reading into the expected SI unit (hPa).
85
+ @param pressureEvent
86
+ Pointer to an Adafruit_Sensor event.
87
+ @returns True if the sensor event was obtained successfully, False
88
+ otherwise.
89
+ */
90
+ /* ******************************************************************************/
91
+ bool getEventPressure (sensors_event_t *pressureEvent) {
92
+ pressureEvent->pressure = _mpl115a2->getPressure () * 10 ;
93
+ return true ;
94
+ }
95
+
96
+ protected:
97
+ Adafruit_MPL115A2 *_mpl115a2; // /< MPL115A2 object
98
+ };
99
+
100
+ #endif // WipperSnapper_I2C_Driver_MPL115A2
0 commit comments