mirror of https://github.com/espruino/BangleApps
parent
0a32e40b1a
commit
c6fd71be03
|
@ -29,6 +29,13 @@
|
||||||
"ecmaVersion": 11
|
"ecmaVersion": 11
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
|
"indent": [
|
||||||
|
"error",
|
||||||
|
2,
|
||||||
|
{
|
||||||
|
"SwitchCase": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
"no-case-declarations": "off",
|
"no-case-declarations": "off",
|
||||||
"no-constant-condition": "off",
|
"no-constant-condition": "off",
|
||||||
"no-delete-var": "off",
|
"no-delete-var": "off",
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
(() => {
|
(() => {
|
||||||
|
|
||||||
//Graph module, as long as modules are not added by the app loader
|
//Graph module, as long as modules are not added by the app loader
|
||||||
Modules.addCached("graph",function(){exports.drawAxes=function(b,c,a){function h(a){return e+m*(a-t)/x}function l(a){return f+g-g*(a-n)/u}var k=a.padx||0,d=a.pady||0,t=-k,w=c.length+k-1,n=(void 0!==a.miny?a.miny:a.miny=c.reduce(function(a,b){return Math.min(a,b)},c[0]))-d;c=(void 0!==a.maxy?a.maxy:a.maxy=c.reduce(function(a,b){return Math.max(a,b)},c[0]))+d;a.gridy&&(d=a.gridy,n=d*Math.floor(n/d),c=d*Math.ceil(c/d));var e=a.x||0,f=a.y||0,m=a.width||b.getWidth()-(e+1),g=a.height||b.getHeight()-(f+1);a.axes&&(null!==a.ylabel&&
|
Modules.addCached("graph",function(){exports.drawAxes=function(b,c,a){function h(a){return e+m*(a-t)/x}function l(a){return f+g-g*(a-n)/u}var k=a.padx||0,d=a.pady||0,t=-k,w=c.length+k-1,n=(void 0!==a.miny?a.miny:a.miny=c.reduce(function(a,b){return Math.min(a,b)},c[0]))-d;c=(void 0!==a.maxy?a.maxy:a.maxy=c.reduce(function(a,b){return Math.max(a,b)},c[0]))+d;a.gridy&&(d=a.gridy,n=d*Math.floor(n/d),c=d*Math.ceil(c/d));var e=a.x||0,f=a.y||0,m=a.width||b.getWidth()-(e+1),g=a.height||b.getHeight()-(f+1);a.axes&&(null!==a.ylabel&&
|
||||||
(e+=6,m-=6),null!==a.xlabel&&(g-=6));a.title&&(f+=6,g-=6);a.axes&&(b.drawLine(e,f,e,f+g),b.drawLine(e,f+g,e+m,f+g));a.title&&(b.setFontAlign(0,-1),b.drawString(a.title,e+m/2,f-6));var x=w-t,u=c-n;u||(u=1);if(a.gridx){b.setFontAlign(0,-1,0);var v=a.gridx;for(d=Math.ceil((t+k)/v)*v;d<=w-k;d+=v){var r=h(d),p=a.xlabel?a.xlabel(d):d;b.setPixel(r,f+g-1);var q=b.stringWidth(p)/2;null!==a.xlabel&&r>q&&b.getWidth()>r+q&&b.drawString(p,r,f+g+2)}}if(a.gridy)for(b.setFontAlign(0,0,1),d=n;d<=c;d+=a.gridy)k=l(d),
|
(e+=6,m-=6),null!==a.xlabel&&(g-=6));a.title&&(f+=6,g-=6);a.axes&&(b.drawLine(e,f,e,f+g),b.drawLine(e,f+g,e+m,f+g));a.title&&(b.setFontAlign(0,-1),b.drawString(a.title,e+m/2,f-6));var x=w-t,u=c-n;u||(u=1);if(a.gridx){b.setFontAlign(0,-1,0);var v=a.gridx;for(d=Math.ceil((t+k)/v)*v;d<=w-k;d+=v){var r=h(d),p=a.xlabel?a.xlabel(d):d;b.setPixel(r,f+g-1);var q=b.stringWidth(p)/2;null!==a.xlabel&&r>q&&b.getWidth()>r+q&&b.drawString(p,r,f+g+2)}}if(a.gridy)for(b.setFontAlign(0,0,1),d=n;d<=c;d+=a.gridy)k=l(d),
|
||||||
p=a.ylabel?a.ylabel(d):d,b.setPixel(e+1,k),q=b.stringWidth(p)/2,null!==a.ylabel&&k>q&&b.getHeight()>k+q&&b.drawString(p,e-5,k+1);b.setFontAlign(-1,-1,0);return{x:e,y:f,w:m,h:g,getx:h,gety:l}};exports.drawLine=function(b,c,a){a=a||{};a=exports.drawAxes(b,c,a);var h=!0,l;for(l in c)h?b.moveTo(a.getx(l),a.gety(c[l])):b.lineTo(a.getx(l),a.gety(c[l])),h=!1;return a};exports.drawBar=function(b,c,a){a=a||{};a.padx=1;a=exports.drawAxes(b,c,a);for(var h in c)b.fillRect(a.getx(h-.5)+1,a.gety(c[h]),a.getx(h+
|
p=a.ylabel?a.ylabel(d):d,b.setPixel(e+1,k),q=b.stringWidth(p)/2,null!==a.ylabel&&k>q&&b.getHeight()>k+q&&b.drawString(p,e-5,k+1);b.setFontAlign(-1,-1,0);return{x:e,y:f,w:m,h:g,getx:h,gety:l}};exports.drawLine=function(b,c,a){a=a||{};a=exports.drawAxes(b,c,a);var h=!0,l;for(l in c)h?b.moveTo(a.getx(l),a.gety(c[l])):b.lineTo(a.getx(l),a.gety(c[l])),h=!1;return a};exports.drawBar=function(b,c,a){a=a||{};a.padx=1;a=exports.drawAxes(b,c,a);for(var h in c)b.fillRect(a.getx(h-.5)+1,a.gety(c[h]),a.getx(h+
|
||||||
.5)-1,a.gety(0));return a}});
|
.5)-1,a.gety(0));return a}});
|
||||||
|
|
||||||
const storage = require("Storage");
|
const storage = require("Storage");
|
||||||
const SETTINGS_FILE = 'activepedom.settings.json';
|
const SETTINGS_FILE = 'activepedom.settings.json';
|
||||||
var history = 86400000; // 28800000=8h 43200000=12h //86400000=24h
|
var history = 86400000; // 28800000=8h 43200000=12h //86400000=24h
|
||||||
|
|
||||||
//return setting
|
//return setting
|
||||||
function setting(key) {
|
function setting(key) {
|
||||||
//define default settings
|
//define default settings
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
'cMaxTime' : 1100,
|
'cMaxTime' : 1100,
|
||||||
'cMinTime' : 240,
|
'cMinTime' : 240,
|
||||||
'stepThreshold' : 30,
|
'stepThreshold' : 30,
|
||||||
|
@ -21,13 +21,13 @@ const DEFAULTS = {
|
||||||
'stepSensitivity' : 80,
|
'stepSensitivity' : 80,
|
||||||
'stepGoal' : 10000,
|
'stepGoal' : 10000,
|
||||||
'stepLength' : 75,
|
'stepLength' : 75,
|
||||||
};
|
};
|
||||||
if (!settings) { loadSettings(); }
|
if (!settings) { loadSettings(); }
|
||||||
return (key in settings) ? settings[key] : DEFAULTS[key];
|
return (key in settings) ? settings[key] : DEFAULTS[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Convert ms to time
|
//Convert ms to time
|
||||||
function getTime(t) {
|
function getTime(t) {
|
||||||
date = new Date(t);
|
date = new Date(t);
|
||||||
offset = date.getTimezoneOffset() / 60;
|
offset = date.getTimezoneOffset() / 60;
|
||||||
//var milliseconds = parseInt((t % 1000) / 100),
|
//var milliseconds = parseInt((t % 1000) / 100),
|
||||||
|
@ -39,9 +39,9 @@ function getTime(t) {
|
||||||
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
||||||
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
||||||
return hours + ":" + minutes + ":" + seconds;
|
return hours + ":" + minutes + ":" + seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDate(t) {
|
function getDate(t) {
|
||||||
date = new Date(t*1);
|
date = new Date(t*1);
|
||||||
year = date.getFullYear();
|
year = date.getFullYear();
|
||||||
month = date.getMonth()+1; //month is zero-based
|
month = date.getMonth()+1; //month is zero-based
|
||||||
|
@ -49,10 +49,10 @@ function getDate(t) {
|
||||||
month = (month < 10) ? "0" + month : month;
|
month = (month < 10) ? "0" + month : month;
|
||||||
day = (day < 10) ? "0" + day : day;
|
day = (day < 10) ? "0" + day : day;
|
||||||
return year + "-" + month + "-" + day;
|
return year + "-" + month + "-" + day;
|
||||||
}
|
}
|
||||||
|
|
||||||
//columns: 0=time, 1=stepsCounted, 2=active, 3=stepsTooShort, 4=stepsTooLong, 5=stepsOutsideTime
|
//columns: 0=time, 1=stepsCounted, 2=active, 3=stepsTooShort, 4=stepsTooLong, 5=stepsOutsideTime
|
||||||
function getArrayFromCSV(file, column) {
|
function getArrayFromCSV(file, column) {
|
||||||
i = 0;
|
i = 0;
|
||||||
array = [];
|
array = [];
|
||||||
now = new Date();
|
now = new Date();
|
||||||
|
@ -67,9 +67,9 @@ function getArrayFromCSV(file, column) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawGraph() {
|
function drawGraph() {
|
||||||
//times
|
//times
|
||||||
// actives = getArrayFromCSV(csvFile, 2);
|
// actives = getArrayFromCSV(csvFile, 2);
|
||||||
// shorts = getArrayFromCSV(csvFile, 3);
|
// shorts = getArrayFromCSV(csvFile, 3);
|
||||||
|
@ -115,16 +115,16 @@ function drawGraph() {
|
||||||
allDataFile = undefined;
|
allDataFile = undefined;
|
||||||
csvFile = undefined;
|
csvFile = undefined;
|
||||||
times = undefined;
|
times = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawMenu () {
|
function drawMenu () {
|
||||||
g.clear();
|
g.clear();
|
||||||
g.setFont("6x8", 1);
|
g.setFont("6x8", 1);
|
||||||
g.drawString("BTN1:Timespan | BTN2:Draw", 20, 10);
|
g.drawString("BTN1:Timespan | BTN2:Draw", 20, 10);
|
||||||
g.drawString("Timespan: " + history/1000/60/60 + " hours", 20, 20);
|
g.drawString("Timespan: " + history/1000/60/60 + " hours", 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
setWatch(function() { //BTN1
|
setWatch(function() { //BTN1
|
||||||
switch(history) {
|
switch(history) {
|
||||||
case 3600000 : //1h
|
case 3600000 : //1h
|
||||||
history = 14400000; //4h
|
history = 14400000; //4h
|
||||||
|
@ -137,29 +137,29 @@ setWatch(function() { //BTN1
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
drawMenu();
|
drawMenu();
|
||||||
}, BTN1, {edge:"rising", debounce:50, repeat:true});
|
}, BTN1, {edge:"rising", debounce:50, repeat:true});
|
||||||
|
|
||||||
setWatch(function() { //BTN2
|
setWatch(function() { //BTN2
|
||||||
g.setFont("6x8", 2);
|
g.setFont("6x8", 2);
|
||||||
g.drawString ("Drawing...",30,60);
|
g.drawString ("Drawing...",30,60);
|
||||||
drawGraph();
|
drawGraph();
|
||||||
}, BTN2, {edge:"rising", debounce:50, repeat:true});
|
}, BTN2, {edge:"rising", debounce:50, repeat:true});
|
||||||
|
|
||||||
setWatch(function() { //BTN3
|
setWatch(function() { //BTN3
|
||||||
}, BTN3, {edge:"rising", debounce:50, repeat:true});
|
}, BTN3, {edge:"rising", debounce:50, repeat:true});
|
||||||
|
|
||||||
setWatch(function() { //BTN4
|
setWatch(function() { //BTN4
|
||||||
}, BTN4, {edge:"rising", debounce:50, repeat:true});
|
}, BTN4, {edge:"rising", debounce:50, repeat:true});
|
||||||
|
|
||||||
setWatch(function() { //BTN5
|
setWatch(function() { //BTN5
|
||||||
}, BTN5, {edge:"rising", debounce:50, repeat:true});
|
}, BTN5, {edge:"rising", debounce:50, repeat:true});
|
||||||
|
|
||||||
//load settings
|
//load settings
|
||||||
let settings;
|
let settings;
|
||||||
function loadSettings() {
|
function loadSettings() {
|
||||||
settings = storage.readJSON(SETTINGS_FILE, 1) || {};
|
settings = storage.readJSON(SETTINGS_FILE, 1) || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
drawMenu();
|
drawMenu();
|
||||||
|
|
||||||
})();
|
})();
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
(function () { 'use strict';
|
(function () { 'use strict';
|
||||||
|
|
||||||
// shortcuts for easier to read formulas
|
// shortcuts for easier to read formulas
|
||||||
|
|
||||||
var PI = Math.PI,
|
var PI = Math.PI,
|
||||||
sin = Math.sin,
|
sin = Math.sin,
|
||||||
cos = Math.cos,
|
cos = Math.cos,
|
||||||
tan = Math.tan,
|
tan = Math.tan,
|
||||||
|
@ -17,54 +17,54 @@ var PI = Math.PI,
|
||||||
acos = Math.acos,
|
acos = Math.acos,
|
||||||
rad = PI / 180;
|
rad = PI / 180;
|
||||||
|
|
||||||
// sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas
|
// sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas
|
||||||
|
|
||||||
|
|
||||||
// date/time constants and conversions
|
// date/time constants and conversions
|
||||||
|
|
||||||
var dayMs = 1000 * 60 * 60 * 24,
|
var dayMs = 1000 * 60 * 60 * 24,
|
||||||
J1970 = 2440588,
|
J1970 = 2440588,
|
||||||
J2000 = 2451545;
|
J2000 = 2451545;
|
||||||
|
|
||||||
function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
|
function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
|
||||||
function fromJulian(j) { return (j + 0.5 - J1970) * dayMs; }
|
function fromJulian(j) { return (j + 0.5 - J1970) * dayMs; }
|
||||||
function toDays(date) { return toJulian(date) - J2000; }
|
function toDays(date) { return toJulian(date) - J2000; }
|
||||||
|
|
||||||
|
|
||||||
// general calculations for position
|
// general calculations for position
|
||||||
|
|
||||||
var e = rad * 23.4397; // obliquity of the Earth
|
var e = rad * 23.4397; // obliquity of the Earth
|
||||||
|
|
||||||
function rightAscension(l, b) { return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l)); }
|
function rightAscension(l, b) { return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l)); }
|
||||||
function declination(l, b) { return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)); }
|
function declination(l, b) { return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)); }
|
||||||
|
|
||||||
function azimuth(H, phi, dec) { return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)); }
|
function azimuth(H, phi, dec) { return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)); }
|
||||||
function altitude(H, phi, dec) { return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)); }
|
function altitude(H, phi, dec) { return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)); }
|
||||||
|
|
||||||
function siderealTime(d, lw) { return rad * (280.16 + 360.9856235 * d) - lw; }
|
function siderealTime(d, lw) { return rad * (280.16 + 360.9856235 * d) - lw; }
|
||||||
|
|
||||||
function astroRefraction(h) {
|
function astroRefraction(h) {
|
||||||
if (h < 0) // the following formula works for positive altitudes only.
|
if (h < 0) // the following formula works for positive altitudes only.
|
||||||
h = 0; // if h = -0.08901179 a div/0 would occur.
|
h = 0; // if h = -0.08901179 a div/0 would occur.
|
||||||
|
|
||||||
// formula 16.4 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
|
// formula 16.4 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
|
||||||
// 1.02 / tan(h + 10.26 / (h + 5.10)) h in degrees, result in arc minutes -> converted to rad:
|
// 1.02 / tan(h + 10.26 / (h + 5.10)) h in degrees, result in arc minutes -> converted to rad:
|
||||||
return 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179));
|
return 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179));
|
||||||
}
|
}
|
||||||
|
|
||||||
// general sun calculations
|
// general sun calculations
|
||||||
|
|
||||||
function solarMeanAnomaly(d) { return rad * (357.5291 + 0.98560028 * d); }
|
function solarMeanAnomaly(d) { return rad * (357.5291 + 0.98560028 * d); }
|
||||||
|
|
||||||
function eclipticLongitude(M) {
|
function eclipticLongitude(M) {
|
||||||
|
|
||||||
var C = rad * (1.9148 * sin(M) + 0.02 * sin(2 * M) + 0.0003 * sin(3 * M)), // equation of center
|
var C = rad * (1.9148 * sin(M) + 0.02 * sin(2 * M) + 0.0003 * sin(3 * M)), // equation of center
|
||||||
P = rad * 102.9372; // perihelion of the Earth
|
P = rad * 102.9372; // perihelion of the Earth
|
||||||
|
|
||||||
return M + C + P + PI;
|
return M + C + P + PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sunCoords(d) {
|
function sunCoords(d) {
|
||||||
|
|
||||||
var M = solarMeanAnomaly(d),
|
var M = solarMeanAnomaly(d),
|
||||||
L = eclipticLongitude(M);
|
L = eclipticLongitude(M);
|
||||||
|
@ -73,15 +73,15 @@ function sunCoords(d) {
|
||||||
dec: declination(L, 0),
|
dec: declination(L, 0),
|
||||||
ra: rightAscension(L, 0)
|
ra: rightAscension(L, 0)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var SunCalc = {};
|
var SunCalc = {};
|
||||||
|
|
||||||
|
|
||||||
// calculates sun position for a given date and latitude/longitude
|
// calculates sun position for a given date and latitude/longitude
|
||||||
|
|
||||||
SunCalc.getPosition = function (date, lat, lng) {
|
SunCalc.getPosition = function (date, lat, lng) {
|
||||||
|
|
||||||
var lw = rad * -lng,
|
var lw = rad * -lng,
|
||||||
phi = rad * lat,
|
phi = rad * lat,
|
||||||
|
@ -94,52 +94,52 @@ SunCalc.getPosition = function (date, lat, lng) {
|
||||||
azimuth: azimuth(H, phi, c.dec),
|
azimuth: azimuth(H, phi, c.dec),
|
||||||
altitude: altitude(H, phi, c.dec)
|
altitude: altitude(H, phi, c.dec)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// sun times configuration (angle, morning name, evening name)
|
// sun times configuration (angle, morning name, evening name)
|
||||||
|
|
||||||
var times = SunCalc.times = [
|
var times = SunCalc.times = [
|
||||||
[-0.833, 'sunrise', 'sunset' ],
|
[-0.833, 'sunrise', 'sunset' ],
|
||||||
[ -0.3, 'sunriseEnd', 'sunsetStart' ],
|
[ -0.3, 'sunriseEnd', 'sunsetStart' ],
|
||||||
[ -6, 'dawn', 'dusk' ],
|
[ -6, 'dawn', 'dusk' ],
|
||||||
[ -12, 'nauticalDawn', 'nauticalDusk'],
|
[ -12, 'nauticalDawn', 'nauticalDusk'],
|
||||||
[ -18, 'nightEnd', 'night' ],
|
[ -18, 'nightEnd', 'night' ],
|
||||||
[ 6, 'goldenHourEnd', 'goldenHour' ]
|
[ 6, 'goldenHourEnd', 'goldenHour' ]
|
||||||
];
|
];
|
||||||
|
|
||||||
// adds a custom time to the times config
|
// adds a custom time to the times config
|
||||||
|
|
||||||
SunCalc.addTime = function (angle, riseName, setName) {
|
SunCalc.addTime = function (angle, riseName, setName) {
|
||||||
times.push([angle, riseName, setName]);
|
times.push([angle, riseName, setName]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// calculations for sun times
|
// calculations for sun times
|
||||||
|
|
||||||
var J0 = 0.0009;
|
var J0 = 0.0009;
|
||||||
|
|
||||||
function julianCycle(d, lw) { return Math.round(d - J0 - lw / (2 * PI)); }
|
function julianCycle(d, lw) { return Math.round(d - J0 - lw / (2 * PI)); }
|
||||||
|
|
||||||
function approxTransit(Ht, lw, n) { return J0 + (Ht + lw) / (2 * PI) + n; }
|
function approxTransit(Ht, lw, n) { return J0 + (Ht + lw) / (2 * PI) + n; }
|
||||||
function solarTransitJ(ds, M, L) { return J2000 + ds + 0.0053 * sin(M) - 0.0069 * sin(2 * L); }
|
function solarTransitJ(ds, M, L) { return J2000 + ds + 0.0053 * sin(M) - 0.0069 * sin(2 * L); }
|
||||||
|
|
||||||
function hourAngle(h, phi, d) { return acos((sin(h) - sin(phi) * sin(d)) / (cos(phi) * cos(d))); }
|
function hourAngle(h, phi, d) { return acos((sin(h) - sin(phi) * sin(d)) / (cos(phi) * cos(d))); }
|
||||||
function observerAngle(height) { return -2.076 * Math.sqrt(height) / 60; }
|
function observerAngle(height) { return -2.076 * Math.sqrt(height) / 60; }
|
||||||
|
|
||||||
// returns set time for the given sun altitude
|
// returns set time for the given sun altitude
|
||||||
function getSetJ(h, lw, phi, dec, n, M, L) {
|
function getSetJ(h, lw, phi, dec, n, M, L) {
|
||||||
|
|
||||||
var w = hourAngle(h, phi, dec),
|
var w = hourAngle(h, phi, dec),
|
||||||
a = approxTransit(w, lw, n);
|
a = approxTransit(w, lw, n);
|
||||||
return solarTransitJ(a, M, L);
|
return solarTransitJ(a, M, L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// calculates sun times for a given date, latitude/longitude, and, optionally,
|
// calculates sun times for a given date, latitude/longitude, and, optionally,
|
||||||
// the observer height (in meters) relative to the horizon
|
// the observer height (in meters) relative to the horizon
|
||||||
|
|
||||||
SunCalc.getTimes = function (date, lat, lng, height) {
|
SunCalc.getTimes = function (date, lat, lng, height) {
|
||||||
|
|
||||||
height = height || 0;
|
height = height || 0;
|
||||||
|
|
||||||
|
@ -178,12 +178,12 @@ SunCalc.getTimes = function (date, lat, lng, height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// moon calculations, based on http://aa.quae.nl/en/reken/hemelpositie.html formulas
|
// moon calculations, based on http://aa.quae.nl/en/reken/hemelpositie.html formulas
|
||||||
|
|
||||||
function moonCoords(d) { // geocentric ecliptic coordinates of the moon
|
function moonCoords(d) { // geocentric ecliptic coordinates of the moon
|
||||||
|
|
||||||
var L = rad * (218.316 + 13.176396 * d), // ecliptic longitude
|
var L = rad * (218.316 + 13.176396 * d), // ecliptic longitude
|
||||||
M = rad * (134.963 + 13.064993 * d), // mean anomaly
|
M = rad * (134.963 + 13.064993 * d), // mean anomaly
|
||||||
|
@ -198,9 +198,9 @@ function moonCoords(d) { // geocentric ecliptic coordinates of the moon
|
||||||
dec: declination(l, b),
|
dec: declination(l, b),
|
||||||
dist: dt
|
dist: dt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
SunCalc.getMoonPosition = function (date, lat, lng) {
|
SunCalc.getMoonPosition = function (date, lat, lng) {
|
||||||
|
|
||||||
var lw = rad * -lng,
|
var lw = rad * -lng,
|
||||||
phi = rad * lat,
|
phi = rad * lat,
|
||||||
|
@ -220,16 +220,16 @@ SunCalc.getMoonPosition = function (date, lat, lng) {
|
||||||
distance: c.dist,
|
distance: c.dist,
|
||||||
parallacticAngle: pa
|
parallacticAngle: pa
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// calculations for illumination parameters of the moon,
|
// calculations for illumination parameters of the moon,
|
||||||
// based on http://idlastro.gsfc.nasa.gov/ftp/pro/astro/mphase.pro formulas and
|
// based on http://idlastro.gsfc.nasa.gov/ftp/pro/astro/mphase.pro formulas and
|
||||||
// Chapter 48 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
|
// Chapter 48 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
|
||||||
|
|
||||||
// Function updated from gist: https://gist.github.com/endel/dfe6bb2fbe679781948c
|
// Function updated from gist: https://gist.github.com/endel/dfe6bb2fbe679781948c
|
||||||
|
|
||||||
SunCalc.getMoonIllumination = function (date) {
|
SunCalc.getMoonIllumination = function (date) {
|
||||||
let month = date.getMonth();
|
let month = date.getMonth();
|
||||||
let year = date.getFullYear();
|
let year = date.getFullYear();
|
||||||
let day = date.getDate();
|
let day = date.getDate();
|
||||||
|
@ -256,16 +256,16 @@ SunCalc.getMoonIllumination = function (date) {
|
||||||
if (b >= 8) b = 0; // 0 and 8 are the same so turn 8 into 0
|
if (b >= 8) b = 0; // 0 and 8 are the same so turn 8 into 0
|
||||||
|
|
||||||
return {phase: b};
|
return {phase: b};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function hoursLater(date, h) {
|
function hoursLater(date, h) {
|
||||||
return new Date(date.valueOf() + h * dayMs / 24);
|
return new Date(date.valueOf() + h * dayMs / 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculations for moon rise/set times are based on http://www.stargazing.net/kepler/moonrise.html article
|
// calculations for moon rise/set times are based on http://www.stargazing.net/kepler/moonrise.html article
|
||||||
|
|
||||||
SunCalc.getMoonTimes = function (date, lat, lng, inUTC) {
|
SunCalc.getMoonTimes = function (date, lat, lng, inUTC) {
|
||||||
var t = date;
|
var t = date;
|
||||||
if (inUTC) t.setUTCHours(0, 0, 0, 0);
|
if (inUTC) t.setUTCHours(0, 0, 0, 0);
|
||||||
else t.setHours(0, 0, 0, 0);
|
else t.setHours(0, 0, 0, 0);
|
||||||
|
@ -317,12 +317,12 @@ SunCalc.getMoonTimes = function (date, lat, lng, inUTC) {
|
||||||
if (!rise && !set) result[ye > 0 ? 'alwaysUp' : 'alwaysDown'] = true;
|
if (!rise && !set) result[ye > 0 ? 'alwaysUp' : 'alwaysDown'] = true;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// export as Node module / AMD module / browser variable
|
// export as Node module / AMD module / browser variable
|
||||||
if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = SunCalc;
|
if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = SunCalc;
|
||||||
else if (typeof define === 'function' && define.amd) define(SunCalc);
|
else if (typeof define === 'function' && define.amd) define(SunCalc);
|
||||||
else global.SunCalc = SunCalc;
|
else global.SunCalc = SunCalc;
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -52,7 +52,7 @@ Bangle.on('lcdPower', (on) => {
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
// call your app function here
|
// call your app function here
|
||||||
drawBerlinClock();
|
drawBerlinClock();
|
||||||
}});
|
}});
|
||||||
|
|
||||||
// refesh every 15 sec
|
// refesh every 15 sec
|
||||||
setInterval(drawBerlinClock, 15E3);
|
setInterval(drawBerlinClock, 15E3);
|
||||||
|
|
|
@ -8,11 +8,11 @@ const Spades = { width : 48, height : 48, bpp : 1,
|
||||||
|
|
||||||
const Hearts = { width : 48, height : 48, bpp : 4,
|
const Hearts = { width : 48, height : 48, bpp : 4,
|
||||||
buffer : require("heatshrink").decompress(atob("ADlVqtQBQ8FBYIKIrnMAAINGqoKC4okGCwYAB4AKDhgKE4oWKAAILDBQwYEBYwwDFwojFgoLHEgQ6H5hhCBZAkCBRAjLEgI6IC4YLIC5Y7BBZXBjgjVABYX/C8CnKABbXLABTvMC8sMC6fAC4KQURwIABRypgULwRgULwRIUCwhIRIwiRSRoZITCwx5POoowRCxAwNFxIwNCxQwLFxYwLCxgwJFxowJCxwwHFx4wHCyAwFFyIwFCyQwDFycAgoXBqAXTgFc4oWUJAJGUJARGVAEo"))
|
buffer : require("heatshrink").decompress(atob("ADlVqtQBQ8FBYIKIrnMAAINGqoKC4okGCwYAB4AKDhgKE4oWKAAILDBQwYEBYwwDFwojFgoLHEgQ6H5hhCBZAkCBRAjLEgI6IC4YLIC5Y7BBZXBjgjVABYX/C8CnKABbXLABTvMC8sMC6fAC4KQURwIABRypgULwRgULwRIUCwhIRIwiRSRoZITCwx5POoowRCxAwNFxIwNCxQwLFxYwLCxgwJFxowJCxwwHFx4wHCyAwFFyIwFCyQwDFycAgoXBqAXTgFc4oWUJAJGUJARGVAEo"))
|
||||||
};
|
};
|
||||||
|
|
||||||
const Diamonds = { width : 48, height : 48, bpp : 4,
|
const Diamonds = { width : 48, height : 48, bpp : 4,
|
||||||
buffer : require("heatshrink").decompress(atob("AHUFC60M4AXV5nFIyvM5hGVC4JIUCwJIUIwRIUIwRIUCwZISIwgABqBGUJCQWFPKBGGJCFcC455OCw4wOOox5QIxB5NOpBIOFxZ5LCxYwKOpQwMIxh5KOxipLL6xgNR5QwMX5TvXPJZ1JJBpGLPJR1LJBZGNPJIWOJA5GOPJB1NJBIWQPIpGRJApGRPIoWSJAa8PJA5GTJAYWUJAJGVAAJGVAHo="))
|
buffer : require("heatshrink").decompress(atob("AHUFC60M4AXV5nFIyvM5hGVC4JIUCwJIUIwRIUIwRIUCwZISIwgABqBGUJCQWFPKBGGJCFcC455OCw4wOOox5QIxB5NOpBIOFxZ5LCxYwKOpQwMIxh5KOxipLL6xgNR5QwMX5TvXPJZ1JJBpGLPJR1LJBZGNPJIWOJA5GOPJB1NJBIWQPIpGRJApGRPIoWSJAa8PJA5GTJAYWUJAJGVAAJGVAHo="))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var deck = [];
|
var deck = [];
|
||||||
|
|
|
@ -7,12 +7,12 @@ setWatch(x=>{
|
||||||
},BTN1,{repeat:true});
|
},BTN1,{repeat:true});
|
||||||
|
|
||||||
function updateAdvertising() {
|
function updateAdvertising() {
|
||||||
try {
|
try {
|
||||||
NRF.setAdvertising({},{
|
NRF.setAdvertising({},{
|
||||||
manufacturer: 0x0590,
|
manufacturer: 0x0590,
|
||||||
manufacturerData: new Uint8Array([mycounter>>8,mycounter&255])
|
manufacturerData: new Uint8Array([mycounter>>8,mycounter&255])
|
||||||
});
|
});
|
||||||
} catch(e){}
|
} catch(e){}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawPlayers() {
|
function drawPlayers() {
|
||||||
|
|
|
@ -26,31 +26,31 @@ const ySpace=[y0, y1, y2];
|
||||||
const pixels = [[[0,0], // digit on/off pixels
|
const pixels = [[[0,0], // digit on/off pixels
|
||||||
[1,1],
|
[1,1],
|
||||||
[1,1]],
|
[1,1]],
|
||||||
[[0,1], // digit 1
|
[[0,1], // digit 1
|
||||||
[0,1],
|
[0,1],
|
||||||
[0,1]],
|
[0,1]],
|
||||||
[[0,1],
|
[[0,1],
|
||||||
[1,0],
|
[1,0],
|
||||||
[1,1]],
|
[1,1]],
|
||||||
[[1,1],
|
[[1,1],
|
||||||
[0,1],
|
[0,1],
|
||||||
[1,1]],
|
[1,1]],
|
||||||
[[1,0],
|
[[1,0],
|
||||||
[1,1],
|
[1,1],
|
||||||
[0,1]],
|
[0,1]],
|
||||||
[[1,1],
|
[[1,1],
|
||||||
[1,0],
|
[1,0],
|
||||||
[0,1]],
|
[0,1]],
|
||||||
[[1,0],
|
[[1,0],
|
||||||
[1,1],
|
[1,1],
|
||||||
[1,1]],
|
[1,1]],
|
||||||
[[1,1],
|
[[1,1],
|
||||||
[0,1],
|
[0,1],
|
||||||
[0,1]],
|
[0,1]],
|
||||||
[[1,1],
|
[[1,1],
|
||||||
[1,1],
|
[1,1],
|
||||||
[1,1]],
|
[1,1]],
|
||||||
[[1,1],
|
[[1,1],
|
||||||
[1,1],
|
[1,1],
|
||||||
[0,1]]];
|
[0,1]]];
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
require("heatshrink").decompress(atob("/4AYv4CB+YdZABPvEkYA/AGv3EkfPAQP+DrI"))
|
require("heatshrink").decompress(atob("/4AYv4CB+YdZABPvEkYA/AGv3EkfPAQP+DrI"))
|
||||||
|
|
|
@ -5,8 +5,8 @@ function redraw() {
|
||||||
g.drawImage(img, 120-96, 120-96, {scale:2});
|
g.drawImage(img, 120-96, 120-96, {scale:2});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Code for button (Puck.js)
|
// Code for button (Puck.js)
|
||||||
var busy = false;
|
var busy = false;
|
||||||
|
|
||||||
var lastTry = getTime();
|
var lastTry = getTime();
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ const drawClockFace = () => {
|
||||||
g.setColor(0.1,0.7,0);
|
g.setColor(0.1,0.7,0);
|
||||||
}
|
}
|
||||||
g.fillCircle(centerX,centerY,radius*0.98);
|
g.fillCircle(centerX,centerY,radius*0.98);
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawAll = () => {
|
const drawAll = () => {
|
||||||
currentDate = new Date();
|
currentDate = new Date();
|
||||||
|
|
|
@ -30,4 +30,4 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
E.showMenu(appMenu)
|
E.showMenu(appMenu)
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,13 +16,13 @@ setWatch(x=>{
|
||||||
},BTN1,{repeat:true});
|
},BTN1,{repeat:true});
|
||||||
|
|
||||||
function updateAdvertising() {
|
function updateAdvertising() {
|
||||||
try {
|
try {
|
||||||
NRF.setAdvertising({},{
|
NRF.setAdvertising({},{
|
||||||
manufacturer: 0x0590,
|
manufacturer: 0x0590,
|
||||||
manufacturerData: new Uint8Array([mycounter>>8,mycounter&255]),
|
manufacturerData: new Uint8Array([mycounter>>8,mycounter&255]),
|
||||||
interval: 60
|
interval: 60
|
||||||
});
|
});
|
||||||
} catch(e){}
|
} catch(e){}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawPlayers() {
|
function drawPlayers() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ E.showMessage("Jingle Bells");
|
||||||
var eventEmitter = new Object();
|
var eventEmitter = new Object();
|
||||||
|
|
||||||
function strofa(notes, times, current, next){
|
function strofa(notes, times, current, next){
|
||||||
eventEmitter.on(current, () => {
|
eventEmitter.on(current, () => {
|
||||||
if (notes.length == 0) {
|
if (notes.length == 0) {
|
||||||
eventEmitter.emit(next);
|
eventEmitter.emit(next);
|
||||||
return;
|
return;
|
||||||
|
@ -15,7 +15,7 @@ eventEmitter.on(current, () => {
|
||||||
eventEmitter.emit(current);
|
eventEmitter.emit(current);
|
||||||
}, time);
|
}, time);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var one = [2637, 2637, 2637, 2637, 2637, 2637, 2637, 3135, 2093, 2349, 2637];
|
var one = [2637, 2637, 2637, 2637, 2637, 2637, 2637, 3135, 2093, 2349, 2637];
|
||||||
|
|
|
@ -16,98 +16,98 @@ var timeInterval;
|
||||||
n is the amount (0..1)
|
n is the amount (0..1)
|
||||||
maxFive is true is this digit only counts 0..5 */
|
maxFive is true is this digit only counts 0..5 */
|
||||||
const DIGITS = {
|
const DIGITS = {
|
||||||
" ":n=>[],
|
" ":n=>[],
|
||||||
"0":n=>[
|
"0":n=>[
|
||||||
[n,0,1,0],
|
[n,0,1,0],
|
||||||
[1,0,1,1],
|
[1,0,1,1],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[n,2,1,2],
|
[n,2,1,2],
|
||||||
[n,1,n,2],
|
[n,1,n,2],
|
||||||
[n,0,n,1]],
|
[n,0,n,1]],
|
||||||
"1":n=>[
|
"1":n=>[
|
||||||
[1-n,0,1,0],
|
[1-n,0,1,0],
|
||||||
[1,0,1,1],
|
[1,0,1,1],
|
||||||
[1-n,1,1,1],
|
[1-n,1,1,1],
|
||||||
[1-n,1,1-n,2],
|
[1-n,1,1-n,2],
|
||||||
[1-n,2,1,2]],
|
[1-n,2,1,2]],
|
||||||
"2":n=>[
|
"2":n=>[
|
||||||
[0,0,1,0],
|
[0,0,1,0],
|
||||||
[1,0,1,1],
|
[1,0,1,1],
|
||||||
[0,1,1,1],
|
[0,1,1,1],
|
||||||
[0,1+n,0,2],
|
[0,1+n,0,2],
|
||||||
[1,2-n,1,2],
|
[1,2-n,1,2],
|
||||||
[0,2,1,2]],
|
[0,2,1,2]],
|
||||||
"3":n=>[
|
"3":n=>[
|
||||||
[0,0,1-n,0],
|
[0,0,1-n,0],
|
||||||
[0,0,0,n],
|
[0,0,0,n],
|
||||||
[1,0,1,1],
|
[1,0,1,1],
|
||||||
[0,1,1,1],
|
[0,1,1,1],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[n,2,1,2]],
|
[n,2,1,2]],
|
||||||
"4":n=>[
|
"4":n=>[
|
||||||
[0,0,0,1],
|
[0,0,0,1],
|
||||||
[1,0,1-n,0],
|
[1,0,1-n,0],
|
||||||
[1,0,1,1-n],
|
[1,0,1,1-n],
|
||||||
[0,1,1,1],
|
[0,1,1,1],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[1-n,2,1,2]],
|
[1-n,2,1,2]],
|
||||||
"5to0": n=>[ // 5 -> 0
|
"5to0": n=>[ // 5 -> 0
|
||||||
[0,0,0,1],
|
[0,0,0,1],
|
||||||
[0,0,1,0],
|
[0,0,1,0],
|
||||||
[n,1,1,1],
|
[n,1,1,1],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[0,2,1,2],
|
[0,2,1,2],
|
||||||
[0,2,0,2],
|
[0,2,0,2],
|
||||||
[1,1-n,1,1],
|
[1,1-n,1,1],
|
||||||
[0,1,0,1+n]],
|
[0,1,0,1+n]],
|
||||||
"5to6": n=>[ // 5 -> 6
|
"5to6": n=>[ // 5 -> 6
|
||||||
[0,0,0,1],
|
[0,0,0,1],
|
||||||
[0,0,1,0],
|
[0,0,1,0],
|
||||||
[0,1,1,1],
|
[0,1,1,1],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[0,2,1,2],
|
[0,2,1,2],
|
||||||
[0,2-n,0,2]],
|
[0,2-n,0,2]],
|
||||||
"6":n=>[
|
"6":n=>[
|
||||||
[0,0,0,1-n],
|
[0,0,0,1-n],
|
||||||
[0,0,1,0],
|
[0,0,1,0],
|
||||||
[n,1,1,1],
|
[n,1,1,1],
|
||||||
[1,1-n,1,1],
|
[1,1-n,1,1],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[n,2,1,2],
|
[n,2,1,2],
|
||||||
[0,1-n,0,2-2*n]],
|
[0,1-n,0,2-2*n]],
|
||||||
"7":n=>[
|
"7":n=>[
|
||||||
[0,0,0,n],
|
[0,0,0,n],
|
||||||
[0,0,1,0],
|
[0,0,1,0],
|
||||||
[1,0,1,1],
|
[1,0,1,1],
|
||||||
[1-n,1,1,1],
|
[1-n,1,1,1],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[1-n,2,1,2],
|
[1-n,2,1,2],
|
||||||
[1-n,1,1-n,2]],
|
[1-n,1,1-n,2]],
|
||||||
"8":n=>[
|
"8":n=>[
|
||||||
[0,0,0,1],
|
[0,0,0,1],
|
||||||
[0,0,1,0],
|
[0,0,1,0],
|
||||||
[1,0,1,1],
|
[1,0,1,1],
|
||||||
[0,1,1,1],
|
[0,1,1,1],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[0,2,1,2],
|
[0,2,1,2],
|
||||||
[0,1,0,2-n]],
|
[0,1,0,2-n]],
|
||||||
"9":n=>[
|
"9":n=>[
|
||||||
[0,0,0,1],
|
[0,0,0,1],
|
||||||
[0,0,1,0],
|
[0,0,1,0],
|
||||||
[1,0,1,1],
|
[1,0,1,1],
|
||||||
[0,1,1-n,1],
|
[0,1,1-n,1],
|
||||||
[0,1,0,1+n],
|
[0,1,0,1+n],
|
||||||
[1,1,1,2],
|
[1,1,1,2],
|
||||||
[0,2,1,2]],
|
[0,2,1,2]],
|
||||||
":":n=>[
|
":":n=>[
|
||||||
[0.4,0.4,0.6,0.4],
|
[0.4,0.4,0.6,0.4],
|
||||||
[0.6,0.4,0.6,0.6],
|
[0.6,0.4,0.6,0.6],
|
||||||
[0.6,0.6,0.4,0.6],
|
[0.6,0.6,0.4,0.6],
|
||||||
[0.4,0.4,0.4,0.6],
|
[0.4,0.4,0.4,0.6],
|
||||||
[0.4,1.4,0.6,1.4],
|
[0.4,1.4,0.6,1.4],
|
||||||
[0.6,1.4,0.6,1.6],
|
[0.6,1.4,0.6,1.6],
|
||||||
[0.6,1.6,0.4,1.6],
|
[0.6,1.6,0.4,1.6],
|
||||||
[0.4,1.4,0.4,1.6]]
|
[0.4,1.4,0.4,1.6]]
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Draw a transition between lastText and thisText.
|
/* Draw a transition between lastText and thisText.
|
||||||
|
|
|
@ -243,7 +243,7 @@ function drawMoonPhase(offset, x, y){
|
||||||
if (getMPhaseSim(offset) == "waning-gibbous") {g.drawImage(getImg("WaningGibbousNorth"), x, y);}
|
if (getMPhaseSim(offset) == "waning-gibbous") {g.drawImage(getImg("WaningGibbousNorth"), x, y);}
|
||||||
if (getMPhaseSim(offset) == "last-quarter") {g.drawImage(getImg("LastQuarterNorth"), x, y);}
|
if (getMPhaseSim(offset) == "last-quarter") {g.drawImage(getImg("LastQuarterNorth"), x, y);}
|
||||||
if (getMPhaseSim(offset) == "waning-crescent") {g.drawImage(getImg("WaningCrescentNorth"), x, y);}
|
if (getMPhaseSim(offset) == "waning-crescent") {g.drawImage(getImg("WaningCrescentNorth"), x, y);}
|
||||||
}
|
}
|
||||||
else { //Southern hemisphere
|
else { //Southern hemisphere
|
||||||
if (getMPhaseSim(offset) == "new") {g.drawImage(getImg("NewMoon"), x, y);}
|
if (getMPhaseSim(offset) == "new") {g.drawImage(getImg("NewMoon"), x, y);}
|
||||||
if (getMPhaseSim(offset) == "waxing-crescent") {g.drawImage(getImg("WaxingCrescentSouth"), x, y);}
|
if (getMPhaseSim(offset) == "waxing-crescent") {g.drawImage(getImg("WaxingCrescentSouth"), x, y);}
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
//manage when things should be enabled and not
|
//manage when things should be enabled and not
|
||||||
Bangle.on('lcdPower', function (on) {
|
Bangle.on('lcdPower', function (on) {
|
||||||
if (on) {
|
if (on) {
|
||||||
Bangle.setHRMPower(1);
|
Bangle.setHRMPower(1);
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
(function() {
|
(function() {
|
||||||
var clickTimes = [];
|
var clickTimes = [];
|
||||||
var clickPattern = "";
|
var clickPattern = "";
|
||||||
var TAPS = 4; // number of taps
|
var TAPS = 4; // number of taps
|
||||||
var PERIOD = 1; // seconds
|
var PERIOD = 1; // seconds
|
||||||
|
|
||||||
// we don't actually create/draw a widget here at all...
|
// we don't actually create/draw a widget here at all...
|
||||||
Bangle.on("lcdPower",function(on) {
|
Bangle.on("lcdPower",function(on) {
|
||||||
// First click (that turns LCD on) isn't given to
|
// First click (that turns LCD on) isn't given to
|
||||||
// setWatch, so handle it here
|
// setWatch, so handle it here
|
||||||
if (!on) return;
|
if (!on) return;
|
||||||
clickTimes=[getTime()];
|
clickTimes=[getTime()];
|
||||||
clickPattern="x";
|
clickPattern="x";
|
||||||
});
|
});
|
||||||
function tap(e,c) {
|
function tap(e,c) {
|
||||||
clickPattern = clickPattern.substr(-3)+c;
|
clickPattern = clickPattern.substr(-3)+c;
|
||||||
while (clickTimes.length>=TAPS) clickTimes.shift();
|
while (clickTimes.length>=TAPS) clickTimes.shift();
|
||||||
clickTimes.push(e.time);
|
clickTimes.push(e.time);
|
||||||
|
@ -20,7 +20,7 @@ function tap(e,c) {
|
||||||
if (clickPeriod<PERIOD && clickPattern.match(/.313/)) {
|
if (clickPeriod<PERIOD && clickPattern.match(/.313/)) {
|
||||||
load("torch.app.js");
|
load("torch.app.js");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setWatch(function(e) { tap(e,"1"); }, BTN1, {repeat:true, edge:"rising"});
|
setWatch(function(e) { tap(e,"1"); }, BTN1, {repeat:true, edge:"rising"});
|
||||||
setWatch(function(e) { tap(e,"3"); }, BTN3, {repeat:true, edge:"rising"});
|
setWatch(function(e) { tap(e,"3"); }, BTN3, {repeat:true, edge:"rising"});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
(function(){
|
(function(){
|
||||||
var CHARGING = 0x07E0;
|
var CHARGING = 0x07E0;
|
||||||
|
|
||||||
function setWidth() {
|
function setWidth() {
|
||||||
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
|
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
|
||||||
}
|
}
|
||||||
function draw() {
|
function draw() {
|
||||||
var s = 39;
|
var s = 39;
|
||||||
var x = this.x, y = this.y;
|
var x = this.x, y = this.y;
|
||||||
if (Bangle.isCharging()) {
|
if (Bangle.isCharging()) {
|
||||||
|
@ -17,15 +17,15 @@ function draw() {
|
||||||
g.fillRect(x+s-3,y+10,x+s,y+14);
|
g.fillRect(x+s-3,y+10,x+s,y+14);
|
||||||
g.setColor(CHARGING).fillRect(x+4,y+6,x+4+E.getBattery()*(s-12)/100,y+17);
|
g.setColor(CHARGING).fillRect(x+4,y+6,x+4+E.getBattery()*(s-12)/100,y+17);
|
||||||
g.setColor(-1);
|
g.setColor(-1);
|
||||||
}
|
}
|
||||||
Bangle.on('charging',function(charging) {
|
Bangle.on('charging',function(charging) {
|
||||||
if(charging) Bangle.buzz();
|
if(charging) Bangle.buzz();
|
||||||
setWidth();
|
setWidth();
|
||||||
Bangle.drawWidgets(); // relayout widgets
|
Bangle.drawWidgets(); // relayout widgets
|
||||||
g.flip();
|
g.flip();
|
||||||
});
|
});
|
||||||
var batteryInterval;
|
var batteryInterval;
|
||||||
Bangle.on('lcdPower', function(on) {
|
Bangle.on('lcdPower', function(on) {
|
||||||
if (on) {
|
if (on) {
|
||||||
WIDGETS["bat"].draw();
|
WIDGETS["bat"].draw();
|
||||||
// refresh once a minute if LCD on
|
// refresh once a minute if LCD on
|
||||||
|
@ -37,7 +37,7 @@ Bangle.on('lcdPower', function(on) {
|
||||||
batteryInterval = undefined;
|
batteryInterval = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
WIDGETS["bat"]={area:"tr",width:40,draw:draw};
|
WIDGETS["bat"]={area:"tr",width:40,draw:draw};
|
||||||
setWidth();
|
setWidth();
|
||||||
})()
|
})()
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
(function(){
|
(function(){
|
||||||
const COLORS = {
|
const COLORS = {
|
||||||
'white': -1,
|
'white': -1,
|
||||||
'charging': 0x07E0, // "Green"
|
'charging': 0x07E0, // "Green"
|
||||||
'high': 0x05E0, // slightly darker green
|
'high': 0x05E0, // slightly darker green
|
||||||
'ok': 0xFD20, // "Orange"
|
'ok': 0xFD20, // "Orange"
|
||||||
'low':0xF800, // "Red"
|
'low':0xF800, // "Red"
|
||||||
}
|
}
|
||||||
const SETTINGS_FILE = 'widbatpc.json'
|
const SETTINGS_FILE = 'widbatpc.json'
|
||||||
|
|
||||||
let settings
|
let settings
|
||||||
function loadSettings() {
|
function loadSettings() {
|
||||||
settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {}
|
settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {}
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
'color': 'By Level',
|
'color': 'By Level',
|
||||||
|
@ -20,13 +20,13 @@ function loadSettings() {
|
||||||
Object.keys(DEFAULTS).forEach(k=>{
|
Object.keys(DEFAULTS).forEach(k=>{
|
||||||
if (settings[k]===undefined) settings[k]=DEFAULTS[k]
|
if (settings[k]===undefined) settings[k]=DEFAULTS[k]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function setting(key) {
|
function setting(key) {
|
||||||
if (!settings) { loadSettings() }
|
if (!settings) { loadSettings() }
|
||||||
return settings[key];
|
return settings[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
const levelColor = (l) => {
|
const levelColor = (l) => {
|
||||||
// "charging" is very bright -> percentage is hard to read, "high" is ok(ish)
|
// "charging" is very bright -> percentage is hard to read, "high" is ok(ish)
|
||||||
const green = setting('percentage') ? COLORS.high : COLORS.charging
|
const green = setting('percentage') ? COLORS.high : COLORS.charging
|
||||||
switch (setting('color')) {
|
switch (setting('color')) {
|
||||||
|
@ -45,12 +45,12 @@ const levelColor = (l) => {
|
||||||
if (l >= 15) return COLORS.ok;
|
if (l >= 15) return COLORS.ok;
|
||||||
return COLORS.low;
|
return COLORS.low;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const chargerColor = () => {
|
const chargerColor = () => {
|
||||||
return (setting('color') === 'Monochrome') ? COLORS.white : COLORS.charging
|
return (setting('color') === 'Monochrome') ? COLORS.white : COLORS.charging
|
||||||
}
|
}
|
||||||
// sets width, returns true if it changed
|
// sets width, returns true if it changed
|
||||||
function setWidth() {
|
function setWidth() {
|
||||||
var w = 40;
|
var w = 40;
|
||||||
if (Bangle.isCharging() && setting('charger'))
|
if (Bangle.isCharging() && setting('charger'))
|
||||||
w += 16;
|
w += 16;
|
||||||
|
@ -59,8 +59,8 @@ function setWidth() {
|
||||||
var changed = WIDGETS["batpc"].width != w;
|
var changed = WIDGETS["batpc"].width != w;
|
||||||
WIDGETS["batpc"].width = w;
|
WIDGETS["batpc"].width = w;
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
function draw() {
|
function draw() {
|
||||||
// if hidden, don't draw
|
// if hidden, don't draw
|
||||||
if (!WIDGETS["batpc"].width) return;
|
if (!WIDGETS["batpc"].width) return;
|
||||||
// else...
|
// else...
|
||||||
|
@ -100,29 +100,29 @@ function draw() {
|
||||||
gfx.setFont('6x8', 2);
|
gfx.setFont('6x8', 2);
|
||||||
gfx.drawString(l, x + 6, y + 4);
|
gfx.drawString(l, x + 6, y + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// reload widget, e.g. when settings have changed
|
// reload widget, e.g. when settings have changed
|
||||||
function reload() {
|
function reload() {
|
||||||
loadSettings()
|
loadSettings()
|
||||||
// need to redraw all widgets, because changing the "charger" setting
|
// need to redraw all widgets, because changing the "charger" setting
|
||||||
// can affect the width and mess with the whole widget layout
|
// can affect the width and mess with the whole widget layout
|
||||||
setWidth()
|
setWidth()
|
||||||
g.clear();
|
g.clear();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
}
|
}
|
||||||
// update widget - redraw just widget, or all widgets if size changed
|
// update widget - redraw just widget, or all widgets if size changed
|
||||||
function update() {
|
function update() {
|
||||||
if (setWidth()) Bangle.drawWidgets();
|
if (setWidth()) Bangle.drawWidgets();
|
||||||
else WIDGETS["batpc"].draw();
|
else WIDGETS["batpc"].draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
Bangle.on('charging',function(charging) {
|
Bangle.on('charging',function(charging) {
|
||||||
if(charging) Bangle.buzz();
|
if(charging) Bangle.buzz();
|
||||||
update();
|
update();
|
||||||
g.flip();
|
g.flip();
|
||||||
});
|
});
|
||||||
var batteryInterval;
|
var batteryInterval;
|
||||||
Bangle.on('lcdPower', function(on) {
|
Bangle.on('lcdPower', function(on) {
|
||||||
if (on) {
|
if (on) {
|
||||||
update();
|
update();
|
||||||
// refresh once a minute if LCD on
|
// refresh once a minute if LCD on
|
||||||
|
@ -134,7 +134,7 @@ Bangle.on('lcdPower', function(on) {
|
||||||
batteryInterval = undefined;
|
batteryInterval = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload};
|
WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload};
|
||||||
setWidth();
|
setWidth();
|
||||||
})()
|
})()
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
(function(){
|
(function(){
|
||||||
var img_bt = E.toArrayBuffer(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="));
|
var img_bt = E.toArrayBuffer(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="));
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
g.reset();
|
g.reset();
|
||||||
if (NRF.getSecurityStatus().connected)
|
if (NRF.getSecurityStatus().connected)
|
||||||
g.setColor(0,0.5,1);
|
g.setColor(0,0.5,1);
|
||||||
else
|
else
|
||||||
g.setColor(0.3,0.3,0.3);
|
g.setColor(0.3,0.3,0.3);
|
||||||
g.drawImage(img_bt,10+this.x,2+this.y);
|
g.drawImage(img_bt,10+this.x,2+this.y);
|
||||||
}
|
}
|
||||||
function changed() {
|
function changed() {
|
||||||
WIDGETS["bluetooth"].draw();
|
WIDGETS["bluetooth"].draw();
|
||||||
g.flip();// turns screen on
|
g.flip();// turns screen on
|
||||||
}
|
}
|
||||||
NRF.on('connect',changed);
|
NRF.on('connect',changed);
|
||||||
NRF.on('disconnect',changed);
|
NRF.on('disconnect',changed);
|
||||||
WIDGETS["bluetooth"]={area:"tr",width:24,draw:draw};
|
WIDGETS["bluetooth"]={area:"tr",width:24,draw:draw};
|
||||||
})()
|
})()
|
||||||
|
|
Loading…
Reference in New Issue