2023-01-26 17:18:55 +00:00
|
|
|
(() => {
|
|
|
|
var alt = "";
|
|
|
|
var lastAlt;
|
|
|
|
var timeout;
|
2022-08-03 06:50:52 +00:00
|
|
|
var settings = Object.assign({
|
2023-01-26 17:18:55 +00:00
|
|
|
interval: 60000,
|
2022-08-03 06:50:52 +00:00
|
|
|
}, require('Storage').readJSON("widalt.json", true) || {});
|
2023-01-26 17:18:55 +00:00
|
|
|
Bangle.setBarometerPower(true, "widalt");
|
|
|
|
Bangle.on("pressure", (p) => {
|
|
|
|
if (timeout) return;
|
|
|
|
//some other app is using the barometer - ignore new readings until our interval is up
|
|
|
|
if (Math.floor(p.altitude) != lastAlt) {
|
|
|
|
lastAlt = Math.floor(p.altitude);
|
|
|
|
alt = p.altitude.toFixed(0);
|
|
|
|
WIDGETS.widalt.draw();
|
2022-08-03 06:06:08 +00:00
|
|
|
}
|
2023-01-26 17:18:55 +00:00
|
|
|
Bangle.setBarometerPower(false, "widalt");
|
|
|
|
timeout = setTimeout(() => {
|
|
|
|
timeout = undefined;
|
|
|
|
Bangle.setBarometerPower(true, "widalt");
|
|
|
|
}, settings.interval);
|
2022-08-03 06:06:08 +00:00
|
|
|
});
|
2023-01-26 17:18:55 +00:00
|
|
|
|
2022-08-02 07:27:26 +00:00
|
|
|
function draw() {
|
2023-01-26 17:18:55 +00:00
|
|
|
if (!Bangle.isLCDOn()) return;
|
2022-08-02 07:27:26 +00:00
|
|
|
g.reset();
|
2023-01-26 17:18:55 +00:00
|
|
|
g.clearRect(this.x, this.y, this.x + this.width, this.y + 23);
|
|
|
|
var w = this.width;
|
|
|
|
this.width = 1 + (alt.length) * 12 + 16;
|
|
|
|
if (w != this.width) Bangle.drawWidgets();
|
|
|
|
g.drawImage(atob("EBCBAAAAAAAIAAwgFXAX0BCYIIggTD/EYPZADkACf/4AAAAA"), this.x, this.y + 4);
|
|
|
|
g.setFontCustom(atob("AAAAABwAAOAAAgAAHAADwAD4AB8AB8AA+AAeAADAAAAOAAP+AH/8B4DwMAGBgAwMAGBgAwOAOA//gD/4AD4AAAAAAAABgAAcAwDAGAwAwP/+B//wAAGAAAwAAGAAAAAAAAIAwHgOA4DwMA+BgOwMDmBg4wOeGA/gwDwGAAAAAAAAAGAHA8A4DwMAGBhAwMMGBjgwOcOA+/gDj4AAAAABgAAcAAHgADsAA5gAOMAHBgBwMAP/+B//wABgAAMAAAAAAAgD4OB/AwOYGBjAwMYGBjBwMe8Bh/AIHwAAAAAAAAAfAAP8AHxwB8GAdgwPMGBxgwMOOAB/gAH4AAAAAAABgAAMAABgAwMAeBgPgMHwBj4AN8AB+AAPAABAAAAAAAMfAH38B/xwMcGBhgwMMGBjgwP+OA+/gDj4AAAAAAAAOAAH4AA/gQMMGBgzwME8BhvAOPgA/4AD8AAEAAAAAAGAwA4OAHBwAAA="), 46, atob("BAgMDAwMDAwMDAwMBQ=="), 21 + (1 << 8) + (1 << 16));
|
2022-08-02 07:27:26 +00:00
|
|
|
g.setFontAlign(-1, 0);
|
2023-01-26 17:18:55 +00:00
|
|
|
g.drawString(alt, this.x + 16, this.y + 12);
|
2022-08-02 07:27:26 +00:00
|
|
|
}
|
2023-01-26 17:18:55 +00:00
|
|
|
WIDGETS.widalt = {
|
2022-08-02 07:27:26 +00:00
|
|
|
area: "tr",
|
2022-08-02 11:48:47 +00:00
|
|
|
width: 6,
|
2022-08-02 07:27:26 +00:00
|
|
|
draw: draw
|
|
|
|
};
|
|
|
|
})();
|