Use prompt with dimiss and pause
parent
ac5c80ff38
commit
dab3c045db
|
|
@ -1,3 +1,4 @@
|
||||||
0.01: Initial version
|
0.01: Initial version
|
||||||
0.02: Do not warn multiple times for the same exceedance
|
0.02: Do not warn multiple times for the same exceedance
|
||||||
0.03: Fix crash
|
0.03: Fix crash
|
||||||
|
0.04: Use Prompt with dismiss and pause
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "widbaroalarm",
|
"id": "widbaroalarm",
|
||||||
"name": "Barometer Alarm Widget",
|
"name": "Barometer Alarm Widget",
|
||||||
"shortName": "Barometer Alarm",
|
"shortName": "Barometer Alarm",
|
||||||
"version": "0.03",
|
"version": "0.04",
|
||||||
"description": "A widget that can alarm on when the pressure reaches defined thresholds.",
|
"description": "A widget that can alarm on when the pressure reaches defined thresholds.",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"type": "widget",
|
"type": "widget",
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,26 @@
|
||||||
},
|
},
|
||||||
onchange: x => save('buzz', x)
|
onchange: x => save('buzz', x)
|
||||||
},
|
},
|
||||||
|
'Dismiss delay': {
|
||||||
|
value: settings.dismissDelayMin,
|
||||||
|
min: 5, max: 60,
|
||||||
|
onchange: v => {
|
||||||
|
save('dismissDelayMin', x)
|
||||||
|
},
|
||||||
|
format: x => {
|
||||||
|
return x + " min";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'Pause delay': {
|
||||||
|
value: settings.pauseDelayMin,
|
||||||
|
min: 30, max: 240,
|
||||||
|
onchange: v => {
|
||||||
|
save('pauseDelayMin', x)
|
||||||
|
},
|
||||||
|
format: x => {
|
||||||
|
return x + " min";
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,21 @@
|
||||||
|
|
||||||
let history3 = storage.readJSON(LOG_FILE, true) || []; // history of recent 3 hours
|
let history3 = storage.readJSON(LOG_FILE, true) || []; // history of recent 3 hours
|
||||||
|
|
||||||
function showAlarm(body, title) {
|
function showAlarm(body, title, key) {
|
||||||
if (body == undefined) return;
|
if (body == undefined) return;
|
||||||
|
|
||||||
require("notify").show({
|
E.showPrompt(body, {
|
||||||
title: title || "Pressure",
|
title: title || "Pressure",
|
||||||
body: body,
|
buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 }
|
||||||
icon: require("heatshrink").decompress(atob("jEY4cA///gH4/++mkK30kiWC4H8x3BGDmSGgYDCgmSoEAg3bsAIDpAIFkmSpMAm3btgIFDQwIGNQpTYkAIJwAHEgMoCA0JgMEyBnBCAW3KoQQDhu3oAIH5JnDBAW24IIBEYm2EYwACBCIACA"))
|
}).then(function (v) {
|
||||||
|
const tsNow = Math.round(Date.now() / 1000); // seconds
|
||||||
|
|
||||||
|
if (v == 2) {
|
||||||
|
saveSetting(key, tsNow + 60 * settings('dismissDelayMin'));
|
||||||
|
}
|
||||||
|
if (v == 3) {
|
||||||
|
saveSetting(key, tsNow + 60 * settings('pauseDelayMin'));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (setting("buzz") &&
|
if (setting("buzz") &&
|
||||||
|
|
@ -48,8 +56,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function didWeAlreadyWarn(key) {
|
function doWeNeedToWarn(key) {
|
||||||
return setting(key) == undefined || setting(key) > 0;
|
const tsNow = Math.round(Date.now() / 1000); // seconds
|
||||||
|
|
||||||
|
return setting(key) == 0 || setting(key) < tsNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForAlarms(pressure) {
|
function checkForAlarms(pressure) {
|
||||||
|
|
@ -77,7 +87,7 @@
|
||||||
if (setting("lowalarm")) {
|
if (setting("lowalarm")) {
|
||||||
// Is below the alarm threshold?
|
// Is below the alarm threshold?
|
||||||
if (pressure <= setting("min")) {
|
if (pressure <= setting("min")) {
|
||||||
if (!didWeAlreadyWarn("lastLowWarningTs")) {
|
if (!doWeNeedToWarn("lastLowWarningTs")) {
|
||||||
showAlarm("Pressure low: " + Math.round(pressure) + " hPa");
|
showAlarm("Pressure low: " + Math.round(pressure) + " hPa");
|
||||||
saveSetting("lastLowWarningTs", ts);
|
saveSetting("lastLowWarningTs", ts);
|
||||||
alreadyWarned = true;
|
alreadyWarned = true;
|
||||||
|
|
@ -92,7 +102,7 @@
|
||||||
if (setting("highalarm")) {
|
if (setting("highalarm")) {
|
||||||
// Is above the alarm threshold?
|
// Is above the alarm threshold?
|
||||||
if (pressure >= setting("max")) {
|
if (pressure >= setting("max")) {
|
||||||
if (!didWeAlreadyWarn("lastHighWarningTs")) {
|
if (!doWeNeedToWarn("lastHighWarningTs")) {
|
||||||
showAlarm("Pressure high: " + Math.round(pressure) + " hPa");
|
showAlarm("Pressure high: " + Math.round(pressure) + " hPa");
|
||||||
saveSetting("lastHighWarningTs", ts);
|
saveSetting("lastHighWarningTs", ts);
|
||||||
alreadyWarned = true;
|
alreadyWarned = true;
|
||||||
|
|
@ -122,7 +132,7 @@
|
||||||
// drop alarm
|
// drop alarm
|
||||||
if (drop3halarm > 0 && oldestPressure > pressure) {
|
if (drop3halarm > 0 && oldestPressure > pressure) {
|
||||||
if (Math.abs(diff) > drop3halarm) {
|
if (Math.abs(diff) > drop3halarm) {
|
||||||
if (!didWeAlreadyWarn("lastDropWarningTs")) {
|
if (!doWeNeedToWarn("lastDropWarningTs")) {
|
||||||
showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " +
|
showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " +
|
||||||
Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "Pressure drop");
|
Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "Pressure drop");
|
||||||
saveSetting("lastDropWarningTs", ts);
|
saveSetting("lastDropWarningTs", ts);
|
||||||
|
|
@ -137,7 +147,7 @@
|
||||||
// raise alarm
|
// raise alarm
|
||||||
if (raise3halarm > 0 && oldestPressure < pressure) {
|
if (raise3halarm > 0 && oldestPressure < pressure) {
|
||||||
if (Math.abs(diff) > raise3halarm) {
|
if (Math.abs(diff) > raise3halarm) {
|
||||||
if (!didWeAlreadyWarn("lastRaiseWarningTs")) {
|
if (!doWeNeedToWarn("lastRaiseWarningTs")) {
|
||||||
showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " +
|
showAlarm((Math.round(Math.abs(diff) * 10) / 10) + " hPa/3h from " +
|
||||||
Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "Pressure raise");
|
Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "Pressure raise");
|
||||||
saveSetting("lastRaiseWarningTs", ts);
|
saveSetting("lastRaiseWarningTs", ts);
|
||||||
|
|
@ -176,7 +186,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
turn on barometer power
|
turn on barometer power
|
||||||
take 5 measurements
|
take `numberOfMeasurements` measurements
|
||||||
sort the results
|
sort the results
|
||||||
take the middle one (median)
|
take the middle one (median)
|
||||||
turn off barometer power
|
turn off barometer power
|
||||||
|
|
@ -186,11 +196,11 @@
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
currentPressures = [];
|
currentPressures = [];
|
||||||
|
|
||||||
Bangle.getPressure().then(baroHandler);
|
const numberOfMeasurements = 5;
|
||||||
Bangle.getPressure().then(baroHandler);
|
|
||||||
Bangle.getPressure().then(baroHandler);
|
for (let i = 0; i < numberOfMeasurements; i++) {
|
||||||
Bangle.getPressure().then(baroHandler);
|
Bangle.getPressure().then(baroHandler);
|
||||||
Bangle.getPressure().then(baroHandler);
|
}
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
Bangle.setBarometerPower(false, "widbaroalarm");
|
Bangle.setBarometerPower(false, "widbaroalarm");
|
||||||
|
|
@ -198,7 +208,7 @@
|
||||||
currentPressures.sort();
|
currentPressures.sort();
|
||||||
|
|
||||||
// take median value
|
// take median value
|
||||||
medianPressure = currentPressures[3];
|
medianPressure = currentPressures[Math.round(numberOfMeasurements / 2) + 1];
|
||||||
checkForAlarms(medianPressure);
|
checkForAlarms(medianPressure);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue