Skip to content
Merged
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
3 changes: 2 additions & 1 deletion apps/twenties/ChangeLog
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion apps/twenties/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
29 changes: 16 additions & 13 deletions apps/twenties/boot.js
Original file line number Diff line number Diff line change
@@ -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();
})();
5 changes: 3 additions & 2 deletions apps/twenties/metadata.json
Original file line number Diff line number Diff line change
@@ -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" }]
}