BangleApps/apps/widhwbttm/widhwbttm.wid.js

59 lines
2.1 KiB
JavaScript
Raw Normal View History

(function() {
2022-12-15 12:02:10 +00:00
let intervalRef = null;
2022-12-21 12:39:33 +00:00
var v_count; // show stats
var v_str_hw=new String();
2022-12-21 12:39:33 +00:00
//if (process.env.BOARD=='BANGLEJS'||process.env.BOARD=='EMSCRIPTEN') var v_bfont_size=2;
var v_bfont_size=2;
if (g.theme.dark==true) var v_color=0xFFFF; //white
else var v_color=0x0000; //black
if (v_count == null || v_count == '') v_count=0;
2022-12-15 22:59:52 +00:00
function draw(){
2022-12-21 12:39:33 +00:00
// if (Bangle.CLOCK) return; //to remove from a clock
2022-12-21 12:39:33 +00:00
if (v_count==0) {
v_str_hw=process.env.VERSION.substr(0,6);
v_count++;
} else if (v_count==1) {
2022-12-15 22:59:52 +00:00
v_str_hw=process.env.BOARD.substr(0,3)+".."+process.env.BOARD.substr(process.env.BOARD.length-3,3);
2022-12-21 12:39:33 +00:00
v_count++;
2022-12-15 22:59:52 +00:00
}
2022-12-21 12:39:33 +00:00
else if (v_count==2) {
2022-12-15 22:59:52 +00:00
v_str_hw="Bat "+E.getBattery()+"%";
2022-12-21 12:39:33 +00:00
v_count++;
}
else {
2022-12-15 22:59:52 +00:00
// text prefix has to be 4char
stor=require("Storage").getStats();
2022-12-21 12:39:33 +00:00
if (v_count==3) {
2022-12-15 22:59:52 +00:00
v_str_hw="Fre "+process.memory().free;
//+"/"+process.memory().total;
2022-12-21 12:39:33 +00:00
v_count++;
2022-12-15 22:59:52 +00:00
}
2022-12-21 12:39:33 +00:00
else if (v_count==4) {
2022-12-15 22:59:52 +00:00
v_str_hw="Sto "+stor.freeBytes;
2022-12-21 12:39:33 +00:00
v_count++;
} else if (v_count==5) {
2022-12-15 22:59:52 +00:00
v_str_hw="Tra "+stor.trashBytes;
2022-12-21 12:39:33 +00:00
v_count++;
} else if (v_count==6) {
2022-12-15 22:59:52 +00:00
v_str_hw="Fil "+stor.fileCount;
2022-12-21 12:39:33 +00:00
v_count=0;
}
2022-12-15 22:59:52 +00:00
// 4 char are prefix
if (v_str_hw.length>7) {
//replace 3 digits by k
//substring betw x and y
v_str_hw=v_str_hw.substr(0,v_str_hw.length-3)+"k";
}
2022-12-21 12:39:33 +00:00
} //end else storage
g.reset().setColor(v_color).setFont("6x8",v_bfont_size).setFontAlign(-1, 0);
2022-12-15 12:02:10 +00:00
//clean a longer previous string, care with br widgets
g.drawString(" ", this.x, this.y+11, true);
g.drawString(v_str_hw, this.x, this.y+11, true);
} //end draw
2022-12-21 12:39:33 +00:00
WIDGETS["wdhwbttm"]={area:"bl",width:100,draw:draw};
2022-12-15 12:02:10 +00:00
if (Bangle.isLCDOn) intervalRef = setInterval(()=>WIDGETS["wdhwbttm"].draw(), 10*1000);
})()