Merge pull request #2100 from peerdavid/master

[BWClock] Set timer for agenda entries
master
Gordon Williams 2022-09-05 10:31:12 +01:00 committed by GitHub
commit 2bf4b82526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 97 additions and 21 deletions

View File

@ -14,4 +14,5 @@
0.14: Adds humidity to weather data.
0.15: Added option for a dynamic mode to show widgets only if unlocked.
0.16: You can now show your agenda if your calendar is synced with Gadgetbridge.
0.17: Fix - Step count was no more shown in the menu.
0.17: Fix - Step count was no more shown in the menu.
0.18: Set timer for an agenda entry by simply clicking in the middle of the screen. Only one timer can be set.

View File

@ -7,7 +7,7 @@ A very minimalistic clock to mainly show date and time.
The BW clock provides many features and also 3rd party integrations:
- Bangle data such as steps, heart rate, battery or charging state.
- A timer can be set directly. *Requirement: Scheduler library*
- Show agenda entries. *Requirement: Gadgetbridge calendar sync enabled*
- Show agenda entries. A timer for an agenda entry can also be set by simply clicking in the middle of the screen. This can be used to not forget a meeting etc. Note that only one agenda-timer can be set at a time. *Requirement: Gadgetbridge calendar sync enabled*
- Weather temperature as well as the wind speed can be shown. *Requirement: Weather app*
- HomeAssistant triggers can be executed directly. *Requirement: HomeAssistant app*

View File

