mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-12 14:05:58 +00:00
Improve compass calibration method
- initiate calibration with first read values to account for min values > 0
This commit is contained in:
parent
686f569540
commit
148ceac296
@ -40,18 +40,28 @@ int32_t BMX160Sensor::runOnce()
|
||||
screen->startAlert((FrameCallback)drawFrameCalibration);
|
||||
}
|
||||
|
||||
if (magAccel.x > highestX)
|
||||
if (firstCalibrationRead) {
|
||||
highestX = magAccel.x;
|
||||
if (magAccel.x < lowestX)
|
||||
lowestX = magAccel.x;
|
||||
if (magAccel.y > highestY)
|
||||
highestY = magAccel.y;
|
||||
if (magAccel.y < lowestY)
|
||||
lowestY = magAccel.y;
|
||||
if (magAccel.z > highestZ)
|
||||
highestZ = magAccel.z;
|
||||
if (magAccel.z < lowestZ)
|
||||
lowestZ = magAccel.z;
|
||||
firstCalibrationRead = false;
|
||||
} else {
|
||||
if (magAccel.x > highestX)
|
||||
highestX = magAccel.x;
|
||||
if (magAccel.x < lowestX)
|
||||
lowestX = magAccel.x;
|
||||
if (magAccel.y > highestY)
|
||||
highestY = magAccel.y;
|
||||
if (magAccel.y < lowestY)
|
||||
lowestY = magAccel.y;
|
||||
if (magAccel.z > highestZ)
|
||||
highestZ = magAccel.z;
|
||||
if (magAccel.z < lowestZ)
|
||||
lowestZ = magAccel.z;
|
||||
}
|
||||
|
||||
uint32_t now = millis();
|
||||
if (now > endCalibrationAt) {
|
||||
@ -116,6 +126,7 @@ void BMX160Sensor::calibrate(uint16_t forSeconds)
|
||||
LOG_DEBUG("BMX160 calibration started for %is", forSeconds);
|
||||
|
||||
doCalibration = true;
|
||||
firstCalibrationRead = true;
|
||||
uint16_t calibrateFor = forSeconds * 1000; // calibrate for seconds provided
|
||||
endCalibrationAt = millis() + calibrateFor;
|
||||
screen->setEndCalibration(endCalibrationAt);
|
||||
|
@ -58,6 +58,7 @@ class MotionSensor
|
||||
|
||||
// Do calibration if true
|
||||
bool doCalibration = false;
|
||||
bool firstCalibrationRead = false;
|
||||
uint32_t endCalibrationAt = 0;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user