2021-12-16 07:06:53 +00:00
|
|
|
const locale = require("locale");
|
2022-01-07 12:30:09 +00:00
|
|
|
const storage = require("Storage");
|
2022-02-08 15:19:07 +00:00
|
|
|
Graphics.prototype.setFontRobotoRegular50NumericOnly = function(scale) {
|
|
|
|
// Actual height 39 (40 - 2)
|
|
|
|
this.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAB8AAAAAAAfAAAAAAAPwAAAAAAB8AAAAAAAeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAA4AAAAAAB+AAAAAAD/gAAAAAD/4AAAAAH/4AAAAAP/wAAAAAP/gAAAAAf/gAAAAAf/AAAAAA/+AAAAAB/+AAAAAB/8AAAAAD/4AAAAAH/4AAAAAD/wAAAAAA/wAAAAAAPgAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///wAAAB////gAAA////8AAA/////gAAP////8AAH8AAA/gAB8AAAD4AA+AAAAfAAPAAAADwADwAAAA8AA8AAAAPAAPAAAADwADwAAAA8AA8AAAAPAAPgAAAHwAB8AAAD4AAfwAAD+AAD/////AAA/////wAAH////4AAAf///4AAAB///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAeAAAAAAAPgAAAAAADwAAAAAAB8AAAAAAAfAAAAAAAHgAAAAAAD4AAAAAAA+AAAAAAAPAAAAAAAH/////wAB/////8AA//////AAP/////wAD/////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAfgAADwAAP4AAB8AAH+AAA/AAD/gAAfwAB/AAAf8AAfAAAP/AAPgAAH7wAD4AAD88AA8AAB+PAAPAAA/DwADwAAfg8AA8AAPwPAAPAAH4DwADwAH8A8AA+AD+APAAPwB/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AAB/wADwAAD/8AA8AAD/8AAPAAD/4AADwAD/4AAA8AD/4AAAPAH/wAAADwH/wAAAA8H/wAAAAPH/wAAAAD3/gAAAAA//gAAAAAP/gAAAAAD/gAAAAAA/AAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwA/4AAAH/Af/AAAH/8P/4AAD//n//AAA//7//4AAfx/+A+AAHwD+AHwAD4AfgB8AA8AHwAPAAPAA8ADwADwAPAA8AA8ADwAPAAPAA8ADwADwAfAA8AA+AH4AfAAHwD+AHwAB/D/4D4AAP/+/n+AAD//n//AAAf/w//gAAB/wH/wAAAHwA/4AAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB+AAAAAAD/8AAAAAD//wAAAAB//+AAAAA///wAAAAf4H+APAAH4AfgDwAD8AB8A8AA+AAfAPAAPAADwDwADwAA8B8AA8AAPAfAAPAADwHgADwAA8D4AA+AAeB+AAHwAHg/AAB+ADwfgAAP8D4/4AAD////8AAAf///8AAAB///+AAAAP//+AAAAAP/4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAOAAAB8AAHwAAAfgAD8AAAH4AA/AAAB8AAHwAAAOAAA4AAAAAAAAAAAAAAAAAAAAAAAAAA"), 46, atob("DRUcHBwcHBwcHBwcDA=="), 50+(scale<<8)+(1<<16));
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
Graphics.prototype.setFontRobotoRegular21 = function(scale) {
|
|
|
|
// Actual height 22 (21 - 0)
|
|
|
|
this.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAB/+YH/5gAAAAAAAAAAA+AAD4AAAAAA+AAD4AAAAAAAAAAAMAAYwABj+AH/4D/wAfjABGM4AZ/gD/4B/sAHYwABiAAEAAAAAAAAOAPw8A/h4HGBh4cHvgweGDhgcHOA8fwBw/AAAAAAAAPgAB/AAGMAAYwMBjDgD48AHH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AAB/+AH/4Af/gBwAAGAAAYAAAAAABxgAPnAB+OAGcYAYxgBjGAHOYAefgA58AAAAAYAABgAA//wD//gBgOAGAYAQBgAAAAH/gAf/AB/+AAAYAABgAAGAAAYAf/gB/+AH/4AAAABAAAHgAAfwAAP4AAH4AAHgAD8AB/AAfgABwAAAAAAQAAB8AAH+AAD/gAA+AAH4AH8AB+AAHwAAP4AAH8AAD4AA/gA/4AH4AAcAAAAAAAAAAYBgBweADzwAH8AAHgAB/gAfPABwOAGAYAAAABAAAHgBgfwGAf44AP/AAP4AH8AD+AAfAABgAAAAAAYDgBgeAGD4AY9gBnmAH4YAfBgB4GAGAYAAAAACAAAMAAB4AP//h/z/OAAOwAAYAAAAAAAf//x///AAAAwAAbAABn+H8P9/wP/8ABwAADAAAAAAAQAAHgAA4AADAAAMAAA4AABwAADgAAGAAAYAAHgAA8AADAAAAAAAHAAA+AAHcAA44ADBgAMGAAwYADjgAHcAAPgAAcAAAAAABwAAPgAP2AA/YADNgAP+AA/4AD/gAM2AAz4AAPgAAMAAAAAH/AAf94AA3gADXAANcAA9wADzAAPMA/0wH/TAf98DgDwH/HAf8cNgBz+AGP/85x/zn2YcfZDxtm+H2
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const SETTINGS_FILE = "circlesclock.json";
|
|
|
|
let settings = Object.assign(
|
|
|
|
storage.readJSON("circlesclock.default.json", true) || {},
|
|
|
|
storage.readJSON(SETTINGS_FILE, true) || {}
|
|
|
|
);
|
2022-06-22 09:09:54 +00:00
|
|
|
|
|
|
|
// Load step goal from health app and pedometer widget as fallback
|
2022-01-26 11:56:23 +00:00
|
|
|
if (settings.stepGoal == undefined) {
|
2022-06-22 09:09:54 +00:00
|
|
|
let d = storage.readJSON("health.json", true) || {};
|
|
|
|
settings.stepGoal = d != undefined && d.settings != undefined ? d.settings.stepGoal : undefined;
|
2022-10-25 06:11:19 +00:00
|
|
|
|
2022-06-22 09:09:54 +00:00
|
|
|
if (settings.stepGoal == undefined) {
|
|
|
|
d = storage.readJSON("wpedom.json", true) || {};
|
|
|
|
settings.stepGoal = d != undefined && d.settings != undefined ? d.settings.goal : 10000;
|
|
|
|
}
|
2022-01-26 11:56:23 +00:00
|
|
|
}
|
2022-01-16 17:44:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read location from myLocation app
|
|
|
|
*/
|
|
|
|
function getLocation() {
|
|
|
|
return storage.readJSON("mylocation.json", 1) || undefined;
|
|
|
|
}
|
|
|
|
let location = getLocation();
|
|
|
|
|
2022-01-05 11:16:14 +00:00
|
|
|
const showWidgets = settings.showWidgets || false;
|
2022-01-26 11:49:39 +00:00
|
|
|
const circleCount = settings.circleCount || 3;
|
2022-10-25 06:11:19 +00:00
|
|
|
const showBigWeather = settings.showBigWeather || false;
|
2022-01-05 11:16:14 +00:00
|
|
|
|
|
|
|
let hrtValue;
|
2022-01-16 17:36:24 +00:00
|
|
|
let now = Math.round(new Date().getTime() / 1000);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-16 17:44:08 +00:00
|
|
|
|
2022-01-05 11:16:14 +00:00
|
|
|
// layout values:
|
2021-12-17 21:36:34 +00:00
|
|
|
const colorFg = g.theme.dark ? '#fff' : '#000';
|
|
|
|
const colorBg = g.theme.dark ? '#000' : '#fff';
|
2021-12-16 07:06:53 +00:00
|
|
|
const colorGrey = '#808080';
|
2021-12-16 16:26:52 +00:00
|
|
|
const colorRed = '#ff0000';
|
2022-01-05 12:27:50 +00:00
|
|
|
const colorGreen = '#008000';
|
|
|
|
const colorBlue = '#0000ff';
|
|
|
|
const colorYellow = '#ffff00';
|
2022-01-06 10:08:46 +00:00
|
|
|
const widgetOffset = showWidgets ? 24 : 0;
|
2022-02-27 11:15:35 +00:00
|
|
|
const dowOffset = circleCount == 3 ? 20 : 22; // dow offset relative to date
|
2022-01-05 11:16:14 +00:00
|
|
|
const h = g.getHeight() - widgetOffset;
|
2021-12-16 07:06:53 +00:00
|
|
|
const w = g.getWidth();
|
2022-02-08 10:41:50 +00:00
|
|
|
const hOffset = (circleCount == 3 ? 34 : 30) - widgetOffset;
|
2021-12-16 07:06:53 +00:00
|
|
|
const h1 = Math.round(1 * h / 5 - hOffset);
|
|
|
|
const h2 = Math.round(3 * h / 5 - hOffset);
|
2022-01-07 12:30:09 +00:00
|
|
|
const h3 = Math.round(8 * h / 8 - hOffset - 3); // circle y position
|
2022-01-26 10:55:16 +00:00
|
|
|
|
|
|
|
/*
|
2022-01-26 11:56:23 +00:00
|
|
|
* circle x positions
|
|
|
|
* depending on circleCount
|
|
|
|
*
|
|
|
|
* | 1 2 3 4 5 6 |
|
|
|
|
* | (1) (2) (3) |
|
|
|
|
* => circles start at 1,3,5 / 6
|
|
|
|
*
|
|
|
|
* | 1 2 3 4 5 6 7 8 |
|
|
|
|
* | (1) (2) (3) (4) |
|
|
|
|
* => circles start at 1,3,5,7 / 8
|
|
|
|
*/
|
2022-01-26 10:55:16 +00:00
|
|
|
const parts = circleCount * 2;
|
|
|
|
const circlePosX = [
|
2022-01-26 11:49:39 +00:00
|
|
|
Math.round(1 * w / parts), // circle1
|
|
|
|
Math.round(3 * w / parts), // circle2
|
|
|
|
Math.round(5 * w / parts), // circle3
|
|
|
|
Math.round(7 * w / parts), // circle4
|
2022-01-26 10:55:16 +00:00
|
|
|
];
|
|
|
|
|
2022-01-30 18:04:15 +00:00
|
|
|
const radiusOuter = circleCount == 3 ? 25 : 20;
|
2022-01-26 10:55:16 +00:00
|
|
|
const radiusInner = circleCount == 3 ? 20 : 15;
|
2022-01-29 21:33:43 +00:00
|
|
|
const circleFontSmall = circleCount == 3 ? "Vector:14" : "Vector:10";
|
|
|
|
const circleFont = circleCount == 3 ? "Vector:15" : "Vector:11";
|
|
|
|
const circleFontBig = circleCount == 3 ? "Vector:16" : "Vector:12";
|
2022-01-27 19:20:01 +00:00
|
|
|
const iconOffset = circleCount == 3 ? 6 : 8;
|
2022-01-26 10:55:16 +00:00
|
|
|
const defaultCircleTypes = ["steps", "hr", "battery", "weather"];
|
|
|
|
|
2022-02-27 11:15:35 +00:00
|
|
|
function hideWidgets() {
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* area to the top bar doesn't get cleared.
|
|
|
|
*/
|
|
|
|
if (WIDGETS && typeof WIDGETS === "object") {
|
|
|
|
for (let wd of WIDGETS) {
|
|
|
|
wd.draw = () => {};
|
|
|
|
wd.area = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-16 07:06:53 +00:00
|
|
|
|
|
|
|
function draw() {
|
2022-01-29 12:40:34 +00:00
|
|
|
g.clear(true);
|
2022-01-05 18:50:07 +00:00
|
|
|
if (!showWidgets) {
|
2022-02-27 11:15:35 +00:00
|
|
|
hideWidgets();
|
2022-01-05 18:50:07 +00:00
|
|
|
} else {
|
|
|
|
Bangle.drawWidgets();
|
|
|
|
}
|
|
|
|
|
2021-12-16 07:06:53 +00:00
|
|
|
g.setColor(colorBg);
|
2022-01-28 12:19:15 +00:00
|
|
|
g.fillRect(0, widgetOffset, w, h2 + 22);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
|
|
|
// time
|
2022-02-08 15:19:07 +00:00
|
|
|
g.setFontRobotoRegular50NumericOnly();
|
2021-12-16 07:06:53 +00:00
|
|
|
g.setColor(colorFg);
|
2022-10-25 06:11:19 +00:00
|
|
|
if (!showBigWeather) {
|
|
|
|
g.setFontAlign(0, -1);
|
|
|
|
g.drawString(locale.time(new Date(), 1), w / 2, h1 + 6);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g.setFontAlign(-1, -1);
|
2022-10-25 06:59:25 +00:00
|
|
|
g.drawString(locale.time(new Date(), 1), 2, h1 + 6);
|
2022-10-25 06:11:19 +00:00
|
|
|
}
|
2022-01-16 17:36:24 +00:00
|
|
|
now = Math.round(new Date().getTime() / 1000);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
|
|
|
// date & dow
|
2022-02-08 15:19:07 +00:00
|
|
|
g.setFontRobotoRegular21();
|
2022-10-25 06:11:19 +00:00
|
|
|
if (!showBigWeather) {
|
|
|
|
g.setFontAlign(0, 0);
|
|
|
|
g.drawString(locale.date(new Date()), w / 2, h2);
|
|
|
|
g.drawString(locale.dow(new Date()), w / 2, h2 + dowOffset);
|
|
|
|
} else {
|
|
|
|
g.setFontAlign(-1, 0);
|
2022-10-25 06:59:25 +00:00
|
|
|
g.drawString(locale.date(new Date()), 2, h2);
|
|
|
|
g.drawString(locale.dow(new Date()), 2, h2 + dowOffset, 1);
|
2022-10-25 06:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// weather
|
|
|
|
if (showBigWeather) {
|
|
|
|
const weather = getWeather();
|
|
|
|
const tempString = weather ? locale.temp(weather.temp - 273.15) : undefined;
|
|
|
|
g.setFontAlign(1, 0);
|
2022-10-25 06:45:37 +00:00
|
|
|
if (tempString) g.drawString(tempString, w, h2);
|
2022-10-25 06:11:19 +00:00
|
|
|
|
|
|
|
const code = weather ? weather.code : -1;
|
2022-10-25 06:40:39 +00:00
|
|
|
if (code > -1) {
|
|
|
|
const icon = getWeatherIconByCode(code, true);
|
|
|
|
if (icon) g.drawImage(icon, w - 48, h1, {scale:0.75});
|
|
|
|
}
|
2022-10-25 06:11:19 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 09:09:54 +00:00
|
|
|
drawCircle(1);
|
|
|
|
drawCircle(2);
|
|
|
|
drawCircle(3);
|
|
|
|
if (circleCount >= 4) drawCircle(4);
|
2022-01-05 12:27:50 +00:00
|
|
|
}
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-07 12:30:09 +00:00
|
|
|
function drawCircle(index) {
|
|
|
|
let type = settings['circle' + index];
|
|
|
|
if (!type) type = defaultCircleTypes[index - 1];
|
2022-01-29 20:51:44 +00:00
|
|
|
const w = getCircleXPosition(type);
|
2022-01-27 20:36:25 +00:00
|
|
|
|
2022-01-05 12:27:50 +00:00
|
|
|
switch (type) {
|
|
|
|
case "steps":
|
|
|
|
drawSteps(w);
|
|
|
|
break;
|
|
|
|
case "stepsDist":
|
|
|
|
drawStepsDistance(w);
|
|
|
|
break;
|
|
|
|
case "hr":
|
|
|
|
drawHeartRate(w);
|
|
|
|
break;
|
|
|
|
case "battery":
|
|
|
|
drawBattery(w);
|
|
|
|
break;
|
2022-01-07 12:30:09 +00:00
|
|
|
case "weather":
|
|
|
|
drawWeather(w);
|
|
|
|
break;
|
2022-01-14 21:16:49 +00:00
|
|
|
case "sunprogress":
|
2022-01-26 10:55:16 +00:00
|
|
|
case "sunProgress":
|
2022-01-14 21:16:49 +00:00
|
|
|
drawSunProgress(w);
|
|
|
|
break;
|
2022-01-27 20:36:25 +00:00
|
|
|
case "temperature":
|
|
|
|
drawTemperature(w);
|
|
|
|
break;
|
|
|
|
case "pressure":
|
|
|
|
drawPressure(w);
|
|
|
|
break;
|
2022-01-27 21:20:32 +00:00
|
|
|
case "altitude":
|
|
|
|
drawAltitude(w);
|
|
|
|
break;
|
2022-01-14 13:46:59 +00:00
|
|
|
case "empty":
|
2022-01-14 21:16:49 +00:00
|
|
|
// we draw nothing here
|
2022-01-14 13:46:59 +00:00
|
|
|
return;
|
2022-01-05 12:27:50 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-07 08:53:40 +00:00
|
|
|
|
2022-01-14 14:19:00 +00:00
|
|
|
// serves as cache for quicker lookup of circle positions
|
|
|
|
let circlePositionsCache = [];
|
|
|
|
/*
|
|
|
|
* Looks in the following order if a circle with the given type is somewhere visible/configured
|
|
|
|
* 1. circlePositionsCache
|
|
|
|
* 2. settings
|
|
|
|
* 3. defaultCircleTypes
|
|
|
|
*
|
|
|
|
* In case 2 and 3 the circlePositionsCache will be updated
|
|
|
|
*/
|
2022-01-07 12:30:09 +00:00
|
|
|
function getCirclePosition(type) {
|
2022-01-14 14:19:00 +00:00
|
|
|
if (circlePositionsCache[type] >= 0) {
|
2022-01-29 20:51:44 +00:00
|
|
|
return circlePositionsCache[type];
|
2022-01-14 14:19:00 +00:00
|
|
|
}
|
2022-01-26 11:49:39 +00:00
|
|
|
for (let i = 1; i <= circleCount; i++) {
|
2022-01-05 12:27:50 +00:00
|
|
|
const setting = settings['circle' + i];
|
2022-01-14 14:19:00 +00:00
|
|
|
if (setting == type) {
|
|
|
|
circlePositionsCache[type] = i - 1;
|
2022-01-29 20:51:44 +00:00
|
|
|
return i - 1;
|
2022-01-14 14:19:00 +00:00
|
|
|
}
|
2022-01-07 12:30:09 +00:00
|
|
|
}
|
|
|
|
for (let i = 0; i < defaultCircleTypes.length; i++) {
|
2022-01-14 14:19:00 +00:00
|
|
|
if (type == defaultCircleTypes[i] && (!settings || settings['circle' + (i + 1)] == undefined)) {
|
|
|
|
circlePositionsCache[type] = i;
|
2022-01-29 20:51:44 +00:00
|
|
|
return i;
|
2022-01-14 14:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-07 12:30:09 +00:00
|
|
|
return undefined;
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 20:51:44 +00:00
|
|
|
function getCircleXPosition(type) {
|
|
|
|
const circlePos = getCirclePosition(type);
|
|
|
|
if (circlePos != undefined) {
|
|
|
|
return circlePosX[circlePos];
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2022-01-05 12:27:50 +00:00
|
|
|
function isCircleEnabled(type) {
|
|
|
|
return getCirclePosition(type) != undefined;
|
|
|
|
}
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-29 20:51:44 +00:00
|
|
|
function getCircleColor(type) {
|
|
|
|
const pos = getCirclePosition(type);
|
|
|
|
const color = settings["circle" + (pos + 1) + "color"];
|
|
|
|
if (color && color != "") return color;
|
|
|
|
}
|
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
function getCircleIconColor(type, color, percent) {
|
2022-01-29 21:33:43 +00:00
|
|
|
const pos = getCirclePosition(type);
|
2022-01-29 21:43:01 +00:00
|
|
|
const colorizeIcon = settings["circle" + (pos + 1) + "colorizeIcon"] == true;
|
2022-01-29 21:33:43 +00:00
|
|
|
if (colorizeIcon) {
|
2022-01-30 19:28:31 +00:00
|
|
|
return getGradientColor(color, percent);
|
2022-01-29 21:33:43 +00:00
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2022-01-29 20:51:44 +00:00
|
|
|
}
|
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
function getGradientColor(color, percent) {
|
|
|
|
if (isNaN(percent)) percent = 0;
|
|
|
|
if (percent > 1) percent = 1;
|
|
|
|
const colorList = [
|
|
|
|
'#00FF00', '#80FF00', '#FFFF00', '#FF8000', '#FF0000'
|
|
|
|
];
|
2022-02-22 14:15:18 +00:00
|
|
|
if (color == "fg") {
|
|
|
|
color = colorFg;
|
|
|
|
}
|
2022-01-30 19:28:31 +00:00
|
|
|
if (color == "green-red") {
|
|
|
|
const colorIndex = Math.round(colorList.length * percent);
|
|
|
|
return colorList[Math.min(colorIndex, colorList.length) - 1] || "#00ff00";
|
|
|
|
}
|
|
|
|
if (color == "red-green") {
|
|
|
|
const colorIndex = colorList.length - Math.round(colorList.length * percent);
|
|
|
|
return colorList[Math.min(colorIndex, colorList.length)] || "#ff0000";
|
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2022-01-29 21:33:43 +00:00
|
|
|
function getImage(graphic, color) {
|
|
|
|
if (!color || color == "") {
|
|
|
|
return graphic;
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
bpp: 1,
|
|
|
|
transparent: 0,
|
|
|
|
buffer: E.toArrayBuffer(graphic),
|
|
|
|
palette: new Uint16Array([colorBg, g.toColor(color)])
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 15:14:42 +00:00
|
|
|
|
2022-01-05 12:27:50 +00:00
|
|
|
function drawSteps(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("steps");
|
2021-12-16 07:06:53 +00:00
|
|
|
const steps = getSteps();
|
2022-01-07 09:26:45 +00:00
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawCircleBackground(w);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const color = getCircleColor("steps");
|
2022-01-29 20:51:44 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
let percent;
|
2022-02-08 10:41:50 +00:00
|
|
|
const stepGoal = settings.stepGoal;
|
2021-12-16 07:06:53 +00:00
|
|
|
if (stepGoal > 0) {
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = steps / stepGoal;
|
2021-12-16 07:06:53 +00:00
|
|
|
if (stepGoal < steps) percent = 1;
|
2022-01-29 20:51:44 +00:00
|
|
|
drawGauge(w, h3, percent, color);
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawInnerCircleAndTriangle(w);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
writeCircleText(w, shortValue(steps));
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-06-22 09:09:54 +00:00
|
|
|
g.drawImage(getImage(atob("EBCBAAAACAAcAB4AHgAeABwwADgGeAZ4AHgAMAAAAHAAIAAA"), getCircleIconColor("steps", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 12:27:50 +00:00
|
|
|
function drawStepsDistance(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("stepsDistance");
|
2022-01-05 12:27:50 +00:00
|
|
|
const steps = getSteps();
|
2022-02-08 10:41:50 +00:00
|
|
|
const stepDistance = settings.stepLength;
|
2022-01-06 12:01:36 +00:00
|
|
|
const stepsDistance = Math.round(steps * stepDistance);
|
2022-01-05 12:27:50 +00:00
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawCircleBackground(w);
|
2022-01-05 12:27:50 +00:00
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const color = getCircleColor("stepsDistance");
|
2022-01-29 20:51:44 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
let percent;
|
2022-02-08 10:41:50 +00:00
|
|
|
const stepDistanceGoal = settings.stepDistanceGoal;
|
2022-01-05 12:27:50 +00:00
|
|
|
if (stepDistanceGoal > 0) {
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = stepsDistance / stepDistanceGoal;
|
2022-01-05 12:27:50 +00:00
|
|
|
if (stepDistanceGoal < stepsDistance) percent = 1;
|
2022-01-29 20:51:44 +00:00
|
|
|
drawGauge(w, h3, percent, color);
|
2022-01-05 12:27:50 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawInnerCircleAndTriangle(w);
|
2022-01-05 12:27:50 +00:00
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
writeCircleText(w, shortValue(stepsDistance));
|
2022-01-05 12:27:50 +00:00
|
|
|
|
2022-06-22 09:09:54 +00:00
|
|
|
g.drawImage(getImage(atob("EBCBAAAACAAcAB4AHgAeABwwADgGeAZ4AHgAMAAAAHAAIAAA"), getCircleIconColor("stepsDistance", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2022-01-05 12:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawHeartRate(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("hr");
|
2022-01-07 09:26:45 +00:00
|
|
|
|
2022-02-22 14:17:09 +00:00
|
|
|
const heartIcon = atob("EBCBAAAAAAAeeD/8P/x//n/+P/w//B/4D/AH4APAAYAAAAAA");
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawCircleBackground(w);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const color = getCircleColor("hr");
|
2022-01-29 20:51:44 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
let percent;
|
2022-01-14 13:46:59 +00:00
|
|
|
if (hrtValue != undefined) {
|
2022-02-08 10:41:50 +00:00
|
|
|
const minHR = settings.minHR;
|
|
|
|
const maxHR = settings.maxHR;
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = (hrtValue - minHR) / (maxHR - minHR);
|
|
|
|
if (isNaN(percent)) percent = 0;
|
2022-01-29 20:51:44 +00:00
|
|
|
drawGauge(w, h3, percent, color);
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawInnerCircleAndTriangle(w);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
writeCircleText(w, hrtValue != undefined ? hrtValue : "-");
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
g.drawImage(getImage(heartIcon, getCircleIconColor("hr", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 12:27:50 +00:00
|
|
|
function drawBattery(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("battery");
|
2021-12-16 07:06:53 +00:00
|
|
|
const battery = E.getBattery();
|
2022-01-07 09:26:45 +00:00
|
|
|
|
2022-02-22 14:17:09 +00:00
|
|
|
const powerIcon = atob("EBCBAAAAA8ADwA/wD/AP8A/wD/AP8A/wD/AP8A/wD/AH4AAA");
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawCircleBackground(w);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
let color = getCircleColor("battery");
|
2022-01-29 20:51:44 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
let percent;
|
2021-12-16 07:06:53 +00:00
|
|
|
if (battery > 0) {
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = battery / 100;
|
2022-01-29 20:51:44 +00:00
|
|
|
drawGauge(w, h3, percent, color);
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawInnerCircleAndTriangle(w);
|
2021-12-17 07:34:28 +00:00
|
|
|
|
|
|
|
if (Bangle.isCharging()) {
|
|
|
|
color = colorGreen;
|
2022-01-07 08:53:40 +00:00
|
|
|
} else {
|
2021-12-17 07:34:28 +00:00
|
|
|
if (settings.batteryWarn != undefined && battery <= settings.batteryWarn) {
|
|
|
|
color = colorRed;
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 15:14:42 +00:00
|
|
|
writeCircleText(w, battery + '%');
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
g.drawImage(getImage(powerIcon, getCircleIconColor("battery", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-07 12:30:09 +00:00
|
|
|
function drawWeather(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("weather");
|
2022-01-07 12:30:09 +00:00
|
|
|
const weather = getWeather();
|
|
|
|
const tempString = weather ? locale.temp(weather.temp - 273.15) : undefined;
|
|
|
|
const code = weather ? weather.code : -1;
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawCircleBackground(w);
|
2022-01-07 12:30:09 +00:00
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const color = getCircleColor("weather");
|
2022-01-30 19:28:31 +00:00
|
|
|
let percent;
|
2022-02-08 10:41:50 +00:00
|
|
|
const data = settings.weatherCircleData;
|
2022-01-14 14:43:17 +00:00
|
|
|
switch (data) {
|
|
|
|
case "humidity":
|
|
|
|
const humidity = weather ? weather.hum : undefined;
|
|
|
|
if (humidity >= 0) {
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = humidity / 100;
|
|
|
|
drawGauge(w, h3, percent, color);
|
2022-01-14 14:43:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "wind":
|
2022-01-18 09:06:21 +00:00
|
|
|
if (weather) {
|
|
|
|
const wind = locale.speed(weather.wind).match(/^(\D*\d*)(.*)$/);
|
|
|
|
if (wind[1] >= 0) {
|
|
|
|
if (wind[2] == "kmh") {
|
|
|
|
wind[1] = windAsBeaufort(wind[1]);
|
|
|
|
}
|
|
|
|
// wind goes from 0 to 12 (see https://en.wikipedia.org/wiki/Beaufort_scale)
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = wind[1] / 12;
|
|
|
|
drawGauge(w, h3, percent, color);
|
2022-01-18 09:06:21 +00:00
|
|
|
}
|
2022-01-14 14:43:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "empty":
|
|
|
|
break;
|
2022-01-11 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
drawInnerCircleAndTriangle(w);
|
2022-01-07 12:30:09 +00:00
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
writeCircleText(w, tempString ? tempString : "?");
|
2022-01-07 12:30:09 +00:00
|
|
|
|
|
|
|
if (code > 0) {
|
|
|
|
const icon = getWeatherIconByCode(code);
|
2022-01-30 19:28:31 +00:00
|
|
|
if (icon) g.drawImage(getImage(icon, getCircleIconColor("weather", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2022-01-26 10:55:16 +00:00
|
|
|
} else {
|
|
|
|
g.drawString("?", w, h3 + radiusOuter);
|
2022-01-07 12:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 21:16:49 +00:00
|
|
|
function drawSunProgress(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("sunprogress");
|
2022-01-14 21:16:49 +00:00
|
|
|
const percent = getSunProgress();
|
|
|
|
|
2022-02-22 14:17:09 +00:00
|
|
|
// sunset icons:
|
|
|
|
const sunSetDown = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAAGYAPAAYAAAAAA");
|
|
|
|
const sunSetUp = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAABgAPABmAAAAAA");
|
|
|
|
|
2022-01-14 21:16:49 +00:00
|
|
|
drawCircleBackground(w);
|
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const color = getCircleColor("sunprogress");
|
2022-01-29 20:51:44 +00:00
|
|
|
|
|
|
|
drawGauge(w, h3, percent, color);
|
2022-01-14 21:16:49 +00:00
|
|
|
|
|
|
|
drawInnerCircleAndTriangle(w);
|
|
|
|
|
2022-01-29 20:51:44 +00:00
|
|
|
let icon = sunSetDown;
|
2022-01-15 09:41:50 +00:00
|
|
|
let text = "?";
|
2022-01-14 21:16:49 +00:00
|
|
|
const times = getSunData();
|
|
|
|
if (times != undefined) {
|
|
|
|
const sunRise = Math.round(times.sunrise.getTime() / 1000);
|
|
|
|
const sunSet = Math.round(times.sunset.getTime() / 1000);
|
2022-01-16 17:36:24 +00:00
|
|
|
if (!isDay()) {
|
|
|
|
// night
|
|
|
|
if (now > sunRise) {
|
|
|
|
// after sunRise
|
|
|
|
const upcomingSunRise = sunRise + 60 * 60 * 24;
|
|
|
|
text = formatSeconds(upcomingSunRise - now);
|
|
|
|
} else {
|
|
|
|
text = formatSeconds(sunRise - now);
|
|
|
|
}
|
2022-01-30 19:28:31 +00:00
|
|
|
icon = sunSetUp;
|
2022-01-14 21:16:49 +00:00
|
|
|
} else {
|
2022-01-16 17:36:24 +00:00
|
|
|
// day, approx sunrise tomorrow:
|
|
|
|
text = formatSeconds(sunSet - now);
|
2022-01-30 19:28:31 +00:00
|
|
|
icon = sunSetDown;
|
2022-01-14 21:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
writeCircleText(w, text);
|
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
g.drawImage(getImage(icon, getCircleIconColor("sunprogress", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2022-01-27 20:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawTemperature(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("temperature");
|
2022-01-27 20:36:25 +00:00
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
getPressureValue("temperature").then((temperature) => {
|
|
|
|
drawCircleBackground(w);
|
2022-01-27 20:36:25 +00:00
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const color = getCircleColor("temperature");
|
2022-01-29 20:51:44 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
let percent;
|
2022-01-28 09:19:00 +00:00
|
|
|
if (temperature) {
|
2022-01-29 20:51:44 +00:00
|
|
|
const min = -40;
|
2022-01-28 09:19:00 +00:00
|
|
|
const max = 85;
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = (temperature - min) / (max - min);
|
2022-01-29 20:51:44 +00:00
|
|
|
drawGauge(w, h3, percent, color);
|
2022-01-28 09:19:00 +00:00
|
|
|
}
|
2022-01-14 21:16:49 +00:00
|
|
|
|
2022-01-30 19:46:51 +00:00
|
|
|
drawInnerCircleAndTriangle(w);
|
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
if (temperature)
|
|
|
|
writeCircleText(w, locale.temp(temperature));
|
2022-06-22 09:09:54 +00:00
|
|
|
|
|
|
|
g.drawImage(getImage(atob("EBCBAAAAAYADwAJAAkADwAPAA8ADwAfgB+AH4AfgA8ABgAAA"), getCircleIconColor("temperature", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2022-01-27 21:20:32 +00:00
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
});
|
2022-01-27 20:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawPressure(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("pressure");
|
2022-01-27 20:36:25 +00:00
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
getPressureValue("pressure").then((pressure) => {
|
|
|
|
drawCircleBackground(w);
|
2022-01-27 20:36:25 +00:00
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const color = getCircleColor("pressure");
|
2022-01-29 20:51:44 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
let percent;
|
2022-01-28 09:19:00 +00:00
|
|
|
if (pressure && pressure > 0) {
|
2022-01-28 12:19:15 +00:00
|
|
|
const minPressure = 950;
|
2022-01-28 09:19:00 +00:00
|
|
|
const maxPressure = 1050;
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = (pressure - minPressure) / (maxPressure - minPressure);
|
2022-01-29 20:51:44 +00:00
|
|
|
drawGauge(w, h3, percent, color);
|
2022-01-28 09:19:00 +00:00
|
|
|
}
|
2022-01-27 20:36:25 +00:00
|
|
|
|
2022-01-30 19:46:51 +00:00
|
|
|
drawInnerCircleAndTriangle(w);
|
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
if (pressure)
|
|
|
|
writeCircleText(w, Math.round(pressure));
|
2022-01-27 20:36:25 +00:00
|
|
|
|
2022-06-22 09:09:54 +00:00
|
|
|
g.drawImage(getImage(atob("EBCBAAAAAYADwAJAAkADwAPAA8ADwAfgB+AH4AfgA8ABgAAA"), getCircleIconColor("pressure", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2022-01-27 20:36:25 +00:00
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
});
|
2022-01-27 21:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawAltitude(w) {
|
2022-01-29 20:51:44 +00:00
|
|
|
if (!w) w = getCircleXPosition("altitude");
|
2022-01-27 21:20:32 +00:00
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
getPressureValue("altitude").then((altitude) => {
|
|
|
|
drawCircleBackground(w);
|
2022-01-27 21:20:32 +00:00
|
|
|
|
2022-02-08 10:41:50 +00:00
|
|
|
const color = getCircleColor("altitude");
|
2022-01-29 20:51:44 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
let percent;
|
2022-01-28 09:19:00 +00:00
|
|
|
if (altitude) {
|
|
|
|
const min = 0;
|
|
|
|
const max = 10000;
|
2022-01-30 19:28:31 +00:00
|
|
|
percent = (altitude - min) / (max - min);
|
2022-01-29 20:51:44 +00:00
|
|
|
drawGauge(w, h3, percent, color);
|
2022-01-28 09:19:00 +00:00
|
|
|
}
|
2022-01-27 21:20:32 +00:00
|
|
|
|
2022-01-30 19:46:51 +00:00
|
|
|
drawInnerCircleAndTriangle(w);
|
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
if (altitude)
|
|
|
|
writeCircleText(w, locale.distance(Math.round(altitude)));
|
2022-01-27 21:20:32 +00:00
|
|
|
|
2022-06-22 09:09:54 +00:00
|
|
|
g.drawImage(getImage(atob("EBCBAAAAAYADwAJAAkADwAPAA8ADwAfgB+AH4AfgA8ABgAAA"), getCircleIconColor("altitude", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
|
2022-01-27 21:20:32 +00:00
|
|
|
|
2022-01-28 09:19:00 +00:00
|
|
|
});
|
2022-01-14 21:16:49 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 09:06:21 +00:00
|
|
|
/*
|
|
|
|
* wind goes from 0 to 12 (see https://en.wikipedia.org/wiki/Beaufort_scale)
|
|
|
|
*/
|
|
|
|
function windAsBeaufort(windInKmh) {
|
|
|
|
const beaufort = [2, 6, 12, 20, 29, 39, 50, 62, 75, 89, 103, 118];
|
|
|
|
let l = 0;
|
|
|
|
while (l < beaufort.length && beaufort[l] < windInKmh) {
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2022-01-14 21:16:49 +00:00
|
|
|
|
2022-01-07 12:30:09 +00:00
|
|
|
/*
|
|
|
|
* Choose weather icon to display based on weather conditition code
|
|
|
|
* https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2
|
|
|
|
*/
|
2022-10-25 06:11:19 +00:00
|
|
|
function getWeatherIconByCode(code, big) {
|
2022-01-07 12:30:09 +00:00
|
|
|
const codeGroup = Math.round(code / 100);
|
2022-10-25 06:11:19 +00:00
|
|
|
if (big == undefined) big = false;
|
2022-02-22 14:17:09 +00:00
|
|
|
|
|
|
|
// weather icons:
|
2022-10-25 06:11:19 +00:00
|
|
|
const weatherCloudy = big ? atob("QEDBAP//wxgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAAAAAAB//gAAAAAAAP//gAAAAAAD///AAAAAAAf4H+AAAAAAD8AD8AAAAAAfgAH4AAAAAB8AAPwAAAAAPgAAf/AAAAB8AAA//AAAAHgAAB/+AAAAeAAAH/8AAAH4AAAIH4AAB/AAAAAHwAAf8AAAAAPgAD/wAAAAAeAAPwAAAAAB4AB8AAAAAADwAHgAAAAAAPAA+AAAAAAA8ADwAAAAAADwA/AAAAAAAPAH8AAAAAAA8A/wAAAAAAHwH4AAAAAAAfg+AAAAAAAAfHwAAAAAAAA+eAAAAAAAAB54AAAAAAAAHvAAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD3gAAAAAAAAeeAAAAAAAAB58AAAAAAAAPj4AAAAAAAB8H4AAAAAAAfgP////////8Af////////gA////////8AAf//////+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==") : atob("EBCBAAAAAAAAAAfgD/Af8H/4//7///////9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8B8AAf/wB//APgAAgfgD+AA8AAAAfAH8AHwAAAA+AP8B+AAAAB4Af//4AAAAHgA///gAAAAPAA//8AAAAA8AAf/wAAAADwAAAAAAAAAPAAAAAAAAAA8AcAAAAAAADwD+AAAAAAAfAfgAAAAAAB+D4AAAAAAAB8fAAAAAAAAD54AAAAAAAAHngAAAAAAAAe8AAAAAAAAA/wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD/AAAAAAAAAPeAAAAAAAAB54AAAAAAAAHnwAAAAAAAA+PgAAAAAAAHwfgAAAAAAB+A/////////wB////////+AD////////wAB///////4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==") : atob("EBCBAAAAAYAP8B/4P/w//D/8f/5//j/8P/w//B/4D/ABgAAA");
|
|
|
|
const weatherPartlyCloudy = big ? atob("QEDBAP//wxgAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAABwAPAA4AAAAHgA8AHgAAAAfADwA+AAAAA+AfgHwAAAAB8P/w+AAAAAD7//3wAAAAAH///+BAAAAAP+B/wOAAAAAfgB+B8AAAAD4AD8H4AAAAPAA/wPwAAAB8AH+Af/AAAHgA/AA//AAAeAH4AB/+AADwAfAAH/8A//AD4AAIH4D/8AfAAAAHwP/wB4AAAAPg//AHgAAAAeAA8B+AAAAB4AB4fwAAAADwAHn/AAAAAPAAff8AAAAA8AA/8AAAAADwAD/AAAAAAPAEH4AAAAAA8A4PgAAAAAHwHgcAAAAAAfg+AwAAAAAAfHwAAAAAAAA+eAAAAAAAAB54AAAAAAAAHvAAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD3gAAAAAAAAeeAAAAAAAAB58AAAAAAAAPj4AAAAAAAB8H4AAAAAAAfgP////////8Af////////gA////////8AAf//////+AAAAAAAAAAAAAAAAA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//4f/4P/gA///B//B/8AAf/8P/8P+AAAAAAAPgAAAAAAAAB8AAAAAAAAAHwAAAAAAAAA+AAAAAAAAADwAAAAAAAAAfAAAAAAAAAB4AAAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==") : atob("EBCBAAAAAYAH4AwwOBBgGEAOQMJAgjmOGcgAgACAAAAAAAAA");
|
2022-02-22 14:17:09 +00:00
|
|
|
|
2022-01-07 12:30:09 +00:00
|
|
|
switch (codeGroup) {
|
|
|
|
case 2:
|
|
|
|
return weatherStormy;
|
|
|
|
case 3:
|
|
|
|
return weatherCloudy;
|
|
|
|
case 5:
|
|
|
|
switch (code) {
|
|
|
|
case 511:
|
|
|
|
return weatherSnowy;
|
|
|
|
case 520:
|
|
|
|
return weatherPartlyRainy;
|
|
|
|
case 521:
|
|
|
|
return weatherPartlyRainy;
|
|
|
|
case 522:
|
|
|
|
return weatherPartlyRainy;
|
|
|
|
case 531:
|
|
|
|
return weatherPartlyRainy;
|
|
|
|
default:
|
|
|
|
return weatherRainy;
|
|
|
|
}
|
2022-02-08 10:41:50 +00:00
|
|
|
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;
|
|
|
|
}
|
2022-06-28 09:19:29 +00:00
|
|
|
default:
|
|
|
|
return undefined;
|
2022-01-07 12:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 21:16:49 +00:00
|
|
|
|
2022-01-14 21:24:40 +00:00
|
|
|
function isDay() {
|
|
|
|
const times = getSunData();
|
|
|
|
if (times == undefined) return true;
|
|
|
|
const sunRise = Math.round(times.sunrise.getTime() / 1000);
|
|
|
|
const sunSet = Math.round(times.sunset.getTime() / 1000);
|
|
|
|
|
|
|
|
return (now > sunRise && now < sunSet);
|
|
|
|
}
|
|
|
|
|
2022-01-14 21:16:49 +00:00
|
|
|
function formatSeconds(s) {
|
|
|
|
if (s > 60 * 60) { // hours
|
|
|
|
return Math.round(s / (60 * 60)) + "h";
|
|
|
|
}
|
|
|
|
if (s > 60) { // minutes
|
2022-01-16 17:36:24 +00:00
|
|
|
return Math.round(s / 60) + "m";
|
2022-01-14 21:16:49 +00:00
|
|
|
}
|
2022-01-16 17:36:24 +00:00
|
|
|
return "<1m";
|
2022-01-14 21:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSunData() {
|
|
|
|
if (location != undefined && location.lat != undefined) {
|
2022-06-22 09:09:54 +00:00
|
|
|
const SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js");
|
2022-01-14 21:16:49 +00:00
|
|
|
// get today's sunlight times for lat/lon
|
2022-01-27 20:36:25 +00:00
|
|
|
return SunCalc ? SunCalc.getTimes(new Date(), location.lat, location.lon) : undefined;
|
2022-01-14 21:16:49 +00:00
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculated progress of the sun between sunrise and sunset in percent
|
|
|
|
*
|
|
|
|
* Taken from rebble app and modified
|
|
|
|
*/
|
|
|
|
function getSunProgress() {
|
|
|
|
const times = getSunData();
|
2022-01-14 21:21:55 +00:00
|
|
|
if (times == undefined) return 0;
|
2022-01-14 21:16:49 +00:00
|
|
|
const sunRise = Math.round(times.sunrise.getTime() / 1000);
|
|
|
|
const sunSet = Math.round(times.sunset.getTime() / 1000);
|
|
|
|
|
2022-01-16 17:36:24 +00:00
|
|
|
if (isDay()) {
|
2022-01-18 07:27:00 +00:00
|
|
|
// during day
|
2022-01-17 15:48:50 +00:00
|
|
|
const dayLength = sunSet - sunRise;
|
|
|
|
if (now > sunRise) {
|
|
|
|
return (now - sunRise) / dayLength;
|
|
|
|
} else {
|
|
|
|
return (sunRise - now) / dayLength;
|
|
|
|
}
|
2022-01-14 21:16:49 +00:00
|
|
|
} else {
|
2022-01-18 07:27:00 +00:00
|
|
|
// during night
|
2022-01-27 19:18:57 +00:00
|
|
|
if (now < sunRise) {
|
|
|
|
const prevSunSet = sunSet - 60 * 60 * 24;
|
2022-01-27 20:36:25 +00:00
|
|
|
return 1 - (sunRise - now) / (sunRise - prevSunSet);
|
2022-01-16 17:36:24 +00:00
|
|
|
} else {
|
2022-01-27 19:18:57 +00:00
|
|
|
const upcomingSunRise = sunRise + 60 * 60 * 24;
|
|
|
|
return (upcomingSunRise - now) / (upcomingSunRise - sunSet);
|
2022-01-16 17:36:24 +00:00
|
|
|
}
|
2022-01-14 21:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
/*
|
|
|
|
* Draws the background and the grey circle
|
|
|
|
*/
|
|
|
|
function drawCircleBackground(w) {
|
2022-01-28 12:19:15 +00:00
|
|
|
g.clearRect(w - radiusOuter - 3, h3 - radiusOuter - 3, w + radiusOuter + 3, h3 + radiusOuter + 3);
|
2022-01-14 15:14:42 +00:00
|
|
|
// Draw rectangle background:
|
|
|
|
g.setColor(colorBg);
|
|
|
|
g.fillRect(w - radiusOuter - 3, h3 - radiusOuter - 3, w + radiusOuter + 3, h3 + radiusOuter + 3);
|
|
|
|
// Draw grey background circle:
|
|
|
|
g.setColor(colorGrey);
|
|
|
|
g.fillCircle(w, h3, radiusOuter);
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawInnerCircleAndTriangle(w) {
|
|
|
|
// Draw inner circle
|
|
|
|
g.setColor(colorBg);
|
|
|
|
g.fillCircle(w, h3, radiusInner);
|
|
|
|
// Draw triangle which covers the bottom of the circle
|
|
|
|
g.fillPoly([w, h3, w - 15, h3 + radiusOuter + 5, w + 15, h3 + radiusOuter + 5]);
|
|
|
|
}
|
|
|
|
|
2021-12-16 07:06:53 +00:00
|
|
|
function radians(a) {
|
|
|
|
return a * Math.PI / 180;
|
|
|
|
}
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
/*
|
|
|
|
* This draws the actual gauge consisting out of lots of little filled circles
|
|
|
|
*/
|
2021-12-16 07:06:53 +00:00
|
|
|
function drawGauge(cx, cy, percent, color) {
|
2022-01-11 10:48:10 +00:00
|
|
|
const offset = 15;
|
2022-01-28 09:19:29 +00:00
|
|
|
const end = 360 - offset;
|
|
|
|
const radius = radiusInner + (circleCount == 3 ? 3 : 2);
|
2022-01-14 15:14:42 +00:00
|
|
|
const size = radiusOuter - radiusInner - 2;
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-30 19:46:51 +00:00
|
|
|
if (percent <= 0) return; // no gauge needed
|
2021-12-16 07:06:53 +00:00
|
|
|
if (percent > 1) percent = 1;
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
const startRotation = -offset;
|
|
|
|
const endRotation = startRotation - ((end - offset) * percent);
|
2021-12-16 07:06:53 +00:00
|
|
|
|
2022-01-30 19:28:31 +00:00
|
|
|
color = getGradientColor(color, percent);
|
2021-12-16 07:06:53 +00:00
|
|
|
g.setColor(color);
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
for (let i = startRotation; i > endRotation - size; i -= size) {
|
|
|
|
x = cx + radius * Math.sin(radians(i));
|
|
|
|
y = cy + radius * Math.cos(radians(i));
|
2021-12-17 21:36:34 +00:00
|
|
|
g.fillCircle(x, y, size);
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 15:14:42 +00:00
|
|
|
function writeCircleText(w, content) {
|
|
|
|
if (content == undefined) return;
|
2022-01-29 21:33:43 +00:00
|
|
|
const font = String(content).length > 4 ? circleFontSmall : String(content).length > 3 ? circleFont : circleFontBig;
|
2022-01-28 09:19:29 +00:00
|
|
|
g.setFont(font);
|
2022-01-14 15:14:42 +00:00
|
|
|
|
|
|
|
g.setFontAlign(0, 0);
|
|
|
|
g.setColor(colorFg);
|
|
|
|
g.drawString(content, w, h3);
|
|
|
|
}
|
|
|
|
|
2021-12-16 07:06:53 +00:00
|
|
|
function shortValue(v) {
|
|
|
|
if (isNaN(v)) return '-';
|
|
|
|
if (v <= 999) return v;
|
|
|
|
if (v >= 1000 && v < 10000) {
|
|
|
|
v = Math.floor(v / 100) * 100;
|
|
|
|
return (v / 1000).toFixed(1).replace(/\.0$/, '') + 'k';
|
|
|
|
}
|
|
|
|
if (v >= 10000) {
|
|
|
|
v = Math.floor(v / 1000) * 1000;
|
|
|
|
return (v / 1000).toFixed(1).replace(/\.0$/, '') + 'k';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSteps() {
|
2022-01-17 11:25:56 +00:00
|
|
|
if (Bangle.getHealthStatus) {
|
|
|
|
return Bangle.getHealthStatus("day").steps;
|
|
|
|
}
|
2022-01-05 18:38:18 +00:00
|
|
|
if (WIDGETS && WIDGETS.wpedom !== undefined) {
|
2021-12-16 07:06:53 +00:00
|
|
|
return WIDGETS.wpedom.getSteps();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-07 12:30:09 +00:00
|
|
|
function getWeather() {
|
|
|
|
const jsonWeather = storage.readJSON('weather.json');
|
|
|
|
return jsonWeather && jsonWeather.weather ? jsonWeather.weather : undefined;
|
|
|
|
}
|
|
|
|
|
2022-01-07 08:53:40 +00:00
|
|
|
function enableHRMSensor() {
|
|
|
|
Bangle.setHRMPower(1, "circleclock");
|
|
|
|
if (hrtValue == undefined) {
|
|
|
|
hrtValue = '...';
|
|
|
|
drawHeartRate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 21:20:32 +00:00
|
|
|
let pressureLocked = false;
|
2022-01-28 12:19:15 +00:00
|
|
|
let pressureCache;
|
2022-01-27 21:20:32 +00:00
|
|
|
|
2022-01-27 20:36:25 +00:00
|
|
|
function getPressureValue(type) {
|
2022-01-30 19:46:51 +00:00
|
|
|
return new Promise((resolve) => {
|
2022-01-27 20:36:25 +00:00
|
|
|
if (Bangle.getPressure) {
|
2022-01-27 21:20:32 +00:00
|
|
|
if (!pressureLocked) {
|
|
|
|
pressureLocked = true;
|
2022-01-28 12:19:15 +00:00
|
|
|
if (pressureCache && pressureCache[type]) {
|
|
|
|
resolve(pressureCache[type]);
|
|
|
|
}
|
2022-01-27 21:20:32 +00:00
|
|
|
Bangle.getPressure().then(function(d) {
|
2022-01-28 09:19:00 +00:00
|
|
|
pressureLocked = false;
|
|
|
|
if (d) {
|
2022-01-28 12:19:15 +00:00
|
|
|
pressureCache = d;
|
2022-01-28 09:19:00 +00:00
|
|
|
if (d[type]) {
|
|
|
|
resolve(d[type]);
|
|
|
|
}
|
2022-01-27 21:20:32 +00:00
|
|
|
}
|
2022-01-30 19:46:51 +00:00
|
|
|
}).catch(() => {});
|
2022-01-27 21:20:32 +00:00
|
|
|
} else {
|
2022-01-28 12:19:15 +00:00
|
|
|
if (pressureCache && pressureCache[type]) {
|
|
|
|
resolve(pressureCache[type]);
|
2022-01-28 09:19:00 +00:00
|
|
|
}
|
2022-01-27 20:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-16 07:06:53 +00:00
|
|
|
Bangle.on('lock', function(isLocked) {
|
|
|
|
if (!isLocked) {
|
2022-01-29 12:40:34 +00:00
|
|
|
draw();
|
2022-01-05 12:27:50 +00:00
|
|
|
if (isCircleEnabled("hr")) {
|
2022-01-07 08:53:40 +00:00
|
|
|
enableHRMSensor();
|
2021-12-17 21:36:34 +00:00
|
|
|
}
|
2021-12-16 07:06:53 +00:00
|
|
|
} else {
|
2022-01-07 08:53:40 +00:00
|
|
|
Bangle.setHRMPower(0, "circleclock");
|
2021-12-16 07:06:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2022-01-31 18:16:39 +00:00
|
|
|
let timerHrm;
|
2022-01-07 08:53:40 +00:00
|
|
|
Bangle.on('HRM', function(hrm) {
|
|
|
|
if (isCircleEnabled("hr")) {
|
2022-02-08 10:41:50 +00:00
|
|
|
if (hrm.confidence >= (settings.confidence)) {
|
2022-01-23 10:52:14 +00:00
|
|
|
hrtValue = hrm.bpm;
|
2022-01-31 18:16:39 +00:00
|
|
|
if (Bangle.isLCDOn()) {
|
|
|
|
drawHeartRate();
|
|
|
|
}
|
|
|
|
}
|
2022-02-01 07:54:21 +00:00
|
|
|
// Let us wait before we overwrite "good" HRM values:
|
2022-01-31 18:16:39 +00:00
|
|
|
if (Bangle.isLCDOn()) {
|
|
|
|
if (timerHrm) clearTimeout(timerHrm);
|
|
|
|
timerHrm = setTimeout(() => {
|
|
|
|
hrtValue = '...';
|
2022-01-23 10:52:14 +00:00
|
|
|
drawHeartRate();
|
2022-02-08 10:41:50 +00:00
|
|
|
}, settings.hrmValidity * 1000);
|
2022-01-23 10:52:14 +00:00
|
|
|
}
|
2022-01-07 08:53:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-29 12:40:34 +00:00
|
|
|
Bangle.on('charging', function(charging) {
|
|
|
|
if (isCircleEnabled("battery")) drawBattery();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (isCircleEnabled("hr")) {
|
|
|
|
enableHRMSensor();
|
|
|
|
}
|
|
|
|
|
2022-01-07 09:26:45 +00:00
|
|
|
Bangle.setUI("clock");
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
|
2022-02-08 15:51:49 +00:00
|
|
|
// schedule a draw for the next minute
|
|
|
|
setTimeout(function() {
|
2022-05-18 18:13:57 +00:00
|
|
|
// draw in interval
|
|
|
|
setInterval(draw, settings.updateInterval * 1000);
|
2022-02-08 15:51:49 +00:00
|
|
|
}, 60000 - (Date.now() % 60000));
|
|
|
|
|
2022-01-07 09:26:45 +00:00
|
|
|
draw();
|