All modules and core of the app was created
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
#include "Sensors.hpp"
|
||||
|
||||
Sensors::Sensors(Barometer &barometer, MPU &mpu, Kalman2DFilter &filter, BatteryController &battery, bool loop_on_fail) {
|
||||
_barometer = &barometer;
|
||||
_mpu = &mpu;
|
||||
_2d_filter = &filter;
|
||||
_battery = &battery;
|
||||
Sensors::Sensors(Barometer *barometer, MPU *mpu, Kalman2DFilter *filter, BatteryController *battery, bool loop_on_fail) {
|
||||
assert(barometer != nullptr);
|
||||
assert(mpu != nullptr);
|
||||
assert(filter != nullptr);
|
||||
assert(battery != nullptr);
|
||||
|
||||
_barometer = barometer;
|
||||
_mpu = mpu;
|
||||
_2d_filter = filter;
|
||||
_battery = battery;
|
||||
|
||||
ESP_LOGI(_tag, "Initialize BMP280...");
|
||||
if (_barometer->initialize()) {
|
||||
@@ -44,12 +49,12 @@ void Sensors::measureBaseAltitudeAsync(void) {
|
||||
_barometer->measureBaseAltitudeAsync();
|
||||
}
|
||||
|
||||
float Sensors::rawFlightHeight(void) {
|
||||
float Sensors::rawFlightHeight(void) const {
|
||||
/* Returns flight height from barometer immediatly */
|
||||
return _barometer->flightHeight();
|
||||
}
|
||||
|
||||
float Sensors::flightHeight(void) {
|
||||
float Sensors::flightHeight(void) const {
|
||||
/* Returns flight height from cache immediatly */
|
||||
if (_flightHeightFromBarometer == NAN) {
|
||||
ESP_LOGW(_tag, "flightHeight called, but tick() has called never");
|
||||
@@ -59,8 +64,8 @@ float Sensors::flightHeight(void) {
|
||||
}
|
||||
}
|
||||
|
||||
MpuData Sensors::mpuData() {
|
||||
if (_mpuData.ax == NAN and _mpuData.gravityZ == NAN) {
|
||||
MpuData Sensors::mpuData() const {
|
||||
if (_mpuData.ax == NAN and _mpuData.gravity == NAN) {
|
||||
ESP_LOGW(_tag, "MPU data looks like .tick() has never called");
|
||||
}
|
||||
return _mpuData;
|
||||
@@ -69,6 +74,7 @@ MpuData Sensors::mpuData() {
|
||||
bool Sensors::tick(void) {
|
||||
/* Super loop iteraion */
|
||||
/* Return true on update */
|
||||
_barometer->tick();
|
||||
bool err;
|
||||
bool isMpuDataReady = _mpu->tick(err);
|
||||
if (isMpuDataReady and !err) {
|
||||
@@ -82,7 +88,8 @@ bool Sensors::tick(void) {
|
||||
.yaw = _mpu->yaw(),
|
||||
.pitch = _mpu->pitch(),
|
||||
.roll = _mpu->roll(),
|
||||
.gravityZ = _mpu->gravityZ() };
|
||||
.gravity = _mpu->gravityZ(),
|
||||
.zInertial = _mpu->accZInertial() };
|
||||
return true;
|
||||
} else if (err) {
|
||||
ESP_LOGE(_tag, "Failed to get DMP data!");
|
||||
@@ -90,6 +97,18 @@ bool Sensors::tick(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int Sensors::batteryCharge(void) {
|
||||
int Sensors::batteryCharge(void) const {
|
||||
return _battery->percent();
|
||||
}
|
||||
|
||||
void Sensors::onMpuCalibrationFinished(OnCalibrationFinishedCb callback) {
|
||||
_mpu->onCalibrationFinished(callback);
|
||||
}
|
||||
|
||||
void Sensors::startMpuCalibration() {
|
||||
_mpu->startCalibration();
|
||||
}
|
||||
|
||||
void Sensors::onMeasuaringAltitudeFinished(OnMeasuringFinishedCb callback) {
|
||||
_barometer->onMeasuaringHeightFinished(callback);
|
||||
}
|
||||
Reference in New Issue
Block a user