mirror of https://github.com/espruino/BangleApps
fix minor error with #269 sanity check
commit
0dbc5e70bb
15
apps.json
15
apps.json
|
@ -1145,5 +1145,18 @@
|
|||
{"name":"devstopwatch.app.js","url":"app.js"},
|
||||
{"name":"devstopwatch.img","url":"app-icon.js","evaluate":true}
|
||||
]
|
||||
}
|
||||
},
|
||||
{ "id": "batchart",
|
||||
"name": "Battery Chart",
|
||||
"shortName":"BatChart",
|
||||
"icon": "app.png",
|
||||
"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": [
|
||||
{"name":"batchart.wid.js","url":"widget.js"},
|
||||
{"name":"batchart.app.js","url":"app.js"},
|
||||
{"name":"batchart.img","url":"app-icon.js","evaluate":true}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
0.01: New app and widget
|
||||
0.02: Widget stores data to file (1 dataset/10min)
|
||||
0.03: Rotate log files once a week.
|
|
@ -0,0 +1 @@
|
|||
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AS64AIF/4pZABYuuGDIv/F/4v/F9+Gw0rAQIASF7YxTF7cxwAvtrdVF9qQTF/4vMYCQvcYCQvcSCQvdqpgQF7oEBYJ4veAoNbF9uGmMrrgvsw2AGILFKF8IACrYxJF8gxDSowvmBwWAF9oPGF9NbmIvtCAovqMAgvqCIgvrrdVF9oSDF9iPuF7crACxf/F++wFqmG2AvXGCouZAH4A/AGY"))
|
|
@ -0,0 +1,34 @@
|
|||
// 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();
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
// call your app function here
|
||||
|
||||
renderBatteryChart();
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -0,0 +1,79 @@
|
|||
(() => {
|
||||
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 recordingInterval1Min = 60*1000; //For testing
|
||||
const recordingInterval10S = 10*1000; //For testing
|
||||
var recordingInterval = null;
|
||||
|
||||
// draw your widget
|
||||
function draw() {
|
||||
g.reset();
|
||||
g.drawString("BC", this.x, this.y);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
Bangle.drawWidgets(); // relayout all widgets
|
||||
}};
|
||||
// load settings, set correct widget width
|
||||
reload();
|
||||
})()
|
Loading…
Reference in New Issue