diff --git a/apps/bwclk/ChangeLog b/apps/bwclk/ChangeLog index 967062223..ae95e8ae7 100644 --- a/apps/bwclk/ChangeLog +++ b/apps/bwclk/ChangeLog @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/apps/bwclk/README.md b/apps/bwclk/README.md index 3f177d6fa..dfb9bf515 100644 --- a/apps/bwclk/README.md +++ b/apps/bwclk/README.md @@ -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* diff --git a/apps/bwclk/app.js b/apps/bwclk/app.js index 577014130..8cd81cbd7 100644 --- a/apps/bwclk/app.js +++ b/apps/bwclk/app.js @@ -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. diff --git a/apps/bwclk/metadata.json b/apps/bwclk/metadata.json index 1eb1fde72..0f9836a42 100644 --- a/apps/bwclk/metadata.json +++ b/apps/bwclk/metadata.json @@ -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", diff --git a/apps/bwclk/screenshot_3.png b/apps/bwclk/screenshot_3.png index f9a9a7d3f..8d982cac4 100644 Binary files a/apps/bwclk/screenshot_3.png and b/apps/bwclk/screenshot_3.png differ