diff --git a/apps/splitsw/ChangeLog b/apps/splitsw/ChangeLog index 5560f00bce..9a08df86c6 100644 --- a/apps/splitsw/ChangeLog +++ b/apps/splitsw/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: Add settings for physical button, and to disable backlight and lock timeouts. diff --git a/apps/splitsw/app.js b/apps/splitsw/app.js index 5d70b471d7..75a21968bc 100644 --- a/apps/splitsw/app.js +++ b/apps/splitsw/app.js @@ -1,8 +1,11 @@ -Bangle.loadWidgets(); -g.clear(true); -Bangle.drawWidgets(); +const DEFAULTS = { + button: 0, + buttonWhileLocked: false, + disableBacklightTimeout: true, + disableLockTimeout: true, +}; -Bangle.setLCDTimeout(undefined); +const settings = require("Storage").readJSON("splitsw.json", 1) || DEFAULTS; let renderIntervalId; let startTime; @@ -27,10 +30,50 @@ var layout = new Layout( { ]}, ] }, { + // TODO: The layout libary always seems to give the physical button label space + // even if it's empty (neither of these work) + // btns:[ + // {label:"", cb: l=>buttonPress()}, + // {cb: l=>buttonPress()}, + // ], lazy: true, back: load, }); +const initStopwatch = function() { + Bangle.loadWidgets(); + g.clear(true); + Bangle.drawWidgets(); // TODO: no sign of the widgets! + + // TODO: it looks like this conflicts with using the layout library + // Bangle.setUI({mode:"custom", btn: ()=>buttonPress()}); + + // TODO: there doesn't seem to be an on button event and this + // conflicts with the setUI back function + // setWatch(function() { + // console.log("Pressed"); + // }, BTN, {edge:"rising", debounce:50, repeat:true}); + + // TODO: it would be confusing to react to an unlock button press + // but not a normal button press! + // if (settings.buttonWhileLocked === true) { + // Bangle.on('lock', function(on, reason) { + // if ((on === false) && (reason === 'button')) { + // buttonPress(); + // } + // }); + // } + + if (settings.disableBacklightTimeout === true) { + Bangle.setOptions({backlightTimeout: 0}); + Bangle.setBacklight(1); + } + + if (settings.disableLockTimeout === true) { + Bangle.setOptions({lockTimeout: 0}); + } +}; + // TODO The code in this function appears in various apps so it might be // nice to add something to the time_utils module. (There is already a // formatDuration function but that doesn't quite work the same way.) @@ -62,6 +105,12 @@ const buzz = function() { Bangle.buzz(50, 0.5); }; +const buttonPress = function() { + console.log("Pressed"); + + // TODO: start, stop or split depending on the app settings +}; + const startStop = function() { buzz(); @@ -164,4 +213,5 @@ const updateStopwatch = function() { // layout.debug(); }; +initStopwatch(); updateStopwatch(); diff --git a/apps/splitsw/metadata.json b/apps/splitsw/metadata.json index d5ae19347f..13e13f2610 100644 --- a/apps/splitsw/metadata.json +++ b/apps/splitsw/metadata.json @@ -1,7 +1,7 @@ { "id": "splitsw", "name": "Stopwatch with split times", "shortName":"Stopwatch", - "version":"0.01", + "version":"0.02", "description": "A basic stopwatch with support for split times", "icon": "app.png", "tags": "tool,outdoors,health", @@ -11,6 +11,8 @@ "allow_emulator": true, "storage": [ {"name":"splitsw.app.js","url":"app.js"}, + {"name":"splitsw.settings.js","url":"settings.js"}, {"name":"splitsw.img","url":"app-icon.js","evaluate":true} - ] + ], + "data": [{"name":"splitsw.json"}] } diff --git a/apps/splitsw/settings.js b/apps/splitsw/settings.js new file mode 100644 index 0000000000..bef0efc9bd --- /dev/null +++ b/apps/splitsw/settings.js @@ -0,0 +1,64 @@ +(function (back) { + const FILE = "splitsw.json"; + const DEFAULTS = { + button: 0, + buttonWhileLocked: false, + disableBacklightTimeout: true, + disableLockTimeout: true, + }; + + let settings = {}; + + const loadSettings = function() { + settings = require('Storage').readJSON(FILE, 1) || DEFAULTS; + }; + + const saveSettings = function() { + require('Storage').writeJSON(FILE, settings); + }; + + const showMenu = function() { + const buttonOptions = [/*LANG*/'Exit','Start/Stop','Start/Split']; + + const menu = { + '': {'title': 'Stopwatch'}, + '< Back': back, + 'Button': { + value: 0|settings.button, + min: 0, + max: buttonOptions.length-1, + format: v => buttonOptions[v], + onchange: v => { + settings.button = 0 | v; + saveSettings(settings); + } + }, + 'Use button while locked': { + value: !!settings.buttonWhileLocked, + onchange: v => { + settings.buttonWhileLocked = v; + saveSettings(); + } + }, + 'Disable backlight timeout': { + value: !!settings.disableBacklightTimeout, + onchange: v => { + settings.disableBacklightTimeout = v; + saveSettings(); + } + }, + 'Disable lock timeout': { + value: !!settings.disableLockTimeout, + onchange: v => { + settings.disableLockTimeout = v; + saveSettings(); + } + }, + }; + + E.showMenu(menu); + }; + + loadSettings(); + showMenu(); +});