mirror of https://github.com/espruino/BangleApps
Copied widbat changes to new widget
parent
42d0646383
commit
257a8b2662
13
apps.json
13
apps.json
|
@ -326,7 +326,7 @@
|
||||||
{ "id": "widbat",
|
{ "id": "widbat",
|
||||||
"name": "Battery Level Widget",
|
"name": "Battery Level Widget",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"version":"0.06",
|
"version":"0.04",
|
||||||
"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",
|
||||||
|
@ -334,6 +334,17 @@
|
||||||
{"name":"widbat.wid.js","url":"widget.js"}
|
{"name":"widbat.wid.js","url":"widget.js"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{ "id": "widbatpc",
|
||||||
|
"name": "Battery Level Widget (with percentage)",
|
||||||
|
"icon": "widget.png",
|
||||||
|
"version":"0.06",
|
||||||
|
"description": "Show the current battery level and charging status in the top right of the clock, with charge percentage",
|
||||||
|
"tags": "widget,battery",
|
||||||
|
"type":"widget",
|
||||||
|
"storage": [
|
||||||
|
{"name":"widbatpc.wid.js","url":"widget.js"}
|
||||||
|
]
|
||||||
|
},
|
||||||
{ "id": "widbt",
|
{ "id": "widbt",
|
||||||
"name": "Bluetooth Widget",
|
"name": "Bluetooth Widget",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
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,10 +1,5 @@
|
||||||
(function(){
|
(function(){
|
||||||
const levelColor = (l) => {
|
var CHARGING = 0x07E0;
|
||||||
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);
|
||||||
|
@ -12,27 +7,16 @@ 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(c).drawImage(atob(
|
g.setColor(CHARGING).drawImage(atob("DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y);
|
||||||
"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(c).fillRect(x+4,y+6,x+4+l*(s-12)/100,y+17);
|
g.setColor(CHARGING).fillRect(x+4,y+6,x+4+E.getBattery()*(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();
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
0.02: Now refresh battery monitor every minute if LCD on
|
||||||
|
0.03: Tweaks for variable size widget system
|
||||||
|
0.04: Ensure redrawing works with variable size widget system
|
||||||
|
0.05: Change color depending on battery level, cloned from widbat
|
||||||
|
0.06: Show battery percentage as text
|
|
@ -0,0 +1,59 @@
|
||||||
|
(function(){
|
||||||
|
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() {
|
||||||
|
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
|
||||||
|
}
|
||||||
|
function draw() {
|
||||||
|
var s = 39;
|
||||||
|
var x = this.x, y = this.y;
|
||||||
|
const l = E.getBattery(), c = levelColor(l);
|
||||||
|
if (Bangle.isCharging()) {
|
||||||
|
g.setColor(c).drawImage(atob(
|
||||||
|
"DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y);
|
||||||
|
x+=16;
|
||||||
|
}
|
||||||
|
g.setColor(-1);
|
||||||
|
g.fillRect(x,y+2,x+s-4,y+21);
|
||||||
|
g.clearRect(x+2,y+4,x+s-6,y+19);
|
||||||
|
g.fillRect(x+s-3,y+10,x+s,y+14);
|
||||||
|
g.setColor(c).fillRect(x+4,y+6,x+4+l*(s-12)/100,y+17);
|
||||||
|
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) {
|
||||||
|
if(charging) Bangle.buzz();
|
||||||
|
setWidth();
|
||||||
|
Bangle.drawWidgets(); // relayout widgets
|
||||||
|
g.flip();
|
||||||
|
});
|
||||||
|
var batteryInterval;
|
||||||
|
Bangle.on('lcdPower', function(on) {
|
||||||
|
if (on) {
|
||||||
|
WIDGETS["bat"].draw();
|
||||||
|
// refresh once a minute if LCD on
|
||||||
|
if (!batteryInterval)
|
||||||
|
batteryInterval = setInterval(draw, 60000);
|
||||||
|
} else {
|
||||||
|
if (batteryInterval) {
|
||||||
|
clearInterval(batteryInterval);
|
||||||
|
batteryInterval = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
WIDGETS["bat"]={area:"tr",width:40,draw:draw};
|
||||||
|
setWidth();
|
||||||
|
})()
|
Binary file not shown.
After Width: | Height: | Size: 297 B |
Loading…
Reference in New Issue