altimeter 0.05: Prompt before resetting calibration (stops long-press of button resetting calibration)
parent
1b50cdf31d
commit
eb937a6f67
|
|
@ -2,3 +2,4 @@
|
|||
0.02: Actually upload correct code
|
||||
0.03: Display sea-level pressure, too, and allow calibration
|
||||
0.04: Switch to using system code for pressure calibration
|
||||
0.05: Prompt before resetting calibration (stops long-press of button resetting calibration)
|
||||
|
|
@ -7,6 +7,7 @@ var R = Bangle.appRect;
|
|||
var y = R.y + R.h/2;
|
||||
var MEDIANLENGTH = 20;
|
||||
var avr = [];
|
||||
var updateDisplay = true;
|
||||
|
||||
function fmt(t) {
|
||||
if ((t > -100) && (t < 1000))
|
||||
|
|
@ -19,48 +20,57 @@ function fmt(t) {
|
|||
Bangle.on('pressure', function(e) {
|
||||
while (avr.length>MEDIANLENGTH) avr.pop();
|
||||
avr.unshift(e.altitude);
|
||||
let median = avr.slice().sort();
|
||||
if (!updateDisplay) return;
|
||||
let median = avr.slice().sort(), value;
|
||||
g.reset().clearRect(0,y-30,g.getWidth()-10,R.h);
|
||||
if (median.length>10) {
|
||||
var mid = median.length>>1;
|
||||
var value = E.sum(median.slice(mid-4,mid+5)) / 9;
|
||||
value = E.sum(median.slice(mid-4,mid+5)) / 9;
|
||||
} else {
|
||||
var value = median[median.length>>1];
|
||||
value = median[median.length>>1];
|
||||
}
|
||||
t = fmt(value);
|
||||
var t = fmt(value);
|
||||
|
||||
g.setFont("Vector",50).setFontAlign(0,0).drawString(t, g.getWidth()/2, y);
|
||||
|
||||
let o = Bangle.getOptions();
|
||||
let sea = o.seaLevelPressure;
|
||||
t = sea.toFixed(1) + " " + e.temperature.toFixed(1);
|
||||
if (0) {
|
||||
/*if (0) {
|
||||
print("alt raw:", value.toFixed(1));
|
||||
print("temperature:", e.temperature);
|
||||
print("pressure:", e.pressure);
|
||||
print("sea pressure:", sea);
|
||||
}
|
||||
}*/
|
||||
g.setFont("Vector",25).setFontAlign(-1,0).drawString(t, 10, R.y+R.h - 35);
|
||||
});
|
||||
|
||||
function setPressure(m, a) {
|
||||
o = Bangle.getOptions();
|
||||
print(o);
|
||||
var o = Bangle.getOptions();
|
||||
//print(o);
|
||||
o.seaLevelPressure = o.seaLevelPressure * m + a;
|
||||
Bangle.setOptions(o);
|
||||
avr = [];
|
||||
}
|
||||
|
||||
print(g.getFonts());
|
||||
g.reset();
|
||||
g.setFont("Vector:15");
|
||||
g.setFontAlign(0,0);
|
||||
g.drawString(/*LANG*/"ALTITUDE (m)", g.getWidth()/2, y-40);
|
||||
g.drawString(/*LANG*/"SEA L (hPa) TEMP (C)", g.getWidth()/2, y+62);
|
||||
g.flip();
|
||||
g.setFont("6x8").setFontAlign(0,0,3).drawString(/*LANG*/"STD", g.getWidth()-5, g.getHeight()/2);
|
||||
Bangle.setUI("updown", btn=> {
|
||||
if (!btn) setPressure(0, 1013.25);
|
||||
if (btn<0) setPressure(1, 1);
|
||||
if (btn>0) setPressure(1, -1);
|
||||
});
|
||||
function start() {
|
||||
g.reset();
|
||||
g.setFont("Vector:15");
|
||||
g.setFontAlign(0,0);
|
||||
g.drawString(/*LANG*/"ALTITUDE (m)", g.getWidth()/2, y-40);
|
||||
g.drawString(/*LANG*/"SEA L (hPa) TEMP (C)", g.getWidth()/2, y+62);
|
||||
g.setFont("6x8").setFontAlign(0,0,3).drawString(/*LANG*/"STD", g.getWidth()-5, g.getHeight()/2);
|
||||
updateDisplay = true;
|
||||
Bangle.setUI("updown", btn => {
|
||||
if (!btn) {
|
||||
updateDisplay = false;
|
||||
E.showPrompt(/*LANG*/"Set calibration to default?",{title:/*LANG*/"Altitude"}).then(function(reset) {
|
||||
start();
|
||||
if (reset) setPressure(0, 1013.25);
|
||||
});
|
||||
}
|
||||
if (btn<0) setPressure(1, 1);
|
||||
if (btn>0) setPressure(1, -1);
|
||||
});
|
||||
}
|
||||
start();
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{ "id": "altimeter",
|
||||
"name": "Altimeter",
|
||||
"version":"0.04",
|
||||
"version":"0.05",
|
||||
"description": "Simple altimeter that can display height changed using Bangle.js 2's built in pressure sensor.",
|
||||
"icon": "app.png",
|
||||
"tags": "tool,outdoors",
|
||||
|
|
|
|||
|
|
@ -925,12 +925,6 @@ module.exports = {
|
|||
"no-undef"
|
||||
]
|
||||
},
|
||||
"apps/fileman/fileman.app.js": {
|
||||
"hash": "f378179e7dd3655ba7e9ce03e1f7fd5a2d1768ad7d9083b22e7d740405be842a",
|
||||
"rules": [
|
||||
"no-undef"
|
||||
]
|
||||
},
|
||||
"apps/flappy/app.js": {
|
||||
"hash": "e24b0c5e0469070e02dae00887bf50569c2c141a80c7c356b36987ddf68ce9cc",
|
||||
"rules": [
|
||||
|
|
@ -1051,12 +1045,6 @@ module.exports = {
|
|||
"no-undef"
|
||||
]
|
||||
},
|
||||
"apps/altimeter/app.js": {
|
||||
"hash": "054ac328db51034aa339f1d10b4d264badd49438b95f08bc6fbfb90bd88c6ae0",
|
||||
"rules": [
|
||||
"no-undef"
|
||||
]
|
||||
},
|
||||
"apps/alpinenav/app.js": {
|
||||
"hash": "f8e59724d282f7c5c989adf64974a3728dc521aa8fbe047b7c37dae09213095a",
|
||||
"rules": [
|
||||
|
|
|
|||
Loading…
Reference in New Issue