Fix draw define first
parent
274b51853f
commit
ffc8d201e3
|
|
@ -19,47 +19,44 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
let batt=E.getBattery();
|
let batt=E.getBattery();
|
||||||
let data = require("smartbatt").get();
|
let data = require("smartbatt").get();
|
||||||
let hrsLeft=data.hrsLeft;
|
let hrsLeft=data.hrsLeft;
|
||||||
let days = hrsLeft / 24;
|
let days = hrsLeft / 24;
|
||||||
|
|
||||||
let txt = showPercent
|
let txt = showPercent
|
||||||
? batt
|
? batt
|
||||||
: (days >= 1
|
: (days >= 1
|
||||||
? Math.round(Math.min(days, 99)) + "d"
|
? Math.round(Math.min(days, 99)) + "d"
|
||||||
: Math.round(hrsLeft) + "h");
|
: Math.round(hrsLeft) + "h");
|
||||||
if(Bangle.isCharging()) txt=E.getBattery();
|
if(Bangle.isCharging()) txt=E.getBattery();
|
||||||
let s = 29;
|
let s = 29;
|
||||||
let x = this.x, y = this.y;
|
let x = this.x, y = this.y;
|
||||||
let xl = x + 4 + batt * (s - 12) / 100;
|
let xl = x + 4 + batt * (s - 12) / 100;
|
||||||
|
|
||||||
// Drawing code follows...
|
// Drawing code follows...
|
||||||
g.setColor(COLORS.bg);
|
g.setColor(COLORS.bg);
|
||||||
g.fillRect(x + 2, y + 5, x + s - 6, y + 18);
|
g.fillRect(x + 2, y + 5, x + s - 6, y + 18);
|
||||||
|
|
||||||
g.setColor(levelColor(batt));
|
g.setColor(levelColor(batt));
|
||||||
g.fillRect(x + 1, y + 3, x + s - 5, y + 4);
|
g.fillRect(x + 1, y + 3, x + s - 5, y + 4);
|
||||||
g.fillRect(x + 1, y + 19, x + s - 5, y + 20);
|
g.fillRect(x + 1, y + 19, x + s - 5, y + 20);
|
||||||
g.fillRect(x, y + 4, x + 1, y + 19);
|
g.fillRect(x, y + 4, x + 1, y + 19);
|
||||||
g.fillRect(x + s - 5, y + 4, x + s - 4, y + 19);
|
g.fillRect(x + s - 5, y + 4, x + s - 4, y + 19);
|
||||||
g.fillRect(x + s - 3, y + 8, x + s - 2, y + 16);
|
g.fillRect(x + s - 3, y + 8, x + s - 2, y + 16);
|
||||||
g.fillRect(x + 4, y + 15, xl, y + 16);
|
g.fillRect(x + 4, y + 15, xl, y + 16);
|
||||||
|
|
||||||
g.setColor(COLORS.fg);
|
g.setColor(COLORS.fg);
|
||||||
g.setFontAlign(0, 0);
|
g.setFontAlign(0, 0);
|
||||||
g.setFont('6x8');
|
g.setFont('6x8');
|
||||||
g.drawString(txt, x + 14, y + 10);
|
g.drawString(txt, x + 14, y + 10);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
WIDGETS["widsmartbatt"] = {
|
WIDGETS["widsmartbatt"] = {
|
||||||
area: "tr",
|
area: "tr",
|
||||||
width: 30,
|
width: 30,
|
||||||
draw: function() {
|
draw: draw
|
||||||
// Call your drawing function
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Touch to temporarily show battery percent
|
// Touch to temporarily show battery percent
|
||||||
|
|
@ -73,7 +70,6 @@
|
||||||
if (w.x - oversize <= x && x < w.x + width + oversize
|
if (w.x - oversize <= x && x < w.x + width + oversize
|
||||||
&& w.y - oversize <= y && y < w.y + height + oversize) {
|
&& w.y - oversize <= y && y < w.y + height + oversize) {
|
||||||
E.stopEventPropagation && E.stopEventPropagation();
|
E.stopEventPropagation && E.stopEventPropagation();
|
||||||
Bangle.buzz(20);
|
|
||||||
showPercent = true;
|
showPercent = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
showPercent = false;
|
showPercent = false;
|
||||||
|
|
@ -87,7 +83,7 @@
|
||||||
Bangle.on('charging', function () {
|
Bangle.on('charging', function () {
|
||||||
WIDGETS["widsmartbatt"].draw();
|
WIDGETS["widsmartbatt"].draw();
|
||||||
});
|
});
|
||||||
//draw once per minute...
|
|
||||||
var id = setInterval(() => WIDGETS["widsmartbatt"].draw(), 60000);
|
var id = setInterval(() => WIDGETS["widsmartbatt"].draw(), 60000);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue