diff --git a/apps/stlap/ChangeLog b/apps/stlap/ChangeLog index 35ba8b130..0c21e6efd 100644 --- a/apps/stlap/ChangeLog +++ b/apps/stlap/ChangeLog @@ -1,3 +1,4 @@ 0.01: New app! 0.02: Bug fixes -0.03: Submitted to the app loader \ No newline at end of file +0.03: Submitted to the app loader +0.04: Reduce battery consumption when the user's not looking \ No newline at end of file diff --git a/apps/stlap/app.js b/apps/stlap/app.js index 0bd18311f..ad5463180 100644 --- a/apps/stlap/app.js +++ b/apps/stlap/app.js @@ -8,7 +8,7 @@ const BUTTON_ICONS = { reset: heatshrink.decompress(atob("jEYwMA/4BB/+BAQPDAQPnAQIAKv///0///8j///EP//wAQQICBwQUCEhgyCHAQ+CIgI=")) }; -let state = storage.readJSON(STATE_PATH); +let state = storage.readJSON(STATE_PATH, 1); const STATE_DEFAULT = { wasRunning: false, //If the stopwatch was ever running since being reset sessionStart: 0, //When the stopwatch was first started @@ -157,7 +157,7 @@ function firstTimeStart(now, time) { elapsedTime: 0, }; lapFile = 'stlap-' + state.sessionStart + '.json'; - setupTimerInterval(); + setupTimerIntervalFast(); Bangle.buzz(200); drawButtons(); } @@ -201,13 +201,15 @@ function start(now, time) { state.elapsedTime += (state.pausedTime - state.startTime); state.startTime = now; state.running = true; - setupTimerInterval(); + setupTimerIntervalFast(); Bangle.buzz(200); drawTime(); drawButtons(); } Bangle.on("touch", (button, xy) => { + setupTimerIntervalFast(); + //In gesture mode, just turn on the light and then return if (gestureMode) { Bangle.setLCDPower(true); @@ -242,6 +244,8 @@ Bangle.on("touch", (button, xy) => { }); Bangle.on('swipe', direction => { + setupTimerIntervalFast(); + let now = (new Date()).getTime(); let time = getTime(); @@ -272,12 +276,23 @@ setWatch(() => { }, BTN1, { repeat: true }); let timerInterval; +let userWatching = false; + +function setupTimerIntervalFast() { + userWatching = true; + setupTimerInterval(); + + setTimeout(() => { + userWatching = false; + setupTimerInterval(); + }, 5000); +} function setupTimerInterval() { if (timerInterval !== undefined) { clearInterval(timerInterval); } - timerInterval = setInterval(drawTime, 10); + timerInterval = setInterval(drawTime, userWatching ? 10 : 1000); } function stopTimerInterval() { @@ -289,7 +304,7 @@ function stopTimerInterval() { drawTime(); if (state.running) { - setupTimerInterval(); + setupTimerIntervalFast(); } //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.drawWidgets(); \ No newline at end of file diff --git a/apps/stlap/metadata.json b/apps/stlap/metadata.json index 1ecdc5b6e..ac846dfd7 100644 --- a/apps/stlap/metadata.json +++ b/apps/stlap/metadata.json @@ -1,7 +1,7 @@ { "id": "stlap", "name": "Stopwatch", - "version": "0.03", + "version": "0.04", "description": "A stopwatch that remembers its state, with a lap timer and a gesture mode (enable by swiping)", "icon": "icon.png", "type": "app", @@ -20,5 +20,9 @@ "url": "icon.js", "evaluate": true } + ], + "data": [ + {"name":"stlap.state.json"}, + {"wildcard":"stlap-*.json"} ] } \ No newline at end of file