Skip to content

Commit 166a3f4

Browse files
authored
Merge pull request #3922 from splch/greener-twenties-v0.5
`twenties`: improve energy efficiency and simplify scheduling logic
2 parents b2a54d6 + e9fa295 commit 166a3f4

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

apps/twenties/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
0.01: New Widget!
22
0.02: Fix calling null on draw
33
0.03: Only vibrate during work
4-
0.04: Convert to boot code
4+
0.04: Convert to boot code
5+
0.05: Improve energy efficiency

apps/twenties/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Twenties
22

3-
Follow the [20-20-20 rule](https://www.aoa.org/AOA/Images/Patients/Eye%20Conditions/20-20-20-rule.pdf) with discrete reminders. Your Bangle will buzz every 20 minutes for you to look away from your screen, and then buzz 20 seconds later to look back. Additionally, alternate between standing and sitting every 20 minutes to be standing for [more than 30 minutes](https://uwaterloo.ca/kinesiology-health-sciences/how-long-should-you-stand-rather-sit-your-work-station) per hour.
3+
Follow the [20-20-20 rule](https://www.aoa.org/AOA/Images/Patients/Eye%20Conditions/20-20-20-rule.pdf) with discrete reminders. Your Bangle will buzz every 20 minutes for you to look away from your screen, and then buzz 20 seconds later to look back. Additionally, alternate between standing and sitting every 20 minutes to be standing for [more than 30 minutes](https://uwaterloo.ca/news/how-long-should-you-stand-rather-sit-your-work-station) per hour.
44

55
## Usage
66

apps/twenties/boot.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
(() => {
2-
const move = 20 * 60 * 1000; // 20 minutes
3-
const look = 20 * 1000; // 20 seconds
2+
const LOOP_INTERVAL = 1.2e6; // 20 minutes
3+
const BUZZ_INTERVAL = 2e4; // 20 seconds
44

5-
const buzz = _ => {
6-
const date = new Date();
7-
const day = date.getDay();
8-
const hour = date.getHours();
9-
// buzz at work
10-
if (day >= 1 && day <= 5 &&
11-
hour >= 8 && hour <= 17) {
12-
Bangle.buzz().then(_ => {
13-
setTimeout(Bangle.buzz, look);
14-
});
5+
const isWorkTime = (d) =>
6+
d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18;
7+
8+
const scheduleNext = () => {
9+
const now = new Date();
10+
if (isWorkTime(now)) {
11+
Bangle.buzz().then(() => setTimeout(Bangle.buzz, BUZZ_INTERVAL));
12+
setTimeout(scheduleNext, LOOP_INTERVAL);
13+
} else {
14+
const next = new Date(now);
15+
next.setHours(8, 0, 0, 0);
16+
while (!isWorkTime(next)) next.setDate(next.getDate() + 1);
17+
setTimeout(scheduleNext, next - now);
1518
}
1619
};
1720

18-
setInterval(buzz, move); // buzz to stand / sit
21+
scheduleNext();
1922
})();

apps/twenties/metadata.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"id": "twenties",
33
"name": "Twenties",
4-
"shortName": "twenties",
5-
"version": "0.04",
4+
"shortName": "Twenties",
5+
"version": "0.05",
66
"description": "Buzzes every 20m to stand / sit and look 20ft away for 20s.",
77
"icon": "app.png",
88
"type": "bootloader",
99
"tags": "alarm,tool,health",
1010
"supports": ["BANGLEJS", "BANGLEJS2"],
11+
"allow_emulator": true,
1112
"readme": "README.md",
1213
"storage": [{ "name": "twenties.boot.js", "url": "boot.js" }]
1314
}

0 commit comments

Comments
 (0)