1
+ /* !
2
+ * @file WipperSnapper_I2C_Driver_BMP3XX.h
3
+ *
4
+ * Device driver for a BMP3XX precision 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_BMP3XX_H
17
+ #define WipperSnapper_I2C_Driver_BMP3XX_H
18
+
19
+ #include " WipperSnapper_I2C_Driver.h"
20
+ #include < Adafruit_BMP3XX.h>
21
+
22
+ #define SEALEVELPRESSURE_HPA (1013.25 ) // /< Default sea level pressure, in hPa
23
+
24
+ /* *************************************************************************/
25
+ /* !
26
+ @brief Class that provides a sensor driver for the BMP3XX temperature
27
+ and pressure sensor.
28
+ */
29
+ /* *************************************************************************/
30
+ class WipperSnapper_I2C_Driver_BMP3XX : public WipperSnapper_I2C_Driver {
31
+
32
+ public:
33
+ /* ******************************************************************************/
34
+ /* !
35
+ @brief Constructor for an BMP3XX sensor.
36
+ @param i2c
37
+ The I2C interface.
38
+ @param sensorAddress
39
+ 7-bit device address.
40
+ */
41
+ /* ******************************************************************************/
42
+ WipperSnapper_I2C_Driver_BMP3XX (TwoWire *i2c, uint16_t sensorAddress)
43
+ : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
44
+ _i2c = i2c;
45
+ _sensorAddress = sensorAddress;
46
+ }
47
+
48
+ /* ******************************************************************************/
49
+ /* !
50
+ @brief Destructor for an BMP3XX sensor.
51
+ */
52
+ /* ******************************************************************************/
53
+ ~WipperSnapper_I2C_Driver_BMP3XX () { delete _bmp3xx; }
54
+
55
+ /* ******************************************************************************/
56
+ /* !
57
+ @brief Initializes the BMP3XX sensor and begins I2C.
58
+ @returns True if initialized successfully, False otherwise.
59
+ */
60
+ /* ******************************************************************************/
61
+ bool begin () {
62
+ _bmp3xx = new Adafruit_BMP3XX ();
63
+ // attempt to initialize BMP3XX
64
+ if (!_bmp3xx->begin_I2C (_sensorAddress, _i2c))
65
+ return false ;
66
+
67
+ // Set up oversampling and filter initialization
68
+ _bmp3xx->setTemperatureOversampling (BMP3_OVERSAMPLING_8X);
69
+ _bmp3xx->setPressureOversampling (BMP3_OVERSAMPLING_4X);
70
+ _bmp3xx->setIIRFilterCoeff (BMP3_IIR_FILTER_COEFF_3);
71
+ _bmp3xx->setOutputDataRate (BMP3_ODR_50_HZ);
72
+
73
+ return true ;
74
+ }
75
+
76
+ /* ******************************************************************************/
77
+ /* !
78
+ @brief Gets the BMP3XX's current temperature.
79
+ @param tempEvent
80
+ Pointer to an Adafruit_Sensor event.
81
+ @returns True if the temperature was obtained successfully, False
82
+ otherwise.
83
+ */
84
+ /* ******************************************************************************/
85
+ bool getEventAmbientTemp (sensors_event_t *tempEvent) {
86
+ if (!_bmp3xx->performReading ())
87
+ return false ;
88
+ tempEvent->temperature = _bmp3xx->temperature ;
89
+ return true ;
90
+ }
91
+
92
+ /* ******************************************************************************/
93
+ /* !
94
+ @brief Reads a pressure sensor and converts
95
+ the reading into the expected SI unit.
96
+ @param pressureEvent
97
+ Pointer to an Adafruit_Sensor event.
98
+ @returns True if the sensor event was obtained successfully, False
99
+ otherwise.
100
+ */
101
+ /* ******************************************************************************/
102
+ bool getEventPressure (sensors_event_t *pressureEvent) {
103
+ if (!_bmp3xx->performReading ())
104
+ return false ;
105
+ pressureEvent->pressure = _bmp3xx->pressure / 100 .0F ;
106
+ return true ;
107
+ }
108
+
109
+ /* ******************************************************************************/
110
+ /* !
111
+ @brief Reads a the BMP3XX's altitude sensor into an event.
112
+ @param altitudeEvent
113
+ Pointer to an adafruit sensor event.
114
+ @returns True if the sensor event was obtained successfully, False
115
+ otherwise.
116
+ */
117
+ /* ******************************************************************************/
118
+ bool getEventAltitude (sensors_event_t *altitudeEvent) {
119
+ if (!_bmp3xx->performReading ())
120
+ return false ;
121
+ // TODO: update once we add an altitude sensor type
122
+ // see https://github.com/adafruit/Adafruit_Sensor/issues/52
123
+ altitudeEvent->data [0 ] = _bmp3xx->readAltitude (SEALEVELPRESSURE_HPA);
124
+ return true ;
125
+ }
126
+
127
+ protected:
128
+ Adafruit_BMP3XX *_bmp3xx; // /< BMP3XX object
129
+ };
130
+
131
+ #endif // WipperSnapper_I2C_Driver_BMP3XX
0 commit comments