presentation_timer: merged save state feature from stopwatch

master
Gabriele Monaco 2023-01-17 09:48:39 +01:00
parent 150e79e11d
commit 4368d66c00
2 changed files with 36 additions and 6 deletions

View File

@ -13,5 +13,8 @@
{"name":"presentation_timer.app.js","url":"presentation_timer.app.js"},
{"name":"presentation_timer.img","url":"presentation_timer.icon.js","evaluate":true}
],
"data": [{ "name": "presentation_timer.csv" }]
"data": [
{"name":"presentation_timer.json"}
{ "name": "presentation_timer.csv" }
]
}

View File

@ -1,9 +1,21 @@
const CONFIGFILE = "presentation_timer.json";
const now = Date.now();
const config = Object.assign({
state: {
total: now,
start: now,
current: now,
running: false,
}
}, require("Storage").readJSON(CONFIGFILE,1) || {});
let w = g.getWidth();
let h = g.getHeight();
let tTotal = Date.now();
let tStart = tTotal;
let tCurrent = tTotal;
let running = false;
let tTotal = config.state.total;
let tStart = config.state.start;
let tCurrent = config.state.current;
let running = config.state.running;
let timeY = 2*h/5;
let displayInterval;
let redrawButtons = true;
@ -15,6 +27,14 @@ const pause_img = atob("GBiBAf////////////////wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wY
const play_img = atob("GBjBAP//AAAAAAAAAAAIAAAOAAAPgAAP4AAP+AAP/AAP/wAP/8AP//AP//gP//gP//AP/8AP/wAP/AAP+AAP4AAPgAAOAAAIAAAAAAAAAAA=");
const reset_img = atob("GBiBAf////////////AAD+AAB+f/5+f/5+f/5+cA5+cA5+cA5+cA5+cA5+cA5+cA5+cA5+f/5+f/5+f/5+AAB/AAD////////////w==");
function saveState() {
config.state.total = tTotal;
config.state.start = tStart;
config.state.current = tCurrent;
config.state.running = running;
require("Storage").writeJSON(CONFIGFILE, config);
}
const margin = 0.5; //half a minute tolerance
//dummy default values
@ -147,6 +167,7 @@ function stopStart() {
} else {
draw();
}
saveState();
}
function setButtonImages() {
@ -171,6 +192,7 @@ function lapReset() {
g.clearRect(0,24,w,h);
draw();
}
saveState();
}
// simple on screen button class
@ -268,5 +290,10 @@ g.fillRect(0,0,w,h);
Bangle.loadWidgets();
Bangle.drawWidgets();
readSlides();
setButtonImages();
if (running) {
startTimer();
} else {
draw();
}
setWatch(() => load(), BTN, { repeat: false, edge: "falling" });