diff --git a/apps/lcars/ChangeLog b/apps/lcars/ChangeLog index 7d8fecb1e..08b3b3d4d 100644 --- a/apps/lcars/ChangeLog +++ b/apps/lcars/ChangeLog @@ -15,4 +15,5 @@ 0.15: Using wpedom to count steps. 0.16: Improved stability. Wind can now be shown. 0.17: Settings for mph/kph and other minor improvements. -0.18: Fullscreen mode can now be enabled or disabled in the settings. \ No newline at end of file +0.18: Fullscreen mode can now be enabled or disabled in the settings. +0.19: Use widtmr for alarm functionality instead of own implementation. \ No newline at end of file diff --git a/apps/lcars/README.md b/apps/lcars/README.md index f979b2304..cf360d647 100644 --- a/apps/lcars/README.md +++ b/apps/lcars/README.md @@ -15,7 +15,7 @@ with Gadgetbride and the weather app must be installed. * Tab on left/right to switch between different screens. * Cusomizable data that is shown on screen 1 (steps, weather etc.) * Shows random and real images of planets. - * Tap on top/bottom of screen 1 to activate an alarm. + * Tap on top/bottom of screen 1 to activate an alarm. Depends on widtmr. * The lower orange line indicates the battery level. * Display graphs (day or month) for steps + hrm on the second screen. @@ -36,8 +36,9 @@ Access different screens via tap on the left/ right side of the screen ![](screenshot_1.png) ![](screenshot_2.png) +## Creator +- [David Peer](https://github.com/peerdavid) ## Contributors -- [David Peer](https://github.com/peerdavid). -- [Adam Schmalhofer](https://github.com/adamschmalhofer). -- [Jon Warrington](https://github.com/BartokW). +- [Adam Schmalhofer](https://github.com/adamschmalhofer) +- [Jon Warrington](https://github.com/BartokW) diff --git a/apps/lcars/lcars.app.js b/apps/lcars/lcars.app.js index 7d5da2d8e..13c163e26 100644 --- a/apps/lcars/lcars.app.js +++ b/apps/lcars/lcars.app.js @@ -480,9 +480,6 @@ function draw(){ // Queue draw first to ensure that its called in one minute again. queueDraw(); - // First handle alarm to show this correctly afterwards - handleAlarm(); - // Next draw the watch face g.reset(); g.clearRect(0, 0, g.getWidth(), g.getHeight()); @@ -561,43 +558,21 @@ function getWeather(){ /* * Handle alarm */ -function getCurrentTimeInMinutes(){ - return Math.floor(Date.now() / (1000*60)); -} - function isAlarmEnabled(){ - return settings.alarm >= 0; + return WIDGETS["widtmr"].isStarted(); } function getAlarmMinutes(){ - var currentTime = getCurrentTimeInMinutes(); - return settings.alarm - currentTime; + return WIDGETS["widtmr"].getRemainingMinutes(); } -function handleAlarm(){ - if(!isAlarmEnabled()){ - return; - } +function increaseAlarm(){ + WIDGETS["widtmr"].increaseTimer(5); + WIDGETS["widtmr"].setStarted(true); +} - if(getAlarmMinutes() > 0){ - return; - } - - // Alarm - var t = 300; - Bangle.buzz(t, 1) - .then(() => new Promise(resolve => setTimeout(resolve, t))) - .then(() => Bangle.buzz(t, 1)) - .then(() => new Promise(resolve => setTimeout(resolve, t))) - .then(() => Bangle.buzz(t, 1)) - .then(() => new Promise(resolve => setTimeout(resolve, t))) - .then(() => Bangle.buzz(t, 1)) - .then(() => new Promise(resolve => setTimeout(resolve, 5E3))) - .then(() => { - // Update alarm state to disabled - settings.alarm = -1; - storage.writeJSON(SETTINGS_FILE, settings); - }); +function decreaseAlarm(){ + WIDGETS["widtmr"].decreaseTimer(5); } @@ -625,26 +600,6 @@ Bangle.on('charging',function(charging) { }); -function increaseAlarm(){ - if(isAlarmEnabled()){ - settings.alarm += 5; - } else { - settings.alarm = getCurrentTimeInMinutes() + 5; - } - - storage.writeJSON(SETTINGS_FILE, settings); -} - - -function decreaseAlarm(){ - if(isAlarmEnabled() && (settings.alarm-5 > getCurrentTimeInMinutes())){ - settings.alarm -= 5; - } else { - settings.alarm = -1; - } - - storage.writeJSON(SETTINGS_FILE, settings); -} function feedback(){ Bangle.buzz(40, 0.3); diff --git a/apps/lcars/metadata.json b/apps/lcars/metadata.json index e6ca10f79..5efd29e7c 100644 --- a/apps/lcars/metadata.json +++ b/apps/lcars/metadata.json @@ -3,8 +3,9 @@ "name": "LCARS Clock", "shortName":"LCARS", "icon": "lcars.png", - "version":"0.18", + "version":"0.19", "readme": "README.md", + "dependencies": {"widtmr":"app"}, "supports": ["BANGLEJS2"], "description": "Library Computer Access Retrieval System (LCARS) clock.", "type": "clock", diff --git a/apps/notanalog/ChangeLog b/apps/notanalog/ChangeLog index 574d46609..bb5297476 100644 --- a/apps/notanalog/ChangeLog +++ b/apps/notanalog/ChangeLog @@ -1,3 +1,4 @@ 0.01: Launch app. 0.02: 12k steps are 360 degrees - improves readability of steps. -0.03: Battery improvements through sleep (no minute updates) and partial updates of drawing. \ No newline at end of file +0.03: Battery improvements through sleep (no minute updates) and partial updates of drawing. +0.04: Use widtmr widget for timer instead of own alarm implementation. \ No newline at end of file diff --git a/apps/notanalog/README.md b/apps/notanalog/README.md index 2928fd959..3a0963090 100644 --- a/apps/notanalog/README.md +++ b/apps/notanalog/README.md @@ -8,8 +8,8 @@ black one the battery level (100% = 360 degrees). The selected theme is also respected. Note that this watch face is in fullscreen mode, but widgets are still loaded in background. -## Other features -- Set a timer - simply touch top (+5min.) or bottom (-5 min.). +## Other Features +- Set a timer - simply touch top (+5min.) or bottom (-5 min.) - depends on widtmr. - If the weather is available through the weather app, the outside temp. will be shown. - Sleep modus at midnight to save more battery (no minute updates). - Icons for charging and GPS. @@ -29,5 +29,5 @@ which helped a lot for this development. Icons from by Freepik - Flaticon -## Contributors +## Creator - [David Peer](https://github.com/peerdavid). \ No newline at end of file diff --git a/apps/notanalog/metadata.json b/apps/notanalog/metadata.json index 5efb6bccf..5a0ddbaf0 100644 --- a/apps/notanalog/metadata.json +++ b/apps/notanalog/metadata.json @@ -3,10 +3,11 @@ "name": "Not Analog", "shortName":"Not Analog", "icon": "notanalog.png", - "version":"0.03", + "version":"0.04", "readme": "README.md", "supports": ["BANGLEJS2"], "description": "An analog watch face for people that can not read analog watch faces.", + "dependencies": {"widtmr":"app"}, "type": "clock", "tags": "clock", "screenshots": [ diff --git a/apps/notanalog/notanalog.app.js b/apps/notanalog/notanalog.app.js index cea8072b8..be9a01fa7 100644 --- a/apps/notanalog/notanalog.app.js +++ b/apps/notanalog/notanalog.app.js @@ -291,7 +291,6 @@ function drawSleep(){ function draw(fastUpdate){ // Execute handlers handleState(fastUpdate); - handleAlarm(); if(state.sleep){ drawSleep(); @@ -388,71 +387,28 @@ function queueDraw() { /* * Handle alarm */ -function getCurrentTimeInMinutes(){ - return Math.floor(Date.now() / (1000*60)); -} - function isAlarmEnabled(){ - return settings.alarm >= 0; + return WIDGETS["widtmr"].isStarted(); } function getAlarmMinutes(){ - var currentTime = getCurrentTimeInMinutes(); - return settings.alarm - currentTime; + return WIDGETS["widtmr"].getRemainingMinutes(); } -function handleAlarm(){ - if(!isAlarmEnabled()){ - return; - } - - if(getAlarmMinutes() > 0){ - return; - } - - // Alarm - var t = 300; - Bangle.buzz(t, 1) - .then(() => new Promise(resolve => setTimeout(resolve, t))) - .then(() => Bangle.buzz(t, 1)) - .then(() => new Promise(resolve => setTimeout(resolve, t))) - .then(() => Bangle.buzz(t, 1)) - .then(() => new Promise(resolve => setTimeout(resolve, t))) - .then(() => Bangle.buzz(t, 1)) - .then(() => new Promise(resolve => setTimeout(resolve, 5E3))) - .then(() => { - // Update alarm state to disabled - settings.alarm = -1; - storage.writeJSON(SETTINGS_FILE, settings); - }); -} - - function increaseAlarm(){ - if(isAlarmEnabled()){ - settings.alarm += 5; - } else { - settings.alarm = getCurrentTimeInMinutes() + 5; - } - - storage.writeJSON(SETTINGS_FILE, settings); + WIDGETS["widtmr"].increaseTimer(5); + WIDGETS["widtmr"].setStarted(true); } - function decreaseAlarm(){ - if(isAlarmEnabled() && (settings.alarm-5 > getCurrentTimeInMinutes())){ - settings.alarm -= 5; - } else { - settings.alarm = -1; - } - - storage.writeJSON(SETTINGS_FILE, settings); + WIDGETS["widtmr"].decreaseTimer(5); } function feedback(){ Bangle.buzz(40, 0.6); } + /* * Lets start widgets, listen for btn etc. */ diff --git a/apps/widtmr/README.md b/apps/widtmr/README.md index 0694a13cc..6820b74d0 100644 --- a/apps/widtmr/README.md +++ b/apps/widtmr/README.md @@ -1,4 +1,4 @@ -# Simple Chronometer Widget +# Timer Widget This is a fork of the Chrono Widget, but implements a simpler UI which to be able to set a timer faster with @@ -6,7 +6,17 @@ less interaction. Additionally, it exposes some functions that can be used by other apps or clocks to easily implement a timer. It is used e.g. by lcars or notanalog. -# Contributors -Originally from [Purple-Tentacle](https://github.com/Purple-Tentacle) +# Lib +Different functions are exposed to integrate a timer +into your own app. -Forked and adapted by [David Peer](https://github.com/peerdavid) \ No newline at end of file +Example: +```Javascript +WIDGETS["widtmr"].isStarted(); +WIDGETS["widtmr"].reload(); +WIDGETS["widtmr"].getRemainingMinutes(); +``` +# Creator + +[David Peer](https://github.com/peerdavid) + forked from [Purple-Tentacle](https://github.com/Purple-Tentacle) diff --git a/apps/widtmr/app.js b/apps/widtmr/app.js index 311e0d3ea..5f836d417 100644 --- a/apps/widtmr/app.js +++ b/apps/widtmr/app.js @@ -1,4 +1,6 @@ /* + * TIMER WIDGET + * * This is a fork of the Chrono Widget, but implements a * simpler UI which to be able to set a timer faster with * less interaction. Additionally, it exposes some functions @@ -18,7 +20,7 @@ let settings; const screenWidth = g.getWidth(); const screenHeight = g.getHeight(); const cx = parseInt(screenWidth/2); -const cy = parseInt(screenHeight/2); +const cy = parseInt(screenHeight/2)-12; function updateSettings() { diff --git a/apps/widtmr/widget.js b/apps/widtmr/widget.js index c918a52e1..127217364 100644 --- a/apps/widtmr/widget.js +++ b/apps/widtmr/widget.js @@ -34,6 +34,18 @@ } + function updateSettings(){ + var now = new Date(); + const goal = new Date(now.getFullYear(), now.getMonth(), now.getDate(), + now.getHours(), now.getMinutes() + settings.minutes, now.getSeconds()); + settings.goal = goal.getTime(); + + settings.goal = goal.getTime(); + storage.writeJSON('widtmr.json', settings); + WIDGETS["widtmr"].reload(); + } + + /* * Add the widgets and functions for other apps */ @@ -92,6 +104,32 @@ }, isStarted: function(){ settings = storage.readJSON("widtmr.json",1)||{started: false}; return settings.started; + + }, setStarted: function(started){ + settings.started=started; + updateSettings(); + + }, increaseTimer: function(m){ + settings.minutes += m; + updateSettings(); + + }, decreaseTimer: function(m){ + settings.minutes -= m; + if(settings.minutes <= 0){ + settings.started=false; + settings.minutes=0; + } + updateSettings(); + + }, getRemainingMinutes: function(){ + settings = storage.readJSON("widtmr.json",1)||{started: false}; + if(!settings.started){ + return -1; + } + + var now = new Date(); + var diff = settings.goal - now; + return Math.floor(diff / (1000*60)); } };