Update widalt.wid.js

master
xxDUxx 2023-01-26 18:18:55 +01:00 committed by GitHub
parent 8c70038661
commit 4e6cc0961d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 25 deletions

View File

@ -1,38 +1,42 @@
(()=>{ (() => {
var alt=""; var alt = "";
var lastAlt=0; var lastAlt;
var timeout;
var settings = Object.assign({ var settings = Object.assign({
interval: 5000, interval: 60000,
}, require('Storage').readJSON("widalt.json", true) || {}); }, require('Storage').readJSON("widalt.json", true) || {});
Bangle.setBarometerPower(true,"widalt"); Bangle.setBarometerPower(true, "widalt");
Bangle.on("pressure", (p)=>{ Bangle.on("pressure", (p) => {
if (Math.floor(p.altitude)!=lastAlt) { if (timeout) return;
lastAlt=Math.floor(p.altitude); //some other app is using the barometer - ignore new readings until our interval is up
alt=p.altitude.toFixed(0); if (Math.floor(p.altitude) != lastAlt) {
var w = WIDGETS["widalt"].width; lastAlt = Math.floor(p.altitude);
WIDGETS["widalt"].width = 1 + (alt.length)*12+16; nextUpdate = Date.now() + settings.interval;
if (w!=WIDGETS["widalt"].width) Bangle.drawWidgets(); alt = p.altitude.toFixed(0);
else WIDGETS["widalt"].draw(); WIDGETS.widalt.draw();
} }
Bangle.setBarometerPower(false,"widalt") Bangle.setBarometerPower(false, "widalt");
setTimeout(()=>{Bangle.setBarometerPower(true,"widalt");},settings.interval); timeout = setTimeout(() => {
timeout = undefined;
Bangle.setBarometerPower(true, "widalt");
}, settings.interval);
}); });
function draw() { function draw() {
if (!Bangle.isLCDOn()) return; if (!Bangle.isLCDOn()) return;
g.reset(); g.reset();
g.setColor(g.theme.bg); g.clearRect(this.x, this.y, this.x + this.width, this.y + 23);
g.fillRect(this.x, this.y, this.x + this.width, this.y + 23); var w = this.width;
g.setColor(g.theme.fg); this.width = 1 + (alt.length) * 12 + 16;
g.drawImage(atob("EBCBAAAAAAAIAAwgFXAX0BCYIIggTD/EYPZADkACf/4AAAAA"), this.x, this.y+4); if (w != this.width) Bang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AAOAAH4AA/gQMMGBgzwME8BhvAOPgA/4AD8AAEAAAAAAGAwA4OAHBwAAA="), 46, atob("BAgMDAwMDAwMDAwMBQ=="), 21 + (1 << 8) + (1 << 16));
g.setFontAlign(-1, 0); g.setFontAlign(-1, 0);
g.drawString(alt, this.x+16, this.y + 12); g.drawString(alt, this.x + 16, this.y + 12);
} }
WIDGETS["widalt"] = { WIDGETS.widalt = {
area: "tr", area: "tr",
width: 6, width: 6,
draw: draw draw: draw
}; };
})(); })();