Merge pull request #813 from hughbarney/master

Fixed widbatpc for Bangle 2
master
Gordon Williams 2021-09-20 10:11:30 +01:00 committed by GitHub
commit e9c67bcc72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 15 deletions

View File

@ -639,10 +639,11 @@
"name": "Battery Level Widget (with percentage)", "name": "Battery Level Widget (with percentage)",
"shortName": "Battery Widget", "shortName": "Battery Widget",
"icon": "widget.png", "icon": "widget.png",
"version":"0.11", "version":"0.12",
"description": "Show the current battery level and charging status in the top right of the clock, with charge percentage", "description": "Show the current battery level and charging status in the top right of the clock, with charge percentage",
"tags": "widget,battery", "tags": "widget,battery,b2",
"type":"widget", "type":"widget",
"readme": "README.md",
"storage": [ "storage": [
{"name":"widbatpc.wid.js","url":"widget.js"}, {"name":"widbatpc.wid.js","url":"widget.js"},
{"name":"widbatpc.settings.js","url":"settings.js"} {"name":"widbatpc.settings.js","url":"settings.js"}

View File

@ -8,3 +8,4 @@
0.09: Fix regression stopping correct widget updates 0.09: Fix regression stopping correct widget updates
0.10: Add 'hide if charge greater than' 0.10: Add 'hide if charge greater than'
0.11: Don't overwrite existing settings on app update 0.11: Don't overwrite existing settings on app update
0.12: Fixed for Bangle 2

8
apps/widbatpc/README.md Normal file
View File

@ -0,0 +1,8 @@
# Battery Widget
Show the current battery level and charging status in the top right of the clock, with charge percentage
Works with Bangle 1 and Bangle 2
![](screenshot.jpg)

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,10 +1,23 @@
(function(){ (function(){
const COLORS = { let COLORS = {};
'white': -1,
'charging': 0x07E0, // "Green" if (process.env.HWVERSION == 1) {
'high': 0x05E0, // slightly darker green COLORS = {
'ok': 0xFD20, // "Orange" 'white': -1, // White
'low':0xF800, // "Red" 'charging': 0x07E0, // Green
'high': 0x05E0, // lightly darker green
'ok': 0xFD20, // Orange
'low': 0xF800, // Red
};
} else {
// bangle 2 is only 7 bit colors
COLORS = {
'white': "#fff", // White
'charging': "#0f0", // Green
'high': "#0f0", // Green
'ok': "#ff0", // Orange
'low': "#f00", // Red
};
} }
const SETTINGS_FILE = 'widbatpc.json' const SETTINGS_FILE = 'widbatpc.json'
@ -66,29 +79,28 @@
// else... // else...
var s = 39; var s = 39;
var x = this.x, y = this.y; var x = this.x, y = this.y;
const l = E.getBattery(), const l = E.getBattery();
c = levelColor(l);
const xl = x+4+l*(s-12)/100 const xl = x+4+l*(s-12)/100
c = levelColor(l);
if (Bangle.isCharging() && setting('charger')) { if (Bangle.isCharging() && setting('charger')) {
g.setColor(chargerColor()).drawImage(atob( g.setColor(chargerColor()).drawImage(atob(
"DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); "DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y);
x+=16; x+=16;
} }
g.setColor(-1); g.setColor(g.theme.fg);
g.fillRect(x,y+2,x+s-4,y+21); g.fillRect(x,y+2,x+s-4,y+21);
g.clearRect(x+2,y+4,x+s-6,y+19); g.clearRect(x+2,y+4,x+s-6,y+19);
g.fillRect(x+s-3,y+10,x+s,y+14); g.fillRect(x+s-3,y+10,x+s,y+14);
g.setColor(c).fillRect(x+4,y+6,xl,y+17); g.setColor(c).fillRect(x+4,y+6,xl,y+17);
g.setColor(-1); g.setColor(g.theme.fg);
if (!setting('percentage')) { if (!setting('percentage')) {
return; return;
} }
let gfx = g let gfx = g
if (setting('color') === 'Monochrome') { if (setting('color') === 'Monochrome') {
// draw text inverted on battery level // draw text inverted on battery level
gfx = Graphics.createCallback(240, 240, 1, gfx = Graphics.createCallback(g.getWidth(),g.getHeight(), 1,
(x,y) => {g.setPixel(x,y,x<=xl?0:-1)}) (x,y) => {g.setPixel(x,y,x<=xl?0:-1)})
} }
gfx.setFontAlign(-1,-1); gfx.setFontAlign(-1,-1);