Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add settings for split stopwatch #3542

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/splitsw/ChangeLog
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
0.01: New App!
0.02: Add settings for physical button, and to disable backlight and lock timeouts.
58 changes: 54 additions & 4 deletions apps/splitsw/app.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,10 +30,50 @@
]},
]
}, {
// 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.)
Expand Down Expand Up @@ -62,6 +105,12 @@
Bangle.buzz(50, 0.5);
};

const buttonPress = function() {

Check warning on line 108 in apps/splitsw/app.js

View workflow job for this annotation

GitHub Actions / build

'buttonPress' is assigned a value but never used
console.log("Pressed");

// TODO: start, stop or split depending on the app settings
};

const startStop = function() {
buzz();

Expand Down Expand Up @@ -164,4 +213,5 @@
// layout.debug();
};

initStopwatch();
updateStopwatch();
6 changes: 4 additions & 2 deletions apps/splitsw/metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"}]
}
64 changes: 64 additions & 0 deletions apps/splitsw/settings.js
Original file line number Diff line number Diff line change
@@ -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();
});
Loading