1
0
Fork 0

Torch: Change start sequence to BTN1/3/1/3 to avoid accidental turning on (fix #342)

master
Gordon Williams 2020-04-23 10:28:42 +01:00
parent bf5bf91967
commit a389ed5dbe
3 changed files with 19 additions and 10 deletions

View File

@ -921,8 +921,8 @@
"name": "Torch",
"shortName":"Torch",
"icon": "app.png",
"version":"0.01",
"description": "Turns screen white to help you see in the dark. Select from the launcher or press BTN3 four times in quick succession to start when in normal clock mode",
"version":"0.02",
"description": "Turns screen white to help you see in the dark. Select from the launcher or press BTN1,BTN3,BTN1,BTN3 quickly to start when in any app that shows widgets",
"tags": "tool,torch",
"storage": [
{"name":"torch.app.js","url":"app.js"},

View File

@ -1 +1,2 @@
0.01: New App!
0.02: Change start sequence to BTN1/3/1/3 to avoid accidental turning on (fix #342)

View File

@ -1,18 +1,26 @@
(function() {
var clickTimes = [];
var CLICK_COUNT = 4; // number of taps
var CLICK_PERIOD = 1; // second
var clickPattern = "";
var TAPS = 4; // number of taps
var PERIOD = 1; // seconds
// we don't actually create/draw a widget here at all...
Bangle.on("lcdPower",function(on) {
// First click (that turns LCD on) isn't given to
// setWatch, so handle it here
if (on) clickTimes=[getTime()];
if (!on) return;
clickTimes=[getTime()];
clickPattern="x";
});
setWatch(function(e) {
while (clickTimes.length>=CLICK_COUNT) clickTimes.shift();
function tap(e,c) {
clickPattern = clickPattern.substr(-3)+c;
while (clickTimes.length>=TAPS) clickTimes.shift();
clickTimes.push(e.time);
var clickPeriod = e.time-clickTimes[0];
if (clickTimes.length==CLICK_COUNT && clickPeriod<CLICK_PERIOD)
if (clickPeriod<PERIOD && clickPattern.match(/.313/)) {
load("torch.app.js");
}, BTN3, {repeat:true, edge:"rising"});
}
}
setWatch(function(e) { tap(e,"1"); }, BTN1, {repeat:true, edge:"rising"});
setWatch(function(e) { tap(e,"3"); }, BTN3, {repeat:true, edge:"rising"});
})();