1
0
Fork 0

BatteryChart 0.10

master
msdeibel 2020-05-11 20:48:50 +02:00
parent 3c92b64bde
commit 4dd102a906
3 changed files with 26 additions and 27 deletions

View File

@ -1272,7 +1272,7 @@
"name": "Battery Chart", "name": "Battery Chart",
"shortName":"Battery Chart", "shortName":"Battery Chart",
"icon": "app.png", "icon": "app.png",
"version":"0.09", "version":"0.10",
"readme": "README.md", "readme": "README.md",
"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",

View File

@ -6,4 +6,5 @@
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 0.07: Improve logging and charting of component states and add widget icon
0.08: Fix for Home button in the app and README added. 0.08: Fix for Home button in the app and README added.
0.09: Fix failing dismissal of Gadgetbridge notifications, record (coarse) bluetooth state 0.09: Fix failing dismissal of Gadgetbridge notifications, record (coarse) bluetooth state
0.10: Remove widget icon and improve listener and setInterval handling for widget (might help with https://github.com/espruino/BangleApps/issues/381)

View File

@ -1,6 +1,7 @@
(() => { (() => {
let recordingInterval = null;
const Storage = require("Storage"); const Storage = require("Storage");
const switchableConsumers = { const switchableConsumers = {
none: 0, none: 0,
lcd: 1, lcd: 1,
@ -14,53 +15,44 @@
const recordingInterval10Min = 60 * 10 * 1000; const recordingInterval10Min = 60 * 10 * 1000;
const recordingInterval1Min = 60 * 1000; //For testing const recordingInterval1Min = 60 * 1000; //For testing
const recordingInterval10S = 10 * 1000; //For testing const recordingInterval10S = 10 * 1000; //For testing
var recordingInterval = null;
var compassEventReceived = false; var compassEventReceived = false;
var gpsEventReceived = false; var gpsEventReceived = false;
var hrmEventReceived = false; var hrmEventReceived = false;
// draw your widget
function draw() { function draw() {
let x = this.x; // void
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();
} }
function onMag() { function batteryChartOnMag() {
compassEventReceived = true; compassEventReceived = true;
// Stop handling events when no longer necessarry // Stop handling events when no longer necessarry
Bangle.removeListener("mag", onMag); Bangle.removeListener("mag", batteryChartOnMag);
} }
function onGps() { function batterChartOnGps() {
gpsEventReceived = true; gpsEventReceived = true;
Bangle.removeListener("GPS", onGps); Bangle.removeListener("GPS", batterChartOnGps);
} }
function onHrm() { function batteryChartOnHrm() {
hrmEventReceived = true; hrmEventReceived = true;
Bangle.removeListener("HRM", onHrm); Bangle.removeListener("HRM", batteryChartOnHrm);
} }
function getEnabledConsumersValue() { function getEnabledConsumersValue() {
// Wait for an event from each of the devices to see if they are switched on // Wait for an event from each of the devices to see if they are switched on
var enabledConsumers = switchableConsumers.none; var enabledConsumers = switchableConsumers.none;
Bangle.on('mag', onMag); Bangle.on('mag', batteryChartOnMag);
Bangle.on('GPS', onGps); Bangle.on('GPS', batterChartOnGps);
Bangle.on('HRM', onHrm); Bangle.on('HRM', batteryChartOnHrm);
// 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.removeListener('mag', batteryChartOnMag);
Bangle.removeListener('GPS', batterChartOnGps);
Bangle.removeListener('HRM', batteryChartOnHrm);
}, 2000); }, 2000);
if (Bangle.isLCDOn()) if (Bangle.isLCDOn())
@ -112,14 +104,20 @@
} }
function reload() { function reload() {
WIDGETS["batchart"].width = 24; console.log("Reloading BatteryChart widget");
WIDGETS["batchart"].width = 0;
if (recordingInterval) {
clearInterval(recordingInterval);
recordingInterval = null;
}
recordingInterval = setInterval(logBatteryData, recordingInterval10Min); recordingInterval = setInterval(logBatteryData, recordingInterval10Min);
} }
// add the widget // add the widget
WIDGETS["batchart"] = { WIDGETS["batchart"] = {
area: "tl", width: 24, draw: draw, reload: reload area: "tl", width: 0, draw: draw, reload: reload
}; };
reload(); reload();