diff --git a/apps.json b/apps.json index 5ec359c16..614befed2 100644 --- a/apps.json +++ b/apps.json @@ -1136,7 +1136,7 @@ "name": "Battery Chart", "shortName":"BatChart", "icon": "widget.png", - "version":"0.01", + "version":"0.02", "description": "A widget and an app for recording and visualizing battery percentage over time.", "tags": "app,widget,battery,time,record,chart,tool", "storage": [ diff --git a/apps/batchart/ChangeLog b/apps/batchart/ChangeLog index 5560f00bc..d885f8fb0 100644 --- a/apps/batchart/ChangeLog +++ b/apps/batchart/ChangeLog @@ -1 +1,2 @@ -0.01: New App! +0.01: New app and widget +0.02: Widget stores data to file (1 dataset/min) diff --git a/apps/batchart/app-icon.js b/apps/batchart/app-icon.js new file mode 100644 index 000000000..0841ea920 --- /dev/null +++ b/apps/batchart/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AS64AIF/4pZABYuuGDIv/F/4v/F9+Gw0rAQIASF7YxTF7cxwAvtrdVF9qQTF/4vMYCQvcYCQvcSCQvdqpgQF7oEBYJ4veAoNbF9uGmMrrgvsw2AGILFKF8IACrYxJF8gxDSowvmBwWAF9oPGF9NbmIvtCAovqMAgvqCIgvrrdVF9oSDF9iPuF7crACxf/F++wFqmG2AvXGCouZAH4A/AGY")) \ No newline at end of file diff --git a/apps/batchart/app.png b/apps/batchart/app.png index 582cb2e08..9a60d1004 100644 Binary files a/apps/batchart/app.png and b/apps/batchart/app.png differ diff --git a/apps/batchart/batchart.dat b/apps/batchart/batchart.dat new file mode 100644 index 000000000..e69de29bb diff --git a/apps/batchart/widget.js b/apps/batchart/widget.js index 85cff4cf4..4335a3719 100644 --- a/apps/batchart/widget.js +++ b/apps/batchart/widget.js @@ -1,9 +1,18 @@ WIDGETS = {}; (() => { + var switchableConsumers = { + none: 0, + lcd: 1, + compass: 2, + bluetooth: 4, + gps: 8, + hrm: 16 + } var settings = {}; var batChartFile; // file for battery percentage recording - const recordingInterval10Min = 60*10*1000; + const recordingInterval10Min = 60 * 10 * 1000; + const recordingInterval1Min = 60*1000; //For testing const recordingInterval10S = 10*1000; //For testing var recordingInterval = null; @@ -16,13 +25,40 @@ WIDGETS = {}; // 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) + WIDGETS["batchart"].width = 24; + + // Check if the data file exists, if not try to create it. + var batChartFileCheck = require("Storage").open("batchart.dat", "r"); + if (!batChartFileCheck) + if (!require("Storage").write("batchart.dat", "")) + //Only continue if the file was created + return; + + recordingInterval = setInterval(() => { + var batChartFileAppend = require("Storage").open("batchart.dat", "a"); + if (batChartFileAppend) { + console.log([getTime().toFixed(0), E.getBattery(), E.getTemperature(), getEnabledConsumersValue()].join(",")); + batChartFileAppend.write([getTime().toFixed(0),E.getBattery].join(",")+"\n"); + } + }, recordingInterval1Min) + } + + function getEnabledConsumersValue() { + var enabledConsumers = switchableConsumers.none; + + if (Bangle.isLCDOn()) + enabledConsumers = enabledConsumers | switchableConsumers.lcd; + // Already added in the hope they will be available soon to get more details + // if (Bangle.isCompassOn()) + // enabledConsumers = enabledConsumers | switchableConsumers.compass; + // if (Bangle.isBluetoothOn()) + // enabledConsumers = enabledConsumers | switchableConsumers.bluetooth; + // if (Bangle.isGpsOn()) + // enabledConsumers = enabledConsumers | switchableConsumers.gps; + // if (Bangle.isHrmOn()) + // enabledConsumers = enabledConsumers | switchableConsumers.hrm; + + return enabledConsumers; } // add the widget