gpsmagcourse: Do not recalculate in getCompass()

master
Erik Andresen 2023-02-27 20:50:51 +01:00
parent 965e60e149
commit eaf17b71cc
1 changed files with 5 additions and 6 deletions

View File

@ -7,6 +7,7 @@
}, require("Storage").readJSON("gpsmagcourse.json", true) || {}); }, require("Storage").readJSON("gpsmagcourse.json", true) || {});
const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined; const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined;
let cntAboveSpeed = 0; let cntAboveSpeed = 0;
let lastMag;
// Check if magnav is installed // Check if magnav is installed
try { try {
@ -40,13 +41,10 @@
if (settings.tiltCompensation) { if (settings.tiltCompensation) {
const origGetCompass = Bangle.getCompass; const origGetCompass = Bangle.getCompass;
Bangle.getCompass = function(argObj) { Bangle.getCompass = function(argObj) {
const mag = origGetCompass(); if (!isNaN(lastMag.heading) && (argObj === undefined || !argObj.noTiltComp)) {
if (!isNaN(mag.heading) && (argObj === undefined || !argObj.noTiltComp)) { return lastMag;
const d = require("magnav").tiltfix(mag, Bangle.getAccel());
mag.headingOrig = mag.heading;
mag.heading = d;
} }
return mag; return origGetCompass();
}; };
Bangle.on('mag', function(mag) { Bangle.on('mag', function(mag) {
@ -55,6 +53,7 @@
mag.headingOrig = mag.heading; mag.headingOrig = mag.heading;
mag.heading = d; mag.heading = d;
} }
lastMag = mag;
}); });
} // if (settings.tiltCompensation) } // if (settings.tiltCompensation)