Force indent to 2 spaces

Based on http://www.espruino.com/Code+Style
pull/451/head
Tuukka Ikkala 2020-05-24 00:32:33 +03:00
parent 0a32e40b1a
commit c6fd71be03
73 changed files with 3124 additions and 3117 deletions

View File

@ -29,6 +29,13 @@
"ecmaVersion": 11
},
"rules": {
"indent": [
"error",
2,
{
"SwitchCase": 1
}
],
"no-case-declarations": "off",
"no-constant-condition": "off",
"no-delete-var": "off",

View File

@ -1,19 +1,19 @@
(() => {
//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&&
//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&&
(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+
.5)-1,a.gety(0));return a}});
const storage = require("Storage");
const SETTINGS_FILE = 'activepedom.settings.json';
var history = 86400000; // 28800000=8h 43200000=12h //86400000=24h
const storage = require("Storage");
const SETTINGS_FILE = 'activepedom.settings.json';
var history = 86400000; // 28800000=8h 43200000=12h //86400000=24h
//return setting
function setting(key) {
//define default settings
const DEFAULTS = {
//return setting
function setting(key) {
//define default settings
const DEFAULTS = {
'cMaxTime' : 1100,
'cMinTime' : 240,
'stepThreshold' : 30,
@ -21,13 +21,13 @@ const DEFAULTS = {
'stepSensitivity' : 80,
'stepGoal' : 10000,
'stepLength' : 75,
};
if (!settings) { loadSettings(); }
return (key in settings) ? settings[key] : DEFAULTS[key];
}
};
if (!settings) { loadSettings(); }
return (key in settings) ? settings[key] : DEFAULTS[key];
}
//Convert ms to time
function getTime(t) {
//Convert ms to time
function getTime(t) {
date = new Date(t);
offset = date.getTimezoneOffset() / 60;
//var milliseconds = parseInt((t % 1000) / 100),
@ -39,9 +39,9 @@ function getTime(t) {
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds;
}
}
function getDate(t) {
function getDate(t) {
date = new Date(t*1);
year = date.getFullYear();
month = date.getMonth()+1; //month is zero-based
@ -49,10 +49,10 @@ function getDate(t) {
month = (month < 10) ? "0" + month : month;
day = (day < 10) ? "0" + day : day;
return year + "-" + month + "-" + day;
}
}
//columns: 0=time, 1=stepsCounted, 2=active, 3=stepsTooShort, 4=stepsTooLong, 5=stepsOutsideTime
function getArrayFromCSV(file, column) {
//columns: 0=time, 1=stepsCounted, 2=active, 3=stepsTooShort, 4=stepsTooLong, 5=stepsOutsideTime
function getArrayFromCSV(file, column) {
i = 0;
array = [];
now = new Date();
@ -67,9 +67,9 @@ function getArrayFromCSV(file, column) {
i++;
}
return array;
}
}
function drawGraph() {
function drawGraph() {
//times
// actives = getArrayFromCSV(csvFile, 2);
// shorts = getArrayFromCSV(csvFile, 3);
@ -115,16 +115,16 @@ function drawGraph() {
allDataFile = undefined;
csvFile = undefined;
times = undefined;
}
}
function drawMenu () {
function drawMenu () {
g.clear();
g.setFont("6x8", 1);
g.drawString("BTN1:Timespan | BTN2:Draw", 20, 10);
g.drawString("Timespan: " + history/1000/60/60 + " hours", 20, 20);
}
}
setWatch(function() { //BTN1
setWatch(function() { //BTN1
switch(history) {
case 3600000 : //1h
history = 14400000; //4h
@ -137,29 +137,29 @@ setWatch(function() { //BTN1
break;
}
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.drawString ("Drawing...",30,60);
drawGraph();
}, BTN2, {edge:"rising", debounce:50, repeat:true});
}, BTN2, {edge:"rising", debounce:50, repeat:true});
setWatch(function() { //BTN3
}, BTN3, {edge:"rising", debounce:50, repeat:true});
setWatch(function() { //BTN3
}, BTN3, {edge:"rising", debounce:50, repeat:true});
setWatch(function() { //BTN4
}, BTN4, {edge:"rising", debounce:50, repeat:true});
setWatch(function() { //BTN4
}, BTN4, {edge:"rising", debounce:50, repeat:true});
setWatch(function() { //BTN5
}, BTN5, {edge:"rising", debounce:50, repeat:true});
setWatch(function() { //BTN5
}, BTN5, {edge:"rising", debounce:50, repeat:true});
//load settings
let settings;
function loadSettings() {
settings = storage.readJSON(SETTINGS_FILE, 1) || {};
}
//load settings
let settings;
function loadSettings() {
settings = storage.readJSON(SETTINGS_FILE, 1) || {};
}
drawMenu();
drawMenu();
})();

View File

@ -6,9 +6,9 @@
(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,
cos = Math.cos,
tan = Math.tan,
@ -17,54 +17,54 @@ var PI = Math.PI,
acos = Math.acos,
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,
J2000 = 2451545;
function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
function fromJulian(j) { return (j + 0.5 - J1970) * dayMs; }
function toDays(date) { return toJulian(date) - J2000; }
function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
function fromJulian(j) { return (j + 0.5 - J1970) * dayMs; }
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 declination(l, b) { return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(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 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 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 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.
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.
// 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));
}
}
// 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
P = rad * 102.9372; // perihelion of the Earth
return M + C + P + PI;
}
}
function sunCoords(d) {
function sunCoords(d) {
var M = solarMeanAnomaly(d),
L = eclipticLongitude(M);
@ -73,15 +73,15 @@ function sunCoords(d) {
dec: declination(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,
phi = rad * lat,
@ -94,52 +94,52 @@ SunCalc.getPosition = function (date, lat, lng) {
azimuth: azimuth(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.3, 'sunriseEnd', 'sunsetStart' ],
[ -6, 'dawn', 'dusk' ],
[ -12, 'nauticalDawn', 'nauticalDusk'],
[ -18, 'nightEnd', 'night' ],
[ 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]);
};
};
// 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 solarTransitJ(ds, M, L) { return J2000 + ds + 0.0053 * sin(M) - 0.0069 * sin(2 * L); }
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 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 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; }
// returns set time for the given sun altitude
function getSetJ(h, lw, phi, dec, n, M, L) {
// returns set time for the given sun altitude
function getSetJ(h, lw, phi, dec, n, M, L) {
var w = hourAngle(h, phi, dec),
a = approxTransit(w, lw, n);
return solarTransitJ(a, M, L);
}
}
// calculates sun times for a given date, latitude/longitude, and, optionally,
// the observer height (in meters) relative to the horizon
// calculates sun times for a given date, latitude/longitude, and, optionally,
// 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;
@ -178,12 +178,12 @@ SunCalc.getTimes = function (date, lat, lng, height) {
}
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
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),
dist: dt
};
}
}
SunCalc.getMoonPosition = function (date, lat, lng) {
SunCalc.getMoonPosition = function (date, lat, lng) {
var lw = rad * -lng,
phi = rad * lat,
@ -220,16 +220,16 @@ SunCalc.getMoonPosition = function (date, lat, lng) {
distance: c.dist,
parallacticAngle: pa
};
};
};
// calculations for illumination parameters of the moon,
// 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.
// calculations for illumination parameters of the moon,
// 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.
// 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 year = date.getFullYear();
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
return {phase: b};
};
};
function hoursLater(date, h) {
function hoursLater(date, h) {
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;
if (inUTC) t.setUTCHours(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;
return result;
};
};
// export as Node module / AMD module / browser variable
if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = SunCalc;
else if (typeof define === 'function' && define.amd) define(SunCalc);
else global.SunCalc = SunCalc;
// export as Node module / AMD module / browser variable
if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = SunCalc;
else if (typeof define === 'function' && define.amd) define(SunCalc);
else global.SunCalc = SunCalc;
}());

