stepo BTN2 switches to launcher

pull/685/head
hughbarney 2021-03-09 21:28:32 +00:00
parent 72c60dbfa7
commit 3a591b85d7
3 changed files with 41 additions and 3 deletions

View File

@ -1,2 +1,2 @@
0.01: First version
0.02: Speeded up first draw, ensure timer is stopped and started depending on screen event
0.02: Speeded up draw, start stop timer, long press BTN2 to switch to the launcher

View File

@ -10,6 +10,7 @@ A large font watch, displays step count in a doughnut guage and warns of low bat
- The guage show percentage of steps out of a goal of 10000 steps
![](screenshot1.jpg)
- When the battery is less than 25% the doughnut turns red
@ -17,8 +18,14 @@ A large font watch, displays step count in a doughnut guage and warns of low bat
![](screenshot2.jpg)
# Notes
## BTN2 Long press to start the launcher
BTN2 is confiured to respond to a 1.5 second press in order to switch
to the launcher App. Simply press and hold until you hear a buzz and
release. This avoids accidently switching out of the watch app when
clothing catches it.
## Notes
* Uses an arrayBuffer to prepare the doughnut guage. The arrayBuffer
is 160*160 and is larger than required. The reason for this is that

View File

@ -108,9 +108,40 @@ Bangle.on('lcdPower', function(on) {
stopTimer();
});
let firstPress = 0;
var pressTimer;
// start a timer and buzz whenn held long enough
function firstPressed() {
firstPress = getTime();
pressTimer = setInterval(longPressCheck, 1500);
}
// if you release too soon there is no buzz as timer is cleared
function thenReleased() {
var dur = getTime() - firstPress;
if (pressTimer) {
clearInterval(pressTimer);
pressTimer = undefined;
}
if ( dur >= 1.5 ) Bangle.showLauncher();
}
// when you feel the buzzer you know you have done a long press
function longPressCheck() {
Bangle.buzz();
if (pressTimer) {
clearInterval(pressTimer);
pressTimer = undefined;
}
}
// make BTN require a long press (1.5 seconds) to switch to launcher
setWatch(firstPressed, BTN2,{repeat:true,edge:"rising"});
setWatch(thenReleased, BTN2,{repeat:true,edge:"falling"});
g.reset();
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
startTimer();
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});