@ -8,10 +8,16 @@ const storage = require('Storage');
* Statics
*/
const SETTINGS_FILE = "bwclk.setting.json";
const TIMER_IDX = "bwclk";
const TIMER_IDX = "bwclk_timer";
const TIMER_AGENDA_IDX = "bwclk_agenda";
const W = g.getWidth();
const H = g.getHeight();
/************
* Global data
*/
var pressureData;
/************
* Settings
*/
@ -181,6 +187,14 @@ function imgAgenda() {
}
}
function imgMountain() {
return {
width : 24, height : 24, bpp : 1,
transparent : 1,
buffer : atob("//////////////////////3///n///D//uZ//E8//A+/+Z+f8//P5//n7//3z//zn//5AAAAAAAA////////////////////")
}
}
/************
* 2D MENU with entries of:
* [name, icon, opt[customDownFun], opt[customUpFun], opt[customCenterFun]]
@ -195,6 +209,7 @@ var menu = [
function(){ return [ E.getBattery() + "%", Bangle.isCharging() ? imgCharging() : imgBattery() ] },
function(){ return [ getSteps(), imgSteps() ] },
function(){ return [ Math.round(Bangle.getHealthStatus("last").bpm) + " bpm", imgBpm()] },
function(){ return [ getAltitude(), imgMountain() ]},
]
]
@ -205,8 +220,8 @@ try{
require('sched');
menu.push([
function(){
var text = isAlarmEnabled() ? getAlarmMinutes() + " min." : "Timer";
return [text, imgTimer(), () => decreaseAlarm(), () => increaseAlarm(), null ]
var text = isAlarmEnabled(TIMER_IDX) ? getAlarmMinutes(TIMER_IDX) + " min." : "Timer";
return [text, imgTimer(), () => decreaseAlarm(TIMER_IDX), () => increaseAlarm(TIMER_IDX), null ]
},
]);
} catch(ex) {
@ -219,6 +234,7 @@ try{
* Note that we handle the agenda differently in order to hide old entries...
*/
var agendaIdx = 0;
var agendaTimerIdx = 0;
if(storage.readJSON("android.calendar.json") !== undefined){
function nextAgendaEntry(){
agendaIdx += 1;
@ -246,9 +262,43 @@ if(storage.readJSON("android.calendar.json") !== undefined){
var title = entry.title.slice(0,14);
var date = new Date(entry.timestamp*1000);
var dateStr = locale.date(date).replace(/\d\d\d\d/,"");
dateStr += entry.durationInSeconds < 86400 ? " / " + locale.time(date,1) : "";
dateStr += entry.durationInSeconds < 86400 ? "/ " + locale.time(date,1) : "";
return [title + "\n" + dateStr, imgAgenda(), () => nextAgendaEntry(), () => previousAgendaEntry(), null]
function dynImgAgenda(){
if(isAlarmEnabled(TIMER_AGENDA_IDX) && agendaTimerIdx == agendaIdx){
return imgTimer();
} else {
return imgAgenda();
}
}
return [title + "\n" + dateStr, dynImgAgenda(), () => nextAgendaEntry(), () => previousAgendaEntry(), function(){
try{
var alarm = require('sched')
// If other time, we disable the old one and enable this one.
if(agendaIdx != agendaTimerIdx){
agendaTimerIdx = -1;
alarm.setAlarm(TIMER_AGENDA_IDX, undefined);
}
// Disable alarm if enabled
if(isAlarmEnabled(TIMER_AGENDA_IDX)){
agendaTimerIdx = -1;
alarm.setAlarm(TIMER_AGENDA_IDX, undefined);
alarm.reload();
return
}
// Otherwise, set alarm for given event
agendaTimerIdx = agendaIdx;
alarm.setAlarm(TIMER_AGENDA_IDX, {
msg: title,
timer : parseInt((date - now)),
});
alarm.reload();
} catch(ex){ }
}]
},
]);
}
@ -330,6 +380,14 @@ function getSteps() {
}
function getAltitude(){
if(pressureData && pressureData.altitude){
return Math.round(pressureData.altitude) + "m";
}
return "???";
}
function getWeather(){
var weatherJson;
@ -364,10 +422,10 @@ function getWeather(){
}
function isAlarmEnabled(){
function isAlarmEnabled(idx){
try{
var alarm = require('sched');
var alarmObj = alarm.getAlarm(TIMER_IDX);
var alarmObj = alarm.getAlarm(idx);
if(alarmObj===undefined || !alarmObj.on){
return false;
}
@ -379,22 +437,22 @@ function isAlarmEnabled(){
}
function getAlarmMinutes(){
if(!isAlarmEnabled()){
function getAlarmMinutes(idx){
if(!isAlarmEnabled(idx)){
return -1;
}
var alarm = require('sched');
var alarmObj = alarm.getAlarm(TIMER_IDX);
var alarmObj = alarm.getAlarm(idx);
return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000));
}
function increaseAlarm(){
function increaseAlarm(idx){
try{
var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
var alarm = require('sched')
alarm.setAlarm(TIMER_IDX, {
var minutes = isAlarmEnabled(idx) ? getAlarmMinutes(idx) : 0;
var alarm = require('sched');
alarm.setAlarm(idx, {
timer : (minutes+5)*60*1000,
});
alarm.reload();
@ -402,16 +460,16 @@ function increaseAlarm(){
}
function decreaseAlarm(){
function decreaseAlarm(idx){
try{
var minutes = getAlarmMinutes();
var minutes = getAlarmMinutes(idx);
minutes -= 5;
var alarm = require('sched')
alarm.setAlarm(TIMER_IDX, undefined);
alarm.setAlarm(idx, undefined);
if(minutes > 0){
alarm.setAlarm(TIMER_IDX, {
alarm.setAlarm(idx, {
timer : minutes*60*1000,
});
}
@ -421,6 +479,19 @@ function decreaseAlarm(){
}
function handleAsyncData(){
try{
if (settings.menuPosX == 1){
Bangle.getPressure().then(data=>{
pressureData = data
});
}
}catch(ex){ }
}
/************
* DRAW
*/
@ -428,6 +499,9 @@ function draw() {
// Queue draw again
queueDraw();
// Now lets measure some data..
handleAsyncData();
// Draw clock
drawDate();
drawTime();
@ -670,6 +744,7 @@ Bangle.on('touch', function(btn, e){
menuEntry[4]();
setTimeout(()=>{
Bangle.buzz(80, 0.6);
drawTime();
}, 250);
} catch(ex){
// In case it fails, we simply ignore it.

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB