2020-04-08 20:28:24 +00:00
|
|
|
|
(() => {
|
2020-04-14 11:55:36 +00:00
|
|
|
|
const Storage = require("Storage");
|
|
|
|
|
|
|
|
|
|
const switchableConsumers = {
|
2020-04-09 06:19:38 +00:00
|
|
|
|
none: 0,
|
|
|
|
|
lcd: 1,
|
|
|
|
|
compass: 2,
|
|
|
|
|
bluetooth: 4,
|
|
|
|
|
gps: 8,
|
|
|
|
|
hrm: 16
|
2020-04-09 14:10:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-04-08 20:28:24 +00:00
|
|
|
|
var batChartFile; // file for battery percentage recording
|
2020-04-09 06:19:38 +00:00
|
|
|
|
const recordingInterval10Min = 60 * 10 * 1000;
|
|
|
|
|
const recordingInterval1Min = 60*1000; //For testing
|
2020-04-08 20:28:24 +00:00
|
|
|
|
const recordingInterval10S = 10*1000; //For testing
|
|
|
|
|
var recordingInterval = null;
|
|
|
|
|
|
2020-04-14 05:48:07 +00:00
|
|
|
|
var compassEventReceived = false;
|
|
|
|
|
var gpsEventReceived = false;
|
|
|
|
|
var hrmEventReceived = false;
|
|
|
|
|
|
2020-04-08 20:28:24 +00:00
|
|
|
|
// draw your widget
|
|
|
|
|
function draw() {
|
|
|
|
|
g.reset();
|
|
|
|
|
g.drawString("BC", this.x, this.y);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 06:19:38 +00:00
|
|
|
|
function getEnabledConsumersValue() {
|
|
|
|
|
var enabledConsumers = switchableConsumers.none;
|
|
|
|
|
|
2020-04-14 05:48:07 +00:00
|
|
|
|
Bangle.on('mag', (() => {
|
|
|
|
|
console.log("mag received");
|
|
|
|
|
compassEventReceived = true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
Bangle.on('GPS', (() => {
|
|
|
|
|
console.log("GPS received");
|
|
|
|
|
gpsEventReceived = true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
Bangle.on('HRM', (() => {
|
|
|
|
|
console.log("HRM received");
|
|
|
|
|
hrmEventReceived = true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Wait two seconds, that should be enough for each of the events to get raised once
|
|
|
|
|
setTimeout(() => {
|
2020-04-14 12:02:03 +00:00
|
|
|
|
Bangle.removeAllListeners;
|
2020-04-14 05:48:07 +00:00
|
|
|
|
}, 2000);
|
|
|
|
|
|
2020-04-09 06:19:38 +00:00
|
|
|
|
if (Bangle.isLCDOn())
|
|
|
|
|
enabledConsumers = enabledConsumers | switchableConsumers.lcd;
|
|
|
|
|
// Already added in the hope they will be available soon to get more details
|
2020-04-14 05:48:07 +00:00
|
|
|
|
if (compassEventReceived)
|
|
|
|
|
enabledConsumers = enabledConsumers | switchableConsumers.compass;
|
|
|
|
|
if (gpsEventReceived)
|
|
|
|
|
enabledConsumers = enabledConsumers | switchableConsumers.gps;
|
|
|
|
|
if (hrmEventReceived)
|
|
|
|
|
enabledConsumers = enabledConsumers | switchableConsumers.hrm;
|
|
|
|
|
//if (Bangle.isBluetoothOn())
|
2020-04-09 06:19:38 +00:00
|
|
|
|
// enabledConsumers = enabledConsumers | switchableConsumers.bluetooth;
|
2020-04-14 05:48:07 +00:00
|
|
|
|
|
|
|
|
|
// Reset the event registration vars
|
|
|
|
|
compassEventReceived = false;
|
|
|
|
|
gpsEventReceived = false;
|
|
|
|
|
hrmEventReceived = false;
|
|
|
|
|
|
|
|
|
|
console.log("Enabled: " + enabledConsumers);
|
2020-04-09 14:10:10 +00:00
|
|
|
|
|
2020-04-09 06:19:38 +00:00
|
|
|
|
return enabledConsumers;
|
2020-04-08 20:28:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 14:10:10 +00:00
|
|
|
|
function logBatteryData() {
|
|
|
|
|
const previousWriteLogName = "bcprvday";
|
2020-04-14 05:48:07 +00:00
|
|
|
|
const previousWriteDay = Storage.read(previousWriteLogName);
|
2020-04-09 14:10:10 +00:00
|
|
|
|
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
|
2020-04-14 11:55:36 +00:00
|
|
|
|
Storage.open(logFileName, "r").erase();
|
2020-04-14 05:48:07 +00:00
|
|
|
|
Storage.write(previousWriteLogName, currentWriteDay);
|
2020-04-09 14:10:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-14 05:48:07 +00:00
|
|
|
|
var bcLogFileA = Storage.open(logFileName, "a");
|
2020-04-09 14:10:10 +00:00
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reload() {
|
|
|
|
|
WIDGETS["batchart"].width = 24;
|
|
|
|
|
|
2020-04-14 05:48:07 +00:00
|
|
|
|
recordingInterval = setInterval(logBatteryData, recordingInterval10S);
|
2020-04-09 14:10:10 +00:00
|
|
|
|
|
|
|
|
|
logBatteryData();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 20:28:24 +00:00
|
|
|
|
// 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();
|
|
|
|
|
})()
|