From a725dc7a7864616f292ef571fcc9406a70e61877 Mon Sep 17 00:00:00 2001 From: nravanelli Date: Thu, 19 Jan 2023 13:09:35 -0500 Subject: [PATCH 01/16] Update Layout.js added functionality for button colour specifications --- modules/Layout.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/Layout.js b/modules/Layout.js index 4cf8752a3..2816ff3cf 100644 --- a/modules/Layout.js +++ b/modules/Layout.js @@ -186,8 +186,12 @@ Layout.prototype.render = function (l) { x+4,y+h-1, x,y+h-5, x,y+4 - ], bg = l.selected?gfx.theme.bgH:gfx.theme.bg2; - gfx.setColor(bg).fillPoly(poly).setColor(l.selected ? gfx.theme.fgH : gfx.theme.fg2).drawPoly(poly); + ], bg = l.selected?gfx.theme.bgH:gfx.theme.bg2, + btnborder = l.selected?gfx.theme.fgH:gfx.theme.fg2; + //add button color option + if(l.btnCol!==undefined) bg = l.btnCol; + if(l.btnBorder1!==undefined) btnborder = l.btnBorder; + gfx.setColor(bg).fillPoly(poly).setColor(btnborder).drawPoly(poly); if (l.col!==undefined) gfx.setColor(l.col); if (l.src) gfx.setBgColor(bg).drawImage( "function"==typeof l.src?l.src():l.src, From a37bfcc9c1ab8b4220d854486d7af7ba3b398403 Mon Sep 17 00:00:00 2001 From: nravanelli Date: Thu, 19 Jan 2023 13:11:34 -0500 Subject: [PATCH 02/16] Update Layout.md --- modules/Layout.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/Layout.md b/modules/Layout.md index 67db21858..b95332263 100644 --- a/modules/Layout.md +++ b/modules/Layout.md @@ -47,6 +47,8 @@ layout.render(); - A `wrap` field to enable line wrapping. Requires some combination of `width`/`height` and `fillx`/`filly` to be set. Not compatible with text rotation. - A `col` field, eg `#f00` for red - A `bgCol` field for background color (will automatically fill on render) +- A `btnCol` field for button background color (will default to theme if not set) +- A `btnBorder` field for button border color (will default to theme if not set) - A `halign` field to set horizontal alignment WITHIN a `v` container. `-1`=left, `1`=right, `0`=center - A `valign` field to set vertical alignment WITHIN a `h` container. `-1`=top, `1`=bottom, `0`=center - A `pad` integer field to set pixels padding From 5e87fc2bcfec4c5d8898bec1477bd6152d7dd09b Mon Sep 17 00:00:00 2001 From: Kedlub Date: Fri, 20 Jan 2023 08:32:08 +0100 Subject: [PATCH 03/16] Swipe to back prototype --- apps/backswipe/ChangeLog | 1 + apps/backswipe/app.png | Bin 0 -> 1620 bytes apps/backswipe/boot.js | 33 +++++++++++++++++++++++++++++++++ apps/backswipe/metadata.json | 13 +++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 apps/backswipe/ChangeLog create mode 100644 apps/backswipe/app.png create mode 100644 apps/backswipe/boot.js create mode 100644 apps/backswipe/metadata.json diff --git a/apps/backswipe/ChangeLog b/apps/backswipe/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/backswipe/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/backswipe/app.png b/apps/backswipe/app.png new file mode 100644 index 0000000000000000000000000000000000000000..582cb2e0853a5a2899a3afbd7eb19cde2ee7f6a0 GIT binary patch literal 1620 zcmV-a2CMmrP)1gXjloC|3_d8m;N2OpV(|i0q4YwBna<2! zK9thw%-*|urnNbV{Gax^?eD+#{x0kLJ~)lj_;W+1>qV*k8akT^^dvctZccUyj4}H~#M%Wwee_v` zHMv7o%BM8@dBrLshn{wGD9BDl?^eV5vSM3T96;NnHvtc6La=(qzq)xrX1d8bK-TN- zrd_f$_O`9nEmS+_S7HTXK<&u;LDIW|qlN&KJvM}tt6TVVqL-AvNv`B*{NzNpBfSQwQP5~Sf(Dp@Vq1+3Q`N9wBQN2`J_?M^u0FIMlt?p^8 z%U3%80kIwg!T{E9<8J18S&$k1`eO)@HP+=TZKo(z3_A3VFYJB=sn`2^Q$mRE>02(+W)np;)L1!GUvU2{O{<&F_nE6Qe#D~Xf|dD z+?d3-D1(IUiL`C2;PPv4CKw8H)v7h8^obJ&Z6D0CjVUe8Xq_NAymxUyPAMU^CCrIu z%1M71EC`5o2if_~7E&h??0jeQ1Y3N6p?}G72FmS*)xQD)%wBE=2tW6@(+MTi!fk9H1pWKew2(jTXVu4%vk26QvSQCbGmk`Z)Y! zBIhh)6vG2)h6mF8wC^|l$M(Eo9D?JiW}=_T2jUA>LC80foTera{^p)Wi`>}Gf;(|ZwEZQ zS^k|*9wyt=f4ZOo!xty7{%}HKD9tBZ50g$=%v&&vMa!#@Nsf>EkEEDA*ST6fiC+An zsNK1#>!x0obq@j$QqYU-ad3ZvbjqUU+%iw(0WahgmHV6yeLWqoYkSl4pzFQ(_Vp&I ztO{WI-48rGLwQb?#vgVvduyd9_6W)rFRoQJq3I(J?{Xmin45#=3l9BmL6Bp<*MZej zrsWN7oRPUr7IvrHoIHOjS=gPTCw>d)^LQK+B|=f2qbGjrWaOd5D<<9Dv>MTW0X3z> zyPy}9`<>1~?NCx@m8G$_@rRTy5zH12YM&P)=tU+L^fgY z^0Z&_6^qdVuwgN3wt_Ze(10?J@%{C2grBk42hsu74qEo^nd&v`X`IHN9lrxzS~GeF S(*#!l0000 Date: Fri, 20 Jan 2023 09:32:11 +0100 Subject: [PATCH 04/16] Settings for disabling specific apps --- apps/backswipe/boot.js | 17 +++++- apps/backswipe/metadata.json | 6 +- apps/backswipe/settings.js | 103 +++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 apps/backswipe/settings.js diff --git a/apps/backswipe/boot.js b/apps/backswipe/boot.js index c45acd4c8..5f7122220 100644 --- a/apps/backswipe/boot.js +++ b/apps/backswipe/boot.js @@ -1,4 +1,6 @@ (function () { + var settings = require("Storage").readJSON("backswipe.json", 1) || {}; + // Overrride the default setUI method, so we can save the back button callback var setUI = Bangle.setUI; Bangle.setUI = function (mode, cb) { @@ -7,9 +9,11 @@ options = mode; } + var currentFile = global.__FILE__ || ""; + print("Setting UI"); if(global.BACK) delete global.BACK; - if (options && options.back) { + if (options && options.back && enabledForApp(currentFile)) { print("Saving back callback"); global.BACK = options.back; } @@ -28,6 +32,17 @@ } } + function enabledForApp(app) { + if (!settings) return true; + if (settings.mode === "blacklist") { + return !settings.apps.includes(app); + } else if (settings.mode === "whitelist") { + return settings.apps.includes(app); + } else { + return settings.mode === "on" ? true : false; + } + } + // Listen to left to right swipe Bangle.on("swipe", goBack); })(); diff --git a/apps/backswipe/metadata.json b/apps/backswipe/metadata.json index 6b7eea3d8..7aa9f6247 100644 --- a/apps/backswipe/metadata.json +++ b/apps/backswipe/metadata.json @@ -8,6 +8,10 @@ "supports" : ["BANGLEJS2"], "type": "bootloader", "storage": [ - {"name":"backswipe.boot.js","url":"boot.js"} + {"name":"backswipe.boot.js","url":"boot.js"}, + {"name":"backswipe.settings.js","url":"settings.js"} + ], + "data": [ + {"name":"backswipe.json"} ] } diff --git a/apps/backswipe/settings.js b/apps/backswipe/settings.js new file mode 100644 index 000000000..80ab25878 --- /dev/null +++ b/apps/backswipe/settings.js @@ -0,0 +1,103 @@ +(function() { + var FILE = 'backswipe.json'; + // Mode can be 'blacklist', 'whitelist', 'on' or 'disabled' + // Apps is an array of app names, where all the apps that are there are either blocked or allowed, depending on the mode + var DEFAULTS = { + 'mode': 'blacklist', + 'apps': [] + }; + + var settings = {}; + + var loadSettings = function() { + var settings = require('Storage').readJSON(FILE, 1) || DEFAULTS; + return settings; + } + + var saveSettings = function(settings) { + require('Storage').write(FILE, settings); + } + + var getApps = function() { + var apps = require('Storage').list(/\.info$/).map(app => { + return app.replace('.info', ''); + }); + return apps; + } + + var getSettings = function() { + var settings = loadSettings(); + return { + mode: settings.mode, + apps: settings.apps, + }; + } + + var showMenu = function() { + var settings = getSettings(); + var menu = { + '': { 'title': 'Backswipe' }, + '< Back': () => { + load(); + E.showMenu(); + }, + 'Mode': { + value: settings.mode, + format: v => v, + onchange: v => { + settings.mode = v; + }, + options: ['blacklist', 'whitelist', 'on', 'disabled'] + }, + 'App List': { + value: '', + format: v => v, + onchange: v => { + showAppSubMenu(); + } + } + }; + + E.showMenu(menu); + } + + var showAppSubMenu = function() { + var menu = { + '': { 'title': 'Backswipe' }, + '< Back': () => { + showMenu(); + }, + 'Add App': () => { + showAppList(); + } + }; + settings.apps.forEach(app => { + menu[app.app] = () => { + settings.apps.splice(settings.apps.indexOf(app), 1); + } + saveSettings(settings); + }); + E.showMenu(menu); + } + + var showAppList = function() { + var apps = getApps(); + var menu = { + '': { 'title': 'Backswipe' }, + '< Back': () => { + showMenu(); + } + }; + apps.forEach(app => { + menu[app] = () => { + settings.apps.push(app); + saveSettings(settings); + showAppSubMenu(); + } + }); + E.showMenu(menu); + } + + loadSettings(); + showMenu(); +}) \ No newline at end of file From 605916ae0a01b7ad38470ffdd5f52f0f4e79bc98 Mon Sep 17 00:00:00 2001 From: Gabriele Monaco Date: Thu, 19 Jan 2023 21:35:57 +0100 Subject: [PATCH 05/16] Fixed stepGoal json path in clkinfo --- modules/clock_info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/clock_info.js b/modules/clock_info.js index 0a6035ccf..7d0cc8593 100644 --- a/modules/clock_info.js +++ b/modules/clock_info.js @@ -54,7 +54,7 @@ let storage = require("Storage"); let stepGoal = undefined; // Load step goal from health app and pedometer widget let d = storage.readJSON("health.json", true) || {}; -stepGoal = d != undefined && d.settings != undefined ? d.settings.stepGoal : undefined; +stepGoal = d.stepGoal; if (stepGoal == undefined) { d = storage.readJSON("wpedom.json", true) || {}; stepGoal = d != undefined && d.settings != undefined ? d.settings.goal : 10000; From 9e8a44dca620affe96fb8b7a3f90c021343820b3 Mon Sep 17 00:00:00 2001 From: nravanelli Date: Fri, 20 Jan 2023 22:49:22 -0500 Subject: [PATCH 06/16] Update Layout.js fixed "fat finger" error in copy/paste from local code; Line 193; l.btnBorder removed btnCol and replaced to bgCol, which is typically ignored in the type:btn --- modules/Layout.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/Layout.js b/modules/Layout.js index 2816ff3cf..396b41cd0 100644 --- a/modules/Layout.js +++ b/modules/Layout.js @@ -189,8 +189,8 @@ Layout.prototype.render = function (l) { ], bg = l.selected?gfx.theme.bgH:gfx.theme.bg2, btnborder = l.selected?gfx.theme.fgH:gfx.theme.fg2; //add button color option - if(l.btnCol!==undefined) bg = l.btnCol; - if(l.btnBorder1!==undefined) btnborder = l.btnBorder; + if(l.bgCol!==undefined) bg = l.bgCol; + if(l.btnBorder!==undefined) btnborder = l.btnBorder; gfx.setColor(bg).fillPoly(poly).setColor(btnborder).drawPoly(poly); if (l.col!==undefined) gfx.setColor(l.col); if (l.src) gfx.setBgColor(bg).drawImage( From f01202ef4af2a37b3e94e9e2e33cca7425651ef8 Mon Sep 17 00:00:00 2001 From: nravanelli Date: Fri, 20 Jan 2023 22:51:20 -0500 Subject: [PATCH 07/16] Update Layout.md defined `bgCol` for when used on a `type:"btn"` --- modules/Layout.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/Layout.md b/modules/Layout.md index b95332263..95bf116dc 100644 --- a/modules/Layout.md +++ b/modules/Layout.md @@ -46,8 +46,7 @@ layout.render(); - A `r` field to set rotation of text or images (0: 0°, 1: 90°, 2: 180°, 3: 270°). - A `wrap` field to enable line wrapping. Requires some combination of `width`/`height` and `fillx`/`filly` to be set. Not compatible with text rotation. - A `col` field, eg `#f00` for red -- A `bgCol` field for background color (will automatically fill on render) -- A `btnCol` field for button background color (will default to theme if not set) +- A `bgCol` field for background color (will automatically fill on render). When `type:"btn"`, this sets the background color of the button, and will not change color on press - A `btnBorder` field for button border color (will default to theme if not set) - A `halign` field to set horizontal alignment WITHIN a `v` container. `-1`=left, `1`=right, `0`=center - A `valign` field to set vertical alignment WITHIN a `h` container. `-1`=top, `1`=bottom, `0`=center From e68c526a3e7102e81664a2314ca3200acd0ec383 Mon Sep 17 00:00:00 2001 From: nravanelli Date: Fri, 20 Jan 2023 23:54:13 -0500 Subject: [PATCH 08/16] Update Layout.js --- modules/Layout.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/Layout.js b/modules/Layout.js index 396b41cd0..5afcce410 100644 --- a/modules/Layout.js +++ b/modules/Layout.js @@ -186,11 +186,11 @@ Layout.prototype.render = function (l) { x+4,y+h-1, x,y+h-5, x,y+4 - ], bg = l.selected?gfx.theme.bgH:gfx.theme.bg2, - btnborder = l.selected?gfx.theme.fgH:gfx.theme.fg2; - //add button color option - if(l.bgCol!==undefined) bg = l.bgCol; - if(l.btnBorder!==undefined) btnborder = l.btnBorder; + ], bg = l.bgCol!==undefined?l.bgCol:gfx.theme.bg2, + btnborder = l.btnBorder!==undefined?l.btnBorder:gfx.theme.fg2; + if(l.selected){ + bg = gfx.theme.bgH, btnborder = gfx.theme.fgH; + } gfx.setColor(bg).fillPoly(poly).setColor(btnborder).drawPoly(poly); if (l.col!==undefined) gfx.setColor(l.col); if (l.src) gfx.setBgColor(bg).drawImage( From 9ec805c67ac85b0f9f90bd78a649c5f0d1cb1c55 Mon Sep 17 00:00:00 2001 From: Gabriele Monaco Date: Fri, 20 Jan 2023 05:18:21 +0100 Subject: [PATCH 09/16] clkinfo: added altitude ranges and unfocus on lock --- modules/clock_info.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/clock_info.js b/modules/clock_info.js index 7d0cc8593..f185a494c 100644 --- a/modules/clock_info.js +++ b/modules/clock_info.js @@ -120,8 +120,10 @@ exports.load = function() { if (Bangle.getPressure){ // Altimeter may not exist bangleItems.push({ name : "Altitude", + hasRange : true, get : () => ({ - text : alt, v : alt, + text : alt, v : parseInt(alt), + min : 0, max : 3000, img : atob("GBiBAAAAAAAAAAAAAAAAAAAAAAACAAAGAAAPAAEZgAOwwAPwQAZgYAwAMBgAGBAACDAADGAABv///////wAAAAAAAAAAAAAAAAAAAA==") }), show : function() { this.interval = setInterval(altUpdateHandler, 60000); alt = "--"; altUpdateHandler(); }, @@ -266,7 +268,14 @@ exports.addInteractive = function(menu, options) { } Bangle.on("swipe",swipeHandler); var touchHandler; + var lockHandler; if (options.x!==undefined && options.y!==undefined && options.w && options.h) { + lockHandler = function() { + if(options.focus) { + options.focus=false; + options.redraw(); + } + }; touchHandler = function(_,e) { if (e.x(options.x+options.w) || e.y>(options.y+options.h)) { @@ -278,7 +287,7 @@ exports.addInteractive = function(menu, options) { } if (!options.focus) { options.focus=true; // if not focussed, set focus - options.redraw(); + options.redraw(); } else if (menu[options.menuA].items[options.menuB].run) { Bangle.buzz(100, 0.7); menu[options.menuA].items[options.menuB].run(); // allow tap on an item to run it (eg home assistant) @@ -287,6 +296,7 @@ exports.addInteractive = function(menu, options) { } }; Bangle.on("touch",touchHandler); + Bangle.on("lock", lockHandler); } // draw the first item menuShowItem(menu[options.menuA].items[options.menuB]); @@ -294,6 +304,7 @@ exports.addInteractive = function(menu, options) { options.remove = function() { Bangle.removeListener("swipe",swipeHandler); if (touchHandler) Bangle.removeListener("touch",touchHandler); + if (lockHandler) Bangle.removeListener("lock", lockHandler); menuHideItem(menu[options.menuA].items[options.menuB]); exports.loadCount--; }; From 3ea038bd85146119f59231594d52040524126daf Mon Sep 17 00:00:00 2001 From: Kedlub Date: Sun, 22 Jan 2023 09:47:48 +0100 Subject: [PATCH 10/16] Functional blacklist and whitelist modes --- apps/backswipe/boot.js | 20 ++++++++----- apps/backswipe/settings.js | 61 +++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/apps/backswipe/boot.js b/apps/backswipe/boot.js index 5f7122220..634a6e9d9 100644 --- a/apps/backswipe/boot.js +++ b/apps/backswipe/boot.js @@ -1,5 +1,9 @@ (function () { - var settings = require("Storage").readJSON("backswipe.json", 1) || {}; + var DEFAULTS = { + mode: 0, + apps: [], + }; + var settings = require("Storage").readJSON("backswipe.json", 1) || DEFAULTS; // Overrride the default setUI method, so we can save the back button callback var setUI = Bangle.setUI; @@ -32,17 +36,19 @@ } } + // Check if the back button should be enabled for the current app + // app is the src file of the app function enabledForApp(app) { if (!settings) return true; - if (settings.mode === "blacklist") { - return !settings.apps.includes(app); - } else if (settings.mode === "whitelist") { - return settings.apps.includes(app); + if (settings.mode === 0) { + return !(settings.apps.filter((a) => a.src === app).length > 0); + } else if (settings.mode === 1) { + return settings.apps.filter((a) => a.src === app).length > 0; } else { - return settings.mode === "on" ? true : false; + return settings.mode === 2 ? true : false; } } - + // Listen to left to right swipe Bangle.on("swipe", goBack); })(); diff --git a/apps/backswipe/settings.js b/apps/backswipe/settings.js index 80ab25878..281f391fe 100644 --- a/apps/backswipe/settings.js +++ b/apps/backswipe/settings.js @@ -1,60 +1,60 @@ -(function() { +(function(back) { var FILE = 'backswipe.json'; // Mode can be 'blacklist', 'whitelist', 'on' or 'disabled' - // Apps is an array of app names, where all the apps that are there are either blocked or allowed, depending on the mode + // Apps is an array of app info objects, where all the apps that are there are either blocked or allowed, depending on the mode var DEFAULTS = { - 'mode': 'blacklist', + 'mode': 0, 'apps': [] }; var settings = {}; var loadSettings = function() { - var settings = require('Storage').readJSON(FILE, 1) || DEFAULTS; - return settings; + settings = require('Storage').readJSON(FILE, 1) || DEFAULTS; } var saveSettings = function(settings) { require('Storage').write(FILE, settings); } + // Get all app info files var getApps = function() { - var apps = require('Storage').list(/\.info$/).map(app => { - return app.replace('.info', ''); + var apps = require('Storage').list(/\.info$/).map(appInfoFileName => { + var appInfo = require('Storage').readJSON(appInfoFileName, 1); + return appInfo && { + 'name': appInfo.name, + 'sortorder': appInfo.sortorder, + 'src': appInfo.src + }; + }).filter(app => app && !!app.src); + apps.sort((a, b) => { + var n = (0 | a.sortorder) - (0 | b.sortorder); + if (n) return n; // do sortorder first + if (a.name < b.name) return -1; + if (a.name > b.name) return 1; + return 0; }); return apps; } - var getSettings = function() { - var settings = loadSettings(); - return { - mode: settings.mode, - apps: settings.apps, - }; - } - var showMenu = function() { - var settings = getSettings(); var menu = { '': { 'title': 'Backswipe' }, '< Back': () => { - load(); - E.showMenu(); + back(); }, 'Mode': { value: settings.mode, - format: v => v, + min: 0, + max: 3, + format: v => ["Blacklist", "Whitelist", "Always On", "Disabled"][v], onchange: v => { settings.mode = v; + saveSettings(settings); }, - options: ['blacklist', 'whitelist', 'on', 'disabled'] }, - 'App List': { - value: '', - format: v => v, - onchange: v => { - showAppSubMenu(); - } + 'App List': () => { + showAppSubMenu(); } }; @@ -72,10 +72,11 @@ } }; settings.apps.forEach(app => { - menu[app.app] = () => { + menu[app.name] = () => { settings.apps.splice(settings.apps.indexOf(app), 1); + saveSettings(settings); + showAppSubMenu(); } - saveSettings(settings); }); E.showMenu(menu); } @@ -89,8 +90,8 @@ } }; apps.forEach(app => { - menu[app] = () => { - settings.apps.push(app); + menu[app.name] = () => { + settings.apps.push(app); saveSettings(settings); showAppSubMenu(); } From 73c7dbf459c07135926ec2eabc115d3838f68c8d Mon Sep 17 00:00:00 2001 From: Kedlub Date: Sun, 22 Jan 2023 09:52:05 +0100 Subject: [PATCH 11/16] Remove debug printing --- apps/backswipe/boot.js | 4 - apps/backswipe/settings.js | 200 ++++++++++++++++++------------------- 2 files changed, 100 insertions(+), 104 deletions(-) diff --git a/apps/backswipe/boot.js b/apps/backswipe/boot.js index 634a6e9d9..523149e8c 100644 --- a/apps/backswipe/boot.js +++ b/apps/backswipe/boot.js @@ -15,10 +15,8 @@ var currentFile = global.__FILE__ || ""; - print("Setting UI"); if(global.BACK) delete global.BACK; if (options && options.back && enabledForApp(currentFile)) { - print("Saving back callback"); global.BACK = options.back; } setUI(mode, cb); @@ -27,10 +25,8 @@ function goBack(lr, ud) { // if it is a left to right swipe if (lr === 1) { - print("Back swipe detected"); // if we're in an app that has a back button, run the callback for it if (global.BACK) { - print("Running back callback"); global.BACK(); } } diff --git a/apps/backswipe/settings.js b/apps/backswipe/settings.js index 281f391fe..2c29e86f8 100644 --- a/apps/backswipe/settings.js +++ b/apps/backswipe/settings.js @@ -1,104 +1,104 @@ (function(back) { - var FILE = 'backswipe.json'; - // Mode can be 'blacklist', 'whitelist', 'on' or 'disabled' - // Apps is an array of app info objects, where all the apps that are there are either blocked or allowed, depending on the mode - var DEFAULTS = { - 'mode': 0, - 'apps': [] + var FILE = 'backswipe.json'; + // Mode can be 'blacklist', 'whitelist', 'on' or 'disabled' + // Apps is an array of app info objects, where all the apps that are there are either blocked or allowed, depending on the mode + var DEFAULTS = { + 'mode': 0, + 'apps': [] + }; + + var settings = {}; + + var loadSettings = function() { + settings = require('Storage').readJSON(FILE, 1) || DEFAULTS; + } + + var saveSettings = function(settings) { + require('Storage').write(FILE, settings); + } + + // Get all app info files + var getApps = function() { + var apps = require('Storage').list(/\.info$/).map(appInfoFileName => { + var appInfo = require('Storage').readJSON(appInfoFileName, 1); + return appInfo && { + 'name': appInfo.name, + 'sortorder': appInfo.sortorder, + 'src': appInfo.src + }; + }).filter(app => app && !!app.src); + apps.sort((a, b) => { + var n = (0 | a.sortorder) - (0 | b.sortorder); + if (n) return n; // do sortorder first + if (a.name < b.name) return -1; + if (a.name > b.name) return 1; + return 0; + }); + return apps; + } + + var showMenu = function() { + var menu = { + '': { 'title': 'Backswipe' }, + '< Back': () => { + back(); + }, + 'Mode': { + value: settings.mode, + min: 0, + max: 3, + format: v => ["Blacklist", "Whitelist", "Always On", "Disabled"][v], + onchange: v => { + settings.mode = v; + saveSettings(settings); + }, + }, + 'App List': () => { + showAppSubMenu(); + } }; - - var settings = {}; - var loadSettings = function() { - settings = require('Storage').readJSON(FILE, 1) || DEFAULTS; - } - - var saveSettings = function(settings) { - require('Storage').write(FILE, settings); - } - - // Get all app info files - var getApps = function() { - var apps = require('Storage').list(/\.info$/).map(appInfoFileName => { - var appInfo = require('Storage').readJSON(appInfoFileName, 1); - return appInfo && { - 'name': appInfo.name, - 'sortorder': appInfo.sortorder, - 'src': appInfo.src - }; - }).filter(app => app && !!app.src); - apps.sort((a, b) => { - var n = (0 | a.sortorder) - (0 | b.sortorder); - if (n) return n; // do sortorder first - if (a.name < b.name) return -1; - if (a.name > b.name) return 1; - return 0; - }); - return apps; - } - - var showMenu = function() { - var menu = { - '': { 'title': 'Backswipe' }, - '< Back': () => { - back(); - }, - 'Mode': { - value: settings.mode, - min: 0, - max: 3, - format: v => ["Blacklist", "Whitelist", "Always On", "Disabled"][v], - onchange: v => { - settings.mode = v; - saveSettings(settings); - }, - }, - 'App List': () => { - showAppSubMenu(); - } - }; - - E.showMenu(menu); - } - - var showAppSubMenu = function() { - var menu = { - '': { 'title': 'Backswipe' }, - '< Back': () => { - showMenu(); - }, - 'Add App': () => { - showAppList(); - } - }; - settings.apps.forEach(app => { - menu[app.name] = () => { - settings.apps.splice(settings.apps.indexOf(app), 1); - saveSettings(settings); - showAppSubMenu(); - } - }); - E.showMenu(menu); - } - - var showAppList = function() { - var apps = getApps(); - var menu = { - '': { 'title': 'Backswipe' }, - '< Back': () => { - showMenu(); - } - }; - apps.forEach(app => { - menu[app.name] = () => { - settings.apps.push(app); - saveSettings(settings); - showAppSubMenu(); - } - }); - E.showMenu(menu); - } - - loadSettings(); - showMenu(); + E.showMenu(menu); + } + + var showAppSubMenu = function() { + var menu = { + '': { 'title': 'Backswipe' }, + '< Back': () => { + showMenu(); + }, + 'Add App': () => { + showAppList(); + } + }; + settings.apps.forEach(app => { + menu[app.name] = () => { + settings.apps.splice(settings.apps.indexOf(app), 1); + saveSettings(settings); + showAppSubMenu(); + } + }); + E.showMenu(menu); + } + + var showAppList = function() { + var apps = getApps(); + var menu = { + '': { 'title': 'Backswipe' }, + '< Back': () => { + showMenu(); + } + }; + apps.forEach(app => { + menu[app.name] = () => { + settings.apps.push(app); + saveSettings(settings); + showAppSubMenu(); + } + }); + E.showMenu(menu); + } + + loadSettings(); + showMenu(); }) \ No newline at end of file From c9e95ed7f31f872424437942f3af1922851907ee Mon Sep 17 00:00:00 2001 From: Kedlub Date: Sun, 22 Jan 2023 10:01:13 +0100 Subject: [PATCH 12/16] New icon --- apps/backswipe/app.png | Bin 1620 -> 764 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/apps/backswipe/app.png b/apps/backswipe/app.png index 582cb2e0853a5a2899a3afbd7eb19cde2ee7f6a0..93019e1e2ca438547bb310cb6d1d0b24ba71ba3d 100644 GIT binary patch delta 740 zcmVAW00c}93=Fw>B}GB*P6`o`Q3?!5 zAThbPfB`pPWMKGq4MZ|9T-FUNVdcl878~F!0$K>9KLD{vI+)GK0%9jY*b*Ric}YPD zkgWq^Cl?ff*gzLE@DzmvIRn`~K(<0U5<3ZroswFd3}oj3*?;i}zva(oV6gbYz`#5a zA(k|afnj?)1B1jJgqX@g1_u6C28L~y5n`YH!Tx0wJ5-WdQ34Y2(|2SjNGwVOOEZH4 zG%byR;nQ*k2Hr>p2H^_~3|!F=cYpzFF)*M>3@1VW0CLzigrgrvvj6}932;bRa{vGi z!vFvd!vV){sDESt00F^CL_t(&f#sO7E<`~ThQF~EQArdcD_GfxLPeudNoW)jjYve~ z?hAMWqV^!3!3%f*g#x=abPBCa+@qF^*mLikxjXCY@0t0NIcL5*kT|aD4aoBH7PUMh zcMq=fa;^P-++tIIA#06U`n3}vgM1wUoLm;E6)k|k7=O*h9U!C60WcY&u6Y1yH5QQZ zGepjSX6X7RJs_K#bw1wr5orT^K+R$u2pm9G8mmytfKy;DWbNN59YE&irHpt09j)9qgdr~o0)xx3pzemVNl1=O**)i%vagklR=iY_3zIhY7$G2Da z^m4^>uYZNGi*N&chN>TJ3OUGKr+4c*y(1>R8o)VlAE0h{G>SYlI$czeUAKD&+!bB7 zQ~)bQ)=(&bwIXX6xCdg+b`5_9sN#0j;0;i<-)Q);v0+hU4Wp^k$sQpeNj9;MWXGrv zYem*jsEMr=SwpEQWTnW;J%mTA$Yqq;k1hCX^vl}+ny%9V> z?3+7CfGXXo)I!6c-=nG1T9Q3NK9X!=AIXkUAC~$ZrHL)|JL(j&(C?x6SuguSoiyKs WlKY?1AE^fb00004iBBgQZ;76qOQH!eYQP$e z!AKAcJ}AB5-5IcA@d8w#^g@T3&dgpul+x+U-n)CIwK<9WpMUnc?eD+#{x0kLJ~)lj z_;W+1>qV*0;V;<>t_7g#4P@iwmk z1qmdsUbfUStd9Y|TVP;i68~i*#Z&Y~>jipZkI1cLC-XG&6_#ObWSo3TMb<VnloLT~EMt9))wb_t9z`$fds1weiDS%fvYLsiPBH2ZnQDk6uTc5^7mPDSrl!}_vf zTUQ)F+oLxD4{1WMdd9!Hc|m5n$vQyR>+YsqvNZO#t<^15JLgwo1!6$$$ooOkyMm*J z0F*s8gnyK)TljRMmz2LruK4O$zQL{wjY9)Z0kt|Lq(2FsQU|U{&Lnw&nv-iz0UQ(1 z_C;r*+zXKT!Vl?Dy;NHGm#6;#j+0`o?rE&cS33Uzu^t4%0M>8gZsvJekQx2@V+fHo z*5xa0rzlknI`ob)Spqpmmr>I{XwtT=f>`%xcYlkXpJLUDL8`0V*CWqymfo()hTHYJB=sn`2^Q$mRE>02( z+W)np;)L1!GUvU2{O{<&F_nE6Qe#D~Xf|dD+?d3-D1(IUiL`C2;PPv4CKw8H)v7h8 z^nZyH25leAvW+P%&S;$=IlOmqK~5megP0ekG0q%cjYX8Luf59F*IsobYlouaRHM0~ z(;q09t|si8%+WECi^loRmFYCwYI6mr1b@o&75=}a@Lib3Y|Ie4CxKK>Okic}5Rq_U zeN+~H!uVe{{lz}^`kQW`|!xuR17T{A$XG+1=zihuSA zi1p!&kSPh)j$Fxp5Gw{9(I0?wrrO+K-v|fy4|DX;36jHEtgI3$_c6CFMEwO7gd?t7 z-aKL)pd~&(x0thy7QxaE*@Ws7r4mmjvcx<3IQ(NG=PY9s!vkrC2h#ks?>HAOpF`dJ zh_{!DY|1~1bS#dwebHHv-OtHAL4Pqg_G^mIKKhN3WERtBFmGXm+WH8Q3O|NVINqP; zhpz`Xd?0}cEM8H=+`36mP?GrceEI9%2{WYQhDKVxISl-_Sn>l$M(Eo9D?J ziW}=_T2jUA>LC80foTera{^p)Wi`>}Gf;(|ZwEZQS^k|*9wyt=f4ZOo!+#eiul{gC zVkpfgTMv^?S+&Oz-^QfHN=vA6Mu zqQHxcUJp$bNst%thoZ%hhv~ZHvseduC&kuI$^k?+Ves;_U-A`;(L4gMVKHj9f;MB& zfHIHq{q=E#pRw2n(gD^ETK4Xl>NV?WoW`FWzXM%bGkOQp1Xln6002ovPDHLkV1k{q B8?pcZ From 7fb4c6f7865618fe72b434865361c047fc098041 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sun, 22 Jan 2023 10:04:29 +0100 Subject: [PATCH 13/16] graphics_utils - Set a default step allowing a full circle arc --- modules/graphics_utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/graphics_utils.js b/modules/graphics_utils.js index 5c08188bc..ca2c0fb76 100644 --- a/modules/graphics_utils.js +++ b/modules/graphics_utils.js @@ -1,6 +1,6 @@ // draw an arc between radii minR and maxR, and between angles minAngle and maxAngle centered at X,Y. All angles are radians. exports.fillArc = function(graphics, X, Y, minR, maxR, minAngle, maxAngle, stepAngle) { - var step = stepAngle || 0.2; + var step = stepAngle || 0.21; var angle = minAngle; var inside = []; var outside = []; From bf5c44c92200dd6993acc71512b69d74a9e95fe1 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sun, 22 Jan 2023 10:05:21 +0100 Subject: [PATCH 14/16] graphics_utils - Use correct parameter variable --- modules/graphics_utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/graphics_utils.js b/modules/graphics_utils.js index ca2c0fb76..f573cf0cf 100644 --- a/modules/graphics_utils.js +++ b/modules/graphics_utils.js @@ -31,5 +31,5 @@ exports.degreesToRadians = function(degrees){ } exports.radiansToDegrees = function(radians){ - return 180/Math.PI * degrees; + return 180/Math.PI * radians; } \ No newline at end of file From d612937bb72fb0b98df1319f71429ffe4bce5dca Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 22 Jan 2023 10:10:29 +0100 Subject: [PATCH 15/16] magnav: Outsource tilt compensation to library --- apps/magnav/ChangeLog | 5 ++-- apps/magnav/lib.js | 41 +++++++++++++++++++++++++++++++ apps/magnav/magnav_b1.js | 45 ++--------------------------------- apps/magnav/metadata.json | 3 ++- apps/waypointer/ChangeLog | 1 + apps/waypointer/app.js | 37 +++++++++++++--------------- apps/waypointer/metadata.json | 4 ++-- 7 files changed, 66 insertions(+), 70 deletions(-) create mode 100644 apps/magnav/lib.js diff --git a/apps/magnav/ChangeLog b/apps/magnav/ChangeLog index 2b2782c7b..14a6eb2a2 100644 --- a/apps/magnav/ChangeLog +++ b/apps/magnav/ChangeLog @@ -2,6 +2,5 @@ 0.02: Course marker 0.03: Tilt compensation and calibration 0.04: Fix Font size -0.05: Inital portable version - - +0.05: Initial portable version +0.06: Outsource tilt compensation to library diff --git a/apps/magnav/lib.js b/apps/magnav/lib.js new file mode 100644 index 000000000..e3fe8fccb --- /dev/null +++ b/apps/magnav/lib.js @@ -0,0 +1,41 @@ +exports.calibrate = () => { + var max={x:-32000, y:-32000, z:-32000}, + min={x:32000, y:32000, z:32000}; + 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; + min.x = m.x { + 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}; + resolve({offset:offset,scale:scale}); + },20000); + }); +} + +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); + 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; +} diff --git a/apps/magnav/magnav_b1.js b/apps/magnav/magnav_b1.js index 739ff881f..0ec49014f 100644 --- a/apps/magnav/magnav_b1.js +++ b/apps/magnav/magnav_b1.js @@ -61,24 +61,7 @@ function newHeading(m,h){ var candraw = false; var CALIBDATA = require("Storage").readJSON("magnav.json",1)||null; - -function 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); - 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; -} +const tiltfixread = require("magnav").tiltfixread; // Note actual mag is 360-m, error in firmware function reading() { @@ -97,30 +80,6 @@ function reading() { flip(buf,Yoff+80); } -function calibrate(){ - var max={x:-32000, y:-32000, z:-32000}, - min={x:32000, y:32000, z:32000}; - 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; - min.x = m.x { - 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}; - resolve({offset:offset,scale:scale}); - },20000); - }); -} - var calibrating=false; function docalibrate(first){ calibrating=true; @@ -139,7 +98,7 @@ function docalibrate(first){ buf.drawString("Fig 8s to",120,0); buf.drawString("Calibrate",120,26); flip(buf,Yoff); - calibrate().then((r)=>{ + require("magnav").calibrate().then((r)=>{ CALIBDATA=r; require("Storage").write("magnav.json",r); restart() diff --git a/apps/magnav/metadata.json b/apps/magnav/metadata.json index cba9a1ac3..bd40a08fd 100644 --- a/apps/magnav/metadata.json +++ b/apps/magnav/metadata.json @@ -1,7 +1,7 @@ { "id": "magnav", "name": "Navigation Compass", - "version": "0.05", + "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", @@ -11,6 +11,7 @@ "storage": [ {"name":"magnav.app.js","url":"magnav_b1.js","supports":["BANGLEJS"]}, {"name":"magnav.app.js","url":"magnav_b2.js","supports":["BANGLEJS2"]}, + {"name":"magnav","url":"lib.js"}, {"name":"magnav.img","url":"magnav-icon.js","evaluate":true} ], "data": [{"name":"magnav.json"}] diff --git a/apps/waypointer/ChangeLog b/apps/waypointer/ChangeLog index 8613ef799..60e8bfab0 100644 --- a/apps/waypointer/ChangeLog +++ b/apps/waypointer/ChangeLog @@ -5,3 +5,4 @@ 0.05: Fix not displaying of wpindex = 0 0.06: Added adjustment for Bangle.js magnetometer heading fix 0.07: Add settings file with the option to disable the slow direction updates +0.08: Use tilt compensation from new magnav library diff --git a/apps/waypointer/app.js b/apps/waypointer/app.js index de6bfdcaa..40e4cf974 100644 --- a/apps/waypointer/app.js +++ b/apps/waypointer/app.js @@ -85,31 +85,22 @@ function newHeading(m,h){ } var CALIBDATA = require("Storage").readJSON("magnav.json",1) || {}; - -function tiltfixread(O,S){ - var m = Bangle.getCompass(); - if (O === undefined || S === undefined) { - // no valid calibration from magnav, use built in - return m.heading; - } - 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); - 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; +let tiltfixread; +try { + tiltfixread = require("magnav").tiltfixread; +} catch(e) { + // magnav not installed } // Note actual mag is 360-m, error in firmware function read_compass() { - var d = tiltfixread(CALIBDATA.offset,CALIBDATA.scale); + let d; + if (tiltfixread === undefined || CALIBDATA.offset === undefined || CALIBDATA.scale === undefined) { + // magnav not installed or no valid calibration, use built in + d = Bangle.getCompass().heading; + } else { + d = tiltfixread(CALIBDATA.offset,CALIBDATA.scale); + } if (isNaN(d)) return; // built in compass heading can return NaN when uncalibrated heading = newHeading(d,heading); direction = wp_bearing - heading; @@ -278,6 +269,9 @@ function doselect(){ wp = waypoints[wpindex]; require("waypoints").save(waypoints); } + if (selected) { + Bangle.resetCompass(); // reset built in compass when a waypoint is selected + } selected=!selected; drawN(); } @@ -294,6 +288,7 @@ Bangle.drawWidgets(); // load widgets can turn off GPS Bangle.setGPSPower(1); Bangle.setCompassPower(1); +Bangle.resetCompass() // reset built in compass on start in case we are not using tilt compensation drawAll(); startTimers(); Bangle.on('GPS', onGPS); diff --git a/apps/waypointer/metadata.json b/apps/waypointer/metadata.json index 0bbc42322..e21c5f10f 100644 --- a/apps/waypointer/metadata.json +++ b/apps/waypointer/metadata.json @@ -1,12 +1,12 @@ { "id": "waypointer", "name": "Way Pointer", - "version": "0.07", + "version": "0.08", "description": "Navigate to a waypoint using the GPS for bearing and compass to point way, uses the same waypoint interface as GPS Navigation", "icon": "waypointer.png", "tags": "tool,outdoors,gps", "supports": ["BANGLEJS", "BANGLEJS2"], - "dependencies" : { "waypoints":"type" }, + "dependencies" : { "waypoints":"type", "magnav" : "app" }, "readme": "README.md", "storage": [ {"name":"waypointer.app.js","url":"app.js"}, From fe491e2d09a70a24410033405ebc09acc9a53486 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 22 Jan 2023 11:01:44 +0100 Subject: [PATCH 16/16] magnav: Outsource tilt compensation to library --- apps/magnav/magnav_b2.js | 45 ++-------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/apps/magnav/magnav_b2.js b/apps/magnav/magnav_b2.js index e54280796..319860159 100644 --- a/apps/magnav/magnav_b2.js +++ b/apps/magnav/magnav_b2.js @@ -53,24 +53,7 @@ function newHeading(m,h){ var candraw = false; var CALIBDATA = require("Storage").readJSON("magnav.json",1)||null; - -function 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); - 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; -} +const tiltfixread = require("magnav").tiltfixread; // Note actual mag is 360-m, error in firmware function reading() { @@ -94,30 +77,6 @@ function reading() { g.flip(); } -function calibrate(){ - var max={x:-32000, y:-32000, z:-32000}, - min={x:32000, y:32000, z:32000}; - 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; - min.x = m.x { - 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}; - resolve({offset:offset,scale:scale}); - },20000); - }); -} - var calibrating=false; function docalibrate(first){ calibrating=true; @@ -137,7 +96,7 @@ function docalibrate(first){ g.drawString("Fig 8s to",88,Ypos); g.drawString("Calibrate",88,Ypos+18); g.flip(); - calibrate().then((r)=>{ + require("magnav").calibrate().then((r)=>{ CALIBDATA=r; require("Storage").write("magnav.json",r); restart();