mirror of https://github.com/espruino/BangleApps
[ActivityReminder] Better handling of period going through midnight
parent
ac5c80ff38
commit
6e88874d41
|
@ -2,17 +2,17 @@ function run() {
|
||||||
if (isNotWorn()) return;
|
if (isNotWorn()) return;
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
let h = now.getHours();
|
let h = now.getHours();
|
||||||
let health = Bangle.getHealthStatus("day");
|
|
||||||
|
|
||||||
if (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour) {
|
if (isDuringAlertHours(h)) {
|
||||||
|
let health = Bangle.getHealthStatus("day");
|
||||||
if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps // more steps made than needed
|
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
|
|| health.steps < activityreminder_data.stepsOnDate) { // new day or reboot of the watch
|
||||||
activityreminder_data.stepsOnDate = health.steps;
|
activityreminder_data.stepsOnDate = health.steps;
|
||||||
activityreminder_data.stepsDate = now;
|
activityreminder_data.stepsDate = now;
|
||||||
activityreminder.saveData(activityreminder_data);
|
activityreminder.saveData(activityreminder_data);
|
||||||
/* todo in a futur release
|
/* todo in a futur release
|
||||||
add settimer to trigger like 10 secs after the stepsDate + minSteps
|
Add settimer to trigger like 30 secs after going in this part cause the person have been walking
|
||||||
cancel all other timers of this app
|
(pass some argument to run() to handle long walks and not triggering so often)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,18 +28,39 @@ function isNotWorn() {
|
||||||
return Bangle.isCharging();
|
return Bangle.isCharging();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const activityreminder = require("activityreminder");
|
const activityreminder = require("activityreminder");
|
||||||
const activityreminder_settings = activityreminder.loadSettings();
|
const activityreminder_settings = activityreminder.loadSettings();
|
||||||
if (activityreminder_settings.enabled) {
|
if (activityreminder_settings.enabled) {
|
||||||
const activityreminder_data = activityreminder.loadData();
|
const activityreminder_data = activityreminder.loadData();
|
||||||
if(activityreminder_data.firstLoad){
|
if(activityreminder_data.firstLoad){
|
||||||
activityreminder_data.firstLoad =false;
|
activityreminder_data.firstLoad = false;
|
||||||
activityreminder.saveData(activityreminder_data);
|
activityreminder.saveData(activityreminder_data);
|
||||||
}
|
}
|
||||||
setInterval(run, 60000);
|
setInterval(run, 60000);
|
||||||
/* todo in a futur release
|
/* todo in a futur release
|
||||||
increase setInterval time to something that is still sensible (5 mins ?)
|
increase setInterval time to something that is still sensible (5 mins ?)
|
||||||
add settimer to trigger like 10 secs after the stepsDate + minSteps
|
when we added a settimer
|
||||||
cancel all other timers of this app
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue