Merge branch 'widbat' of https://github.com/rigrig/BangleApps into rigrig-widbat
commit
42d0646383
|
|
@ -326,7 +326,7 @@
|
||||||
{ "id": "widbat",
|
{ "id": "widbat",
|
||||||
"name": "Battery Level Widget",
|
"name": "Battery Level Widget",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"version":"0.04",
|
"version":"0.06",
|
||||||
"description": "Show the current battery level and charging status in the top right of the clock",
|
"description": "Show the current battery level and charging status in the top right of the clock",
|
||||||
"tags": "widget,battery",
|
"tags": "widget,battery",
|
||||||
"type":"widget",
|
"type":"widget",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
0.02: Now refresh battery monitor every minute if LCD on
|
0.02: Now refresh battery monitor every minute if LCD on
|
||||||
0.03: Tweaks for variable size widget system
|
0.03: Tweaks for variable size widget system
|
||||||
0.04: Ensure redrawing works with variable size widget system
|
0.04: Ensure redrawing works with variable size widget system
|
||||||
|
0.05: Change color depending on battery level
|
||||||
|
0.06: Show battery percentage as text
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
(function(){
|
(function(){
|
||||||
var CHARGING = 0x07E0;
|
const levelColor = (l) => {
|
||||||
|
if (Bangle.isCharging()) return 0x07E0; // "Green"
|
||||||
|
if (l >= 50) return 0x05E0; // slightly darker green
|
||||||
|
if (l >= 15) return 0xFD20; // "Orange"
|
||||||
|
return 0xF800; // "Red"
|
||||||
|
}
|
||||||
|
|
||||||
function setWidth() {
|
function setWidth() {
|
||||||
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
|
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
|
||||||
|
|
@ -7,16 +12,27 @@ function setWidth() {
|
||||||
function draw() {
|
function draw() {
|
||||||
var s = 39;
|
var s = 39;
|
||||||
var x = this.x, y = this.y;
|
var x = this.x, y = this.y;
|
||||||
|
const l = E.getBattery(), c = levelColor(l);
|
||||||
if (Bangle.isCharging()) {
|
if (Bangle.isCharging()) {
|
||||||
g.setColor(CHARGING).drawImage(atob("DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y);
|
g.setColor(c).drawImage(atob(
|
||||||
|
"DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y);
|
||||||
x+=16;
|
x+=16;
|
||||||
}
|
}
|
||||||
g.setColor(-1);
|
g.setColor(-1);
|
||||||
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(CHARGING).fillRect(x+4,y+6,x+4+E.getBattery()*(s-12)/100,y+17);
|
g.setColor(c).fillRect(x+4,y+6,x+4+l*(s-12)/100,y+17);
|
||||||
g.setColor(-1);
|
g.setColor(-1);
|
||||||
|
g.setFontAlign(-1,-1);
|
||||||
|
if (l >= 100) {
|
||||||
|
g.setFont('4x6', 2);
|
||||||
|
g.drawString(l, x + 6, y + 7);
|
||||||
|
} else {
|
||||||
|
if (l < 10) x+=6;
|
||||||
|
g.setFont('6x8', 2);
|
||||||
|
g.drawString(l, x + 6, y + 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Bangle.on('charging',function(charging) {
|
Bangle.on('charging',function(charging) {
|
||||||
if(charging) Bangle.buzz();
|
if(charging) Bangle.buzz();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue