From ea4e3eb6e69d3144d4d49468035760efef32d64c Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Sat, 30 Mar 2024 16:10:03 +0100 Subject: [PATCH] Fix compass calibration interval timeout --- src/js/tabs/setup.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/js/tabs/setup.js b/src/js/tabs/setup.js index 3bdde312c77..017821b3ce0 100644 --- a/src/js/tabs/setup.js +++ b/src/js/tabs/setup.js @@ -145,12 +145,32 @@ setup.initialize = function (callback) { $('#mag_calib_rest').hide(); }); - GUI.timeout_add('button_reset', function () { - gui_log(i18n.getMessage('initialSetupMagCalibEnded')); - _self.removeClass('calibrating'); - $('#mag_calib_running').hide(); - $('#mag_calib_rest').show(); - }, 30000); + function isCalibrationRunning() { + return FC.CONFIG.armingDisableFlags & (1 << 12) ? true : false; + } + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { + let cycle = 0; + const cycleMax = 45; + const interval = 1000; + const intervalId = setInterval(function () { + if (cycle >= cycleMax || !isCalibrationRunning()) { + clearInterval(intervalId); + gui_log(i18n.getMessage('initialSetupMagCalibEnded')); + _self.removeClass('calibrating'); + $('#mag_calib_running').hide(); + $('#mag_calib_rest').show(); + } + cycle++; + }, interval); + } else { + GUI.timeout_add('button_reset', function () { + gui_log(i18n.getMessage('initialSetupMagCalibEnded')); + _self.removeClass('calibrating'); + $('#mag_calib_running').hide(); + $('#mag_calib_rest').show(); + }, 30000); + } } });