1
0
Fork 0

sonicclk minor - add settings to control twist/lcd

master
Joseph Moroney 2022-01-06 17:29:22 +10:00
parent 1906dd2839
commit 97696f7928
4 changed files with 75 additions and 10 deletions

View File

@ -5381,7 +5381,7 @@
{ {
"id": "sonicclk", "id": "sonicclk",
"name": "Sonic Clock", "name": "Sonic Clock",
"version": "1.01", "version": "1.10",
"description": "A classic sonic clock featuring run, stop and wait animations.", "description": "A classic sonic clock featuring run, stop and wait animations.",
"icon": "app.png", "icon": "app.png",
"screenshots": [{"url":"screenshot.png"}], "screenshots": [{"url":"screenshot.png"}],

View File

@ -1,2 +1,3 @@
1.00 Added sonic clock app 1.00 Added sonic clock app
1.01 Fixed text alignment issue; Increased acceleration required to activate twist; 1.01 Fixed text alignment issue; Increased acceleration required to activate twist;
1.10 Added settings menu to control twist threshold and LCD Activity

View File

@ -8,6 +8,13 @@ A classic sonic clock featuring run, stop and wait animations.
- Sonic will run when the screen is unlocked - Sonic will run when the screen is unlocked
- Sonic will stop when the screen is locked - Sonic will stop when the screen is locked
- Sonic will wait when looking at your watch face (when `Bangle.on("twist", fn)` is fired). - Sonic will wait when looking at your watch face (when `Bangle.on("twist", fn)` is fired). This option is configurable (see below).
## Configuration
To access the settings menu, you can **double tap** on the **right** side of the watch. The following options are configurable:
- `Active Mode` - catering for 'active' behaviour where the `twist` method can be fired undesirably. When `on` this will prevent the LCD from turning on when a `twist` event is fired.
- `Twist Thresh` - customise the acceleration needed to activate the twist method (see the [`Bangle.setOptions`](https://www.espruino.com/Reference#:~:text=twisted%3F%20default%20%3D%20true-,twistThreshold,-How%20much%20acceleration) method for more info).
### Made with love by [Joseph](https://github.com/Johoseph) 🤗 ### Made with love by [Joseph](https://github.com/Johoseph) 🤗

View File

@ -109,10 +109,14 @@ let currentSonic = -1;
let drawTimeout, drawInterval, waitTimeout; let drawTimeout, drawInterval, waitTimeout;
let bgScroll = [0, null]; let bgScroll = [0, null];
const start = () => { const fullReset = () => {
if (drawTimeout) clearTimeout(drawTimeout); if (drawTimeout) clearTimeout(drawTimeout);
if (waitTimeout) clearTimeout(waitTimeout); if (waitTimeout) clearTimeout(waitTimeout);
if (drawInterval) clearInterval(drawInterval); if (drawInterval) clearInterval(drawInterval);
}
const start = () => {
fullReset();
drawInterval = setInterval(() => { drawInterval = setInterval(() => {
draw("start"); draw("start");
@ -252,22 +256,75 @@ const draw = (action) => {
if (action === "reset") queueDraw(); if (action === "reset") queueDraw();
}; };
// Settings
const settings = require("Storage").readJSON("sonicclk-settings") || {
activeMode: false,
twistThreshold: 1600,
};
let isSettings = false;
const settingsMenu = {
"": { "title": "Settings" },
"Active Mode": {
value: settings.activeMode,
format: v => v ? "On" : "Off",
onchange: v => settings.activeMode = v,
},
"Twist Thresh" : {
value: settings.twistThreshold,
min: 800, max: 4000, step: 200,
onchange: v => settings.twistThreshold = v,
},
"Exit" : () => {
isSettings = false;
require("Storage").writeJSON("sonicclk-settings", settings);
Bangle.setOptions({
lockTimeout: 10000,
backlightTimeout: 12000,
twistThreshold: settings.twistThreshold,
});
E.showMenu();
draw("reset");
start();
}
};
g.setTheme({ bg: "#0099ff", fg: "#fff", dark: true }).clear(); g.setTheme({ bg: "#0099ff", fg: "#fff", dark: true }).clear();
Bangle.on("lock", (locked) => { Bangle.on("lock", (locked) => {
if (locked) { if (!isSettings) {
stop(); if (locked) {
} else { stop();
start(); } else {
start();
}
} }
}); });
Bangle.on("twist", () => wait()); Bangle.on("twist", () => {
if (settings.activeMode) {
fullReset();
draw("reset");
} else {
wait();
}
});
Bangle.on("tap", (d) => {
if (d.double && d.dir === "right") {
fullReset();
isSettings = true;
Bangle.setLocked(false);
E.showMenu(settingsMenu);
}
});
Bangle.setOptions({ Bangle.setOptions({
lockTimeout: 10000, lockTimeout: 10000,
backlightTimeout: 12000, backlightTimeout: 12000,
twistThreshold: 1600, twistThreshold: settings.twistThreshold,
}); });
Bangle.setUI("clock"); Bangle.setUI("clock");