parent
936702d9fc
commit
e161a030c1
|
|
@ -76,6 +76,12 @@ function doWeNeedToAlarm(key) {
|
||||||
return setting(key) == undefined || setting(key) == 0 || setting(key) < tsNow;
|
return setting(key) == undefined || setting(key) == 0 || setting(key) < tsNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidPressureValue(pressure) {
|
||||||
|
if (pressure == undefined || pressure <= 0)
|
||||||
|
return false;
|
||||||
|
return pressure > 800 && pressure < 1200; // very rough values
|
||||||
|
}
|
||||||
|
|
||||||
function handlePressureValue(pressure) {
|
function handlePressureValue(pressure) {
|
||||||
if (pressure == undefined || pressure <= 0)
|
if (pressure == undefined || pressure <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -85,6 +91,17 @@ function handlePressureValue(pressure) {
|
||||||
|
|
||||||
history3.push(d);
|
history3.push(d);
|
||||||
|
|
||||||
|
// delete entries older than 3h
|
||||||
|
for (let i = 0; i < history3.length; i++) {
|
||||||
|
if (history3[i]["ts"] < ts - (3 * 60 * 60)) {
|
||||||
|
history3.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// delete oldest entries until we have max 50
|
||||||
|
while (history3.length > 50) {
|
||||||
|
history3.shift();
|
||||||
|
}
|
||||||
|
|
||||||
// write data to storage
|
// write data to storage
|
||||||
storage.writeJSON(LOG_FILE, history3);
|
storage.writeJSON(LOG_FILE, history3);
|
||||||
|
|
||||||
|
|
@ -99,17 +116,6 @@ function handlePressureValue(pressure) {
|
||||||
function checkForAlarms(pressure, ts) {
|
function checkForAlarms(pressure, ts) {
|
||||||
let alreadyWarned = false;
|
let alreadyWarned = false;
|
||||||
|
|
||||||
// delete entries older than 3h
|
|
||||||
for (let i = 0; i < history3.length; i++) {
|
|
||||||
if (history3[i]["ts"] < ts - (3 * 60 * 60)) {
|
|
||||||
history3.shift();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// delete oldest entries until we have max 50
|
|
||||||
while (history3.length > 50) {
|
|
||||||
history3.shift();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setting("lowalarm")) {
|
if (setting("lowalarm")) {
|
||||||
// Is below the alarm threshold?
|
// Is below the alarm threshold?
|
||||||
if (pressure <= setting("min")) {
|
if (pressure <= setting("min")) {
|
||||||
|
|
@ -217,8 +223,12 @@ function getPressureValue() {
|
||||||
Bangle.on('pressure', function(e) {
|
Bangle.on('pressure', function(e) {
|
||||||
while (currentPressures.length > MEDIANLENGTH)
|
while (currentPressures.length > MEDIANLENGTH)
|
||||||
currentPressures.pop();
|
currentPressures.pop();
|
||||||
currentPressures.unshift(e.pressure);
|
|
||||||
median = currentPressures.slice().sort();
|
const pressure = e.pressure;
|
||||||
|
if (isValidPressureValue(pressure)) {
|
||||||
|
currentPressures.unshift(pressure);
|
||||||
|
median = currentPressures.slice().sort();
|
||||||
|
}
|
||||||
|
|
||||||
if (median.length > 10) {
|
if (median.length > 10) {
|
||||||
var mid = median.length >> 1;
|
var mid = median.length >> 1;
|
||||||
|
|
@ -231,7 +241,7 @@ function getPressureValue() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function() { turnOff(); }, 10000);
|
setTimeout(function() { turnOff(); }, 30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function turnOff() {
|
function turnOff() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue