1
0
Fork 0

Setting to toggle visibility of widgets

Setting to set minimal heart rate
master
Marco Heiming 2022-01-05 12:16:14 +01:00
parent f81032ac5b
commit 71504a7414
2 changed files with 45 additions and 18 deletions

View File

@ -8,12 +8,13 @@ const powerIconGreen = heatshrink.decompress(atob("h0OwYQNkAEDpAEDiQEDkmSAgUJkmA
const powerIconRed = heatshrink.decompress(atob("h0OwYQNoAEDyAEDkgEDpIFDiVJBweSAgUJkmAAoYZDgQpEBwYAJA")); const powerIconRed = heatshrink.decompress(atob("h0OwYQNoAEDyAEDkgEDpIFDiVJBweSAgUJkmAAoYZDgQpEBwYAJA"));
let settings; let settings;
function loadSettings() { function loadSettings() {
settings = require("Storage").readJSON("circlesclock.json", 1) || { settings = require("Storage").readJSON("circlesclock.json", 1) || {
'minHR': 40,
'maxHR': 200, 'maxHR': 200,
'stepGoal': 10000, 'stepGoal': 10000,
'batteryWarn': 30 'batteryWarn': 30,
'showWidgets': false
}; };
// Load step goal from pedometer widget as fallback // Load step goal from pedometer widget as fallback
if (settings.stepGoal == undefined) { if (settings.stepGoal == undefined) {
@ -21,18 +22,21 @@ function loadSettings() {
settings.stepGoal = d != undefined && d.settings != undefined ? d.settings.goal : 10000; settings.stepGoal = d != undefined && d.settings != undefined ? d.settings.goal : 10000;
} }
} }
loadSettings();
const showWidgets = settings.showWidgets || false;
let hrtValue;
// layout values:
const colorFg = g.theme.dark ? '#fff' : '#000'; const colorFg = g.theme.dark ? '#fff' : '#000';
const colorBg = g.theme.dark ? '#000' : '#fff'; const colorBg = g.theme.dark ? '#000' : '#fff';
const colorGrey = '#808080'; const colorGrey = '#808080';
const colorRed = '#ff0000'; const colorRed = '#ff0000';
const colorGreen = '#00ff00'; const colorGreen = '#00ff00';
const widgetOffset = showWidgets ? 12 : 0;
let hrtValue; const h = g.getHeight() - widgetOffset;
const h = g.getHeight();
const w = g.getWidth(); const w = g.getWidth();
const hOffset = 30; const hOffset = 30 - widgetOffset;
const h1 = Math.round(1 * h / 5 - hOffset); const h1 = Math.round(1 * h / 5 - hOffset);
const h2 = Math.round(3 * h / 5 - hOffset); const h2 = Math.round(3 * h / 5 - hOffset);
const h3 = Math.round(8 * h / 8 - hOffset); const h3 = Math.round(8 * h / 8 - hOffset);
@ -102,7 +106,7 @@ function drawHeartRate() {
g.fillCircle(w2, h3, radiusOuter); g.fillCircle(w2, h3, radiusOuter);
if (hrtValue != undefined && hrtValue > 0) { if (hrtValue != undefined && hrtValue > 0) {
const minHR = 40; const minHR = settings.minHR || 40;
const percent = (hrtValue - minHR) / (settings.maxHR - minHR); const percent = (hrtValue - minHR) / (settings.maxHR - minHR);
drawGauge(w2, h3, percent, colorRed); drawGauge(w2, h3, percent, colorRed);
} }
@ -233,19 +237,24 @@ Bangle.on('charging', function(charging) {
}); });
g.clear(); g.clear();
Bangle.loadWidgets(); Bangle.loadWidgets();
/* if (!showWidgets) {
* we are not drawing the widgets as we are taking over the whole screen /*
* so we will blank out the draw() functions of each widget and change the * we are not drawing the widgets as we are taking over the whole screen
* area to the top bar doesn't get cleared. * so we will blank out the draw() functions of each widget and change the
*/ * area to the top bar doesn't get cleared.
if (typeof WIDGETS === "object") { */
for (let wd of WIDGETS) { if (WIDGETS && typeof WIDGETS === "object") {
wd.draw = () => {}; for (let wd of WIDGETS) {
wd.area = ""; wd.draw = () => {};
wd.area = "";
}
} }
} }
loadSettings();
setInterval(draw, 60000); setInterval(draw, 60000);
draw(); draw();
Bangle.setUI("clock"); Bangle.setUI("clock");

View File

@ -8,6 +8,16 @@
} }
E.showMenu({ E.showMenu({
'': { 'title': 'circlesclock' }, '': { 'title': 'circlesclock' },
'min heartrate': {
value: "minHR" in settings ? settings.minHR : 40,
min: 0,
max : 250,
step: 10,
format: x => {
return x;
},
onchange: x => save('minHR', x),
},
'max heartrate': { 'max heartrate': {
value: "maxHR" in settings ? settings.maxHR : 200, value: "maxHR" in settings ? settings.maxHR : 200,
min: 20, min: 20,
@ -38,6 +48,14 @@
}, },
onchange: x => save('batteryWarn', x), onchange: x => save('batteryWarn', x),
}, },
'show widgets': {
value: "showWidgets" in settings ? settings.showWidgets : false,
format: () => (settings.showWidgets ? 'Yes' : 'No'),
onchange: () => {
settings.showWidgets = !settings.showWidgets;
save('showWidgets', settings.showWidgets);
},
},
'< Back': back, '< Back': back,
}); });
}); });