0.07: Ensure barometer gets turned off after a few readings (isBarometerOn broken in 2v16)

master
Gordon Williams 2023-02-27 13:17:41 +00:00
parent 769c4c2793
commit cc24cb5bb3
3 changed files with 29 additions and 28 deletions

View File

@ -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)

View File

@ -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",

View File

@ -211,19 +211,8 @@ function calculcate3hAveragePressure() {
} }
} }
/* function barometerPressureHandler(e) {
turn on barometer power
take multiple measurements
sort the results
take the middle one (median)
turn off barometer power
*/
function getPressureValue() {
if (stop)
return;
const MEDIANLENGTH = 20; const MEDIANLENGTH = 20;
Bangle.setBarometerPower(true, "widbaroalarm");
Bangle.on('pressure', function(e) {
while (currentPressures.length > MEDIANLENGTH) while (currentPressures.length > MEDIANLENGTH)
currentPressures.pop(); currentPressures.pop();
@ -242,13 +231,24 @@ function getPressureValue() {
} }
} }
} }
}); }
setTimeout(function() { turnOff(); }, 30000); /*
turn on barometer power
take multiple measurements
sort the results
take the middle one (median)
turn off barometer power
*/
function getPressureValue() {
if (stop) return;
Bangle.setBarometerPower(true, "widbaroalarm");
Bangle.on('pressure', barometerPressureHandler);
setTimeout(turnOff, 30000);
} }
function turnOff() { function turnOff() {
if (Bangle.isBarometerOn()) Bangle.removeListener('pressure', barometerPressureHandler);
Bangle.setBarometerPower(false, "widbaroalarm"); Bangle.setBarometerPower(false, "widbaroalarm");
} }