Adds BatteryChart app and widget

master
Markus 2020-04-08 22:28:24 +02:00
parent 204ccd81ad
commit dbb558a5c8
5 changed files with 81 additions and 0 deletions

View File

@ -1131,5 +1131,18 @@
"storage": [ "storage": [
{"name":"custom"} {"name":"custom"}
] ]
},
{ "id": "batchart",
"name": "Battery Chart",
"shortName":"BatChart",
"icon": "widget.png",
"version":"0.01",
"description": "A widget and an app for recording and visualizing battery percentage over time.",
"tags": "app,widget,battery,time,record,chart,tool",
"storage": [
{"name":"batchart.wid.js","url":"widget.js"},
{"name":"batchart.app.js","url":"app.js"},
{"name":"batchart.img.js","url":"app-icon.js"}
]
} }
] ]

1
apps/batchart/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New App!

32
apps/batchart/app.js Normal file
View File

@ -0,0 +1,32 @@
// place your const, vars, functions or classes here
function renderBatteryChart(){
g.drawString("t", 215, 175);
g.drawLine(40,190,40,80);
g.drawString("%", 39, 70);
g.drawString("100", 15, 75);
g.drawLine(35,80,40,80);
g.drawString("50", 20,125);
g.drawLine(35,130,40,130);
g.drawString("0", 25, 175);
g.drawLine(35,180,210,180);
g.drawString("Chart not yet functional", 60, 125);
}
// special function to handle display switch on
Bangle.on('lcdPower', (on) => {
if (on) {
// call your app function here
// If you clear the screen, do Bangle.drawWidgets();
renderBatteryChart();
}
});
g.clear();
// call your app function here
renderBatteryChart();

BIN
apps/batchart/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

35
apps/batchart/widget.js Normal file
View File

@ -0,0 +1,35 @@
WIDGETS = {};
(() => {
var settings = {};
var batChartFile; // file for battery percentage recording
const recordingInterval10Min = 60*10*1000;
const recordingInterval10S = 10*1000; //For testing
var recordingInterval = null;
// draw your widget
function draw() {
if (!settings.isRecording) return;
g.reset();
g.drawString("BC", this.x, this.y);
}
// Called by the heart app to reload settings and decide what's
function reload() {
WIDGETS["batchart"].width = 24;
batChartFile = require("Storage").open(".batchart","a");
recordingInterval = setInterval(()=>{
if (batChartFile)
console.log ([getTime().toFixed(0),E.getBattery()].join(","));
//batChartfile.write([getTime().toFixed(0),E.getBattery].join(",")+"\n");
}, recordingInterval10S)
}
// add the widget
WIDGETS["batchart"]={area:"tl",width:24,draw:draw,reload:function() {
reload();
Bangle.drawWidgets(); // relayout all widgets
}};
// load settings, set correct widget width
reload();
})()