Expose timer functions for other apps. Updated notanalog and lcars to use this lib.

master
David Peer 2022-02-25 17:55:47 +01:00
parent a03fdec826
commit b8215908a6
11 changed files with 85 additions and 119 deletions

View File

@ -16,3 +16,4 @@
0.16: Improved stability. Wind can now be shown. 0.16: Improved stability. Wind can now be shown.
0.17: Settings for mph/kph and other minor improvements. 0.17: Settings for mph/kph and other minor improvements.
0.18: Fullscreen mode can now be enabled or disabled in the settings. 0.18: Fullscreen mode can now be enabled or disabled in the settings.
0.19: Use widtmr for alarm functionality instead of own implementation.

View File

@ -15,7 +15,7 @@ with Gadgetbride and the weather app must be installed.
* Tab on left/right to switch between different screens. * Tab on left/right to switch between different screens.
* Cusomizable data that is shown on screen 1 (steps, weather etc.) * Cusomizable data that is shown on screen 1 (steps, weather etc.)
* Shows random and real images of planets. * 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. * The lower orange line indicates the battery level.
* Display graphs (day or month) for steps + hrm on the second screen. * 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_1.png)
![](screenshot_2.png) ![](screenshot_2.png)
## Creator
- [David Peer](https://github.com/peerdavid)
## Contributors ## Contributors
- [David Peer](https://github.com/peerdavid). - [Adam Schmalhofer](https://github.com/adamschmalhofer)
- [Adam Schmalhofer](https://github.com/adamschmalhofer). - [Jon Warrington](https://github.com/BartokW)
- [Jon Warrington](https://github.com/BartokW).

View File

@ -480,9 +480,6 @@ function draw(){
// Queue draw first to ensure that its called in one minute again. // Queue draw first to ensure that its called in one minute again.
queueDraw(); queueDraw();
// First handle alarm to show this correctly afterwards
handleAlarm();
// Next draw the watch face // Next draw the watch face
g.reset(); g.reset();
g.clearRect(0, 0, g.getWidth(), g.getHeight()); g.clearRect(0, 0, g.getWidth(), g.getHeight());
@ -561,43 +558,21 @@ function getWeather(){
/* /*
* Handle alarm * Handle alarm
*/ */
function getCurrentTimeInMinutes(){
return Math.floor(Date.now() / (1000*60));
}
function isAlarmEnabled(){ function isAlarmEnabled(){
return settings.alarm >= 0; return WIDGETS["widtmr"].isStarted();
} }
function getAlarmMinutes(){ function getAlarmMinutes(){
var currentTime = getCurrentTimeInMinutes(); return WIDGETS["widtmr"].getRemainingMinutes();
return settings.alarm - currentTime;
} }
function handleAlarm(){ function increaseAlarm(){
if(!isAlarmEnabled()){ WIDGETS["widtmr"].increaseTimer(5);
return; WIDGETS["widtmr"].setStarted(true);
} }
if(getAlarmMinutes() > 0){ function decreaseAlarm(){
return; WIDGETS["widtmr"].decreaseTimer(5);
}
// 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);
});
} }
@ -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(){ function feedback(){
Bangle.buzz(40, 0.3); Bangle.buzz(40, 0.3);

View File

@ -3,8 +3,9 @@
"name": "LCARS Clock", "name": "LCARS Clock",
"shortName":"LCARS", "shortName":"LCARS",
"icon": "lcars.png", "icon": "lcars.png",
"version":"0.18", "version":"0.19",
"readme": "README.md", "readme": "README.md",
"dependencies": {"widtmr":"app"},
"supports": ["BANGLEJS2"], "supports": ["BANGLEJS2"],
"description": "Library Computer Access Retrieval System (LCARS) clock.", "description": "Library Computer Access Retrieval System (LCARS) clock.",
"type": "clock", "type": "clock",

View File

@ -1,3 +1,4 @@
0.01: Launch app. 0.01: Launch app.
0.02: 12k steps are 360 degrees - improves readability of steps. 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. 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.

View File

@ -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 The selected theme is also respected. Note that this watch face is in fullscreen
mode, but widgets are still loaded in background. mode, but widgets are still loaded in background.
## Other features ## Other Features
- Set a timer - simply touch top (+5min.) or bottom (-5 min.). - 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. - 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). - Sleep modus at midnight to save more battery (no minute updates).
- Icons for charging and GPS. - Icons for charging and GPS.
@ -29,5 +29,5 @@ which helped a lot for this development.
Icons from <a href="https://www.flaticon.com/free-icons" title="icons">by Freepik - Flaticon</a> Icons from <a href="https://www.flaticon.com/free-icons" title="icons">by Freepik - Flaticon</a>
## Contributors ## Creator
- [David Peer](https://github.com/peerdavid). - [David Peer](https://github.com/peerdavid).

View File

@ -3,10 +3,11 @@
"name": "Not Analog", "name": "Not Analog",
"shortName":"Not Analog", "shortName":"Not Analog",
"icon": "notanalog.png", "icon": "notanalog.png",
"version":"0.03", "version":"0.04",
"readme": "README.md", "readme": "README.md",
"supports": ["BANGLEJS2"], "supports": ["BANGLEJS2"],
"description": "An analog watch face for people that can not read analog watch faces.", "description": "An analog watch face for people that can not read analog watch faces.",
"dependencies": {"widtmr":"app"},
"type": "clock", "type": "clock",
"tags": "clock", "tags": "clock",
"screenshots": [ "screenshots": [

View File

@ -291,7 +291,6 @@ function drawSleep(){
function draw(fastUpdate){ function draw(fastUpdate){
// Execute handlers // Execute handlers
handleState(fastUpdate); handleState(fastUpdate);
handleAlarm();
if(state.sleep){ if(state.sleep){
drawSleep(); drawSleep();
@ -388,71 +387,28 @@ function queueDraw() {
/* /*
* Handle alarm * Handle alarm
*/ */
function getCurrentTimeInMinutes(){
return Math.floor(Date.now() / (1000*60));
}
function isAlarmEnabled(){ function isAlarmEnabled(){
return settings.alarm >= 0; return WIDGETS["widtmr"].isStarted();
} }
function getAlarmMinutes(){ function getAlarmMinutes(){
var currentTime = getCurrentTimeInMinutes(); return WIDGETS["widtmr"].getRemainingMinutes();
return settings.alarm - currentTime;
} }
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(){ function increaseAlarm(){
if(isAlarmEnabled()){ WIDGETS["widtmr"].increaseTimer(5);
settings.alarm += 5; WIDGETS["widtmr"].setStarted(true);
} else {
settings.alarm = getCurrentTimeInMinutes() + 5;
}
storage.writeJSON(SETTINGS_FILE, settings);
} }
function decreaseAlarm(){ function decreaseAlarm(){
if(isAlarmEnabled() && (settings.alarm-5 > getCurrentTimeInMinutes())){ WIDGETS["widtmr"].decreaseTimer(5);
settings.alarm -= 5;
} else {
settings.alarm = -1;
}
storage.writeJSON(SETTINGS_FILE, settings);
} }
function feedback(){ function feedback(){
Bangle.buzz(40, 0.6); Bangle.buzz(40, 0.6);
} }
/* /*
* Lets start widgets, listen for btn etc. * Lets start widgets, listen for btn etc.
*/ */

View File

@ -1,4 +1,4 @@
# Simple Chronometer Widget # Timer Widget
This is a fork of the Chrono Widget, but implements a This is a fork of the Chrono Widget, but implements a
simpler UI which to be able to set a timer faster with 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 that can be used by other apps or clocks to easily
implement a timer. It is used e.g. by lcars or notanalog. implement a timer. It is used e.g. by lcars or notanalog.
# Contributors # Lib
Originally from [Purple-Tentacle](https://github.com/Purple-Tentacle) Different functions are exposed to integrate a timer
into your own app.
Forked and adapted by [David Peer](https://github.com/peerdavid) 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)

View File

@ -1,4 +1,6 @@
/* /*
* TIMER WIDGET
*
* This is a fork of the Chrono Widget, but implements a * This is a fork of the Chrono Widget, but implements a
* simpler UI which to be able to set a timer faster with * simpler UI which to be able to set a timer faster with
* less interaction. Additionally, it exposes some functions * less interaction. Additionally, it exposes some functions
@ -18,7 +20,7 @@ let settings;
const screenWidth = g.getWidth(); const screenWidth = g.getWidth();
const screenHeight = g.getHeight(); const screenHeight = g.getHeight();
const cx = parseInt(screenWidth/2); const cx = parseInt(screenWidth/2);
const cy = parseInt(screenHeight/2); const cy = parseInt(screenHeight/2)-12;
function updateSettings() { function updateSettings() {

View File

@ -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 * Add the widgets and functions for other apps
*/ */
@ -92,6 +104,32 @@
}, isStarted: function(){ }, isStarted: function(){
settings = storage.readJSON("widtmr.json",1)||{started: false}; settings = storage.readJSON("widtmr.json",1)||{started: false};
return settings.started; 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));
} }
}; };