Here's the solution I have come up with for turning the BTN2 short press into a long press. I start a timer and when I have held the button long enough I make the Bangle buzz, then I can release the button. If the button is released too early there is no buzz. I cancell the timer on release of BTN2. This works quite nicely, it mean you just hold BTN2 until the buzz then release. This will stop going into the launcher by accidently catching BTN2 with your sleeve etc. But it still allows you to get into the launcher if you want to.
// 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;
}
}
var pressTimer;
// 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"});
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Here's the solution I have come up with for turning the BTN2 short press into a long press. I start a timer and when I have held the button long enough I make the Bangle buzz, then I can release the button. If the button is released too early there is no buzz. I cancell the timer on release of BTN2. This works quite nicely, it mean you just hold BTN2 until the buzz then release. This will stop going into the launcher by accidently catching BTN2 with your sleeve etc. But it still allows you to get into the launcher if you want to.