View File

@ -52,7 +52,7 @@ Bangle.on('lcdPower', (on) => {
Bangle.drawWidgets();
// call your app function here
drawBerlinClock();
}});
}});
// refesh every 15 sec
setInterval(drawBerlinClock, 15E3);

View File

@ -8,11 +8,11 @@ const Spades = { width : 48, height : 48, bpp : 1,
const Hearts = { width : 48, height : 48, bpp : 4,
buffer : require("heatshrink").decompress(atob("ADlVqtQBQ8FBYIKIrnMAAINGqoKC4okGCwYAB4AKDhgKE4oWKAAILDBQwYEBYwwDFwojFgoLHEgQ6H5hhCBZAkCBRAjLEgI6IC4YLIC5Y7BBZXBjgjVABYX/C8CnKABbXLABTvMC8sMC6fAC4KQURwIABRypgULwRgULwRIUCwhIRIwiRSRoZITCwx5POoowRCxAwNFxIwNCxQwLFxYwLCxgwJFxowJCxwwHFx4wHCyAwFFyIwFCyQwDFycAgoXBqAXTgFc4oWUJAJGUJARGVAEo"))
};
};
const Diamonds = { width : 48, height : 48, bpp : 4,
buffer : require("heatshrink").decompress(atob("AHUFC60M4AXV5nFIyvM5hGVC4JIUCwJIUIwRIUIwRIUCwZISIwgABqBGUJCQWFPKBGGJCFcC455OCw4wOOox5QIxB5NOpBIOFxZ5LCxYwKOpQwMIxh5KOxipLL6xgNR5QwMX5TvXPJZ1JJBpGLPJR1LJBZGNPJIWOJA5GOPJB1NJBIWQPIpGRJApGRPIoWSJAa8PJA5GTJAYWUJAJGVAAJGVAHo="))
};
};
var deck = [];

