From c6fd71be0333cc317d4b7f36dccd7460f67ccac3 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Sun, 24 May 2020 00:32:33 +0300 Subject: [PATCH] Force indent to 2 spaces Based on http://www.espruino.com/Code+Style --- apps/.eslintrc.json | 7 + apps/activepedom/app.js | 140 ++--- apps/activepedom/widget.js | 6 +- apps/astrocalc/astrocalc-app.js | 190 +++---- apps/astrocalc/suncalc.js | 286 +++++----- apps/batchart/widget.js | 2 +- apps/bclock/clock-binary.js | 134 ++--- apps/beebclock/beebclock.js | 642 +++++++++++----------- apps/berlinc/berlin-clock.js | 60 +- apps/blackjack/blackjack.app.js | 250 ++++----- apps/bledetect/bledetect.js | 16 +- apps/blescan/blescan.js | 24 +- apps/blobclk/clock-blob.js | 156 +++--- apps/boldclk/bold_clock.js | 164 +++--- apps/calculator/app.js | 2 +- apps/chronowid/app.js | 16 +- apps/chronowid/widget.js | 170 +++--- apps/clickms/click-master.js | 12 +- apps/clock2x3/clock2x3-app.js | 64 +-- apps/compass/compass.js | 2 +- apps/cube/cube-icon.js | 2 +- apps/cube/cube.js | 6 +- apps/dane/app.js | 4 +- apps/daysl/widget.js | 6 +- apps/demoapp/app.js | 64 +-- apps/dotmatrixclock/app.js | 16 +- apps/findphone/app.js | 22 +- apps/flagrse/app.js | 56 +- apps/flappy/app.js | 2 +- apps/gallifr/app.js | 62 +-- apps/gallifr/settings.js | 60 +- apps/getup/app.js | 40 +- apps/gpsnav/app.js | 62 +-- apps/hidcam/app.js | 6 +- apps/hidjoystick/app.js | 106 ++-- apps/horsey/horse-race.js | 18 +- apps/impwclock/clock-impword.js | 168 +++--- apps/jbells/jbells.js | 12 +- apps/locale/locales.js | 844 ++++++++++++++--------------- apps/marioclock/marioclock-app.js | 66 +-- apps/mclock/clock-morphing.js | 184 +++---- apps/metronome/metronome.js | 76 +-- apps/miclock/clock-mixed.js | 112 ++-- apps/miplant/app.js | 4 +- apps/mmonday/manic-monday.js | 4 +- apps/moonphase/app.js | 422 +++++++-------- apps/morse/morse-code.js | 28 +- apps/nato/nato.js | 2 +- apps/ncfrun/nceu-funrun.js | 2 +- apps/numerals/numerals.app.js | 2 +- apps/numerals/numerals.settings.js | 24 +- apps/pipboy/app.js | 38 +- apps/pomodo/pomodoro.js | 394 +++++++------- apps/rclock/rclock.app.js | 4 +- apps/scolor/show-color.js | 94 ++-- apps/stetho/stetho.js | 4 +- apps/swatch/stopwatch.js | 4 +- apps/torch/widget.js | 40 +- apps/toucher/app.js | 54 +- apps/wclock/clock-word.js | 170 +++--- apps/welcome/app.js | 40 +- apps/widbat/widget.js | 76 +-- apps/widbatpc/settings.js | 8 +- apps/widbatpc/widget.js | 250 ++++----- apps/widbt/widget.js | 32 +- apps/widclk/widget.js | 44 +- apps/widhwt/widget.js | 32 +- apps/widid/widget.js | 16 +- apps/widmp/widget.js | 48 +- apps/widram/widget.js | 16 +- apps/widtbat/widget.js | 28 +- apps/widver/widget.js | 16 +- apps/wohrm/app.js | 8 +- 73 files changed, 3124 insertions(+), 3117 deletions(-) diff --git a/apps/.eslintrc.json b/apps/.eslintrc.json index 4ed76396a..2abf034d5 100644 --- a/apps/.eslintrc.json +++ b/apps/.eslintrc.json @@ -29,6 +29,13 @@ "ecmaVersion": 11 }, "rules": { + "indent": [ + "error", + 2, + { + "SwitchCase": 1 + } + ], "no-case-declarations": "off", "no-constant-condition": "off", "no-delete-var": "off", diff --git a/apps/activepedom/app.js b/apps/activepedom/app.js index cc875f371..ec9b1237f 100644 --- a/apps/activepedom/app.js +++ b/apps/activepedom/app.js @@ -1,33 +1,33 @@ (() => { -//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+ + 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 = { - 'cMaxTime' : 1100, - 'cMinTime' : 240, - 'stepThreshold' : 30, - 'intervalResetActive' : 30000, - 'stepSensitivity' : 80, - 'stepGoal' : 10000, - 'stepLength' : 75, -}; -if (!settings) { loadSettings(); } -return (key in settings) ? settings[key] : DEFAULTS[key]; -} + //return setting + function setting(key) { + //define default settings + const DEFAULTS = { + 'cMaxTime' : 1100, + 'cMinTime' : 240, + 'stepThreshold' : 30, + 'intervalResetActive' : 30000, + 'stepSensitivity' : 80, + 'stepGoal' : 10000, + 'stepLength' : 75, + }; + 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,27 +49,27 @@ 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(); while ((nextLine = file.readLine())) { //as long as there is a next line - if(nextLine) { - dataSplitted = nextLine.split(','); //split line, - diff = now - dataSplitted[0]; //calculate difference between now and stored time - if (diff <= history) { //only entries from the last x ms - array.push(dataSplitted[column]); - } + if(nextLine) { + dataSplitted = nextLine.split(','); //split line, + diff = now - dataSplitted[0]; //calculate difference between now and stored time + if (diff <= history) { //only entries from the last x ms + array.push(dataSplitted[column]); } - i++; + } + i++; } return array; -} + } -function drawGraph() { + function drawGraph() { //times // actives = getArrayFromCSV(csvFile, 2); // shorts = getArrayFromCSV(csvFile, 3); @@ -104,62 +104,62 @@ function drawGraph() { g.drawString("First: " + first, 10, 30); g.drawString(" Last: " + last, 10, 40); require("graph").drawLine(g, steps, { - //title: "Steps Counted", - axes : true, - gridy : gridyValue, - y : 60, //offset on screen - x : 5, //offset on screen + //title: "Steps Counted", + axes : true, + gridy : gridyValue, + y : 60, //offset on screen + x : 5, //offset on screen }); //free memory from big variables allData = undefined; 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 - break; - case 86400000 : //24 - history = 3600000; //1h - break; - default : - history = history + 14400000; //4h - break; + case 3600000 : //1h + history = 14400000; //4h + break; + case 86400000 : //24 + history = 3600000; //1h + break; + default : + history = history + 14400000; //4h + 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(); })(); \ No newline at end of file diff --git a/apps/activepedom/widget.js b/apps/activepedom/widget.js index 2ae1b9b62..ed91a4cfd 100644 --- a/apps/activepedom/widget.js +++ b/apps/activepedom/widget.js @@ -26,7 +26,7 @@ var storeDataInterval = 5*60*1000; //ms let settings; - //load settings + //load settings function loadSettings() { settings = s.readJSON(SETTINGS_FILE, 1) || {}; } @@ -69,8 +69,8 @@ '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]; } function setStepSensitivity(s) { diff --git a/apps/astrocalc/astrocalc-app.js b/apps/astrocalc/astrocalc-app.js index 6b848abda..4e7aa0b40 100644 --- a/apps/astrocalc/astrocalc-app.js +++ b/apps/astrocalc/astrocalc-app.js @@ -155,7 +155,7 @@ function drawMoonPositionPage(gps, title) { drawPoint(azimuthDegrees, 8, {r: 1, g: 1, b: 1}); let m = setWatch(() => { - let m = moonIndexPageMenu(gps); + let m = moonIndexPageMenu(gps); }, BTN3, {repeat: false, edge: "falling"}); } @@ -232,61 +232,61 @@ function drawSunShowPage(gps, key, date) { drawPoint(azimuthDegrees, 8, {r: 1, g: 1, b: 0}); m = setWatch(() => { - m = sunIndexPageMenu(gps); + m = sunIndexPageMenu(gps); }, BTN3, {repeat: false, edge: "falling"}); return null; } function sunIndexPageMenu(gps) { - const sunTimes = SunCalc.getTimes(new Date(), gps.lat, gps.lon); + const sunTimes = SunCalc.getTimes(new Date(), gps.lat, gps.lon); - const sunMenu = { - "": { - "title": "-- Sun --", - }, - "Current Pos": () => { - m = E.showMenu(); - drawSunShowPage(gps, "Current Pos", new Date()); - }, + const sunMenu = { + "": { + "title": "-- Sun --", + }, + "Current Pos": () => { + m = E.showMenu(); + drawSunShowPage(gps, "Current Pos", new Date()); + }, + }; + + Object.keys(sunTimes).sort().reduce((menu, key) => { + const title = titlizeKey(key); + menu[title] = () => { + m = E.showMenu(); + drawSunShowPage(gps, key, sunTimes[key]); }; + return menu; + }, sunMenu); - Object.keys(sunTimes).sort().reduce((menu, key) => { - const title = titlizeKey(key); - menu[title] = () => { - m = E.showMenu(); - drawSunShowPage(gps, key, sunTimes[key]); - }; - return menu; - }, sunMenu); + sunMenu["< Back"] = () => m = indexPageMenu(gps); - sunMenu["< Back"] = () => m = indexPageMenu(gps); - - return E.showMenu(sunMenu); + return E.showMenu(sunMenu); } function moonIndexPageMenu(gps) { - const moonMenu = { - "": { - "title": "-- Moon --", - }, - "Times": () => { - m = E.showMenu(); - drawMoonTimesPage(gps, "Times"); - }, - "Position": () => { - m = E.showMenu(); - drawMoonPositionPage(gps, "Position"); - }, - "Illumination": () => { - m = E.showMenu(); - drawMoonIlluminationPage(gps, "Illumination"); - }, - "< Back": () => m = indexPageMenu(gps), - }; + const moonMenu = { + "": { + "title": "-- Moon --", + }, + "Times": () => { + m = E.showMenu(); + drawMoonTimesPage(gps, "Times"); + }, + "Position": () => { + m = E.showMenu(); + drawMoonPositionPage(gps, "Position"); + }, + "Illumination": () => { + m = E.showMenu(); + drawMoonIlluminationPage(gps, "Illumination"); + }, + "< Back": () => m = indexPageMenu(gps), + }; - return E.showMenu(moonMenu); + return E.showMenu(moonMenu); } function indexPageMenu(gps) { @@ -314,74 +314,74 @@ function getCenterStringX(str) { * GPS wait page, shows GPS locating animation until it gets a lock, then moves to the Sun page */ function drawGPSWaitPage() { - const img = require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AW43GF1wwsFwYwqFwowoFw4wmFxIwdE5YAPF/4vM5nN6YAE5vMF8YtHGIgvhFpQxKF7AuOGA4vXFyAwGF63MFyIABF6xeWMC4UDLwvNGpAJG5gwSdhIIDRBLyWCIgcJHAgJJDoouQF4vMQoICBBJoeGFx6GGACIfHL6YvaX6gvZeCIdFc4gAFXogvGFxgwFDwovQCAguOGAnMMBxeG5guTGAggGGAwNKFySREcA3N5vM5gDBdpQvXEY4AKXqovGGCKbFF7AwPZQwvZGJgtGF7vGdQItG5gSIF7gASF/44WEzgwRF0wwHF1AwFF1QwDF1gvwAH4A/AFAA==")); - const str1 = "Astrocalc v0.02"; - const str2 = "Locating GPS"; - const str3 = "Please wait..."; + const img = require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AW43GF1wwsFwYwqFwowoFw4wmFxIwdE5YAPF/4vM5nN6YAE5vMF8YtHGIgvhFpQxKF7AuOGA4vXFyAwGF63MFyIABF6xeWMC4UDLwvNGpAJG5gwSdhIIDRBLyWCIgcJHAgJJDoouQF4vMQoICBBJoeGFx6GGACIfHL6YvaX6gvZeCIdFc4gAFXogvGFxgwFDwovQCAguOGAnMMBxeG5guTGAggGGAwNKFySREcA3N5vM5gDBdpQvXEY4AKXqovGGCKbFF7AwPZQwvZGJgtGF7vGdQItG5gSIF7gASF/44WEzgwRF0wwHF1AwFF1QwDF1gvwAH4A/AFAA==")); + const str1 = "Astrocalc v0.02"; + const str2 = "Locating GPS"; + const str3 = "Please wait..."; - g.clear(); - g.drawImage(img, 100, 50); - g.setFont("6x8", 1); - g.drawString(str1, getCenterStringX(str1), 105); - g.drawString(str2, getCenterStringX(str2), 140); - g.drawString(str3, getCenterStringX(str3), 155); + g.clear(); + g.drawImage(img, 100, 50); + g.setFont("6x8", 1); + g.drawString(str1, getCenterStringX(str1), 105); + g.drawString(str2, getCenterStringX(str2), 140); + g.drawString(str3, getCenterStringX(str3), 155); - if (lastGPS) { - lastGPS = JSON.parse(lastGPS); - lastGPS.time = new Date(); + if (lastGPS) { + lastGPS = JSON.parse(lastGPS); + lastGPS.time = new Date(); - const str4 = "Press Button 3 to use last GPS"; - g.setColor("#d32e29"); - g.fillRect(0, 190, g.getWidth(), 215); - g.setColor("#ffffff"); - g.drawString(str4, getCenterStringX(str4), 200); + const str4 = "Press Button 3 to use last GPS"; + g.setColor("#d32e29"); + g.fillRect(0, 190, g.getWidth(), 215); + g.setColor("#ffffff"); + g.drawString(str4, getCenterStringX(str4), 200); - setWatch(() => { - clearWatch(); - Bangle.setGPSPower(0); - m = indexPageMenu(lastGPS); - }, BTN3, {repeat: false}); - } - - g.flip(); - - const DEBUG = false; - if (DEBUG) { + setWatch(() => { clearWatch(); + Bangle.setGPSPower(0); + m = indexPageMenu(lastGPS); + }, BTN3, {repeat: false}); + } - const gps = { - "lat": 56.45783133333, - "lon": -3.02188583333, - "alt": 75.3, - "speed": 0.070376, - "course": NaN, - "time":new Date(), - "satellites": 4, - "fix": 1 - }; + g.flip(); - m = indexPageMenu(gps); + const DEBUG = false; + if (DEBUG) { + clearWatch(); - return; - } + const gps = { + "lat": 56.45783133333, + "lon": -3.02188583333, + "alt": 75.3, + "speed": 0.070376, + "course": NaN, + "time":new Date(), + "satellites": 4, + "fix": 1 + }; - Bangle.on('GPS', (gps) => { - if (gps.fix === 0) return; - clearWatch(); + m = indexPageMenu(gps); - if (isNaN(gps.course)) gps.course = 0; - require("Storage").writeJSON(LAST_GPS_FILE, JSON.stringify(gps)); - Bangle.setGPSPower(0); - Bangle.buzz(); - Bangle.setLCDPower(true); + return; + } - m = indexPageMenu(gps); - }); + Bangle.on('GPS', (gps) => { + if (gps.fix === 0) return; + clearWatch(); + + if (isNaN(gps.course)) gps.course = 0; + require("Storage").writeJSON(LAST_GPS_FILE, JSON.stringify(gps)); + Bangle.setGPSPower(0); + Bangle.buzz(); + Bangle.setLCDPower(true); + + m = indexPageMenu(gps); + }); } function init() { - Bangle.setGPSPower(1); - drawGPSWaitPage(); + Bangle.setGPSPower(1); + drawGPSWaitPage(); } let m; diff --git a/apps/astrocalc/suncalc.js b/apps/astrocalc/suncalc.js index 6ef5aa2d0..e2beaedca 100644 --- a/apps/astrocalc/suncalc.js +++ b/apps/astrocalc/suncalc.js @@ -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,219 +17,219 @@ 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. + 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 + 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); + L = eclipticLongitude(M); return { - dec: declination(L, 0), - ra: rightAscension(L, 0) + 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, - d = toDays(date), + phi = rad * lat, + d = toDays(date), - c = sunCoords(d), - H = siderealTime(d, lw) - c.ra; + c = sunCoords(d), + H = siderealTime(d, lw) - c.ra; return { - azimuth: azimuth(H, phi, c.dec), - altitude: altitude(H, phi, c.dec) + 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); + 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; var lw = rad * -lng, - phi = rad * lat, + phi = rad * lat, - dh = observerAngle(height), + dh = observerAngle(height), - d = toDays(date), - n = julianCycle(d, lw), - ds = approxTransit(0, lw, n), + d = toDays(date), + n = julianCycle(d, lw), + ds = approxTransit(0, lw, n), - M = solarMeanAnomaly(ds), - L = eclipticLongitude(M), - dec = declination(L, 0), + M = solarMeanAnomaly(ds), + L = eclipticLongitude(M), + dec = declination(L, 0), - Jnoon = solarTransitJ(ds, M, L), + Jnoon = solarTransitJ(ds, M, L), - i, len, time, h0, Jset, Jrise; + i, len, time, h0, Jset, Jrise; var result = { - solarNoon: new Date(fromJulian(Jnoon)), - nadir: new Date(fromJulian(Jnoon - 0.5)) + solarNoon: new Date(fromJulian(Jnoon)), + nadir: new Date(fromJulian(Jnoon - 0.5)) }; for (i = 0, len = times.length; i < len; i += 1) { - time = times[i]; - h0 = (time[0] + dh) * rad; + time = times[i]; + h0 = (time[0] + dh) * rad; - Jset = getSetJ(h0, lw, phi, dec, n, M, L); - Jrise = Jnoon - (Jset - Jnoon); + Jset = getSetJ(h0, lw, phi, dec, n, M, L); + Jrise = Jnoon - (Jset - Jnoon); - result[time[1]] = new Date(fromJulian(Jrise) - (dayMs / 2)); - result[time[2]] = new Date(fromJulian(Jset) + (dayMs / 2)); + result[time[1]] = new Date(fromJulian(Jrise) - (dayMs / 2)); + result[time[2]] = new Date(fromJulian(Jset) + (dayMs / 2)); } 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 - F = rad * (93.272 + 13.229350 * d), // mean distance + M = rad * (134.963 + 13.064993 * d), // mean anomaly + F = rad * (93.272 + 13.229350 * d), // mean distance - l = L + rad * 6.289 * sin(M), // longitude - b = rad * 5.128 * sin(F), // latitude - dt = 385001 - 20905 * cos(M); // distance to the moon in km + l = L + rad * 6.289 * sin(M), // longitude + b = rad * 5.128 * sin(F), // latitude + dt = 385001 - 20905 * cos(M); // distance to the moon in km return { - ra: rightAscension(l, b), - dec: declination(l, b), - dist: dt + ra: rightAscension(l, b), + 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, - d = toDays(date), + phi = rad * lat, + d = toDays(date), - c = moonCoords(d), - H = siderealTime(d, lw) - c.ra, - h = altitude(H, phi, c.dec), - // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H)); + c = moonCoords(d), + H = siderealTime(d, lw) - c.ra, + h = altitude(H, phi, c.dec), + // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. + pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H)); h = h + astroRefraction(h); // altitude correction for refraction return { - azimuth: azimuth(H, phi, c.dec), - altitude: h, - distance: c.dist, - parallacticAngle: pa + azimuth: azimuth(H, phi, c.dec), + altitude: h, + 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,57 +256,57 @@ 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); var hc = 0.133 * rad, - h0 = SunCalc.getMoonPosition(t, lat, lng).altitude - hc, - h1, h2, rise, set, a, b, xe, ye, d, roots, x1, x2, dx; + h0 = SunCalc.getMoonPosition(t, lat, lng).altitude - hc, + h1, h2, rise, set, a, b, xe, ye, d, roots, x1, x2, dx; // go in 2-hour chunks, each time seeing if a 3-point quadratic curve crosses zero (which means rise or set) for (var i = 1; i <= 24; i += 2) { - h1 = SunCalc.getMoonPosition(hoursLater(t, i), lat, lng).altitude - hc; - h2 = SunCalc.getMoonPosition(hoursLater(t, i + 1), lat, lng).altitude - hc; + h1 = SunCalc.getMoonPosition(hoursLater(t, i), lat, lng).altitude - hc; + h2 = SunCalc.getMoonPosition(hoursLater(t, i + 1), lat, lng).altitude - hc; - a = (h0 + h2) / 2 - h1; - b = (h2 - h0) / 2; - xe = -b / (2 * a); - ye = (a * xe + b) * xe + h1; - d = b * b - 4 * a * h1; - roots = 0; + a = (h0 + h2) / 2 - h1; + b = (h2 - h0) / 2; + xe = -b / (2 * a); + ye = (a * xe + b) * xe + h1; + d = b * b - 4 * a * h1; + roots = 0; - if (d >= 0) { - dx = Math.sqrt(d) / (Math.abs(a) * 2); - x1 = xe - dx; - x2 = xe + dx; - if (Math.abs(x1) <= 1) roots++; - if (Math.abs(x2) <= 1) roots++; - if (x1 < -1) x1 = x2; - } + if (d >= 0) { + dx = Math.sqrt(d) / (Math.abs(a) * 2); + x1 = xe - dx; + x2 = xe + dx; + if (Math.abs(x1) <= 1) roots++; + if (Math.abs(x2) <= 1) roots++; + if (x1 < -1) x1 = x2; + } - if (roots === 1) { - if (h0 < 0) rise = i + x1; - else set = i + x1; + if (roots === 1) { + if (h0 < 0) rise = i + x1; + else set = i + x1; - } else if (roots === 2) { - rise = i + (ye < 0 ? x2 : x1); - set = i + (ye < 0 ? x1 : x2); - } + } else if (roots === 2) { + rise = i + (ye < 0 ? x2 : x1); + set = i + (ye < 0 ? x1 : x2); + } - if (rise && set) break; + if (rise && set) break; - h0 = h2; + h0 = h2; } var result = {}; @@ -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; }()); diff --git a/apps/batchart/widget.js b/apps/batchart/widget.js index 4a116c990..d6e00b283 100644 --- a/apps/batchart/widget.js +++ b/apps/batchart/widget.js @@ -66,7 +66,7 @@ // Very coarse first approach to check if the BLE device is on. if (NRF.getSecurityStatus().connected) - enabledConsumers = enabledConsumers | switchableConsumers.bluetooth; + enabledConsumers = enabledConsumers | switchableConsumers.bluetooth; // Reset the event registration vars compassEventReceived = false; diff --git a/apps/bclock/clock-binary.js b/apps/bclock/clock-binary.js index 98191f364..833aa00f6 100644 --- a/apps/bclock/clock-binary.js +++ b/apps/bclock/clock-binary.js @@ -6,98 +6,98 @@ const colpos = canvasWidth / numberOfColumns - 10; const binSize = (canvasWidth / numberOfColumns) / 3; const findBinary = target => { - return [ - [0, 0, 0, 0], // 0 - [1, 0, 0, 0], // 1 - [0, 1, 0, 0], // 2 - [1, 1, 0, 0], // 3 - [0, 0, 1, 0], // 4 - [1, 0, 1, 0], // 5 - [0, 1, 1, 0], // 6 - [1, 1, 1, 0], // 7 - [0, 0, 0, 1], // 8 - [1, 0, 0, 1], // 9 - ][target]; + return [ + [0, 0, 0, 0], // 0 + [1, 0, 0, 0], // 1 + [0, 1, 0, 0], // 2 + [1, 1, 0, 0], // 3 + [0, 0, 1, 0], // 4 + [1, 0, 1, 0], // 5 + [0, 1, 1, 0], // 6 + [1, 1, 1, 0], // 7 + [0, 0, 0, 1], // 8 + [1, 0, 0, 1], // 9 + ][target]; }; const getCurrentTime = () => { - const flattenArray = (array = []) => [].concat.apply([], array); - const format = number => { - const numberStr = number.toString(); - return numberStr.length === 1 ? ["0", numberStr] : numberStr.split(""); - }; - const now = new Date(); - return flattenArray([now.getHours(), now.getMinutes(), now.getSeconds()].map(format)); + const flattenArray = (array = []) => [].concat.apply([], array); + const format = number => { + const numberStr = number.toString(); + return numberStr.length === 1 ? ["0", numberStr] : numberStr.split(""); + }; + const now = new Date(); + return flattenArray([now.getHours(), now.getMinutes(), now.getSeconds()].map(format)); }; let prevFrame = []; const drawColumn = (position = 0, column = [0, 0, 0, 0]) => { - const maxDotsPerColumn = [2, 4, 3, 4, 3, 4]; + const maxDotsPerColumn = [2, 4, 3, 4, 3, 4]; - const columnPos = position * colpos; - let pos = colpos / 2 + 45; - const frame = column.reverse(); - const drawDot = fn => g[fn]((columnPos + colpos / 2), pos, binSize); + const columnPos = position * colpos; + let pos = colpos / 2 + 45; + const frame = column.reverse(); + const drawDot = fn => g[fn]((columnPos + colpos / 2), pos, binSize); - for (let i = 0; i < frame.length; i += 1) { - if (i + maxDotsPerColumn[position] >= 4 || drawFullGrid) { - if (prevFrame && prevFrame[position] && prevFrame[position][i]) { - if (frame[i] !== prevFrame[position][i]) { - // subsequent draw - g.clearRect((columnPos + colpos / 2) - 15, pos - 15, (columnPos + colpos / 2) + 20, pos + 20); - if (frame[i]) { - drawDot('fillCircle'); - } else { - drawDot('drawCircle'); - } - } - } else { - // First draw - if (frame[i]) { - drawDot('fillCircle'); - } else { - drawDot('drawCircle'); - } - } + for (let i = 0; i < frame.length; i += 1) { + if (i + maxDotsPerColumn[position] >= 4 || drawFullGrid) { + if (prevFrame && prevFrame[position] && prevFrame[position][i]) { + if (frame[i] !== prevFrame[position][i]) { + // subsequent draw + g.clearRect((columnPos + colpos / 2) - 15, pos - 15, (columnPos + colpos / 2) + 20, pos + 20); + if (frame[i]) { + drawDot('fillCircle'); + } else { + drawDot('drawCircle'); + } } - pos += colpos; + } else { + // First draw + if (frame[i]) { + drawDot('fillCircle'); + } else { + drawDot('drawCircle'); + } + } } + pos += colpos; + } }; const drawClock = () => { - const data = getCurrentTime().map(findBinary); - for (let i = 0; i < data.length; i += 1) { - drawColumn(i, data[i]); - } - prevFrame = data; + const data = getCurrentTime().map(findBinary); + for (let i = 0; i < data.length; i += 1) { + drawColumn(i, data[i]); + } + prevFrame = data; }; // Themes const drawTheme = (idx) => () => { - idx += 1; - const themes = [ - [[0, 0, 0], [1, 1, 1]], - [[1, 1, 1], [0, 0, 0]], - [[0, 0, 0], [1, 0, 0]], - [[0, 0, 0], [0, 1, 0]], - [[0, 0, 0], [0, 0, 1]], - ]; - if (idx >= themes.length) idx = 0; - const color = themes[idx]; - g.setBgColor.apply(g, color[0]); - g.setColor.apply(g, color[1]); - g.clear(); + idx += 1; + const themes = [ + [[0, 0, 0], [1, 1, 1]], + [[1, 1, 1], [0, 0, 0]], + [[0, 0, 0], [1, 0, 0]], + [[0, 0, 0], [0, 1, 0]], + [[0, 0, 0], [0, 0, 1]], + ]; + if (idx >= themes.length) idx = 0; + const color = themes[idx]; + g.setBgColor.apply(g, color[0]); + g.setColor.apply(g, color[1]); + g.clear(); }; const nextTheme = drawTheme(0); setWatch(() => { - prevFrame = []; - Bangle.beep(); - nextTheme(); + prevFrame = []; + Bangle.beep(); + nextTheme(); }, BTN1, { repeat: true }); Bangle.on('lcdPower', on => { - if (on) drawClock(); + if (on) drawClock(); }); g.clear(); diff --git a/apps/beebclock/beebclock.js b/apps/beebclock/beebclock.js index 7b071c22d..6ed4f532e 100644 --- a/apps/beebclock/beebclock.js +++ b/apps/beebclock/beebclock.js @@ -10,388 +10,388 @@ require('FontTeletext10x18Ascii').add(Graphics); // Double height text Graphics.prototype.drawStringDH = function (txt, px, py, align, gw) { - let g2 = Graphics.createArrayBuffer(gw,18,1,{msb:true}); - g2.setFontTeletext10x18Ascii(); - let w = g2.stringWidth(txt); - let c = (w+3)>>2; - g2.drawString(txt); - let img = {width:w,height:1,transparent:0,buffer:new ArrayBuffer(c)}; - let a = new Uint8Array(img.buffer); + let g2 = Graphics.createArrayBuffer(gw,18,1,{msb:true}); + g2.setFontTeletext10x18Ascii(); + let w = g2.stringWidth(txt); + let c = (w+3)>>2; + g2.drawString(txt); + let img = {width:w,height:1,transparent:0,buffer:new ArrayBuffer(c)}; + let a = new Uint8Array(img.buffer); - let x; - switch (align) { + let x; + switch (align) { case 'C': x = px + (gw - w)/2; break; case 'R': x = gw - w + px; break; default: x = px; - } + } - for (var y=0;y<18;y++) { - a.set(new Uint8Array(g2.buffer,gw*y/8,c)); - this.drawImage(img,x,py+y*2); - this.drawImage(img,x,py+1+y*2); - } + for (var y=0;y<18;y++) { + a.set(new Uint8Array(g2.buffer,gw*y/8,c)); + this.drawImage(img,x,py+y*2); + this.drawImage(img,x,py+1+y*2); + } }; // Fill rectangle rotated around the centre Graphics.prototype.fillRotRect = function (sina, cosa, cx, cy, x0, x1, y0, y1) { - let fn = Math.ceil; - return this.fillPoly([ - fn(cx - x0*cosa + y0*sina), fn(cy - x0*sina - y0*cosa), - fn(cx - x1*cosa + y0*sina), fn(cy - x1*sina - y0*cosa), - fn(cx - x1*cosa + y1*sina), fn(cy - x1*sina - y1*cosa), - fn(cx - x0*cosa + y1*sina), fn(cy - x0*sina - y1*cosa) - ]); + let fn = Math.ceil; + return this.fillPoly([ + fn(cx - x0*cosa + y0*sina), fn(cy - x0*sina - y0*cosa), + fn(cx - x1*cosa + y0*sina), fn(cy - x1*sina - y0*cosa), + fn(cx - x1*cosa + y1*sina), fn(cy - x1*sina - y1*cosa), + fn(cx - x0*cosa + y1*sina), fn(cy - x0*sina - y1*cosa) + ]); }; // Draw a line from r1,a to r2,a relative to cx+cy Graphics.prototype.drawRotLine = function (sina, cosa, cx, cy, r1, r2) { - return this.drawLine( - cx + r1*sina, cy - r1*cosa, - cx + r2*sina, cy - r2*cosa - ); + return this.drawLine( + cx + r1*sina, cy - r1*cosa, + cx + r2*sina, cy - r2*cosa + ); }; (function(g) { - // Display modes - // - // 0: full-screen - // 1: with widgets - // 2: centred on Bangle (v.1), no widgets or time/date - // 3: centred with time above - // 4: centred with date above - // 5: centred with time and date above - let mode; + // Display modes + // + // 0: full-screen + // 1: with widgets + // 2: centred on Bangle (v.1), no widgets or time/date + // 3: centred with time above + // 4: centred with date above + // 5: centred with time and date above + let mode; - // R1, R2: Outer and inner radii of hour marks - // RC1, RC2: Outer and inner radii of hub - // CX, CY: Centre location, relative to buffer (not screen, necessarily) - // HW2, MW2: Half-width of hour and minute hand - // HR, MR: Length of hour and minute hand, relative to CX,CY - // M: Half-width of gap in hour marks - // HSCALE: Half-width of hour mark as function(0 { + const fw = R1 * 2; + const fh = R1 * 2; + const fw2 = R1; + const fh2 = R1; + let hs = []; + + // Wipe the image and start with white + G.clear(); + G.setColor(1,1,1); + + // Draw the hour marks. for (let h=1; h<=12; h++) { - const a = Math.PI * h / 6; - ss[h] = Math.sin(a); - cs[h] = Math.cos(a); + hs[h] = HSCALE(h); + G.fillRotRect(ss[h], cs[h], CX, CY, -hs[h], hs[h], R2, R1); + } - // Draw the face with hour and minute hand. Ideally, we'd separate - // the face from the hands and double-buffer, but memory is limited, - // so we buffer once and minute, and draw the second hand dynamically - // (with a bit of flicker) - const drawFace = (G) => { - const fw = R1 * 2; - const fh = R1 * 2; - const fw2 = R1; - const fh2 = R1; - let hs = []; + // Draw the hub + G.fillCircle(CX, CY, RC1); - // Wipe the image and start with white - G.clear(); - G.setColor(1,1,1); + // Black + G.setColor(0,0,0); - // Draw the hour marks. - for (let h=1; h<=12; h++) { - hs[h] = HSCALE(h); - G.fillRotRect(ss[h], cs[h], CX, CY, -hs[h], hs[h], R2, R1); + // Clear the centre of the hub + G.fillCircle(CX, CY, RC2); - } + // Draw the gap in the hour marks + for (let h=1; h<=12; h++) { + G.fillRotRect(ss[h], cs[h], CX, CY, -M, M, R2-1, R1+1); + } - // Draw the hub - G.fillCircle(CX, CY, RC1); + // Back to white for future draw operations + G.setColor(1,1,1); - // Black - G.setColor(0,0,0); + // While the buffer remains full-screen, we may trim out the + // bottom of the image so we can shift the whole thing down for + // widgets. + const img = {width:GW,height:GH-TM,buffer:G.buffer}; + return img; + }; - // Clear the centre of the hub - G.fillCircle(CX, CY, RC2); + let hours, minutes, seconds, date; - // Draw the gap in the hour marks - for (let h=1; h<=12; h++) { - G.fillRotRect(ss[h], cs[h], CX, CY, -M, M, R2-1, R1+1); - } + // Schedule event for calling at the start of the next second + const inOneSecond = (cb) => { + let now = new Date(); + clearTimeout(); + setTimeout(cb, 1000 - now.getMilliseconds()); + }; - // Back to white for future draw operations - G.setColor(1,1,1); + // Schedule event for calling at the start of the next minute + const inOneMinute = (cb) => { + let now = new Date(); + clearTimeout(); + setTimeout(cb, 60000 - (now.getSeconds() * 1000 + now.getMilliseconds())); + }; - // While the buffer remains full-screen, we may trim out the - // bottom of the image so we can shift the whole thing down for - // widgets. - const img = {width:GW,height:GH-TM,buffer:G.buffer}; - return img; - }; + // Draw a fat hour/minute hand + const drawHand = (G, a, w2, r1, r2) => + G.fillRotRect(Math.sin(a), Math.cos(a), CX, CY, -w2, w2, r1, r2); - let hours, minutes, seconds, date; + // Redraw function + const drawAll = (force) => { + let now = new Date(); - // Schedule event for calling at the start of the next second - const inOneSecond = (cb) => { - let now = new Date(); - clearTimeout(); - setTimeout(cb, 1000 - now.getMilliseconds()); - }; + if (!faceImg) force = true; - // Schedule event for calling at the start of the next minute - const inOneMinute = (cb) => { - let now = new Date(); - clearTimeout(); - setTimeout(cb, 60000 - (now.getSeconds() * 1000 + now.getMilliseconds())); - }; + let face_changed = force; + let date_changed = false; - // Draw a fat hour/minute hand - const drawHand = (G, a, w2, r1, r2) => - G.fillRotRect(Math.sin(a), Math.cos(a), CX, CY, -w2, w2, r1, r2); + tmp = hours; + hours = now.getHours(); + if (tmp !== hours) + face_changed = true; - // Redraw function - const drawAll = (force) => { - let now = new Date(); + tmp = minutes; + minutes = now.getMinutes(); + if (tmp !== minutes) + face_changed = true; - if (!faceImg) force = true; + // If the face has been updated and/or needs a redraw, + // face_changed is true. - let face_changed = force; - let date_changed = false; + let time_changed = face_changed; - tmp = hours; - hours = now.getHours(); - if (tmp !== hours) - face_changed = true; + // If the screen needs an update, regardless of whether the face + // needs a redraw, time_changed is true. - tmp = minutes; - minutes = now.getMinutes(); - if (tmp !== minutes) - face_changed = true; + if (with_seconds) { + // If we're going by second, we always need an update. + seconds = now.getSeconds(); + time_changed = true; + } - // If the face has been updated and/or needs a redraw, - // face_changed is true. + if (with_digital_date) { + // See if the date has changed. If it has, then we need a + // full-blown redraw of the screen and the face, plus text. + tmp = date; + date = now.getDate(); + if (tmp !== date) { + date_changed = true; + face_changed = true; // Should have changed anyway with hour/minute rollover + } + } - let time_changed = face_changed; + if (face_changed) { + // Redraw the face and hands onto the buffer G1. + faceImg = drawFace(G1); + drawHand(G1, Math.PI*hours/6, HW2, RC1, HR); + drawHand(G1, Math.PI*minutes/30, MW2, RC1, MR); + } - // If the screen needs an update, regardless of whether the face - // needs a redraw, time_changed is true. + // Has the time updated? If so, we'll need to draw something. + if (time_changed) { - if (with_seconds) { - // If we're going by second, we always need an update. - seconds = now.getSeconds(); - time_changed = true; + // Are we adding text? + if (with_digital_date || with_digital_time) { + + // Construct the date/time text to add above the face + let d = now.toString(); + let da = d.toString().split(" "); + let txt; + + if (with_digital_time) { + txt = da[4].substr(0, 5); + if (with_digital_date) + G1.drawStringDH(txt+',', 24, 0, 'L', GW); + else + G1.drawStringDH(txt, 0, 0, 'C', GW); } if (with_digital_date) { - // See if the date has changed. If it has, then we need a - // full-blown redraw of the screen and the face, plus text. - tmp = date; - date = now.getDate(); - if (tmp !== date) { - date_changed = true; - face_changed = true; // Should have changed anyway with hour/minute rollover - } + let txt = [da[0], da[1], da[2]].join(" "); + if (with_digital_time) + G1.drawStringDH(txt, -24, 0, 'R', GW); + else + G1.drawStringDH(txt, 0, 0, 'C', GW); } + } - if (face_changed) { - // Redraw the face and hands onto the buffer G1. - faceImg = drawFace(G1); - drawHand(G1, Math.PI*hours/6, HW2, RC1, HR); - drawHand(G1, Math.PI*minutes/30, MW2, RC1, MR); - } + // If the time has updated, we need to _at least_ draw the + // image to the screen. + g.setColor(1,1,1); + g.drawImage({width:GW, + height:GH-TM, + buffer:G1.buffer}, 0, TM); - // Has the time updated? If so, we'll need to draw something. - if (time_changed) { + // and possibly add the second hand + if (with_seconds) { + let a = 2.0 * Math.PI * seconds / 60.0; + g.drawRotLine(Math.sin(a), Math.cos(a), CX, CY+TM, RC1, R1); + } - // Are we adding text? - if (with_digital_date || with_digital_time) { - - // Construct the date/time text to add above the face - let d = now.toString(); - let da = d.toString().split(" "); - let txt; - - if (with_digital_time) { - txt = da[4].substr(0, 5); - if (with_digital_date) - G1.drawStringDH(txt+',', 24, 0, 'L', GW); - else - G1.drawStringDH(txt, 0, 0, 'C', GW); - } - - if (with_digital_date) { - let txt = [da[0], da[1], da[2]].join(" "); - if (with_digital_time) - G1.drawStringDH(txt, -24, 0, 'R', GW); - else - G1.drawStringDH(txt, 0, 0, 'C', GW); - } - } - - // If the time has updated, we need to _at least_ draw the - // image to the screen. - g.setColor(1,1,1); - g.drawImage({width:GW, - height:GH-TM, - buffer:G1.buffer}, 0, TM); - - // and possibly add the second hand - if (with_seconds) { - let a = 2.0 * Math.PI * seconds / 60.0; - g.drawRotLine(Math.sin(a), Math.cos(a), CX, CY+TM, RC1, R1); - } - - // Clock chime on the hour. - if (hours >= 0 && minutes === 0) - try { - Bangle.buzz(); - } catch (e) { } - - // And draw widgets if we're in that mode - if (with_widgets) - Bangle.drawWidgets(); - } - - // Schedule to repeat this. A `setTimeout(1000)` isn't good - // enough, as all the above might've taken some milliseconds and - // we don't want to drift. - if (with_seconds) - inOneSecond(drawAll); - else - inOneMinute(drawAll); - }; - - const setButtons = () => { - const opts = { repeat: true, edge:'rising', debounce:30}; - - // BTN1: enable/disable second hand - setWatch(changeSeconds, BTN1, opts); - - // BTN2: return to launcher - setWatch(Bangle.showLauncher, BTN2, { repeat:false, edge:'falling' }); - - // BTN3: change display mode - setWatch(function () { ++mode; setMode(); drawAll(true); }, BTN3, opts); - }; - - // Load display parameters based on `mode` - const setMode = () => { - // Normalize mode to 0 <= mode <= 5 - mode = (6+mode) % 6; - - // [R1, R2, RC1, RC2, HW2, MW3, HR, MR, M, HSCALE] = - const scales = [ - [120, 84, 17, 12.4, 4.6, 2.2, 8, 2, 1, h => (3.0 + Math.ceil(h/1.5)) ], - [102, 70, 14.6, 10.7, 3.88, 1.8, 8, 2, 1, h => (2.4 + Math.ceil(h/1.6)) ], - ]; - - if (mode < 3) { - // Face without time/date text. Might have widgets though. - with_digital_time = with_digital_date = false; - with_widgets = (mode == 1); - } - else { - // Face with time/date text, but no widgets - with_digital_time = (mode-2)&1; - with_digital_date = (mode-2)&2; - with_widgets = false; - } - - // Destructure the array to the global display parameters - let arr = scales[mode > 0 ? 1 : 0]; - R1 = arr[0]; - R2 = arr[1]; - RC1 = arr[2]; - RC2 = arr[3]; - HW2 = arr[4]; - MW2 = arr[5]; - HR = R2 - arr[6]; - MR = R1 - arr[7]; - M = arr[8]; - HSCALE = arr[9]; - TM = with_widgets ? 36 : 0; - - CX = GW/2; - CY = R1; - - // If we're in the small-face + text regime, we're going to buffer - // the full screen but draw the clock face further down to give - // space for the text. - // - // Compare with modes 0 (full-screen) and 1 (with_widgets==true) - // where the face is drawn at the top of the buffer, but drawn - // lower down the screen (so CY doesn't move) - if (mode > 1) { - CY += 36; - } - - // We only don't bother redrawing the face from modes 2 to 5, as - // they're the same. - if (!faceImg || mode<3) { - faceImg = undefined; - } - - // Store the settings for next time + // Clock chime on the hour. + if (hours >= 0 && minutes === 0) try { - storage.writeJSON(filename, [mode,with_seconds]); - } catch (e) { - console.log(e); - } + Bangle.buzz(); + } catch (e) { } - // Clear the screen: we need to make sure all parts are cleaned off. - g.clear(); - }; - - const changeSeconds = () => { - with_seconds = !with_seconds; - drawAll(true); - }; - - Bangle.loadWidgets(); - - // Restore mode - try { - conf = storage.readJSON(filename); - mode = conf[0]; - with_seconds = conf[1]; - } catch (e) { - console.log(e); - mode = 1; + // And draw widgets if we're in that mode + if (with_widgets) + Bangle.drawWidgets(); } - setButtons(); - setMode(); - drawAll(); + // Schedule to repeat this. A `setTimeout(1000)` isn't good + // enough, as all the above might've taken some milliseconds and + // we don't want to drift. + if (with_seconds) + inOneSecond(drawAll); + else + inOneMinute(drawAll); + }; - Bangle.on('lcdPower', (on) => { - if (on) { - Bangle.loadWidgets(); - Bangle.drawWidgets(); - drawAll(); - } else { - clearTimeout(); - } - }); + const setButtons = () => { + const opts = { repeat: true, edge:'rising', debounce:30}; + + // BTN1: enable/disable second hand + setWatch(changeSeconds, BTN1, opts); + + // BTN2: return to launcher + setWatch(Bangle.showLauncher, BTN2, { repeat:false, edge:'falling' }); + + // BTN3: change display mode + setWatch(function () { ++mode; setMode(); drawAll(true); }, BTN3, opts); + }; + + // Load display parameters based on `mode` + const setMode = () => { + // Normalize mode to 0 <= mode <= 5 + mode = (6+mode) % 6; + + // [R1, R2, RC1, RC2, HW2, MW3, HR, MR, M, HSCALE] = + const scales = [ + [120, 84, 17, 12.4, 4.6, 2.2, 8, 2, 1, h => (3.0 + Math.ceil(h/1.5)) ], + [102, 70, 14.6, 10.7, 3.88, 1.8, 8, 2, 1, h => (2.4 + Math.ceil(h/1.6)) ], + ]; + + if (mode < 3) { + // Face without time/date text. Might have widgets though. + with_digital_time = with_digital_date = false; + with_widgets = (mode == 1); + } + else { + // Face with time/date text, but no widgets + with_digital_time = (mode-2)&1; + with_digital_date = (mode-2)&2; + with_widgets = false; + } + + // Destructure the array to the global display parameters + let arr = scales[mode > 0 ? 1 : 0]; + R1 = arr[0]; + R2 = arr[1]; + RC1 = arr[2]; + RC2 = arr[3]; + HW2 = arr[4]; + MW2 = arr[5]; + HR = R2 - arr[6]; + MR = R1 - arr[7]; + M = arr[8]; + HSCALE = arr[9]; + TM = with_widgets ? 36 : 0; + + CX = GW/2; + CY = R1; + + // If we're in the small-face + text regime, we're going to buffer + // the full screen but draw the clock face further down to give + // space for the text. + // + // Compare with modes 0 (full-screen) and 1 (with_widgets==true) + // where the face is drawn at the top of the buffer, but drawn + // lower down the screen (so CY doesn't move) + if (mode > 1) { + CY += 36; + } + + // We only don't bother redrawing the face from modes 2 to 5, as + // they're the same. + if (!faceImg || mode<3) { + faceImg = undefined; + } + + // Store the settings for next time + try { + storage.writeJSON(filename, [mode,with_seconds]); + } catch (e) { + console.log(e); + } + + // Clear the screen: we need to make sure all parts are cleaned off. + g.clear(); + }; + + const changeSeconds = () => { + with_seconds = !with_seconds; + drawAll(true); + }; + + Bangle.loadWidgets(); + + // Restore mode + try { + conf = storage.readJSON(filename); + mode = conf[0]; + with_seconds = conf[1]; + } catch (e) { + console.log(e); + mode = 1; + } + + setButtons(); + setMode(); + drawAll(); + + Bangle.on('lcdPower', (on) => { + if (on) { + Bangle.loadWidgets(); + Bangle.drawWidgets(); + drawAll(); + } else { + clearTimeout(); + } + }); })(g); diff --git a/apps/berlinc/berlin-clock.js b/apps/berlinc/berlin-clock.js index 0c8e2d076..1061b6cd3 100644 --- a/apps/berlinc/berlin-clock.js +++ b/apps/berlinc/berlin-clock.js @@ -6,43 +6,43 @@ rowHeight = height/4; rowlights = []; function drawBerlinClock() { - var now = new Date(); - rowlights[0] = Math.floor(now.getHours() / 5); - rowlights[1] = now.getHours() % 5; - rowlights[2] = Math.floor(now.getMinutes() / 5); - rowlights[3] = now.getMinutes() % 5; + var now = new Date(); + rowlights[0] = Math.floor(now.getHours() / 5); + rowlights[1] = now.getHours() % 5; + rowlights[2] = Math.floor(now.getMinutes() / 5); + rowlights[3] = now.getMinutes() % 5; - g.clear(); + g.clear(); - g.drawRect(0,0,width,height); - for (row = 0 ; row < 4 ; row++) { - nfields = fields[row]; - boxWidth = width/nfields; + g.drawRect(0,0,width,height); + for (row = 0 ; row < 4 ; row++) { + nfields = fields[row]; + boxWidth = width/nfields; - for (col = 0 ; col < nfields ; col++) { - x1 = col*boxWidth; - y1 = row*rowHeight; - x2 = (col+1)*boxWidth; - y2 = (row+1)*rowHeight; + for (col = 0 ; col < nfields ; col++) { + x1 = col*boxWidth; + y1 = row*rowHeight; + x2 = (col+1)*boxWidth; + y2 = (row+1)*rowHeight; - g.setColor(1,1,1); - g.drawRect(x1,y1,x2,y2); - if (col { g.clear(); if (on) { Bangle.drawWidgets(); - // call your app function here - drawBerlinClock(); -}}); + // call your app function here + drawBerlinClock(); + }}); // refesh every 15 sec setInterval(drawBerlinClock, 15E3); diff --git a/apps/blackjack/blackjack.app.js b/apps/blackjack/blackjack.app.js index dc5d35494..ccc437e58 100644 --- a/apps/blackjack/blackjack.app.js +++ b/apps/blackjack/blackjack.app.js @@ -1,18 +1,18 @@ const Clubs = { width : 48, height : 48, bpp : 1, - buffer : require("heatshrink").decompress(atob("ACcP+AFDn/8Aod//wFD///AgUBAoOAApsDAoPAAr4vLI4pTEgP8L4M/wEH/5rB//gh//x/x//wj//9/3//4n4iBAAIZBAol/Aof+Apv5z4FP+OPAo41BAoX8I4Pj45HBAoPD4YFBLIOD4JZBRAMD4CKC/AFBj59Cg/gQYYFXAB4=")) + buffer : require("heatshrink").decompress(atob("ACcP+AFDn/8Aod//wFD///AgUBAoOAApsDAoPAAr4vLI4pTEgP8L4M/wEH/5rB//gh//x/x//wj//9/3//4n4iBAAIZBAol/Aof+Apv5z4FP+OPAo41BAoX8I4Pj45HBAoPD4YFBLIOD4JZBRAMD4CKC/AFBj59Cg/gQYYFXAB4=")) }; const Spades = { width : 48, height : 48, bpp : 1, - buffer : require("heatshrink").decompress(atob("ABsBwAFDgfAAocH8AFDh/wAocf/AFDn/8Aod//wFD///FwYFBGAUDAoIwCg4FBGAUPAoIwCj4FBGAU/AoIwCv4FBGAQEBGAQuCGAQuCGAQFLHQQ8CAupHLL4prB+fPTgU/8fHVwbLLApbXFbpYFLdIoADA==")) + buffer : require("heatshrink").decompress(atob("ABsBwAFDgfAAocH8AFDh/wAocf/AFDn/8Aod//wFD///FwYFBGAUDAoIwCg4FBGAUPAoIwCj4FBGAU/AoIwCv4FBGAQEBGAQuCGAQuCGAQFLHQQ8CAupHLL4prB+fPTgU/8fHVwbLLApbXFbpYFLdIoADA==")) }; 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, - buffer : require("heatshrink").decompress(atob("AHUFC60M4AXV5nFIyvM5hGVC4JIUCwJIUIwRIUIwRIUCwZISIwgABqBGUJCQWFPKBGGJCFcC455OCw4wOOox5QIxB5NOpBIOFxZ5LCxYwKOpQwMIxh5KOxipLL6xgNR5QwMX5TvXPJZ1JJBpGLPJR1LJBZGNPJIWOJA5GOPJB1NJBIWQPIpGRJApGRPIoWSJAa8PJA5GTJAYWUJAJGVAAJGVAHo=")) - }; + buffer : require("heatshrink").decompress(atob("AHUFC60M4AXV5nFIyvM5hGVC4JIUCwJIUIwRIUIwRIUCwZISIwgABqBGUJCQWFPKBGGJCFcC455OCw4wOOox5QIxB5NOpBIOFxZ5LCxYwKOpQwMIxh5KOxipLL6xgNR5QwMX5TvXPJZ1JJBpGLPJR1LJBZGNPJIWOJA5GOPJB1NJBIWQPIpGRJApGRPIoWSJAa8PJA5GTJAYWUJAJGVAAJGVAHo=")) +}; var deck = []; @@ -20,168 +20,168 @@ var player = {Hand:[]}; var computer = {Hand:[]}; function createDeck() { - var suits = ["Spades", "Hearts", "Diamonds", "Clubs"]; - var values = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]; + var suits = ["Spades", "Hearts", "Diamonds", "Clubs"]; + var values = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]; - var dck = []; - for (var i = 0 ; i < values.length; i++) { - for(var x = 0; x < suits.length; x++) { - dck.push({ Value: values[i], Suit: suits[x] }); - } + var dck = []; + for (var i = 0 ; i < values.length; i++) { + for(var x = 0; x < suits.length; x++) { + dck.push({ Value: values[i], Suit: suits[x] }); } - return dck; + } + return dck; } function shuffle(a) { - var j, x, i; - for (i = a.length - 1; i > 0; i--) { - j = Math.floor(Math.random() * (i + 1)); - x = a[i]; - a[i] = a[j]; - a[j] = x; - } - return a; + var j, x, i; + for (i = a.length - 1; i > 0; i--) { + j = Math.floor(Math.random() * (i + 1)); + x = a[i]; + a[i] = a[j]; + a[j] = x; + } + return a; } function EndGameMessdage(msg){ - g.drawString(msg, 155, 200); - setTimeout(function(){ - startGame(); - }, 2500); + g.drawString(msg, 155, 200); + setTimeout(function(){ + startGame(); + }, 2500); } function hitMe() { - player.Hand.push(deck.pop()); - renderOnScreen(1); - var playerWeight = calcWeight(player.Hand, 0); + player.Hand.push(deck.pop()); + renderOnScreen(1); + var playerWeight = calcWeight(player.Hand, 0); - if(playerWeight == 21) - EndGameMessdage('WINNER'); - else if(playerWeight > 21) - EndGameMessdage('LOOSER'); + if(playerWeight == 21) + EndGameMessdage('WINNER'); + else if(playerWeight > 21) + EndGameMessdage('LOOSER'); } function calcWeight(hand, hideCard) { - if(hideCard === 1) { - if (hand[0].Value == "J" || hand[0].Value == "Q" || hand[0].Value == "K") - return "10 +"; - else if (hand[0].Value == "A") - return "11 +"; - else - return parseInt(hand[0].Value) +" +"; + if(hideCard === 1) { + if (hand[0].Value == "J" || hand[0].Value == "Q" || hand[0].Value == "K") + return "10 +"; + else if (hand[0].Value == "A") + return "11 +"; + else + return parseInt(hand[0].Value) +" +"; + } + else { + var weight = 0; + for(i=0; i 21 || bangleWeight < playerWeight) - EndGameMessdage('WINNER'); - else if(bangleWeight > playerWeight) - EndGameMessdage('LOOSER'); + if (bangleWeight == playerWeight) + EndGameMessdage('TIES'); + else if(playerWeight==21 || bangleWeight > 21 || bangleWeight < playerWeight) + EndGameMessdage('WINNER'); + else if(bangleWeight > playerWeight) + EndGameMessdage('LOOSER'); } function renderOnScreen(HideCard) { - const fontName = "6x8"; + const fontName = "6x8"; - g.clear(); // clear screen - g.reset(); // default draw styles - g.setFont(fontName, 1); + g.clear(); // clear screen + g.reset(); // default draw styles + g.setFont(fontName, 1); - g.drawString('RST', 220, 35); - g.drawString('Hit', 60, 230); - g.drawString('Stand', 165, 230); + g.drawString('RST', 220, 35); + g.drawString('Hit', 60, 230); + g.drawString('Stand', 165, 230); - g.setFont(fontName, 3); - for(i=0; i { - devices.forEach(device =>{ - let deviceName = device.id.substring(0,17); + devices.forEach(device =>{ + let deviceName = device.id.substring(0,17); - if (device.name) { - deviceName = device.name; - } + if (device.name) { + deviceName = device.name; + } - menu[deviceName] = () => showDeviceInfo(device); - }); - showMainMenu(menu); + menu[deviceName] = () => showDeviceInfo(device); + }); + showMainMenu(menu); }, { active: true }); } diff --git a/apps/blescan/blescan.js b/apps/blescan/blescan.js index b3c1dc721..0a85113bd 100644 --- a/apps/blescan/blescan.js +++ b/apps/blescan/blescan.js @@ -22,22 +22,22 @@ function draw() { function scan() { NRF.findDevices(devices => { - for (let device of devices) { + for (let device of devices) { - // Only display devices that advertise a name + // Only display devices that advertise a name - if (device.name) { - // Remove no devices found message if it is present - if (menu[NODEVICE]) { - delete menu[NODEVICE]; - } - menu[device.name] = { - value : device.rssi, - onchange : () => {} - }; + if (device.name) { + // Remove no devices found message if it is present + if (menu[NODEVICE]) { + delete menu[NODEVICE]; } + menu[device.name] = { + value : device.rssi, + onchange : () => {} + }; } - draw(); + } + draw(); }, { active: true }); } diff --git a/apps/blobclk/clock-blob.js b/apps/blobclk/clock-blob.js index 48187d23c..1d85bc65e 100644 --- a/apps/blobclk/clock-blob.js +++ b/apps/blobclk/clock-blob.js @@ -1,103 +1,103 @@ const buf = Graphics.createArrayBuffer(144,200,1,{msb:true}); const NUMBERS = [ - [1,1,1,1,3,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1],//0 - [0,1,1,1,3,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1],//1 - [1,1,1,1,3,0,0,1,1,1,2,1,1,1,4,1,1,1,0,0,1,1,1,1,1],//2 - [1,1,1,1,3,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1],//3 - [1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,5,1,1,1,1,0,0,1,1,1],//4 - [1,1,1,1,1,1,1,1,0,0,5,1,1,1,3,0,0,1,1,1,1,1,1,1,1],//5 - [1,1,1,1,1,1,1,1,0,0,1,1,1,1,3,1,1,0,1,1,1,1,1,1,1],//6 - [1,1,1,1,3,0,0,1,1,1,0,2,1,1,1,0,1,1,1,0,0,1,1,1,0],//7 - [1,1,1,1,3,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1],//8 - [1,1,1,1,3,1,1,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1] //9 + [1,1,1,1,3,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1],//0 + [0,1,1,1,3,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,1],//1 + [1,1,1,1,3,0,0,1,1,1,2,1,1,1,4,1,1,1,0,0,1,1,1,1,1],//2 + [1,1,1,1,3,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1],//3 + [1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,5,1,1,1,1,0,0,1,1,1],//4 + [1,1,1,1,1,1,1,1,0,0,5,1,1,1,3,0,0,1,1,1,1,1,1,1,1],//5 + [1,1,1,1,1,1,1,1,0,0,1,1,1,1,3,1,1,0,1,1,1,1,1,1,1],//6 + [1,1,1,1,3,0,0,1,1,1,0,2,1,1,1,0,1,1,1,0,0,1,1,1,0],//7 + [1,1,1,1,3,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1],//8 + [1,1,1,1,3,1,1,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1] //9 ]; let intervalRef = null; let digits = [-1,-1,-1,-1,-1,-1]; function flip() { - g.setColor(1,1,1); - g.drawImage({width:buf.getWidth(),height:buf.getHeight(),buffer:buf.buffer},55,26); + g.setColor(1,1,1); + g.drawImage({width:buf.getWidth(),height:buf.getHeight(),buffer:buf.buffer},55,26); } function drawPixel(ox,oy,x,y,r,p) { - let x1 = ox+x*(r*2+1); - let y1 = oy+y*(r*2+1); - let xmid = x1+r; - let ymid = y1+r; - let x2 = xmid+r; - let y2 = ymid+r; - if (p > 0) { - if (p > 1) { - buf.setColor(0,0,0); - buf.fillRect(x1,y1,x2,y2); - } - buf.setColor(1,1,1); - } else { - buf.setColor(0,0,0); - } - if (p < 2) { - buf.fillRect(x1,y1,x2,y2); - } else if (p === 2) { - buf.fillPoly([xmid,y1,x2,y1,x2,y2,x1,y2,x1,ymid]); - } else if (p === 3) { - buf.fillPoly([x1,y1,xmid,y1,x2,ymid,x2,y2,x1,y2]); - } else if (p === 4) { - buf.fillPoly([x1,y1,x2,y1,x2,ymid,xmid,y2,x1,y2]); - } else if (p === 5) { - buf.fillPoly([x1,y1,x2,y1,x2,y2,xmid,y2,x1,ymid]); + let x1 = ox+x*(r*2+1); + let y1 = oy+y*(r*2+1); + let xmid = x1+r; + let ymid = y1+r; + let x2 = xmid+r; + let y2 = ymid+r; + if (p > 0) { + if (p > 1) { + buf.setColor(0,0,0); + buf.fillRect(x1,y1,x2,y2); } + buf.setColor(1,1,1); + } else { + buf.setColor(0,0,0); + } + if (p < 2) { + buf.fillRect(x1,y1,x2,y2); + } else if (p === 2) { + buf.fillPoly([xmid,y1,x2,y1,x2,y2,x1,y2,x1,ymid]); + } else if (p === 3) { + buf.fillPoly([x1,y1,xmid,y1,x2,ymid,x2,y2,x1,y2]); + } else if (p === 4) { + buf.fillPoly([x1,y1,x2,y1,x2,ymid,xmid,y2,x1,y2]); + } else if (p === 5) { + buf.fillPoly([x1,y1,x2,y1,x2,y2,xmid,y2,x1,ymid]); + } } function redraw() { - let time = new Date(); - let hours = time.getHours(); - let mins = time.getMinutes(); - let secs = time.getSeconds(); + let time = new Date(); + let hours = time.getHours(); + let mins = time.getMinutes(); + let secs = time.getSeconds(); - let newDigits = [Math.floor(hours/10),hours%10,Math.floor(mins/10),mins%10,Math.floor(secs/10),secs%10]; + let newDigits = [Math.floor(hours/10),hours%10,Math.floor(mins/10),mins%10,Math.floor(secs/10),secs%10]; - for (var p = 0;p<25;p++) { - var px = p%5; - var py = Math.floor(p/5); - if (digits[0] === -1 || NUMBERS[newDigits[0]][p] !== NUMBERS[digits[0]][p] ) { - drawPixel(0,20,px,py,6,NUMBERS[newDigits[0]][p]); - } - if (digits[1] === -1 || NUMBERS[newDigits[1]][p] !== NUMBERS[digits[1]][p] ) { - drawPixel(78,20,px,py,6,NUMBERS[newDigits[1]][p]); - } - if (digits[2] === -1 || NUMBERS[newDigits[2]][p] !== NUMBERS[digits[2]][p] ) { - drawPixel(0,92,px,py,6,NUMBERS[newDigits[2]][p]); - } - if (digits[3] === -1 || NUMBERS[newDigits[3]][p] !== NUMBERS[digits[3]][p] ) { - drawPixel(78,92,px,py,6,NUMBERS[newDigits[3]][p]); - } - if (digits[4] === -1 || NUMBERS[newDigits[4]][p] !== NUMBERS[digits[4]][p] ) { - drawPixel(69,164,px,py,3,NUMBERS[newDigits[4]][p]); - } - if (digits[5] === -1 || NUMBERS[newDigits[5]][p] !== NUMBERS[digits[5]][p] ) { - drawPixel(108,164,px,py,3,NUMBERS[newDigits[5]][p]); - } + for (var p = 0;p<25;p++) { + var px = p%5; + var py = Math.floor(p/5); + if (digits[0] === -1 || NUMBERS[newDigits[0]][p] !== NUMBERS[digits[0]][p] ) { + drawPixel(0,20,px,py,6,NUMBERS[newDigits[0]][p]); } - digits = newDigits; - flip(); + if (digits[1] === -1 || NUMBERS[newDigits[1]][p] !== NUMBERS[digits[1]][p] ) { + drawPixel(78,20,px,py,6,NUMBERS[newDigits[1]][p]); + } + if (digits[2] === -1 || NUMBERS[newDigits[2]][p] !== NUMBERS[digits[2]][p] ) { + drawPixel(0,92,px,py,6,NUMBERS[newDigits[2]][p]); + } + if (digits[3] === -1 || NUMBERS[newDigits[3]][p] !== NUMBERS[digits[3]][p] ) { + drawPixel(78,92,px,py,6,NUMBERS[newDigits[3]][p]); + } + if (digits[4] === -1 || NUMBERS[newDigits[4]][p] !== NUMBERS[digits[4]][p] ) { + drawPixel(69,164,px,py,3,NUMBERS[newDigits[4]][p]); + } + if (digits[5] === -1 || NUMBERS[newDigits[5]][p] !== NUMBERS[digits[5]][p] ) { + drawPixel(108,164,px,py,3,NUMBERS[newDigits[5]][p]); + } + } + digits = newDigits; + flip(); } function clearTimers() { - if(intervalRef) { - clearInterval(intervalRef); - intervalRef = undefined; - } + if(intervalRef) { + clearInterval(intervalRef); + intervalRef = undefined; + } } function startTimers() { - g.clear(); - Bangle.drawWidgets(); - intervalRef = setInterval(redraw,1000); - redraw(); + g.clear(); + Bangle.drawWidgets(); + intervalRef = setInterval(redraw,1000); + redraw(); } Bangle.loadWidgets(); startTimers(); Bangle.on('lcdPower',function(on) { - if (on) { - startTimers(); - } else { - clearTimers(); - } + if (on) { + startTimers(); + } else { + clearTimers(); + } }); // Show launcher when middle button pressed setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"}); diff --git a/apps/boldclk/bold_clock.js b/apps/boldclk/bold_clock.js index 9ef95bb2e..4a082a45b 100644 --- a/apps/boldclk/bold_clock.js +++ b/apps/boldclk/bold_clock.js @@ -1,12 +1,12 @@ var hour_hand = { - width : 61, height : 8, bpp : 1, - transparent : 0, - buffer : E.toArrayBuffer(atob("/////////////////////////////////////////////////////////////////////////////////w==")) + width : 61, height : 8, bpp : 1, + transparent : 0, + buffer : E.toArrayBuffer(atob("/////////////////////////////////////////////////////////////////////////////////w==")) }; var minute_hand = { - width : 110, height : 4, bpp : 1, - transparent : 0, - buffer : E.toArrayBuffer(atob("/////////////////////////////////////////////////////////////////////////w==")) + width : 110, height : 4, bpp : 1, + transparent : 0, + buffer : E.toArrayBuffer(atob("/////////////////////////////////////////////////////////////////////////w==")) }; //g.fillRect(0,24,239,239); // Apps area @@ -24,117 +24,117 @@ let tick1 = Graphics.createArrayBuffer(8,4,1); tick1.fillRect(0,0,tick1.getWidth()-1, tick1.getHeight()-1); function big_wheel_x(angle){ - return clock_center.x + radius * Math.cos(angle*p180); + return clock_center.x + radius * Math.cos(angle*p180); } function big_wheel_y(angle){ - return clock_center.y + radius * Math.sin(angle*p180); + return clock_center.y + radius * Math.sin(angle*p180); } function rotate_around_x(center_x, angle, tick){ - return center_x + Math.cos(angle*p180) * tick.getWidth()/2; + return center_x + Math.cos(angle*p180) * tick.getWidth()/2; } function rotate_around_y(center_y, angle, tick){ - return center_y + Math.sin(angle*p180) * tick.getWidth()/2; + return center_y + Math.sin(angle*p180) * tick.getWidth()/2; } function hour_pos_x(angle){ - return clock_center.x + Math.cos(angle*p180) * hour_hand.width/2; + return clock_center.x + Math.cos(angle*p180) * hour_hand.width/2; } function hour_pos_y(angle){ - return clock_center.y + Math.sin(angle*p180) * hour_hand.width/2; + return clock_center.y + Math.sin(angle*p180) * hour_hand.width/2; } function minute_pos_x(angle){ - return clock_center.x + Math.cos(angle*p180) * minute_hand.width/2; + return clock_center.x + Math.cos(angle*p180) * minute_hand.width/2; } function minute_pos_y(angle){ - return clock_center.y + Math.sin(angle*p180) * minute_hand.width/2; + return clock_center.y + Math.sin(angle*p180) * minute_hand.width/2; } function minute_angle(date){ - //let minutes = date.getMinutes() + date.getSeconds()/60; - let minutes = date.getMinutes(); - return 6*minutes - 90; + //let minutes = date.getMinutes() + date.getSeconds()/60; + let minutes = date.getMinutes(); + return 6*minutes - 90; } function hour_angle(date){ - let hours= date.getHours() + date.getMinutes()/60; - return 30*hours - 90; + let hours= date.getHours() + date.getMinutes()/60; + return 30*hours - 90; } function draw_clock(){ - //console.log("draw_clock"); - let date = new Date(); - //g.clear(); - g.setBgColor(0,0,0); - g.setColor(0,0,0); - g.fillRect(0,24,239,239); // clear app area - g.setColor(1,1,1); + //console.log("draw_clock"); + let date = new Date(); + //g.clear(); + g.setBgColor(0,0,0); + g.setColor(0,0,0); + g.fillRect(0,24,239,239); // clear app area + g.setColor(1,1,1); - // draw cross lines for testing - // g.setColor(1,0,0); - // g.drawLine(clock_center.x - radius, clock_center.y, clock_center.x + radius, clock_center.y); - // g.drawLine(clock_center.x, clock_center.y - radius, clock_center.x, clock_center.y + radius); + // draw cross lines for testing + // g.setColor(1,0,0); + // g.drawLine(clock_center.x - radius, clock_center.y, clock_center.x + radius, clock_center.y); + // g.drawLine(clock_center.x, clock_center.y - radius, clock_center.x, clock_center.y + radius); - g.setColor(1,1,1); - let ticks = [0, 90, 180, 270]; - ticks.forEach((item)=>{ - let agl = item+180; - g.drawImage(tick0.asImage(), rotate_around_x(big_wheel_x(item), agl, tick0), rotate_around_y(big_wheel_y(item), agl, tick0), {rotate:agl*p180}); - }); - ticks = [30, 60, 120, 150, 210, 240, 300, 330]; - ticks.forEach((item)=>{ - let agl = item+180; - g.drawImage(tick5.asImage(), rotate_around_x(big_wheel_x(item), agl, tick5), rotate_around_y(big_wheel_y(item), agl, tick5), {rotate:agl*p180}); - }); + g.setColor(1,1,1); + let ticks = [0, 90, 180, 270]; + ticks.forEach((item)=>{ + let agl = item+180; + g.drawImage(tick0.asImage(), rotate_around_x(big_wheel_x(item), agl, tick0), rotate_around_y(big_wheel_y(item), agl, tick0), {rotate:agl*p180}); + }); + ticks = [30, 60, 120, 150, 210, 240, 300, 330]; + ticks.forEach((item)=>{ + let agl = item+180; + g.drawImage(tick5.asImage(), rotate_around_x(big_wheel_x(item), agl, tick5), rotate_around_y(big_wheel_y(item), agl, tick5), {rotate:agl*p180}); + }); - let hour_agl = hour_angle(date); - let minute_agl = minute_angle(date); - g.drawImage(hour_hand, hour_pos_x(hour_agl), hour_pos_y(hour_agl), {rotate:hour_agl*p180}); // - g.drawImage(minute_hand, minute_pos_x(minute_agl), minute_pos_y(minute_agl), {rotate:minute_agl*p180}); // - g.setColor(1,1,1); - g.fillCircle(clock_center.x, clock_center.y, 6); - g.setColor(0,0,0); - g.fillCircle(clock_center.x, clock_center.y, 3); + let hour_agl = hour_angle(date); + let minute_agl = minute_angle(date); + g.drawImage(hour_hand, hour_pos_x(hour_agl), hour_pos_y(hour_agl), {rotate:hour_agl*p180}); // + g.drawImage(minute_hand, minute_pos_x(minute_agl), minute_pos_y(minute_agl), {rotate:minute_agl*p180}); // + g.setColor(1,1,1); + g.fillCircle(clock_center.x, clock_center.y, 6); + g.setColor(0,0,0); + g.fillCircle(clock_center.x, clock_center.y, 3); - // draw minute ticks. Takes long time to draw! - g.setColor(1,1,1); - for (var i=0; i<60; i++){ - let agl = i*6+180; - g.drawImage(tick1.asImage(), rotate_around_x(big_wheel_x(i*6), agl, tick1), rotate_around_y(big_wheel_y(i*6), agl, tick1), {rotate:agl*p180}); - } + // draw minute ticks. Takes long time to draw! + g.setColor(1,1,1); + for (var i=0; i<60; i++){ + let agl = i*6+180; + g.drawImage(tick1.asImage(), rotate_around_x(big_wheel_x(i*6), agl, tick1), rotate_around_y(big_wheel_y(i*6), agl, tick1), {rotate:agl*p180}); + } - g.flip(); - //console.log(date); + g.flip(); + //console.log(date); } function clearTimers(){ - //console.log("clearTimers"); - if(intervalRef) { - clearInterval(intervalRef); - intervalRef = null; - //console.log("interval is cleared"); - } + //console.log("clearTimers"); + if(intervalRef) { + clearInterval(intervalRef); + intervalRef = null; + //console.log("interval is cleared"); + } } function startTimers(){ - //console.log("startTimers"); - if(intervalRef) clearTimers(); - intervalRef = setInterval(draw_clock, 60*1000); - //console.log("interval is set"); - draw_clock(); + //console.log("startTimers"); + if(intervalRef) clearTimers(); + intervalRef = setInterval(draw_clock, 60*1000); + //console.log("interval is set"); + draw_clock(); } Bangle.on('lcdPower', (on) => { - if (on) { - //console.log("lcdPower: on"); - Bangle.drawWidgets(); - startTimers(); - } else { - //console.log("lcdPower: off"); - clearTimers(); - } + if (on) { + //console.log("lcdPower: on"); + Bangle.drawWidgets(); + startTimers(); + } else { + //console.log("lcdPower: off"); + clearTimers(); + } }); Bangle.on('faceUp',function(up){ - //console.log("faceUp: " + up + " LCD: " + Bangle.isLCDOn()); - if (up && !Bangle.isLCDOn()) { - //console.log("faceUp and LCD off"); - clearTimers(); - Bangle.setLCDPower(true); - } + //console.log("faceUp: " + up + " LCD: " + Bangle.isLCDOn()); + if (up && !Bangle.isLCDOn()) { + //console.log("faceUp and LCD off"); + clearTimers(); + Bangle.setLCDPower(true); + } }); g.clear(); diff --git a/apps/calculator/app.js b/apps/calculator/app.js index ad26d2d22..a736b715d 100644 --- a/apps/calculator/app.js +++ b/apps/calculator/app.js @@ -372,7 +372,7 @@ function buttonPress(val) { for (var k in keys) { if (keys.hasOwnProperty(k)) { - drawKey(k, keys[k], k == '5'); + drawKey(k, keys[k], k == '5'); } } g.setFont('7x11Numeric7Seg', 2.8); diff --git a/apps/chronowid/app.js b/apps/chronowid/app.js index dd9531233..0cacdee23 100644 --- a/apps/chronowid/app.js +++ b/apps/chronowid/app.js @@ -45,12 +45,12 @@ function showMenu() { } }, 'Reset values': function() { - settingsChronowid.hours = 0; - settingsChronowid.minutes = 0; - settingsChronowid.seconds = 0; - settingsChronowid.started = false; - updateSettings(); - showMenu(); + settingsChronowid.hours = 0; + settingsChronowid.minutes = 0; + settingsChronowid.seconds = 0; + settingsChronowid.started = false; + updateSettings(); + showMenu(); }, 'Hours': { value: settingsChronowid.hours, @@ -89,8 +89,8 @@ function showMenu() { settingsChronowid.started = v; updateSettings(); } - }, - }; + }, + }; timerMenu['-Exit-'] = ()=>{load();}; return E.showMenu(timerMenu); } diff --git a/apps/chronowid/widget.js b/apps/chronowid/widget.js index 0c9366b86..f0e785efd 100644 --- a/apps/chronowid/widget.js +++ b/apps/chronowid/widget.js @@ -1,93 +1,93 @@ (() => { - const storage = require('Storage'); - settingsChronowid = storage.readJSON("chronowid.json",1)||{}; //read settingsChronowid from file - var height = 23; - var width = 58; - var interval = 0; //used for the 1 second interval timer - var now = new Date(); + const storage = require('Storage'); + settingsChronowid = storage.readJSON("chronowid.json",1)||{}; //read settingsChronowid from file + var height = 23; + var width = 58; + var interval = 0; //used for the 1 second interval timer + var now = new Date(); - var time = 0; - var diff = settingsChronowid.goal - now; + var time = 0; + var diff = settingsChronowid.goal - now; - //Convert ms to time - function getTime(t) { - var milliseconds = parseInt((t % 1000) / 100), - seconds = Math.floor((t / 1000) % 60), - minutes = Math.floor((t / (1000 * 60)) % 60), - hours = Math.floor((t / (1000 * 60 * 60)) % 24); + //Convert ms to time + function getTime(t) { + var milliseconds = parseInt((t % 1000) / 100), + seconds = Math.floor((t / 1000) % 60), + minutes = Math.floor((t / (1000 * 60)) % 60), + hours = Math.floor((t / (1000 * 60 * 60)) % 24); - hours = (hours < 10) ? "0" + hours : hours; - minutes = (minutes < 10) ? "0" + minutes : minutes; - seconds = (seconds < 10) ? "0" + seconds : seconds; + hours = (hours < 10) ? "0" + hours : hours; + minutes = (minutes < 10) ? "0" + minutes : minutes; + seconds = (seconds < 10) ? "0" + seconds : seconds; - return hours + ":" + minutes + ":" + seconds; + return hours + ":" + minutes + ":" + seconds; + } + + function printDebug() { + print ("Nowtime: " + getTime(now)); + print ("Now: " + now); + print ("Goaltime: " + getTime(settingsChronowid.goal)); + print ("Goal: " + settingsChronowid.goal); + print("Difftime: " + getTime(diff)); + print("Diff: " + diff); + print ("Started: " + settingsChronowid.started); + print ("----"); + } + + //counts down, calculates and displays + function countDown() { + now = new Date(); + diff = settingsChronowid.goal - now; //calculate difference + WIDGETS["chronowid"].draw(); + //time is up + if (settingsChronowid.started && diff < 1000) { + Bangle.buzz(1500); + //write timer off to file + settingsChronowid.started = false; + storage.writeJSON('chronowid.json', settingsChronowid); + clearInterval(interval); //stop interval } - - function printDebug() { - print ("Nowtime: " + getTime(now)); - print ("Now: " + now); - print ("Goaltime: " + getTime(settingsChronowid.goal)); - print ("Goal: " + settingsChronowid.goal); - print("Difftime: " + getTime(diff)); - print("Diff: " + diff); - print ("Started: " + settingsChronowid.started); - print ("----"); - } - - //counts down, calculates and displays - function countDown() { - now = new Date(); - diff = settingsChronowid.goal - now; //calculate difference - WIDGETS["chronowid"].draw(); - //time is up - if (settingsChronowid.started && diff < 1000) { - Bangle.buzz(1500); - //write timer off to file - settingsChronowid.started = false; - storage.writeJSON('chronowid.json', settingsChronowid); - clearInterval(interval); //stop interval - } - //printDebug(); - } - - // draw your widget - function draw() { - if (!settingsChronowid.started) { - width = 0; - return; //do not draw anything if timer is not started - } - g.reset(); - if (diff >= 0) { - if (diff < 3600000) { //less than 1 hour left - width = 58; - g.clearRect(this.x,this.y,this.x+width,this.y+height); - g.setFont("6x8", 2); - g.drawString(getTime(diff).substring(3), this.x+1, this.y+5); //remove hour part 00:00:00 -> 00:00 - } - if (diff >= 3600000) { //one hour or more left - width = 48; - g.clearRect(this.x,this.y,this.x+width,this.y+height); - g.setFont("6x8", 1); - g.drawString(getTime(diff), this.x+1, this.y+((height/2)-4)); //display hour 00:00:00 - } - } - // not needed anymoe, because we check if diff < 1000 now, so 00:00 is displayed. - // else { - // width = 58; - // g.clearRect(this.x,this.y,this.x+width,this.y+height); - // g.setFont("6x8", 2); - // g.drawString("END", this.x+15, this.y+5); - // } - } - - if (settingsChronowid.started) interval = setInterval(countDown, 1000); //start countdown each second - - // add the widget - WIDGETS["chronowid"]={area:"bl",width:width,draw:draw,reload:function() { - reload(); - Bangle.drawWidgets(); // relayout all widgets - }}; - //printDebug(); - countDown(); + } + + // draw your widget + function draw() { + if (!settingsChronowid.started) { + width = 0; + return; //do not draw anything if timer is not started + } + g.reset(); + if (diff >= 0) { + if (diff < 3600000) { //less than 1 hour left + width = 58; + g.clearRect(this.x,this.y,this.x+width,this.y+height); + g.setFont("6x8", 2); + g.drawString(getTime(diff).substring(3), this.x+1, this.y+5); //remove hour part 00:00:00 -> 00:00 + } + if (diff >= 3600000) { //one hour or more left + width = 48; + g.clearRect(this.x,this.y,this.x+width,this.y+height); + g.setFont("6x8", 1); + g.drawString(getTime(diff), this.x+1, this.y+((height/2)-4)); //display hour 00:00:00 + } + } + // not needed anymoe, because we check if diff < 1000 now, so 00:00 is displayed. + // else { + // width = 58; + // g.clearRect(this.x,this.y,this.x+width,this.y+height); + // g.setFont("6x8", 2); + // g.drawString("END", this.x+15, this.y+5); + // } + } + + if (settingsChronowid.started) interval = setInterval(countDown, 1000); //start countdown each second + + // add the widget + WIDGETS["chronowid"]={area:"bl",width:width,draw:draw,reload:function() { + reload(); + Bangle.drawWidgets(); // relayout all widgets + }}; + + //printDebug(); + countDown(); })(); \ No newline at end of file diff --git a/apps/clickms/click-master.js b/apps/clickms/click-master.js index b9f76364b..55027e733 100644 --- a/apps/clickms/click-master.js +++ b/apps/clickms/click-master.js @@ -7,12 +7,12 @@ setWatch(x=>{ },BTN1,{repeat:true}); function updateAdvertising() { -try { - NRF.setAdvertising({},{ - manufacturer: 0x0590, - manufacturerData: new Uint8Array([mycounter>>8,mycounter&255]) - }); -} catch(e){} + try { + NRF.setAdvertising({},{ + manufacturer: 0x0590, + manufacturerData: new Uint8Array([mycounter>>8,mycounter&255]) + }); + } catch(e){} } function drawPlayers() { diff --git a/apps/clock2x3/clock2x3-app.js b/apps/clock2x3/clock2x3-app.js index 511a7662b..4caec28cb 100644 --- a/apps/clock2x3/clock2x3-app.js +++ b/apps/clock2x3/clock2x3-app.js @@ -14,9 +14,9 @@ const x21=x20+pw+ps; const x30=x21+pw+ds; const x31=x30+pw+ps; const xSpace=[[x00,x01], // all pixel x spacing - [x10,x11], - [x20,x21], - [x30,x31]]; + [x10,x11], + [x20,x21], + [x30,x31]]; const y0=oy; // y spacing const y1=y0+pw+ps; @@ -24,35 +24,35 @@ const y2=y1+pw+ps; const ySpace=[y0, y1, y2]; const pixels = [[[0,0], // digit on/off pixels - [1,1], - [1,1]], - [[0,1], // digit 1 - [0,1], - [0,1]], - [[0,1], - [1,0], - [1,1]], - [[1,1], - [0,1], - [1,1]], - [[1,0], - [1,1], - [0,1]], - [[1,1], - [1,0], - [0,1]], - [[1,0], - [1,1], - [1,1]], - [[1,1], - [0,1], - [0,1]], - [[1,1], - [1,1], - [1,1]], - [[1,1], - [1,1], - [0,1]]]; + [1,1], + [1,1]], +[[0,1], // digit 1 + [0,1], + [0,1]], +[[0,1], + [1,0], + [1,1]], +[[1,1], + [0,1], + [1,1]], +[[1,0], + [1,1], + [0,1]], +[[1,1], + [1,0], + [0,1]], +[[1,0], + [1,1], + [1,1]], +[[1,1], + [0,1], + [0,1]], +[[1,1], + [1,1], + [1,1]], +[[1,1], + [1,1], + [0,1]]]; let idTimeout = null; diff --git a/apps/compass/compass.js b/apps/compass/compass.js index a014d79ff..d983affd8 100644 --- a/apps/compass/compass.js +++ b/apps/compass/compass.js @@ -12,7 +12,7 @@ function arrow(r,c) { 120+60*Math.sin(r), 130-60*Math.cos(r), 120+10*Math.sin(r+p), 130-10*Math.cos(r+p), 120+10*Math.sin(r+-p), 130-10*Math.cos(r-p), - ]); + ]); } var oldHeading = 0; diff --git a/apps/cube/cube-icon.js b/apps/cube/cube-icon.js index 5ff0a2154..72a4ba4d9 100644 --- a/apps/cube/cube-icon.js +++ b/apps/cube/cube-icon.js @@ -1 +1 @@ - require("heatshrink").decompress(atob("/4AYv4CB+YdZABPvEkYA/AGv3EkfPAQP+DrI")) +require("heatshrink").decompress(atob("/4AYv4CB+YdZABPvEkYA/AGv3EkfPAQP+DrI")) diff --git a/apps/cube/cube.js b/apps/cube/cube.js index 7e0e70edf..426171469 100644 --- a/apps/cube/cube.js +++ b/apps/cube/cube.js @@ -2,9 +2,9 @@ var rx = 0, ry = 0; function draw() { var rcx=Math.cos(rx), - rsx=Math.sin(rx), - rcy=Math.cos(ry), - rsy=Math.sin(ry); + rsx=Math.sin(rx), + rcy=Math.cos(ry), + rsy=Math.sin(ry); function p(x,y,z) { var t; t = x*rcy + z*rsy; diff --git a/apps/dane/app.js b/apps/dane/app.js index dc6262c58..5f7a48fbc 100644 --- a/apps/dane/app.js +++ b/apps/dane/app.js @@ -110,8 +110,8 @@ function drawTimeText() { var time = da[4].split(":"); var hours = time[0], - minutes = time[1], - seconds = time[2]; + minutes = time[1], + seconds = time[2]; g.setColor(mainColor); g.setFont(font, timeFontSize); g.drawString(`${hours}:${minutes}:${seconds}`, xyCenter, yposTime, true); diff --git a/apps/daysl/widget.js b/apps/daysl/widget.js index 4a32d5f26..4edbc3230 100644 --- a/apps/daysl/widget.js +++ b/apps/daysl/widget.js @@ -7,7 +7,7 @@ var debug = 0; //1 = show debug info //write settings to file function updateSettings() { - storage.write('daysleft.json', settings); + storage.write('daysleft.json', settings); } //Define standard settings @@ -24,8 +24,8 @@ settings = storage.readJSON('daysleft.json',1); //read storage if (!settings) resetSettings(); //if settings file was not found, set to standard var dd = settings.day, - mm = settings.month-1, //-1 because month is zero-based - yy = settings.year; + mm = settings.month-1, //-1 because month is zero-based + yy = settings.year; const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds const targetDate = new Date(yy, mm, dd); //is 00:00 diff --git a/apps/demoapp/app.js b/apps/demoapp/app.js index cb3136196..13c043587 100644 --- a/apps/demoapp/app.js +++ b/apps/demoapp/app.js @@ -27,22 +27,22 @@ var scenes = [ "| __|_ -| . | _| | | | | . |\n"+ "|____|___| _|_| |___|_|_|_|___|\n"+ " |_| espruino.com\n\n", - "The JavaScript Interpreter for uCs\n", - " * On-chip JS Interpreter", - " * GPS, Acclerometer, Compass", - " * 64 MHz, 64kB RAM, 512kB + 4MB Flash", - " * 240x240 IPS LCD", - " * Speaker & Vibration motor", - " * Bluetooth LE", - " * 1 week battery life", - "", - "Includes:", - " * Tensorflow AI", - " * Bluetooth LE central & periph", - " * Graphics Library", - " * VT100 terminal", - "","","" - ]; + "The JavaScript Interpreter for uCs\n", + " * On-chip JS Interpreter", + " * GPS, Acclerometer, Compass", + " * 64 MHz, 64kB RAM, 512kB + 4MB Flash", + " * 240x240 IPS LCD", + " * Speaker & Vibration motor", + " * Bluetooth LE", + " * 1 week battery life", + "", + "Includes:", + " * Tensorflow AI", + " * Bluetooth LE central & periph", + " * Graphics Library", + " * VT100 terminal", + "","","" + ]; var n=0; var i = setInterval(function() { Terminal.println(txt[n]); @@ -62,19 +62,19 @@ var scenes = [ function() { var img = require("heatshrink").decompress(atob("oNBxH+5wA/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AHGpAAoQKv4ADCBQAeqsrAAejBw9/B4oABqt/IGepHw5CEQspALH5hBC5pAvv4/MAALFkIBWpPI6IHqpAu0Z3GfYOpRYdPQEhALYIp2FBYNVI4JAvvL4LH0yBYAFJAQQQ5Ay1JAFftBAQBYxCDv+qIGiCHIQiGnIBfOv5BJIQRAyIJkrvKEkIBrFBB4qEGIGRCNYsZAQIQV/IZDEiICRCDQVJAUIQVPC4lVIF6yJQYpAZ5t/FYvNIBepqtVIJGjIDoqBDY2pdYo3DfAhBIQLmpvIcDvIrC5oJEIAhTCGQmj5qgEC4t5e7YrBqt5BI6UFBg15v4XHbQwAQb4oAKv7NKABdVRoYATUAwnICqjZFIMdVE4+jXI4XGYCxBFFZN/M5OpCxUrvJ/ZFYmjvNVAAY+KCwpDBC6YAV5vNC9oA/AH4A/AHYA==")); - g.clear(); - y = 0; - var step = 4; - var i = setInterval(function() { - y+=step; g.clear(); - g.drawImage(img,60,60,{rotate:Math.sin(y*0.03)*0.5}); - g.flip(); - }, 20); - Bangle.setLCDMode("120x120"); - return function() { - if (i) clearInterval(i); - }; + y = 0; + var step = 4; + var i = setInterval(function() { + y+=step; + g.clear(); + g.drawImage(img,60,60,{rotate:Math.sin(y*0.03)*0.5}); + g.flip(); + }, 20); + Bangle.setLCDMode("120x120"); + return function() { + if (i) clearInterval(i); + }; }, function() { var rx = 0, ry = 0; @@ -82,9 +82,9 @@ var scenes = [ // draw a cube function draw() { var rcx=Math.cos(rx), - rsx=Math.sin(rx), - rcy=Math.cos(ry), - rsy=Math.sin(ry); + rsx=Math.sin(rx), + rcy=Math.cos(ry), + rsy=Math.sin(ry); // Project 3D coordinates into 2D function p(x,y,z) { var t; @@ -149,7 +149,7 @@ var scenes = [ y+=step; g.scroll(0,1); g.drawImage(img,Math.random()*240,Math.random()*240, - {rotate:Math.random()*6.3, scale:0.5+Math.random()}); + {rotate:Math.random()*6.3, scale:0.5+Math.random()}); }, 1); Bangle.setLCDMode(); return function() { diff --git a/apps/dotmatrixclock/app.js b/apps/dotmatrixclock/app.js index 94c628b1b..ba34d4885 100755 --- a/apps/dotmatrixclock/app.js +++ b/apps/dotmatrixclock/app.js @@ -88,10 +88,10 @@ function binToHex(bins) { function hexToBin(hexStr) { const regEx = new RegExp("..", "g"); const bin = hexStr - .replace(regEx, el => el + '_') - .slice(0, -1) - .split('_') - .map(hex => ("00000000" + (parseInt(hex, 16)).toString(2)).substr(-8)); + .replace(regEx, el => el + '_') + .slice(0, -1) + .split('_') + .map(hex => ("00000000" + (parseInt(hex, 16)).toString(2)).substr(-8)); return bin; } @@ -153,8 +153,8 @@ function drawFont(str, font, x, y) { const gridWidthTotal = (rows * (pxlW + gap)) + gutter; for (let i = 0; i < charArr.length; i++) { const charAsBin = fontMap.hasOwnProperty(charArr[i])? - hexToBin(fontMap[charArr[i]]): - fontMap.empty; + hexToBin(fontMap[charArr[i]]): + fontMap.empty; drawGrid( {x: x + (i * gridWidthTotal), y: y}, @@ -188,8 +188,8 @@ function drawCompass(lastHeading) { const cps = Bangle.getCompass(); let angle = cps.heading; let heading = angle? - directions[Math.round(((angle %= 360) < 0 ? angle + 360 : angle) / 45) % 8]: - "-- "; + directions[Math.round(((angle %= 360) < 0 ? angle + 360 : angle) / 45) % 8]: + "-- "; heading = (heading + " ").slice(0, 3); if (lastHeading != heading) drawFont(heading, "5x5", 40, 67); diff --git a/apps/findphone/app.js b/apps/findphone/app.js index bbabdd38a..a532e3b50 100644 --- a/apps/findphone/app.js +++ b/apps/findphone/app.js @@ -2,7 +2,7 @@ var storage = require('Storage'); //notify your phone function find(){ - Bluetooth.println(JSON.stringify({t:"findPhone", n:true})); + Bluetooth.println(JSON.stringify({t:"findPhone", n:true})); } //init graphics @@ -17,17 +17,17 @@ const settings = storage.readJSON('setting.json',1) || { HID: false }; //check if HID enabled and show message if (settings.HID=="kb" || settings.HID=="kbmedia") { - g.setColor(0x03E0); - g.drawString("click to find", g.getWidth()/2, g.getHeight()/2); + g.setColor(0x03E0); + g.drawString("click to find", g.getWidth()/2, g.getHeight()/2); - //register all buttons and screen to find phone - setWatch(find, BTN1); - setWatch(find, BTN2); - setWatch(find, BTN3); - setWatch(find, BTN4); - setWatch(find, BTN5); + //register all buttons and screen to find phone + setWatch(find, BTN1); + setWatch(find, BTN2); + setWatch(find, BTN3); + setWatch(find, BTN4); + setWatch(find, BTN5); }else{ - g.setColor(0xf800); - g.drawString("enable HID!", g.getWidth()/2, g.getHeight()/2); + g.setColor(0xf800); + g.drawString("enable HID!", g.getWidth()/2, g.getHeight()/2); } \ No newline at end of file diff --git a/apps/flagrse/app.js b/apps/flagrse/app.js index e7e8e2445..e03e4fb07 100644 --- a/apps/flagrse/app.js +++ b/apps/flagrse/app.js @@ -5,15 +5,15 @@ 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(); function flag() { E.showMessage("Working..."); if (busy && lastTry+5 { for (i = angle1; i < angle2; i=i+incr) { brush = thickness * (angle2-angle1) /angle2; points = [ - x + Math.sin(i) * (segRadius+brush), - y - Math.cos(i) * (segRadius+brush), - x + Math.sin(i+incr) * (segRadius+brush), - y - Math.cos(i+incr) * (segRadius+brush), - x + Math.sin(i+incr) * (segRadius-brush), - y - Math.cos(i+incr) * (segRadius-brush), - x + Math.sin(i) * (segRadius-brush), - y - Math.cos(i) * (segRadius-brush) + x + Math.sin(i) * (segRadius+brush), + y - Math.cos(i) * (segRadius+brush), + x + Math.sin(i+incr) * (segRadius+brush), + y - Math.cos(i+incr) * (segRadius+brush), + x + Math.sin(i+incr) * (segRadius-brush), + y - Math.cos(i+incr) * (segRadius-brush), + x + Math.sin(i) * (segRadius-brush), + y - Math.cos(i) * (segRadius-brush) ]; g.fillPoly(points); } @@ -165,11 +165,11 @@ const drawMinuteHand = () => { g.setColor(0,1,0); break; case "blue": - g.setColor(0,0,1); - break; + g.setColor(0,0,1); + break; case "80s": - g.setColor(1,0,0); - break; + g.setColor(1,0,0); + break; default: g.setColor(0,1,0); } @@ -177,7 +177,7 @@ const drawMinuteHand = () => { var points = [centerX,centerY]; for (i = 0; i < angle; i=i+cirRad/60) { points.push(Math.round(centerX + Math.sin(i) * radius), - Math.round(centerY - Math.cos(i) * radius)); + Math.round(centerY - Math.cos(i) * radius)); } g.fillPoly(points); }; @@ -194,24 +194,24 @@ const drawHourHand = () => { }; const drawClockFace = () => { - switch(colour) { - case "red": - g.setColor(0.8,0.3,0); - break; - case "green": - g.setColor(0.1,0.7,0); - break; - case "blue": - g.setColor(0,0.3,0.8); - break; - case "80s": - g.setColor(1,1,1); - break; - default: - g.setColor(0.1,0.7,0); - } - g.fillCircle(centerX,centerY,radius*0.98); - }; + switch(colour) { + case "red": + g.setColor(0.8,0.3,0); + break; + case "green": + g.setColor(0.1,0.7,0); + break; + case "blue": + g.setColor(0,0.3,0.8); + break; + case "80s": + g.setColor(1,1,1); + break; + default: + g.setColor(0.1,0.7,0); + } + g.fillCircle(centerX,centerY,radius*0.98); +}; const drawAll = () => { currentDate = new Date(); diff --git a/apps/gallifr/settings.js b/apps/gallifr/settings.js index bf6aae846..feb6b0ffc 100644 --- a/apps/gallifr/settings.js +++ b/apps/gallifr/settings.js @@ -1,33 +1,33 @@ // make sure to enclose the function in parentheses (function (back) { - let settings = require('Storage').readJSON('gallifr.json',1)||{}; - let colours = ["green","red","blue","80s"]; - let onoff = ["on","off"]; - function save(key, value) { - settings[key] = value; - require('Storage').writeJSON('gallifr.json',settings); + let settings = require('Storage').readJSON('gallifr.json',1)||{}; + let colours = ["green","red","blue","80s"]; + let onoff = ["on","off"]; + function save(key, value) { + settings[key] = value; + require('Storage').writeJSON('gallifr.json',settings); + } + const appMenu = { + '': {'title': 'Clock Settings'}, + '< Back': back, + 'Colour': { + value: 0|settings['colour'], + min:0,max:3, + format: m => colours[m], + onchange: m => {save('colour', m)} + }, + 'Widgets': { + value: 0|settings['widgets'], + min:0,max:1, + format: m => onoff[m], + onchange: m => {save('widgets', m)} + }, + 'Decoration': { + value: 0|settings['decoration'], + min:0,max:1, + format: m => onoff[m], + onchange: m => {save('decoration', m)} } - const appMenu = { - '': {'title': 'Clock Settings'}, - '< Back': back, - 'Colour': { - value: 0|settings['colour'], - min:0,max:3, - format: m => colours[m], - onchange: m => {save('colour', m)} - }, - 'Widgets': { - value: 0|settings['widgets'], - min:0,max:1, - format: m => onoff[m], - onchange: m => {save('widgets', m)} - }, - 'Decoration': { - value: 0|settings['decoration'], - min:0,max:1, - format: m => onoff[m], - onchange: m => {save('decoration', m)} - } - }; - E.showMenu(appMenu) - }) + }; + E.showMenu(appMenu) +}) diff --git a/apps/getup/app.js b/apps/getup/app.js index 8e4a4a099..3a22aa410 100644 --- a/apps/getup/app.js +++ b/apps/getup/app.js @@ -3,38 +3,38 @@ const storage = require("Storage"); const SETTINGS_FILE = 'getup.settings.json'; function setting(key) { - const DEFAULTS = { - 'sitTime' : 20, - 'moveTime' : 1 - } - if (!settings) { - loadSettings(); - } - return (key in settings) ? settings[key] : DEFAULTS[key]; + const DEFAULTS = { + 'sitTime' : 20, + 'moveTime' : 1 + } + if (!settings) { + loadSettings(); + } + return (key in settings) ? settings[key] : DEFAULTS[key]; } let settings; function loadSettings() { - settings = storage.readJSON(SETTINGS_FILE, 1) || {}; + settings = storage.readJSON(SETTINGS_FILE, 1) || {}; } //vibrate, draw move message and start timer for sitting message function remind() { - Bangle.buzz(1000,1); - g.clear(); - g.setFont("8x12",4); - g.setColor(0x03E0); - g.drawString("MOVE!", g.getWidth()/2, g.getHeight()/2); - setTimeout(print_message,setting("moveTime") * 60000); + Bangle.buzz(1000,1); + g.clear(); + g.setFont("8x12",4); + g.setColor(0x03E0); + g.drawString("MOVE!", g.getWidth()/2, g.getHeight()/2); + setTimeout(print_message,setting("moveTime") * 60000); } //draw sitting message and start timer for reminder function print_message(){ - g.clear(); - g.setFont("8x12",2); - g.setColor(0xF800); - g.drawString("sitting is dangerous!", g.getWidth()/2, g.getHeight()/2); - setTimeout(remind,setting("sitTime") * 60000); + g.clear(); + g.setFont("8x12",2); + g.setColor(0xF800); + g.drawString("sitting is dangerous!", g.getWidth()/2, g.getHeight()/2); + setTimeout(remind,setting("sitTime") * 60000); } //init graphics diff --git a/apps/gpsnav/app.js b/apps/gpsnav/app.js index 960ad7e4d..1e70b0cd3 100644 --- a/apps/gpsnav/app.js +++ b/apps/gpsnav/app.js @@ -4,8 +4,8 @@ var buf = Graphics.createArrayBuffer(240,50,2,{msb:true}); var candraw = true; function flip(b,y) { - g.drawImage({width:240,height:50,bpp:2,buffer:b.buffer, palette:pal2color},0,y); - b.clear(); + g.drawImage({width:240,height:50,bpp:2,buffer:b.buffer, palette:pal2color},0,y); + b.clear(); } var brg=0; @@ -44,27 +44,27 @@ function drawCompass(course) { if (bpos>210) bpos = 226; buf.setColor(2); buf.fillCircle(bpos,40,8); - } + } flip(buf,Yoff); } //displayed heading var heading = 0; function newHeading(m,h){ - var s = Math.abs(m - h); - var delta = 1; - if (s<2) return h; - if (m > h){ - if (s >= 180) { delta = -1; s = 360 - s;} - } else if (m <= h){ - if (s < 180) delta = -1; - else s = 360 -s; - } - delta = delta * (1 + Math.round(s/15)); - heading+=delta; - if (heading<0) heading += 360; - if (heading>360) heading -= 360; - return heading; + var s = Math.abs(m - h); + var delta = 1; + if (s<2) return h; + if (m > h){ + if (s >= 180) { delta = -1; s = 360 - s;} + } else if (m <= h){ + if (s < 180) delta = -1; + else s = 360 -s; + } + delta = delta * (1 + Math.round(s/15)); + heading+=delta; + if (heading<0) heading += 360; + if (heading>360) heading -= 360; + return heading; } var course =0; @@ -193,17 +193,17 @@ function setButtons(){ } var SCREENACCESS = { - withApp:true, - request:function(){ - this.withApp=false; - stopdraw(); - clearWatch(); - }, - release:function(){ - this.withApp=true; - startdraw(); - setButtons(); - } + withApp:true, + request:function(){ + this.withApp=false; + stopdraw(); + clearWatch(); + }, + release:function(){ + this.withApp=true; + startdraw(); + setButtons(); + } } Bangle.on('lcdPower',function(on) { @@ -229,9 +229,9 @@ function nextwp(inc){ function doselect(){ if (selected && waypoints[wpindex].lat===undefined && savedfix.fix) { - waypoints[wpindex] ={name:"@"+wp.name, lat:savedfix.lat, lon:savedfix.lon}; - wp = waypoints[wpindex]; - require("Storage").writeJSON("waypoints.json", waypoints); + waypoints[wpindex] ={name:"@"+wp.name, lat:savedfix.lat, lon:savedfix.lon}; + wp = waypoints[wpindex]; + require("Storage").writeJSON("waypoints.json", waypoints); } selected=!selected; drawN(); diff --git a/apps/hidcam/app.js b/apps/hidcam/app.js index adb1a4b29..bb8ddf7e9 100644 --- a/apps/hidcam/app.js +++ b/apps/hidcam/app.js @@ -48,9 +48,9 @@ function drawApp() { if (camShot) { setWatch(function(e) { - E.showMessage('camShot !'); - setTimeout(drawApp, 1000); - camShot(() => {}); + E.showMessage('camShot !'); + setTimeout(drawApp, 1000); + camShot(() => {}); }, BTN2, { edge:"falling",repeat:true,debounce:50}); drawApp(); diff --git a/apps/hidjoystick/app.js b/apps/hidjoystick/app.js index 0b3187a53..134814cee 100644 --- a/apps/hidjoystick/app.js +++ b/apps/hidjoystick/app.js @@ -4,71 +4,71 @@ const settings = storage.readJSON('setting.json',1) || { HID: false }; var sendInProgress = false; // Only send one message at a time, do not flood const sendHid = function (x, y, btn1, btn2, btn3, btn4, btn5, cb) { - try { - const buttons = (btn5<<4) | (btn4<<3) | (btn3<<2) | (btn2<<1) | (btn1<<0); - if (!sendInProgress) { - sendInProgress = true; - NRF.sendHIDReport([buttons, x, y], () => { - sendInProgress = false; - if (cb) cb(); - }); - } - } catch(e) { - print(e); - } + try { + const buttons = (btn5<<4) | (btn4<<3) | (btn3<<2) | (btn2<<1) | (btn1<<0); + if (!sendInProgress) { + sendInProgress = true; + NRF.sendHIDReport([buttons, x, y], () => { + sendInProgress = false; + if (cb) cb(); + }); + } + } catch(e) { + print(e); + } }; function drawApp() { - g.clear(); - g.setFont("6x8",2); - g.setFontAlign(0,0); - g.drawString("Joystick", 120, 120); - const d = g.getWidth() - 18; + g.clear(); + g.setFont("6x8",2); + g.setFontAlign(0,0); + g.drawString("Joystick", 120, 120); + const d = g.getWidth() - 18; - function c(a) { - return { - width: 8, - height: a.length, - bpp: 1, - buffer: (new Uint8Array(a)).buffer - }; - } + function c(a) { + return { + width: 8, + height: a.length, + bpp: 1, + buffer: (new Uint8Array(a)).buffer + }; + } - g.drawImage(c([16,56,124,254,16,16,16,16]),d,40); - g.drawImage(c([16,16,16,16,254,124,56,16]),d,194); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,116); + g.drawImage(c([16,56,124,254,16,16,16,16]),d,40); + g.drawImage(c([16,16,16,16,254,124,56,16]),d,194); + g.drawImage(c([0,8,12,14,255,14,12,8]),d,116); } function update() { - const btn1 = BTN1.read(); - const btn2 = BTN2.read(); - const btn3 = BTN3.read(); - const btn4 = BTN4.read(); - const btn5 = BTN5.read(); - const acc = Bangle.getAccel(); - var x = acc.x*-127; - var y = acc.y*-127; + const btn1 = BTN1.read(); + const btn2 = BTN2.read(); + const btn3 = BTN3.read(); + const btn4 = BTN4.read(); + const btn5 = BTN5.read(); + const acc = Bangle.getAccel(); + var x = acc.x*-127; + var y = acc.y*-127; - // check limits - if (x > 127) x = 127; - else if (x < -127) x = -127; - if (y > 127) y = 127; - else if (y < -127) y = -127; + // check limits + if (x > 127) x = 127; + else if (x < -127) x = -127; + if (y > 127) y = 127; + else if (y < -127) y = -127; - sendHid(x & 0xff, y & 0xff, btn1, btn2, btn3, btn4, btn5); + sendHid(x & 0xff, y & 0xff, btn1, btn2, btn3, btn4, btn5); } if (settings.HID === "joy") { - drawApp(); - setInterval(update, 100); // 10 Hz + drawApp(); + setInterval(update, 100); // 10 Hz } else { - E.showPrompt("Enable HID?",{title:"HID disabled"}).then(function(enable) { - if (enable) { - settings.HID = "joy"; - storage.write('setting.json', settings); - setTimeout(load, 1000, "hidjoystick.app.js"); - } else { - setTimeout(load, 1000); - } - }); + E.showPrompt("Enable HID?",{title:"HID disabled"}).then(function(enable) { + if (enable) { + settings.HID = "joy"; + storage.write('setting.json', settings); + setTimeout(load, 1000, "hidjoystick.app.js"); + } else { + setTimeout(load, 1000); + } + }); } diff --git a/apps/horsey/horse-race.js b/apps/horsey/horse-race.js index 170ca22f2..bd09e3802 100644 --- a/apps/horsey/horse-race.js +++ b/apps/horsey/horse-race.js @@ -16,13 +16,13 @@ setWatch(x=>{ },BTN1,{repeat:true}); function updateAdvertising() { -try { - NRF.setAdvertising({},{ - manufacturer: 0x0590, - manufacturerData: new Uint8Array([mycounter>>8,mycounter&255]), - interval: 60 - }); -} catch(e){} + try { + NRF.setAdvertising({},{ + manufacturer: 0x0590, + manufacturerData: new Uint8Array([mycounter>>8,mycounter&255]), + interval: 60 + }); + } catch(e){} } function drawPlayers() { @@ -44,7 +44,7 @@ function drawPlayers() { var d = 63 - (offset&63); g.fillRect(0,10,240,12); for (var x=d;x<240;x+=64) - g.fillRect(x,12,x+2,12+20); + g.fillRect(x,12,x+2,12+20); var y = 20; var p = mycounter-offset; g.drawString("You",p-16,y+20); @@ -60,7 +60,7 @@ function drawPlayers() { g.fillRect(0,150,240,152); for (var x=d;x<240;x+=64) - g.fillRect(x,152,x+2,160); + g.fillRect(x,152,x+2,160); g.flip(); } diff --git a/apps/impwclock/clock-impword.js b/apps/impwclock/clock-impword.js index ff4e24e2c..94b92b778 100644 --- a/apps/impwclock/clock-impword.js +++ b/apps/impwclock/clock-impword.js @@ -7,30 +7,30 @@ by Gordon Williams https://github.com/gfwilliams /* jshint esversion: 6 */ const allWords = [ - "AEARLYDN", - "LATEYRZO", - "MORNINGO", - "KMIDDLEN", - "AFTERDAY", - "OFDZTHEC", - "EVENINGR", - "ORMNIGHT" + "AEARLYDN", + "LATEYRZO", + "MORNINGO", + "KMIDDLEN", + "AFTERDAY", + "OFDZTHEC", + "EVENINGR", + "ORMNIGHT" ]; const timeOfDay = { - 0: ["", 0, 0], - 1: ["EARLYMORNING", 10, 20, 30, 40, 50, 02, 12, 22, 32, 42, 52, 62], - 2: ["MORNING", 02, 12, 22, 32, 42, 52, 62], - 3: ["LATEMORNING", 01, 11, 21, 31, 02, 12, 22, 32, 42, 52, 62], - 4: ["MIDDAY", 13, 23, 33, 54, 64, 74], - 5: ["EARLYAFTERNOON", 10, 20, 30, 40, 50, 04, 14, 24, 34, 44, 70, 71, 72, 73], - 6: ["AFTERNOON", 04, 14, 24, 34, 44, 70, 71, 72, 73], - 7: ["LATEAFTERNOON", 01, 11, 21, 31, 04, 14, 24, 34, 44, 70, 71, 72, 73], - 8: ["EARLYEVENING", 10, 20, 30, 40, 50, 06, 16, 26, 36, 46, 56, 66], - 9: ["EVENING", 06, 16, 26, 36, 46, 56, 66], - 10: ["NIGHT", 37, 47, 57, 67, 77], - 11: ["MIDDLEOFTHENIGHT", 13, 23, 33, 43, 53, 63, 05, 15, 45, 55, 65, 37,47,57,67,77 ], + 0: ["", 0, 0], + 1: ["EARLYMORNING", 10, 20, 30, 40, 50, 02, 12, 22, 32, 42, 52, 62], + 2: ["MORNING", 02, 12, 22, 32, 42, 52, 62], + 3: ["LATEMORNING", 01, 11, 21, 31, 02, 12, 22, 32, 42, 52, 62], + 4: ["MIDDAY", 13, 23, 33, 54, 64, 74], + 5: ["EARLYAFTERNOON", 10, 20, 30, 40, 50, 04, 14, 24, 34, 44, 70, 71, 72, 73], + 6: ["AFTERNOON", 04, 14, 24, 34, 44, 70, 71, 72, 73], + 7: ["LATEAFTERNOON", 01, 11, 21, 31, 04, 14, 24, 34, 44, 70, 71, 72, 73], + 8: ["EARLYEVENING", 10, 20, 30, 40, 50, 06, 16, 26, 36, 46, 56, 66], + 9: ["EVENING", 06, 16, 26, 36, 46, 56, 66], + 10: ["NIGHT", 37, 47, 57, 67, 77], + 11: ["MIDDLEOFTHENIGHT", 13, 23, 33, 43, 53, 63, 05, 15, 45, 55, 65, 37,47,57,67,77 ], }; @@ -51,100 +51,100 @@ var hidxPrev; function drawWordClock() { - // get time - var t = new Date(); - var h = t.getHours(); - var m = t.getMinutes(); - var time = ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2); - var day = t.getDay(); + // get time + var t = new Date(); + var h = t.getHours(); + var m = t.getMinutes(); + var time = ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2); + var day = t.getDay(); - var hidx; + var hidx; - var activeColor = activeColorDay; - if(h < 7 || h > 19) {activeColor = activeColorNight;} + var activeColor = activeColorDay; + if(h < 7 || h > 19) {activeColor = activeColorNight;} - g.setFont("6x8",fontSize); - g.setColor(passivColor); - g.setFontAlign(0, -1, 0); + g.setFont("6x8",fontSize); + g.setColor(passivColor); + g.setFontAlign(0, -1, 0); - // Switch case isn't good for this in Js apparently so... - if(h < 3){ + // Switch case isn't good for this in Js apparently so... + if(h < 3){ // Middle of the Night hidx = 11; - } - else if (h < 7){ + } + else if (h < 7){ // Early Morning hidx = 1; - } - else if (h < 10){ + } + else if (h < 10){ // Morning hidx = 2; - } - else if (h < 12){ + } + else if (h < 12){ // Late Morning hidx = 3; - } - else if (h < 13){ + } + else if (h < 13){ // Midday hidx = 4; - } - else if (h < 14){ + } + else if (h < 14){ // Early afternoon hidx = 5; - } - else if (h < 16){ + } + else if (h < 16){ // Afternoon hidx = 6; - } - else if (h < 17){ + } + else if (h < 17){ // Late Afternoon hidx = 7; - } - else if (h < 19){ + } + else if (h < 19){ // Early evening hidx = 8; - } - else if (h < 21){ + } + else if (h < 21){ // evening hidx = 9; - } - else if (h < 24){ + } + else if (h < 24){ // Night hidx = 10; - } + } - // check whether we need to redraw the watchface - if (hidx !== hidxPrev) { - // draw allWords - var c; - var y = ys; - var x = xs; - allWords.forEach((line) => { - x = xs; - for (c in line) { - g.drawString(line[c], x, y); - x += dx; - } - y += dy; - }); + // check whether we need to redraw the watchface + if (hidx !== hidxPrev) { + // draw allWords + var c; + var y = ys; + var x = xs; + allWords.forEach((line) => { + x = xs; + for (c in line) { + g.drawString(line[c], x, y); + x += dx; + } + y += dy; + }); - // write hour in active color - g.setColor(activeColor); - timeOfDay[hidx][0].split('').forEach((c, pos) => { - x = xs + (timeOfDay[hidx][pos + 1] / 10 | 0) * dx; - y = ys + (timeOfDay[hidx][pos + 1] % 10) * dy; - g.drawString(c, x, y); - }); - hidxPrev = hidx; - } + // write hour in active color + g.setColor(activeColor); + timeOfDay[hidx][0].split('').forEach((c, pos) => { + x = xs + (timeOfDay[hidx][pos + 1] / 10 | 0) * dx; + y = ys + (timeOfDay[hidx][pos + 1] % 10) * dy; + g.drawString(c, x, y); + }); + hidxPrev = hidx; + } - // Display digital time while button 1 is pressed - g.clearRect(0, 215, 240, 240); - if (BTN1.read()){ - g.setColor(activeColor); - g.drawString(time, 120, 215); - } + // Display digital time while button 1 is pressed + g.clearRect(0, 215, 240, 240); + if (BTN1.read()){ + g.setColor(activeColor); + g.drawString(time, 120, 215); + } } diff --git a/apps/jbells/jbells.js b/apps/jbells/jbells.js index faab3defd..1da78f5f1 100644 --- a/apps/jbells/jbells.js +++ b/apps/jbells/jbells.js @@ -3,19 +3,19 @@ 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; + eventEmitter.emit(next); + return; } let note = notes.shift(); let time = times.shift(); Bangle.beep(time, note).then(() => { - setTimeout(() => { + setTimeout(() => { eventEmitter.emit(current); - }, time); + }, time); }); -}); + }); } var one = [2637, 2637, 2637, 2637, 2637, 2637, 2637, 3135, 2093, 2349, 2637]; diff --git a/apps/locale/locales.js b/apps/locale/locales.js index f1df28734..65b080d0c 100644 --- a/apps/locale/locales.js +++ b/apps/locale/locales.js @@ -1,16 +1,16 @@ /* jshint esversion: 6 */ const distanceUnits = { // how many meters per X? - "m": 1, - "yd": 0.9144, - "mi": 1609.34, - "km": 1000, - "kmi": 1000 + "m": 1, + "yd": 0.9144, + "mi": 1609.34, + "km": 1000, + "kmi": 1000 }; const speedUnits = { // how many kph per X? - "kmh": 1, - "kph": 1, - "km/h": 1, - "mph": 1.60934 + "kmh": 1, + "kph": 1, + "km/h": 1, + "mph": 1.60934 }; /* @@ -34,417 +34,417 @@ timePattern / datePattern: */ var locales = { - "en_GB": { // this is default - lang: "en_GB", - decimal_point: ".", - thousands_sep: ",", - currency_symbol: "£", currency_first: true, - int_curr_symbol: "GBP", - speed: 'mph', - distance: { "0": "yd", "1": "mi" }, - temperature: '°C', - ampm: { 0: "am", 1: "pm" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%b %d %Y", 1: "%d/%m/%Y" }, // Feb 28 2020" // "01/03/2020"(short) - abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", - month: "January,February,March,April,May,June,July,August,September,October,November,December", - abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", - day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", - // No translation for english... - }, - "de_DE": { - lang: "de_DE", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "\x80", - int_curr_symbol: "EUR", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH:%MM:%SS", 1: "%HH:%MM" }, - datePattern: { 0: "%A, %d. %B %Y", "1": "%d.%m.%Y" }, // Sonntag, 1. März 2020 // 01.01.20 - abmonth: "Jan,Feb,Mär,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez", - month: "Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember", - abday: "So,Mo,Di,Mi,Do,Fr,Sa", - day: "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag", - trans: { yes: "ja", Yes: "Ja", no: "nein", No: "Nein", ok: "ok", on: "an", off: "aus" } - }, - "en_US": { - lang: "en_US", - decimal_point: ".", - thousands_sep: ",", - currency_symbol: "$", currency_first: true, - int_curr_symbol: "USD", - speed: "mph", - distance: { 0: "yd", 1: "mi" }, - temperature: "°F", - ampm: { 0: "am", 1: "pm" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%b %d, %Y", 1: "%m/%d/%y" }, - abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", - month: "January,February,March,April,May,June,July,August,September,October,November,December", - abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", - day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", - // No translation for english... - }, - "en_JP": { // we do not have the font, so it is not ja_JP - lang: "en_JP", - decimal_point: ".", - thousands_sep: ",", - currency_symbol: "¥", - int_curr_symbol: "JPY", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°F", - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%y/%M/%d", 1: "%y/%m;/%d" }, - abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", - month: "January,February,March,April,May,June,July,August,September,October,November,December", - abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", - day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", - // No translation for english... - }, - "nl_NL": { - lang: "nl_NL", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "\x80", - int_curr_symbol: "EUR", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH:%MM:%SS", 1: "%HH:%MM" }, - datePattern: { 0: "%A %B %d %Y", 1: "%d.%m.%y" }, // zondag 1 maart 2020 // 01.01.20 - abday: "zo,ma,di,wo,do,vr,za", - day: "zondag,maandag,dinsdag,woensdag,donderdag,vrijdag,zaterdag", - abmonth: "jan,feb,mrt,apr,mei,jun,jul,aug,sep,okt,nov,dec", - month: "januari,februari,maart,april,mei,juni,juli,augustus,september,oktober,november,december", - // No translation for english... - }, - "en_CA": { - lang: "en_CA", - decimal_point: ".", - thousands_sep: ",", - currency_symbol: "$", - int_curr_symbol: "CAD", - speed: "km/h", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "am", 1: "pm" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%A, %B %d, %Y", "1": "%Y-%m-%d" }, // Sunday, March 1, 2020 // 2012-12-20 - abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", - month: "January,February,March,April,May,June,July,August,September,October,November,December", - abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", - day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", - // No translation for english... - }, - "fr_FR": { - lang: "fr_FR", - decimal_point: ",", - thousands_sep: " ", - currency_symbol: "\x80", - int_curr_symbol: "EUR", - speed: "km/h", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%A %d %B %Y", "1": "%d/%m/%Y" }, // dimanche 1 mars 2020 // 01/03/2020 - abmonth: "janv,févr,mars,avril,mai,juin,juil,août,sept,oct,nov,déc", - month: "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", - abday: "dim,lun,mar,mer,jeu,ven,sam", - day: "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi", - trans: { yes: "oui", Yes: "Oui", no: "no", No: "No", ok: "ok", on: "on", off: "off" } - }, - "sv_SE": { - lang: "sv_SE", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "kr", - int_curr_symbol: "SKR", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "fm", 1: "em" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%A %B %d %Y", "1": "%Y-%m-%d" }, // söndag 1 mars 2020 // 2020-03-01 - abmonth: "jan,feb,mars,apr,maj,juni,juli,aug,sep,okt,nov,dec", - month: "januari,februari,mars,april,maj,juni,juli,augusti,september,oktober,november,december", - abday: "sön,mån,tis,ons,tors,fre,lör", - day: "söndag,måndag,tisdag,onsdag,torsdag,fredag,lördag", - trans: { yes: "ja", Yes: "Ja", no: "nej", No: "Nej", ok: "ok", on: "on", off: "off" } - }, - "en_AU": { - lang: "en_AU", - decimal_point: ".", - thousands_sep: ",", - currency_symbol: "$", - int_curr_symbol: "AUD", - speed: "mph", - distance: { 0: "mi", 1: "kmi" }, - temperature: "°F", - ampm: { 0: "am", 1: "pm" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%A, %B %d, %Y", "1": "%m/%d/%y" }, // Sunday, 1 March 2020 // 1/3/20 - abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", - month: "January,February,March,April,May,June,July,August,September,October,November,December", - abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", - day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", - // No translation for english... - }, - "de_AT": { - lang: "de_AT", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "\x80", - int_curr_symbol: "EUR", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%A, %d. %B %Y", "1": "%d.%m.%y" }, // Sonntag, 1. März 2020 // 01.03.20 - abmonth: "Jän,Feb,März,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez", - month: "Jänner,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember", - abday: "So,Mo,Di,Mi,Do,Fr,Sa", - day: "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag", - trans: { yes: "ja", Yes: "Ja", no: "nein", No: "Nein", ok: "ok", on: "an", off: "aus" } - }, - "en_IL": { - lang: "en_IL", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "₪", - int_curr_symbol: "ILS", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "am", 1: "pm" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%A, %B %d, %Y", "1": "%d/%m/%Y" }, // Sunday, 1 March 2020 // 01/03/2020 - abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", - month: "January,February,March,April,May,June,July,August,September,October,November,December", - abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", - day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", - // No translation for english... - }, - "es_ES": { - lang: "es_ES", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "\x80", - int_curr_symbol: "EUR", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%A, %d de %B de %Y", "1": "%d/%m/%y" }, // domingo, 1 de marzo de 2020 // 01/03/20 - abmonth: "ene,feb,mar,abr,may,jun,jul,ago,sept,oct,nov,dic", - month: "enero,febrero,marzo,abril,mayo,junio,julio,agosto,septiembre,octubre,noviembre,diciembre", - abday: "dom,lun,mar,mié,jue,vie,sáb", - day: "domingo,lunes,martes,miércoles,jueves,viernes,sábado", - trans: { yes: "sí", Yes: "Sí", no: "no", No: "No", ok: "ok", on: "on", off: "off" } - }, - "fr_BE": { - lang: "fr_BE", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "\x80", - int_curr_symbol: "EUR", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%A %B %d %Y", "1": "%d/%m/%y" }, // dimanche 1 mars 2020 // 01/03/20 - abmonth: "anv.,févr.,mars,avril,mai,juin,juil.,août,sept.,oct.,nov.,déc.", - month: "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", - abday: "dim,lun,mar,mer,jeu,ven,sam", - day: "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi", - trans: { yes: "oui", Yes: "Oui", no: "no", No: "No", ok: "ok", on: "on", off: "off" } - }, - "fi_FI": { - lang: "fi_FI", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "\x80", - int_curr_symbol: "EUR", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "ap", 1: "ip" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, // 17.00.00 // 17.00 - datePattern: { 0: "%A %d. %B %Y", "1": "%-d/%-m/%Y" }, // sunnuntai 1. maaliskuuta 2020 // 1.3.2020 - abmonth: "tammik,helmik,maalisk,huhtik,toukok,kesäk,heinäk,elok,syysk,lokak,marrask,jouluk", - month: "tammikuuta,helmikuuta,maaliskuuta,huhtikuuta,toukokuuta,kesäkuuta,heinäkuuta,elokuuta,syyskuuta,lokakuuta,marraskuuta,joulukuuta", - abday: "su,ma,ti,ke,to,pe,la", - day: "sunnuntaina,maanantaina,tiistaina,keskiviikkona,torstaina,perjantaina,lauantaina", - trans: { yes: "oui", Yes: "Oui", no: "no", No: "No", ok: "ok", on: "on", off: "off" } - }, - "de_CH": { - lang: "de_CH", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "CHF", - int_curr_symbol: "CHF", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "vorm", 1: " nachm" }, - timePattern: { 0: "%HH:%MM:%SS", 1: "%HH:%MM" }, - datePattern: { 0: "%A, %d. %B %Y", "1": "%d.%m.%Y" }, // Sonntag, 1. März 2020 // 1.3.2020 - abmonth: "Jan,Feb,März,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez", - month: "Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember", - abday: "So,Mo,Di,Mi,Do,Fr,Sa", - day: "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag", - trans: { yes: "ja", Yes: "Ja", no: "nein", No: "Nein", ok: "ok", on: "an", off: "aus" } - }, - "fr_CH": { - lang: "fr_CH", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "CHF", - int_curr_symbol: "CHF", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "AM", 1: "PM" }, - timePattern: { 0: "%HH:%MM:%SS", 1: "%HH:%MM" }, - datePattern: { 0: "%A %d %B %Y", "1": "%d/%m/%y" }, // dimanche 1 mars 2020 // 01/03/20 - abmonth: "anv.,févr.,mars,avril,mai,juin,juil.,août,sept.,oct.,nov.,déc.", - month: "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", - abday: "dim,lun,mar,mer,jeu,ven,sam", - day: "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi", - trans: { yes: "oui", Yes: "Oui", no: "no", No: "No", ok: "ok", on: "on", off: "off" } - }, - "it_CH": { - lang: "it_CH", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "CHF", - int_curr_symbol: "CHF", - speed: 'kmh', - distance: { "0": "m", "1": "km" }, - temperature: '°C', - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH.%MM.%SS ", 1: "%HH.%MM" }, // 17.00.00 // 17.00 - datePattern: { 0: "%A %B %d %Y", "1": "%d/%m/%Y" }, // sunnuntai 1. maaliskuuta 2020 // 1.3.2020 - abmonth: "gen,feb,mar,apr,mag,giu,lug,ago,set,ott,nov,dic", - month: "gennaio,febbraio,marzo,aprile,maggio,giugno,luglio,agosto,settembre,ottobre,novembre,dicembre", - abday: "dom,lun,mar,mer,gio,ven,sab", - day: "domenica,lunedì,martedì,mercoledì,giovedì,venerdì, sabato", - trans: { yes: "sì", Yes: "Sì", no: "no", No: "No", ok: "ok", on: "on", off: "off" } - }, - "it_IT": { - lang: "it_IT", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "\x80", - int_curr_symbol: "EUR", - speed: 'kmh', - distance: { "0": "m", "1": "km" }, - temperature: '°C', - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH.%MM.%SS ", 1: "%HH.%MM" }, // 17.00.00 // 17.00 - datePattern: { 0: "%A %B %d %Y", "1": "%d/%m/%Y" }, // sunnuntai 1. maaliskuuta 2020 // 1.3.2020 - abmonth: "gen,feb,mar,apr,mag,giu,lug,ago,set,ott,nov,dic", - month: "gennaio,febbraio,marzo,aprile,maggio,giugno,luglio,agosto,settembre,ottobre,novembre,dicembre", - abday: "dom,lun,mar,mer,gio,ven,sab", - day: "domenica,lunedì,martedì,mercoledì,giovedì,venerdì, sabato", - trans: { yes: "sì", Yes: "Sì", no: "no", No: "No", ok: "ok", on: "on", off: "off" } - }, - "wae_CH": { - lang: "wae_CH", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "CHF", - int_curr_symbol: "CHF", - speed: 'kmh', - distance: { "0": "m", "1": "km" }, - temperature: '°C', - ampm: { 0: "", 1: "" }, - timePattern: { 0: "%HH.%MM.%SS ", 1: "%HH.%MM" }, // 17.00.00 // 17.00 - datePattern: { 0: "%A, %d. %B %Y", "1": "%Y-%m-%d" }, // Sunntag, 1. Märze 2020 // 2020-03-01 - abmonth: "Jen,Hor,Mär,Abr,Mei,Brá,Hei,Öig,Her,Wím,Win,Chr", - month: "Jenner,Hornig,Märze,Abrille,Meije,Bráčet,Heiwet,Öigšte,Herbštmánet,Wímánet,Wintermánet,Chrištmánet", - abday: "Sun,Män,Ziš,Mit,Fró,Fri,Sam", - day: "Sunntag,Mäntag,Zištag,Mittwuč,Fróntag,Fritag,Samštag", - trans: { yes: "sì", Yes: "Sì", no: "no", No: "No", ok: "ok", on: "on", off: "off" } - }, - "tr_TR": { // this is default - lang: "tr_TR", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "TL", - int_curr_symbol: "TRY", - speed: 'kmh', - distance: { "0": "m", "1": "km" }, - temperature: '°C', - ampm: { 0: "öö", 1: "ös" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%d %w %Y %A", 1: "%d/%m/%Y" }, // 1 Mart 2020 Pazar // "01/03/2020" - abmonth: "Oca,Sub,Mar,Nis,May,Haz,Tem,Agu,Eyl,Eki,Kas,Ara", - month: "Ocak,Subat,Mart,Nisan,Mayis,Haziran,Temmuz,Agustos,Eylul,Ekim,Kasim,Aralik", - abday: "Paz,Pzt,Sal,Car,Per,Cum,Cmt", - day: "Pazar,Pazartesi,Sali,Carsamba,Persembe,Cuma,Cumartesi", - trans: { yes: "evet", Yes: "Evet", no: "hayir", No: "Hayir", ok: "tamam", on: "acik", off: "kapali" } - }, - "hu_HU": { - lang: "hu_HU", - decimal_point: ",", - thousands_sep: " ", - currency_symbol: "Ft", - int_curr_symbol: "HUF", - speed: 'kph', - distance: { "0": "m", "1": "km" }, - temperature: '°C', - ampm: { 0: "de", 1: "du" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%Y %b %d, %A", 1: "%Y.%m.%d" }, // 2020 Feb 28, Péntek" // "2020.03.01."(short) - abmonth: "Jan,Feb,Már,Ápr,Máj,Jún,Júl,Aug,Szep,Okt,Nov,Dec", - month: "Január,Február,Március,Április,Május,Június,Július,Augusztus,Szeptember,Október,November,December", - abday: "Vas,Hét,Ke,Szer,Csüt,Pén,Szom", - day: "Vasárnap,Hétfő,Kedd,Szerda,Csütörtök,Péntek,Szombat", - trans: { yes: "igen", Yes: "Igen", no: "nem", No: "Nem", ok: "ok", on: "be", off: "ki" } - }, - "pt_BR": { - lang: "pt_BR", - decimal_point: ",", - thousands_sep: ".", - currency_symbol: "R$", currency_first: true, - int_curr_symbol: "BRL", - speed: "kmh", - distance: { 0: "m", 1: "km" }, - temperature: "°C", - ampm: { 0: "am", 1: "pm" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%d %b %Y", 1: "%d/%m/%y" }, - abmonth: "Jan,Fev,Mar,Abr,Mai,Jun,Jul,Ago,Set,Out,Nov,Dez", - month: "Janeiro,Fevereiro,Março,Abril,Maio,Junho,Julho,Agosto,Setembro,Outubro,Novembro,Dezembro", - abday: "Dom,Seg,Ter,Qua,Qui,Sex,Sab", - day: "Domingo,Segunda-feira,Terça-feira,Quarta-feira,Quinta-feira,Sexta-feira,Sábado", - trans: { yes: "sim", Yes: "Sim", no: "não", No: "Não", ok: "certo", on: "ligado", off: "desligado" } - }, - "cs_CZ": { - lang: "cs_CZ", - decimal_point: ",", - thousands_sep: " ", - currency_symbol: "Kč", - int_curr_symbol: " CZK", - speed: 'kmh', - distance: { "0": "m", "1": "km" }, - temperature: '°C', - ampm: { 0: "dop", 1: "odp" }, - timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, - datePattern: { 0: "%d. %b %Y", 1: "%d.%m.%Y" }, // "30. led 2020" // "30.01.2020"(short) - abmonth: "led,úno,bře,dub,kvě,čvn,čvc,srp,zář,říj,lis,pro", - month: "leden,únor,březen,duben,květen,červen,červenec,srpen,září,říjen,listopad,prosinec", - abday: "ne,po,út,st,čt,pá,so", - day: "neděle,pondělí,úterý,středa,čtvrtek,pátek,sobota", - trans: { yes: "tak", Yes: "Tak", no: "nie", No: "Nie", ok: "ok", on: "na", off: "poza" } - } + "en_GB": { // this is default + lang: "en_GB", + decimal_point: ".", + thousands_sep: ",", + currency_symbol: "£", currency_first: true, + int_curr_symbol: "GBP", + speed: 'mph', + distance: { "0": "yd", "1": "mi" }, + temperature: '°C', + ampm: { 0: "am", 1: "pm" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%b %d %Y", 1: "%d/%m/%Y" }, // Feb 28 2020" // "01/03/2020"(short) + abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", + month: "January,February,March,April,May,June,July,August,September,October,November,December", + abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", + day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", + // No translation for english... + }, + "de_DE": { + lang: "de_DE", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "\x80", + int_curr_symbol: "EUR", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH:%MM:%SS", 1: "%HH:%MM" }, + datePattern: { 0: "%A, %d. %B %Y", "1": "%d.%m.%Y" }, // Sonntag, 1. März 2020 // 01.01.20 + abmonth: "Jan,Feb,Mär,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez", + month: "Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember", + abday: "So,Mo,Di,Mi,Do,Fr,Sa", + day: "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag", + trans: { yes: "ja", Yes: "Ja", no: "nein", No: "Nein", ok: "ok", on: "an", off: "aus" } + }, + "en_US": { + lang: "en_US", + decimal_point: ".", + thousands_sep: ",", + currency_symbol: "$", currency_first: true, + int_curr_symbol: "USD", + speed: "mph", + distance: { 0: "yd", 1: "mi" }, + temperature: "°F", + ampm: { 0: "am", 1: "pm" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%b %d, %Y", 1: "%m/%d/%y" }, + abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", + month: "January,February,March,April,May,June,July,August,September,October,November,December", + abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", + day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", + // No translation for english... + }, + "en_JP": { // we do not have the font, so it is not ja_JP + lang: "en_JP", + decimal_point: ".", + thousands_sep: ",", + currency_symbol: "¥", + int_curr_symbol: "JPY", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°F", + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%y/%M/%d", 1: "%y/%m;/%d" }, + abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", + month: "January,February,March,April,May,June,July,August,September,October,November,December", + abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", + day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", + // No translation for english... + }, + "nl_NL": { + lang: "nl_NL", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "\x80", + int_curr_symbol: "EUR", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH:%MM:%SS", 1: "%HH:%MM" }, + datePattern: { 0: "%A %B %d %Y", 1: "%d.%m.%y" }, // zondag 1 maart 2020 // 01.01.20 + abday: "zo,ma,di,wo,do,vr,za", + day: "zondag,maandag,dinsdag,woensdag,donderdag,vrijdag,zaterdag", + abmonth: "jan,feb,mrt,apr,mei,jun,jul,aug,sep,okt,nov,dec", + month: "januari,februari,maart,april,mei,juni,juli,augustus,september,oktober,november,december", + // No translation for english... + }, + "en_CA": { + lang: "en_CA", + decimal_point: ".", + thousands_sep: ",", + currency_symbol: "$", + int_curr_symbol: "CAD", + speed: "km/h", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "am", 1: "pm" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%A, %B %d, %Y", "1": "%Y-%m-%d" }, // Sunday, March 1, 2020 // 2012-12-20 + abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", + month: "January,February,March,April,May,June,July,August,September,October,November,December", + abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", + day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", + // No translation for english... + }, + "fr_FR": { + lang: "fr_FR", + decimal_point: ",", + thousands_sep: " ", + currency_symbol: "\x80", + int_curr_symbol: "EUR", + speed: "km/h", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%A %d %B %Y", "1": "%d/%m/%Y" }, // dimanche 1 mars 2020 // 01/03/2020 + abmonth: "janv,févr,mars,avril,mai,juin,juil,août,sept,oct,nov,déc", + month: "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", + abday: "dim,lun,mar,mer,jeu,ven,sam", + day: "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi", + trans: { yes: "oui", Yes: "Oui", no: "no", No: "No", ok: "ok", on: "on", off: "off" } + }, + "sv_SE": { + lang: "sv_SE", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "kr", + int_curr_symbol: "SKR", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "fm", 1: "em" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%A %B %d %Y", "1": "%Y-%m-%d" }, // söndag 1 mars 2020 // 2020-03-01 + abmonth: "jan,feb,mars,apr,maj,juni,juli,aug,sep,okt,nov,dec", + month: "januari,februari,mars,april,maj,juni,juli,augusti,september,oktober,november,december", + abday: "sön,mån,tis,ons,tors,fre,lör", + day: "söndag,måndag,tisdag,onsdag,torsdag,fredag,lördag", + trans: { yes: "ja", Yes: "Ja", no: "nej", No: "Nej", ok: "ok", on: "on", off: "off" } + }, + "en_AU": { + lang: "en_AU", + decimal_point: ".", + thousands_sep: ",", + currency_symbol: "$", + int_curr_symbol: "AUD", + speed: "mph", + distance: { 0: "mi", 1: "kmi" }, + temperature: "°F", + ampm: { 0: "am", 1: "pm" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%A, %B %d, %Y", "1": "%m/%d/%y" }, // Sunday, 1 March 2020 // 1/3/20 + abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", + month: "January,February,March,April,May,June,July,August,September,October,November,December", + abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", + day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", + // No translation for english... + }, + "de_AT": { + lang: "de_AT", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "\x80", + int_curr_symbol: "EUR", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%A, %d. %B %Y", "1": "%d.%m.%y" }, // Sonntag, 1. März 2020 // 01.03.20 + abmonth: "Jän,Feb,März,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez", + month: "Jänner,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember", + abday: "So,Mo,Di,Mi,Do,Fr,Sa", + day: "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag", + trans: { yes: "ja", Yes: "Ja", no: "nein", No: "Nein", ok: "ok", on: "an", off: "aus" } + }, + "en_IL": { + lang: "en_IL", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "₪", + int_curr_symbol: "ILS", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "am", 1: "pm" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%A, %B %d, %Y", "1": "%d/%m/%Y" }, // Sunday, 1 March 2020 // 01/03/2020 + abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", + month: "January,February,March,April,May,June,July,August,September,October,November,December", + abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", + day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", + // No translation for english... + }, + "es_ES": { + lang: "es_ES", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "\x80", + int_curr_symbol: "EUR", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%A, %d de %B de %Y", "1": "%d/%m/%y" }, // domingo, 1 de marzo de 2020 // 01/03/20 + abmonth: "ene,feb,mar,abr,may,jun,jul,ago,sept,oct,nov,dic", + month: "enero,febrero,marzo,abril,mayo,junio,julio,agosto,septiembre,octubre,noviembre,diciembre", + abday: "dom,lun,mar,mié,jue,vie,sáb", + day: "domingo,lunes,martes,miércoles,jueves,viernes,sábado", + trans: { yes: "sí", Yes: "Sí", no: "no", No: "No", ok: "ok", on: "on", off: "off" } + }, + "fr_BE": { + lang: "fr_BE", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "\x80", + int_curr_symbol: "EUR", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%A %B %d %Y", "1": "%d/%m/%y" }, // dimanche 1 mars 2020 // 01/03/20 + abmonth: "anv.,févr.,mars,avril,mai,juin,juil.,août,sept.,oct.,nov.,déc.", + month: "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", + abday: "dim,lun,mar,mer,jeu,ven,sam", + day: "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi", + trans: { yes: "oui", Yes: "Oui", no: "no", No: "No", ok: "ok", on: "on", off: "off" } + }, + "fi_FI": { + lang: "fi_FI", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "\x80", + int_curr_symbol: "EUR", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "ap", 1: "ip" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, // 17.00.00 // 17.00 + datePattern: { 0: "%A %d. %B %Y", "1": "%-d/%-m/%Y" }, // sunnuntai 1. maaliskuuta 2020 // 1.3.2020 + abmonth: "tammik,helmik,maalisk,huhtik,toukok,kesäk,heinäk,elok,syysk,lokak,marrask,jouluk", + month: "tammikuuta,helmikuuta,maaliskuuta,huhtikuuta,toukokuuta,kesäkuuta,heinäkuuta,elokuuta,syyskuuta,lokakuuta,marraskuuta,joulukuuta", + abday: "su,ma,ti,ke,to,pe,la", + day: "sunnuntaina,maanantaina,tiistaina,keskiviikkona,torstaina,perjantaina,lauantaina", + trans: { yes: "oui", Yes: "Oui", no: "no", No: "No", ok: "ok", on: "on", off: "off" } + }, + "de_CH": { + lang: "de_CH", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "CHF", + int_curr_symbol: "CHF", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "vorm", 1: " nachm" }, + timePattern: { 0: "%HH:%MM:%SS", 1: "%HH:%MM" }, + datePattern: { 0: "%A, %d. %B %Y", "1": "%d.%m.%Y" }, // Sonntag, 1. März 2020 // 1.3.2020 + abmonth: "Jan,Feb,März,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez", + month: "Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember", + abday: "So,Mo,Di,Mi,Do,Fr,Sa", + day: "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag", + trans: { yes: "ja", Yes: "Ja", no: "nein", No: "Nein", ok: "ok", on: "an", off: "aus" } + }, + "fr_CH": { + lang: "fr_CH", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "CHF", + int_curr_symbol: "CHF", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "AM", 1: "PM" }, + timePattern: { 0: "%HH:%MM:%SS", 1: "%HH:%MM" }, + datePattern: { 0: "%A %d %B %Y", "1": "%d/%m/%y" }, // dimanche 1 mars 2020 // 01/03/20 + abmonth: "anv.,févr.,mars,avril,mai,juin,juil.,août,sept.,oct.,nov.,déc.", + month: "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", + abday: "dim,lun,mar,mer,jeu,ven,sam", + day: "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi", + trans: { yes: "oui", Yes: "Oui", no: "no", No: "No", ok: "ok", on: "on", off: "off" } + }, + "it_CH": { + lang: "it_CH", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "CHF", + int_curr_symbol: "CHF", + speed: 'kmh', + distance: { "0": "m", "1": "km" }, + temperature: '°C', + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH.%MM.%SS ", 1: "%HH.%MM" }, // 17.00.00 // 17.00 + datePattern: { 0: "%A %B %d %Y", "1": "%d/%m/%Y" }, // sunnuntai 1. maaliskuuta 2020 // 1.3.2020 + abmonth: "gen,feb,mar,apr,mag,giu,lug,ago,set,ott,nov,dic", + month: "gennaio,febbraio,marzo,aprile,maggio,giugno,luglio,agosto,settembre,ottobre,novembre,dicembre", + abday: "dom,lun,mar,mer,gio,ven,sab", + day: "domenica,lunedì,martedì,mercoledì,giovedì,venerdì, sabato", + trans: { yes: "sì", Yes: "Sì", no: "no", No: "No", ok: "ok", on: "on", off: "off" } + }, + "it_IT": { + lang: "it_IT", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "\x80", + int_curr_symbol: "EUR", + speed: 'kmh', + distance: { "0": "m", "1": "km" }, + temperature: '°C', + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH.%MM.%SS ", 1: "%HH.%MM" }, // 17.00.00 // 17.00 + datePattern: { 0: "%A %B %d %Y", "1": "%d/%m/%Y" }, // sunnuntai 1. maaliskuuta 2020 // 1.3.2020 + abmonth: "gen,feb,mar,apr,mag,giu,lug,ago,set,ott,nov,dic", + month: "gennaio,febbraio,marzo,aprile,maggio,giugno,luglio,agosto,settembre,ottobre,novembre,dicembre", + abday: "dom,lun,mar,mer,gio,ven,sab", + day: "domenica,lunedì,martedì,mercoledì,giovedì,venerdì, sabato", + trans: { yes: "sì", Yes: "Sì", no: "no", No: "No", ok: "ok", on: "on", off: "off" } + }, + "wae_CH": { + lang: "wae_CH", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "CHF", + int_curr_symbol: "CHF", + speed: 'kmh', + distance: { "0": "m", "1": "km" }, + temperature: '°C', + ampm: { 0: "", 1: "" }, + timePattern: { 0: "%HH.%MM.%SS ", 1: "%HH.%MM" }, // 17.00.00 // 17.00 + datePattern: { 0: "%A, %d. %B %Y", "1": "%Y-%m-%d" }, // Sunntag, 1. Märze 2020 // 2020-03-01 + abmonth: "Jen,Hor,Mär,Abr,Mei,Brá,Hei,Öig,Her,Wím,Win,Chr", + month: "Jenner,Hornig,Märze,Abrille,Meije,Bráčet,Heiwet,Öigšte,Herbštmánet,Wímánet,Wintermánet,Chrištmánet", + abday: "Sun,Män,Ziš,Mit,Fró,Fri,Sam", + day: "Sunntag,Mäntag,Zištag,Mittwuč,Fróntag,Fritag,Samštag", + trans: { yes: "sì", Yes: "Sì", no: "no", No: "No", ok: "ok", on: "on", off: "off" } + }, + "tr_TR": { // this is default + lang: "tr_TR", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "TL", + int_curr_symbol: "TRY", + speed: 'kmh', + distance: { "0": "m", "1": "km" }, + temperature: '°C', + ampm: { 0: "öö", 1: "ös" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%d %w %Y %A", 1: "%d/%m/%Y" }, // 1 Mart 2020 Pazar // "01/03/2020" + abmonth: "Oca,Sub,Mar,Nis,May,Haz,Tem,Agu,Eyl,Eki,Kas,Ara", + month: "Ocak,Subat,Mart,Nisan,Mayis,Haziran,Temmuz,Agustos,Eylul,Ekim,Kasim,Aralik", + abday: "Paz,Pzt,Sal,Car,Per,Cum,Cmt", + day: "Pazar,Pazartesi,Sali,Carsamba,Persembe,Cuma,Cumartesi", + trans: { yes: "evet", Yes: "Evet", no: "hayir", No: "Hayir", ok: "tamam", on: "acik", off: "kapali" } + }, + "hu_HU": { + lang: "hu_HU", + decimal_point: ",", + thousands_sep: " ", + currency_symbol: "Ft", + int_curr_symbol: "HUF", + speed: 'kph', + distance: { "0": "m", "1": "km" }, + temperature: '°C', + ampm: { 0: "de", 1: "du" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%Y %b %d, %A", 1: "%Y.%m.%d" }, // 2020 Feb 28, Péntek" // "2020.03.01."(short) + abmonth: "Jan,Feb,Már,Ápr,Máj,Jún,Júl,Aug,Szep,Okt,Nov,Dec", + month: "Január,Február,Március,Április,Május,Június,Július,Augusztus,Szeptember,Október,November,December", + abday: "Vas,Hét,Ke,Szer,Csüt,Pén,Szom", + day: "Vasárnap,Hétfő,Kedd,Szerda,Csütörtök,Péntek,Szombat", + trans: { yes: "igen", Yes: "Igen", no: "nem", No: "Nem", ok: "ok", on: "be", off: "ki" } + }, + "pt_BR": { + lang: "pt_BR", + decimal_point: ",", + thousands_sep: ".", + currency_symbol: "R$", currency_first: true, + int_curr_symbol: "BRL", + speed: "kmh", + distance: { 0: "m", 1: "km" }, + temperature: "°C", + ampm: { 0: "am", 1: "pm" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%d %b %Y", 1: "%d/%m/%y" }, + abmonth: "Jan,Fev,Mar,Abr,Mai,Jun,Jul,Ago,Set,Out,Nov,Dez", + month: "Janeiro,Fevereiro,Março,Abril,Maio,Junho,Julho,Agosto,Setembro,Outubro,Novembro,Dezembro", + abday: "Dom,Seg,Ter,Qua,Qui,Sex,Sab", + day: "Domingo,Segunda-feira,Terça-feira,Quarta-feira,Quinta-feira,Sexta-feira,Sábado", + trans: { yes: "sim", Yes: "Sim", no: "não", No: "Não", ok: "certo", on: "ligado", off: "desligado" } + }, + "cs_CZ": { + lang: "cs_CZ", + decimal_point: ",", + thousands_sep: " ", + currency_symbol: "Kč", + int_curr_symbol: " CZK", + speed: 'kmh', + distance: { "0": "m", "1": "km" }, + temperature: '°C', + ampm: { 0: "dop", 1: "odp" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%d. %b %Y", 1: "%d.%m.%Y" }, // "30. led 2020" // "30.01.2020"(short) + abmonth: "led,úno,bře,dub,kvě,čvn,čvc,srp,zář,říj,lis,pro", + month: "leden,únor,březen,duben,květen,červen,červenec,srpen,září,říjen,listopad,prosinec", + abday: "ne,po,út,st,čt,pá,so", + day: "neděle,pondělí,úterý,středa,čtvrtek,pátek,sobota", + trans: { yes: "tak", Yes: "Tak", no: "nie", No: "Nie", ok: "ok", on: "na", off: "poza" } + } }; diff --git a/apps/marioclock/marioclock-app.js b/apps/marioclock/marioclock-app.js index 7601b89ba..886e53dc0 100644 --- a/apps/marioclock/marioclock-app.js +++ b/apps/marioclock/marioclock-app.js @@ -96,30 +96,30 @@ function phoneOutbound(msg) { } function phoneClearMessage() { - if (phone.message === null) return; + if (phone.message === null) return; - if (phone.messageTimeout) { - clearTimeout(phone.messageTimeout); - phone.messageTimeout = null; - } - phone.message = null; - phone.messageScrollX = null; - phone.messageType = null; + if (phone.messageTimeout) { + clearTimeout(phone.messageTimeout); + phone.messageTimeout = null; + } + phone.message = null; + phone.messageScrollX = null; + phone.messageType = null; } function phoneNewMessage(type, msg) { - Bangle.buzz(); + Bangle.buzz(); - phoneClearMessage(); - phone.messageTimeout = setTimeout(() => phone.message = null, ONE_SECOND * 30); - phone.message = msg; - phone.messageType = type; + phoneClearMessage(); + phone.messageTimeout = setTimeout(() => phone.message = null, ONE_SECOND * 30); + phone.message = msg; + phone.messageType = type; - // Notify user and active screen - if (!Bangle.isLCDOn()) { - clearTimers(); - Bangle.setLCDPower(true); - } + // Notify user and active screen + if (!Bangle.isLCDOn()) { + clearTimers(); + Bangle.setLCDPower(true); + } } function truncStr(str, max) { @@ -258,7 +258,7 @@ function drawTrees() { // remove first sprite if offscreen let firstBackgroundSprite = backgroundArr[0]; if (firstBackgroundSprite) { - if (firstBackgroundSprite.x < -15) backgroundArr.splice(0, 1); + if (firstBackgroundSprite.x < -15) backgroundArr.splice(0, 1); } // set background sprite if array empty @@ -365,7 +365,7 @@ function drawNotice(x, y) { function drawCharacter(date, character) { // calculate jumping const seconds = date.getSeconds(), - milliseconds = date.getMilliseconds(); + milliseconds = date.getMilliseconds(); if (seconds == 59 && milliseconds > 800 && !characterSprite.isJumping) { characterSprite.isJumping = true; @@ -486,22 +486,22 @@ function drawInfo(date) { } xPos = phone.messageScrollX; } else { - xPos = (W - g.stringWidth(str)) / 2; + xPos = (W - g.stringWidth(str)) / 2; } } else { switch(infoMode) { - case PHON_MODE: - str = buildPhonStr(); - break; - case TEMP_MODE: - str = buildTempStr(); - break; - case BATT_MODE: - str = buildBatStr(); - break; - case DATE_MODE: - default: - str = buildDateStr(date); + case PHON_MODE: + str = buildPhonStr(); + break; + case TEMP_MODE: + str = buildTempStr(); + break; + case BATT_MODE: + str = buildBatStr(); + break; + case DATE_MODE: + default: + str = buildDateStr(date); } xPos = (W - g.stringWidth(str)) / 2; } diff --git a/apps/mclock/clock-morphing.js b/apps/mclock/clock-morphing.js index 32048cd60..15ab206b9 100644 --- a/apps/mclock/clock-morphing.js +++ b/apps/mclock/clock-morphing.js @@ -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. diff --git a/apps/metronome/metronome.js b/apps/metronome/metronome.js index 6e0827c19..275c6775d 100644 --- a/apps/metronome/metronome.js +++ b/apps/metronome/metronome.js @@ -29,23 +29,23 @@ function loadSettings() { function changecolor() { const colors = { - 0: { value: 0xF800, name: "Red" }, - 1: { value: 0xFFFF, name: "White" }, - 2: { value: 0x9492, name: "gray" }, - 3: { value: 0xFFFF, name: "White" }, - 4: { value: 0x9492, name: "gray" }, - 5: { value: 0xFFFF, name: "White" }, - 6: { value: 0x9492, name: "gray" }, - 7: { value: 0xFFFF, name: "White" }, - }; - g.setColor(colors[cindex].value); - if (cindex == setting('beatsperbar')-1) { - cindex = 0; - } - else { + 0: { value: 0xF800, name: "Red" }, + 1: { value: 0xFFFF, name: "White" }, + 2: { value: 0x9492, name: "gray" }, + 3: { value: 0xFFFF, name: "White" }, + 4: { value: 0x9492, name: "gray" }, + 5: { value: 0xFFFF, name: "White" }, + 6: { value: 0x9492, name: "gray" }, + 7: { value: 0xFFFF, name: "White" }, + }; + g.setColor(colors[cindex].value); + if (cindex == setting('beatsperbar')-1) { + cindex = 0; + } + else { cindex += 1; - } - return cindex; + } + return cindex; } function updateScreen() { @@ -63,27 +63,27 @@ function updateScreen() { Bangle.on('touch', function(button) { // setting bpm by tapping the screen. Uses the mean time difference between several tappings. - if (tindex < time_diffs.length) { - if (Date.now()-tStart < 5000) { - time_diffs[tindex] = Date.now()-tStart; - } - } else { - tindex=0; - time_diffs[tindex] = Date.now()-tStart; - } - tindex += 1; - mean_time = 0.0; - for(count = 0; count < time_diffs.length; count++) { - mean_time += time_diffs[count]; + if (tindex < time_diffs.length) { + if (Date.now()-tStart < 5000) { + time_diffs[tindex] = Date.now()-tStart; } - time_diff = mean_time/count; + } else { + tindex=0; + time_diffs[tindex] = Date.now()-tStart; + } + tindex += 1; + mean_time = 0.0; + for(count = 0; count < time_diffs.length; count++) { + mean_time += time_diffs[count]; + } + time_diff = mean_time/count; - tStart = Date.now(); - clearInterval(time_diff); - bpm = (60 * 1000/(time_diff)); - updateScreen(); - clearInterval(interval); - interval = setInterval(updateScreen, 60000 / bpm); + tStart = Date.now(); + clearInterval(time_diff); + bpm = (60 * 1000/(time_diff)); + updateScreen(); + clearInterval(interval); + interval = setInterval(updateScreen, 60000 / bpm); return bpm; }); @@ -96,9 +96,9 @@ setWatch(() => { setWatch(() => { if (bpm > 1) { - bpm -= 1; - clearInterval(interval); - interval = setInterval(updateScreen, 60000 / bpm); + bpm -= 1; + clearInterval(interval); + interval = setInterval(updateScreen, 60000 / bpm); } }, BTN3, {repeat:true}); diff --git a/apps/miclock/clock-mixed.js b/apps/miclock/clock-mixed.js index bf6efb09e..0bed137c6 100644 --- a/apps/miclock/clock-mixed.js +++ b/apps/miclock/clock-mixed.js @@ -4,73 +4,73 @@ const Radius = { "center": 8, "hour": 78, "min": 95, "dots": 102 }; const Center = { "x": 120, "y": 132 }; function rotatePoint(x, y, d) { - rad = -1 * d / 180 * Math.PI; - var sin = Math.sin(rad); - var cos = Math.cos(rad); - xn = ((Center.x + x * cos - y * sin) + 0.5) | 0; - yn = ((Center.y + x * sin - y * cos) + 0.5) | 0; - p = [xn, yn]; - return p; + rad = -1 * d / 180 * Math.PI; + var sin = Math.sin(rad); + var cos = Math.cos(rad); + xn = ((Center.x + x * cos - y * sin) + 0.5) | 0; + yn = ((Center.y + x * sin - y * cos) + 0.5) | 0; + p = [xn, yn]; + return p; } function drawMixedClock() { - var date = new Date(); - var dateArray = date.toString().split(" "); - var isEn = locale.name.startsWith("en"); - var point = []; - var minute = date.getMinutes(); - var hour = date.getHours(); - var radius; + var date = new Date(); + var dateArray = date.toString().split(" "); + var isEn = locale.name.startsWith("en"); + var point = []; + var minute = date.getMinutes(); + var hour = date.getHours(); + var radius; - // draw date - g.setColor(0x7be0); - g.setFont("6x8", 2); - g.setFontAlign(-1, 0); - g.drawString(locale.dow(date,true) + ' ', 4, 35, true); - g.drawString(isEn?(' ' + dateArray[2]):locale.month(date,true), 4, 225, true); - g.setFontAlign(1, 0); - g.drawString(isEn?locale.month(date,true):(' ' + dateArray[2]), 237, 35, true); - g.drawString(dateArray[3], 237, 225, true); + // draw date + g.setColor(0x7be0); + g.setFont("6x8", 2); + g.setFontAlign(-1, 0); + g.drawString(locale.dow(date,true) + ' ', 4, 35, true); + g.drawString(isEn?(' ' + dateArray[2]):locale.month(date,true), 4, 225, true); + g.setFontAlign(1, 0); + g.drawString(isEn?locale.month(date,true):(' ' + dateArray[2]), 237, 35, true); + g.drawString(dateArray[3], 237, 225, true); - // draw hour and minute dots - g.setColor(0xFD20); // orange - for (i = 0; i < 60; i++) { - radius = (i % 5) ? 2 : 4; - point = rotatePoint(0, Radius.dots, i * 6); - g.fillCircle(point[0], point[1], radius); - } + // draw hour and minute dots + g.setColor(0xFD20); // orange + for (i = 0; i < 60; i++) { + radius = (i % 5) ? 2 : 4; + point = rotatePoint(0, Radius.dots, i * 6); + g.fillCircle(point[0], point[1], radius); + } - // erase last minutes hand - g.setColor(0); - point = rotatePoint(0, Radius.min, (minute - 1) * 6); - g.drawLine(Center.x, Center.y, point[0], point[1]); + // erase last minutes hand + g.setColor(0); + point = rotatePoint(0, Radius.min, (minute - 1) * 6); + g.drawLine(Center.x, Center.y, point[0], point[1]); - // erase last two hour hands - g.setColor(0); - p = rotatePoint(0, Radius.hour, hour % 12 * 30 + (minute - 2) / 2 | 0); - g.drawLine(Center.x, Center.y, p[0], p[1]); - point = rotatePoint(0, Radius.hour, hour % 12 * 30 + (minute - 1) / 2 | 0); - g.drawLine(Center.x, Center.y, point[0], point[1]); + // erase last two hour hands + g.setColor(0); + p = rotatePoint(0, Radius.hour, hour % 12 * 30 + (minute - 2) / 2 | 0); + g.drawLine(Center.x, Center.y, p[0], p[1]); + point = rotatePoint(0, Radius.hour, hour % 12 * 30 + (minute - 1) / 2 | 0); + g.drawLine(Center.x, Center.y, point[0], point[1]); - // draw digital time - g.setFont("6x8", 3); - g.setColor(0x7be0); - g.setFontAlign(0, 0); - g.drawString(dateArray[4].substr(0, 5), 120, 180, true); + // draw digital time + g.setFont("6x8", 3); + g.setColor(0x7be0); + g.setFontAlign(0, 0); + g.drawString(dateArray[4].substr(0, 5), 120, 180, true); - // draw new minute hand - point = rotatePoint(0, Radius.min, minute * 6); - g.setColor(0xFFFF); - g.drawLine(Center.x, Center.y, point[0], point[1]); - // draw new hour hand - point = rotatePoint(0, Radius.hour, hour % 12 * 30 + date.getMinutes() / 2 | 0); - g.setColor(0xFFFF); - g.drawLine(Center.x, Center.y, point[0], point[1]); + // draw new minute hand + point = rotatePoint(0, Radius.min, minute * 6); + g.setColor(0xFFFF); + g.drawLine(Center.x, Center.y, point[0], point[1]); + // draw new hour hand + point = rotatePoint(0, Radius.hour, hour % 12 * 30 + date.getMinutes() / 2 | 0); + g.setColor(0xFFFF); + g.drawLine(Center.x, Center.y, point[0], point[1]); - // draw center - g.setColor(0xFD20); - g.fillCircle(Center.x, Center.y, Radius.center); + // draw center + g.setColor(0xFD20); + g.fillCircle(Center.x, Center.y, Radius.center); } Bangle.on('lcdPower', function(on) { if (on) diff --git a/apps/miplant/app.js b/apps/miplant/app.js index 336fddc15..f26bfc5b8 100644 --- a/apps/miplant/app.js +++ b/apps/miplant/app.js @@ -32,8 +32,8 @@ function parseDevice(device) { case 0x1009: event.fertility = d.getUint16(offset+3,true)/10; break; // case 0x1007: break; // 3 bytes? got 84,0,0 or 68,0,0 default: event.code = code; - event.raw = new Uint8Array(d.buffer, offset+3, l); - break; + event.raw = new Uint8Array(d.buffer, offset+3, l); + break; } //print(event); show(event); diff --git a/apps/mmonday/manic-monday.js b/apps/mmonday/manic-monday.js index c949fafbf..fd76ee328 100644 --- a/apps/mmonday/manic-monday.js +++ b/apps/mmonday/manic-monday.js @@ -7,12 +7,12 @@ but because we're going lower level we need to account for the different pin. */ if (s.beep=="vib") { function freq(f) { - if (f===0) digitalWrite(D13, 0); + if (f===0) digitalWrite(D13, 0); else analogWrite(D13, 0.1, {freq: f}); } } else { function freq(f) { - if (f===0) digitalWrite(D18, 0); + if (f===0) digitalWrite(D18, 0); else analogWrite(D18, 0.5, {freq: f}); } } diff --git a/apps/moonphase/app.js b/apps/moonphase/app.js index 480a0e144..321e6ab3f 100644 --- a/apps/moonphase/app.js +++ b/apps/moonphase/app.js @@ -8,22 +8,22 @@ var timer; var fix; var PI = Math.PI, - sin = Math.sin, - cos = Math.cos, - tan = Math.tan, - asin = Math.asin, - atan = Math.atan2, - acos = Math.acos, - rad = PI / 180, - dayMs = 1000 * 60 * 60 * 24, - J1970 = 2440588, - J2000 = 2451545; + sin = Math.sin, + cos = Math.cos, + tan = Math.tan, + asin = Math.asin, + atan = Math.atan2, + acos = Math.acos, + rad = PI / 180, + dayMs = 1000 * 60 * 60 * 24, + J1970 = 2440588, + J2000 = 2451545; var SunCalc = {}; //pictures function getImg(i) { - var data = { + var data = { "NewMoon": "AD8AAH/4AHwPgDwA8BwADg4AAcMAADHAAA5gAAGYAABsAAAPAAADwAAA8AAAPAAADwAAA2AAAZgAAGcAADjAAAw4AAcHAAOA8APAHwPgAf/gAA/AAA==", "WaxingCrescentNorth" : "AD8AAH/4AHw/gDwH8BwA/g4AH8MAB/HAAf5gAD+YAA/sAAP/AAD/wAA/8AAP/AAD/wAA/2AAP5gAD+cAB/jAAfw4AH8HAD+A8B/AHw/gAf/gAA/AAA==", "WaningCrescentSouth" : "AD8AAH/4AHw/gDwH8BwA/g4AH8MAB/HAAf5gAD+YAA/sAAP/AAD/wAA/8AAP/AAD/wAA/2AAP5gAD+cAB/jAAfw4AH8HAD+A8B/AHw/gAf/gAA/AAA==", @@ -38,12 +38,12 @@ function getImg(i) { "LastQuarterSouth" : "AD8AAH/4AHx/gDwf8BwH/g4B/8MAf/HAH/5gB/+YAf/sAH//AB//wAf/8AH//AB//wAf/2AH/5gB/+cAf/jAH/w4B/8HAf+A8H/AHx/gAf/gAA/AAA==", "WaningCrescentNorth" : "AD8AAH/4AH8PgD+A8B/ADg/gAcP4ADH+AA5/AAGfwABv8AAP/AAD/wAA/8AAP/AAD/wAA38AAZ/AAGf4ADj+AAw/gAcH8AOA/gPAH8PgAf/gAA/AAA==", "WaxingCrescentSouth" : "AD8AAH/4AH8PgD+A8B/ADg/gAcP4ADH+AA5/AAGfwABv8AAP/AAD/wAA/8AAP/AAD/wAA38AAZ/AAGf4ADj+AAw/gAcH8AOA/gPAH8PgAf/gAA/AAA==" - }; - return { - width : 26, height : 26, bpp : 1, - transparent : 0, - buffer : E.toArrayBuffer(atob(data[i])) - }; + }; + return { + width : 26, height : 26, bpp : 1, + transparent : 0, + buffer : E.toArrayBuffer(atob(data[i])) + }; } // sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas // date/time constants and conversions @@ -59,182 +59,182 @@ function azimuth(H, phi, dec) { return atan(sin(H), cos(H) * sin(phi) - tan(dec 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 astroRefraction(h) { - if (h < 0) // the following formula works for positive altitudes only. - h = 0; // if h = -0.08901179 a div/0 would occur. + 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)); + // 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 function solarMeanAnomaly(d) { return rad * (357.5291 + 0.98560028 * d); } 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 + 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; + return M + C + P + PI; } function sunCoords(d) { - var M = solarMeanAnomaly(d), - L = eclipticLongitude(M); - return { - dec: declination(L, 0), - ra: rightAscension(L, 0) - }; + var M = solarMeanAnomaly(d), + L = eclipticLongitude(M); + return { + dec: declination(L, 0), + ra: rightAscension(L, 0) + }; } // adds a custom time to the times config SunCalc.addTime = function (angle, riseName, setName) { - times.push([angle, riseName, setName]); + times.push([angle, riseName, setName]); }; // moon calculations, based on http://aa.quae.nl/en/reken/hemelpositie.html formulas 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 - F = rad * (93.272 + 13.229350 * d), // mean distance - l = L + rad * 6.289 * sin(M), // longitude - b = rad * 5.128 * sin(F), // latitude - dt = 385001 - 20905 * cos(M); // distance to the moon in km + var L = rad * (218.316 + 13.176396 * d), // ecliptic longitude + M = rad * (134.963 + 13.064993 * d), // mean anomaly + F = rad * (93.272 + 13.229350 * d), // mean distance + l = L + rad * 6.289 * sin(M), // longitude + b = rad * 5.128 * sin(F), // latitude + dt = 385001 - 20905 * cos(M); // distance to the moon in km - return { - ra: rightAscension(l, b), - dec: declination(l, b), - dist: dt - }; + return { + ra: rightAscension(l, b), + dec: declination(l, b), + dist: dt + }; } SunCalc.getMoonPosition = function (date, lat, lng) { - var lw = rad * -lng, - phi = rad * lat, - d = toDays(date), - c = moonCoords(d), - H = siderealTime(d, lw) - c.ra, - h = altitude(H, phi, c.dec), - // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H)); - h = h + astroRefraction(h); // altitude correction for refraction - return { - azimuth: azimuth(H, phi, c.dec), - altitude: h, - distance: c.dist, - parallacticAngle: pa - }; + var lw = rad * -lng, + phi = rad * lat, + d = toDays(date), + c = moonCoords(d), + H = siderealTime(d, lw) - c.ra, + h = altitude(H, phi, c.dec), + // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. + pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H)); + h = h + astroRefraction(h); // altitude correction for refraction + return { + azimuth: azimuth(H, phi, c.dec), + altitude: h, + 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. SunCalc.getMoonIllumination = function (date) { - var year = date.getFullYear(); - var month = date.getMonth(); - var day = date.getDate(); - var Moon = { - phases: ['new', 'waxing-crescent', 'first-quarter', 'waxing-gibbous', 'full', 'waning-gibbous', 'last-quarter', 'waning-crescent'], - phase: function (year, month, day) { - let c = 0; - let e = 0; - let jd = 0; - let b = 0; - if (month < 3) { - year--; - month += 12; - } - ++month; - c = 365.25 * year; - e = 30.6 * month; - jd = c + e + day - 694039.09; // jd is total days elapsed - jd /= 29.5305882; // divide by the moon cycle - b = parseInt(jd); // int(jd) -> b, take integer part of jd - jd -= b; // subtract integer part to leave fractional part of original jd - b = Math.round(jd * 8); // scale fraction from 0-8 and round - if (b >= 8) b = 0; // 0 and 8 are the same so turn 8 into 0 - return {phase: b, name: Moon.phases[b]}; - } - }; - return (Moon.phase(year, month, day)); + var year = date.getFullYear(); + var month = date.getMonth(); + var day = date.getDate(); + var Moon = { + phases: ['new', 'waxing-crescent', 'first-quarter', 'waxing-gibbous', 'full', 'waning-gibbous', 'last-quarter', 'waning-crescent'], + phase: function (year, month, day) { + let c = 0; + let e = 0; + let jd = 0; + let b = 0; + if (month < 3) { + year--; + month += 12; + } + ++month; + c = 365.25 * year; + e = 30.6 * month; + jd = c + e + day - 694039.09; // jd is total days elapsed + jd /= 29.5305882; // divide by the moon cycle + b = parseInt(jd); // int(jd) -> b, take integer part of jd + jd -= b; // subtract integer part to leave fractional part of original jd + b = Math.round(jd * 8); // scale fraction from 0-8 and round + if (b >= 8) b = 0; // 0 and 8 are the same so turn 8 into 0 + return {phase: b, name: Moon.phases[b]}; + } + }; + return (Moon.phase(year, month, day)); }; 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 SunCalc.getMoonTimes = function (date, lat, lng, inUTC) { - var t = new Date(date); - if (inUTC) t.setUTCHours(0, 0, 0, 0); - else t.setHours(0, 0, 0, 0); - var hc = 0.133 * rad, - h0 = SunCalc.getMoonPosition(t, lat, lng).altitude - hc, - h1, h2, rise, set, a, b, xe, ye, d, roots, x1, x2, dx; + var t = new Date(date); + if (inUTC) t.setUTCHours(0, 0, 0, 0); + else t.setHours(0, 0, 0, 0); + var hc = 0.133 * rad, + h0 = SunCalc.getMoonPosition(t, lat, lng).altitude - hc, + h1, h2, rise, set, a, b, xe, ye, d, roots, x1, x2, dx; - // go in 2-hour chunks, each time seeing if a 3-point quadratic curve crosses zero (which means rise or set) - for (var i = 1; i <= 24; i += 2) { - h1 = SunCalc.getMoonPosition(hoursLater(t, i), lat, lng).altitude - hc; - h2 = SunCalc.getMoonPosition(hoursLater(t, i + 1), lat, lng).altitude - hc; - a = (h0 + h2) / 2 - h1; - b = (h2 - h0) / 2; - xe = -b / (2 * a); - ye = (a * xe + b) * xe + h1; - d = b * b - 4 * a * h1; - roots = 0; - if (d >= 0) { - dx = Math.sqrt(d) / (Math.abs(a) * 2); - x1 = xe - dx; - x2 = xe + dx; - if (Math.abs(x1) <= 1) roots++; - if (Math.abs(x2) <= 1) roots++; - if (x1 < -1) x1 = x2; - } - if (roots === 1) { - if (h0 < 0) rise = i + x1; - else set = i + x1; - } else if (roots === 2) { - rise = i + (ye < 0 ? x2 : x1); - set = i + (ye < 0 ? x1 : x2); - } - if (rise && set) break; - h0 = h2; + // go in 2-hour chunks, each time seeing if a 3-point quadratic curve crosses zero (which means rise or set) + for (var i = 1; i <= 24; i += 2) { + h1 = SunCalc.getMoonPosition(hoursLater(t, i), lat, lng).altitude - hc; + h2 = SunCalc.getMoonPosition(hoursLater(t, i + 1), lat, lng).altitude - hc; + a = (h0 + h2) / 2 - h1; + b = (h2 - h0) / 2; + xe = -b / (2 * a); + ye = (a * xe + b) * xe + h1; + d = b * b - 4 * a * h1; + roots = 0; + if (d >= 0) { + dx = Math.sqrt(d) / (Math.abs(a) * 2); + x1 = xe - dx; + x2 = xe + dx; + if (Math.abs(x1) <= 1) roots++; + if (Math.abs(x2) <= 1) roots++; + if (x1 < -1) x1 = x2; } - var result = {}; - if (rise) result.rise = hoursLater(t, rise); - if (set) result.set = hoursLater(t, set); - if (!rise && !set) result[ye > 0 ? 'alwaysUp' : 'alwaysDown'] = true; - return result; + if (roots === 1) { + if (h0 < 0) rise = i + x1; + else set = i + x1; + } else if (roots === 2) { + rise = i + (ye < 0 ? x2 : x1); + set = i + (ye < 0 ? x1 : x2); + } + if (rise && set) break; + h0 = h2; + } + var result = {}; + if (rise) result.rise = hoursLater(t, rise); + if (set) result.set = hoursLater(t, set); + if (!rise && !set) result[ye > 0 ? 'alwaysUp' : 'alwaysDown'] = true; + return result; }; function getMPhaseComp (offset) { - var date = new Date(); - date.setDate(date.getDate() + offset); - var dd = String(date.getDate()); - if(dd<10){dd='0'+dd;} - var mm = String(date.getMonth() + 1); - if(mm<10){mm='0'+mm;} - var yyyy = date.getFullYear(); - var phase = SunCalc.getMoonIllumination(date); - return dd + "." + mm + "." + yyyy + ": "+ phase.name; + var date = new Date(); + date.setDate(date.getDate() + offset); + var dd = String(date.getDate()); + if(dd<10){dd='0'+dd;} + var mm = String(date.getMonth() + 1); + if(mm<10){mm='0'+mm;} + var yyyy = date.getFullYear(); + var phase = SunCalc.getMoonIllumination(date); + return dd + "." + mm + "." + yyyy + ": "+ phase.name; } function getMPhaseSim (offset) { - var date = new Date(); - date.setDate(date.getDate() + offset); - var dd = String(date.getDate()); - if(dd<10){dd='0'+dd;} - var mm = String(date.getMonth() + 1); - if(mm<10){mm='0'+mm;} - var yyyy = date.getFullYear(); - var phase = SunCalc.getMoonIllumination(date); - return phase.name; + var date = new Date(); + date.setDate(date.getDate() + offset); + var dd = String(date.getDate()); + if(dd<10){dd='0'+dd;} + var mm = String(date.getMonth() + 1); + if(mm<10){mm='0'+mm;} + var yyyy = date.getFullYear(); + var phase = SunCalc.getMoonIllumination(date); + return phase.name; } function drawMoonPhase(offset, x, y){ - if (coords.lat >= 0 && coords.lat <= 90){ //Northern hemisphere + if (coords.lat >= 0 && coords.lat <= 90){ //Northern hemisphere if (getMPhaseSim(offset) == "new") {g.drawImage(getImg("NewMoon"), x, y);} if (getMPhaseSim(offset) == "waxing-crescent") {g.drawImage(getImg("WaxingCrescentNorth"), x, y);} if (getMPhaseSim(offset) == "first-quarter") {g.drawImage(getImg("FirstQuarterNorth"), x, y);} @@ -243,8 +243,8 @@ 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 + } + else { //Southern hemisphere if (getMPhaseSim(offset) == "new") {g.drawImage(getImg("NewMoon"), x, y);} if (getMPhaseSim(offset) == "waxing-crescent") {g.drawImage(getImg("WaxingCrescentSouth"), x, y);} if (getMPhaseSim(offset) == "first-quarter") {g.drawImage(getImg("FirstQuarterSouth"), x, y);} @@ -253,101 +253,101 @@ function drawMoonPhase(offset, x, y){ if (getMPhaseSim(offset) == "waning-gibbous") {g.drawImage(getImg("WaningGibbousSouth"), x, y);} if (getMPhaseSim(offset) == "last-quarter") {g.drawImage(getImg("LastQuarterSouth"), x, y);} if (getMPhaseSim(offset) == "waning-crescent") {g.drawImage(getImg("WaningCrescentSouth"), x, y);} - } + } } function drawMoon(offset, x, y) { - g.setFont("6x8"); - g.clear(); - g.drawString("Key1: day+, Key2:today, Key3:day-",x,y-30); - g.drawString("Last known coordinates: " + coords.lat.toFixed(4) + " " + coords.lon.toFixed(4), x, y-20); - g.drawString("Press BTN4 to update",x, y-10); + g.setFont("6x8"); + g.clear(); + g.drawString("Key1: day+, Key2:today, Key3:day-",x,y-30); + g.drawString("Last known coordinates: " + coords.lat.toFixed(4) + " " + coords.lon.toFixed(4), x, y-20); + g.drawString("Press BTN4 to update",x, y-10); - g.drawString(getMPhaseComp(offset),x,y+30); - drawMoonPhase(offset, x+35, y+40); + g.drawString(getMPhaseComp(offset),x,y+30); + drawMoonPhase(offset, x+35, y+40); - g.drawString(getMPhaseComp(offset+2),x,y+70); - drawMoonPhase(offset+2, x+35, y+80); + g.drawString(getMPhaseComp(offset+2),x,y+70); + drawMoonPhase(offset+2, x+35, y+80); - g.drawString(getMPhaseComp(offset+4),x,y+110); - drawMoonPhase(offset+4, x+35, y+120); + g.drawString(getMPhaseComp(offset+4),x,y+110); + drawMoonPhase(offset+4, x+35, y+120); - g.drawString(getMPhaseComp(offset+6),x,y+150); - drawMoonPhase(offset+6, x+35, y+160); + g.drawString(getMPhaseComp(offset+6),x,y+150); + drawMoonPhase(offset+6, x+35, y+160); } //Write coordinates to file function updateCoords() { - storage.write('coords.json', coords); + storage.write('coords.json', coords); } //set coordinates to default (city where I live) function resetCoords() { - coords = { + coords = { lat : 52.96236, lon : 7.62571, - }; - updateCoords(); + }; + updateCoords(); } function getGpsFix() { - Bangle.on('GPS', function(fix) { - g.clear(); + Bangle.on('GPS', function(fix) { + g.clear(); - if (fix.fix == 1) { - var gpsString = "lat: " + fix.lat.toFixed(4) + " lon: " + fix.lon.toFixed(4); - coords.lat = fix.lat; - coords.lon = fix.lon; - updateCoords(); - g.drawString("Got GPS fix and wrote coords to file",10,20); - g.drawString(gpsString,10,30); - g.drawString("Press BTN5 to return to app",10,40); - clearInterval(timer); - timer = undefined; - } - else { - g.drawString("Searching satellites...",10,20); - g.drawString("Press BTN5 to stop GPS",10, 30); - } - }); + if (fix.fix == 1) { + var gpsString = "lat: " + fix.lat.toFixed(4) + " lon: " + fix.lon.toFixed(4); + coords.lat = fix.lat; + coords.lon = fix.lon; + updateCoords(); + g.drawString("Got GPS fix and wrote coords to file",10,20); + g.drawString(gpsString,10,30); + g.drawString("Press BTN5 to return to app",10,40); + clearInterval(timer); + timer = undefined; + } + else { + g.drawString("Searching satellites...",10,20); + g.drawString("Press BTN5 to stop GPS",10, 30); + } + }); } function start() { - var x = 10; - var y = 50; - var offsetMoon = 0; - coords = storage.readJSON('coords.json',1); //read coordinates from file - if (!coords) resetCoords(); //if coordinates could not be read, reset them + var x = 10; + var y = 50; + var offsetMoon = 0; + coords = storage.readJSON('coords.json',1); //read coordinates from file + if (!coords) resetCoords(); //if coordinates could not be read, reset them + drawMoon(offsetMoon, x, y); //offset, x, y + + //define button functions + setWatch(function() { //BTN1 + offsetMoon++; //jump to next day drawMoon(offsetMoon, x, y); //offset, x, y + }, BTN1, {edge:"rising", debounce:50, repeat:true}); - //define button functions - setWatch(function() { //BTN1 - offsetMoon++; //jump to next day - drawMoon(offsetMoon, x, y); //offset, x, y - }, BTN1, {edge:"rising", debounce:50, repeat:true}); + setWatch(function() { //BTN2 + offsetMoon = 0; //jump to today + drawMoon(offsetMoon, x, y); //offset, x, y + }, BTN2, {edge:"rising", debounce:50, repeat:true}); - setWatch(function() { //BTN2 - offsetMoon = 0; //jump to today - drawMoon(offsetMoon, x, y); //offset, x, y - }, BTN2, {edge:"rising", debounce:50, repeat:true}); + setWatch(function() { //BTN3 + offsetMoon--; //jump to next day + drawMoon(offsetMoon, x, y); //offset, x, y + }, BTN3, {edge:"rising", debounce:50, repeat:true}); - setWatch(function() { //BTN3 - offsetMoon--; //jump to next day - drawMoon(offsetMoon, x, y); //offset, x, y - }, BTN3, {edge:"rising", debounce:50, repeat:true}); + setWatch(function() { //BTN4 + g.drawString("--- Getting GPS signal ---",x, y); + Bangle.setGPSPower(1); + timer = setInterval(getGpsFix, 10000); + }, BTN4, {edge:"rising", debounce:50, repeat:true}); - setWatch(function() { //BTN4 - g.drawString("--- Getting GPS signal ---",x, y); - Bangle.setGPSPower(1); - timer = setInterval(getGpsFix, 10000); - }, BTN4, {edge:"rising", debounce:50, repeat:true}); - - setWatch(function() { //BTN5 - if (timer) clearInterval(timer); - timer = undefined; - Bangle.setGPSPower(0); - drawMoon(offsetMoon, x, y); //offset, x, y - }, BTN5, {edge:"rising", debounce:50, repeat:true}); + setWatch(function() { //BTN5 + if (timer) clearInterval(timer); + timer = undefined; + Bangle.setGPSPower(0); + drawMoon(offsetMoon, x, y); //offset, x, y + }, BTN5, {edge:"rising", debounce:50, repeat:true}); } start(); \ No newline at end of file diff --git a/apps/morse/morse-code.js b/apps/morse/morse-code.js index 72e58d6eb..227aeed81 100644 --- a/apps/morse/morse-code.js +++ b/apps/morse/morse-code.js @@ -95,20 +95,20 @@ const beepItOut = () => { // Could make buzz optional or switchable potentially BUZZING ? Bangle.buzz(UNITS[UNIT_INDEX] === '.' ? UNIT : 3 * UNIT) : null ]) - .then(() => { - if (UNITS[UNIT_INDEX + 1]) { - setTimeout(() => { - UNIT_INDEX++; - beepItOut(); - }, UNIT); - } else { - setTimeout(() => { - BEEPING = false; - UNIT_INDEX = 0; - writeLetter(); - }, 3 * UNIT); - } - }); + .then(() => { + if (UNITS[UNIT_INDEX + 1]) { + setTimeout(() => { + UNIT_INDEX++; + beepItOut(); + }, UNIT); + } else { + setTimeout(() => { + BEEPING = false; + UNIT_INDEX = 0; + writeLetter(); + }, 3 * UNIT); + } + }); }, wait); }; const startBeep = () => { diff --git a/apps/nato/nato.js b/apps/nato/nato.js index f4301b83f..e9bbd9bba 100644 --- a/apps/nato/nato.js +++ b/apps/nato/nato.js @@ -53,7 +53,7 @@ const writeText = (txt) => { var width = g.stringWidth(txt); - // Fit text to screen + // Fit text to screen var fontFix = FONT_SIZE; while(width > SCREEN_PIXELS-10){ fontFix--; diff --git a/apps/ncfrun/nceu-funrun.js b/apps/ncfrun/nceu-funrun.js index cd2fab866..30e587188 100644 --- a/apps/ncfrun/nceu-funrun.js +++ b/apps/ncfrun/nceu-funrun.js @@ -118,7 +118,7 @@ function arrow(r,c) { 180+20*Math.sin(r+p), 180-20*Math.cos(r+p), 180-10*Math.sin(r), 180+10*Math.cos(r), 180+20*Math.sin(r+-p), 180-20*Math.cos(r-p), - ]); + ]); } function onCompass(m) { diff --git a/apps/numerals/numerals.app.js b/apps/numerals/numerals.app.js index f95c7d379..a74da4460 100644 --- a/apps/numerals/numerals.app.js +++ b/apps/numerals/numerals.app.js @@ -83,7 +83,7 @@ draw(settings.drawMode); Bangle.on('lcdPower', function(on){ if (on){ if (settings.color==0) _rCol = Math.floor(Math.random()*_hCol.length); - draw(settings.drawMode); + draw(settings.drawMode); interval=setInterval(draw, REFRESH_RATE, settings.drawMode); }else { diff --git a/apps/numerals/numerals.settings.js b/apps/numerals/numerals.settings.js index 37af6b6f2..fbd721146 100644 --- a/apps/numerals/numerals.settings.js +++ b/apps/numerals/numerals.settings.js @@ -17,25 +17,25 @@ let col = ["rnd","r/g","y/w","o/c","b/y"]; let btn = [[24,"BTN1"],[22,"BTN2"],[23,"BTN3"],[11,"BTN4"],[16,"BTN5"]]; var menu={ - "" : { "title":"Numerals"}, - "Colors": { - value: 0|numeralsSettings.color, - min:0,max:4, - format: v=>col[v], - onchange: v=> { numeralsSettings.color=v; updateSettings();} + "" : { "title":"Numerals"}, + "Colors": { + value: 0|numeralsSettings.color, + min:0,max:4, + format: v=>col[v], + onchange: v=> { numeralsSettings.color=v; updateSettings();} }, - "Draw mode": { - value: 0|dm.indexOf(numeralsSettings.drawMode), - min:0,max:1, - format: v=>dm[v], - onchange: v=> { numeralsSettings.drawMode=dm[v]; updateSettings();} + "Draw mode": { + value: 0|dm.indexOf(numeralsSettings.drawMode), + min:0,max:1, + format: v=>dm[v], + onchange: v=> { numeralsSettings.drawMode=dm[v]; updateSettings();} }, "Menu button": { value: btn.findIndex(e=>e[0]==numeralsSettings.menuButton), min:0,max:4, format: v=>btn[v][1], onchange: v=> { numeralsSettings.menuButton=btn[v][0]; updateSettings();} - }, + }, "< back": back }; E.showMenu(menu); diff --git a/apps/pipboy/app.js b/apps/pipboy/app.js index a8539c7db..5f885d769 100644 --- a/apps/pipboy/app.js +++ b/apps/pipboy/app.js @@ -77,29 +77,29 @@ function boy() { } function drawClock() { - var t = new Date(); - var h = t.getHours(); - var m = t.getMinutes(); - var dd = t.getDate(); - var mm = t.getMonth()+1; //month is zero-based - var yy = t.getFullYear(); - var time = ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2); + var t = new Date(); + var h = t.getHours(); + var m = t.getMinutes(); + var dd = t.getDate(); + var mm = t.getMonth()+1; //month is zero-based + var yy = t.getFullYear(); + var time = ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2); - //create date string - if (dd.toString().length < 2) dd = '0' + dd; - if (mm.toString().length < 2) mm = '0' + mm; - var date = dd + "." + mm + "." + yy; + //create date string + if (dd.toString().length < 2) dd = '0' + dd; + if (mm.toString().length < 2) mm = '0' + mm; + var date = dd + "." + mm + "." + yy; - g.setFont("6x8",bigFont); - g.setColor(green); - g.setFontAlign(0, -1, 0); + g.setFont("6x8",bigFont); + g.setColor(green); + g.setFontAlign(0, -1, 0); - g.clearRect(0, 110, 150, 140); - g.drawString(time, 70, 110); + g.clearRect(0, 110, 150, 140); + g.drawString(time, 70, 110); - //draw date - g.setFont("6x8", tinyFont); - g.drawString(date, 67, 177); + //draw date + g.setFont("6x8", tinyFont); + g.drawString(date, 67, 177); } function drawAll() { diff --git a/apps/pomodo/pomodoro.js b/apps/pomodo/pomodoro.js index 013828d12..3e11739da 100644 --- a/apps/pomodo/pomodoro.js +++ b/apps/pomodo/pomodoro.js @@ -3,254 +3,254 @@ const storage = require("Storage"); const DEFAULT_TIME = 1500; // 25m const TIME_BREAK = 300; const STATES = { - INIT: 1, - STARTED: 2, - DONE: 3, - BREAK: 4 + INIT: 1, + STARTED: 2, + DONE: 3, + BREAK: 4 }; var counterInterval; class State { - constructor (state) { - this.state = state; - this.next = null; + constructor (state) { + this.state = state; + this.next = null; + } + + setNext (next) { + this.next = next; + } + + setButtons () {} + + clear () { + clearWatch(); + g.clear(); + g.setFontAlign(0, 0); + } + + draw () { + g.clear(); + } + + init () { } + + go (nextState) { + if (nextState) { + this.next = nextState; } - setNext (next) { - this.next = next; - } - - setButtons () {} - - clear () { - clearWatch(); - g.clear(); - g.setFontAlign(0, 0); - } - - draw () { - g.clear(); - } - - init () { } - - go (nextState) { - if (nextState) { - this.next = nextState; - } - - this.clear(); - this.init(); - this.setButtons(); - this.draw(); - } + this.clear(); + this.init(); + this.setButtons(); + this.draw(); + } } class InitState extends State { - constructor (time) { - super(STATES.INIT); + constructor (time) { + super(STATES.INIT); - this.timeCounter = parseInt(storage.read(".pomodo") || DEFAULT_TIME, 10); - } + this.timeCounter = parseInt(storage.read(".pomodo") || DEFAULT_TIME, 10); + } - saveTime () { - storage.write('.pomodo', '' + this.timeCounter); - } + saveTime () { + storage.write('.pomodo', '' + this.timeCounter); + } - setButtons () { - setWatch(() => { - if (this.timeCounter + 300 > 3599) { - this.timeCounter = 3599; - } else { - this.timeCounter += 300; - } + setButtons () { + setWatch(() => { + if (this.timeCounter + 300 > 3599) { + this.timeCounter = 3599; + } else { + this.timeCounter += 300; + } - this.draw(); + this.draw(); - }, BTN1, { repeat: true }); + }, BTN1, { repeat: true }); - setWatch(() => { - if (this.timeCounter - 300 > 0) { - this.timeCounter -= 300; - this.draw(); - } - }, BTN3, { repeat: true }); + setWatch(() => { + if (this.timeCounter - 300 > 0) { + this.timeCounter -= 300; + this.draw(); + } + }, BTN3, { repeat: true }); - setWatch(() => { - if (this.timeCounter - 60 > 0) { - this.timeCounter -= 60; - this.draw(); - } - }, BTN4, { repeat: true }); + setWatch(() => { + if (this.timeCounter - 60 > 0) { + this.timeCounter -= 60; + this.draw(); + } + }, BTN4, { repeat: true }); - setWatch(() => { - if (this.timeCounter + 60 > 3599) { - this.timeCounter = 3599; - } else { - this.timeCounter += 60; - } + setWatch(() => { + if (this.timeCounter + 60 > 3599) { + this.timeCounter = 3599; + } else { + this.timeCounter += 60; + } - this.draw(); + this.draw(); - }, BTN5, { repeat: true }); + }, BTN5, { repeat: true }); - setWatch(() => { - this.saveTime(); - const startedState = new StartedState(this.timeCounter); + setWatch(() => { + this.saveTime(); + const startedState = new StartedState(this.timeCounter); - this.setNext(startedState); - this.next.go(); - }, BTN2, { repeat: true }); - } + this.setNext(startedState); + this.next.go(); + }, BTN2, { repeat: true }); + } - draw () { - g.clear(); - g.setFontAlign(0, 0); // center font - g.setFont("Vector", 50); // vector font, 80px - drawCounter(this.timeCounter); - } + draw () { + g.clear(); + g.setFontAlign(0, 0); // center font + g.setFont("Vector", 50); // vector font, 80px + drawCounter(this.timeCounter); + } } class StartedState extends State { - constructor (timeCounter) { - super(STATES.STARTED); + constructor (timeCounter) { + super(STATES.STARTED); - this.timeCounter = timeCounter; + this.timeCounter = timeCounter; + } + + draw () { + drawCounter(this.timeCounter, 120, 120); + } + + init () { + function countDown () { + this.timeCounter--; + + // Out of time + if (this.timeCounter <= 0) { + clearInterval(counterInterval); + counterInterval = undefined; + this.next.go(); + return; + } + + this.draw(); } - draw () { - drawCounter(this.timeCounter, 120, 120); - } - - init () { - function countDown () { - this.timeCounter--; - - // Out of time - if (this.timeCounter <= 0) { - clearInterval(counterInterval); - counterInterval = undefined; - this.next.go(); - return; - } - - this.draw(); - } - - const doneState = new DoneState(); - this.setNext(doneState); - counterInterval = setInterval(countDown.bind(this), 1000); - } + const doneState = new DoneState(); + this.setNext(doneState); + counterInterval = setInterval(countDown.bind(this), 1000); + } } class BreakState extends State { - constructor () { - super(STATES.BREAK); - } + constructor () { + super(STATES.BREAK); + } - draw () { - g.setFontAlign(0, 0); - } + draw () { + g.setFontAlign(0, 0); + } - init () { - const startedState = new StartedState(TIME_BREAK); + init () { + const startedState = new StartedState(TIME_BREAK); - this.setNext(startedState); - this.next.go(); - } + this.setNext(startedState); + this.next.go(); + } } class DoneState extends State { - constructor () { - super(STATES.DONE); + constructor () { + super(STATES.DONE); + } + + setButtons () { + setWatch(() => { + const initState = new InitState(); + clearTimeout(this.timeout); + initState.go(); + }, BTN1, { repeat: true }); + + setWatch(() => { + const breakState = new BreakState(); + clearTimeout(this.timeout); + breakState.go(); + }, BTN3, { repeat: true }); + + setWatch(() => { + }, BTN2, { repeat: true }); + } + + draw () { + g.clear(); + g.setFont("6x8", 2); + g.setFontAlign(0, 0, 3); + g.drawString("AGAIN", 230, 50); + g.drawString("BREAK", 230, 190); + g.setFont("Vector", 45); + g.setFontAlign(-1, -1); + + g.drawString('You\nare\na\nhero!', 50, 40); + } + + init () { + + function buzz () { + Bangle.buzz(); + Bangle.beep(200, 4000) + .then(() => new Promise(resolve => setTimeout(resolve, 50))) + .then(() => Bangle.beep(200, 3000)) + .then(() => new Promise(resolve => setTimeout(resolve, 200))) + .then(() => Bangle.beep(200, 3000)) + .then(() => new Promise(resolve => setTimeout(resolve, 300))) + .then(() => { + Bangle.beep(200, 3000); + Bangle.buzz() + }); } - setButtons () { - setWatch(() => { - const initState = new InitState(); - clearTimeout(this.timeout); - initState.go(); - }, BTN1, { repeat: true }); - - setWatch(() => { - const breakState = new BreakState(); - clearTimeout(this.timeout); - breakState.go(); - }, BTN3, { repeat: true }); - - setWatch(() => { - }, BTN2, { repeat: true }); - } - - draw () { - g.clear(); - g.setFont("6x8", 2); - g.setFontAlign(0, 0, 3); - g.drawString("AGAIN", 230, 50); - g.drawString("BREAK", 230, 190); - g.setFont("Vector", 45); - g.setFontAlign(-1, -1); - - g.drawString('You\nare\na\nhero!', 50, 40); - } - - init () { - - function buzz () { - Bangle.buzz(); - Bangle.beep(200, 4000) - .then(() => new Promise(resolve => setTimeout(resolve, 50))) - .then(() => Bangle.beep(200, 3000)) - .then(() => new Promise(resolve => setTimeout(resolve, 200))) - .then(() => Bangle.beep(200, 3000)) - .then(() => new Promise(resolve => setTimeout(resolve, 300))) - .then(() => { - Bangle.beep(200, 3000); - Bangle.buzz() - }); - } - - buzz(); - // again, 10 secs later - this.timeout = setTimeout(buzz.bind(this), 10000); - } + buzz(); + // again, 10 secs later + this.timeout = setTimeout(buzz.bind(this), 10000); + } } function drawCounter (currentValue, x, y) { - if (currentValue < 0) { - return; - } + if (currentValue < 0) { + return; + } - x = x || 120; - y = y || 120; + x = x || 120; + y = y || 120; - let minutes = 0; - let seconds = 0; + let minutes = 0; + let seconds = 0; - if (currentValue >= 60) { - minutes = Math.floor(currentValue / 60); - seconds = currentValue % 60; - } else { - seconds = currentValue; - } + if (currentValue >= 60) { + minutes = Math.floor(currentValue / 60); + seconds = currentValue % 60; + } else { + seconds = currentValue; + } - let minutesString = '' + minutes; - let secondsString = '' + seconds; + let minutesString = '' + minutes; + let secondsString = '' + seconds; - if (minutes < 10) { - minutesString = '0' + minutes; - } + if (minutes < 10) { + minutesString = '0' + minutes; + } - if (seconds < 10) { - secondsString = '0' + seconds; - } + if (seconds < 10) { + secondsString = '0' + seconds; + } - g.clear(); - g.drawString(minutesString + ':' + secondsString, x, y); + g.clear(); + g.drawString(minutesString + ':' + secondsString, x, y); } function init () { - const initState = new InitState(); - initState.go(); + const initState = new InitState(); + initState.go(); } init(); diff --git a/apps/rclock/rclock.app.js b/apps/rclock/rclock.app.js index a22f6e2b7..f9b8a9e6f 100644 --- a/apps/rclock/rclock.app.js +++ b/apps/rclock/rclock.app.js @@ -167,7 +167,7 @@ g.drawString(date, settings.date.center, settings.date.middle); }; - //setInterval for HR visualisation + //setInterval for HR visualisation const newBeats = function (hr) { if (id != 0) { changeInterval(id, 6e3 / hr.bpm); @@ -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); diff --git a/apps/scolor/show-color.js b/apps/scolor/show-color.js index 9a28b26dc..e248ee80d 100644 --- a/apps/scolor/show-color.js +++ b/apps/scolor/show-color.js @@ -1,60 +1,60 @@ /* jshint esversion: 6 */ (function() { - const colors = { - 0: { value: 0x0000, name: "Black" }, - 1: { value: 0x000F, name: "Navy" }, - 2: { value: 0x03E0, name: "DarkGreen" }, - 3: { value: 0x03EF, name: "DarkCyan" }, - 4: { value: 0x7800, name: "Maroon" }, - 5: { value: 0x780F, name: "Purple" }, - 6: { value: 0x7BE0, name: "Olive" }, - 7: { value: 0xC618, name: "LightGray" }, - 8: { value: 0x7BEF, name: "DarkGrey" }, - 9: { value: 0x001F, name: "Blue" }, - 10: { value: 0x07E0, name: "Green" }, - 11: { value: 0x07FF, name: "Cyan" }, - 12: { value: 0xF800, name: "Red" }, - 13: { value: 0xF81F, name: "Magenta" }, - 14: { value: 0xFFE0, name: "Yellow" }, - 15: { value: 0xFFFF, name: "White" }, - 16: { value: 0xFD20, name: "Orange" }, - 17: { value: 0xAFE5, name: "GreenYellow" }, - 18: { value: 0xF81F, name: "Pink" }, - }; + const colors = { + 0: { value: 0x0000, name: "Black" }, + 1: { value: 0x000F, name: "Navy" }, + 2: { value: 0x03E0, name: "DarkGreen" }, + 3: { value: 0x03EF, name: "DarkCyan" }, + 4: { value: 0x7800, name: "Maroon" }, + 5: { value: 0x780F, name: "Purple" }, + 6: { value: 0x7BE0, name: "Olive" }, + 7: { value: 0xC618, name: "LightGray" }, + 8: { value: 0x7BEF, name: "DarkGrey" }, + 9: { value: 0x001F, name: "Blue" }, + 10: { value: 0x07E0, name: "Green" }, + 11: { value: 0x07FF, name: "Cyan" }, + 12: { value: 0xF800, name: "Red" }, + 13: { value: 0xF81F, name: "Magenta" }, + 14: { value: 0xFFE0, name: "Yellow" }, + 15: { value: 0xFFFF, name: "White" }, + 16: { value: 0xFD20, name: "Orange" }, + 17: { value: 0xAFE5, name: "GreenYellow" }, + 18: { value: 0xF81F, name: "Pink" }, + }; - const maxColors = 19; - var index = 0; + const maxColors = 19; + var index = 0; - function drawColor() { + function drawColor() { - // draw filled rectangle - g.setColor(colors[index % maxColors].value); - g.fillRect(0, 24, g.getWidth(), g.getHeight()); + // draw filled rectangle + g.setColor(colors[index % maxColors].value); + g.fillRect(0, 24, g.getWidth(), g.getHeight()); - // draw value name of color - g.setFontAlign(0, 0); - g.setColor(0xFFFF); - if (colors[index % maxColors].name == "White") - g.setColor(0); - g.setFont("6x8", 4); - g.drawString('0x' + colors[index % maxColors].value.toString(16), 120, 80); - g.setFont("6x8", 3); - g.drawString(colors[index % maxColors].name, 120, 160); + // draw value name of color + g.setFontAlign(0, 0); + g.setColor(0xFFFF); + if (colors[index % maxColors].name == "White") + g.setColor(0); + g.setFont("6x8", 4); + g.drawString('0x' + colors[index % maxColors].value.toString(16), 120, 80); + g.setFont("6x8", 3); + g.drawString(colors[index % maxColors].name, 120, 160); - // draw next button info - g.setFont("6x8", 2); - g.setFontAlign(0, 0, 3); - g.drawString("Next", 230, 60); + // draw next button info + g.setFont("6x8", 2); + g.setFontAlign(0, 0, 3); + g.drawString("Next", 230, 60); - // set watches for button 1 - index++; - setWatch(drawColor, BTN1, { repeate: true }); + // set watches for button 1 + index++; + setWatch(drawColor, BTN1, { repeate: true }); - } + } - g.clear(); - setWatch(drawColor, BTN1, { repeate: false }); - E.showMessage("Press BTN1\nto start"); + g.clear(); + setWatch(drawColor, BTN1, { repeate: false }); + E.showMessage("Press BTN1\nto start"); })(); diff --git a/apps/stetho/stetho.js b/apps/stetho/stetho.js index ec0916f4e..6fee91c12 100644 --- a/apps/stetho/stetho.js +++ b/apps/stetho/stetho.js @@ -11,8 +11,8 @@ var hrm; var SPEAKER_PIN = D18; function freq(f) { - console.log("frequency: ", f); - if (f===0) digitalWrite(SPEAKER_PIN, 0); + console.log("frequency: ", f); + if (f===0) digitalWrite(SPEAKER_PIN, 0); else analogWrite(SPEAKER_PIN, 0.5, {freq: f}); } diff --git a/apps/swatch/stopwatch.js b/apps/swatch/stopwatch.js index 478de2712..91082e22a 100644 --- a/apps/swatch/stopwatch.js +++ b/apps/swatch/stopwatch.js @@ -83,8 +83,8 @@ setWatch(function() { // Start/stop Bangle.beep(); if (started) tStart = Date.now()+tStart-tCurrent; - tTotal = Date.now()+tTotal-tCurrent; - tCurrent = Date.now(); + tTotal = Date.now()+tTotal-tCurrent; + tCurrent = Date.now(); if (displayInterval) { clearInterval(displayInterval); displayInterval = undefined; diff --git a/apps/torch/widget.js b/apps/torch/widget.js index a5002ea71..08c94fad8 100644 --- a/apps/torch/widget.js +++ b/apps/torch/widget.js @@ -1,26 +1,26 @@ (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) { - clickPattern = clickPattern.substr(-3)+c; - while (clickTimes.length>=TAPS) clickTimes.shift(); - clickTimes.push(e.time); - var clickPeriod = e.time-clickTimes[0]; - if (clickPeriod=TAPS) clickTimes.shift(); + clickTimes.push(e.time); + var clickPeriod = e.time-clickTimes[0]; + if (clickPeriod app.endsWith('.info')).map(app => Storage.readJSON(app,1) || { name: "DEAD: "+app.substr(1) }) - .filter(app=>app.type=="app" || app.type=="clock" || !app.type) - .sort((a,b)=>{ - var n=(0|a.sortorder)-(0|b.sortorder); - if (n) return n; // do sortorder first - if (a.nameb.name) return 1; - return 0; + const exit_app = { + name: 'Exit', + special: true + }; + const raw_apps = Storage.list(/\.info$/).filter(app => app.endsWith('.info')).map(app => Storage.readJSON(app,1) || { name: "DEAD: "+app.substr(1) }) + .filter(app=>app.type=="app" || app.type=="clock" || !app.type) + .sort((a,b)=>{ + var n=(0|a.sortorder)-(0|b.sortorder); + if (n) return n; // do sortorder first + if (a.nameb.name) return 1; + return 0; }).map(raw => ({ name: raw.name, src: raw.src, @@ -51,12 +51,12 @@ function getApps(){ version: raw.version })); - const apps = [Object.assign({}, exit_app)].concat(raw_apps); - apps.push(exit_app); - return apps.map((app, i) => { - app.x = getPosition(i); - return app; - }); + const apps = [Object.assign({}, exit_app)].concat(raw_apps); + apps.push(exit_app); + return apps.map((app, i) => { + app.x = getPosition(i); + return app; + }); } const APPS = getApps(); @@ -105,8 +105,8 @@ function render(){ //draw icon const icon = app.icon ? - icons[app.name] ? icons[app.name] : Storage.read(app.icon) - : null; + icons[app.name] ? icons[app.name] : Storage.read(app.icon) + : null; if(icon){ icons[app.name] = icon; @@ -132,13 +132,13 @@ function render(){ } if(settings.highres){ - const type = app.type ? app.type : 'App'; - const version = app.version ? app.version : '0.00'; - const info = type+' v'+version; - g.setFontAlign(0,1); - g.setFont('6x8', 1.5); - g.setColor(scale,scale,scale); - g.drawString(info, HALF, 215, { scale: scale }); + const type = app.type ? app.type : 'App'; + const version = app.version ? app.version : '0.00'; + const info = type+' v'+version; + g.setFontAlign(0,1); + g.setFont('6x8', 1.5); + g.setColor(scale,scale,scale); + g.drawString(info, HALF, 215, { scale: scale }); } }); diff --git a/apps/wclock/clock-word.js b/apps/wclock/clock-word.js index 00b262ef7..b8c36f548 100644 --- a/apps/wclock/clock-word.js +++ b/apps/wclock/clock-word.js @@ -1,39 +1,39 @@ /* jshint esversion: 6 */ const allWords = [ - "ATWENTYD", - "QUARTERY", - "FIVEHALF", - "DPASTORO", - "FIVEIGHT", - "SIXTHREE", - "TWELEVEN", - "FOURNINE" + "ATWENTYD", + "QUARTERY", + "FIVEHALF", + "DPASTORO", + "FIVEIGHT", + "SIXTHREE", + "TWELEVEN", + "FOURNINE" ]; const hours = { - 0: ["", 0, 0], - 1: ["ONE", 17, 47, 77], - 2: ["TWO", 06, 16, 17], - 3: ["THREE", 35, 45, 55, 65, 75], - 4: ["FOUR", 07, 17, 27, 37], - 5: ["FIVE", 04, 14, 24, 34], - 6: ["SIX", 05, 15, 25], - 7: ["SEVEN", 05, 46, 56, 66, 67], - 8: ["EIGHT", 34, 44, 54, 64, 74], - 9: ["NINE", 47, 57, 67, 77], - 10: ["TEN", 74, 75, 76], - 11: ["ELEVEN", 26, 36, 46, 56, 66, 76], - 12: ["TWELVE", 06, 16, 26, 36, 56, 66] + 0: ["", 0, 0], + 1: ["ONE", 17, 47, 77], + 2: ["TWO", 06, 16, 17], + 3: ["THREE", 35, 45, 55, 65, 75], + 4: ["FOUR", 07, 17, 27, 37], + 5: ["FIVE", 04, 14, 24, 34], + 6: ["SIX", 05, 15, 25], + 7: ["SEVEN", 05, 46, 56, 66, 67], + 8: ["EIGHT", 34, 44, 54, 64, 74], + 9: ["NINE", 47, 57, 67, 77], + 10: ["TEN", 74, 75, 76], + 11: ["ELEVEN", 26, 36, 46, 56, 66, 76], + 12: ["TWELVE", 06, 16, 26, 36, 56, 66] }; const mins = { - 0: ["A", 0, 0], - 1: ["FIVE", 02, 12, 22, 32], - 2: ["TEN", 10, 30, 40], - 3: ["QUARTER", 01, 11, 21, 31, 41, 51, 61], - 4: ["TWENTY", 10, 20, 30, 40, 50, 60], - 5: ["HALF", 42, 52, 62, 72], - 6: ["PAST", 13, 23, 33, 43], - 7: ["TO", 43, 53] + 0: ["A", 0, 0], + 1: ["FIVE", 02, 12, 22, 32], + 2: ["TEN", 10, 30, 40], + 3: ["QUARTER", 01, 11, 21, 31, 41, 51, 61], + 4: ["TWENTY", 10, 20, 30, 40, 50, 60], + 5: ["HALF", 42, 52, 62, 72], + 6: ["PAST", 13, 23, 33, 43], + 7: ["TO", 43, 53] }; // offsets and incerments @@ -49,71 +49,71 @@ const activeColor = 0xF800 /*red*/ ; function drawWordClock() { - // get time - var t = new Date(); - var h = t.getHours(); - var m = t.getMinutes(); - var time = ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2); + // get time + var t = new Date(); + var h = t.getHours(); + var m = t.getMinutes(); + var time = ("0" + h).substr(-2) + ":" + ("0" + m).substr(-2); - var hidx; - var midx; - var midxA = []; + var hidx; + var midx; + var midxA = []; - g.setFont("6x8",fontSize); - g.setColor(passivColor); - g.setFontAlign(0, -1, 0); + g.setFont("6x8",fontSize); + g.setColor(passivColor); + g.setFontAlign(0, -1, 0); - // draw allWords - var c; - var y = ys; - var x = xs; - allWords.forEach((line) => { - x = xs; - for (c in line) { - g.drawString(line[c], x, y); - x += dx; - } - y += dy; - }); - - // calc indexes - midx = Math.round(m / 5); - hidx = h % 12; - if (hidx === 0) { hidx = 12; } - if (midx > 6) { - if (midx == 12) { midx = 0; } - hidx++; + // draw allWords + var c; + var y = ys; + var x = xs; + allWords.forEach((line) => { + x = xs; + for (c in line) { + g.drawString(line[c], x, y); + x += dx; } - if (midx !== 0) { - if (midx <= 6) { - midxA = [midx, 6]; - } else { - midxA = [12 - midx, 7]; - } + y += dy; + }); + + // calc indexes + midx = Math.round(m / 5); + hidx = h % 12; + if (hidx === 0) { hidx = 12; } + if (midx > 6) { + if (midx == 12) { midx = 0; } + hidx++; + } + if (midx !== 0) { + if (midx <= 6) { + midxA = [midx, 6]; + } else { + midxA = [12 - midx, 7]; } + } - // write hour in active color - g.setColor(activeColor); - hours[hidx][0].split('').forEach((c, pos) => { - x = xs + (hours[hidx][pos + 1] / 10 | 0) * dx; - y = ys + (hours[hidx][pos + 1] % 10) * dy; + // write hour in active color + g.setColor(activeColor); + hours[hidx][0].split('').forEach((c, pos) => { + x = xs + (hours[hidx][pos + 1] / 10 | 0) * dx; + y = ys + (hours[hidx][pos + 1] % 10) * dy; - g.drawString(c, x, y); + g.drawString(c, x, y); + }); + + // write min words in active color + midxA.forEach(idx => { + mins[idx][0].split('').forEach((c, pos) => { + x = xs + (mins[idx][pos + 1] / 10 | 0) * dx; + y = ys + (mins[idx][pos + 1] % 10) * dy; + g.drawString(c, x, y); }); + }); - // write min words in active color - midxA.forEach(idx => { - mins[idx][0].split('').forEach((c, pos) => { - x = xs + (mins[idx][pos + 1] / 10 | 0) * dx; - y = ys + (mins[idx][pos + 1] % 10) * dy; - g.drawString(c, x, y); - }); - }); - - // display digital time - g.setColor(activeColor); - g.clearRect(0, 215, 240, 240); - g.drawString(time, 120, 215); + // display digital time + g.setColor(activeColor); + g.clearRect(0, 215, 240, 240); + g.drawString(time, 120, 215); } Bangle.on('lcdPower', function(on) { diff --git a/apps/welcome/app.js b/apps/welcome/app.js index b4c79ddaa..8cbdc2efa 100644 --- a/apps/welcome/app.js +++ b/apps/welcome/app.js @@ -87,7 +87,7 @@ var scenes = [ ()=>{g.setFont("Vector",36);g.drawString("1",200,40);}, ()=>g.drawString("2",200,120), ()=>g.drawString("3",200,200) - ],200); + ],200); }, function() { g.reset(); @@ -138,15 +138,15 @@ var scenes = [ var x = 120, y = 10, h=21; animate([ ()=>{g.drawString("Bangle.js has a",x,y+=h); - g.drawString("simple touchscreen",x,y+=h);}, + g.drawString("simple touchscreen",x,y+=h);}, 0,0, ()=>{g.drawString("It'll detect touch",x,y+=h*2); - g.drawString("on left and right",x,y+=h);}, + g.drawString("on left and right",x,y+=h);}, 0,0, ()=>{g.drawString("Horizontal swipes",x,y+=h*2); - g.drawString("work too. Try now",x,y+=h); - g.drawString("to change page.",x,y+=h);} - ],300); + g.drawString("work too. Try now",x,y+=h); + g.drawString("to change page.",x,y+=h);} + ],300); }, function() { g.reset(); @@ -156,15 +156,15 @@ var scenes = [ var x = 120, y = 10, h=21; animate([ ()=>{g.drawString("Bangle.js",x,y+=h); - g.drawString("comes with",x,y+=h); - g.drawString("a few simple",x,y+=h); - g.drawString("apps installed",x,y+=h);}, + g.drawString("comes with",x,y+=h); + g.drawString("a few simple",x,y+=h); + g.drawString("apps installed",x,y+=h);}, 0,0, ()=>{g.drawString("To add more, visit",x,y+=h*2); - g.drawString("banglejs.com/apps",x,y+=h); - g.drawString("with a Bluetooth",x,y+=h); - g.drawString("capable device",x,y+=h);}, - ],400); + g.drawString("banglejs.com/apps",x,y+=h); + g.drawString("with a Bluetooth",x,y+=h); + g.drawString("capable device",x,y+=h);}, + ],400); }, function() { g.reset(); @@ -186,9 +186,9 @@ var scenes = [ rx += 0.1; ry += 0.11; var rcx=Math.cos(rx), - rsx=Math.sin(rx), - rcy=Math.cos(ry), - rsy=Math.sin(ry); + rsx=Math.sin(rx), + rcy=Math.cos(ry), + rsy=Math.sin(ry); // Project 3D coordinates into 2D function p(x,y,z) { var t; @@ -240,10 +240,10 @@ var scenes = [ animate([ ()=>g.drawString("That's it!",x,y+=h), ()=>{g.drawString("Press",x,y+=h*3); - g.drawString("Button 2",x,y+=h); - g.drawString("to start",x,y+=h); - g.drawString("Bangle.js",x,y+=h);} - ],400); + g.drawString("Button 2",x,y+=h); + g.drawString("to start",x,y+=h); + g.drawString("Bangle.js",x,y+=h);} + ],400); } ]; diff --git a/apps/widbat/widget.js b/apps/widbat/widget.js index dd6774d4c..bca3ae046 100644 --- a/apps/widbat/widget.js +++ b/apps/widbat/widget.js @@ -1,43 +1,43 @@ (function(){ -var CHARGING = 0x07E0; + var CHARGING = 0x07E0; -function setWidth() { - WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0); -} -function draw() { - var s = 39; - var x = this.x, y = this.y; - if (Bangle.isCharging()) { - g.setColor(CHARGING).drawImage(atob("DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); - x+=16; + function setWidth() { + WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0); } - g.setColor(-1); - g.fillRect(x,y+2,x+s-4,y+21); - g.clearRect(x+2,y+4,x+s-6,y+19); - 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) { - if(charging) Bangle.buzz(); + function draw() { + var s = 39; + var x = this.x, y = this.y; + if (Bangle.isCharging()) { + g.setColor(CHARGING).drawImage(atob("DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); + x+=16; + } + g.setColor(-1); + g.fillRect(x,y+2,x+s-4,y+21); + g.clearRect(x+2,y+4,x+s-6,y+19); + 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) { + if(charging) Bangle.buzz(); + setWidth(); + Bangle.drawWidgets(); // relayout widgets + g.flip(); + }); + var batteryInterval; + Bangle.on('lcdPower', function(on) { + if (on) { + WIDGETS["bat"].draw(); + // refresh once a minute if LCD on + if (!batteryInterval) + batteryInterval = setInterval(()=>WIDGETS["bat"].draw(), 60000); + } else { + if (batteryInterval) { + clearInterval(batteryInterval); + batteryInterval = undefined; + } + } + }); + WIDGETS["bat"]={area:"tr",width:40,draw:draw}; setWidth(); - Bangle.drawWidgets(); // relayout widgets - g.flip(); -}); -var batteryInterval; -Bangle.on('lcdPower', function(on) { - if (on) { - WIDGETS["bat"].draw(); - // refresh once a minute if LCD on - if (!batteryInterval) - batteryInterval = setInterval(()=>WIDGETS["bat"].draw(), 60000); - } else { - if (batteryInterval) { - clearInterval(batteryInterval); - batteryInterval = undefined; - } - } -}); -WIDGETS["bat"]={area:"tr",width:40,draw:draw}; -setWidth(); })() diff --git a/apps/widbatpc/settings.js b/apps/widbatpc/settings.js index f38bb3a08..009fa4994 100644 --- a/apps/widbatpc/settings.js +++ b/apps/widbatpc/settings.js @@ -52,8 +52,8 @@ const newIndex = (oldIndex + 1) % COLORS.length s.color = COLORS[newIndex] save('color')(s.color) - } - }, + } + }, 'Hide if >': { value: s.hideifmorethan||100, min: 10, @@ -61,7 +61,7 @@ step: 10, format: x => x+"%", onchange: save('hideifmorethan'), - }, - } + }, + } E.showMenu(menu) }) diff --git a/apps/widbatpc/widget.js b/apps/widbatpc/widget.js index 3fa4cb79a..9bf43cfaa 100644 --- a/apps/widbatpc/widget.js +++ b/apps/widbatpc/widget.js @@ -1,140 +1,140 @@ (function(){ -const COLORS = { - 'white': -1, - 'charging': 0x07E0, // "Green" - 'high': 0x05E0, // slightly darker green - 'ok': 0xFD20, // "Orange" - 'low':0xF800, // "Red" -} -const SETTINGS_FILE = 'widbatpc.json' + const COLORS = { + 'white': -1, + 'charging': 0x07E0, // "Green" + 'high': 0x05E0, // slightly darker green + 'ok': 0xFD20, // "Orange" + 'low':0xF800, // "Red" + } + const SETTINGS_FILE = 'widbatpc.json' -let settings -function loadSettings() { - settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {} - const DEFAULTS = { - 'color': 'By Level', - 'percentage': true, - 'charger': true, - 'hideifmorethan': 100, - }; - Object.keys(DEFAULTS).forEach(k=>{ - if (settings[k]===undefined) settings[k]=DEFAULTS[k] - }); -} -function setting(key) { - if (!settings) { loadSettings() } - return settings[key]; -} + let settings + function loadSettings() { + settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {} + const DEFAULTS = { + 'color': 'By Level', + 'percentage': true, + 'charger': true, + 'hideifmorethan': 100, + }; + Object.keys(DEFAULTS).forEach(k=>{ + if (settings[k]===undefined) settings[k]=DEFAULTS[k] + }); + } + 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')) { - case 'Monochrome': return COLORS.white; // no chance of reading the percentage here :-( - case 'Green': return green; - case 'By Level': // fall through - default: - if (setting('charger')) { + const green = setting('percentage') ? COLORS.high : COLORS.charging + switch (setting('color')) { + case 'Monochrome': return COLORS.white; // no chance of reading the percentage here :-( + case 'Green': return green; + case 'By Level': // fall through + default: + if (setting('charger')) { // charger icon -> always make percentage readable - if (Bangle.isCharging() || l >= 50) return green; - } else { + if (Bangle.isCharging() || l >= 50) return green; + } else { // no icon -> brightest green to indicate charging, even when showing percentage - if (Bangle.isCharging()) return COLORS.charging; - if (l >= 50) return COLORS.high; - } - if (l >= 15) return COLORS.ok; - return COLORS.low; + if (Bangle.isCharging()) return COLORS.charging; + if (l >= 50) return COLORS.high; + } + if (l >= 15) return COLORS.ok; + return COLORS.low; + } } -} -const chargerColor = () => { - return (setting('color') === 'Monochrome') ? COLORS.white : COLORS.charging -} -// sets width, returns true if it changed -function setWidth() { - var w = 40; - if (Bangle.isCharging() && setting('charger')) - w += 16; - if (E.getBattery() > setting('hideifmorethan')) - w = 0; - var changed = WIDGETS["batpc"].width != w; - WIDGETS["batpc"].width = w; - return changed; -} -function draw() { + const chargerColor = () => { + return (setting('color') === 'Monochrome') ? COLORS.white : COLORS.charging + } + // sets width, returns true if it changed + function setWidth() { + var w = 40; + if (Bangle.isCharging() && setting('charger')) + w += 16; + if (E.getBattery() > setting('hideifmorethan')) + w = 0; + var changed = WIDGETS["batpc"].width != w; + WIDGETS["batpc"].width = w; + return changed; + } + function draw() { // if hidden, don't draw - if (!WIDGETS["batpc"].width) return; - // else... - var s = 39; - var x = this.x, y = this.y; - const l = E.getBattery(), - c = levelColor(l); - const xl = x+4+l*(s-12)/100 + if (!WIDGETS["batpc"].width) return; + // else... + var s = 39; + var x = this.x, y = this.y; + const l = E.getBattery(), + c = levelColor(l); + const xl = x+4+l*(s-12)/100 - if (Bangle.isCharging() && setting('charger')) { - g.setColor(chargerColor()).drawImage(atob( - "DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); - x+=16; - } - g.setColor(-1); - g.fillRect(x,y+2,x+s-4,y+21); - g.clearRect(x+2,y+4,x+s-6,y+19); - g.fillRect(x+s-3,y+10,x+s,y+14); + if (Bangle.isCharging() && setting('charger')) { + g.setColor(chargerColor()).drawImage(atob( + "DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y); + x+=16; + } + g.setColor(-1); + g.fillRect(x,y+2,x+s-4,y+21); + g.clearRect(x+2,y+4,x+s-6,y+19); + g.fillRect(x+s-3,y+10,x+s,y+14); - g.setColor(c).fillRect(x+4,y+6,xl,y+17); - g.setColor(-1); - if (!setting('percentage')) { - return; - } - let gfx = g - if (setting('color') === 'Monochrome') { + g.setColor(c).fillRect(x+4,y+6,xl,y+17); + g.setColor(-1); + if (!setting('percentage')) { + return; + } + let gfx = g + if (setting('color') === 'Monochrome') { // draw text inverted on battery level - gfx = Graphics.createCallback(240, 240, 1, - (x,y) => {g.setPixel(x,y,x<=xl?0:-1)}) + gfx = Graphics.createCallback(240, 240, 1, + (x,y) => {g.setPixel(x,y,x<=xl?0:-1)}) + } + gfx.setFontAlign(-1,-1); + if (l >= 100) { + gfx.setFont('4x6', 2); + gfx.drawString(l, x + 6, y + 7); + } else { + if (l < 10) x+=6; + gfx.setFont('6x8', 2); + gfx.drawString(l, x + 6, y + 4); + } } - gfx.setFontAlign(-1,-1); - if (l >= 100) { - gfx.setFont('4x6', 2); - gfx.drawString(l, x + 6, y + 7); - } else { - if (l < 10) x+=6; - gfx.setFont('6x8', 2); - gfx.drawString(l, x + 6, y + 4); + // 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() { + if (setWidth()) Bangle.drawWidgets(); + else WIDGETS["batpc"].draw(); } -} -// 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() { - if (setWidth()) Bangle.drawWidgets(); - else WIDGETS["batpc"].draw(); -} -Bangle.on('charging',function(charging) { - if(charging) Bangle.buzz(); - update(); - g.flip(); -}); -var batteryInterval; -Bangle.on('lcdPower', function(on) { - if (on) { - update(); - // refresh once a minute if LCD on - if (!batteryInterval) - batteryInterval = setInterval(update, 60000); - } else { - if (batteryInterval) { - clearInterval(batteryInterval); - batteryInterval = undefined; - } - } -}); -WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload}; -setWidth(); + Bangle.on('charging',function(charging) { + if(charging) Bangle.buzz(); + update(); + g.flip(); + }); + var batteryInterval; + Bangle.on('lcdPower', function(on) { + if (on) { + update(); + // refresh once a minute if LCD on + if (!batteryInterval) + batteryInterval = setInterval(update, 60000); + } else { + if (batteryInterval) { + clearInterval(batteryInterval); + batteryInterval = undefined; + } + } + }); + WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload}; + setWidth(); })() diff --git a/apps/widbt/widget.js b/apps/widbt/widget.js index c3254c791..2236ee50d 100644 --- a/apps/widbt/widget.js +++ b/apps/widbt/widget.js @@ -1,19 +1,19 @@ (function(){ -var img_bt = E.toArrayBuffer(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA==")); + var img_bt = E.toArrayBuffer(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA==")); -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() { - WIDGETS["bluetooth"].draw(); - g.flip();// turns screen on -} -NRF.on('connect',changed); -NRF.on('disconnect',changed); -WIDGETS["bluetooth"]={area:"tr",width:24,draw: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() { + WIDGETS["bluetooth"].draw(); + g.flip();// turns screen on + } + NRF.on('connect',changed); + NRF.on('disconnect',changed); + WIDGETS["bluetooth"]={area:"tr",width:24,draw:draw}; })() diff --git a/apps/widclk/widget.js b/apps/widclk/widget.js index ff22bb4d1..90280139e 100644 --- a/apps/widclk/widget.js +++ b/apps/widclk/widget.js @@ -1,27 +1,27 @@ (() => { - let intervalRef = null; - var width = 5 * 6*2 + let intervalRef = null; + var width = 5 * 6*2 - function draw() { - g.reset().setFont("6x8", 2).setFontAlign(-1, 0); - var time = require("locale").time(new Date(),1); - g.drawString(time, this.x, this.y+11, true); // 5 * 6*2 = 60 + function draw() { + g.reset().setFont("6x8", 2).setFontAlign(-1, 0); + var time = require("locale").time(new Date(),1); + g.drawString(time, this.x, this.y+11, true); // 5 * 6*2 = 60 + } + function clearTimers(){ + if(intervalRef) { + clearInterval(intervalRef); + intervalRef = null; } - function clearTimers(){ - if(intervalRef) { - clearInterval(intervalRef); - intervalRef = null; - } - } - function startTimers(){ - intervalRef = setInterval(()=>WIDGETS["wdclk"].draw(), 60*1000); - WIDGETS["wdclk"].draw(); - } - Bangle.on('lcdPower', (on) => { - clearTimers(); - if (on) startTimers(); - }); + } + function startTimers(){ + intervalRef = setInterval(()=>WIDGETS["wdclk"].draw(), 60*1000); + WIDGETS["wdclk"].draw(); + } + Bangle.on('lcdPower', (on) => { + clearTimers(); + if (on) startTimers(); + }); - WIDGETS["wdclk"]={area:"tr",width:width,draw:draw}; - if (Bangle.isLCDOn) intervalRef = setInterval(()=>WIDGETS["wdclk"].draw(), 60*1000); + WIDGETS["wdclk"]={area:"tr",width:width,draw:draw}; + if (Bangle.isLCDOn) intervalRef = setInterval(()=>WIDGETS["wdclk"].draw(), 60*1000); })() diff --git a/apps/widhwt/widget.js b/apps/widhwt/widget.js index 3fff48800..6affdea52 100644 --- a/apps/widhwt/widget.js +++ b/apps/widhwt/widget.js @@ -1,23 +1,23 @@ /* jshint esversion: 6 */ (() => { - var icon = require("heatshrink").decompress(atob("jEYwIKHgwCBhwCBh4CEggPCkACBmAXDBwVZ+EB+F4gEsjl8EgMP+EChk/gEMh+ehkA+YIBxwxBnF/4HggH/wEAj0AA==")); - var color = 0x4A69; + var icon = require("heatshrink").decompress(atob("jEYwIKHgwCBhwCBh4CEggPCkACBmAXDBwVZ+EB+F4gEsjl8EgMP+EChk/gEMh+ehkA+YIBxwxBnF/4HggH/wEAj0AA==")); + var color = 0x4A69; - function draw() { - g.reset().setColor(color).drawImage(icon, this.x + 1, 0); - } + function draw() { + g.reset().setColor(color).drawImage(icon, this.x + 1, 0); + } - WIDGETS["widhwt"] = { area: "tr", width: 26, draw: draw }; + WIDGETS["widhwt"] = { area: "tr", width: 26, draw: draw }; - Bangle.on('swipe', function() { - color = 0x41f; - Bangle.buzz(); - Bangle.drawWidgets(); - setTimeout(() => { - color = 0x4A69; - Bangle.buzz(1E3, 1); - Bangle.drawWidgets(); - }, 35E3); + Bangle.on('swipe', function() { + color = 0x41f; + Bangle.buzz(); + Bangle.drawWidgets(); + setTimeout(() => { + color = 0x4A69; + Bangle.buzz(1E3, 1); + Bangle.drawWidgets(); + }, 35E3); - }); + }); })(); \ No newline at end of file diff --git a/apps/widid/widget.js b/apps/widid/widget.js index efbfdfd19..e97eecb65 100644 --- a/apps/widid/widget.js +++ b/apps/widid/widget.js @@ -1,12 +1,12 @@ /* jshint esversion: 6 */ (() => { - var id = NRF.getAddress().substr().substr(12).split(":"); + var id = NRF.getAddress().substr().substr(12).split(":"); - // draw your widget at xpos - function draw() { - g.reset().setColor(0, 0.5, 1).setFont("6x8", 1); - g.drawString(id[0], this.x+2, this.y+4, true); - g.drawString(id[1], this.x+2, this.y+14, true); - } - WIDGETS["widid"] = { area:"tr", width:16, draw: draw }; + // draw your widget at xpos + function draw() { + g.reset().setColor(0, 0.5, 1).setFont("6x8", 1); + g.drawString(id[0], this.x+2, this.y+4, true); + g.drawString(id[1], this.x+2, this.y+14, true); + } + WIDGETS["widid"] = { area:"tr", width:16, draw: draw }; })(); diff --git a/apps/widmp/widget.js b/apps/widmp/widget.js index be4c2bb39..cebdb60f5 100644 --- a/apps/widmp/widget.js +++ b/apps/widmp/widget.js @@ -1,33 +1,33 @@ /* jshint esversion: 6 */ (() => { - const BLACK = 0, MOON = 0x41f, MC = 29.5305882, NM = 694039.09; - var r = 12, mx = 0, my = 0; + const BLACK = 0, MOON = 0x41f, MC = 29.5305882, NM = 694039.09; + var r = 12, mx = 0, my = 0; - var moon = { - 0: () => { g.reset().setColor(BLACK).fillRect(mx - r, my - r, mx + r, my + r);}, - 1: () => { moon[0](); g.setColor(MOON).drawCircle(mx, my, r);}, - 2: () => { moon[3](); g.setColor(BLACK).fillEllipse(mx - r / 2, my - r, mx + r / 2, my + r);}, - 3: () => { moon[0](); g.setColor(MOON).fillCircle(mx, my, r).setColor(BLACK).fillRect(mx - r, my - r, mx, my + r);}, - 4: () => { moon[3](); g.setColor(MOON).fillEllipse(mx - r / 2, my - r, mx + r / 2, my + r);}, - 5: () => { moon[0](); g.setColor(MOON).fillCircle(mx, my, r);}, - 6: () => { moon[7](); g.setColor(MOON).fillEllipse(mx - r / 2, my - r, mx + r / 2, my + r);}, - 7: () => { moon[0](); g.setColor(MOON).fillCircle(mx, my, r).setColor(BLACK).fillRect(mx, my - r, mx + r + r, my + r);}, - 8: () => { moon[7](); g.setColor(BLACK).fillEllipse(mx - r / 2, my - r, mx + r / 2, my + r);} - }; + var moon = { + 0: () => { g.reset().setColor(BLACK).fillRect(mx - r, my - r, mx + r, my + r);}, + 1: () => { moon[0](); g.setColor(MOON).drawCircle(mx, my, r);}, + 2: () => { moon[3](); g.setColor(BLACK).fillEllipse(mx - r / 2, my - r, mx + r / 2, my + r);}, + 3: () => { moon[0](); g.setColor(MOON).fillCircle(mx, my, r).setColor(BLACK).fillRect(mx - r, my - r, mx, my + r);}, + 4: () => { moon[3](); g.setColor(MOON).fillEllipse(mx - r / 2, my - r, mx + r / 2, my + r);}, + 5: () => { moon[0](); g.setColor(MOON).fillCircle(mx, my, r);}, + 6: () => { moon[7](); g.setColor(MOON).fillEllipse(mx - r / 2, my - r, mx + r / 2, my + r);}, + 7: () => { moon[0](); g.setColor(MOON).fillCircle(mx, my, r).setColor(BLACK).fillRect(mx, my - r, mx + r + r, my + r);}, + 8: () => { moon[7](); g.setColor(BLACK).fillEllipse(mx - r / 2, my - r, mx + r / 2, my + r);} + }; - function moonPhase(d) { - var tmp, month = d.getMonth(), year = d.getFullYear(), day = d.getDate(); - if (month < 3) {year--; month += 12;} - tmp = ((365.25 * year + 30.6 * ++month + day - NM) / MC); - return Math.round(((tmp - (tmp | 0)) * 7)+1); - } + function moonPhase(d) { + var tmp, month = d.getMonth(), year = d.getFullYear(), day = d.getDate(); + if (month < 3) {year--; month += 12;} + tmp = ((365.25 * year + 30.6 * ++month + day - NM) / MC); + return Math.round(((tmp - (tmp | 0)) * 7)+1); + } - function draw() { - mx = this.x; my = this.y + 12; - moon[moonPhase(Date())](); - } + function draw() { + mx = this.x; my = this.y + 12; + moon[moonPhase(Date())](); + } - WIDGETS["widmoon"] = { area: "tr", width: 24, draw: draw }; + WIDGETS["widmoon"] = { area: "tr", width: 24, draw: draw }; })(); diff --git a/apps/widram/widget.js b/apps/widram/widget.js index bd44b98a4..dc7fed6c3 100644 --- a/apps/widram/widget.js +++ b/apps/widram/widget.js @@ -10,14 +10,14 @@ var ramInterval; Bangle.on('lcdPower', function(on) { if (on) { - WIDGETS["ram"].draw(); - if (!ramInterval) ramInterval = setInterval(()=>WIDGETS["ram"].draw(), 10000); - } else { - if (ramInterval) { - clearInterval(ramInterval); - ramInterval = undefined; - } - } + WIDGETS["ram"].draw(); + if (!ramInterval) ramInterval = setInterval(()=>WIDGETS["ram"].draw(), 10000); + } else { + if (ramInterval) { + clearInterval(ramInterval); + ramInterval = undefined; + } + } }); WIDGETS["ram"]={area:"tl",width: 24,draw:draw}; })() diff --git a/apps/widtbat/widget.js b/apps/widtbat/widget.js index f60034300..8cc4b0c83 100644 --- a/apps/widtbat/widget.js +++ b/apps/widtbat/widget.js @@ -1,18 +1,18 @@ /* jshint esversion: 6 */ (() => { - const CBS = 0x41f, CBC = 0x07E0; - var batS = require("heatshrink").decompress(atob("j0TwIHEv///kD////EfAYPwuEAgPB4EAg/HCgMfzgDBvwOC/IOC84ONDoUcFgc/AYOAHYRDE")); - var xo = 6, xl = 22, yo = 9, h = 17; + const CBS = 0x41f, CBC = 0x07E0; + var batS = require("heatshrink").decompress(atob("j0TwIHEv///kD////EfAYPwuEAgPB4EAg/HCgMfzgDBvwOC/IOC84ONDoUcFgc/AYOAHYRDE")); + var xo = 6, xl = 22, yo = 9, h = 17; - function draw() { - g.reset().setColor(CBS).drawImage(batS, this.x + 1, this.y + 4); - g.setColor(0).fillRect(this.x + xo, this.y + yo, this.x + xl, this.y + h); - var cbc = (Bangle.isCharging()) ? CBC : CBS; - g.setColor(cbc).fillRect(this.x + xo, this.y + yo, this.x + (xl - xo) / 100 * E.getBattery() + xo, this.y + h); - } - Bangle.on('charging', function(charging) { - if (charging) Bangle.buzz(); - Bangle.drawWidgets(); - }); - WIDGETS["widtbat"] = { area:"tr", width:32, draw: draw }; + function draw() { + g.reset().setColor(CBS).drawImage(batS, this.x + 1, this.y + 4); + g.setColor(0).fillRect(this.x + xo, this.y + yo, this.x + xl, this.y + h); + var cbc = (Bangle.isCharging()) ? CBC : CBS; + g.setColor(cbc).fillRect(this.x + xo, this.y + yo, this.x + (xl - xo) / 100 * E.getBattery() + xo, this.y + h); + } + Bangle.on('charging', function(charging) { + if (charging) Bangle.buzz(); + Bangle.drawWidgets(); + }); + WIDGETS["widtbat"] = { area:"tr", width:32, draw: draw }; })(); diff --git a/apps/widver/widget.js b/apps/widver/widget.js index b5edfc08c..5da66444f 100644 --- a/apps/widver/widget.js +++ b/apps/widver/widget.js @@ -1,11 +1,11 @@ /* jshint esversion: 6 */ (() => { - var width = 28, - ver = process.env.VERSION.split('.'); - function draw() { - g.reset().setColor(0, 0.5, 1).setFont("6x8", 1); - g.drawString(ver[0], this.x + 2, this.y + 4, true); - g.setFontAlign(0, -1, 0).drawString(ver[1], this.x + width / 2, this.y + 14, true); - } - WIDGETS["version"] = { area: "tr", width: width, draw: draw }; + var width = 28, + ver = process.env.VERSION.split('.'); + function draw() { + g.reset().setColor(0, 0.5, 1).setFont("6x8", 1); + g.drawString(ver[0], this.x + 2, this.y + 4, true); + g.setFontAlign(0, -1, 0).drawString(ver[1], this.x + width / 2, this.y + 14, true); + } + WIDGETS["version"] = { area: "tr", width: width, draw: draw }; })(); diff --git a/apps/wohrm/app.js b/apps/wohrm/app.js index b3ce8acc8..d30072a60 100644 --- a/apps/wohrm/app.js +++ b/apps/wohrm/app.js @@ -143,13 +143,13 @@ function renderConfidenceBars(){ if(!confidenceChanged) { return; } if(hrConfidence >= 85){ - g.setColor(0, 255, 0); + g.setColor(0, 255, 0); } else if (hrConfidence >= 50) { - g.setColor(255, 255, 0); + g.setColor(255, 255, 0); } else if(hrConfidence >= 0){ - g.setColor(255, 0, 0); + g.setColor(255, 0, 0); } else { - g.setColor(255, 255, 255); + g.setColor(255, 255, 255); } g.fillRect(45, 110, 55, 150);