2022-05-11 19:58:00 +00:00
|
|
|
function run() {
|
|
|
|
if (isNotWorn()) return;
|
2022-05-12 09:34:42 +00:00
|
|
|
let now = new Date();
|
|
|
|
let h = now.getHours();
|
2022-05-11 19:58:00 +00:00
|
|
|
|
2022-05-26 19:02:07 +00:00
|
|
|
if (isDuringAlertHours(h)) {
|
|
|
|
let health = Bangle.getHealthStatus("day");
|
2022-05-12 08:30:11 +00:00
|
|
|
if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps // more steps made than needed
|
|
|
|
|| health.steps < activityreminder_data.stepsOnDate) { // new day or reboot of the watch
|
2022-05-11 19:58:00 +00:00
|
|
|
activityreminder_data.stepsOnDate = health.steps;
|
|
|
|
activityreminder_data.stepsDate = now;
|
2022-05-12 08:30:11 +00:00
|
|
|
activityreminder.saveData(activityreminder_data);
|
2022-05-12 10:21:21 +00:00
|
|
|
/* todo in a futur release
|
2022-05-26 19:02:07 +00:00
|
|
|
Add settimer to trigger like 30 secs after going in this part cause the person have been walking
|
|
|
|
(pass some argument to run() to handle long walks and not triggering so often)
|
2022-05-12 10:21:21 +00:00
|
|
|
*/
|
2022-05-12 08:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(activityreminder.mustAlert(activityreminder_data, activityreminder_settings)){
|
|
|
|
load('activityreminder.app.js');
|
2022-04-05 14:27:16 +00:00
|
|
|
}
|
2022-04-18 14:28:34 +00:00
|
|
|
}
|
2022-05-11 19:58:00 +00:00
|
|
|
|
2022-04-18 14:28:34 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 19:58:00 +00:00
|
|
|
function isNotWorn() {
|
2022-05-12 10:21:21 +00:00
|
|
|
// todo in a futur release check temperature and mouvement in a futur release
|
2022-05-26 19:21:15 +00:00
|
|
|
return (Bangle.isCharging() || activityreminder_settings.tempThreshold <= E.getTemperature());
|
2022-05-11 19:58:00 +00:00
|
|
|
}
|
2022-04-07 16:16:51 +00:00
|
|
|
|
2022-05-26 19:02:07 +00:00
|
|
|
function isDuringAlertHours(h) {
|
|
|
|
if(activityreminder_settings.startHour < activityreminder_settings.endHour){ // not passing through midnight
|
|
|
|
return (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour)
|
|
|
|
} else{ // passing through midnight
|
|
|
|
reutn (h >= activityreminder_settings.startHour || h < activityreminder_settings.endHour)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bangle.on('midnight', function() {
|
|
|
|
/*
|
|
|
|
Usefull trick to have the app working smothly for people using it at night
|
|
|
|
*/
|
|
|
|
let now = new Date();
|
|
|
|
let h = now.getHours();
|
|
|
|
if (activityreminder_settings.enabled && isDuringAlertHours(h)){
|
|
|
|
// updating only the steps and keeping the original stepsDate on purpose
|
|
|
|
activityreminder_data.stepsOnDate = 0;
|
|
|
|
activityreminder.saveData(activityreminder_data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-11 19:58:00 +00:00
|
|
|
const activityreminder = require("activityreminder");
|
2022-05-12 09:34:42 +00:00
|
|
|
const activityreminder_settings = activityreminder.loadSettings();
|
2022-05-11 19:58:00 +00:00
|
|
|
if (activityreminder_settings.enabled) {
|
2022-05-12 09:34:42 +00:00
|
|
|
const activityreminder_data = activityreminder.loadData();
|
2022-05-12 08:30:11 +00:00
|
|
|
if(activityreminder_data.firstLoad){
|
2022-05-26 19:02:07 +00:00
|
|
|
activityreminder_data.firstLoad = false;
|
2022-05-12 08:30:11 +00:00
|
|
|
activityreminder.saveData(activityreminder_data);
|
|
|
|
}
|
2022-04-18 15:30:57 +00:00
|
|
|
setInterval(run, 60000);
|
2022-05-12 10:21:21 +00:00
|
|
|
/* todo in a futur release
|
|
|
|
increase setInterval time to something that is still sensible (5 mins ?)
|
2022-05-26 19:02:07 +00:00
|
|
|
when we added a settimer
|
2022-05-12 10:21:21 +00:00
|
|
|
*/
|
2022-04-05 14:27:16 +00:00
|
|
|
}
|
2022-05-26 19:02:07 +00:00
|
|
|
|