0.07: Ensure barometer gets turned off after a few readings (isBarometerOn broken in 2v16)
parent
769c4c2793
commit
cc24cb5bb3
|
|
@ -7,3 +7,4 @@
|
||||||
Show difference of last measurement to pressure average of the the last three hours in the widget
|
Show difference of last measurement to pressure average of the the last three hours in the widget
|
||||||
Only use valid pressure values
|
Only use valid pressure values
|
||||||
0.06: Fix exception
|
0.06: Fix exception
|
||||||
|
0.07: Ensure barometer gets turned off after a few readings (isBarometerOn broken in 2v16)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "widbaroalarm",
|
"id": "widbaroalarm",
|
||||||
"name": "Barometer Alarm Widget",
|
"name": "Barometer Alarm Widget",
|
||||||
"shortName": "Barometer Alarm",
|
"shortName": "Barometer Alarm",
|
||||||
"version": "0.06",
|
"version": "0.07",
|
||||||
"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",
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,28 @@ function calculcate3hAveragePressure() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function barometerPressureHandler(e) {
|
||||||
|
const MEDIANLENGTH = 20;
|
||||||
|
while (currentPressures.length > MEDIANLENGTH)
|
||||||
|
currentPressures.pop();
|
||||||
|
|
||||||
|
const pressure = e.pressure;
|
||||||
|
if (isValidPressureValue(pressure)) {
|
||||||
|
currentPressures.unshift(pressure);
|
||||||
|
median = currentPressures.slice().sort();
|
||||||
|
|
||||||
|
if (median.length > 10) {
|
||||||
|
var mid = median.length >> 1;
|
||||||
|
medianPressure = Math.round(E.sum(median.slice(mid - 4, mid + 5)) / 9);
|
||||||
|
if (medianPressure > 0) {
|
||||||
|
turnOff();
|
||||||
|
draw();
|
||||||
|
handlePressureValue(medianPressure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
turn on barometer power
|
turn on barometer power
|
||||||
take multiple measurements
|
take multiple measurements
|
||||||
|
|
@ -219,37 +241,15 @@ function calculcate3hAveragePressure() {
|
||||||
turn off barometer power
|
turn off barometer power
|
||||||
*/
|
*/
|
||||||
function getPressureValue() {
|
function getPressureValue() {
|
||||||
if (stop)
|
if (stop) return;
|
||||||
return;
|
|
||||||
const MEDIANLENGTH = 20;
|
|
||||||
Bangle.setBarometerPower(true, "widbaroalarm");
|
Bangle.setBarometerPower(true, "widbaroalarm");
|
||||||
Bangle.on('pressure', function(e) {
|
Bangle.on('pressure', barometerPressureHandler);
|
||||||
while (currentPressures.length > MEDIANLENGTH)
|
setTimeout(turnOff, 30000);
|
||||||
currentPressures.pop();
|
|
||||||
|
|
||||||
const pressure = e.pressure;
|
|
||||||
if (isValidPressureValue(pressure)) {
|
|
||||||
currentPressures.unshift(pressure);
|
|
||||||
median = currentPressures.slice().sort();
|
|
||||||
|
|
||||||
if (median.length > 10) {
|
|
||||||
var mid = median.length >> 1;
|
|
||||||
medianPressure = Math.round(E.sum(median.slice(mid - 4, mid + 5)) / 9);
|
|
||||||
if (medianPressure > 0) {
|
|
||||||
turnOff();
|
|
||||||
draw();
|
|
||||||
handlePressureValue(medianPressure);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function() { turnOff(); }, 30000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function turnOff() {
|
function turnOff() {
|
||||||
if (Bangle.isBarometerOn())
|
Bangle.removeListener('pressure', barometerPressureHandler);
|
||||||
Bangle.setBarometerPower(false, "widbaroalarm");
|
Bangle.setBarometerPower(false, "widbaroalarm");
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue