Added clockinfo to simple timer and improved the clkinfo module (run with optional feedback).

pull/2143/head
David Peer 2022-09-23 16:08:16 +02:00
parent 59d63885fa
commit c362881de1
10 changed files with 113 additions and 9 deletions

View File

@ -19,4 +19,5 @@
0.19: Fix - Compatibility with "Digital clock widget" 0.19: Fix - Compatibility with "Digital clock widget"
0.20: Better handling of async data such as getPressure. 0.20: Better handling of async data such as getPressure.
0.21: On the default menu the week of year can be shown. 0.21: On the default menu the week of year can be shown.
0.22: Use the new clkinfo module for the menu. 0.22: Use the new clkinfo module for the menu.
0.23: Feedback of apps after run is now optional and decided by the corresponding clkinfo.

View File

@ -164,8 +164,10 @@ function runMenuItem(){
var menuEntry = menu[settings.menuPosX]; var menuEntry = menu[settings.menuPosX];
var item = menuEntry.items[settings.menuPosY-1]; var item = menuEntry.items[settings.menuPosY-1];
try{ try{
item.run(); var ret = item.run();
Bangle.buzz(300, 0.6).then(() => {}); if(ret){
Bangle.buzz(300, 0.6);
}
} catch (ex) { } catch (ex) {
// Simply ignore it... // Simply ignore it...
} }

View File

@ -1,7 +1,7 @@
{ {
"id": "bwclk", "id": "bwclk",
"name": "BW Clock", "name": "BW Clock",
"version": "0.22", "version": "0.23",
"description": "A very minimalistic clock to mainly show date and time.", "description": "A very minimalistic clock to mainly show date and time.",
"readme": "README.md", "readme": "README.md",
"icon": "app.png", "icon": "app.png",

View File

@ -1,3 +1,4 @@
0.01: Release 0.01: Release
0.02: Includeas the ha.lib.js library that can be used by other apps or clocks. 0.02: Includeas the ha.lib.js library that can be used by other apps or clocks.
0.03: Added clkinfo for clocks. 0.03: Added clkinfo for clocks.
0.04: Feedback if clkinfo run is called.

View File

@ -17,6 +17,7 @@
run: function() { run: function() {
ha.sendTrigger("TRIGGER_BW"); ha.sendTrigger("TRIGGER_BW");
ha.sendTrigger(trigger.trigger); ha.sendTrigger(trigger.trigger);
return true;
} }
}); });
}); });

View File

@ -1,7 +1,7 @@
{ {
"id": "ha", "id": "ha",
"name": "HomeAssistant", "name": "HomeAssistant",
"version": "0.03", "version": "0.04",
"description": "Integrates your BangleJS into HomeAssistant.", "description": "Integrates your BangleJS into HomeAssistant.",
"icon": "ha.png", "icon": "ha.png",
"type": "app", "type": "app",

View File

@ -1,2 +1,3 @@
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.

97
apps/smpltmr/clkinfo.js Normal file
View File

@ -0,0 +1,97 @@
(function() {
const TIMER_IDX = "smpltmr";
function isAlarmEnabled(){
try{
var alarm = require('sched');
var alarmObj = alarm.getAlarm(TIMER_IDX);
if(alarmObj===undefined || !alarmObj.on){
return false;
}
return true;
} catch(ex){ }
return false;
}
function getAlarmMinutes(){
if(!isAlarmEnabled()){
return -1;
}
var alarm = require('sched');
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 "T-" + String(min);
}
function increaseAlarm(t){
try{
var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
var alarm = require('sched')
alarm.setAlarm(TIMER_IDX, {
timer : (minutes+t)*60*1000,
});
alarm.reload();
} catch(ex){ }
}
function decreaseAlarm(t){
try{
var minutes = getAlarmMinutes();
minutes -= t;
var alarm = require('sched')
alarm.setAlarm(TIMER_IDX, undefined);
if(minutes > 0){
alarm.setAlarm(TIMER_IDX, {
timer : minutes*60*1000,
});
}
alarm.reload();
} catch(ex){ }
}
var img = atob("GBiBAeAAB+AAB/v/3/v/3/v/3/v/3/v/n/n/H/z+P/48//85//+b//+b//8p//4E//yCP/kBH/oAn/oAX/oAX/oAX/oAX+AAB+AABw==")
var smpltmrItems = {
name: "Timer",
img: img,
items: [
{
name: "Timer",
get: () => ({ text: getAlarmMinutesText() + (isAlarmEnabled() ? " min" : ""), img: null}),
show: function() { smpltmrItems.items[0].emit("redraw"); },
hide: function () {},
run: function() { }
},
]
};
var offsets = [+1,+5,-1,-5];
offsets.forEach((o, i) => {
smpltmrItems.items = smpltmrItems.items.concat({
name: String(o),
get: () => ({ text: getAlarmMinutesText() + " (" + (o > 0 ? "+" : "") + o + ")", img: null}),
show: function() { smpltmrItems.items[i+1].emit("redraw"); },
hide: function () {},
run: function() {
if(o > 0) increaseAlarm(o);
else decreaseAlarm(Math.abs(o));
this.show();
}
});
});
return smpltmrItems;
})

View File

@ -2,7 +2,7 @@
"id": "smpltmr", "id": "smpltmr",
"name": "Simple Timer", "name": "Simple Timer",
"shortName": "Simple Timer", "shortName": "Simple Timer",
"version": "0.02", "version": "0.03",
"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",
@ -12,6 +12,7 @@
"readme": "README.md", "readme": "README.md",
"storage": [ "storage": [
{"name":"smpltmr.app.js","url":"app.js"}, {"name":"smpltmr.app.js","url":"app.js"},
{"name":"smpltmr.clkinfo.js","url":"clkinfo.js"},
{"name":"smpltmr.img","url":"app-icon.js","evaluate":true} {"name":"smpltmr.img","url":"app-icon.js","evaluate":true}
] ]
} }

View File

@ -18,7 +18,7 @@ Note that each item is an object with:
* 'item.show' : called when item should be shown. Enables updates. Call BEFORE 'get' * 'item.show' : called when item should be shown. Enables updates. Call BEFORE 'get'
* 'item.hide' : called when item should be hidden. Disables updates. * 'item.hide' : called when item should be hidden. Disables updates.
* .on('redraw', ...) : event that is called when 'get' should be called again (only after 'item.show') * .on('redraw', ...) : event that is called when 'get' should be called again (only after 'item.show')
* 'item.run' : (optional) called if the info screen is tapped - can perform some action * 'item.run' : (optional) called if the info screen is tapped - can perform some action. Return true if the caller should feedback the user.
See the bottom of this file for example usage... See the bottom of this file for example usage...