Merge pull request #3922 from splch/greener-twenties-v0.5

`twenties`: improve energy efficiency and simplify scheduling logic
master
Rob Pilling 2025-07-04 12:00:56 +01:00 committed by GitHub
commit 166a3f4b5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 17 deletions

View File

@ -1,4 +1,5 @@
0.01: New Widget!
0.02: Fix calling null on draw
0.03: Only vibrate during work
0.04: Convert to boot code
0.04: Convert to boot code
0.05: Improve energy efficiency

View File

@ -1,6 +1,6 @@
# Twenties
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.
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.
## Usage

View File

@ -1,19 +1,22 @@
(() => {
const move = 20 * 60 * 1000; // 20 minutes
const look = 20 * 1000; // 20 seconds
const LOOP_INTERVAL = 1.2e6; // 20 minutes
const BUZZ_INTERVAL = 2e4; // 20 seconds
const buzz = _ => {
const date = new Date();
const day = date.getDay();
const hour = date.getHours();
// buzz at work
if (day >= 1 && day <= 5 &&
hour >= 8 && hour <= 17) {
Bangle.buzz().then(_ => {
setTimeout(Bangle.buzz, look);
});
const isWorkTime = (d) =>
d.getDay() % 6 && d.getHours() >= 8 && d.getHours() < 18;
const scheduleNext = () => {
const now = new Date();
if (isWorkTime(now)) {
Bangle.buzz().then(() => setTimeout(Bangle.buzz, BUZZ_INTERVAL));
setTimeout(scheduleNext, LOOP_INTERVAL);
} else {
const next = new Date(now);
next.setHours(8, 0, 0, 0);
while (!isWorkTime(next)) next.setDate(next.getDate() + 1);
setTimeout(scheduleNext, next - now);
}
};
setInterval(buzz, move); // buzz to stand / sit
scheduleNext();
})();

View File

@ -1,13 +1,14 @@
{
"id": "twenties",
"name": "Twenties",
"shortName": "twenties",
"version": "0.04",
"shortName": "Twenties",
"version": "0.05",
"description": "Buzzes every 20m to stand / sit and look 20ft away for 20s.",
"icon": "app.png",
"type": "bootloader",
"tags": "alarm,tool,health",
"supports": ["BANGLEJS", "BANGLEJS2"],
"allow_emulator": true,
"readme": "README.md",
"storage": [{ "name": "twenties.boot.js", "url": "boot.js" }]
}