1
0
Fork 0

Experimental changes for hrm, gps an compass

master
msdeibel 2020-04-14 07:48:07 +02:00
parent 9fad35f39e
commit c64d7bf57e
2 changed files with 73 additions and 37 deletions

View File

@ -7,12 +7,12 @@ const MaxValueCount = 144;
const GraphXMax = GraphXZero + MaxValueCount;
const GraphLcdY = GraphYZero + 10;
// const GraphCompassY = GraphYZero + 16;
const GraphCompassY = GraphYZero + 16;
// const GraphBluetoothY = GraphYZero + 22;
// const GraphGpsY = GraphYZero + 28;
// const GraphHrmY = GraphYZero + 34;
const GraphGpsY = GraphYZero + 28;
const GraphHrmY = GraphYZero + 34;
var Storage = require("Storage");
const Storage = require("Storage");
function renderCoordinateSystem() {
g.setFont("6x8", 1);
@ -149,13 +149,13 @@ function renderData(dataArray) {
g.drawLine(GraphXZero + i, GraphLcdY, GraphXZero + i, GraphLcdY + 1);
}
// // Compass state
// if (switchables & switchableConsumers.lcd == switchableConsumers.lcd) {
// g.setColor(0, 1, 0);
// g.setFontAlign(-1, -1, 0);
// g.drawString("Compass", GraphXMax + GraphMarkerOffset, GraphCompassY - 2, true);
// g.drawLine(GraphXZero + i, GraphCompassY, GraphXZero + i, GraphCompassY + 1);
// }
// Compass state
if (switchables & switchableConsumers.lcd == switchableConsumers.lcd) {
g.setColor(0, 1, 0);
g.setFontAlign(-1, -1, 0);
g.drawString("Compass", GraphXMax + GraphMarkerOffset, GraphCompassY - 2, true);
g.drawLine(GraphXZero + i, GraphCompassY, GraphXZero + i, GraphCompassY + 1);
}
// // Bluetooth state
// if (switchables & switchableConsumers.lcd == switchableConsumers.lcd) {
@ -165,21 +165,21 @@ function renderData(dataArray) {
// g.drawLine(GraphXZero + i, GraphBluetoothY, GraphXZero + i, GraphBluetoothY + 1);
// }
// // Gps state
// if (switchables & switchableConsumers.lcd == switchableConsumers.lcd) {
// g.setColor(0.8, 0.5, 0.24);
// g.setFontAlign(-1, -1, 0);
// g.drawString("GPS", GraphXMax + GraphMarkerOffset, GraphGpsY - 2, true);
// g.drawLine(GraphXZero + i, GraphGpsY, GraphXZero + i, GraphGpsY + 1);
// }
// Gps state
if (switchables & switchableConsumers.lcd == switchableConsumers.lcd) {
g.setColor(0.8, 0.5, 0.24);
g.setFontAlign(-1, -1, 0);
g.drawString("GPS", GraphXMax + GraphMarkerOffset, GraphGpsY - 2, true);
g.drawLine(GraphXZero + i, GraphGpsY, GraphXZero + i, GraphGpsY + 1);
}
// // Hrm state
// if (switchables & switchableConsumers.lcd == switchableConsumers.lcd) {
// g.setColor(1, 0, 0);
// g.setFontAlign(1, -1, 0);
// g.drawString("HRM", GraphXZero - GraphMarkerOffset, GraphHrmY - 2, true);
// g.drawLine(GraphXZero + i, GraphHrmY, GraphXZero + i, GraphHrmY + 1);
// }
// Hrm state
if (switchables & switchableConsumers.lcd == switchableConsumers.lcd) {
g.setColor(1, 0, 0);
g.setFontAlign(1, -1, 0);
g.drawString("HRM", GraphXZero - GraphMarkerOffset, GraphHrmY - 2, true);
g.drawLine(GraphXZero + i, GraphHrmY, GraphXZero + i, GraphHrmY + 1);
}
}
dataArray = null;

View File

@ -15,6 +15,12 @@
const recordingInterval10S = 10*1000; //For testing
var recordingInterval = null;
var compassEventReceived = false;
var gpsEventReceived = false;
var hrmEventReceived = false;
const Storage = require("Storage");
// draw your widget
function draw() {
g.reset();
@ -24,24 +30,54 @@
function getEnabledConsumersValue() {
var enabledConsumers = switchableConsumers.none;
Bangle.on('mag', (() => {
console.log("mag received");
compassEventReceived = true;
Bangle.on("mag", () => {});
}));
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(() => {
Bangle.on('mag', () => {});
Bangle.on('GPS', () => {});
Bangle.on('HRM', () => {});
}, 2000);
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())
if (compassEventReceived)
enabledConsumers = enabledConsumers | switchableConsumers.compass;
if (gpsEventReceived)
enabledConsumers = enabledConsumers | switchableConsumers.gps;
if (hrmEventReceived)
enabledConsumers = enabledConsumers | switchableConsumers.hrm;
//if (Bangle.isBluetoothOn())
// enabledConsumers = enabledConsumers | switchableConsumers.bluetooth;
// if (Bangle.isGpsOn())
// enabledConsumers = enabledConsumers | switchableConsumers.gps;
// if (Bangle.isHrmOn())
// enabledConsumers = enabledConsumers | switchableConsumers.hrm;
// Reset the event registration vars
compassEventReceived = false;
gpsEventReceived = false;
hrmEventReceived = false;
console.log("Enabled: " + enabledConsumers);
return enabledConsumers;
}
function logBatteryData() {
const previousWriteLogName = "bcprvday";
const previousWriteDay = require("Storage").read(previousWriteLogName);
const previousWriteDay = Storage.read(previousWriteLogName);
const currentWriteDay = new Date().getDay();
const logFileName = "bclog" + currentWriteDay;
@ -49,11 +85,11 @@
// 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);
Storage.erase(logFileName);
Storage.write(previousWriteLogName, currentWriteDay);
}
var bcLogFileA = require("Storage").open(logFileName, "a");
var bcLogFileA = 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");
@ -63,7 +99,7 @@
function reload() {
WIDGETS["batchart"].width = 24;
recordingInterval = setInterval(logBatteryData, recordingInterval10Min);
recordingInterval = setInterval(logBatteryData, recordingInterval10S);
logBatteryData();
}