From 06d457f4e5cb3ed3ed6ac17da749b6846c88cef0 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 4 Nov 2025 20:03:07 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixes=20barometer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp32/include/peripherals/barometer.h | 30 ++++++++++++--------------- esp32/src/peripherals/peripherals.cpp | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/esp32/include/peripherals/barometer.h b/esp32/include/peripherals/barometer.h index 796bd86..5a67232 100644 --- a/esp32/include/peripherals/barometer.h +++ b/esp32/include/peripherals/barometer.h @@ -36,37 +36,33 @@ struct BarometerMsg : public SensorMessageBase { friend void toJson(JsonVariant v, BarometerMsg const& a) { a.toJson(v); } }; -class Barometer { +class Barometer : public SensorBase { public: - bool initialize() { - bmp_success = _bmp.begin(); - return bmp_success; + bool initialize() override { + _msg.success = _bmp.begin(); + return _msg.success; } - bool readBarometer() { - if (!bmp_success) return false; - _bmp.getTemperature(&temperature); + bool update() override { + if (!_msg.success) return false; + _bmp.getTemperature(&_msg.temperature); sensors_event_t event; _bmp.getEvent(&event); - pressure = event.pressure; - altitude = _bmp.pressureToAltitude(seaLevelPressure, pressure); + _msg.pressure = event.pressure; + _msg.altitude = _bmp.pressureToAltitude(seaLevelPressure, _msg.pressure); return true; } - float getPressure() { return pressure; } + float getPressure() { return _msg.pressure; } - float getAltitude() { return altitude; } + float getAltitude() { return _msg.altitude; } - float getTemperature() { return temperature; } + float getTemperature() { return _msg.temperature; } - bool active() { return bmp_success; } + bool active() { return _msg.success; } private: Adafruit_BMP085_Unified _bmp {10085}; - bool bmp_success {false}; - float pressure {0}; - float altitude {0}; - float temperature {0}; const float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; }; \ No newline at end of file diff --git a/esp32/src/peripherals/peripherals.cpp b/esp32/src/peripherals/peripherals.cpp index c69d101..3048d8d 100644 --- a/esp32/src/peripherals/peripherals.cpp +++ b/esp32/src/peripherals/peripherals.cpp @@ -101,7 +101,7 @@ bool Peripherals::readBMP() { bool updated = false; #if FT_ENABLED(USE_BMP180) beginTransaction(); - updated = _bmp.readBarometer(); + updated = _bmp.update(); endTransaction(); #endif return updated;