barometer

- update every second
- go back with short button press
master
Erik Andresen 2022-10-27 21:09:43 +02:00
parent a897cbb38d
commit b095eb74cd
3 changed files with 20 additions and 11 deletions

View File

@ -1,3 +1,4 @@
0.01: Display pressure as number and hand 0.01: Display pressure as number and hand
0.02: Use theme color 0.02: Use theme color
0.03: workaround for some firmwares that return 'undefined' for first call to barometer 0.03: workaround for some firmwares that return 'undefined' for first call to barometer
0.04: Update every second, go back with short button press

View File

@ -59,6 +59,7 @@ function drawTicks(){
function drawScaleLabels(){ function drawScaleLabels(){
g.setColor(g.theme.fg); g.setColor(g.theme.fg);
g.setFont("Vector",12); g.setFont("Vector",12);
g.setFontAlign(-1,-1);
let label = MIN; let label = MIN;
for (let i=0;i <= NUMBER_OF_LABELS; i++){ for (let i=0;i <= NUMBER_OF_LABELS; i++){
@ -103,22 +104,29 @@ function drawIcons() {
} }
g.setBgColor(g.theme.bg); g.setBgColor(g.theme.bg);
g.clear();
drawTicks();
drawScaleLabels();
drawIcons();
try { try {
function baroHandler(data) { function baroHandler(data) {
if (data===undefined) // workaround for https://github.com/espruino/BangleApps/issues/1429 g.clear();
setTimeout(() => Bangle.getPressure().then(baroHandler), 500);
else drawTicks();
drawScaleLabels();
drawIcons();
if (data!==undefined) {
drawHand(Math.round(data.pressure)); drawHand(Math.round(data.pressure));
} }
}
Bangle.getPressure().then(baroHandler); Bangle.getPressure().then(baroHandler);
setInterval(() => Bangle.getPressure().then(baroHandler), 1000);
} catch(e) { } catch(e) {
if (e !== undefined) {
print(e.message); print(e.message);
print("barometer not supporter, show a demo value"); }
print("barometer not supported, show a demo value");
drawHand(MIN); drawHand(MIN);
} }
Bangle.setUI({
mode : "custom",
back : function() {load();}
});

View File

@ -1,7 +1,7 @@
{ "id": "barometer", { "id": "barometer",
"name": "Barometer", "name": "Barometer",
"shortName":"Barometer", "shortName":"Barometer",
"version":"0.03", "version":"0.04",
"description": "A simple barometer that displays the current air pressure", "description": "A simple barometer that displays the current air pressure",
"icon": "barometer.png", "icon": "barometer.png",
"tags": "tool,outdoors", "tags": "tool,outdoors",