Skip to content

Commit eb937a6

Browse files
committed
altimeter 0.05: Prompt before resetting calibration (stops long-press of button resetting calibration)
1 parent 1b50cdf commit eb937a6

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

apps/altimeter/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
0.02: Actually upload correct code
33
0.03: Display sea-level pressure, too, and allow calibration
44
0.04: Switch to using system code for pressure calibration
5+
0.05: Prompt before resetting calibration (stops long-press of button resetting calibration)

apps/altimeter/app.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var R = Bangle.appRect;
77
var y = R.y + R.h/2;
88
var MEDIANLENGTH = 20;
99
var avr = [];
10+
var updateDisplay = true;
1011

1112
function fmt(t) {
1213
if ((t > -100) && (t < 1000))
@@ -19,48 +20,57 @@ function fmt(t) {
1920
Bangle.on('pressure', function(e) {
2021
while (avr.length>MEDIANLENGTH) avr.pop();
2122
avr.unshift(e.altitude);
22-
let median = avr.slice().sort();
23+
if (!updateDisplay) return;
24+
let median = avr.slice().sort(), value;
2325
g.reset().clearRect(0,y-30,g.getWidth()-10,R.h);
2426
if (median.length>10) {
2527
var mid = median.length>>1;
26-
var value = E.sum(median.slice(mid-4,mid+5)) / 9;
28+
value = E.sum(median.slice(mid-4,mid+5)) / 9;
2729
} else {
28-
var value = median[median.length>>1];
30+
value = median[median.length>>1];
2931
}
30-
t = fmt(value);
32+
var t = fmt(value);
3133

3234
g.setFont("Vector",50).setFontAlign(0,0).drawString(t, g.getWidth()/2, y);
3335

3436
let o = Bangle.getOptions();
3537
let sea = o.seaLevelPressure;
3638
t = sea.toFixed(1) + " " + e.temperature.toFixed(1);
37-
if (0) {
39+
/*if (0) {
3840
print("alt raw:", value.toFixed(1));
3941
print("temperature:", e.temperature);
4042
print("pressure:", e.pressure);
4143
print("sea pressure:", sea);
42-
}
44+
}*/
4345
g.setFont("Vector",25).setFontAlign(-1,0).drawString(t, 10, R.y+R.h - 35);
4446
});
4547

4648
function setPressure(m, a) {
47-
o = Bangle.getOptions();
48-
print(o);
49+
var o = Bangle.getOptions();
50+
//print(o);
4951
o.seaLevelPressure = o.seaLevelPressure * m + a;
5052
Bangle.setOptions(o);
5153
avr = [];
5254
}
5355

54-
print(g.getFonts());
55-
g.reset();
56-
g.setFont("Vector:15");
57-
g.setFontAlign(0,0);
58-
g.drawString(/*LANG*/"ALTITUDE (m)", g.getWidth()/2, y-40);
59-
g.drawString(/*LANG*/"SEA L (hPa) TEMP (C)", g.getWidth()/2, y+62);
60-
g.flip();
61-
g.setFont("6x8").setFontAlign(0,0,3).drawString(/*LANG*/"STD", g.getWidth()-5, g.getHeight()/2);
62-
Bangle.setUI("updown", btn=> {
63-
if (!btn) setPressure(0, 1013.25);
64-
if (btn<0) setPressure(1, 1);
65-
if (btn>0) setPressure(1, -1);
66-
});
56+
function start() {
57+
g.reset();
58+
g.setFont("Vector:15");
59+
g.setFontAlign(0,0);
60+
g.drawString(/*LANG*/"ALTITUDE (m)", g.getWidth()/2, y-40);
61+
g.drawString(/*LANG*/"SEA L (hPa) TEMP (C)", g.getWidth()/2, y+62);
62+
g.setFont("6x8").setFontAlign(0,0,3).drawString(/*LANG*/"STD", g.getWidth()-5, g.getHeight()/2);
63+
updateDisplay = true;
64+
Bangle.setUI("updown", btn => {
65+
if (!btn) {
66+
updateDisplay = false;
67+
E.showPrompt(/*LANG*/"Set calibration to default?",{title:/*LANG*/"Altitude"}).then(function(reset) {
68+
start();
69+
if (reset) setPressure(0, 1013.25);
70+
});
71+
}
72+
if (btn<0) setPressure(1, 1);
73+
if (btn>0) setPressure(1, -1);
74+
});
75+
}
76+
start();

apps/altimeter/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ "id": "altimeter",
22
"name": "Altimeter",
3-
"version":"0.04",
3+
"version":"0.05",
44
"description": "Simple altimeter that can display height changed using Bangle.js 2's built in pressure sensor.",
55
"icon": "app.png",
66
"tags": "tool,outdoors",

apps/lint_exemptions.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -925,12 +925,6 @@ module.exports = {
925925
"no-undef"
926926
]
927927
},
928-
"apps/fileman/fileman.app.js": {
929-
"hash": "f378179e7dd3655ba7e9ce03e1f7fd5a2d1768ad7d9083b22e7d740405be842a",
930-
"rules": [
931-
"no-undef"
932-
]
933-
},
934928
"apps/flappy/app.js": {
935929
"hash": "e24b0c5e0469070e02dae00887bf50569c2c141a80c7c356b36987ddf68ce9cc",
936930
"rules": [
@@ -1051,12 +1045,6 @@ module.exports = {
10511045
"no-undef"
10521046
]
10531047
},
1054-
"apps/altimeter/app.js": {
1055-
"hash": "054ac328db51034aa339f1d10b4d264badd49438b95f08bc6fbfb90bd88c6ae0",
1056-
"rules": [
1057-
"no-undef"
1058-
]
1059-
},
10601048
"apps/alpinenav/app.js": {
10611049
"hash": "f8e59724d282f7c5c989adf64974a3728dc521aa8fbe047b7c37dae09213095a",
10621050
"rules": [

0 commit comments

Comments
 (0)