View File

@ -7,12 +7,12 @@ setWatch(x=>{
},BTN1,{repeat:true});
function updateAdvertising() {
try {
try {
NRF.setAdvertising({},{
manufacturer: 0x0590,
manufacturerData: new Uint8Array([mycounter>>8,mycounter&255])
});
} catch(e){}
} catch(e){}
}
function drawPlayers() {

View File

@ -26,31 +26,31 @@ const ySpace=[y0, y1, y2];
const pixels = [[[0,0], // digit on/off pixels
[1,1],
[1,1]],
[[0,1], // digit 1
[[0,1], // digit 1
[0,1],
[0,1]],
[[0,1],
[[0,1],
[1,0],
[1,1]],
[[1,1],
[[1,1],
[0,1],
[1,1]],
[[1,0],
[[1,0],
[1,1],
[0,1]],
[[1,1],
[[1,1],
[1,0],
[0,1]],
[[1,0],
[[1,0],
[1,1],
[1,1]],
[[1,1],
[[1,1],
[0,1],
[0,1]],
[[1,1],
[[1,1],
[1,1],
[1,1]],
[[1,1],
[[1,1],
[1,1],
[0,1]]];

View File

@ -1 +1 @@
require("heatshrink").decompress(atob("/4AYv4CB+YdZABPvEkYA/AGv3EkfPAQP+DrI"))
require("heatshrink").decompress(atob("/4AYv4CB+YdZABPvEkYA/AGv3EkfPAQP+DrI"))

View File

@ -5,8 +5,8 @@ function redraw() {
g.drawImage(img, 120-96, 120-96, {scale:2});
}
// Code for button (Puck.js)
var busy = false;
// Code for button (Puck.js)
var busy = false;
var lastTry = getTime();

View File

@ -211,7 +211,7 @@ const drawClockFace = () => {
g.setColor(0.1,0.7,0);
}
g.fillCircle(centerX,centerY,radius*0.98);
};
};
const drawAll = () => {
currentDate = new Date();

View File

@ -30,4 +30,4 @@
}
};
E.showMenu(appMenu)
})
})

View File

@ -16,13 +16,13 @@ setWatch(x=>{
},BTN1,{repeat:true});
function updateAdvertising() {
try {
try {
NRF.setAdvertising({},{
manufacturer: 0x0590,
manufacturerData: new Uint8Array([mycounter>>8,mycounter&255]),
interval: 60
});
} catch(e){}
} catch(e){}
}
function drawPlayers() {

View File

@ -3,7 +3,7 @@ E.showMessage("Jingle Bells");
var eventEmitter = new Object();
function strofa(notes, times, current, next){
eventEmitter.on(current, () => {
eventEmitter.on(current, () => {
if (notes.length == 0) {
eventEmitter.emit(next);
return;
@ -15,7 +15,7 @@ eventEmitter.on(current, () => {
eventEmitter.emit(current);
}, time);
});
});
});
}
var one = [2637, 2637, 2637, 2637, 2637, 2637, 2637, 3135, 2093, 2349, 2637];

View File

@ -16,98 +16,98 @@ var timeInterval;
n is the amount (0..1)
maxFive is true is this digit only counts 0..5 */
const DIGITS = {
" ":n=>[],
"0":n=>[
[n,0,1,0],
[1,0,1,1],
[1,1,1,2],
[n,2,1,2],
[n,1,n,2],
[n,0,n,1]],
"1":n=>[
[1-n,0,1,0],
[1,0,1,1],
[1-n,1,1,1],
[1-n,1,1-n,2],
[1-n,2,1,2]],
"2":n=>[
[0,0,1,0],
[1,0,1,1],
[0,1,1,1],
[0,1+n,0,2],
[1,2-n,1,2],
[0,2,1,2]],
"3":n=>[
[0,0,1-n,0],
[0,0,0,n],
[1,0,1,1],
[0,1,1,1],
[1,1,1,2],
[n,2,1,2]],
"4":n=>[
[0,0,0,1],
[1,0,1-n,0],
[1,0,1,1-n],
[0,1,1,1],
[1,1,1,2],
[1-n,2,1,2]],
"5to0": n=>[ // 5 -> 0
[0,0,0,1],
[0,0,1,0],
[n,1,1,1],
[1,1,1,2],
[0,2,1,2],
[0,2,0,2],
[1,1-n,1,1],
[0,1,0,1+n]],
"5to6": n=>[ // 5 -> 6
[0,0,0,1],
[0,0,1,0],
[0,1,1,1],
[1,1,1,2],
[0,2,1,2],
[0,2-n,0,2]],
"6":n=>[
[0,0,0,1-n],
[0,0,1,0],
[n,1,1,1],
[1,1-n,1,1],
[1,1,1,2],
[n,2,1,2],
[0,1-n,0,2-2*n]],
"7":n=>[
[0,0,0,n],
[0,0,1,0],
[1,0,1,1],
[1-n,1,1,1],
[1,1,1,2],
[1-n,2,1,2],
[1-n,1,1-n,2]],
"8":n=>[
[0,0,0,1],
[0,0,1,0],
[1,0,1,1],
[0,1,1,1],
[1,1,1,2],
[0,2,1,2],
[0,1,0,2-n]],
"9":n=>[
[0,0,0,1],
[0,0,1,0],
[1,0,1,1],
[0,1,1-n,1],
[0,1,0,1+n],
[1,1,1,2],
[0,2,1,2]],
":":n=>[
[0.4,0.4,0.6,0.4],
[0.6,0.4,0.6,0.6],
[0.6,0.6,0.4,0.6],
[0.4,0.4,0.4,0.6],
[0.4,1.4,0.6,1.4],
[0.6,1.4,0.6,1.6],
[0.6,1.6,0.4,1.6],
[0.4,1.4,0.4,1.6]]
" ":n=>[],
"0":n=>[
[n,0,1,0],
[1,0,1,1],
[1,1,1,2],
[n,2,1,2],
[n,1,n,2],
[n,0,n,1]],
"1":n=>[
[1-n,0,1,0],
[1,0,1,1],
[1-n,1,1,1],
[1-n,1,1-n,2],
[1-n,2,1,2]],
"2":n=>[
[0,0,1,0],
[1,0,1,1],
[0,1,1,1],
[0,1+n,0,2],
[1,2-n,1,2],
[0,2,1,2]],
"3":n=>[
[0,0,1-n,0],
[0,0,0,n],
[1,0,1,1],
[0,1,1,1],
[1,1,1,2],
[n,2,1,2]],
"4":n=>[
[0,0,0,1],
[1,0,1-n,0],
[1,0,1,1-n],
[0,1,1,1],
[1,1,1,2],
[1-n,2,1,2]],
"5to0": n=>[ // 5 -> 0
[0,0,0,1],
[0,0,1,0],
[n,1,1,1],
[1,1,1,2],
[0,2,1,2],
[0,2,0,2],
[1,1-n,1,1],
[0,1,0,1+n]],
"5to6": n=>[ // 5 -> 6
[0,0,0,1],
[0,0,1,0],
[0,1,1,1],
[1,1,1,2],
[0,2,1,2],
[0,2-n,0,2]],
"6":n=>[
[0,0,0,1-n],
[0,0,1,0],
[n,1,1,1],
[1,1-n,1,1],
[1,1,1,2],
[n,2,1,2],
[0,1-n,0,2-2*n]],
"7":n=>[
[0,0,0,n],
[0,0,1,0],
[1,0,1,1],
[1-n,1,1,1],
[1,1,1,2],
[1-n,2,1,2],
[1-n,1,1-n,2]],
"8":n=>[
[0,0,0,1],
[0,0,1,0],
[1,0,1,1],
[0,1,1,1],
[1,1,1,2],
[0,2,1,2],
[0,1,0,2-n]],
"9":n=>[
[0,0,0,1],
[0,0,1,0],
[1,0,1,1],
[0,1,1-n,1],
[0,1,0,1+n],
[1,1,1,2],
[0,2,1,2]],
":":n=>[
[0.4,0.4,0.6,0.4],
[0.6,0.4,0.6,0.6],
[0.6,0.6,0.4,0.6],
[0.4,0.4,0.4,0.6],
[0.4,1.4,0.6,1.4],
[0.6,1.4,0.6,1.6],
[0.6,1.6,0.4,1.6],
[0.4,1.4,0.4,1.6]]
};
/* Draw a transition between lastText and thisText.

View File

@ -243,7 +243,7 @@ function drawMoonPhase(offset, 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) == "waning-crescent") {g.drawImage(getImg("WaningCrescentNorth"), x, y);}
}
}
else { //Southern hemisphere
if (getMPhaseSim(offset) == "new") {g.drawImage(getImg("NewMoon"), x, y);}
if (getMPhaseSim(offset) == "waxing-crescent") {g.drawImage(getImg("WaxingCrescentSouth"), x, y);}

View File

@ -206,7 +206,7 @@
Bangle.loadWidgets();
Bangle.drawWidgets();
//manage when things should be enabled and not
//manage when things should be enabled and not
Bangle.on('lcdPower', function (on) {
if (on) {
Bangle.setHRMPower(1);

View File

@ -1,18 +1,18 @@
(function() {
var clickTimes = [];
var clickPattern = "";
var TAPS = 4; // number of taps
var PERIOD = 1; // seconds
var clickTimes = [];
var clickPattern = "";
var TAPS = 4; // number of taps
var PERIOD = 1; // seconds
// we don't actually create/draw a widget here at all...
Bangle.on("lcdPower",function(on) {
// we don't actually create/draw a widget here at all...
Bangle.on("lcdPower",function(on) {
// First click (that turns LCD on) isn't given to
// setWatch, so handle it here
if (!on) return;
clickTimes=[getTime()];
clickPattern="x";
});
function tap(e,c) {
});
function tap(e,c) {
clickPattern = clickPattern.substr(-3)+c;
while (clickTimes.length>=TAPS) clickTimes.shift();
clickTimes.push(e.time);
@ -20,7 +20,7 @@ function tap(e,c) {
if (clickPeriod<PERIOD && clickPattern.match(/.313/)) {
load("torch.app.js");
}
}
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,"1"); }, BTN1, {repeat:true, edge:"rising"});
setWatch(function(e) { tap(e,"3"); }, BTN3, {repeat:true, edge:"rising"});
})();

View File

@ -1,10 +1,10 @@
(function(){
var CHARGING = 0x07E0;
var CHARGING = 0x07E0;
function setWidth() {
function setWidth() {
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
}
function draw() {
}
function draw() {
var s = 39;
var x = this.x, y = this.y;
if (Bangle.isCharging()) {
@ -17,15 +17,15 @@ function draw() {
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(-1);
}
Bangle.on('charging',function(charging) {
}
Bangle.on('charging',function(charging) {
if(charging) Bangle.buzz();
setWidth();
Bangle.drawWidgets(); // relayout widgets
g.flip();
});
var batteryInterval;
Bangle.on('lcdPower', function(on) {
});
var batteryInterval;
Bangle.on('lcdPower', function(on) {
if (on) {
WIDGETS["bat"].draw();
// refresh once a minute if LCD on
@ -37,7 +37,7 @@ Bangle.on('lcdPower', function(on) {
batteryInterval = undefined;
}
}
});
WIDGETS["bat"]={area:"tr",width:40,draw:draw};
setWidth();
});
WIDGETS["bat"]={area:"tr",width:40,draw:draw};
setWidth();
})()

View File

@ -1,15 +1,15 @@
(function(){
const COLORS = {
const COLORS = {
'white': -1,
'charging': 0x07E0, // "Green"
'high': 0x05E0, // slightly darker green
'ok': 0xFD20, // "Orange"
'low':0xF800, // "Red"
}
const SETTINGS_FILE = 'widbatpc.json'
}
const SETTINGS_FILE = 'widbatpc.json'
let settings
function loadSettings() {
let settings
function loadSettings() {
settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {}
const DEFAULTS = {
'color': 'By Level',
@ -20,13 +20,13 @@ function loadSettings() {
Object.keys(DEFAULTS).forEach(k=>{
if (settings[k]===undefined) settings[k]=DEFAULTS[k]
});
}
function setting(key) {
}
function setting(key) {
if (!settings) { loadSettings() }
return settings[key];
}
}
const levelColor = (l) => {
const levelColor = (l) => {
// "charging" is very bright -> percentage is hard to read, "high" is ok(ish)
const green = setting('percentage') ? COLORS.high : COLORS.charging
switch (setting('color')) {
@ -45,12 +45,12 @@ const levelColor = (l) => {
if (l >= 15) return COLORS.ok;
return COLORS.low;
}
}
const chargerColor = () => {
}
const chargerColor = () => {
return (setting('color') === 'Monochrome') ? COLORS.white : COLORS.charging
}
// sets width, returns true if it changed
function setWidth() {
}
// sets width, returns true if it changed
function setWidth() {
var w = 40;
if (Bangle.isCharging() && setting('charger'))
w += 16;
@ -59,8 +59,8 @@ function setWidth() {
var changed = WIDGETS["batpc"].width != w;
WIDGETS["batpc"].width = w;
return changed;
}
function draw() {
}
function draw() {
// if hidden, don't draw
if (!WIDGETS["batpc"].width) return;
// else...
@ -100,29 +100,29 @@ function draw() {
gfx.setFont('6x8', 2);
gfx.drawString(l, x + 6, y + 4);
}
}
// reload widget, e.g. when settings have changed
function reload() {
}
// reload widget, e.g. when settings have changed
function reload() {
loadSettings()
// need to redraw all widgets, because changing the "charger" setting
// can affect the width and mess with the whole widget layout
setWidth()
g.clear();
Bangle.drawWidgets();
}
// update widget - redraw just widget, or all widgets if size changed
function update() {
}
// update widget - redraw just widget, or all widgets if size changed
function update() {
if (setWidth()) Bangle.drawWidgets();
else WIDGETS["batpc"].draw();
}
}
Bangle.on('charging',function(charging) {
Bangle.on('charging',function(charging) {
if(charging) Bangle.buzz();
update();
g.flip();
});
var batteryInterval;
Bangle.on('lcdPower', function(on) {
});
var batteryInterval;
Bangle.on('lcdPower', function(on) {
if (on) {
update();
// refresh once a minute if LCD on
@ -134,7 +134,7 @@ Bangle.on('lcdPower', function(on) {
batteryInterval = undefined;
}
}
});
WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload};
setWidth();
});
WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload};
setWidth();
})()

View File

@ -1,19 +1,19 @@
(function(){
var img_bt = E.toArrayBuffer(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="));
var img_bt = E.toArrayBuffer(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="));
function draw() {
function draw() {
g.reset();
if (NRF.getSecurityStatus().connected)
g.setColor(0,0.5,1);
else
g.setColor(0.3,0.3,0.3);
g.drawImage(img_bt,10+this.x,2+this.y);
}
function changed() {
}
function changed() {
WIDGETS["bluetooth"].draw();
g.flip();// turns screen on
}
NRF.on('connect',changed);
NRF.on('disconnect',changed);
WIDGETS["bluetooth"]={area:"tr",width:24,draw:draw};
}
NRF.on('connect',changed);
NRF.on('disconnect',changed);
WIDGETS["bluetooth"]={area:"tr",width:24,draw:draw};
})()