Yet Another Battery Widget

pull/2692/head
Hugh Barney 2023-04-16 17:01:30 +01:00
parent 82b78d5b69
commit 2216398bb8
5 changed files with 54 additions and 0 deletions

11
apps/widbatc/README.md Normal file
View File

@ -0,0 +1,11 @@
# Yet Another Battery Widget
Shows the current battery level status in the top right in digits using the Lato font
* Works with Bangle 2
* Simple design, no settings
* Uses current colour theme to match clock
![](screenshot.png)
Written by: [Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/)

BIN
apps/widbatc/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -0,0 +1,17 @@
{
"id": "widbatac",
"name": "Yet Another Battery Widget",
"shortName":"Battery Level",
"icon": "icon.png",
"screenshots": [{"url":"screenshot.png"}],
"version":"0.01",
"type": "widget",
"supports": ["BANGLEJS", "BANGLEJS2"],
"readme": "README.md",
"description": "Shows the current battery level status in the top right using the Lato Font in digits",
"tags": "widget,battery",
"provides_widgets" : ["battery"],
"storage": [
{"name":"widbatc.wid.js","url":"widget.js"}
]
}

BIN
apps/widbatc/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

26
apps/widbatc/widget.js Normal file
View File

@ -0,0 +1,26 @@
setInterval(()=>WIDGETS["batc"].draw(), 60000);
Bangle.on('lcdPower', function(on) {
if (on) WIDGETS["bata"].draw();
});
WIDGETS["bata"]={area:"tr",sortorder:10,width:48,draw:function() {
g.reset();
// Lato from fonts.google.com, Actual height 17 (17 - 1), Numeric only
const scale = 1;
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+(scale<<8)+(1<<16));
var bp = "" + E.getBattery().toString();
var text_w = g.stringWidth(bp);
var bw = 7; // battery width
var w = text_w + 3 + bw + 2;
// we need this to be able to shrink or grow on the 3,2,1 digit battery levels
if (w != this.width) {this.width = w; setTimeout(() => Bangle.drawWidgets(),10); return;}
var h = 12; // height
var x = this.x, y = this.y + 4;
g.setColor(g.theme.bg);
g.fillRect(this.x, this.y, this.x + this.width, this.y + 23); // erase background
g.setColor(g.theme.fg);
g.setFontAlign(-1, 0);
g.drawString(bp, this.x, this.y + 12);
x = x + text_w + 3;
g.fillRect(x+2,y,x+5,y+1); // contact
g.fillRect(x,y+2,x+bw,y+2+h); // outer
}};