1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-25 17:25:20 +03:00

Introduced 'baroStartCalibration()' / 'baroSetGroundLevel()' to make barometer code more self contained.

This commit is contained in:
mikeller 2019-11-16 12:48:47 +13:00
parent dd0b45dc87
commit ef556c0f59
8 changed files with 25 additions and 15 deletions

View file

@ -48,12 +48,9 @@
#include "fc/runtime_config.h"
#include "sensors/barometer.h"
#include "sensors/sensors.h"
#ifdef USE_HARDWARE_REVISION_DETECTION
#include "hardware_revision.h"
#endif
#include "barometer.h"
baro_t baro; // barometer access functions
@ -139,6 +136,11 @@ static int32_t baroGroundAltitude = 0;
static int32_t baroGroundPressure = 8*101325;
static uint32_t baroPressureSum = 0;
#define CALIBRATING_BARO_CYCLES 200 // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles
#define SET_GROUND_LEVEL_BARO_CYCLES 10 // calibrate baro to new ground level (10 * 25 ms = ~250 ms non blocking)
static bool baroReady = false;
void baroPreInit(void)
{
#ifdef USE_SPI
@ -278,12 +280,20 @@ bool isBaroCalibrationComplete(void)
return calibratingB == 0;
}
void baroSetCalibrationCycles(uint16_t calibrationCyclesRequired)
static void baroSetCalibrationCycles(uint16_t calibrationCyclesRequired)
{
calibratingB = calibrationCyclesRequired;
}
static bool baroReady = false;
void baroStartCalibration(void)
{
baroSetCalibrationCycles(CALIBRATING_BARO_CYCLES);
}
void baroSetGroundLevel(void)
{
baroSetCalibrationCycles(SET_GROUND_LEVEL_BARO_CYCLES);
}
#define PRESSURE_SAMPLES_MEDIAN 3