From dbb558a5c87aa9755aac86b37b5240fee518798f Mon Sep 17 00:00:00 2001 From: Markus Date: Wed, 8 Apr 2020 22:28:24 +0200 Subject: [PATCH 1/6] Adds BatteryChart app and widget --- apps.json | 13 +++++++++++++ apps/batchart/ChangeLog | 1 + apps/batchart/app.js | 32 ++++++++++++++++++++++++++++++++ apps/batchart/app.png | Bin 0 -> 1620 bytes apps/batchart/widget.js | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 apps/batchart/ChangeLog create mode 100644 apps/batchart/app.js create mode 100644 apps/batchart/app.png create mode 100644 apps/batchart/widget.js 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 0000000000000000000000000000000000000000..582cb2e0853a5a2899a3afbd7eb19cde2ee7f6a0 GIT binary patch literal 1620 zcmV-a2CMmrP)1gXjloC|3_d8m;N2OpV(|i0q4YwBna<2! zK9thw%-*|urnNbV{Gax^?eD+#{x0kLJ~)lj_;W+1>qV*k8akT^^dvctZccUyj4}H~#M%Wwee_v` zHMv7o%BM8@dBrLshn{wGD9BDl?^eV5vSM3T96;NnHvtc6La=(qzq)xrX1d8bK-TN- zrd_f$_O`9nEmS+_S7HTXK<&u;LDIW|qlN&KJvM}tt6TVVqL-AvNv`B*{NzNpBfSQwQP5~Sf(Dp@Vq1+3Q`N9wBQN2`J_?M^u0FIMlt?p^8 z%U3%80kIwg!T{E9<8J18S&$k1`eO)@HP+=TZKo(z3_A3VFYJB=sn`2^Q$mRE>02(+W)np;)L1!GUvU2{O{<&F_nE6Qe#D~Xf|dD z+?d3-D1(IUiL`C2;PPv4CKw8H)v7h8^obJ&Z6D0CjVUe8Xq_NAymxUyPAMU^CCrIu z%1M71EC`5o2if_~7E&h??0jeQ1Y3N6p?}G72FmS*)xQD)%wBE=2tW6@(+MTi!fk9H1pWKew2(jTXVu4%vk26QvSQCbGmk`Z)Y! zBIhh)6vG2)h6mF8wC^|l$M(Eo9D?JiW}=_T2jUA>LC80foTera{^p)Wi`>}Gf;(|ZwEZQ zS^k|*9wyt=f4ZOo!xty7{%}HKD9tBZ50g$=%v&&vMa!#@Nsf>EkEEDA*ST6fiC+An zsNK1#>!x0obq@j$QqYU-ad3ZvbjqUU+%iw(0WahgmHV6yeLWqoYkSl4pzFQ(_Vp&I ztO{WI-48rGLwQb?#vgVvduyd9_6W)rFRoQJq3I(J?{Xmin45#=3l9BmL6Bp<*MZej zrsWN7oRPUr7IvrHoIHOjS=gPTCw>d)^LQK+B|=f2qbGjrWaOd5D<<9Dv>MTW0X3z> zyPy}9`<>1~?NCx@m8G$_@rRTy5zH12YM&P)=tU+L^fgY z^0Z&_6^qdVuwgN3wt_Ze(10?J@%{C2grBk42hsu74qEo^nd&v`X`IHN9lrxzS~GeF S(*#!l0000 { + 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 From fa23aaf3f0094617c4b04bd9e957e0dc112306b4 Mon Sep 17 00:00:00 2001 From: msdeibel Date: Thu, 9 Apr 2020 08:19:38 +0200 Subject: [PATCH 2/6] Widget stores data to file, icon added --- apps.json | 2 +- apps/batchart/ChangeLog | 3 ++- apps/batchart/app-icon.js | 1 + apps/batchart/app.png | Bin 1620 -> 1498 bytes apps/batchart/batchart.dat | 0 apps/batchart/widget.js | 52 +++++++++++++++++++++++++++++++------ 6 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 apps/batchart/app-icon.js create mode 100644 apps/batchart/batchart.dat 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 582cb2e0853a5a2899a3afbd7eb19cde2ee7f6a0..9a60d100432a8648784022c43dd397e72afb5ccc 100644 GIT binary patch literal 1498 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA3?vioaBc-sjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WMyDrW(e>JaRrI9F>&y)aPhP93bFBvatKRv$*A)y83?JG2&CS-=*Ko0#DIQ#y<@*e_hGNeN2AW)xO4f={VR9w-@O0i#)HQ|H;jVO5EzgU z&|F(M37Ah9N`m}?|Br0I5d5886&MMe1s;*b3=DjSL74G){)!Z!phSslL`iUdT1k0g zQ7S`0VrE{6US4X6f{C7io@r{UQ7SMHjXhl)Lp;3iPP!d*$UwwZdu@Z5c94FD#)YC4 zFaFoZ^IAvGHd(mvaQ7}br)Ame6L+|j`v3Fz5IK?G&fp{K9PJ+mj_`exiF%`H8us9B z_*HAu4NQD8D-Q1Gc2WB1$U8?tZ->zWHopSf=cgK^EDpYzrp=u7fTde7ob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O{-dgz6Ke5>FZGo<5&Mq0i(4E(oP@&iXk z=-U1(Bgrgt{}SSg8|!FVQpN1*ApW3%X$qBd0$g%sHPPlXP=%gv2Ryu4{(qfM9wyt= zf4ZOo!xty7{%}HKD9tBZ50g$=%v&&vMa!#@Nsf>EkEEDA*ST6fiC+AnsNK1#>!x0o zbq@j$QqYU-ad3ZvbjqUU+%iw(0WahgmHV6yeLWqoYkSl4pzFQ(_Vp&ItO{WI-48rG zLwQb?#vgVvduyd9_6W)rFMqC8HKFMv5ASjy{+OGC=L-(~Zb6V^zSn`(Q>Nt&ZJd$0 zO%`^i+?+grDp}Z_q9=X}=<|3S6D2}Xo}(vz>ty7i#49G<-Lx9fe*rb6#JivumHVB} zLG4gdXO*R~xABLfz>ADt4^0(GkQeZWqQ#Jh>AK{zSO1DgHe=9$GLP~7^>KusvDgRF0oD#$_U@VLHS1}d#-AO(16^7(dI!@4R{#J2 M07*qoM6N<$f_kSNbpQYW 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 From 98440c54c9dd4f9ba7b8326710692cfc94cc5e85 Mon Sep 17 00:00:00 2001 From: msdeibel Date: Thu, 9 Apr 2020 08:25:27 +0200 Subject: [PATCH 3/6] Use correct batchart icon --- apps.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps.json b/apps.json index 614befed2..beddd2878 100644 --- a/apps.json +++ b/apps.json @@ -1135,14 +1135,14 @@ { "id": "batchart", "name": "Battery Chart", "shortName":"BatChart", - "icon": "widget.png", + "icon": "app.png", "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": [ {"name":"batchart.wid.js","url":"widget.js"}, {"name":"batchart.app.js","url":"app.js"}, - {"name":"batchart.img.js","url":"app-icon.js"} + {"name":"batchart.img.js","url":"app-icon.js","evaluate":true} ] } ] From 248b0bbf96668d4e8c88d04c0adf8eaa585a9795 Mon Sep 17 00:00:00 2001 From: msdeibel Date: Thu, 9 Apr 2020 08:30:15 +0200 Subject: [PATCH 4/6] Removes WIDGETS declaration --- apps/batchart/widget.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/batchart/widget.js b/apps/batchart/widget.js index 4335a3719..48c54426b 100644 --- a/apps/batchart/widget.js +++ b/apps/batchart/widget.js @@ -1,5 +1,3 @@ -WIDGETS = {}; - (() => { var switchableConsumers = { none: 0, From 8d89334c4de6162de928d6ac304ec17f790663dd Mon Sep 17 00:00:00 2001 From: msdeibel Date: Thu, 9 Apr 2020 08:35:11 +0200 Subject: [PATCH 5/6] Small fixes --- apps/batchart/app.js | 2 ++ apps/batchart/widget.js | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/batchart/app.js b/apps/batchart/app.js index c82b15737..684f9a88d 100644 --- a/apps/batchart/app.js +++ b/apps/batchart/app.js @@ -27,6 +27,8 @@ Bangle.on('lcdPower', (on) => { }); g.clear(); +Bangle.loadWidgets(); +Bangle.drawWidgets(); // call your app function here renderBatteryChart(); diff --git a/apps/batchart/widget.js b/apps/batchart/widget.js index 48c54426b..b002da5d9 100644 --- a/apps/batchart/widget.js +++ b/apps/batchart/widget.js @@ -16,7 +16,6 @@ // draw your widget function draw() { - if (!settings.isRecording) return; g.reset(); g.drawString("BC", this.x, this.y); } From 9851328c69f3b8701fe25c8a2c4b3ca2a84aca86 Mon Sep 17 00:00:00 2001 From: msdeibel Date: Thu, 9 Apr 2020 16:10:10 +0200 Subject: [PATCH 6/6] Rotate log files once a week --- apps.json | 2 +- apps/batchart/ChangeLog | 3 ++- apps/batchart/app-icon.js | 2 +- apps/batchart/widget.js | 55 +++++++++++++++++++++++---------------- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/apps.json b/apps.json index beddd2878..0347dd0c1 100644 --- a/apps.json +++ b/apps.json @@ -1136,7 +1136,7 @@ "name": "Battery Chart", "shortName":"BatChart", "icon": "app.png", - "version":"0.02", + "version":"0.03", "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 d885f8fb0..1b77ff82f 100644 --- a/apps/batchart/ChangeLog +++ b/apps/batchart/ChangeLog @@ -1,2 +1,3 @@ 0.01: New app and widget -0.02: Widget stores data to file (1 dataset/min) +0.02: Widget stores data to file (1 dataset/10min) +0.03: Rotate log files once a week. diff --git a/apps/batchart/app-icon.js b/apps/batchart/app-icon.js index 0841ea920..b41629e01 100644 --- a/apps/batchart/app-icon.js +++ b/apps/batchart/app-icon.js @@ -1 +1 @@ -require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AS64AIF/4pZABYuuGDIv/F/4v/F9+Gw0rAQIASF7YxTF7cxwAvtrdVF9qQTF/4vMYCQvcYCQvcSCQvdqpgQF7oEBYJ4veAoNbF9uGmMrrgvsw2AGILFKF8IACrYxJF8gxDSowvmBwWAF9oPGF9NbmIvtCAovqMAgvqCIgvrrdVF9oSDF9iPuF7crACxf/F++wFqmG2AvXGCouZAH4A/AGY")) \ No newline at end of file +require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AS64AIF/4pZABYuuGDIv/F/4v/F9+Gw0rAQIASF7YxTF7cxwAvtrdVF9qQTF/4vMYCQvcYCQvcSCQvdqpgQF7oEBYJ4veAoNbF9uGmMrrgvsw2AGILFKF8IACrYxJF8gxDSowvmBwWAF9oPGF9NbmIvtCAovqMAgvqCIgvrrdVF9oSDF9iPuF7crACxf/F++wFqmG2AvXGCouZAH4A/AGY")) diff --git a/apps/batchart/widget.js b/apps/batchart/widget.js index b002da5d9..2e2f43cdf 100644 --- a/apps/batchart/widget.js +++ b/apps/batchart/widget.js @@ -6,7 +6,8 @@ bluetooth: 4, gps: 8, hrm: 16 - } + }; + var settings = {}; var batChartFile; // file for battery percentage recording const recordingInterval10Min = 60 * 10 * 1000; @@ -20,26 +21,6 @@ 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; - - // 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; @@ -54,10 +35,40 @@ // enabledConsumers = enabledConsumers | switchableConsumers.gps; // if (Bangle.isHrmOn()) // enabledConsumers = enabledConsumers | switchableConsumers.hrm; - + return enabledConsumers; } + function logBatteryData() { + const previousWriteLogName = "bcprvday"; + const previousWriteDay = require("Storage").read(previousWriteLogName); + const currentWriteDay = new Date().getDay(); + + const logFileName = "bclog" + currentWriteDay; + + // Change log target on day change + if (previousWriteDay != currentWriteDay) { + //Remove a log file containing data from a week ago + require("Storage").erase(logFileName); + require("Storage").write(previousWriteLogName, currentWriteDay); + } + + var bcLogFileA = require("Storage").open(logFileName, "a"); + if (bcLogFileA) { + console.log([getTime().toFixed(0), E.getBattery(), E.getTemperature(), getEnabledConsumersValue()].join(",")); + bcLogFileA.write([[getTime().toFixed(0), E.getBattery(), E.getTemperature(), getEnabledConsumersValue()].join(",")].join(",")+"\n"); + } + } + + // Called by the heart app to reload settings and decide what's + function reload() { + WIDGETS["batchart"].width = 24; + + recordingInterval = setInterval(logBatteryData, recordingInterval10Min); + + logBatteryData(); + } + // add the widget WIDGETS["batchart"]={area:"tl",width:24,draw:draw,reload:function() { reload();