Move default settings to external file
parent
6872c38a8d
commit
6daccc3813
|
|
@ -20,25 +20,14 @@ const weatherStormy = atob("EBCBAAAAAYAH4AwwOBBgGEAOQMJAgjmOGcgAgACAAAAAAAAA");
|
|||
const sunSetDown = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAAGYAPAAYAAAAAA");
|
||||
const sunSetUp = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAABgAPABmAAAAAA");
|
||||
|
||||
let settings = storage.readJSON("circlesclock.json", 1) || {
|
||||
'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'
|
||||
};
|
||||
const SETTINGS_FILE = "circlesclock.json";
|
||||
let settings = Object.assign(
|
||||
storage.readJSON("circlesclock.default.json", true) || {},
|
||||
storage.readJSON(SETTINGS_FILE, true) || {}
|
||||
);
|
||||
// Load step goal from pedometer widget as fallback
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +58,7 @@ const widgetOffset = showWidgets ? 24 : 0;
|
|||
const dowOffset = circleCount == 3 ? 22 : 24; // dow offset relative to date
|
||||
const h = g.getHeight() - widgetOffset;
|
||||
const w = g.getWidth();
|
||||
const hOffset = 30 - widgetOffset;
|
||||
const hOffset = (circleCount == 3 ? 34 : 30) - widgetOffset;
|
||||
const h1 = Math.round(1 * h / 5 - hOffset);
|
||||
const h2 = Math.round(3 * h / 5 - hOffset);
|
||||
const h3 = Math.round(8 * h / 8 - hOffset - 3); // circle y position
|
||||
|
|
@ -279,10 +268,10 @@ function drawSteps(w) {
|
|||
|
||||
drawCircleBackground(w);
|
||||
|
||||
const color = getCircleColor("steps") || colorBlue;
|
||||
const color = getCircleColor("steps");
|
||||
|
||||
let percent;
|
||||
const stepGoal = settings.stepGoal || 10000;
|
||||
const stepGoal = settings.stepGoal;
|
||||
if (stepGoal > 0) {
|
||||
percent = steps / stepGoal;
|
||||
if (stepGoal < steps) percent = 1;
|
||||
|
|
@ -299,15 +288,15 @@ function drawSteps(w) {
|
|||
function drawStepsDistance(w) {
|
||||
if (!w) w = getCircleXPosition("stepsDistance");
|
||||
const steps = getSteps();
|
||||
const stepDistance = settings.stepLength || 0.8;
|
||||
const stepDistance = settings.stepLength;
|
||||
const stepsDistance = Math.round(steps * stepDistance);
|
||||
|
||||
drawCircleBackground(w);
|
||||
|
||||
const color = getCircleColor("stepsDistance") || colorGreen;
|
||||
const color = getCircleColor("stepsDistance");
|
||||
|
||||
let percent;
|
||||
const stepDistanceGoal = settings.stepDistanceGoal || 8000;
|
||||
const stepDistanceGoal = settings.stepDistanceGoal;
|
||||
if (stepDistanceGoal > 0) {
|
||||
percent = stepsDistance / stepDistanceGoal;
|
||||
if (stepDistanceGoal < stepsDistance) percent = 1;
|
||||
|
|
@ -326,12 +315,12 @@ function drawHeartRate(w) {
|
|||
|
||||
drawCircleBackground(w);
|
||||
|
||||
const color = getCircleColor("hr") || colorRed;
|
||||
const color = getCircleColor("hr");
|
||||
|
||||
let percent;
|
||||
if (hrtValue != undefined) {
|
||||
const minHR = settings.minHR || 40;
|
||||
const maxHR = settings.maxHR || 200;
|
||||
const minHR = settings.minHR;
|
||||
const maxHR = settings.maxHR;
|
||||
percent = (hrtValue - minHR) / (maxHR - minHR);
|
||||
if (isNaN(percent)) percent = 0;
|
||||
drawGauge(w, h3, percent, color);
|
||||
|
|
@ -350,7 +339,7 @@ function drawBattery(w) {
|
|||
|
||||
drawCircleBackground(w);
|
||||
|
||||
let color = getCircleColor("battery") || colorYellow;
|
||||
let color = getCircleColor("battery");
|
||||
|
||||
let percent;
|
||||
if (battery > 0) {
|
||||
|
|
@ -380,9 +369,9 @@ function drawWeather(w) {
|
|||
|
||||
drawCircleBackground(w);
|
||||
|
||||
const color = getCircleColor("weather") || colorYellow;
|
||||
const color = getCircleColor("weather");
|
||||
let percent;
|
||||
const data = settings.weatherCircleData || "humidity";
|
||||
const data = settings.weatherCircleData;
|
||||
switch (data) {
|
||||
case "humidity":
|
||||
const humidity = weather ? weather.hum : undefined;
|
||||
|
|
@ -427,7 +416,7 @@ function drawSunProgress(w) {
|
|||
|
||||
drawCircleBackground(w);
|
||||
|
||||
const color = getCircleColor("sunprogress") || colorYellow;
|
||||
const color = getCircleColor("sunprogress");
|
||||
|
||||
drawGauge(w, h3, percent, color);
|
||||
|
||||
|
|
@ -467,7 +456,7 @@ function drawTemperature(w) {
|
|||
getPressureValue("temperature").then((temperature) => {
|
||||
drawCircleBackground(w);
|
||||
|
||||
const color = getCircleColor("temperature") || colorGreen;
|
||||
const color = getCircleColor("temperature");
|
||||
|
||||
let percent;
|
||||
if (temperature) {
|
||||
|
|
@ -493,7 +482,7 @@ function drawPressure(w) {
|
|||
getPressureValue("pressure").then((pressure) => {
|
||||
drawCircleBackground(w);
|
||||
|
||||
const color = getCircleColor("pressure") || colorGreen;
|
||||
const color = getCircleColor("pressure");
|
||||
|
||||
let percent;
|
||||
if (pressure && pressure > 0) {
|
||||
|
|
@ -519,7 +508,7 @@ function drawAltitude(w) {
|
|||
getPressureValue("altitude").then((altitude) => {
|
||||
drawCircleBackground(w);
|
||||
|
||||
const color = getCircleColor("altitude") || colorGreen;
|
||||
const color = getCircleColor("altitude");
|
||||
|
||||
let percent;
|
||||
if (altitude) {
|
||||
|
|
@ -578,23 +567,23 @@ function getWeatherIconByCode(code) {
|
|||
default:
|
||||
return weatherRainy;
|
||||
}
|
||||
case 6:
|
||||
return weatherSnowy;
|
||||
case 7:
|
||||
return weatherFoggy;
|
||||
case 8:
|
||||
switch (code) {
|
||||
case 800:
|
||||
return isDay() ? weatherSunny : weatherMoon;
|
||||
case 801:
|
||||
return weatherPartlyCloudy;
|
||||
case 802:
|
||||
return weatherPartlyCloudy;
|
||||
case 6:
|
||||
return weatherSnowy;
|
||||
case 7:
|
||||
return weatherFoggy;
|
||||
case 8:
|
||||
switch (code) {
|
||||
case 800:
|
||||
return isDay() ? weatherSunny : weatherMoon;
|
||||
case 801:
|
||||
return weatherPartlyCloudy;
|
||||
case 802:
|
||||
return weatherPartlyCloudy;
|
||||
default:
|
||||
return weatherCloudy;
|
||||
}
|
||||
default:
|
||||
return weatherCloudy;
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -797,7 +786,7 @@ Bangle.on('lock', function(isLocked) {
|
|||
let timerHrm;
|
||||
Bangle.on('HRM', function(hrm) {
|
||||
if (isCircleEnabled("hr")) {
|
||||
if (hrm.confidence >= (settings.confidence || 0)) {
|
||||
if (hrm.confidence >= (settings.confidence)) {
|
||||
hrtValue = hrm.bpm;
|
||||
if (Bangle.isLCDOn()) {
|
||||
drawHeartRate();
|
||||
|
|
@ -809,7 +798,7 @@ Bangle.on('HRM', function(hrm) {
|
|||
timerHrm = setTimeout(() => {
|
||||
hrtValue = '...';
|
||||
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",
|
||||
"name": "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",
|
||||
"icon": "app.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": [
|
||||
{"name":"circlesclock.app.js","url":"app.js"},
|
||||
{"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": [
|
||||
{"name":"circlesclock.json"}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
(function(back) {
|
||||
const SETTINGS_FILE = "circlesclock.json";
|
||||
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) {
|
||||
settings[key] = value;
|
||||
storage.write(SETTINGS_FILE, settings);
|
||||
|
|
@ -10,8 +14,8 @@
|
|||
const valuesCircleTypes = ["empty", "steps", "stepsDist", "hr", "battery", "weather", "sunprogress", "temperature", "pressure", "altitude"];
|
||||
const namesCircleTypes = ["empty", "steps", "distance", "heart", "battery", "weather", "sun", "temperature", "pressure", "altitude"];
|
||||
|
||||
const valuesColors = ["", "#ff0000", "#00ff00", "#0000ff", "#ffff00", "#ff00ff", "#00ffff", "#fff", "#000", "green-red", "red-green"];
|
||||
const namesColors = ["default", "red", "green", "blue", "yellow", "magenta", "cyan", "white", "black", "green->red", "red->green"];
|
||||
const valuesColors = ["", "#ff0000", "#00ff00", "#0000ff", "#ffff00", "#ff00ff", "#00ffff", "#fff", "#000", "green-red", "red-green"];
|
||||
const namesColors = ["default", "red", "green", "blue", "yellow", "magenta", "cyan", "white", "black", "green->red", "red->green"];
|
||||
|
||||
const weatherData = ["empty", "humidity", "wind"];
|
||||
|
||||
|
|
@ -20,7 +24,7 @@
|
|||
'': { 'title': 'Circles clock' },
|
||||
/*LANG*/'< Back': back,
|
||||
/*LANG*/'circle count': {
|
||||
value: "circleCount" in settings ? settings.circleCount : 3,
|
||||
value: settings.circleCount,
|
||||
min: 3,
|
||||
max : 4,
|
||||
step: 1,
|
||||
|
|
@ -33,7 +37,7 @@
|
|||
/*LANG*/'heartrate': ()=>showHRMenu(),
|
||||
/*LANG*/'steps': ()=>showStepMenu(),
|
||||
/*LANG*/'battery warn': {
|
||||
value: "batteryWarn" in settings ? settings.batteryWarn : 30,
|
||||
value: settings.batteryWarn,
|
||||
min: 10,
|
||||
max : 100,
|
||||
step: 10,
|
||||
|
|
@ -43,12 +47,12 @@
|
|||
onchange: x => save('batteryWarn', x),
|
||||
},
|
||||
/*LANG*/'show widgets': {
|
||||
value: "showWidgets" in settings ? settings.showWidgets : false,
|
||||
value: !!settings.showWidgets,
|
||||
format: () => (settings.showWidgets ? 'Yes' : 'No'),
|
||||
onchange: x => save('showWidgets', x),
|
||||
},
|
||||
/*LANG*/'weather circle': {
|
||||
value: settings.weatherCircleData ? weatherData.indexOf(settings.weatherCircleData) : 1,
|
||||
/*LANG*/'weather data': {
|
||||
value: weatherData.indexOf(settings.weatherCircleData),
|
||||
min: 0, max: 2,
|
||||
format: v => weatherData[v],
|
||||
onchange: x => save('weatherCircleData', weatherData[x]),
|
||||
|
|
@ -62,7 +66,7 @@
|
|||
'': { 'title': /*LANG*/'Heartrate' },
|
||||
/*LANG*/'< Back': ()=>showMainMenu(),
|
||||
/*LANG*/'minimum': {
|
||||
value: "minHR" in settings ? settings.minHR : 40,
|
||||
value: settings.minHR,
|
||||
min: 0,
|
||||
max : 250,
|
||||
step: 5,
|
||||
|
|
@ -72,7 +76,7 @@
|
|||
onchange: x => save('minHR', x),
|
||||
},
|
||||
/*LANG*/'maximum': {
|
||||
value: "maxHR" in settings ? settings.maxHR : 200,
|
||||
value: settings.maxHR,
|
||||
min: 20,
|
||||
max : 250,
|
||||
step: 5,
|
||||
|
|
@ -82,7 +86,7 @@
|
|||
onchange: x => save('maxHR', x),
|
||||
},
|
||||
/*LANG*/'min. confidence': {
|
||||
value: "confidence" in settings ? settings.confidence : 0,
|
||||
value: settings.confidence,
|
||||
min: 0,
|
||||
max : 100,
|
||||
step: 10,
|
||||
|
|
@ -92,7 +96,7 @@
|
|||
onchange: x => save('confidence', x),
|
||||
},
|
||||
/*LANG*/'valid period': {
|
||||
value: "hrmValidity" in settings ? settings.hrmValidity : 30,
|
||||
value: settings.hrmValidity,
|
||||
min: 10,
|
||||
max : 600,
|
||||
step: 10,
|
||||
|
|
@ -110,7 +114,7 @@
|
|||
'': { 'title': /*LANG*/'Steps' },
|
||||
/*LANG*/'< Back': ()=>showMainMenu(),
|
||||
/*LANG*/'goal': {
|
||||
value: "stepGoal" in settings ? settings.stepGoal : 10000,
|
||||
value: settings.stepGoal,
|
||||
min: 2000,
|
||||
max : 50000,
|
||||
step: 2000,
|
||||
|
|
@ -120,7 +124,7 @@
|
|||
onchange: x => save('stepGoal', x),
|
||||
},
|
||||
/*LANG*/'distance goal': {
|
||||
value: "stepDistanceGoal" in settings ? settings.stepDistanceGoal : 8000,
|
||||
value: settings.stepDistanceGoal,
|
||||
min: 2000,
|
||||
max : 30000,
|
||||
step: 1000,
|
||||
|
|
@ -130,7 +134,7 @@
|
|||
onchange: x => save('stepDistanceGoal', x),
|
||||
},
|
||||
/*LANG*/'step length': {
|
||||
value: "stepLength" in settings ? settings.stepLength : 0.8,
|
||||
value: settings.stepLength,
|
||||
min: 0.1,
|
||||
max : 1.5,
|
||||
step: 0.01,
|
||||
|
|
@ -142,9 +146,6 @@
|
|||
};
|
||||
E.showMenu(menu);
|
||||
}
|
||||
|
||||
const defaultCircleTypes = ["steps", "hr", "battery", "weather"];
|
||||
|
||||
function showCircleMenu(circleId) {
|
||||
const circleName = "circle" + circleId;
|
||||
const colorKey = circleName + "color";
|
||||
|
|
@ -154,19 +155,19 @@
|
|||
'': { 'title': /*LANG*/'Circle ' + circleId },
|
||||
/*LANG*/'< Back': ()=>showMainMenu(),
|
||||
/*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,
|
||||
format: v => namesCircleTypes[v],
|
||||
onchange: x => save(circleName, valuesCircleTypes[x]),
|
||||
},
|
||||
/*LANG*/'color': {
|
||||
value: settings[colorKey] ? valuesColors.indexOf(settings[colorKey]) : 0,
|
||||
value: valuesColors.indexOf(settings[colorKey]) || 0,
|
||||
min: 0, max: valuesColors.length - 1,
|
||||
format: v => namesColors[v],
|
||||
onchange: x => save(colorKey, valuesColors[x]),
|
||||
},
|
||||
/*LANG*/'colorize icon': {
|
||||
value: colorizeIconKey in settings ? settings[colorizeIconKey] : false,
|
||||
value: settings[colorizeIconKey] || false,
|
||||
format: () => (settings[colorizeIconKey] ? 'Yes' : 'No'),
|
||||
onchange: x => save(colorizeIconKey, x),
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue