🐛 Fixes barometer
This commit is contained in:
@@ -36,37 +36,33 @@ struct BarometerMsg : public SensorMessageBase {
|
|||||||
friend void toJson(JsonVariant v, BarometerMsg const& a) { a.toJson(v); }
|
friend void toJson(JsonVariant v, BarometerMsg const& a) { a.toJson(v); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Barometer {
|
class Barometer : public SensorBase<BarometerMsg> {
|
||||||
public:
|
public:
|
||||||
bool initialize() {
|
bool initialize() override {
|
||||||
bmp_success = _bmp.begin();
|
_msg.success = _bmp.begin();
|
||||||
return bmp_success;
|
return _msg.success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool readBarometer() {
|
bool update() override {
|
||||||
if (!bmp_success) return false;
|
if (!_msg.success) return false;
|
||||||
_bmp.getTemperature(&temperature);
|
_bmp.getTemperature(&_msg.temperature);
|
||||||
sensors_event_t event;
|
sensors_event_t event;
|
||||||
_bmp.getEvent(&event);
|
_bmp.getEvent(&event);
|
||||||
pressure = event.pressure;
|
_msg.pressure = event.pressure;
|
||||||
altitude = _bmp.pressureToAltitude(seaLevelPressure, pressure);
|
_msg.altitude = _bmp.pressureToAltitude(seaLevelPressure, _msg.pressure);
|
||||||
return true;
|
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:
|
private:
|
||||||
Adafruit_BMP085_Unified _bmp {10085};
|
Adafruit_BMP085_Unified _bmp {10085};
|
||||||
bool bmp_success {false};
|
|
||||||
float pressure {0};
|
|
||||||
float altitude {0};
|
|
||||||
float temperature {0};
|
|
||||||
|
|
||||||
const float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
|
const float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
|
||||||
};
|
};
|
||||||
@@ -101,7 +101,7 @@ bool Peripherals::readBMP() {
|
|||||||
bool updated = false;
|
bool updated = false;
|
||||||
#if FT_ENABLED(USE_BMP180)
|
#if FT_ENABLED(USE_BMP180)
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
updated = _bmp.readBarometer();
|
updated = _bmp.update();
|
||||||
endTransaction();
|
endTransaction();
|
||||||
#endif
|
#endif
|
||||||
return updated;
|
return updated;
|
||||||
|
|||||||
Reference in New Issue
Block a user