From cc57c42a17d44016834cd749a5fe4aba0f10b2b5 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 16 Feb 2023 19:05:45 +0100 Subject: [PATCH 01/25] magnav Add tiltfix() for compensation on given sensor values --- apps/magnav/ChangeLog | 1 + apps/magnav/lib.js | 16 +++++++++++----- apps/magnav/metadata.json | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/magnav/ChangeLog b/apps/magnav/ChangeLog index 14a6eb2a2..7b548841a 100644 --- a/apps/magnav/ChangeLog +++ b/apps/magnav/ChangeLog @@ -4,3 +4,4 @@ 0.04: Fix Font size 0.05: Initial portable version 0.06: Outsource tilt compensation to library +0.07: Add tiltfix() for compensation on given sensor values diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js index e3fe8fccb..39c51a1e1 100644 --- a/apps/magnav/lib.js +++ b/apps/magnav/lib.js @@ -22,11 +22,10 @@ exports.calibrate = () => { }); } -exports.tiltfixread = (O,S) => { - "ram" - var m = Bangle.getCompass(); - var g = Bangle.getAccel(); - m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; +exports.tiltfix = (m,g,O,S) => { + if (O & S) { + m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; + } var d = Math.atan2(-m.dx,m.dy)*180/Math.PI; if (d<0) d+=360; var phi = Math.atan(-g.x/-g.z); @@ -39,3 +38,10 @@ exports.tiltfixread = (O,S) => { if (psi<0) psi+=360; return psi; } + +exports.tiltfixread = (O,S) => { + "ram" + var m = Bangle.getCompass({noTiltComp: true}); + var g = Bangle.getAccel(); + return exports.tiltfix(m,g,O,S); +} diff --git a/apps/magnav/metadata.json b/apps/magnav/metadata.json index bd40a08fd..6bdb9d0b6 100644 --- a/apps/magnav/metadata.json +++ b/apps/magnav/metadata.json @@ -1,7 +1,7 @@ { "id": "magnav", "name": "Navigation Compass", - "version": "0.06", + "version": "0.07", "description": "Compass with linear display as for GPSNAV. Has Tilt compensation and remembers calibration.", "screenshots": [{"url":"screenshot-b2.png"},{"url":"screenshot-light-b2.png"}], "icon": "magnav.png", From f1ce35362e5eae3f3c3fcef059ef133459846ee9 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 16 Feb 2023 19:07:59 +0100 Subject: [PATCH 02/25] Adding gpsmagdir bootloader modification Replace GPS heading with compass heading when speed is slow or standing still to avoid the heading from jumping around randomly --- apps/gpsmagdir/README.md | 12 ++++++ apps/gpsmagdir/app.png | Bin 0 -> 1224 bytes apps/gpsmagdir/boot.js | 81 +++++++++++++++++++++++++++++++++++ apps/gpsmagdir/metadata.json | 17 ++++++++ 4 files changed, 110 insertions(+) create mode 100644 apps/gpsmagdir/README.md create mode 100644 apps/gpsmagdir/app.png create mode 100644 apps/gpsmagdir/boot.js create mode 100644 apps/gpsmagdir/metadata.json diff --git a/apps/gpsmagdir/README.md b/apps/gpsmagdir/README.md new file mode 100644 index 000000000..b4c3acf0c --- /dev/null +++ b/apps/gpsmagdir/README.md @@ -0,0 +1,12 @@ +TODO: +- Add Widget +- Add Settings +- Test on BangleJS +- Document settings with defaults +- Document Widget +- Write a summary why +- Drop a note about compass north vs true north +- Note that top of Bangle must point at moving direction when compass +- Document uncompensated compass only when clock is faced up +- Note to regularly calibrate compass before use +- Note compass value not when NaN after calibration diff --git a/apps/gpsmagdir/app.png b/apps/gpsmagdir/app.png new file mode 100644 index 0000000000000000000000000000000000000000..c7e990268e5962927ee471d37fadf9771a4cca2f GIT binary patch literal 1224 zcmV;(1ULJMP)cO9wm>?PxZ;CM{L|NFa>cvE}i;JKF;-c}&k9r^;Tz02kbJ*pX z>Yl-#>Y8Pyw|iXTd`TU4`t_^tdsY4F)mwlrx>&p*2KSQ(>)=WSd9a&2_yn#*PytpG zgMb)ZpaRDfmXnX!p%^>|5EAN$X^mu0Y#D?Ba~Qhji#-w1W}!{!+I zX!OAo=9#gHzatbL6DoMPW5fr?Xc<@fHLmnrBN09O+-PunD1gB?2>~8_ZJt$zvB%gp zyesuZq42$dJ#=-h26 z=Oe*`bvs%QE6IcNO$B%`P3z#gx_wCo4{?QmxK_frM6tTawuC)at=d%K|*u z>+(_dv5?qGe)ZAx0+jyNTGr2<Md;x z5DK?gAMRl%`A1+md2p^q?8JQaKdpy*iNOyw0e?{eR=Di!l+7hRlR|*rZ8>?xNy>vF zd7z2GOQwjsoL>T1N(?IDdC>=3oO4Tj)e7FnZ3{?5A$DLj5Q@s?Tif+--XR7%nx*bm zRzHE>4`-;A0Xd;}q4ReIED*i_`xS^oNc<`OA(;;gI)suRY_M-_Z95TCe`eL`gSoJE zKq&pXm4!Zqb|IABX5F|>K!?C3o@^9QEw}9?yfs;+#8&^pow+cM!IUeBQeqf;Ae&+i zomFI(5E6&2?K76z8J9RD2tUS%IcZ~`KbEc3E8$) zl9LFfPdAHFD+O3NTHVHN6WzilGVjuvj&kCH|LAQuFyeZgOTBr)c|I$YB;F>Zu9(Wvl)nxE$D(J|a_ZWq mljzhvIyZC$bkPNL1pff@&jb*6-b};*0000 0) { + const isFaceUp = (acc) => { + return (acc.z<-6700/8192) && (acc.z>-9000/8192) && Math.abs(acc.x)<2048/8192 && Math.abs(acc.y)<2048/8192; + }; + + const changeGpsCourse = (gps) => { + if (gps.speed < settings.speed) { + if (settings.compassSrc === 1 && (settings.tiltCompensation || isFaceUp(Bangle.getAccel()))) { // Use uncompensated firmware heading only if face is up + const heading = Bangle.getCompass().heading; + if (!isNaN(heading)) { + gps.courseOrig = gps.course; + gps.course = Bangle.getCompass().heading; + } + } else if (settings.compassSrc === 2) { // magnav tilt correction with magnav calibration + gps.courseOrig = gps.course; + gps.course = require("magnav").tiltfixread(CALIBDATA.offset,CALIBDATA.scale); + } + } + return gps; + }; + + // Modify GPS event + Bangle.on('GPS', gps => { + changeGpsCourse(gps); + }); + const origGetGPSFix = Bangle.getGPSFix; + Bangle.getGPSFix = function() { + return changeGpsCourse(origGetGPSFix()); + }; + + // Enable Compass with GPS + const origSetGPSPower = Bangle.setGPSPower; + Bangle.setGPSPower = function(on, id) { + const isGPSon = origSetGPSPower(on, id); + Bangle.setCompassPower(isGPSon, "gpsmagdir"); + return isGPSon; + }; + } // if (settings.compassSrc > 0) +} diff --git a/apps/gpsmagdir/metadata.json b/apps/gpsmagdir/metadata.json new file mode 100644 index 000000000..ebff8f7c9 --- /dev/null +++ b/apps/gpsmagdir/metadata.json @@ -0,0 +1,17 @@ +{ + "id": "gpsmagdir", + "name": "GPS Compass heading switcher", + "shortName":"GPS/Compass direction", + "icon": "app.png", + "version":"0.01", + "description": "Replace GPS heading with compass heading when speed is slow or standing still to avoid the heading from jumping around randomly.", + "type": "bootloader", + "tags": "outdoors", + "supports": ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"gpsmagdir.boot.js","url":"boot.js"} + ], + "data": [{"name":"gpsmagdir.json"}] +} + From 742bcdddabfabfabb5c2fc9b0ce010010e703747 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 16 Feb 2023 19:19:01 +0100 Subject: [PATCH 03/25] magnav Add tiltfix() for compensation on given sensor values --- apps/magnav/lib.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js index 39c51a1e1..fe58615cb 100644 --- a/apps/magnav/lib.js +++ b/apps/magnav/lib.js @@ -23,6 +23,7 @@ exports.calibrate = () => { } exports.tiltfix = (m,g,O,S) => { + "ram" if (O & S) { m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; } From 0b263219750f323f286f3c2ba61aedacf4789b75 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Fri, 17 Feb 2023 18:11:12 +0100 Subject: [PATCH 04/25] gpsmagdir: Add widget --- apps/gpsmagdir/metadata.json | 5 ++- apps/gpsmagdir/widget.js | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 apps/gpsmagdir/widget.js diff --git a/apps/gpsmagdir/metadata.json b/apps/gpsmagdir/metadata.json index ebff8f7c9..f83f1ee90 100644 --- a/apps/gpsmagdir/metadata.json +++ b/apps/gpsmagdir/metadata.json @@ -6,11 +6,12 @@ "version":"0.01", "description": "Replace GPS heading with compass heading when speed is slow or standing still to avoid the heading from jumping around randomly.", "type": "bootloader", - "tags": "outdoors", + "tags": "outdoors,widget", "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "storage": [ - {"name":"gpsmagdir.boot.js","url":"boot.js"} + {"name":"gpsmagdir.boot.js","url":"boot.js"}, + {"name":"gpsmagdir.wid.js","url":"widget.js"} ], "data": [{"name":"gpsmagdir.json"}] } diff --git a/apps/gpsmagdir/widget.js b/apps/gpsmagdir/widget.js new file mode 100644 index 000000000..cf3c9c60c --- /dev/null +++ b/apps/gpsmagdir/widget.js @@ -0,0 +1,80 @@ +(() => { + const settings = Object.assign({ + compassSrc: 1, // 0 = off + showWidget: 2, // 0 = never, 1 = when replacing GPS course with compass course, 2 = when GPS is on + }, require("Storage").readJSON("gpsmagdir.json", true) || {}); + + function isInside(rect, e) { + return e.x>=rect.x && e.x=rect.y && e.y<=rect.y+rect.h; + } + + function draw() { + if (this.width) { + g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23); + + if (this.show) { + this.width = 24; + g.reset(); + g.drawImage(require("heatshrink").decompress(atob("jEYwgrohEN6EwBQ+DBYM4wALFxGA7vdB4IWFxEABYMAnAlECwMNBYPQCIQLDgALDDAI5EBYIFBBYIeBBYRBGA4QnBCAZBDA4ILLEZYLMKYR9FAgaKFNYpgCD4RBFAwQLBCwpOELAwACgeIwbLHK5ILPAAwA=")), this.x, this.y); + if (this.show === 2) { + // draw stroke + g.setColor(1,0,0).fillPoly([this.x+2, 0, + this.x+this.width-1,this.y+21, + this.x+this.width-3, this.y+23, + this.x, 2 + ]); + } + } + } + + const newWidth = this.show ? 24 : 0; + if (newWidth !== this.width) { + this.width = newWidth; + Bangle.drawWidgets(); + } + } + + if (settings.compassSrc > 0 && settings.showWidget > 0) { + // add your widget + WIDGETS.gpsmagdir={ + area:"tr", // tl (top left), tr (top right), bl (bottom left), br (bottom right) + width: 0, // hide by default + draw:draw, + show:0 // 0 = hide, 1 = show, 2 = with stroke + }; + + // show only when GPS course is replaced + Bangle.on('GPS', function(gps) { + if (gps.courseOrig && WIDGETS.gpsmagdir.show !== 1 && Bangle.isGPSOn()) { + WIDGETS.gpsmagdir.show = 1; + WIDGETS.gpsmagdir.draw(); + } else if (WIDGETS.gpsmagdir.show) { + WIDGETS.gpsmagdir.show = settings.showWidget === 1 ? 0 : 2; + WIDGETS.gpsmagdir.draw(); + } + }); + + // hide widget if GPS is turned off + const origSetGPSPower = Bangle.setGPSPower; + Bangle.setGPSPower = function(on, id) { + const isGPSon = origSetGPSPower(on, id); + if (!isGPSon && WIDGETS.gpsmagdir.show) { + WIDGETS.gpsmagdir.show = 0; + WIDGETS.gpsmagdir.draw(); + } else if (isGPSon && !WIDGETS.gpsmagdir.show) { + WIDGETS.gpsmagdir.show = 2; + WIDGETS.gpsmagdir.draw(); + } + return isGPSon; + }; + + // reset compass on click on widget + Bangle.on('touch', function(button, touch) { + if (WIDGETS.gpsmagdir && WIDGETS.gpsmagdir.x && WIDGETS.gpsmagdir.width && isInside({x: WIDGETS.gpsmagdir.x, y: WIDGETS.gpsmagdir.y, w: WIDGETS.gpsmagdir.width, h: 24}, touch)) { + Bangle.buzz(50); + Bangle.resetCompass(); + } + }); + } // if (settings.compassSrc > 0 && settings.showWidget) +})(); From 78302ecd4dd506be2a066284c577dc9bbd09d5a3 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Fri, 17 Feb 2023 18:22:57 +0100 Subject: [PATCH 05/25] gpsmagdir boot: magnav check --- apps/gpsmagdir/boot.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/gpsmagdir/boot.js b/apps/gpsmagdir/boot.js index 94daf88ca..b8a58f371 100644 --- a/apps/gpsmagdir/boot.js +++ b/apps/gpsmagdir/boot.js @@ -7,6 +7,19 @@ }, require("Storage").readJSON("gpsmagdir.json", true) || {}); const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) || {} : undefined; + // Check if magnav is installed + try { + require("magnav"); + } catch(err) { + // not installed, adjust settings to work without magnav + if (settings.compassSrc === 2) { + settings.compassSrc = 1; + } + if (settings.tiltCompensation) { + settings.tiltCompensation = false; + } + } + // execute Bangle.resetCompass() after Bangle.setCompassPower(); if (settings.resetCompassOnPwr) { const origSetCompassPower = Bangle.setCompassPower; From 4b4057764f390541a147835d4e830831afca2f45 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Fri, 17 Feb 2023 18:35:14 +0100 Subject: [PATCH 06/25] gpsmagdir: check for magnav calibration --- apps/gpsmagdir/boot.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/gpsmagdir/boot.js b/apps/gpsmagdir/boot.js index b8a58f371..2ccdb4290 100644 --- a/apps/gpsmagdir/boot.js +++ b/apps/gpsmagdir/boot.js @@ -5,7 +5,7 @@ resetCompassOnPwr: true, // reset compass on power on tiltCompensation: true, // tilt compensation on default compass }, require("Storage").readJSON("gpsmagdir.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; // Check if magnav is installed try { @@ -19,6 +19,10 @@ settings.tiltCompensation = false; } } + if (settings.compassSrc === 2 && !CALIBDATA) { + // No calibration for magnav, fallback to default compass + settings.compassSrc = 1; + } // execute Bangle.resetCompass() after Bangle.setCompassPower(); if (settings.resetCompassOnPwr) { From 8b6fcced6616aa1798f84fbfa6207b405190ea22 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 19 Feb 2023 11:13:41 +0100 Subject: [PATCH 07/25] gpsmagdir: Readme updates --- apps/gpsmagdir/README.md | 57 +++++++++++++++++++++++++++++++++------- apps/gpsmagdir/boot.js | 6 ++--- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/apps/gpsmagdir/README.md b/apps/gpsmagdir/README.md index b4c3acf0c..de7526ccd 100644 --- a/apps/gpsmagdir/README.md +++ b/apps/gpsmagdir/README.md @@ -1,12 +1,49 @@ -TODO: -- Add Widget +# GPS Compass heading switcher +The GPS course and speed is calculated by the difference of positions. +However GPS position is noisy and prone to jump around. +This results in randomly jumping GPS course values when speed is slow or standing still. +So in these cases a user might want to get his moving direction from a compass instead. +This is why this app replaces the GPS heading with the compass heading when the speed is slower then 6 km/h (threshold is configurable, see settings). + +## Important Notes +* **Watch orientation** + When the GPS is calculating the course the orientation of the watch does not matter. + When the Compass is used as the source of the current heading its top must obviously point at the moving direction (Usually away from you). +* **Tilt compensation** + When "Navigation Compass" is installed the built-in compass gets automatic tilt compensation. This can be turned off in settings. Without "Navigation Compass" installed or this feature disabled the watch must be orientated with the display up to provide a useable compass value. +* **Compass reset and calibration** + When using "Navigation Compass" as compass source (see settings) please remember to calibrate it regularly. + With this app installed the built-in compass calibration is automatically reset when the compass is turned on (deactivatable in settings). It can also be reset with a tap on the Widget (Bangle.js 2 only). Please note that directly after a reset the built-in compass must be turned 360 degrees to provide a useable value. +* **True north vs magnetic north** + Please note that the compass does not point to the "real north" but depending on your location there is an offset, see [Magnetic declination](https://en.wikipedia.org/wiki/Magnetic_declination) + However the error from local magnetic interference and from calibration will probably be higher.. + +## Widget +The widget indicates if the current GPS heading is provided from GPS or compass. +It can be turned off in the settings. +On Bangle.js 2 a click on the widget does reset the built-in compass. + +## Settings +* **speed** + - (default = 6 km/h) When lower then this use direction from compass +* **compassSrc** + - off: + - built-in (default): + - Navigation Compass: +* **reset compass on power on** + - off: + - on (default): +* **tilt compensation** + - off: + - on (default): +* **show Widget** + - Never + - Active (default): When replacing GPS course with compass course + - GPS on + +## TODO: - Add Settings -- Test on BangleJS - Document settings with defaults -- Document Widget -- Write a summary why -- Drop a note about compass north vs true north -- Note that top of Bangle must point at moving direction when compass -- Document uncompensated compass only when clock is faced up -- Note to regularly calibrate compass before use -- Note compass value not when NaN after calibration +- Check magnav dependency in settings +- note magnav silently downgrade +- Test on BangleJS diff --git a/apps/gpsmagdir/boot.js b/apps/gpsmagdir/boot.js index 2ccdb4290..2195a8424 100644 --- a/apps/gpsmagdir/boot.js +++ b/apps/gpsmagdir/boot.js @@ -1,9 +1,9 @@ { const settings = Object.assign({ speed: 6, // when lower then this use direction from compass - compassSrc: 1, // [off, firmware, magnav] + compassSrc: 1, // [off, built-in, magnav] resetCompassOnPwr: true, // reset compass on power on - tiltCompensation: true, // tilt compensation on default compass + tiltCompensation: true, // tilt compensation on built-in compass }, require("Storage").readJSON("gpsmagdir.json", true) || {}); const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined; @@ -64,7 +64,7 @@ const changeGpsCourse = (gps) => { if (gps.speed < settings.speed) { - if (settings.compassSrc === 1 && (settings.tiltCompensation || isFaceUp(Bangle.getAccel()))) { // Use uncompensated firmware heading only if face is up + if (settings.compassSrc === 1 && (settings.tiltCompensation || isFaceUp(Bangle.getAccel()))) { // Use uncompensated built-in compass heading only if face is up const heading = Bangle.getCompass().heading; if (!isNaN(heading)) { gps.courseOrig = gps.course; From 7d5151c3226e558c68a9865b241dfd16b938c994 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 19 Feb 2023 11:52:58 +0100 Subject: [PATCH 08/25] gpsmagdir renamed to gpsmagcourse --- apps/{gpsmagdir => gpsmagcourse}/README.md | 0 apps/{gpsmagdir => gpsmagcourse}/app.png | Bin apps/{gpsmagdir => gpsmagcourse}/boot.js | 4 +-- .../{gpsmagdir => gpsmagcourse}/metadata.json | 10 +++--- apps/{gpsmagdir => gpsmagcourse}/widget.js | 30 +++++++++--------- 5 files changed, 22 insertions(+), 22 deletions(-) rename apps/{gpsmagdir => gpsmagcourse}/README.md (100%) rename apps/{gpsmagdir => gpsmagcourse}/app.png (100%) rename apps/{gpsmagdir => gpsmagcourse}/boot.js (96%) rename apps/{gpsmagdir => gpsmagcourse}/metadata.json (64%) rename apps/{gpsmagdir => gpsmagcourse}/widget.js (70%) diff --git a/apps/gpsmagdir/README.md b/apps/gpsmagcourse/README.md similarity index 100% rename from apps/gpsmagdir/README.md rename to apps/gpsmagcourse/README.md diff --git a/apps/gpsmagdir/app.png b/apps/gpsmagcourse/app.png similarity index 100% rename from apps/gpsmagdir/app.png rename to apps/gpsmagcourse/app.png diff --git a/apps/gpsmagdir/boot.js b/apps/gpsmagcourse/boot.js similarity index 96% rename from apps/gpsmagdir/boot.js rename to apps/gpsmagcourse/boot.js index 2195a8424..189dd9e35 100644 --- a/apps/gpsmagdir/boot.js +++ b/apps/gpsmagcourse/boot.js @@ -4,7 +4,7 @@ compassSrc: 1, // [off, built-in, magnav] resetCompassOnPwr: true, // reset compass on power on tiltCompensation: true, // tilt compensation on built-in compass - }, require("Storage").readJSON("gpsmagdir.json", true) || {}); + }, require("Storage").readJSON("gpsmagcourse.json", true) || {}); const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined; // Check if magnav is installed @@ -91,7 +91,7 @@ const origSetGPSPower = Bangle.setGPSPower; Bangle.setGPSPower = function(on, id) { const isGPSon = origSetGPSPower(on, id); - Bangle.setCompassPower(isGPSon, "gpsmagdir"); + Bangle.setCompassPower(isGPSon, "gpsmagcourse"); return isGPSon; }; } // if (settings.compassSrc > 0) diff --git a/apps/gpsmagdir/metadata.json b/apps/gpsmagcourse/metadata.json similarity index 64% rename from apps/gpsmagdir/metadata.json rename to apps/gpsmagcourse/metadata.json index f83f1ee90..2dcc27384 100644 --- a/apps/gpsmagdir/metadata.json +++ b/apps/gpsmagcourse/metadata.json @@ -1,7 +1,7 @@ { - "id": "gpsmagdir", + "id": "gpsmagcourse", "name": "GPS Compass heading switcher", - "shortName":"GPS/Compass direction", + "shortName":"GPS/Comp. course", "icon": "app.png", "version":"0.01", "description": "Replace GPS heading with compass heading when speed is slow or standing still to avoid the heading from jumping around randomly.", @@ -10,9 +10,9 @@ "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "storage": [ - {"name":"gpsmagdir.boot.js","url":"boot.js"}, - {"name":"gpsmagdir.wid.js","url":"widget.js"} + {"name":"gpsmagcourse.boot.js","url":"boot.js"}, + {"name":"gpsmagcourse.wid.js","url":"widget.js"} ], - "data": [{"name":"gpsmagdir.json"}] + "data": [{"name":"gpsmagcourse.json"}] } diff --git a/apps/gpsmagdir/widget.js b/apps/gpsmagcourse/widget.js similarity index 70% rename from apps/gpsmagdir/widget.js rename to apps/gpsmagcourse/widget.js index cf3c9c60c..0df33755d 100644 --- a/apps/gpsmagdir/widget.js +++ b/apps/gpsmagcourse/widget.js @@ -2,7 +2,7 @@ const settings = Object.assign({ compassSrc: 1, // 0 = off showWidget: 2, // 0 = never, 1 = when replacing GPS course with compass course, 2 = when GPS is on - }, require("Storage").readJSON("gpsmagdir.json", true) || {}); + }, require("Storage").readJSON("gpsmagcourse.json", true) || {}); function isInside(rect, e) { return e.x>=rect.x && e.x 0 && settings.showWidget > 0) { // add your widget - WIDGETS.gpsmagdir={ + WIDGETS.gpsmagcourse={ area:"tr", // tl (top left), tr (top right), bl (bottom left), br (bottom right) width: 0, // hide by default draw:draw, @@ -46,12 +46,12 @@ // show only when GPS course is replaced Bangle.on('GPS', function(gps) { - if (gps.courseOrig && WIDGETS.gpsmagdir.show !== 1 && Bangle.isGPSOn()) { - WIDGETS.gpsmagdir.show = 1; - WIDGETS.gpsmagdir.draw(); - } else if (WIDGETS.gpsmagdir.show) { - WIDGETS.gpsmagdir.show = settings.showWidget === 1 ? 0 : 2; - WIDGETS.gpsmagdir.draw(); + if (gps.courseOrig && WIDGETS.gpsmagcourse.show !== 1 && Bangle.isGPSOn()) { + WIDGETS.gpsmagcourse.show = 1; + WIDGETS.gpsmagcourse.draw(); + } else if (WIDGETS.gpsmagcourse.show) { + WIDGETS.gpsmagcourse.show = settings.showWidget === 1 ? 0 : 2; + WIDGETS.gpsmagcourse.draw(); } }); @@ -59,19 +59,19 @@ const origSetGPSPower = Bangle.setGPSPower; Bangle.setGPSPower = function(on, id) { const isGPSon = origSetGPSPower(on, id); - if (!isGPSon && WIDGETS.gpsmagdir.show) { - WIDGETS.gpsmagdir.show = 0; - WIDGETS.gpsmagdir.draw(); - } else if (isGPSon && !WIDGETS.gpsmagdir.show) { - WIDGETS.gpsmagdir.show = 2; - WIDGETS.gpsmagdir.draw(); + if (!isGPSon && WIDGETS.gpsmagcourse.show) { + WIDGETS.gpsmagcourse.show = 0; + WIDGETS.gpsmagcourse.draw(); + } else if (isGPSon && !WIDGETS.gpsmagcourse.show) { + WIDGETS.gpsmagcourse.show = 2; + WIDGETS.gpsmagcourse.draw(); } return isGPSon; }; // reset compass on click on widget Bangle.on('touch', function(button, touch) { - if (WIDGETS.gpsmagdir && WIDGETS.gpsmagdir.x && WIDGETS.gpsmagdir.width && isInside({x: WIDGETS.gpsmagdir.x, y: WIDGETS.gpsmagdir.y, w: WIDGETS.gpsmagdir.width, h: 24}, touch)) { + if (WIDGETS.gpsmagcourse && WIDGETS.gpsmagcourse.x && WIDGETS.gpsmagcourse.width && isInside({x: WIDGETS.gpsmagcourse.x, y: WIDGETS.gpsmagcourse.y, w: WIDGETS.gpsmagcourse.width, h: 24}, touch)) { Bangle.buzz(50); Bangle.resetCompass(); } From fab9e85cc3551eeda57143d56324a36a5306e3a4 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 19 Feb 2023 11:56:28 +0100 Subject: [PATCH 09/25] gpsmagcourse: Add settings (untested) --- apps/gpsmagcourse/settings.js | 91 +++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 apps/gpsmagcourse/settings.js diff --git a/apps/gpsmagcourse/settings.js b/apps/gpsmagcourse/settings.js new file mode 100644 index 000000000..e5fd524c9 --- /dev/null +++ b/apps/gpsmagcourse/settings.js @@ -0,0 +1,91 @@ +(function(back) { + var FILE = "gpsmagcourse.json"; + // Load settings + const settings = Object.assign({ + speed: 6, // when lower then this use direction from compass + compassSrc: 1, // [off, built-in, magnav] + resetCompassOnPwr: true, // reset compass on power on + tiltCompensation: true, // tilt compensation on built-in compass + showWidget: 2, // 0 = never, 1 = when replacing GPS course with compass course, 2 = when GPS is on + }, require("Storage").readJSON(FILE, true) || {}); + + let magnavInstalled = true; + // Check if magnav is installed + try { + require("magnav"); + } catch(err) { + // not installed + magnavInstalled = false; + } + + if (!magnavInstalled) { + // adjust settings to work without magnav + if (settings.compassSrc === 2) { + settings.compassSrc = 1; + } + if (settings.tiltCompensation) { + settings.tiltCompensation = false; + } + } + const compassSrcOpts = ["off", "built-in"]; + if (magnavInstalled) { + compassSrcOpts.push("magnav"); + } + + function writeSettings() { + require('Storage').writeJSON(FILE, settings); + } + + const menu = { + "" : { "title" : /*LANG*/"GPS/Comp. course" }, + "< Back" : () => back(), + /*LANG*/'Speed threshold': { + value: settings.speed, + min: 1, max: 20, + onchange: v => { + settings.speed = v; + writeSettings(); + } + }, + /*LANG*/'Compass source': { + value: settings.compassSrc, + min: 0, max: compassSrcOpts.length-1, + format: v => compassSrcOpts[v], + onchange: v => { + settings.compassSrc = v; + writeSettings(); + } + }, + /*LANG*/'Reset compass when powered on': { + value: !!settings.resetCompassOnPwr, + format: v => v?/*LANG*/"On":/*LANG*/"Off", + onchange: v => { + settings.resetCompassOnPwr = v; + writeSettings(); + } + }, + /*LANG*/'Show Widget': { + value: settings.showWidget, + min: 0, max: 2, + format: v => ["Never", "Active", "GPS on"][v], + onchange: v => { + settings.showWidget = v; + writeSettings(); + } + }, + }; + + if (magnavInstalled) { + menu[/*LANG*/'Tilt compensation on built-in compass'] = { + value: !!settings.tiltCompensation, + format: v => v?/*LANG*/"On":/*LANG*/"Off", + onchange: v => { + settings.tiltCompensation = v; + writeSettings(); + } + }; + } + + // Show the menu + E.showMenu(menu); +})(load); From 78fd64bf3f89bf363dd4fea0e2a217510e45b5d4 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 19 Feb 2023 19:15:26 +0100 Subject: [PATCH 10/25] gpsmagcourse: settings changes --- apps/gpsmagcourse/README.md | 1 - apps/gpsmagcourse/metadata.json | 7 ++++--- apps/gpsmagcourse/settings.js | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/gpsmagcourse/README.md b/apps/gpsmagcourse/README.md index de7526ccd..de6c51751 100644 --- a/apps/gpsmagcourse/README.md +++ b/apps/gpsmagcourse/README.md @@ -42,7 +42,6 @@ On Bangle.js 2 a click on the widget does reset the built-in compass. - GPS on ## TODO: -- Add Settings - Document settings with defaults - Check magnav dependency in settings - note magnav silently downgrade diff --git a/apps/gpsmagcourse/metadata.json b/apps/gpsmagcourse/metadata.json index 2dcc27384..266924bef 100644 --- a/apps/gpsmagcourse/metadata.json +++ b/apps/gpsmagcourse/metadata.json @@ -1,7 +1,7 @@ { "id": "gpsmagcourse", - "name": "GPS Compass heading switcher", - "shortName":"GPS/Comp. course", + "name": "GPS Compass course switcher", + "shortName":"GPS/Compass course", "icon": "app.png", "version":"0.01", "description": "Replace GPS heading with compass heading when speed is slow or standing still to avoid the heading from jumping around randomly.", @@ -11,7 +11,8 @@ "readme": "README.md", "storage": [ {"name":"gpsmagcourse.boot.js","url":"boot.js"}, - {"name":"gpsmagcourse.wid.js","url":"widget.js"} + {"name":"gpsmagcourse.wid.js","url":"widget.js"}, + {"name":"gpsmagcourse.settings.js","url":"settings.js"} ], "data": [{"name":"gpsmagcourse.json"}] } diff --git a/apps/gpsmagcourse/settings.js b/apps/gpsmagcourse/settings.js index e5fd524c9..572850d6f 100644 --- a/apps/gpsmagcourse/settings.js +++ b/apps/gpsmagcourse/settings.js @@ -27,9 +27,9 @@ settings.tiltCompensation = false; } } - const compassSrcOpts = ["off", "built-in"]; + const compassSrcOpts = [/*LANG*/"off", /*LANG*/"built-in"]; if (magnavInstalled) { - compassSrcOpts.push("magnav"); + compassSrcOpts.push(/*LANG*/"magnav"); } function writeSettings() { @@ -37,11 +37,11 @@ } const menu = { - "" : { "title" : /*LANG*/"GPS/Comp. course" }, + "" : { "title" : /*LANG*/"GPS/Com.course" }, "< Back" : () => back(), /*LANG*/'Speed threshold': { value: settings.speed, - min: 1, max: 20, + min: 1, max: 20, step: 0.5, onchange: v => { settings.speed = v; writeSettings(); @@ -67,7 +67,7 @@ /*LANG*/'Show Widget': { value: settings.showWidget, min: 0, max: 2, - format: v => ["Never", "Active", "GPS on"][v], + format: v => [/*LANG*/"Never", /*LANG*/"Active", /*LANG*/"GPS on"][v], onchange: v => { settings.showWidget = v; writeSettings(); @@ -88,4 +88,4 @@ // Show the menu E.showMenu(menu); -})(load); +}) From a59f500895af09e1dc14d06b92cb3c2bafe41424 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Mon, 20 Feb 2023 21:35:35 +0100 Subject: [PATCH 11/25] gpsmagcourse: README updates --- apps/gpsmagcourse/README.md | 47 +++++++++++++++------------------ apps/gpsmagcourse/metadata.json | 2 +- apps/gpsmagcourse/widget.js | 2 +- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/apps/gpsmagcourse/README.md b/apps/gpsmagcourse/README.md index de6c51751..bca039424 100644 --- a/apps/gpsmagcourse/README.md +++ b/apps/gpsmagcourse/README.md @@ -1,9 +1,9 @@ -# GPS Compass heading switcher +# GPS Compass course switcher The GPS course and speed is calculated by the difference of positions. However GPS position is noisy and prone to jump around. This results in randomly jumping GPS course values when speed is slow or standing still. -So in these cases a user might want to get his moving direction from a compass instead. -This is why this app replaces the GPS heading with the compass heading when the speed is slower then 6 km/h (threshold is configurable, see settings). +So in these cases a user might want to get the moving direction from a compass instead. +This is why this app replaces the GPS course with the compass heading when the speed is slower then 6 km/h (threshold is configurable, see settings). ## Important Notes * **Watch orientation** @@ -19,30 +19,25 @@ This is why this app replaces the GPS heading with the compass heading when the However the error from local magnetic interference and from calibration will probably be higher.. ## Widget -The widget indicates if the current GPS heading is provided from GPS or compass. +The widget indicates if the current GPS course is provided from GPS or compass. It can be turned off in the settings. On Bangle.js 2 a click on the widget does reset the built-in compass. ## Settings -* **speed** - - (default = 6 km/h) When lower then this use direction from compass -* **compassSrc** - - off: - - built-in (default): - - Navigation Compass: -* **reset compass on power on** - - off: - - on (default): -* **tilt compensation** - - off: - - on (default): -* **show Widget** - - Never - - Active (default): When replacing GPS course with compass course - - GPS on - -## TODO: -- Document settings with defaults -- Check magnav dependency in settings -- note magnav silently downgrade -- Test on BangleJS +* **Speed threshold** + - (default = 6 km/h) When GPS speed is lower then this threshold use the compass direction. +* **Compass source** + - off: Disables this addon. + - built-in (default): Uses the built-in compass. Its calibration can be restarted by pressing the Widget. When tilt compensation is disabled or "Navigation compass" is not installed the watch must be orientated horizontally for the compass heading to be used. + - magnav (only if "Navigation Compass" is installed): Compass heading is provided by "Navigation Compass" (magnav). Remember to calibrate it regularly. +* **Reset compass when powered on** + - Off: Do nothing when compass is turned on. + - On (default): The calibration of the built-in compass is reset when it is turned on. +* **Tilt compensation on built-in compass** + Only available if "Navigation Compass" is installed. + - Off: Leaves the value of the built-in compass unchanged. + - On (default): Apply the tilt compensation from "Navigation Compass" to the built-in compass in _all_ applications. +* **Show Widget** + - Never: Widget is hidden. + - Active (default): Widget is only visible when replacing GPS course with compass heading. + - GPS on: Widget is shown as soon as GPS is enabled, crossed out when GPS provides the course and displayed normally when the compass heading is used. diff --git a/apps/gpsmagcourse/metadata.json b/apps/gpsmagcourse/metadata.json index 266924bef..057b01383 100644 --- a/apps/gpsmagcourse/metadata.json +++ b/apps/gpsmagcourse/metadata.json @@ -4,7 +4,7 @@ "shortName":"GPS/Compass course", "icon": "app.png", "version":"0.01", - "description": "Replace GPS heading with compass heading when speed is slow or standing still to avoid the heading from jumping around randomly.", + "description": "Replaces the GPS course with the compass heading when speed is slow or standing still to avoid the value from jumping randomly. For best experience also install \"Navigation Compass\", although not a requirement (see README).", "type": "bootloader", "tags": "outdoors,widget", "supports": ["BANGLEJS","BANGLEJS2"], diff --git a/apps/gpsmagcourse/widget.js b/apps/gpsmagcourse/widget.js index 0df33755d..0e00a1a70 100644 --- a/apps/gpsmagcourse/widget.js +++ b/apps/gpsmagcourse/widget.js @@ -71,7 +71,7 @@ // reset compass on click on widget Bangle.on('touch', function(button, touch) { - if (WIDGETS.gpsmagcourse && WIDGETS.gpsmagcourse.x && WIDGETS.gpsmagcourse.width && isInside({x: WIDGETS.gpsmagcourse.x, y: WIDGETS.gpsmagcourse.y, w: WIDGETS.gpsmagcourse.width, h: 24}, touch)) { + if (touch && WIDGETS.gpsmagcourse && WIDGETS.gpsmagcourse.x && WIDGETS.gpsmagcourse.width && isInside({x: WIDGETS.gpsmagcourse.x, y: WIDGETS.gpsmagcourse.y, w: WIDGETS.gpsmagcourse.width, h: 24}, touch)) { Bangle.buzz(50); Bangle.resetCompass(); } From ed3ebf97543d324df6fb16b4808565a641b0e31c Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Wed, 22 Feb 2023 19:33:24 +0100 Subject: [PATCH 12/25] gpsmagcourse: Avoid jitter, fix widget --- apps/gpsmagcourse/README.md | 2 +- apps/gpsmagcourse/boot.js | 4 +++- apps/gpsmagcourse/widget.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/gpsmagcourse/README.md b/apps/gpsmagcourse/README.md index bca039424..f6e60ea61 100644 --- a/apps/gpsmagcourse/README.md +++ b/apps/gpsmagcourse/README.md @@ -25,7 +25,7 @@ On Bangle.js 2 a click on the widget does reset the built-in compass. ## Settings * **Speed threshold** - - (default = 6 km/h) When GPS speed is lower then this threshold use the compass direction. + - (default = 6 km/h) When GPS speed is lower then this threshold use the compass direction. The speed must be for at least 10 seconds this fast to switch back to GPS course. * **Compass source** - off: Disables this addon. - built-in (default): Uses the built-in compass. Its calibration can be restarted by pressing the Widget. When tilt compensation is disabled or "Navigation compass" is not installed the watch must be orientated horizontally for the compass heading to be used. diff --git a/apps/gpsmagcourse/boot.js b/apps/gpsmagcourse/boot.js index 189dd9e35..ffa9512fa 100644 --- a/apps/gpsmagcourse/boot.js +++ b/apps/gpsmagcourse/boot.js @@ -6,6 +6,7 @@ tiltCompensation: true, // tilt compensation on built-in compass }, require("Storage").readJSON("gpsmagcourse.json", true) || {}); const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined; + let cntAboveSpeed = 0; // Check if magnav is installed try { @@ -63,7 +64,8 @@ }; const changeGpsCourse = (gps) => { - if (gps.speed < settings.speed) { + cntAboveSpeed = gps.speed < settings.speed ? 0 : cntAboveSpeed+1; + if (cntAboveSpeed < 10) { // need to stay x events above or equal threshold if (settings.compassSrc === 1 && (settings.tiltCompensation || isFaceUp(Bangle.getAccel()))) { // Use uncompensated built-in compass heading only if face is up const heading = Bangle.getCompass().heading; if (!isNaN(heading)) { diff --git a/apps/gpsmagcourse/widget.js b/apps/gpsmagcourse/widget.js index 0e00a1a70..6317cedcd 100644 --- a/apps/gpsmagcourse/widget.js +++ b/apps/gpsmagcourse/widget.js @@ -49,7 +49,7 @@ if (gps.courseOrig && WIDGETS.gpsmagcourse.show !== 1 && Bangle.isGPSOn()) { WIDGETS.gpsmagcourse.show = 1; WIDGETS.gpsmagcourse.draw(); - } else if (WIDGETS.gpsmagcourse.show) { + } else if (!gps.courseOrig && WIDGETS.gpsmagcourse.show === 1) { WIDGETS.gpsmagcourse.show = settings.showWidget === 1 ? 0 : 2; WIDGETS.gpsmagcourse.draw(); } From db370302a573a90cf75500ee2ea26122c0de5968 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 23 Feb 2023 19:30:15 +0100 Subject: [PATCH 13/25] gpsmagcourse: conform with 0ba8cef33c1a313626e204cd811ed02a58381d11 --- apps/gpsmagcourse/settings.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/gpsmagcourse/settings.js b/apps/gpsmagcourse/settings.js index 572850d6f..5eb27400d 100644 --- a/apps/gpsmagcourse/settings.js +++ b/apps/gpsmagcourse/settings.js @@ -58,7 +58,6 @@ }, /*LANG*/'Reset compass when powered on': { value: !!settings.resetCompassOnPwr, - format: v => v?/*LANG*/"On":/*LANG*/"Off", onchange: v => { settings.resetCompassOnPwr = v; writeSettings(); @@ -78,7 +77,6 @@ if (magnavInstalled) { menu[/*LANG*/'Tilt compensation on built-in compass'] = { value: !!settings.tiltCompensation, - format: v => v?/*LANG*/"On":/*LANG*/"Off", onchange: v => { settings.tiltCompensation = v; writeSettings(); From 965e60e149f9f90851c73032a80342beacd6a57d Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 26 Feb 2023 09:00:26 +0100 Subject: [PATCH 14/25] gpsmagcourse README updates --- apps/gpsmagcourse/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/gpsmagcourse/README.md b/apps/gpsmagcourse/README.md index f6e60ea61..81fed2986 100644 --- a/apps/gpsmagcourse/README.md +++ b/apps/gpsmagcourse/README.md @@ -3,7 +3,7 @@ The GPS course and speed is calculated by the difference of positions. However GPS position is noisy and prone to jump around. This results in randomly jumping GPS course values when speed is slow or standing still. So in these cases a user might want to get the moving direction from a compass instead. -This is why this app replaces the GPS course with the compass heading when the speed is slower then 6 km/h (threshold is configurable, see settings). +This is why this service replaces the GPS course with the compass heading when the speed is slower then 6 km/h (threshold is configurable, see settings). ## Important Notes * **Watch orientation** @@ -13,7 +13,7 @@ This is why this app replaces the GPS course with the compass heading when the s When "Navigation Compass" is installed the built-in compass gets automatic tilt compensation. This can be turned off in settings. Without "Navigation Compass" installed or this feature disabled the watch must be orientated with the display up to provide a useable compass value. * **Compass reset and calibration** When using "Navigation Compass" as compass source (see settings) please remember to calibrate it regularly. - With this app installed the built-in compass calibration is automatically reset when the compass is turned on (deactivatable in settings). It can also be reset with a tap on the Widget (Bangle.js 2 only). Please note that directly after a reset the built-in compass must be turned 360 degrees to provide a useable value. + With this service installed the built-in compass calibration is automatically reset when the compass is turned on (deactivatable in settings). It can also be reset with a tap on the Widget (Bangle.js 2 only). Please note that directly after a reset the built-in compass must be turned 360 degrees to provide a useable value. * **True north vs magnetic north** Please note that the compass does not point to the "real north" but depending on your location there is an offset, see [Magnetic declination](https://en.wikipedia.org/wiki/Magnetic_declination) However the error from local magnetic interference and from calibration will probably be higher.. From eaf17b71cc5b52e75d89ea5fd83243e8adc6f90a Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Mon, 27 Feb 2023 20:50:51 +0100 Subject: [PATCH 15/25] gpsmagcourse: Do not recalculate in getCompass() --- apps/gpsmagcourse/boot.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/gpsmagcourse/boot.js b/apps/gpsmagcourse/boot.js index ffa9512fa..0aa456fe3 100644 --- a/apps/gpsmagcourse/boot.js +++ b/apps/gpsmagcourse/boot.js @@ -7,6 +7,7 @@ }, require("Storage").readJSON("gpsmagcourse.json", true) || {}); const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined; let cntAboveSpeed = 0; + let lastMag; // Check if magnav is installed try { @@ -40,13 +41,10 @@ if (settings.tiltCompensation) { const origGetCompass = Bangle.getCompass; Bangle.getCompass = function(argObj) { - const mag = origGetCompass(); - if (!isNaN(mag.heading) && (argObj === undefined || !argObj.noTiltComp)) { - const d = require("magnav").tiltfix(mag, Bangle.getAccel()); - mag.headingOrig = mag.heading; - mag.heading = d; + if (!isNaN(lastMag.heading) && (argObj === undefined || !argObj.noTiltComp)) { + return lastMag; } - return mag; + return origGetCompass(); }; Bangle.on('mag', function(mag) { @@ -55,6 +53,7 @@ mag.headingOrig = mag.heading; mag.heading = d; } + lastMag = mag; }); } // if (settings.tiltCompensation) From 864ef1b2bce558e6349d155287a7659cd6aad666 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Mon, 27 Feb 2023 21:11:15 +0100 Subject: [PATCH 16/25] magnav: replace var with let/const --- apps/magnav/lib.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js index fe58615cb..443fc91ac 100644 --- a/apps/magnav/lib.js +++ b/apps/magnav/lib.js @@ -1,8 +1,8 @@ exports.calibrate = () => { - var max={x:-32000, y:-32000, z:-32000}, + const max={x:-32000, y:-32000, z:-32000}, min={x:32000, y:32000, z:32000}; - var ref = setInterval(()=>{ - var m = Bangle.getCompass(); + const ref = setInterval(()=>{ + const m = Bangle.getCompass(); max.x = m.x>max.x?m.x:max.x; max.y = m.y>max.y?m.y:max.y; max.z = m.z>max.z?m.z:max.z; @@ -13,10 +13,10 @@ exports.calibrate = () => { return new Promise((resolve) => { setTimeout(()=>{ if(ref) clearInterval(ref); - var offset = {x:(max.x+min.x)/2,y:(max.y+min.y)/2,z:(max.z+min.z)/2}; - var delta = {x:(max.x-min.x)/2,y:(max.y-min.y)/2,z:(max.z-min.z)/2}; - var avg = (delta.x+delta.y+delta.z)/3; - var scale = {x:avg/delta.x, y:avg/delta.y, z:avg/delta.z}; + const offset = {x:(max.x+min.x)/2,y:(max.y+min.y)/2,z:(max.z+min.z)/2}; + const delta = {x:(max.x-min.x)/2,y:(max.y-min.y)/2,z:(max.z-min.z)/2}; + const avg = (delta.x+delta.y+delta.z)/3; + const scale = {x:avg/delta.x, y:avg/delta.y, z:avg/delta.z}; resolve({offset:offset,scale:scale}); },20000); }); @@ -27,22 +27,22 @@ exports.tiltfix = (m,g,O,S) => { if (O & S) { m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; } - var d = Math.atan2(-m.dx,m.dy)*180/Math.PI; + let d = Math.atan2(-m.dx,m.dy)*180/Math.PI; if (d<0) d+=360; - var phi = Math.atan(-g.x/-g.z); - var cosphi = Math.cos(phi), sinphi = Math.sin(phi); - var theta = Math.atan(-g.y/(-g.x*sinphi-g.z*cosphi)); - var costheta = Math.cos(theta), sintheta = Math.sin(theta); - var xh = m.dy*costheta + m.dx*sinphi*sintheta + m.dz*cosphi*sintheta; - var yh = m.dz*sinphi - m.dx*cosphi; - var psi = Math.atan2(yh,xh)*180/Math.PI; + const phi = Math.atan(-g.x/-g.z); + const cosphi = Math.cos(phi), sinphi = Math.sin(phi); + const theta = Math.atan(-g.y/(-g.x*sinphi-g.z*cosphi)); + const costheta = Math.cos(theta), sintheta = Math.sin(theta); + const xh = m.dy*costheta + m.dx*sinphi*sintheta + m.dz*cosphi*sintheta; + const yh = m.dz*sinphi - m.dx*cosphi; + let psi = Math.atan2(yh,xh)*180/Math.PI; if (psi<0) psi+=360; return psi; } exports.tiltfixread = (O,S) => { "ram" - var m = Bangle.getCompass({noTiltComp: true}); - var g = Bangle.getAccel(); - return exports.tiltfix(m,g,O,S); + const mag = Bangle.getCompass({noTiltComp: true}); + const acc = Bangle.getAccel(); + return exports.tiltfix(mag,acc,O,S); } From d92dee62469bc6aacdf052cc3aace63529913d9e Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Mon, 27 Feb 2023 21:30:40 +0100 Subject: [PATCH 17/25] magnav: fix calibration check --- apps/magnav/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js index 443fc91ac..88e8a8426 100644 --- a/apps/magnav/lib.js +++ b/apps/magnav/lib.js @@ -24,7 +24,7 @@ exports.calibrate = () => { exports.tiltfix = (m,g,O,S) => { "ram" - if (O & S) { + if (O && S) { m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; } let d = Math.atan2(-m.dx,m.dy)*180/Math.PI; From 096b8721fa4eaff400be3e2c21753a0aff2bfb0d Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 28 Feb 2023 09:28:28 +0100 Subject: [PATCH 18/25] Revert "magnav: fix calibration check" This reverts commit d92dee62469bc6aacdf052cc3aace63529913d9e. --- apps/magnav/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js index 88e8a8426..443fc91ac 100644 --- a/apps/magnav/lib.js +++ b/apps/magnav/lib.js @@ -24,7 +24,7 @@ exports.calibrate = () => { exports.tiltfix = (m,g,O,S) => { "ram" - if (O && S) { + if (O & S) { m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; } let d = Math.atan2(-m.dx,m.dy)*180/Math.PI; From 27e8080cef0a58cb24fdc9e98c389177f0153652 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 28 Feb 2023 09:28:39 +0100 Subject: [PATCH 19/25] Revert "magnav: replace var with let/const" This reverts commit 864ef1b2bce558e6349d155287a7659cd6aad666. --- apps/magnav/lib.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js index 443fc91ac..fe58615cb 100644 --- a/apps/magnav/lib.js +++ b/apps/magnav/lib.js @@ -1,8 +1,8 @@ exports.calibrate = () => { - const max={x:-32000, y:-32000, z:-32000}, + var max={x:-32000, y:-32000, z:-32000}, min={x:32000, y:32000, z:32000}; - const ref = setInterval(()=>{ - const m = Bangle.getCompass(); + var ref = setInterval(()=>{ + var m = Bangle.getCompass(); max.x = m.x>max.x?m.x:max.x; max.y = m.y>max.y?m.y:max.y; max.z = m.z>max.z?m.z:max.z; @@ -13,10 +13,10 @@ exports.calibrate = () => { return new Promise((resolve) => { setTimeout(()=>{ if(ref) clearInterval(ref); - const offset = {x:(max.x+min.x)/2,y:(max.y+min.y)/2,z:(max.z+min.z)/2}; - const delta = {x:(max.x-min.x)/2,y:(max.y-min.y)/2,z:(max.z-min.z)/2}; - const avg = (delta.x+delta.y+delta.z)/3; - const scale = {x:avg/delta.x, y:avg/delta.y, z:avg/delta.z}; + var offset = {x:(max.x+min.x)/2,y:(max.y+min.y)/2,z:(max.z+min.z)/2}; + var delta = {x:(max.x-min.x)/2,y:(max.y-min.y)/2,z:(max.z-min.z)/2}; + var avg = (delta.x+delta.y+delta.z)/3; + var scale = {x:avg/delta.x, y:avg/delta.y, z:avg/delta.z}; resolve({offset:offset,scale:scale}); },20000); }); @@ -27,22 +27,22 @@ exports.tiltfix = (m,g,O,S) => { if (O & S) { m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; } - let d = Math.atan2(-m.dx,m.dy)*180/Math.PI; + var d = Math.atan2(-m.dx,m.dy)*180/Math.PI; if (d<0) d+=360; - const phi = Math.atan(-g.x/-g.z); - const cosphi = Math.cos(phi), sinphi = Math.sin(phi); - const theta = Math.atan(-g.y/(-g.x*sinphi-g.z*cosphi)); - const costheta = Math.cos(theta), sintheta = Math.sin(theta); - const xh = m.dy*costheta + m.dx*sinphi*sintheta + m.dz*cosphi*sintheta; - const yh = m.dz*sinphi - m.dx*cosphi; - let psi = Math.atan2(yh,xh)*180/Math.PI; + var phi = Math.atan(-g.x/-g.z); + var cosphi = Math.cos(phi), sinphi = Math.sin(phi); + var theta = Math.atan(-g.y/(-g.x*sinphi-g.z*cosphi)); + var costheta = Math.cos(theta), sintheta = Math.sin(theta); + var xh = m.dy*costheta + m.dx*sinphi*sintheta + m.dz*cosphi*sintheta; + var yh = m.dz*sinphi - m.dx*cosphi; + var psi = Math.atan2(yh,xh)*180/Math.PI; if (psi<0) psi+=360; return psi; } exports.tiltfixread = (O,S) => { "ram" - const mag = Bangle.getCompass({noTiltComp: true}); - const acc = Bangle.getAccel(); - return exports.tiltfix(mag,acc,O,S); + var m = Bangle.getCompass({noTiltComp: true}); + var g = Bangle.getAccel(); + return exports.tiltfix(m,g,O,S); } From 0677f027d058f536ce7a3499f18366079bc55900 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 28 Feb 2023 09:28:55 +0100 Subject: [PATCH 20/25] Revert "magnav" This reverts commit 742bcdddabfabfabb5c2fc9b0ce010010e703747. --- apps/magnav/lib.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js index fe58615cb..39c51a1e1 100644 --- a/apps/magnav/lib.js +++ b/apps/magnav/lib.js @@ -23,7 +23,6 @@ exports.calibrate = () => { } exports.tiltfix = (m,g,O,S) => { - "ram" if (O & S) { m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; } From 71964b041ec24be413985ec3e7ed084b2677bbb1 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 28 Feb 2023 09:29:11 +0100 Subject: [PATCH 21/25] Revert "magnav" This reverts commit cc57c42a17d44016834cd749a5fe4aba0f10b2b5. --- apps/magnav/ChangeLog | 1 - apps/magnav/lib.js | 16 +++++----------- apps/magnav/metadata.json | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/apps/magnav/ChangeLog b/apps/magnav/ChangeLog index 7b548841a..14a6eb2a2 100644 --- a/apps/magnav/ChangeLog +++ b/apps/magnav/ChangeLog @@ -4,4 +4,3 @@ 0.04: Fix Font size 0.05: Initial portable version 0.06: Outsource tilt compensation to library -0.07: Add tiltfix() for compensation on given sensor values diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js index 39c51a1e1..e3fe8fccb 100644 --- a/apps/magnav/lib.js +++ b/apps/magnav/lib.js @@ -22,10 +22,11 @@ exports.calibrate = () => { }); } -exports.tiltfix = (m,g,O,S) => { - if (O & S) { - m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; - } +exports.tiltfixread = (O,S) => { + "ram" + var m = Bangle.getCompass(); + var g = Bangle.getAccel(); + m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z; var d = Math.atan2(-m.dx,m.dy)*180/Math.PI; if (d<0) d+=360; var phi = Math.atan(-g.x/-g.z); @@ -38,10 +39,3 @@ exports.tiltfix = (m,g,O,S) => { if (psi<0) psi+=360; return psi; } - -exports.tiltfixread = (O,S) => { - "ram" - var m = Bangle.getCompass({noTiltComp: true}); - var g = Bangle.getAccel(); - return exports.tiltfix(m,g,O,S); -} diff --git a/apps/magnav/metadata.json b/apps/magnav/metadata.json index 6bdb9d0b6..bd40a08fd 100644 --- a/apps/magnav/metadata.json +++ b/apps/magnav/metadata.json @@ -1,7 +1,7 @@ { "id": "magnav", "name": "Navigation Compass", - "version": "0.07", + "version": "0.06", "description": "Compass with linear display as for GPSNAV. Has Tilt compensation and remembers calibration.", "screenshots": [{"url":"screenshot-b2.png"},{"url":"screenshot-light-b2.png"}], "icon": "magnav.png", From 331a366ce71f6fc4c462256d862fdea0090ba8de Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 28 Feb 2023 10:36:45 +0100 Subject: [PATCH 22/25] gpsmagswitch: Drop tiltCompensation because of unscaled values --- apps/gpsmagcourse/README.md | 15 +++++---------- apps/gpsmagcourse/boot.js | 28 ++-------------------------- apps/gpsmagcourse/settings.js | 16 +--------------- 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/apps/gpsmagcourse/README.md b/apps/gpsmagcourse/README.md index 81fed2986..162f8a2c0 100644 --- a/apps/gpsmagcourse/README.md +++ b/apps/gpsmagcourse/README.md @@ -4,13 +4,12 @@ However GPS position is noisy and prone to jump around. This results in randomly jumping GPS course values when speed is slow or standing still. So in these cases a user might want to get the moving direction from a compass instead. This is why this service replaces the GPS course with the compass heading when the speed is slower then 6 km/h (threshold is configurable, see settings). +You can switch between the built-in compass and "Navigation Compass" (magnav) as the source of the compass heading. When using magnav on Bangle.js 2 at least firmware 2v16.191 is recommended to get a three-dimensional reading. ## Important Notes * **Watch orientation** When the GPS is calculating the course the orientation of the watch does not matter. When the Compass is used as the source of the current heading its top must obviously point at the moving direction (Usually away from you). -* **Tilt compensation** - When "Navigation Compass" is installed the built-in compass gets automatic tilt compensation. This can be turned off in settings. Without "Navigation Compass" installed or this feature disabled the watch must be orientated with the display up to provide a useable compass value. * **Compass reset and calibration** When using "Navigation Compass" as compass source (see settings) please remember to calibrate it regularly. With this service installed the built-in compass calibration is automatically reset when the compass is turned on (deactivatable in settings). It can also be reset with a tap on the Widget (Bangle.js 2 only). Please note that directly after a reset the built-in compass must be turned 360 degrees to provide a useable value. @@ -21,22 +20,18 @@ This is why this service replaces the GPS course with the compass heading when t ## Widget The widget indicates if the current GPS course is provided from GPS or compass. It can be turned off in the settings. -On Bangle.js 2 a click on the widget does reset the built-in compass. +On Bangle.js 2 a click on the widget does reset the built-in compass, has only an affect if the built-in compass is used. ## Settings * **Speed threshold** - (default = 6 km/h) When GPS speed is lower then this threshold use the compass direction. The speed must be for at least 10 seconds this fast to switch back to GPS course. * **Compass source** - - off: Disables this addon. - - built-in (default): Uses the built-in compass. Its calibration can be restarted by pressing the Widget. When tilt compensation is disabled or "Navigation compass" is not installed the watch must be orientated horizontally for the compass heading to be used. - - magnav (only if "Navigation Compass" is installed): Compass heading is provided by "Navigation Compass" (magnav). Remember to calibrate it regularly. + - off: Disables this service. + - built-in (default if "Navigation Compass" is not installed): Uses the built-in compass. Its calibration can be restarted by pressing the Widget. The watch must be orientated horizontally for the compass heading to be used. + - magnav (default if "Navigation Compass" is installed): Compass heading is provided by "Navigation Compass" (magnav). Remember to calibrate it regularly, at least each time after attaching the charge cable. * **Reset compass when powered on** - Off: Do nothing when compass is turned on. - On (default): The calibration of the built-in compass is reset when it is turned on. -* **Tilt compensation on built-in compass** - Only available if "Navigation Compass" is installed. - - Off: Leaves the value of the built-in compass unchanged. - - On (default): Apply the tilt compensation from "Navigation Compass" to the built-in compass in _all_ applications. * **Show Widget** - Never: Widget is hidden. - Active (default): Widget is only visible when replacing GPS course with compass heading. diff --git a/apps/gpsmagcourse/boot.js b/apps/gpsmagcourse/boot.js index 0aa456fe3..ea8527577 100644 --- a/apps/gpsmagcourse/boot.js +++ b/apps/gpsmagcourse/boot.js @@ -1,13 +1,11 @@ { const settings = Object.assign({ speed: 6, // when lower then this use direction from compass - compassSrc: 1, // [off, built-in, magnav] + compassSrc: 2, // [off, built-in, magnav] resetCompassOnPwr: true, // reset compass on power on - tiltCompensation: true, // tilt compensation on built-in compass }, require("Storage").readJSON("gpsmagcourse.json", true) || {}); const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined; let cntAboveSpeed = 0; - let lastMag; // Check if magnav is installed try { @@ -17,9 +15,6 @@ if (settings.compassSrc === 2) { settings.compassSrc = 1; } - if (settings.tiltCompensation) { - settings.tiltCompensation = false; - } } if (settings.compassSrc === 2 && !CALIBDATA) { // No calibration for magnav, fallback to default compass @@ -38,25 +33,6 @@ }; } // if (settings.resetCompassOnPwr) - if (settings.tiltCompensation) { - const origGetCompass = Bangle.getCompass; - Bangle.getCompass = function(argObj) { - if (!isNaN(lastMag.heading) && (argObj === undefined || !argObj.noTiltComp)) { - return lastMag; - } - return origGetCompass(); - }; - - Bangle.on('mag', function(mag) { - if (!isNaN(mag.heading)) { - const d = require("magnav").tiltfix(mag, Bangle.getAccel()); - mag.headingOrig = mag.heading; - mag.heading = d; - } - lastMag = mag; - }); - } // if (settings.tiltCompensation) - if (settings.compassSrc > 0) { const isFaceUp = (acc) => { return (acc.z<-6700/8192) && (acc.z>-9000/8192) && Math.abs(acc.x)<2048/8192 && Math.abs(acc.y)<2048/8192; @@ -65,7 +41,7 @@ const changeGpsCourse = (gps) => { cntAboveSpeed = gps.speed < settings.speed ? 0 : cntAboveSpeed+1; if (cntAboveSpeed < 10) { // need to stay x events above or equal threshold - if (settings.compassSrc === 1 && (settings.tiltCompensation || isFaceUp(Bangle.getAccel()))) { // Use uncompensated built-in compass heading only if face is up + if (settings.compassSrc === 1 && isFaceUp(Bangle.getAccel())) { // Use built-in compass heading only if face is up const heading = Bangle.getCompass().heading; if (!isNaN(heading)) { gps.courseOrig = gps.course; diff --git a/apps/gpsmagcourse/settings.js b/apps/gpsmagcourse/settings.js index 5eb27400d..e574292d6 100644 --- a/apps/gpsmagcourse/settings.js +++ b/apps/gpsmagcourse/settings.js @@ -3,9 +3,8 @@ // Load settings const settings = Object.assign({ speed: 6, // when lower then this use direction from compass - compassSrc: 1, // [off, built-in, magnav] + compassSrc: 2, // [off, built-in, magnav] resetCompassOnPwr: true, // reset compass on power on - tiltCompensation: true, // tilt compensation on built-in compass showWidget: 2, // 0 = never, 1 = when replacing GPS course with compass course, 2 = when GPS is on }, require("Storage").readJSON(FILE, true) || {}); @@ -23,9 +22,6 @@ if (settings.compassSrc === 2) { settings.compassSrc = 1; } - if (settings.tiltCompensation) { - settings.tiltCompensation = false; - } } const compassSrcOpts = [/*LANG*/"off", /*LANG*/"built-in"]; if (magnavInstalled) { @@ -74,16 +70,6 @@ }, }; - if (magnavInstalled) { - menu[/*LANG*/'Tilt compensation on built-in compass'] = { - value: !!settings.tiltCompensation, - onchange: v => { - settings.tiltCompensation = v; - writeSettings(); - } - }; - } - // Show the menu E.showMenu(menu); }) From 82c64a7e6254b2066ed28dcde92b053e3f2f0e88 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 28 Feb 2023 19:20:19 +0100 Subject: [PATCH 23/25] gpsmagswitch: minor fixes --- apps/gpsmagcourse/README.md | 8 ++++---- apps/gpsmagcourse/boot.js | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/gpsmagcourse/README.md b/apps/gpsmagcourse/README.md index 162f8a2c0..82670e7a2 100644 --- a/apps/gpsmagcourse/README.md +++ b/apps/gpsmagcourse/README.md @@ -11,7 +11,7 @@ You can switch between the built-in compass and "Navigation Compass" (magnav) as When the GPS is calculating the course the orientation of the watch does not matter. When the Compass is used as the source of the current heading its top must obviously point at the moving direction (Usually away from you). * **Compass reset and calibration** - When using "Navigation Compass" as compass source (see settings) please remember to calibrate it regularly. + When using "Navigation Compass" as compass source (see settings) please remember to calibrate it regularly. The author recommends to calibrate before every use and at least each time after attaching the charge cable. With this service installed the built-in compass calibration is automatically reset when the compass is turned on (deactivatable in settings). It can also be reset with a tap on the Widget (Bangle.js 2 only). Please note that directly after a reset the built-in compass must be turned 360 degrees to provide a useable value. * **True north vs magnetic north** Please note that the compass does not point to the "real north" but depending on your location there is an offset, see [Magnetic declination](https://en.wikipedia.org/wiki/Magnetic_declination) @@ -20,15 +20,15 @@ You can switch between the built-in compass and "Navigation Compass" (magnav) as ## Widget The widget indicates if the current GPS course is provided from GPS or compass. It can be turned off in the settings. -On Bangle.js 2 a click on the widget does reset the built-in compass, has only an affect if the built-in compass is used. +On Bangle.js 2 a click on the widget does reset the built-in compass, it has only an affect if the built-in compass is used. ## Settings * **Speed threshold** - - (default = 6 km/h) When GPS speed is lower then this threshold use the compass direction. The speed must be for at least 10 seconds this fast to switch back to GPS course. + - (default = 6 km/h) When GPS speed is lower then this threshold use the compass direction. The speed must be for at least 10 seconds this fast to switch back to GPS course. The optimum threshold varies with the quality of the GPS reception. * **Compass source** - off: Disables this service. - built-in (default if "Navigation Compass" is not installed): Uses the built-in compass. Its calibration can be restarted by pressing the Widget. The watch must be orientated horizontally for the compass heading to be used. - - magnav (default if "Navigation Compass" is installed): Compass heading is provided by "Navigation Compass" (magnav). Remember to calibrate it regularly, at least each time after attaching the charge cable. + - magnav (default if "Navigation Compass" is installed and calibrated): Compass heading is provided by "Navigation Compass" (magnav). * **Reset compass when powered on** - Off: Do nothing when compass is turned on. - On (default): The calibration of the built-in compass is reset when it is turned on. diff --git a/apps/gpsmagcourse/boot.js b/apps/gpsmagcourse/boot.js index ea8527577..723e27598 100644 --- a/apps/gpsmagcourse/boot.js +++ b/apps/gpsmagcourse/boot.js @@ -6,6 +6,7 @@ }, require("Storage").readJSON("gpsmagcourse.json", true) || {}); const CALIBDATA = (settings.compassSrc === 2) ? require("Storage").readJSON("magnav.json",1) : undefined; let cntAboveSpeed = 0; + let lastGPS; // Check if magnav is installed try { @@ -17,7 +18,7 @@ } } if (settings.compassSrc === 2 && !CALIBDATA) { - // No calibration for magnav, fallback to default compass + // No calibration for magnav, fallback to built-in compass settings.compassSrc = 1; } @@ -47,7 +48,7 @@ gps.courseOrig = gps.course; gps.course = Bangle.getCompass().heading; } - } else if (settings.compassSrc === 2) { // magnav tilt correction with magnav calibration + } else if (settings.compassSrc === 2) { // magnav gps.courseOrig = gps.course; gps.course = require("magnav").tiltfixread(CALIBDATA.offset,CALIBDATA.scale); } @@ -57,18 +58,21 @@ // Modify GPS event Bangle.on('GPS', gps => { - changeGpsCourse(gps); + lastGPS = gps; + if (!isNaN(gps.course)) { + changeGpsCourse(gps); + } }); const origGetGPSFix = Bangle.getGPSFix; Bangle.getGPSFix = function() { - return changeGpsCourse(origGetGPSFix()); + return lastGPS === undefined ? origGetGPSFix() : lastGPS; }; // Enable Compass with GPS const origSetGPSPower = Bangle.setGPSPower; Bangle.setGPSPower = function(on, id) { const isGPSon = origSetGPSPower(on, id); - Bangle.setCompassPower(isGPSon, "gpsmagcourse"); + Bangle.setCompassPower(isGPSon, "gpsmagcourse" + (id || '')); return isGPSon; }; } // if (settings.compassSrc > 0) From e8bbfd5ae485c78574065c6fc74ad4b30ef851d5 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 28 Feb 2023 19:22:14 +0100 Subject: [PATCH 24/25] Revert "settings: Also invert value" This reverts commit fb1518f6b8fd4c2250e58dcbe9785d14341dc556. --- apps/sleepphasealarm/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sleepphasealarm/settings.js b/apps/sleepphasealarm/settings.js index e72d95e7f..29e3d33c9 100644 --- a/apps/sleepphasealarm/settings.js +++ b/apps/sleepphasealarm/settings.js @@ -90,7 +90,7 @@ E.showMenu({ "" : { "title" : "SleepPhaseAlarm" }, 'Keep alarm enabled': { - value: !config.settings.disableAlarm, + value: !!config.settings.disableAlarm, onchange: v => { config.settings.disableAlarm = !v; writeSettings(); From 51e22e70e8f23514a29bb3e17acbf3b006cf7ec4 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 28 Feb 2023 19:24:40 +0100 Subject: [PATCH 25/25] Revert "Revert "settings: Also invert value"" This reverts commit e8bbfd5ae485c78574065c6fc74ad4b30ef851d5. --- apps/sleepphasealarm/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sleepphasealarm/settings.js b/apps/sleepphasealarm/settings.js index 29e3d33c9..e72d95e7f 100644 --- a/apps/sleepphasealarm/settings.js +++ b/apps/sleepphasealarm/settings.js @@ -90,7 +90,7 @@ E.showMenu({ "" : { "title" : "SleepPhaseAlarm" }, 'Keep alarm enabled': { - value: !!config.settings.disableAlarm, + value: !config.settings.disableAlarm, onchange: v => { config.settings.disableAlarm = !v; writeSettings();