firmware: add persistent level calibration

This commit is contained in:
2026-07-17 02:37:49 -06:00
parent fb2ca464b9
commit 4f96902068
9 changed files with 212 additions and 9 deletions
@@ -0,0 +1,26 @@
#pragma once
#include "sensor_state.h"
struct LevelCalibrationState {
bool valid = false;
bool active = false;
float pitchOffsetDegrees = 0;
float rollOffsetDegrees = 0;
unsigned long startedMs = 0;
unsigned long lastSampleMs = 0;
uint32_t sampleCount = 0;
float pitchSum = 0;
float rollSinSum = 0;
float rollCosSum = 0;
float firstPitch = 0;
float firstRoll = 0;
};
extern LevelCalibrationState levelCalibration;
void initLevelCalibration();
bool startLevelCalibration(const ImuState& imu);
bool updateLevelCalibration(const ImuState& imu, String& result);
void clearLevelCalibration();
float calibratedPitchDegrees(const ImuState& imu);
float calibratedRollDegrees(const ImuState& imu);