From 1fb1f1accf9ce2089c8cc85c76e632258eabec5c Mon Sep 17 00:00:00 2001 From: Yifan Date: Thu, 12 Dec 2024 21:18:51 -0800 Subject: [PATCH] Fix calibration initialization issue in calibrate() Previously, calibrationData[3][2] was set to zeros since read() was not called before getX(), getY(), and getZ(). This caused incorrect calibration when any axis had consistently positive or negative values, resulting in max/min values being zero. This fix removes the unnecessary assignment to calibrationData[3][2], ensuring proper calibration. --- src/QMC5883LCompass.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/QMC5883LCompass.cpp b/src/QMC5883LCompass.cpp index 489fc76..f2e30cf 100644 --- a/src/QMC5883LCompass.cpp +++ b/src/QMC5883LCompass.cpp @@ -150,9 +150,7 @@ void QMC5883LCompass::setSmoothing(byte steps, bool adv){ void QMC5883LCompass::calibrate() { clearCalibration(); long calibrationData[3][2] = {{65000, -65000}, {65000, -65000}, {65000, -65000}}; - long x = calibrationData[0][0] = calibrationData[0][1] = getX(); - long y = calibrationData[1][0] = calibrationData[1][1] = getY(); - long z = calibrationData[2][0] = calibrationData[2][1] = getZ(); + long x, y, z; unsigned long startTime = millis();