16
16
#ifndef WipperSnapper_I2C_Driver_BMP5XX_H
17
17
#define WipperSnapper_I2C_Driver_BMP5XX_H
18
18
19
- #include " WipperSnapper_I2C_Driver.h"
20
19
#include < Adafruit_BMP5XX.h>
21
20
22
- #define SEALEVELPRESSURE_HPA (1013.25 ) // /< Default sea level pressure, in hPa
21
+ #include " WipperSnapper_I2C_Driver.h"
22
+
23
+ #define SEALEVELPRESSURE_HPA (1013.25 ) // /< Default sea level pressure, in hPa
23
24
24
25
/* *************************************************************************/
25
26
/* !
28
29
*/
29
30
/* *************************************************************************/
30
31
class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver {
31
-
32
- public:
32
+ public:
33
33
/* ******************************************************************************/
34
34
/* !
35
35
@brief Constructor for an BMP5XX sensor.
@@ -49,9 +49,9 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver {
49
49
@brief Destructor for an BMP5XX sensor.
50
50
*/
51
51
/* ******************************************************************************/
52
- ~WipperSnapper_I2C_Driver_BMP5XX () {
52
+ ~WipperSnapper_I2C_Driver_BMP5XX () {
53
53
if (_bmp5xx) {
54
- delete _bmp5xx;
54
+ delete _bmp5xx;
55
55
_bmp5xx = nullptr ;
56
56
}
57
57
}
@@ -64,8 +64,11 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver {
64
64
/* ******************************************************************************/
65
65
bool begin () {
66
66
_bmp5xx = new Adafruit_BMP5xx ();
67
- if (!_bmp5xx->begin (_sensorAddress, _i2c))
67
+ if (!_bmp5xx->begin (_sensorAddress, _i2c)) {
68
+ delete _bmp5xx;
69
+ _bmp5xx = nullptr ;
68
70
return false ;
71
+ }
69
72
70
73
// Set up oversampling and filter initialization
71
74
_bmp5xx->setTemperatureOversampling (BMP5XX_OVERSAMPLING_8X);
@@ -86,8 +89,9 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver {
86
89
*/
87
90
/* ******************************************************************************/
88
91
bool getEventAmbientTemp (sensors_event_t *tempEvent) {
89
- if (!_bmp5xx->performReading ())
92
+ if (!_bmp5xx->performReading ()) {
90
93
return false ;
94
+ }
91
95
tempEvent->temperature = _bmp5xx->temperature ;
92
96
return true ;
93
97
}
@@ -103,9 +107,10 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver {
103
107
*/
104
108
/* ******************************************************************************/
105
109
bool getEventPressure (sensors_event_t *pressureEvent) {
106
- if (!_bmp5xx->performReading ())
110
+ if (!_bmp5xx->performReading ()) {
107
111
return false ;
108
- pressureEvent->pressure = _bmp5xx->pressure / 10 .0F ;
112
+ }
113
+ pressureEvent->pressure = _bmp5xx->pressure ;
109
114
return true ;
110
115
}
111
116
@@ -119,14 +124,15 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver {
119
124
*/
120
125
/* ******************************************************************************/
121
126
bool getEventAltitude (sensors_event_t *altitudeEvent) {
122
- if (!_bmp5xx->performReading ())
127
+ if (!_bmp5xx->performReading ()) {
123
128
return false ;
129
+ }
124
130
altitudeEvent->altitude = _bmp5xx->readAltitude (SEALEVELPRESSURE_HPA);
125
131
return true ;
126
132
}
127
133
128
- protected:
129
- Adafruit_BMP5xx *_bmp5xx; // /< BMP5xx object
134
+ protected:
135
+ Adafruit_BMP5xx *_bmp5xx; // /< BMP5xx object
130
136
};
131
137
132
- #endif // WipperSnapper_I2C_Driver_BMP5XX
138
+ #endif // WipperSnapper_I2C_Driver_BMP5XX
0 commit comments