Create clkinfo.js from @RelapsingCertainly's gist, added avgDrainage clkInfo

master
RKBoss6 2025-08-02 15:43:47 -04:00 committed by GitHub
parent 611fa88828
commit a0dd97cece
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 89 additions and 0 deletions

89
apps/smartbatt/clkinfo.js Normal file
View File

@ -0,0 +1,89 @@
(function() {
var img;
var v;
var data;
var hrLeft = 0;
var daysLeft = 0;
var showPercent=false;
//updates values
function updateValues(){
v = E.getBattery();
data = require("smartbatt").get();
hrLeft = data.hrsLeft;
daysLeft = hrLeft / 24;
hrLeft = Math.round(hrLeft);
daysLeft = Math.round(daysLeft);
}
//draws battery icon and fill bar
function drawBatt(){
v =E.getBattery();
var s=24,g=Graphics.createArrayBuffer(24,24,1,{msb:true});
g.fillRect(0,6,s-3,18).clearRect(2,8,s-5,16).fillRect(s-2,10,s,15).fillRect(3,9,3+v*(s-9)/100,15);
g.transparent=0;
img=g.asImage("string");
}
//calls both updates for values and icons.
//might split in the future since values updates once every five minutes so we dont need to call it in every minute while the battery can be updated once a minute.
function updateDisplay(){
updateValues();
drawBatt();
}
return {
name: "SmartBatt",
items: [
{ name : "BattStatus",
get : () => {
updateValues();
drawBatt();
//update clock info according to batt state
if (Bangle.isCharging()) {
return { text: v+"%", img : img};
}
else if(daysLeft >= 1) {
return { text: daysLeft+"d", img : img};
}
else {
return {text: hrLeft+"h", img: img};
}
},
show : function() {
this.interval = setInterval(()=>{
updateDisplay();
this.emit('redraw');
}, 60000);
},
hide : function() {
clearInterval(this.interval);
this.interval = undefined;
}
},
{ name : "AvgDrainage",
get : () => {
drawBatt()
var data=require("smartbatt").get();
return { text: data.avgDrainage.toFixed(2)+"/h", img : img};
},
show : function() {
this.interval = setInterval(()=>{
this.emit('redraw');
}, 60000);
},
hide : function() {
clearInterval(this.interval);
this.interval = undefined;
}
}
]
};
})