From 3a591b85d79d4fac6074beb554972c8d1eb6d2b9 Mon Sep 17 00:00:00 2001 From: hughbarney Date: Tue, 9 Mar 2021 21:28:32 +0000 Subject: [PATCH] stepo BTN2 switches to launcher --- apps/stepo/ChangeLog | 2 +- apps/stepo/README.md | 9 ++++++++- apps/stepo/app.js | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/apps/stepo/ChangeLog b/apps/stepo/ChangeLog index c91dc7abd..c94954969 100644 --- a/apps/stepo/ChangeLog +++ b/apps/stepo/ChangeLog @@ -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 diff --git a/apps/stepo/README.md b/apps/stepo/README.md index 86f462ca2..26531c121 100644 --- a/apps/stepo/README.md +++ b/apps/stepo/README.md @@ -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 diff --git a/apps/stepo/app.js b/apps/stepo/app.js index 1e6ca7b53..e3f7092f1 100644 --- a/apps/stepo/app.js +++ b/apps/stepo/app.js @@ -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"});