widbaroalarm: keep interval

Do not immediately measure on start
pull/3191/head
Erik Andresen 2024-02-09 20:16:14 +01:00
parent 8412ac52ba
commit bc33c03312
4 changed files with 17 additions and 5 deletions

View File

@ -9,3 +9,5 @@
0.06: Fix exception
0.07: Ensure barometer gets turned off after a few readings (isBarometerOn broken in 2v16)
0.08: Compatibility with hideable Widgets
0.09: Do not immediately measure on start, keep interval
Add plot history to settings

View File

@ -2,7 +2,7 @@
"id": "widbaroalarm",
"name": "Barometer Alarm Widget",
"shortName": "Barometer Alarm",
"version": "0.08",
"version": "0.09",
"description": "A widget that can alarm on when the pressure reaches defined thresholds.",
"icon": "widget.png",
"type": "widget",

View File

@ -107,7 +107,7 @@
return x + " min";
}
},
'Log graph': () => {E.showMenu(); draw();},
'Plot history': () => {E.showMenu(); draw();},
};
E.showMenu(menu);
}

View File

@ -293,8 +293,18 @@ WIDGETS["baroalarm"] = {
draw : draw
};
if (interval > 0) {
setInterval(getPressureValue, interval * 60000);
// delay pressure measurement by interval-lastrun
const lastRun = history3.length > 0 ? history3[history3.length-1].ts : 0;
const lastRunAgo = Math.round(Date.now() / 1000) - lastRun;
let diffNextRun = interval*60-lastRunAgo;
if (diffNextRun < 0) {
diffNextRun = 0; // run asap
}
getPressureValue();
setTimeout(() => {
if (interval > 0) {
setInterval(getPressureValue, interval * 60000);
}
getPressureValue();
}, diffNextRun*1000);
})();