diff --git a/apps.json b/apps.json index 6b9198f33..5ec359c16 100644 --- a/apps.json +++ b/apps.json @@ -1131,5 +1131,18 @@ "storage": [ {"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"} + ] } ] diff --git a/apps/batchart/ChangeLog b/apps/batchart/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/batchart/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/batchart/app.js b/apps/batchart/app.js new file mode 100644 index 000000000..c82b15737 --- /dev/null +++ b/apps/batchart/app.js @@ -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(); diff --git a/apps/batchart/app.png b/apps/batchart/app.png new file mode 100644 index 000000000..582cb2e08 Binary files /dev/null and b/apps/batchart/app.png differ diff --git a/apps/batchart/widget.js b/apps/batchart/widget.js new file mode 100644 index 000000000..85cff4cf4 --- /dev/null +++ b/apps/batchart/widget.js @@ -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(); +})() \ No newline at end of file