diff --git a/apps/smpltmr/ChangeLog b/apps/smpltmr/ChangeLog index 55c5fc4f6..2e8589304 100644 --- a/apps/smpltmr/ChangeLog +++ b/apps/smpltmr/ChangeLog @@ -9,3 +9,6 @@ 0.09: Timer ClockInfo resets to timer menu when blurred 0.10: Timer ClockInfo now uses +- icons, and changes timer from 'T-5 min' to just '5 min' to aid readability 0.11: Fix to handle updated firmware on fw 2v25 (or cutting edge >2v24.164), btn -> btnRelease. The timer would fire on long press before the watch reset. +0.12: Fix ClockInfo so it updates after leaving +5min/etc by blurring + ClockInfo now shows time left in icon, updates more often the closer to the time + Tapping clockinfo adds 1 min, added +30min option too \ No newline at end of file diff --git a/apps/smpltmr/clkinfo.js b/apps/smpltmr/clkinfo.js index 6fc2cd265..1ff40b041 100644 --- a/apps/smpltmr/clkinfo.js +++ b/apps/smpltmr/clkinfo.js @@ -1,60 +1,23 @@ (function() { - const TIMER_IDX = "smpltmr"; - var alarm = require('sched'); + const TIMER_IDX = "smpltmr", alarm = require('sched'); - function isAlarmEnabled(){ - try{ - - var alarmObj = alarm.getAlarm(TIMER_IDX); - if(alarmObj===undefined || !alarmObj.on){ - return false; - } - - return true; - - } catch(ex){ } - return false; + function getAlarm() { + var alarmObj = alarm.getAlarm(TIMER_IDX), + min = (alarmObj && alarmObj.on) ? alarm.getTimeToAlarm(alarmObj)/(60*1000) : 0; + return { + minutes : min, + text : min ? ((min<1) ? "<1" : Math.round(min)) + /*LANG*/" min" : /*LANG*/"OFF", + max : alarmObj?alarmObj.timer/60000:1 + }; } - function getAlarmMinutes(){ - if(!isAlarmEnabled()){ - return -1; - } - var alarmObj = alarm.getAlarm(TIMER_IDX); - return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000)); - } - - function getAlarmMinutesText(){ - var min = getAlarmMinutes(); - if(min < 0) - return "OFF"; - return min + " min"; - } - - function increaseAlarm(t){ - try{ - var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0; - alarm.setAlarm(TIMER_IDX, { - timer : (minutes+t)*60*1000, - }); - alarm.reload(); - } catch(ex){ } - } - - function decreaseAlarm(t){ - try{ - var minutes = getAlarmMinutes(); - minutes -= t; - - alarm.setAlarm(TIMER_IDX, undefined); - if(minutes > 0){ - alarm.setAlarm(TIMER_IDX, { - timer : minutes*60*1000, - }); - } - - alarm.reload(); - } catch(ex){ } + function changeAlarm(t) { + var minutes = Math.round(getAlarm().minutes) + t; + alarm.setAlarm(TIMER_IDX, undefined); + if(minutes > 0) + alarm.setAlarm(TIMER_IDX, { timer : minutes*60000 }); + alarm.reload(); + return true; } var smpltmrItems = { @@ -63,35 +26,50 @@ items: [ { name: null, - get: () => ({ text: getAlarmMinutesText(), img: smpltmrItems.img } ), - show: function() { this.interval = setInterval(()=>this.emit('redraw'), 60000); }, - hide: function () { clearInterval(this.interval); delete this.interval; }, - //run: function() { } // should tapping do something? + get: function() { + var alm = getAlarm(); + if (alm.minutes > 0) { // draw an icon showing actual progress (don't ever go 100% as looks odd) + if (this.uses) { + if (this.timeout) clearTimeout(this.timeout); + this.timeout = setTimeout(()=>{ + this.emit('redraw'); + delete this.timeout; + }, alm.minutes<3 ? 2000 : (alm.minutes < 30 ? 30000 : 60000)); + } + var gr = Graphics.createArrayBuffer(24,24,1), poly = [11.5,13.5], s=Math.sin,c=Math.cos, a = Math.min(alm.minutes * Math.PI*2 / alm.max,5.5); + for (var i=0;i { + let onBlur = function(clkinfo) { clkinfo.setItem(clkinfo.menuA,0); }; // change back to menu + [-5,-30].forEach(o => { smpltmrItems.items = smpltmrItems.items.concat({ name: null, - get: () => ({ text: (o > 0 ? "+" : "") + o + " min", img: (o>0)?atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgYGBgYGDAYDDAYDDH/jDH/jDAYDDAYDBgYGBgYGAwAMA4AcAeB4AH/gAB+AA=="):atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgAGBgAGDAADDAADDH/jDH/jDAADDAADBgAGBgAGAwAMA4AcAeB4AH/gAB+AA==") }), - show: function() { }, - hide: function() { }, - blur: restoreMainItem, - run: function() { - if(o > 0) increaseAlarm(o); - else decreaseAlarm(Math.abs(o)); - this.show(); - return true; - } + get: () => ({ text: o + /*LANG*/" min", img: atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgAGBgAGDAADDAADDH/jDH/jDAADDAADBgAGBgAGAwAMA4AcAeB4AH/gAB+AA==") }), + show: function() {}, + hide: function() {}, + blur: onBlur, run: changeAlarm.bind(null,o) + }); + }); + [+30,+5].forEach(o => { + smpltmrItems.items = smpltmrItems.items.concat({ + name: null, + get: () => ({ text: "+" + o + /*LANG*/" min", img: atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgYGBgYGDAYDDAYDDH/jDH/jDAYDDAYDBgYGBgYGAwAMA4AcAeB4AH/gAB+AA==") }), + show: function() {}, + hide: function() {}, + blur: onBlur, run: changeAlarm.bind(null,o) }); }); return smpltmrItems; -}) +}) \ No newline at end of file diff --git a/apps/smpltmr/metadata.json b/apps/smpltmr/metadata.json index 93205e3df..11c9eec05 100644 --- a/apps/smpltmr/metadata.json +++ b/apps/smpltmr/metadata.json @@ -2,7 +2,7 @@ "id": "smpltmr", "name": "Simple Timer", "shortName": "Simple Timer", - "version": "0.11", + "version": "0.12", "description": "A very simple app to start a timer.", "icon": "app.png", "tags": "tool,alarm,timer,clkinfo",