Improve logging and charting of component states and add widget icon

master
Markus 2020-04-14 22:15:15 +02:00
parent 935241d7c5
commit a798bb9dc6
3 changed files with 22 additions and 11 deletions

View File

@ -1164,7 +1164,7 @@
"name": "Battery Chart", "name": "Battery Chart",
"shortName":"Battery Chart", "shortName":"Battery Chart",
"icon": "app.png", "icon": "app.png",
"version":"0.06", "version":"0.07",
"description": "A widget and an app for recording and visualizing battery percentage over time.", "description": "A widget and an app for recording and visualizing battery percentage over time.",
"tags": "app,widget,battery,time,record,chart,tool", "tags": "app,widget,battery,time,record,chart,tool",
"storage": [ "storage": [

View File

@ -4,3 +4,4 @@
0.04: chart in the app is now active. 0.04: chart in the app is now active.
0.05: Display temperature and LCD state in chart 0.05: Display temperature and LCD state in chart
0.06: Fixes widget events and charting of component states 0.06: Fixes widget events and charting of component states
0.07: Improve logging and charting of component states and add widget icon

View File

@ -1,5 +1,3 @@
WIDGETS = {};
(() => { (() => {
const Storage = require("Storage"); const Storage = require("Storage");
@ -24,8 +22,16 @@ WIDGETS = {};
// draw your widget // draw your widget
function draw() { function draw() {
let x = this.x;
let y = this.y;
g.setColor(0, 1, 0);
g.fillPoly([x+5, y, x+5, y+4, x+1, y+4, x+1, y+20, x+18, y+20, x+18, y+4, x+13, y+4, x+13, y], true);
g.setColor(0,0,0);
g.drawPoly([x+5, y+6, x+8, y+12, x+13, y+12, x+16, y+18], false);
g.reset(); g.reset();
g.drawString("BC", this.x, this.y);
} }
function onMag(){ function onMag(){
@ -53,7 +59,7 @@ WIDGETS = {};
// Wait two seconds, that should be enough for each of the events to get raised once // Wait two seconds, that should be enough for each of the events to get raised once
setTimeout(() => { setTimeout(() => {
Bangle.removeAllListeners; Bangle.removeAllListeners();
}, 2000); }, 2000);
if (Bangle.isLCDOn()) if (Bangle.isLCDOn())
@ -73,7 +79,7 @@ WIDGETS = {};
gpsEventReceived = false; gpsEventReceived = false;
hrmEventReceived = false; hrmEventReceived = false;
return enabledConsumers; return enabledConsumers.toString();
} }
function logBatteryData() { function logBatteryData() {
@ -84,7 +90,7 @@ WIDGETS = {};
const logFileName = "bclog" + currentWriteDay; const logFileName = "bclog" + currentWriteDay;
// Change log target on day change // Change log target on day change
if (previousWriteDay != NaN if (!isNaN(previousWriteDay)
&& previousWriteDay != currentWriteDay) { && previousWriteDay != currentWriteDay) {
//Remove a log file containing data from a week ago //Remove a log file containing data from a week ago
Storage.open(logFileName, "r").erase(); Storage.open(logFileName, "r").erase();
@ -93,9 +99,13 @@ WIDGETS = {};
var bcLogFileA = Storage.open(logFileName, "a"); var bcLogFileA = Storage.open(logFileName, "a");
if (bcLogFileA) { if (bcLogFileA) {
let logString = [getTime().toFixed(0), E.getBattery(), E.getTemperature(), getEnabledConsumersValue()].join(","); let logTime = getTime().toFixed(0);
let logPercent = E.getBattery();
let logTemperature = E.getTemperature();
let logConsumers = getEnabledConsumersValue();
let logString = [logTime, logPercent, logTemperature, logConsumers].join(",");
console.log(logString);
bcLogFileA.write(logString + "\n"); bcLogFileA.write(logString + "\n");
} }
} }
@ -103,7 +113,7 @@ WIDGETS = {};
function reload() { function reload() {
WIDGETS["batchart"].width = 24; WIDGETS["batchart"].width = 24;
recordingInterval = setInterval(logBatteryData, recordingInterval10S); recordingInterval = setInterval(logBatteryData, recordingInterval10Min);
logBatteryData(); logBatteryData();
} }