forked from FOSS/BangleApps
commit
69aecf40ea
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -107,9 +107,52 @@
|
|||
return x + " min";
|
||||
}
|
||||
},
|
||||
'Plot history': () => {E.showMenu(); draw();},
|
||||
};
|
||||
E.showMenu(menu);
|
||||
}
|
||||
|
||||
function draw() {
|
||||
const history3 = require('Storage').readJSON("widbaroalarm.log.json", true) || []; // history of recent 3 hours
|
||||
|
||||
const now = new Date()/(1000);
|
||||
let curtime = now-3*60*60; // 3h ago
|
||||
const data = [];
|
||||
while (curtime <= now) {
|
||||
// find closest value in history for this timestamp
|
||||
const closest = history3.reduce((prev, curr) => {
|
||||
return (Math.abs(curr.ts - curtime) < Math.abs(prev.ts - curtime) ? curr : prev);
|
||||
});
|
||||
data.push(closest.p);
|
||||
curtime += settings.interval*60;
|
||||
}
|
||||
|
||||
Bangle.setUI({
|
||||
mode: "custom",
|
||||
back: () => showMainMenu(),
|
||||
});
|
||||
|
||||
g.reset().setFont("6x8",1);
|
||||
require("graph").drawLine(g, data, {
|
||||
axes: true,
|
||||
x: 4,
|
||||
y: Bangle.appRect.y+8,
|
||||
height: Bangle.appRect.h-20,
|
||||
gridx: 1,
|
||||
gridy: 1,
|
||||
miny: Math.min.apply(null, data)-1,
|
||||
maxy: Math.max.apply(null, data)+1,
|
||||
title: /*LANG*/"Barometer history (mBar)",
|
||||
ylabel: y => y,
|
||||
xlabel: i => {
|
||||
const t = -3*60 + settings.interval*i;
|
||||
if (t % 60 === 0) {
|
||||
return "-" + t/60 + "h";
|
||||
}
|
||||
return "";
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
showMainMenu();
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue