Merge pull request #3922 from splch/greener-twenties-v0.5
`twenties`: improve energy efficiency and simplify scheduling logicmaster
commit
166a3f4b5d
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -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" }]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue