Move default settings to external file
parent
6872c38a8d
commit
6daccc3813
|
|
@ -20,25 +20,14 @@ const weatherStormy = atob("EBCBAAAAAYAH4AwwOBBgGEAOQMJAgjmOGcgAgACAAAAAAAAA");
|
||||||
const sunSetDown = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAAGYAPAAYAAAAAA");
|
const sunSetDown = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAAGYAPAAYAAAAAA");
|
||||||
const sunSetUp = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAABgAPABmAAAAAA");
|
const sunSetUp = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAABgAPABmAAAAAA");
|
||||||
|
|
||||||
let settings = storage.readJSON("circlesclock.json", 1) || {
|
const SETTINGS_FILE = "circlesclock.json";
|
||||||
'minHR': 40,
|
let settings = Object.assign(
|
||||||
'maxHR': 200,
|
storage.readJSON("circlesclock.default.json", true) || {},
|
||||||
'confidence': 0,
|
storage.readJSON(SETTINGS_FILE, true) || {}
|
||||||
'stepGoal': 10000,
|
);
|
||||||
'stepDistanceGoal': 8000,
|
|
||||||
'stepLength': 0.8,
|
|
||||||
'batteryWarn': 30,
|
|
||||||
'showWidgets': false,
|
|
||||||
'weatherCircleData': 'humidity',
|
|
||||||
'circleCount': 3,
|
|
||||||
'circle1': 'hr',
|
|
||||||
'circle2': 'steps',
|
|
||||||
'circle3': 'battery',
|
|
||||||
'circle4': 'weather'
|
|
||||||
};
|
|
||||||
// Load step goal from pedometer widget as fallback
|
// Load step goal from pedometer widget as fallback
|
||||||
if (settings.stepGoal == undefined) {
|
if (settings.stepGoal == undefined) {
|
||||||
const d = storage.readJSON("wpedom.json", 1) || {};
|
const d = storage.readJSON("wpedom.json", true) || {};
|
||||||
settings.stepGoal = d != undefined && d.settings != undefined ? d.settings.goal : 10000;
|
settings.stepGoal = d != undefined && d.settings != undefined ? d.settings.goal : 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +58,7 @@ const widgetOffset = showWidgets ? 24 : 0;
|
||||||
const dowOffset = circleCount == 3 ? 22 : 24; // dow offset relative to date
|
const dowOffset = circleCount == 3 ? 22 : 24; // dow offset relative to date
|
||||||
const h = g.getHeight() - widgetOffset;
|
const h = g.getHeight() - widgetOffset;
|
||||||
const w = g.getWidth();
|
const w = g.getWidth();
|
||||||
const hOffset = 30 - widgetOffset;
|
const hOffset = (circleCount == 3 ? 34 : 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 - 3); // circle y position
|
const h3 = Math.round(8 * h / 8 - hOffset - 3); // circle y position
|
||||||
|
|
@ -279,10 +268,10 @@ function drawSteps(w) {
|
||||||
|
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
const color = getCircleColor("steps") || colorBlue;
|
const color = getCircleColor("steps");
|
||||||
|
|
||||||
let percent;
|
let percent;
|
||||||
const stepGoal = settings.stepGoal || 10000;
|
const stepGoal = settings.stepGoal;
|
||||||
if (stepGoal > 0) {
|
if (stepGoal > 0) {
|
||||||
percent = steps / stepGoal;
|
percent = steps / stepGoal;
|
||||||
if (stepGoal < steps) percent = 1;
|
if (stepGoal < steps) percent = 1;
|
||||||
|
|
@ -299,15 +288,15 @@ function drawSteps(w) {
|
||||||
function drawStepsDistance(w) {
|
function drawStepsDistance(w) {
|
||||||
if (!w) w = getCircleXPosition("stepsDistance");
|
if (!w) w = getCircleXPosition("stepsDistance");
|
||||||
const steps = getSteps();
|
const steps = getSteps();
|
||||||
const stepDistance = settings.stepLength || 0.8;
|
const stepDistance = settings.stepLength;
|
||||||
const stepsDistance = Math.round(steps * stepDistance);
|
const stepsDistance = Math.round(steps * stepDistance);
|
||||||
|
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
const color = getCircleColor("stepsDistance") || colorGreen;
|
const color = getCircleColor("stepsDistance");
|
||||||
|
|
||||||
let percent;
|
let percent;
|
||||||
const stepDistanceGoal = settings.stepDistanceGoal || 8000;
|
const stepDistanceGoal = settings.stepDistanceGoal;
|
||||||
if (stepDistanceGoal > 0) {
|
if (stepDistanceGoal > 0) {
|
||||||
percent = stepsDistance / stepDistanceGoal;
|
percent = stepsDistance / stepDistanceGoal;
|
||||||
if (stepDistanceGoal < stepsDistance) percent = 1;
|
if (stepDistanceGoal < stepsDistance) percent = 1;
|
||||||
|
|
@ -326,12 +315,12 @@ function drawHeartRate(w) {
|
||||||
|
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
const color = getCircleColor("hr") || colorRed;
|
const color = getCircleColor("hr");
|
||||||
|
|
||||||
let percent;
|
let percent;
|
||||||
if (hrtValue != undefined) {
|
if (hrtValue != undefined) {
|
||||||
const minHR = settings.minHR || 40;
|
const minHR = settings.minHR;
|
||||||
const maxHR = settings.maxHR || 200;
|
const maxHR = settings.maxHR;
|
||||||
percent = (hrtValue - minHR) / (maxHR - minHR);
|
percent = (hrtValue - minHR) / (maxHR - minHR);
|
||||||
if (isNaN(percent)) percent = 0;
|
if (isNaN(percent)) percent = 0;
|
||||||
drawGauge(w, h3, percent, color);
|
drawGauge(w, h3, percent, color);
|
||||||
|
|
@ -350,7 +339,7 @@ function drawBattery(w) {
|
||||||
|
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
let color = getCircleColor("battery") || colorYellow;
|
let color = getCircleColor("battery");
|
||||||
|
|
||||||
let percent;
|
let percent;
|
||||||
if (battery > 0) {
|
if (battery > 0) {
|
||||||
|
|
@ -380,9 +369,9 @@ function drawWeather(w) {
|
||||||
|
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
const color = getCircleColor("weather") || colorYellow;
|
const color = getCircleColor("weather");
|
||||||
let percent;
|
let percent;
|
||||||
const data = settings.weatherCircleData || "humidity";
|
const data = settings.weatherCircleData;
|
||||||
switch (data) {
|
switch (data) {
|
||||||
case "humidity":
|
case "humidity":
|
||||||
const humidity = weather ? weather.hum : undefined;
|
const humidity = weather ? weather.hum : undefined;
|
||||||
|
|
@ -427,7 +416,7 @@ function drawSunProgress(w) {
|
||||||
|
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
const color = getCircleColor("sunprogress") || colorYellow;
|
const color = getCircleColor("sunprogress");
|
||||||
|
|
||||||
drawGauge(w, h3, percent, color);
|
drawGauge(w, h3, percent, color);
|
||||||
|
|
||||||
|
|
@ -467,7 +456,7 @@ function drawTemperature(w) {
|
||||||
getPressureValue("temperature").then((temperature) => {
|
getPressureValue("temperature").then((temperature) => {
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
const color = getCircleColor("temperature") || colorGreen;
|
const color = getCircleColor("temperature");
|
||||||
|
|
||||||
let percent;
|
let percent;
|
||||||
if (temperature) {
|
if (temperature) {
|
||||||
|
|
@ -493,7 +482,7 @@ function drawPressure(w) {
|
||||||
getPressureValue("pressure").then((pressure) => {
|
getPressureValue("pressure").then((pressure) => {
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
const color = getCircleColor("pressure") || colorGreen;
|
const color = getCircleColor("pressure");
|
||||||
|
|
||||||
let percent;
|
let percent;
|
||||||
if (pressure && pressure > 0) {
|
if (pressure && pressure > 0) {
|
||||||
|
|
@ -519,7 +508,7 @@ function drawAltitude(w) {
|
||||||
getPressureValue("altitude").then((altitude) => {
|
getPressureValue("altitude").then((altitude) => {
|
||||||
drawCircleBackground(w);
|
drawCircleBackground(w);
|
||||||
|
|
||||||
const color = getCircleColor("altitude") || colorGreen;
|
const color = getCircleColor("altitude");
|
||||||
|
|
||||||
let percent;
|
let percent;
|
||||||
if (altitude) {
|
if (altitude) {
|
||||||
|
|
@ -797,7 +786,7 @@ Bangle.on('lock', function(isLocked) {
|
||||||
let timerHrm;
|
let timerHrm;
|
||||||
Bangle.on('HRM', function(hrm) {
|
Bangle.on('HRM', function(hrm) {
|
||||||
if (isCircleEnabled("hr")) {
|
if (isCircleEnabled("hr")) {
|
||||||
if (hrm.confidence >= (settings.confidence || 0)) {
|
if (hrm.confidence >= (settings.confidence)) {
|
||||||
hrtValue = hrm.bpm;
|
hrtValue = hrm.bpm;
|
||||||
if (Bangle.isLCDOn()) {
|
if (Bangle.isLCDOn()) {
|
||||||
drawHeartRate();
|
drawHeartRate();
|
||||||
|
|
@ -809,7 +798,7 @@ Bangle.on('HRM', function(hrm) {
|
||||||
timerHrm = setTimeout(() => {
|
timerHrm = setTimeout(() => {
|
||||||
hrtValue = '...';
|
hrtValue = '...';
|
||||||
drawHeartRate();
|
drawHeartRate();
|
||||||
}, settings.hrmValidity * 1000 || 30000);
|
}, settings.hrmValidity * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"minHR": 40,
|
||||||
|
"maxHR": 200,
|
||||||
|
"confidence": 0,
|
||||||
|
"stepGoal": 10000,
|
||||||
|
"stepDistanceGoal": 8000,
|
||||||
|
"stepLength": 0.8,
|
||||||
|
"batteryWarn": 30,
|
||||||
|
"showWidgets": false,
|
||||||
|
"weatherCircleData": "humidity",
|
||||||
|
"circleCount": 3,
|
||||||
|
"circle1": "hr",
|
||||||
|
"circle2": "steps",
|
||||||
|
"circle3": "battery",
|
||||||
|
"circle4": "weather",
|
||||||
|
"circle1color": "green-red",
|
||||||
|
"circle2color": "#0000ff",
|
||||||
|
"circle3color": "red-green",
|
||||||
|
"circle4color": "#ffff00",
|
||||||
|
"circle1colorizeIcon": true,
|
||||||
|
"circle2colorizeIcon": true,
|
||||||
|
"circle3colorizeIcon": true,
|
||||||
|
"circle4colorizeIcon": false,
|
||||||
|
"hrmValidity": 60
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{ "id": "circlesclock",
|
{ "id": "circlesclock",
|
||||||
"name": "Circles clock",
|
"name": "Circles clock",
|
||||||
"shortName":"Circles clock",
|
"shortName":"Circles clock",
|
||||||
"version":"0.09",
|
"version":"0.10",
|
||||||
"description": "A clock with three or four circles for different data at the bottom in a probably familiar style",
|
"description": "A clock with three or four circles for different data at the bottom in a probably familiar style",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"screenshots": [{"url":"screenshot-dark.png"}, {"url":"screenshot-light.png"}, {"url":"screenshot-dark-4.png"}, {"url":"screenshot-light-4.png"}],
|
"screenshots": [{"url":"screenshot-dark.png"}, {"url":"screenshot-light.png"}, {"url":"screenshot-dark-4.png"}, {"url":"screenshot-light-4.png"}],
|
||||||
|
|
@ -13,7 +13,8 @@
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"circlesclock.app.js","url":"app.js"},
|
{"name":"circlesclock.app.js","url":"app.js"},
|
||||||
{"name":"circlesclock.img","url":"app-icon.js","evaluate":true},
|
{"name":"circlesclock.img","url":"app-icon.js","evaluate":true},
|
||||||
{"name":"circlesclock.settings.js","url":"settings.js"}
|
{"name":"circlesclock.settings.js","url":"settings.js"},
|
||||||
|
{"name":"circlesclock.default.json","url":"default.json"}
|
||||||
],
|
],
|
||||||
"data": [
|
"data": [
|
||||||
{"name":"circlesclock.json"}
|
{"name":"circlesclock.json"}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
(function(back) {
|
(function(back) {
|
||||||
const SETTINGS_FILE = "circlesclock.json";
|
const SETTINGS_FILE = "circlesclock.json";
|
||||||
const storage = require('Storage');
|
const storage = require('Storage');
|
||||||
let settings = storage.readJSON(SETTINGS_FILE, 1) || {};
|
let settings = Object.assign(
|
||||||
|
storage.readJSON("circlesclock.default.json", true) || {},
|
||||||
|
storage.readJSON(SETTINGS_FILE, true) || {}
|
||||||
|
);
|
||||||
|
|
||||||
function save(key, value) {
|
function save(key, value) {
|
||||||
settings[key] = value;
|
settings[key] = value;
|
||||||
storage.write(SETTINGS_FILE, settings);
|
storage.write(SETTINGS_FILE, settings);
|
||||||
|
|
@ -20,7 +24,7 @@
|
||||||
'': { 'title': 'Circles clock' },
|
'': { 'title': 'Circles clock' },
|
||||||
/*LANG*/'< Back': back,
|
/*LANG*/'< Back': back,
|
||||||
/*LANG*/'circle count': {
|
/*LANG*/'circle count': {
|
||||||
value: "circleCount" in settings ? settings.circleCount : 3,
|
value: settings.circleCount,
|
||||||
min: 3,
|
min: 3,
|
||||||
max : 4,
|
max : 4,
|
||||||
step: 1,
|
step: 1,
|
||||||
|
|
@ -33,7 +37,7 @@
|
||||||
/*LANG*/'heartrate': ()=>showHRMenu(),
|
/*LANG*/'heartrate': ()=>showHRMenu(),
|
||||||
/*LANG*/'steps': ()=>showStepMenu(),
|
/*LANG*/'steps': ()=>showStepMenu(),
|
||||||
/*LANG*/'battery warn': {
|
/*LANG*/'battery warn': {
|
||||||
value: "batteryWarn" in settings ? settings.batteryWarn : 30,
|
value: settings.batteryWarn,
|
||||||
min: 10,
|
min: 10,
|
||||||
max : 100,
|
max : 100,
|
||||||
step: 10,
|
step: 10,
|
||||||
|
|
@ -43,12 +47,12 @@
|
||||||
onchange: x => save('batteryWarn', x),
|
onchange: x => save('batteryWarn', x),
|
||||||
},
|
},
|
||||||
/*LANG*/'show widgets': {
|
/*LANG*/'show widgets': {
|
||||||
value: "showWidgets" in settings ? settings.showWidgets : false,
|
value: !!settings.showWidgets,
|
||||||
format: () => (settings.showWidgets ? 'Yes' : 'No'),
|
format: () => (settings.showWidgets ? 'Yes' : 'No'),
|
||||||
onchange: x => save('showWidgets', x),
|
onchange: x => save('showWidgets', x),
|
||||||
},
|
},
|
||||||
/*LANG*/'weather circle': {
|
/*LANG*/'weather data': {
|
||||||
value: settings.weatherCircleData ? weatherData.indexOf(settings.weatherCircleData) : 1,
|
value: weatherData.indexOf(settings.weatherCircleData),
|
||||||
min: 0, max: 2,
|
min: 0, max: 2,
|
||||||
format: v => weatherData[v],
|
format: v => weatherData[v],
|
||||||
onchange: x => save('weatherCircleData', weatherData[x]),
|
onchange: x => save('weatherCircleData', weatherData[x]),
|
||||||
|
|
@ -62,7 +66,7 @@
|
||||||
'': { 'title': /*LANG*/'Heartrate' },
|
'': { 'title': /*LANG*/'Heartrate' },
|
||||||
/*LANG*/'< Back': ()=>showMainMenu(),
|
/*LANG*/'< Back': ()=>showMainMenu(),
|
||||||
/*LANG*/'minimum': {
|
/*LANG*/'minimum': {
|
||||||
value: "minHR" in settings ? settings.minHR : 40,
|
value: settings.minHR,
|
||||||
min: 0,
|
min: 0,
|
||||||
max : 250,
|
max : 250,
|
||||||
step: 5,
|
step: 5,
|
||||||
|
|
@ -72,7 +76,7 @@
|
||||||
onchange: x => save('minHR', x),
|
onchange: x => save('minHR', x),
|
||||||
},
|
},
|
||||||
/*LANG*/'maximum': {
|
/*LANG*/'maximum': {
|
||||||
value: "maxHR" in settings ? settings.maxHR : 200,
|
value: settings.maxHR,
|
||||||
min: 20,
|
min: 20,
|
||||||
max : 250,
|
max : 250,
|
||||||
step: 5,
|
step: 5,
|
||||||
|
|
@ -82,7 +86,7 @@
|
||||||
onchange: x => save('maxHR', x),
|
onchange: x => save('maxHR', x),
|
||||||
},
|
},
|
||||||
/*LANG*/'min. confidence': {
|
/*LANG*/'min. confidence': {
|
||||||
value: "confidence" in settings ? settings.confidence : 0,
|
value: settings.confidence,
|
||||||
min: 0,
|
min: 0,
|
||||||
max : 100,
|
max : 100,
|
||||||
step: 10,
|
step: 10,
|
||||||
|
|
@ -92,7 +96,7 @@
|
||||||
onchange: x => save('confidence', x),
|
onchange: x => save('confidence', x),
|
||||||
},
|
},
|
||||||
/*LANG*/'valid period': {
|
/*LANG*/'valid period': {
|
||||||
value: "hrmValidity" in settings ? settings.hrmValidity : 30,
|
value: settings.hrmValidity,
|
||||||
min: 10,
|
min: 10,
|
||||||
max : 600,
|
max : 600,
|
||||||
step: 10,
|
step: 10,
|
||||||
|
|
@ -110,7 +114,7 @@
|
||||||
'': { 'title': /*LANG*/'Steps' },
|
'': { 'title': /*LANG*/'Steps' },
|
||||||
/*LANG*/'< Back': ()=>showMainMenu(),
|
/*LANG*/'< Back': ()=>showMainMenu(),
|
||||||
/*LANG*/'goal': {
|
/*LANG*/'goal': {
|
||||||
value: "stepGoal" in settings ? settings.stepGoal : 10000,
|
value: settings.stepGoal,
|
||||||
min: 2000,
|
min: 2000,
|
||||||
max : 50000,
|
max : 50000,
|
||||||
step: 2000,
|
step: 2000,
|
||||||
|
|
@ -120,7 +124,7 @@
|
||||||
onchange: x => save('stepGoal', x),
|
onchange: x => save('stepGoal', x),
|
||||||
},
|
},
|
||||||
/*LANG*/'distance goal': {
|
/*LANG*/'distance goal': {
|
||||||
value: "stepDistanceGoal" in settings ? settings.stepDistanceGoal : 8000,
|
value: settings.stepDistanceGoal,
|
||||||
min: 2000,
|
min: 2000,
|
||||||
max : 30000,
|
max : 30000,
|
||||||
step: 1000,
|
step: 1000,
|
||||||
|
|
@ -130,7 +134,7 @@
|
||||||
onchange: x => save('stepDistanceGoal', x),
|
onchange: x => save('stepDistanceGoal', x),
|
||||||
},
|
},
|
||||||
/*LANG*/'step length': {
|
/*LANG*/'step length': {
|
||||||
value: "stepLength" in settings ? settings.stepLength : 0.8,
|
value: settings.stepLength,
|
||||||
min: 0.1,
|
min: 0.1,
|
||||||
max : 1.5,
|
max : 1.5,
|
||||||
step: 0.01,
|
step: 0.01,
|
||||||
|
|
@ -142,9 +146,6 @@
|
||||||
};
|
};
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultCircleTypes = ["steps", "hr", "battery", "weather"];
|
|
||||||
|
|
||||||
function showCircleMenu(circleId) {
|
function showCircleMenu(circleId) {
|
||||||
const circleName = "circle" + circleId;
|
const circleName = "circle" + circleId;
|
||||||
const colorKey = circleName + "color";
|
const colorKey = circleName + "color";
|
||||||
|
|
@ -154,19 +155,19 @@
|
||||||
'': { 'title': /*LANG*/'Circle ' + circleId },
|
'': { 'title': /*LANG*/'Circle ' + circleId },
|
||||||
/*LANG*/'< Back': ()=>showMainMenu(),
|
/*LANG*/'< Back': ()=>showMainMenu(),
|
||||||
/*LANG*/'data': {
|
/*LANG*/'data': {
|
||||||
value: settings[circleName]!=undefined ? valuesCircleTypes.indexOf(settings[circleName]) : valuesCircleTypes.indexOf(defaultCircleTypes[circleId -1]),
|
value: valuesCircleTypes.indexOf(settings[circleName]),
|
||||||
min: 0, max: valuesCircleTypes.length - 1,
|
min: 0, max: valuesCircleTypes.length - 1,
|
||||||
format: v => namesCircleTypes[v],
|
format: v => namesCircleTypes[v],
|
||||||
onchange: x => save(circleName, valuesCircleTypes[x]),
|
onchange: x => save(circleName, valuesCircleTypes[x]),
|
||||||
},
|
},
|
||||||
/*LANG*/'color': {
|
/*LANG*/'color': {
|
||||||
value: settings[colorKey] ? valuesColors.indexOf(settings[colorKey]) : 0,
|
value: valuesColors.indexOf(settings[colorKey]) || 0,
|
||||||
min: 0, max: valuesColors.length - 1,
|
min: 0, max: valuesColors.length - 1,
|
||||||
format: v => namesColors[v],
|
format: v => namesColors[v],
|
||||||
onchange: x => save(colorKey, valuesColors[x]),
|
onchange: x => save(colorKey, valuesColors[x]),
|
||||||
},
|
},
|
||||||
/*LANG*/'colorize icon': {
|
/*LANG*/'colorize icon': {
|
||||||
value: colorizeIconKey in settings ? settings[colorizeIconKey] : false,
|
value: settings[colorizeIconKey] || false,
|
||||||
format: () => (settings[colorizeIconKey] ? 'Yes' : 'No'),
|
format: () => (settings[colorizeIconKey] ? 'Yes' : 'No'),
|
||||||
onchange: x => save(colorizeIconKey, x),
|
onchange: x => save(colorizeIconKey, x),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue