Improved smpltmr clock info to be not specialiset for bw clock.

master
David Peer 2022-10-02 14:30:13 +02:00
parent 3809c91f1f
commit ae84bc9a18
4 changed files with 127 additions and 125 deletions

View File

@ -217,7 +217,7 @@ function drawCursor(){
} }
function drawCmd(cmd){ function drawCmd(cmd){
var c = 0; var c = 0;
var x = 10; var x = 10;
var y = 28; var y = 28;
@ -236,38 +236,38 @@ function drawCursor(){
g.setColor(g.theme.fg); g.setColor(g.theme.fg);
g.drawString(cmd, x+c, y); g.drawString(cmd, x+c, y);
} }
function twoD(str){ function twoD(str){
return ("0" + str).slice(-2) return ("0" + str).slice(-2)
} }
/************************************************ /************************************************
* Listener * Listener
*/ */
// timeout used to update every minute // timeout used to update every minute
var drawTimeout; var drawTimeout;
// schedule a draw for the next minute // schedule a draw for the next minute
function queueDraw() { function queueDraw() {
if (drawTimeout) clearTimeout(drawTimeout); if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = setTimeout(function() { drawTimeout = setTimeout(function() {
drawTimeout = undefined; drawTimeout = undefined;
draw(); draw();
}, 60000 - (Date.now() % 60000)); }, 60000 - (Date.now() % 60000));
} }
// Stop updates when LCD is off, restart when on // Stop updates when LCD is off, restart when on
Bangle.on('lcdPower',on=>{ Bangle.on('lcdPower',on=>{
if (on) { if (on) {
draw(); // draw immediately, queue redraw draw(); // draw immediately, queue redraw
} else { // stop draw timer } else { // stop draw timer
if (drawTimeout) clearTimeout(drawTimeout); if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined; drawTimeout = undefined;
} }
}); });
Bangle.on('lock', function(isLocked) { Bangle.on('lock', function(isLocked) {
@ -275,7 +275,7 @@ Bangle.on('lock', function(isLocked) {
}); });
Bangle.on('charging',function(charging) { Bangle.on('charging',function(charging) {
if (drawTimeout) clearTimeout(drawTimeout); if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined; drawTimeout = undefined;
@ -283,11 +283,11 @@ Bangle.on('lock', function(isLocked) {
settings.menuPosY=0; settings.menuPosY=0;
draw(); draw();
}); });
var lock_input = 0; var lock_input = 0;
Bangle.on('touch', function(btn, e){ Bangle.on('touch', function(btn, e){
if(lock_input > 0){ if(lock_input > 0){
return; return;
} }
@ -357,15 +357,15 @@ Bangle.on('lock', function(isLocked) {
} }
draw(); draw();
}); });
E.on("kill", function(){ E.on("kill", function(){
try{ try{
storage.write(SETTINGS_FILE, settings); storage.write(SETTINGS_FILE, settings);
} catch(ex){ } catch(ex){
// If this fails, we still kill the app... // If this fails, we still kill the app...
} }
}); });
/************************************************ /************************************************

View File

@ -1,3 +1,4 @@
0.01: Release 0.01: Release
0.02: Rewrite with new interface 0.02: Rewrite with new interface
0.03: Added clock infos to expose timer functionality to clocks. 0.03: Added clock infos to expose timer functionality to clocks.
0.04: Improvements of clock infos.

View File

@ -69,7 +69,7 @@
img: img, img: img,
items: [ items: [
{ {
name: "Timer", name: null,
get: () => ({ text: getAlarmMinutesText() + (isAlarmEnabled() ? " min" : ""), img: null}), get: () => ({ text: getAlarmMinutesText() + (isAlarmEnabled() ? " min" : ""), img: null}),
show: function() { smpltmrItems.items[0].emit("redraw"); }, show: function() { smpltmrItems.items[0].emit("redraw"); },
hide: function () {}, hide: function () {},
@ -78,17 +78,18 @@
] ]
}; };
var offsets = [+1,+5,-1,-5]; var offsets = [+5,-5];
offsets.forEach((o, i) => { offsets.forEach((o, i) => {
smpltmrItems.items = smpltmrItems.items.concat({ smpltmrItems.items = smpltmrItems.items.concat({
name: String(o), name: null,
get: () => ({ text: getAlarmMinutesText() + " (" + (o > 0 ? "+" : "") + o + ")", img: null}), get: () => ({ text: (o > 0 ? "+" : "") + o + " min.", img: null}),
show: function() { smpltmrItems.items[i+1].emit("redraw"); }, show: function() { smpltmrItems.items[i+1].emit("redraw"); },
hide: function () {}, hide: function () {},
run: function() { run: function() {
if(o > 0) increaseAlarm(o); if(o > 0) increaseAlarm(o);
else decreaseAlarm(Math.abs(o)); else decreaseAlarm(Math.abs(o));
this.show(); this.show();
return true;
} }
}); });
}); });

View File

@ -2,7 +2,7 @@
"id": "smpltmr", "id": "smpltmr",
"name": "Simple Timer", "name": "Simple Timer",
"shortName": "Simple Timer", "shortName": "Simple Timer",
"version": "0.03", "version": "0.04",
"description": "A very simple app to start a timer.", "description": "A very simple app to start a timer.",
"icon": "app.png", "icon": "app.png",
"tags": "tool,alarm,timer", "tags": "tool,alarm,timer",