Merge pull request #1367 from Johoseph/app/sonic-clock

Added configurable settings to Sonic Clock app
pull/1375/head
Gordon Williams 2022-01-31 10:08:49 +00:00 committed by GitHub
commit c7bfc902e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 12 deletions

View File

@ -1,2 +1,5 @@
0.01 Added sonic clock app
0.02 Fixed text alignment issue; Increased acceleration required to activate twist;
0.01 [MAJOR] Added sonic clock app
0.02 [PATCH] Fixed text alignment issue; Increased acceleration required to activate twist;
0.03 [MINOR] Added settings menu to control twist threshold and LCD Activity
0.04 [PATCH] Call `Bangle.setUI` when exiting settings menu, settings tap moved to top
0.05 [PATCH] Firmware 2v11 - use `wakeOnTwist` rather than manual `setLCDPower`; Reset sonic on `fullReset`

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 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 **top** 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) 🤗

View File

@ -109,10 +109,16 @@ let currentSonic = -1;
let drawTimeout, drawInterval, waitTimeout;
let bgScroll = [0, null];
const start = () => {
const fullReset = () => {
if (drawTimeout) clearTimeout(drawTimeout);
if (waitTimeout) clearTimeout(waitTimeout);
if (drawInterval) clearInterval(drawInterval);
currentSonic = -1;
currentSpeed = 0;
};
const start = () => {
fullReset();
drawInterval = setInterval(() => {
draw("start");
@ -144,7 +150,6 @@ const wait = () => {
currentSpeed = 0;
if (drawTimeout) clearTimeout(drawTimeout);
if (drawInterval) clearInterval(drawInterval);
Bangle.setLCDPower(1);
drawInterval = setInterval(() => draw("wait"), timeout);
@ -252,22 +257,80 @@ const draw = (action) => {
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,
wakeOnTwist: !settings.activeMode,
});
E.showMenu();
Bangle.setUI("clock");
draw("reset");
start();
},
};
g.setTheme({ bg: "#0099ff", fg: "#fff", dark: true }).clear();
Bangle.on("lock", (locked) => {
if (locked) {
stop();
} else {
start();
if (!isSettings) {
if (locked) {
stop();
} 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 === "top") {
fullReset();
isSettings = true;
Bangle.setLocked(false);
E.showMenu(settingsMenu);
}
});
Bangle.setOptions({
lockTimeout: 10000,
backlightTimeout: 12000,
twistThreshold: 1600,
twistThreshold: settings.twistThreshold,
wakeOnTwist: !settings.activeMode,
});
Bangle.setUI("clock");

View File

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