Merge pull request #392 from v1nc/getup

New App: Get Up - reminds you to move after some time sitting
pull/408/head
Gordon Williams 2020-05-11 08:36:47 +01:00 committed by GitHub
commit ebc78c65c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 117 additions and 0 deletions

View File

@ -1675,5 +1675,20 @@
{"name":"findphone.app.js","url":"app.js"},
{"name":"findphone.img","url":"app-icon.js","evaluate":true}
]
},
{ "id": "getup",
"name": "Get Up",
"shortName":"Get Up",
"icon": "app.png",
"version":"0.01",
"description": "Reminds you to getup every x minutes. Sitting to long is dangerous!",
"tags": "tools,health",
"readme": "README.md",
"allow_emulator":true,
"storage": [
{"name":"getup.app.js","url":"app.js"},
{"name":"getup.settings.js","url":"settings.js"},
{"name":"getup.img","url":"app-icon.js","evaluate":true}
]
}
]

1
apps/getup/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: First Version

7
apps/getup/README.md Normal file
View File

@ -0,0 +1,7 @@
# Get Up
Reminds you to getup every x minutes (default: 20).
Sitting to long is dangerous!
Sit and move time configurable in settings.

1
apps/getup/app-icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A75wACCJugAAguaGBouFGCwuF53NFxem6PX6/R0wwVF4xgJEwOsFoMrlYDB1gwUL55dCFQIvE65hUL54jBRgQvF6JgaRxQpCF4SUC67BV5ouLF40yGAOBF64ANR4vXwJhCR6oABq4ACF5TvDAAOsL4LvS4wuGGBi6DGIYuSAAQvGMJiSC6JdSGAovPGAQAFXSQvDrgrBqwvMGAzqTF4d/F4owLADKQGmQv/F7eAF4UySQQwn0ZcCq0ylkySFYyDMEgvDvQwFAAYvk0aLBqy/CAAaUhSAi+BX4QzCAwJkgF4eAX4gzDSsIvDeIzFlGAhhEF9QAHBwIwvF8IwSF7oxMF8gALSEQwRF/4v/YH4v/GD4usAH4A/AH4ARA="))

45
apps/getup/app.js Normal file
View File

@ -0,0 +1,45 @@
//init settings
const storage = require("Storage");
const SETTINGS_FILE = 'getup.settings.json';
function setting(key) {
const DEFAULTS = {
'sitTime' : 20,
'moveTime' : 1
}
if (!settings) {
loadSettings();
}
return (key in settings) ? settings[key] : DEFAULTS[key];
}
let settings;
function loadSettings() {
settings = storage.readJSON(SETTINGS_FILE, 1) || {};
}
//vibrate, draw move message and start timer for sitting message
function remind() {
Bangle.buzz(1000,1);
g.clear();
g.setFont("8x12",4);
g.setColor(0x03E0);
g.drawString("MOVE!", g.getWidth()/2, g.getHeight()/2);
setTimeout(print_message,setting("moveTime") * 60000);
}
//draw sitting message and start timer for reminder
function print_message(){
g.clear();
g.setFont("8x12",2);
g.setColor(0xF800);
g.drawString("sitting is dangerous!", g.getWidth()/2, g.getHeight()/2);
setTimeout(remind,setting("sitTime") * 60000);
}
//init graphics
require("Font8x12").add(Graphics);
g.setFontAlign(0,0);
g.flip();
print_message();

BIN
apps/getup/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

48
apps/getup/settings.js Normal file
View File

@ -0,0 +1,48 @@
// This file should contain exactly one function, which shows the app's settings
/**
* @param {function} back Use back() to return to settings menu
*/
(function(back) {
const SETTINGS_FILE = 'getup.settings.json';
// initialize with default settings...
let s = {
'sitTime' : 20,
'moveTime' : 1
};
// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
const storage = require('Storage');
const saved = storage.readJSON(SETTINGS_FILE, 1) || {};
for (const key in saved) {
s[key] = saved[key];
}
// creates a function to safe a specific setting, e.g. save('color')(1)
function save(key) {
return function (value) {
s[key] = value;
storage.write(SETTINGS_FILE, s);
};
}
const menu = {
'': { 'title': 'Get Up' },
'< Back': back,
'Sit time (min)': {
value: s.sitTime,
min: 0,
max: 10000,
step: 1,
onchange: save('sitTime'),
},
'Move time (min)': {
value: s.moveTime,
min: 0,
max: 5000,
step: 1,
onchange: save('moveTime'),
},
};
E.showMenu(menu);
});