mirror of https://github.com/espruino/BangleApps
stlap: slow down javascript when the user's not watching
parent
8702b35045
commit
16d4dc7588
|
@ -157,7 +157,7 @@ function firstTimeStart(now, time) {
|
||||||
elapsedTime: 0,
|
elapsedTime: 0,
|
||||||
};
|
};
|
||||||
lapFile = 'stlap-' + state.sessionStart + '.json';
|
lapFile = 'stlap-' + state.sessionStart + '.json';
|
||||||
setupTimerInterval();
|
setupTimerIntervalFast();
|
||||||
Bangle.buzz(200);
|
Bangle.buzz(200);
|
||||||
drawButtons();
|
drawButtons();
|
||||||
}
|
}
|
||||||
|
@ -201,13 +201,15 @@ function start(now, time) {
|
||||||
state.elapsedTime += (state.pausedTime - state.startTime);
|
state.elapsedTime += (state.pausedTime - state.startTime);
|
||||||
state.startTime = now;
|
state.startTime = now;
|
||||||
state.running = true;
|
state.running = true;
|
||||||
setupTimerInterval();
|
setupTimerIntervalFast();
|
||||||
Bangle.buzz(200);
|
Bangle.buzz(200);
|
||||||
drawTime();
|
drawTime();
|
||||||
drawButtons();
|
drawButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
Bangle.on("touch", (button, xy) => {
|
Bangle.on("touch", (button, xy) => {
|
||||||
|
setupTimerIntervalFast();
|
||||||
|
|
||||||
//In gesture mode, just turn on the light and then return
|
//In gesture mode, just turn on the light and then return
|
||||||
if (gestureMode) {
|
if (gestureMode) {
|
||||||
Bangle.setLCDPower(true);
|
Bangle.setLCDPower(true);
|
||||||
|
@ -242,6 +244,8 @@ Bangle.on("touch", (button, xy) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Bangle.on('swipe', direction => {
|
Bangle.on('swipe', direction => {
|
||||||
|
setupTimerIntervalFast();
|
||||||
|
|
||||||
let now = (new Date()).getTime();
|
let now = (new Date()).getTime();
|
||||||
let time = getTime();
|
let time = getTime();
|
||||||
|
|
||||||
|
@ -272,12 +276,23 @@ setWatch(() => {
|
||||||
}, BTN1, { repeat: true });
|
}, BTN1, { repeat: true });
|
||||||
|
|
||||||
let timerInterval;
|
let timerInterval;
|
||||||
|
let userWatching = false;
|
||||||
|
|
||||||
|
function setupTimerIntervalFast() {
|
||||||
|
userWatching = true;
|
||||||
|
setupTimerInterval();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
userWatching = false;
|
||||||
|
setupTimerInterval();
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
function setupTimerInterval() {
|
function setupTimerInterval() {
|
||||||
if (timerInterval !== undefined) {
|
if (timerInterval !== undefined) {
|
||||||
clearInterval(timerInterval);
|
clearInterval(timerInterval);
|
||||||
}
|
}
|
||||||
timerInterval = setInterval(drawTime, 10);
|
timerInterval = setInterval(drawTime, userWatching ? 10 : 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopTimerInterval() {
|
function stopTimerInterval() {
|
||||||
|
@ -289,7 +304,7 @@ function stopTimerInterval() {
|
||||||
|
|
||||||
drawTime();
|
drawTime();
|
||||||
if (state.running) {
|
if (state.running) {
|
||||||
setupTimerInterval();
|
setupTimerIntervalFast();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save our state when the app is closed
|
//Save our state when the app is closed
|
||||||
|
@ -300,5 +315,8 @@ E.on('kill', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// change interval depending of whether the user's looking
|
||||||
|
Bangle.on("twist", setupTimerIntervalFast);
|
||||||
|
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
Loading…
Reference in New Issue