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(){
// Set to zero if alarm was disabled before
if(!isAlarmEnabled()){
WIDGETS["widtmr"].resetTimer();
}
WIDGETS["widtmr"].increaseTimer(5);
WIDGETS["widtmr"].setStarted(true);
}

View File

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

View File

@ -22,25 +22,36 @@ into your own app.
The following functions are available:
- isStarted() -> boolean
- setStarted(boolean) -> void
- resetTimer() -> void
- increaseTimer(int) -> void
- decreaseTimer(int) -> void
- getRemainingMinutes() -> int
- getRemainingTime() -> DateTime
- 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
Bangle.loadWidgets();
...
WIDGETS["widtmr"].increaseTimer(5);
WIDGETS["widtmr"].setStarted(true);
Bangle.on('touch', function(btn, e){
// 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
Bangle.loadWidgets();
...
WIDGETS["widtmr"].decreaseTimer(5);
Bangle.on('touch', function(btn, e){
WIDGETS["widtmr"].decreaseTimer(5);
}
```
# Creator

View File

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