From 89a8d9a0263404725e8a14468d8c120593acda0e Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 20:30:12 +0200 Subject: [PATCH 1/6] gpstrek - Differentiate between starting/stopping for usage and background --- apps/gpstrek/app.js | 6 +++--- apps/gpstrek/widget.js | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/gpstrek/app.js b/apps/gpstrek/app.js index 091c407fb..057d01388 100644 --- a/apps/gpstrek/app.js +++ b/apps/gpstrek/app.js @@ -7,7 +7,7 @@ if (showWidgets){ } let state = WIDGETS["gpstrek"].getState(); -WIDGETS["gpstrek"].start(); +WIDGETS["gpstrek"].start(false); function parseNumber(toParse){ if (toParse.includes(".")) return parseFloat(toParse); @@ -591,8 +591,8 @@ function showMenu(){ "Route" : showRouteMenu, "Waypoint" : showWaypointMenu, "Calibration": showCalibrationMenu, - "Start" : ()=>{ E.showPrompt("Start?").then((v)=>{ if (v) {state.active = true; removeMenu();} else {E.showMenu(mainmenu);}});}, - "Stop" : ()=>{ E.showPrompt("Stop?").then((v)=>{ if (v) {WIDGETS["gpstrek"].stop(); removeMenu();} else {E.showMenu(mainmenu);}});}, + "Start" : ()=>{ E.showPrompt("Start?").then((v)=>{ if (v) {WIDGETS["gpstrek"].start(true); removeMenu();} else {E.showMenu(mainmenu);}});}, + "Stop" : ()=>{ E.showPrompt("Stop?").then((v)=>{ if (v) {WIDGETS["gpstrek"].stop(true); removeMenu();} else {E.showMenu(mainmenu);}});}, "Reset" : ()=>{ E.showPrompt("Do Reset?").then((v)=>{ if (v) {WIDGETS["gpstrek"].resetState(); removeMenu();} else {E.showMenu(mainmenu);}});}, "Slices" : { value : numberOfSlices, diff --git a/apps/gpstrek/widget.js b/apps/gpstrek/widget.js index bba1298d0..acb8e016a 100644 --- a/apps/gpstrek/widget.js +++ b/apps/gpstrek/widget.js @@ -72,7 +72,7 @@ function onPressure(e) { } } -function start(){ +function start(bg){ Bangle.on('GPS', onGPS); Bangle.on("HRM", onPulse); Bangle.on("mag", onMag); @@ -83,13 +83,18 @@ function start(){ Bangle.setHRMPower(1, "gpstrek"); Bangle.setCompassPower(1, "gpstrek"); Bangle.setBarometerPower(1, "gpstrek"); - state.active = true; + if (bg){ + state.active = true; + saveState(); + } Bangle.drawWidgets(); } -function stop(){ - state.active = false; - saveState(); +function stop(bg){ + if (bg){ + state.active = false; + saveState(); + } Bangle.drawWidgets(); } From 50c3d764d9568253c5096c9e12259ce58cf31fb7 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 20:36:47 +0200 Subject: [PATCH 2/6] gpstrek - Make starting and stopping the background activity more explicit --- apps/gpstrek/app.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/gpstrek/app.js b/apps/gpstrek/app.js index 057d01388..0c3579d4b 100644 --- a/apps/gpstrek/app.js +++ b/apps/gpstrek/app.js @@ -6,8 +6,8 @@ if (showWidgets){ Bangle.loadWidgets(); } -let state = WIDGETS["gpstrek"].getState(); -WIDGETS["gpstrek"].start(false); +let state = WIDGETS.gpstrek.getState(); +WIDGETS.gpstrek.start(false); function parseNumber(toParse){ if (toParse.includes(".")) return parseFloat(toParse); @@ -582,6 +582,18 @@ function showWaypointMenu(){ E.showMenu(menu); } +function showBackgroundMenu(){ + let menu = { + "" : { + "title" : "Background", + back : showMenu, + }, + "Start" : ()=>{ E.showPrompt("Start?").then((v)=>{ if (v) {WIDGETS.gpstrek.start(true); removeMenu();} else {E.showMenu(mainmenu);}});}, + "Stop" : ()=>{ E.showPrompt("Stop?").then((v)=>{ if (v) {WIDGETS.gpstrek.stop(true); removeMenu();} else {E.showMenu(mainmenu);}});}, + }; + E.showMenu(menu); +} + function showMenu(){ var mainmenu = { "" : { @@ -590,10 +602,9 @@ function showMenu(){ }, "Route" : showRouteMenu, "Waypoint" : showWaypointMenu, + "Background" : showBackgroundMenu, "Calibration": showCalibrationMenu, - "Start" : ()=>{ E.showPrompt("Start?").then((v)=>{ if (v) {WIDGETS["gpstrek"].start(true); removeMenu();} else {E.showMenu(mainmenu);}});}, - "Stop" : ()=>{ E.showPrompt("Stop?").then((v)=>{ if (v) {WIDGETS["gpstrek"].stop(true); removeMenu();} else {E.showMenu(mainmenu);}});}, - "Reset" : ()=>{ E.showPrompt("Do Reset?").then((v)=>{ if (v) {WIDGETS["gpstrek"].resetState(); removeMenu();} else {E.showMenu(mainmenu);}});}, + "Reset" : ()=>{ E.showPrompt("Do Reset?").then((v)=>{ if (v) {WIDGETS.gpstrek.resetState(); removeMenu();} else {E.showMenu(mainmenu);}});}, "Slices" : { value : numberOfSlices, min:1,max:6,step:1, From f12c25cb784b0956118e01d3fa9e91db03eb7bc3 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 20:41:47 +0200 Subject: [PATCH 3/6] gpstrek - Bump version --- apps/gpstrek/ChangeLog | 1 + apps/gpstrek/metadata.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/gpstrek/ChangeLog b/apps/gpstrek/ChangeLog index 5560f00bc..2f1a9ce45 100644 --- a/apps/gpstrek/ChangeLog +++ b/apps/gpstrek/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: Make selection of background activity more explicit diff --git a/apps/gpstrek/metadata.json b/apps/gpstrek/metadata.json index 5168c870e..f0fe0c7e0 100644 --- a/apps/gpstrek/metadata.json +++ b/apps/gpstrek/metadata.json @@ -1,7 +1,7 @@ { "id": "gpstrek", "name": "GPS Trekking", - "version": "0.01", + "version": "0.02", "description": "Helper for tracking the status/progress during hiking. Do NOT depend on this for navigation!", "icon": "icon.png", "screenshots": [{"url":"screen1.png"},{"url":"screen2.png"},{"url":"screen3.png"},{"url":"screen4.png"}], From c2d55ab0312dafe143c4046d6058c3cfa2dce5dd Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 21:10:30 +0200 Subject: [PATCH 4/6] gpstrek - Adds state file as data --- apps/gpstrek/metadata.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/gpstrek/metadata.json b/apps/gpstrek/metadata.json index f0fe0c7e0..67f71566e 100644 --- a/apps/gpstrek/metadata.json +++ b/apps/gpstrek/metadata.json @@ -13,5 +13,6 @@ {"name":"gpstrek.app.js","url":"app.js"}, {"name":"gpstrek.wid.js","url":"widget.js"}, {"name":"gpstrek.img","url":"app-icon.js","evaluate":true} - ] + ], + "data": [{"name":"gpstrek.state.json"}] } From 6dbd99fdabe3d1c38a1ec31037b3ea3870e7ead5 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 21:13:07 +0200 Subject: [PATCH 5/6] gpstrek - Only store state file if needed --- apps/gpstrek/widget.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/gpstrek/widget.js b/apps/gpstrek/widget.js index acb8e016a..8d9831e06 100644 --- a/apps/gpstrek/widget.js +++ b/apps/gpstrek/widget.js @@ -1,6 +1,7 @@ (() => { const STORAGE=require('Storage'); let state = STORAGE.readJSON("gpstrek.state.json")||{}; +let bgChanged = false; function saveState(){ state.saved = Date.now(); @@ -8,7 +9,7 @@ function saveState(){ } E.on("kill",()=>{ - if (state.active){ + if (bgChanged){ saveState(); } }); @@ -84,6 +85,7 @@ function start(bg){ Bangle.setCompassPower(1, "gpstrek"); Bangle.setBarometerPower(1, "gpstrek"); if (bg){ + if (!state.active) bgChanged = true; state.active = true; saveState(); } @@ -92,6 +94,7 @@ function start(bg){ function stop(bg){ if (bg){ + if (state.active) bgChanged = true; state.active = false; saveState(); } @@ -112,7 +115,7 @@ if (state.saved && state.saved < Date.now() - 60000){ } if (state.active){ - start(); + start(false); } WIDGETS["gpstrek"]={ From 453885fccd12f3ee546aada676cd2313a68cfa4b Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 21:22:30 +0200 Subject: [PATCH 6/6] gpstrek - Update readme --- apps/gpstrek/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/gpstrek/README.md b/apps/gpstrek/README.md index eecf4d087..439b7497a 100644 --- a/apps/gpstrek/README.md +++ b/apps/gpstrek/README.md @@ -39,5 +39,9 @@ If the compass fallback starts to show unreliable values, you can reset the cali ## Widget -The widget keeps the sensors alive and records some very basic statics when the app is not started. -This uses a lot of power so ensure to stop the app if you are not actively using it. +The widget keeps the sensors alive and records some very basic statistics when the app is not started. It shows as the app icon in the widget bar when the background task is active. +This uses a lot of power so ensure to stop the app if you are not actively using it. + +# Creator + +[halemmerich](https://github.com/halemmerich)