For watch faces we want to start at 0 rather than the last value that was set...

master
David Peer 2022-02-26 09:36:29 +01:00
parent ef31fd4f01
commit 777943e031
4 changed files with 31 additions and 6 deletions

View File

@ -567,6 +567,11 @@ function getAlarmMinutes(){
} }
function increaseAlarm(){ function increaseAlarm(){
// Set to zero if alarm was disabled before
if(!isAlarmEnabled()){
WIDGETS["widtmr"].resetTimer();
}
WIDGETS["widtmr"].increaseTimer(5); WIDGETS["widtmr"].increaseTimer(5);
WIDGETS["widtmr"].setStarted(true); WIDGETS["widtmr"].setStarted(true);
} }

View File

@ -396,6 +396,10 @@ function getAlarmMinutes(){
} }
function increaseAlarm(){ function increaseAlarm(){
if(!isAlarmEnabled()){
WIDGETS["widtmr"].resetTimer();
}
WIDGETS["widtmr"].increaseTimer(5); WIDGETS["widtmr"].increaseTimer(5);
WIDGETS["widtmr"].setStarted(true); WIDGETS["widtmr"].setStarted(true);
} }

View File

@ -22,25 +22,36 @@ into your own app.
The following functions are available: The following functions are available:
- isStarted() -> boolean - isStarted() -> boolean
- setStarted(boolean) -> void - setStarted(boolean) -> void
- resetTimer() -> void
- increaseTimer(int) -> void - increaseTimer(int) -> void
- decreaseTimer(int) -> void - decreaseTimer(int) -> void
- getRemainingMinutes() -> int - getRemainingMinutes() -> int
- getRemainingTime() -> DateTime - getRemainingTime() -> DateTime
- getRemainingTimeStr() -> str - getRemainingTimeStr() -> str
Example to increase the timer by 5 and ensure that its started: For example if we want to increase the timer by +5 minutes each time
the touch event is fired:
```Javascript ```Javascript
Bangle.loadWidgets(); Bangle.loadWidgets();
... ...
WIDGETS["widtmr"].increaseTimer(5); Bangle.on('touch', function(btn, e){
WIDGETS["widtmr"].setStarted(true); // Set to zero if alarm was disabled before
if(!isAlarmEnabled()){
WIDGETS["widtmr"].resetTimer();
}
WIDGETS["widtmr"].increaseTimer(5);
WIDGETS["widtmr"].setStarted(true);
});
``` ```
Example to decrease the timer. This also disables the timer if time <= 0.: Example to decrease the timer by 5 and stop if 0 is reached:
```Javascript ```Javascript
Bangle.loadWidgets(); Bangle.loadWidgets();
... ...
WIDGETS["widtmr"].decreaseTimer(5); Bangle.on('touch', function(btn, e){
WIDGETS["widtmr"].decreaseTimer(5);
}
``` ```
# Creator # Creator

View File

@ -121,6 +121,11 @@
} }
updateSettings(); updateSettings();
}, resetTimer: function(){
settings.started=false;
settings.minutes = 0;
updateSettings();
}, getRemainingMinutes: function(){ }, getRemainingMinutes: function(){
settings = storage.readJSON("widtmr.json",1)||{started: false}; settings = storage.readJSON("widtmr.json",1)||{started: false};
if(!settings.started){ if(!settings.started){
@ -129,7 +134,7 @@
var now = new Date(); var now = new Date();
var diff = settings.goal - now; var diff = settings.goal - now;
return Math.ceil(diff / (1000*60)); return Math.round(diff / (1000*60));
}, getRemainingTimeStr: function(){ }, getRemainingTimeStr: function(){
settings = storage.readJSON("widtmr.json",1)||{started: false}; settings = storage.readJSON("widtmr.json",1)||{started: false};