Fix the const reassign bug (cutting edge firmware) and better indentation and scoping
parent
0cc0a40356
commit
85a52afbf5
|
|
@ -4,3 +4,4 @@
|
||||||
0.04: Obey system quiet mode
|
0.04: Obey system quiet mode
|
||||||
0.05: Battery optimisation, add the pause option, bug fixes
|
0.05: Battery optimisation, add the pause option, bug fixes
|
||||||
0.06: Add a temperature threshold to detect (and not alert) if the BJS isn't worn. Better support for the peoples using the app at night
|
0.06: Add a temperature threshold to detect (and not alert) if the BJS isn't worn. Better support for the peoples using the app at night
|
||||||
|
0.07: Fix bug on the cutting edge firmware
|
||||||
|
|
@ -1,42 +1,43 @@
|
||||||
function drawAlert() {
|
(function () {
|
||||||
E.showPrompt("Inactivity detected", {
|
function drawAlert() {
|
||||||
title: "Activity reminder",
|
E.showPrompt("Inactivity detected", {
|
||||||
buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 }
|
title: "Activity reminder",
|
||||||
}).then(function (v) {
|
buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 }
|
||||||
if (v == 1) {
|
}).then(function (v) {
|
||||||
activityreminder_data.okDate = new Date();
|
if (v == 1) {
|
||||||
|
activityreminder_data.okDate = new Date();
|
||||||
|
}
|
||||||
|
if (v == 2) {
|
||||||
|
activityreminder_data.dismissDate = new Date();
|
||||||
|
}
|
||||||
|
if (v == 3) {
|
||||||
|
activityreminder_data.pauseDate = new Date();
|
||||||
|
}
|
||||||
|
activityreminder.saveData(activityreminder_data);
|
||||||
|
load();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Obey system quiet mode:
|
||||||
|
if (!(storage.readJSON('setting.json', 1) || {}).quiet) {
|
||||||
|
Bangle.buzz(400);
|
||||||
|
}
|
||||||
|
setTimeout(load, 20000);
|
||||||
}
|
}
|
||||||
if (v == 2) {
|
|
||||||
activityreminder_data.dismissDate = new Date();
|
function run() {
|
||||||
|
if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) {
|
||||||
|
drawAlert();
|
||||||
|
} else {
|
||||||
|
eval(storage.read("activityreminder.settings.js"))(() => load());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (v == 3) {
|
|
||||||
activityreminder_data.pauseDate = new Date();
|
const activityreminder = require("activityreminder");
|
||||||
}
|
const storage = require("Storage");
|
||||||
activityreminder.saveData(activityreminder_data);
|
g.clear();
|
||||||
load();
|
Bangle.loadWidgets();
|
||||||
});
|
Bangle.drawWidgets();
|
||||||
|
const activityreminder_settings = activityreminder.loadSettings();
|
||||||
// Obey system quiet mode:
|
const activityreminder_data = activityreminder.loadData();
|
||||||
if (!(storage.readJSON('setting.json', 1) || {}).quiet) {
|
run();
|
||||||
Bangle.buzz(400);
|
})();
|
||||||
}
|
|
||||||
setTimeout(load, 20000);
|
|
||||||
}
|
|
||||||
|
|
||||||
function run() {
|
|
||||||
if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) {
|
|
||||||
drawAlert();
|
|
||||||
} else {
|
|
||||||
eval(storage.read("activityreminder.settings.js"))(() => load());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const activityreminder = require("activityreminder");
|
|
||||||
const storage = require("Storage");
|
|
||||||
g.clear();
|
|
||||||
Bangle.loadWidgets();
|
|
||||||
Bangle.drawWidgets();
|
|
||||||
const activityreminder_settings = activityreminder.loadSettings();
|
|
||||||
const activityreminder_data = activityreminder.loadData();
|
|
||||||
run();
|
|
||||||
|
|
@ -1,65 +1,67 @@
|
||||||
function run() {
|
(function () {
|
||||||
if (isNotWorn()) return;
|
function run() {
|
||||||
let now = new Date();
|
if (isNotWorn()) return;
|
||||||
let h = now.getHours();
|
let now = new Date();
|
||||||
|
let h = now.getHours();
|
||||||
|
|
||||||
if (isDuringAlertHours(h)) {
|
if (isDuringAlertHours(h)) {
|
||||||
let health = Bangle.getHealthStatus("day");
|
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);
|
||||||
|
/* todo in a futur release
|
||||||
|
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)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) {
|
||||||
|
load('activityreminder.app.js');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function isNotWorn() {
|
||||||
|
return (Bangle.isCharging() || activityreminder_settings.tempThreshold >= E.getTemperature());
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
return (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);
|
activityreminder.saveData(activityreminder_data);
|
||||||
/* todo in a futur release
|
|
||||||
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)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
if(activityreminder.mustAlert(activityreminder_data, activityreminder_settings)){
|
|
||||||
load('activityreminder.app.js');
|
|
||||||
|
const activityreminder = require("activityreminder");
|
||||||
|
const activityreminder_settings = activityreminder.loadSettings();
|
||||||
|
if (activityreminder_settings.enabled) {
|
||||||
|
const activityreminder_data = activityreminder.loadData();
|
||||||
|
if (activityreminder_data.firstLoad) {
|
||||||
|
activityreminder_data.firstLoad = false;
|
||||||
|
activityreminder.saveData(activityreminder_data);
|
||||||
}
|
}
|
||||||
|
setInterval(run, 60000);
|
||||||
|
/* todo in a futur release
|
||||||
|
increase setInterval time to something that is still sensible (5 mins ?)
|
||||||
|
when we added a settimer
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
}
|
|
||||||
|
|
||||||
function isNotWorn() {
|
|
||||||
return (Bangle.isCharging() || activityreminder_settings.tempThreshold >= E.getTemperature());
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
return (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_settings = activityreminder.loadSettings();
|
|
||||||
if (activityreminder_settings.enabled) {
|
|
||||||
const activityreminder_data = activityreminder.loadData();
|
|
||||||
if(activityreminder_data.firstLoad){
|
|
||||||
activityreminder_data.firstLoad = false;
|
|
||||||
activityreminder.saveData(activityreminder_data);
|
|
||||||
}
|
|
||||||
setInterval(run, 60000);
|
|
||||||
/* todo in a futur release
|
|
||||||
increase setInterval time to something that is still sensible (5 mins ?)
|
|
||||||
when we added a settimer
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
const storage = require("Storage");
|
|
||||||
|
|
||||||
exports.loadSettings = function () {
|
exports.loadSettings = function () {
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
@ -10,15 +8,15 @@ exports.loadSettings = function () {
|
||||||
pauseDelayMin: 120,
|
pauseDelayMin: 120,
|
||||||
minSteps: 50,
|
minSteps: 50,
|
||||||
tempThreshold: 27
|
tempThreshold: 27
|
||||||
}, storage.readJSON("activityreminder.s.json", true) || {});
|
}, require("Storage").readJSON("activityreminder.s.json", true) || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.writeSettings = function (settings) {
|
exports.writeSettings = function (settings) {
|
||||||
storage.writeJSON("activityreminder.s.json", settings);
|
require("Storage").writeJSON("activityreminder.s.json", settings);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.saveData = function (data) {
|
exports.saveData = function (data) {
|
||||||
storage.writeJSON("activityreminder.data.json", data);
|
require("Storage").writeJSON("activityreminder.data.json", data);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.loadData = function () {
|
exports.loadData = function () {
|
||||||
|
|
@ -31,7 +29,7 @@ exports.loadData = function () {
|
||||||
dismissDate: new Date(1970),
|
dismissDate: new Date(1970),
|
||||||
pauseDate: new Date(1970),
|
pauseDate: new Date(1970),
|
||||||
},
|
},
|
||||||
storage.readJSON("activityreminder.data.json") || {});
|
require("Storage").readJSON("activityreminder.data.json") || {});
|
||||||
|
|
||||||
if(typeof(data.stepsDate) == "string")
|
if(typeof(data.stepsDate) == "string")
|
||||||
data.stepsDate = new Date(data.stepsDate);
|
data.stepsDate = new Date(data.stepsDate);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Activity Reminder",
|
"name": "Activity Reminder",
|
||||||
"shortName":"Activity Reminder",
|
"shortName":"Activity Reminder",
|
||||||
"description": "A reminder to take short walks for the ones with a sedentary lifestyle",
|
"description": "A reminder to take short walks for the ones with a sedentary lifestyle",
|
||||||
"version":"0.06",
|
"version":"0.07",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"type": "app",
|
"type": "app",
|
||||||
"tags": "tool,activity",
|
"tags": "tool,activity",
|
||||||
|
|
|
||||||
|
|
@ -1,85 +1,85 @@
|
||||||
(function (back) {
|
(function (back) {
|
||||||
// Load settings
|
// Load settings
|
||||||
const activityreminder = require("activityreminder");
|
const activityreminder = require("activityreminder");
|
||||||
const settings = activityreminder.loadSettings();
|
const settings = activityreminder.loadSettings();
|
||||||
|
|
||||||
// Show the menu
|
// Show the menu
|
||||||
E.showMenu({
|
E.showMenu({
|
||||||
"": { "title": "Activity Reminder" },
|
"": { "title": "Activity Reminder" },
|
||||||
"< Back": () => back(),
|
"< Back": () => back(),
|
||||||
'Enable': {
|
'Enable': {
|
||||||
value: settings.enabled,
|
value: settings.enabled,
|
||||||
format: v => v ? "Yes" : "No",
|
format: v => v ? "Yes" : "No",
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
settings.enabled = v;
|
settings.enabled = v;
|
||||||
activityreminder.writeSettings(settings);
|
activityreminder.writeSettings(settings);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Start hour': {
|
'Start hour': {
|
||||||
value: settings.startHour,
|
value: settings.startHour,
|
||||||
min: 0, max: 24,
|
min: 0, max: 24,
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
settings.startHour = v;
|
settings.startHour = v;
|
||||||
activityreminder.writeSettings(settings);
|
activityreminder.writeSettings(settings);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'End hour': {
|
'End hour': {
|
||||||
value: settings.endHour,
|
value: settings.endHour,
|
||||||
min: 0, max: 24,
|
min: 0, max: 24,
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
settings.endHour = v;
|
settings.endHour = v;
|
||||||
activityreminder.writeSettings(settings);
|
activityreminder.writeSettings(settings);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Max inactivity': {
|
'Max inactivity': {
|
||||||
value: settings.maxInnactivityMin,
|
value: settings.maxInnactivityMin,
|
||||||
min: 15, max: 120,
|
min: 15, max: 120,
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
settings.maxInnactivityMin = v;
|
settings.maxInnactivityMin = v;
|
||||||
activityreminder.writeSettings(settings);
|
activityreminder.writeSettings(settings);
|
||||||
},
|
},
|
||||||
format: x => {
|
format: x => {
|
||||||
return x + " min";
|
return x + " min";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Dismiss delay': {
|
'Dismiss delay': {
|
||||||
value: settings.dismissDelayMin,
|
value: settings.dismissDelayMin,
|
||||||
min: 5, max: 60,
|
min: 5, max: 60,
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
settings.dismissDelayMin = v;
|
settings.dismissDelayMin = v;
|
||||||
activityreminder.writeSettings(settings);
|
activityreminder.writeSettings(settings);
|
||||||
},
|
},
|
||||||
format: x => {
|
format: x => {
|
||||||
return x + " min";
|
return x + " min";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Pause delay': {
|
'Pause delay': {
|
||||||
value: settings.pauseDelayMin,
|
value: settings.pauseDelayMin,
|
||||||
min: 30, max: 240, step: 5,
|
min: 30, max: 240, step: 5,
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
settings.pauseDelayMin = v;
|
settings.pauseDelayMin = v;
|
||||||
activityreminder.writeSettings(settings);
|
activityreminder.writeSettings(settings);
|
||||||
},
|
},
|
||||||
format: x => {
|
format: x => {
|
||||||
return x + " min";
|
return x + " min";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Min steps': {
|
'Min steps': {
|
||||||
value: settings.minSteps,
|
value: settings.minSteps,
|
||||||
min: 10, max: 500, step: 10,
|
min: 10, max: 500, step: 10,
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
settings.minSteps = v;
|
settings.minSteps = v;
|
||||||
activityreminder.writeSettings(settings);
|
activityreminder.writeSettings(settings);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Temp Threshold': {
|
'Temp Threshold': {
|
||||||
value: settings.tempThreshold,
|
value: settings.tempThreshold,
|
||||||
min: 20, max: 40, step: 0.5,
|
min: 20, max: 40, step: 0.5,
|
||||||
format: v => v + "°C",
|
format: v => v + "°C",
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
settings.tempThreshold = v;
|
settings.tempThreshold = v;
|
||||||
activityreminder.writeSettings(settings);
|
activityreminder.writeSettings(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue