Merge pull request #2175 from halemmerich/gpstrek

gpstrek - Improve background/widget handling
pull/2176/head
Gordon Williams 2022-10-14 08:25:51 +01:00 committed by GitHub
commit e7a0e1a40f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 16 deletions

View File

@ -1 +1,2 @@
0.01: New App!
0.02: Make selection of background activity more explicit

View File

@ -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)

View File

@ -6,8 +6,8 @@ if (showWidgets){
Bangle.loadWidgets();
}
let state = WIDGETS["gpstrek"].getState();
WIDGETS["gpstrek"].start();
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) {state.active = true; removeMenu();} else {E.showMenu(mainmenu);}});},
"Stop" : ()=>{ E.showPrompt("Stop?").then((v)=>{ if (v) {WIDGETS["gpstrek"].stop(); 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,

View File

@ -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"}],
@ -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"}]
}

View File

@ -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();
}
});
@ -72,7 +73,7 @@ function onPressure(e) {
}
}
function start(){
function start(bg){
Bangle.on('GPS', onGPS);
Bangle.on("HRM", onPulse);
Bangle.on("mag", onMag);
@ -83,13 +84,20 @@ function start(){
Bangle.setHRMPower(1, "gpstrek");
Bangle.setCompassPower(1, "gpstrek");
Bangle.setBarometerPower(1, "gpstrek");
state.active = true;
if (bg){
if (!state.active) bgChanged = true;
state.active = true;
saveState();
}
Bangle.drawWidgets();
}
function stop(){
state.active = false;
saveState();
function stop(bg){
if (bg){
if (state.active) bgChanged = true;
state.active = false;
saveState();
}
Bangle.drawWidgets();
}
@ -107,7 +115,7 @@ if (state.saved && state.saved < Date.now() - 60000){
}
if (state.active){
start();
start(false);
}
WIDGETS["gpstrek"]={