mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-13 22:25:46 +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,6 +40,15 @@ int32_t BMX160Sensor::runOnce()
|
|||||||
screen->startAlert((FrameCallback)drawFrameCalibration);
|
screen->startAlert((FrameCallback)drawFrameCalibration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (firstCalibrationRead) {
|
||||||
|
highestX = magAccel.x;
|
||||||
|
lowestX = magAccel.x;
|
||||||
|
highestY = magAccel.y;
|
||||||
|
lowestY = magAccel.y;
|
||||||
|
highestZ = magAccel.z;
|
||||||
|
lowestZ = magAccel.z;
|
||||||
|
firstCalibrationRead = false;
|
||||||
|
} else {
|
||||||
if (magAccel.x > highestX)
|
if (magAccel.x > highestX)
|
||||||
highestX = magAccel.x;
|
highestX = magAccel.x;
|
||||||
if (magAccel.x < lowestX)
|
if (magAccel.x < lowestX)
|
||||||
@ -52,6 +61,7 @@ int32_t BMX160Sensor::runOnce()
|
|||||||
highestZ = magAccel.z;
|
highestZ = magAccel.z;
|
||||||
if (magAccel.z < lowestZ)
|
if (magAccel.z < lowestZ)
|
||||||
lowestZ = magAccel.z;
|
lowestZ = magAccel.z;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if (now > endCalibrationAt) {
|
if (now > endCalibrationAt) {
|
||||||
@ -116,6 +126,7 @@ void BMX160Sensor::calibrate(uint16_t forSeconds)
|
|||||||
LOG_DEBUG("BMX160 calibration started for %is", forSeconds);
|
LOG_DEBUG("BMX160 calibration started for %is", forSeconds);
|
||||||
|
|
||||||
doCalibration = true;
|
doCalibration = true;
|
||||||
|
firstCalibrationRead = true;
|
||||||
uint16_t calibrateFor = forSeconds * 1000; // calibrate for seconds provided
|
uint16_t calibrateFor = forSeconds * 1000; // calibrate for seconds provided
|
||||||
endCalibrationAt = millis() + calibrateFor;
|
endCalibrationAt = millis() + calibrateFor;
|
||||||
screen->setEndCalibration(endCalibrationAt);
|
screen->setEndCalibration(endCalibrationAt);
|
||||||
|
@ -58,6 +58,7 @@ class MotionSensor
|
|||||||
|
|
||||||
// Do calibration if true
|
// Do calibration if true
|
||||||
bool doCalibration = false;
|
bool doCalibration = false;
|
||||||
|
bool firstCalibrationRead = false;
|
||||||
uint32_t endCalibrationAt = 0;
|
uint32_t endCalibrationAt = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user