Skip to content

Commit c45810e

Browse files
committed
Add function to retrieve barometric pressure
Introduced getBaroPressure() to obtain pressure in hPa from the BMP sensor. Updated header and implementation files to support pressure readings alongside temperature.
1 parent 38e144f commit c45810e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

inc/sp140/altimeter.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ float getVerticalSpeed();
2222
// Set the ground altitude to the current altitude to compute AGL
2323
void setGroundAltitude(const STR_DEVICE_DATA_140_V1& deviceData);
2424

25-
// Get the temperature in degrees Celsius
26-
float getBaroTemperature();
27-
28-
#endif // INC_SP140_ALTIMETER_H_
25+
// Get the temperature in degrees Celsius
26+
float getBaroTemperature();
27+
28+
// Get the pressure in hPa
29+
float getBaroPressure();
30+
31+
#endif // INC_SP140_ALTIMETER_H_

src/sp140/altimeter.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Adafruit_BMP3XX bmp;
77
bool bmpPresent = false;
88
float groundAltitude = 0;
99

10-
// Buffer to store altitude readings with timestamps
1110
struct AltitudeReading {
1211
float altitude;
1312
unsigned long timestamp;
1413
};
1514

15+
// Buffer to store altitude readings with timestamps
1616
CircularBuffer<AltitudeReading, VARIO_BUFFER_SIZE> altitudeBuffer;
1717

1818
float getAltitude(const STR_DEVICE_DATA_140_V1& deviceData) {
@@ -67,6 +67,14 @@ float getBaroTemperature() {
6767
return __FLT_MIN__; // Return a very small number if BMP is not present
6868
}
6969

70+
// Get the pressure in hPa
71+
float getBaroPressure() {
72+
if (bmpPresent) {
73+
return bmp.readPressure() / 100.0f; // Convert Pa to hPa
74+
}
75+
return __FLT_MIN__; // Return a very small number if BMP is not present
76+
}
77+
7078
// Start the bmp3XX sensor
7179
bool setupAltimeter(bool altWire) {
7280
TwoWire* wire = &Wire;

0 commit comments

Comments
 (0)