diff --git a/Bangle.js.svg b/Bangle.js.svg
new file mode 100644
index 000000000..90c908c9b
--- /dev/null
+++ b/Bangle.js.svg
@@ -0,0 +1,478 @@
+
+
diff --git a/android-chrome-192x192.png b/android-chrome-192x192.png
new file mode 100644
index 000000000..a4dff3bb5
Binary files /dev/null and b/android-chrome-192x192.png differ
diff --git a/android-chrome-512x512.png b/android-chrome-512x512.png
new file mode 100644
index 000000000..f89cbfb31
Binary files /dev/null and b/android-chrome-512x512.png differ
diff --git a/apple-touch-icon.png b/apple-touch-icon.png
new file mode 100644
index 000000000..2330e0fdf
Binary files /dev/null and b/apple-touch-icon.png differ
diff --git a/apps.json b/apps.json
index b088865d2..dcb27d1d1 100644
--- a/apps.json
+++ b/apps.json
@@ -15,8 +15,8 @@
{ "id": "moonphase",
"name": "Moonphase",
"icon": "app.png",
- "version":"0.01",
- "description": "Shows current moon phase. Currently only with fixed coordinates (northern hemisphere).",
+ "version":"0.02",
+ "description": "Shows current moon phase. Now with GPS function.",
"tags": "",
"allow_emulator":true,
"storage": [
@@ -91,7 +91,7 @@
{ "id": "gbridge",
"name": "Gadgetbridge",
"icon": "app.png",
- "version":"0.04",
+ "version":"0.06",
"description": "The default notification handler for Gadgetbridge notifications from Android",
"tags": "tool,system,android,widget",
"storage": [
@@ -392,7 +392,8 @@
{ "id": "swatch",
"name": "Stopwatch",
"icon": "stopwatch.png",
- "version":"0.03",
+ "version":"0.05",
+ "interface": "interface.html",
"description": "Simple stopwatch with Lap Time logging to a JSON file",
"tags": "health",
"allow_emulator":true,
@@ -892,7 +893,7 @@
{ "id": "marioclock",
"name": "Mario Clock",
"icon": "marioclock.png",
- "version":"0.04",
+ "version":"0.05",
"description": "Animated Mario clock, jumps to change the time!",
"tags": "clock,mario,retro",
"type": "clock",
@@ -963,7 +964,28 @@
{"name":"chrono.img","url":"chrono-icon.js","evaluate":true}
]
},
- { "id": "widhwt",
+ { "id": "astrocalc",
+ "name": "Astrocalc",
+ "icon": "astrocalc.png",
+ "version":"0.01",
+ "description": "Calculates interesting information on the sun and moon cycles for the current day based on your location.",
+ "tags": "app,sun,moon,cycles,tool,outdoors",
+ "allow_emulator":true,
+ "storage": [
+ {"name":"astrocalc.app.js","url":"astrocalc-app.js"},
+ {"name":"suncalc.js","url":"suncalc.js"},
+ {"name":"astrocalc.img","url":"astrocalc-icon.js","evaluate":true},
+ {"name":"first-quarter.img","url":"first-quarter-icon.js","evaluate":true},
+ {"name":"last-quarter.img","url":"last-quarter-icon.js","evaluate":true},
+ {"name":"waning-crescent.img","url":"waning-crescent-icon.js","evaluate":true},
+ {"name":"waning-gibbous.img","url":"waning-gibbous-icon.js","evaluate":true},
+ {"name":"full.img","url":"full-icon.js","evaluate":true},
+ {"name":"new.img","url":"new-icon.js","evaluate":true},
+ {"name":"waxing-gibbous.img","url":"waxing-gibbous-icon.js","evaluate":true},
+ {"name":"waxing-crescent.img","url":"waxing-crescent-icon.js","evaluate":true}
+ ]
+ },
+ { "id": "widhwt",
"name": "Hand Wash Timer",
"icon": "widget.png",
"version":"0.01",
@@ -973,5 +995,56 @@
"storage": [
{"name":"widhwt.wid.js","url":"widget.js"}
]
+ },
+ { "id": "toucher",
+ "name": "Touch Launcher",
+ "shortName":"Menu",
+ "icon": "app.png",
+ "version":"0.02",
+ "description": "Touch enable left to right launcher.",
+ "tags": "tool,system,launcher",
+ "type":"launch",
+ "storage": [
+ {"name":"toucher.app.js","url":"app.js"}
+ ],
+ "sortorder" : -10
+ },
+ {
+ "id": "balltastic",
+ "name": "Balltastic",
+ "icon": "app.png",
+ "version": "0.01",
+ "description": "Simple but fun ball eats dots game.",
+ "tags": "game,fun",
+ "type": "app",
+ "storage": [
+ {"name":"balltastic.app.js","url":"app.js"},
+ {"name":"balltastic.img","url":"app-icon.js","evaluate":true}
+ ]
+ },
+ {
+ "id": "rpgdice",
+ "name": "RPG dice",
+ "icon": "rpgdice.png",
+ "version": "0.01",
+ "description": "Simple RPG dice rolling app.",
+ "tags": "game,fun",
+ "type": "app",
+ "allow_emulator": true,
+ "storage": [
+ {"name":"rpgdice.app.js","url": "app.js"},
+ {"name":"rpgdice.img","url": "app-icon.js","evaluate":true}
+ ]
+ },
+ { "id": "widmp",
+ "name": "Moon Phase Widget",
+ "icon": "widget.png",
+ "version":"0.01",
+ "description": "Display the current moon phase in blueish for the northern hemisphere in eight phases",
+ "tags": "widget,tools",
+ "type":"widget",
+ "storage": [
+ {"name":"widmp.wid.js","url":"widget.js"}
+ ]
}
]
diff --git a/apps/astrocalc/ChangeLog b/apps/astrocalc/ChangeLog
new file mode 100644
index 000000000..0c8adeb61
--- /dev/null
+++ b/apps/astrocalc/ChangeLog
@@ -0,0 +1 @@
+0.01: Create astrocalc app
diff --git a/apps/astrocalc/astrocalc-app.js b/apps/astrocalc/astrocalc-app.js
new file mode 100644
index 000000000..318147b13
--- /dev/null
+++ b/apps/astrocalc/astrocalc-app.js
@@ -0,0 +1,348 @@
+/**
+ * Inspired by: https://www.timeanddate.com
+ */
+
+const SunCalc = require("suncalc.js");
+
+function drawMoon(phase, x, y) {
+ const moonImgFiles = [
+ "new",
+ "waxing-crescent",
+ "first-quarter",
+ "waxing-gibbous",
+ "full",
+ "waning-gibbous",
+ "last-quarter",
+ "waning-crescent",
+ ];
+
+ img = require("Storage").read(`${moonImgFiles[phase]}.img`);
+ // image width & height = 92px
+ g.drawImage(img, x - parseInt(92 / 2), y);
+}
+
+// linear interpolation between two values a and b
+// u controls amount of a/b and is in range [0.0,1.0]
+function lerp(a,b,u) {
+ return (1-u) * a + u * b;
+}
+
+function titlizeKey(key) {
+ return (key[0].toUpperCase() + key.slice(1)).match(/[A-Z][a-z]+/g).join(" ");
+}
+
+function dateToTimeString(date) {
+ const hrs = ("0" + date.getHours()).substr(-2);
+ const mins = ("0" + date.getMinutes()).substr(-2);
+ const secs = ("0" + date.getMinutes()).substr(-2);
+
+ return `${hrs}:${mins}:${secs}`;
+}
+
+function drawTitle(key) {
+ const fontHeight = 16;
+ const x = 0;
+ const x2 = g.getWidth() - 1;
+ const y = fontHeight + 26;
+ const y2 = g.getHeight() - 1;
+ const title = titlizeKey(key);
+
+ g.setFont("6x8", 2);
+ g.setFontAlign(0,-1);
+ g.drawString(title,(x+x2)/2,y-fontHeight-2);
+ g.drawLine(x,y-2,x2,y-2);
+}
+
+/**
+ * @params {Number} angle Angle of point around a radius
+ * @params {Number} radius Radius of the point to be drawn, default 2
+ * @params {Object} color Color of the point
+ * @params {Number} color.r Red 0-1
+ * @params {Number} color.g Green 0-1
+ * @params {Number} color.b Blue 0-1
+ */
+function drawPoint(angle, radius, color) {
+ const pRad = Math.PI / 180;
+ const faceWidth = 80; // watch face radius
+ const centerPx = g.getWidth() / 2;
+
+ const a = angle * pRad;
+ const x = centerPx + Math.sin(a) * faceWidth;
+ const y = centerPx - Math.cos(a) * faceWidth;
+
+ if (!radius) radius = 2;
+
+ g.setColor(color.r, color.g, color.b);
+ g.fillCircle(x, y + 20, radius);
+}
+
+function drawPoints() {
+ const startColor = {r: 140, g: 255, b: 255}; // light blue
+ const endColor = {r: 0, g: 0, b: 140}; // dark turquoise
+
+ const steps = 60;
+ const step_u = 1.0 / (steps / 2);
+ let u = 0.0;
+
+ for (let i = 0; i < steps; i++) {
+ const colR = lerp(startColor.r, endColor.r, u) / 255;
+ const colG = lerp(startColor.g, endColor.g, u) / 255;
+ const colB = lerp(startColor.b, endColor.b, u) / 255;
+ const col = {r: colR, g: colG, b: colB};
+
+ if (i >= 0 && i <= 30) {
+ u += step_u;
+ } else {
+ u -= step_u;
+ }
+
+ drawPoint((360 * i) / steps, 2, col);
+ }
+}
+
+function drawData(title, obj, startX, startY) {
+ g.clear();
+ drawTitle(title);
+
+ let xPos, yPos;
+
+ if (typeof(startX) === "undefined" || startX === null) {
+ // Center text
+ g.setFontAlign(0,-1);
+ xPos = (0 + g.getWidth() - 2) / 2;
+ } else {
+ xPos = startX;
+ }
+
+ if (typeof(startY) === "undefined") {
+ yPos = 5;
+ } else {
+ yPos = startY;
+ }
+
+ g.setFont("6x8", 1);
+
+ Object.keys(obj).forEach((key) => {
+ g.drawString(`${key}: ${obj[key]}`, xPos, yPos += 20);
+ });
+
+ g.flip();
+}
+
+function drawMoonPositionPage(gps, title) {
+ const pos = SunCalc.getMoonPosition(new Date(), gps.lat, gps.lon);
+
+ const pageData = {
+ Azimuth: pos.azimuth.toFixed(2),
+ Altitude: pos.altitude.toFixed(2),
+ Distance: `${pos.distance.toFixed(0)} km`,
+ "Parallactic Ang": pos.parallacticAngle.toFixed(2),
+ };
+ const azimuthDegrees = parseInt(pos.azimuth * 180 / Math.PI);
+
+ drawData(title, pageData, null, 80);
+ drawPoints();
+ drawPoint(azimuthDegrees, 8, {r: 1, g: 1, b: 1});
+
+ let m = setWatch(() => {
+ let m = moonIndexPageMenu(gps);
+ }, BTN3, {repeat: false, edge: "falling"});
+}
+
+function drawMoonIlluminationPage(gps, title) {
+ const phaseNames = [
+ "New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous",
+ "Full Moon", "Waning Gibbous", "Last Quater", "Waning Crescent",
+ ];
+
+ const phase = SunCalc.getMoonIllumination(new Date());
+ const pageData = {
+ Phase: phaseNames[phase.phase],
+ };
+
+ drawData(title, pageData, null, 35);
+ drawMoon(phase.phase, g.getWidth() / 2, g.getHeight() / 2);
+
+ let m = setWatch(() => {
+ let m = moonIndexPageMenu(gps);
+ }, BTN3, {repease: false, edge: "falling"});
+}
+
+
+function drawMoonTimesPage(gps, title) {
+ const times = SunCalc.getMoonTimes(new Date(), gps.lat, gps.lon);
+
+ const pageData = {
+ Rise: dateToTimeString(times.rise),
+ Set: dateToTimeString(times.set),
+ };
+
+ drawData(title, pageData, null, 105);
+ drawPoints();
+
+ // Draw the moon rise position
+ const risePos = SunCalc.getMoonPosition(times.rise, gps.lat, gps.lon);
+ const riseAzimuthDegrees = parseInt(risePos.azimuth * 180 / Math.PI);
+ drawPoint(riseAzimuthDegrees, 8, {r: 1, g: 1, b: 1});
+
+ // Draw the moon set position
+ const setPos = SunCalc.getMoonPosition(times.set, gps.lat, gps.lon);
+ const setAzimuthDegrees = parseInt(setPos.azimuth * 180 / Math.PI);
+ drawPoint(setAzimuthDegrees, 8, {r: 1, g: 1, b: 1});
+
+ let m = setWatch(() => {
+ let m = moonIndexPageMenu(gps);
+ }, BTN3, {repease: false, edge: "falling"});
+}
+
+function drawSunShowPage(gps, key, date) {
+ const pos = SunCalc.getPosition(date, gps.lat, gps.lon);
+
+ const hrs = ("0" + date.getHours()).substr(-2);
+ const mins = ("0" + date.getMinutes()).substr(-2);
+ const secs = ("0" + date.getMinutes()).substr(-2);
+ const time = `${hrs}:${mins}:${secs}`;
+
+ const azimuth = Number(pos.azimuth.toFixed(2));
+ const azimuthDegrees = parseInt(pos.azimuth * 180 / Math.PI);
+ const altitude = Number(pos.altitude.toFixed(2));
+
+ const pageData = {
+ Time: time,
+ Altitude: altitude,
+ Azimumth: azimuth,
+ Degrees: azimuthDegrees
+ };
+
+ drawData(key, pageData, null, 85);
+
+ drawPoints();
+
+ // Draw the suns position
+ drawPoint(azimuthDegrees, 8, {r: 1, g: 1, b: 0});
+
+ m = setWatch(() => {
+ m = sunIndexPageMenu(gps);
+ }, BTN3, {repeat: false, edge: "falling"});
+
+ return null;
+}
+
+function sunIndexPageMenu(gps) {
+ 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());
+ },
+ };
+
+ 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);
+
+ 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),
+ };
+
+ return E.showMenu(moonMenu);
+}
+
+function indexPageMenu(gps) {
+ const menu = {
+ "": {
+ "title": "Select",
+ },
+ "Sun": () => {
+ m = sunIndexPageMenu(gps);
+ },
+ "Moon": () => {
+ m = moonIndexPageMenu(gps);
+ },
+ "< Exit": () => { load(); }
+ };
+
+ return E.showMenu(menu);
+}
+
+/**
+ * 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=="))
+
+ g.clear();
+ g.drawImage(img, 100, 50);
+ g.setFont("6x8", 1);
+ g.drawString("Astrocalc v0.01", 80, 105);
+ g.drawString("Locating GPS", 85, 140);
+ g.drawString("Please wait...", 80, 155);
+ g.flip();
+
+ const DEBUG = false;
+ if (DEBUG) {
+ const gps = {
+ "lat": 56.45783133333,
+ "lon": -3.02188583333,
+ "alt": 75.3,
+ "speed": 0.070376,
+ "course": NaN,
+ "time":new Date(),
+ "satellites": 4,
+ "fix": 1
+ };
+
+ m = indexPageMenu(gps);
+
+ return;
+ }
+
+ Bangle.on('GPS', (gps) => {
+ if (gps.fix === 0) return;
+
+ Bangle.setGPSPower(0);
+ Bangle.buzz();
+ Bangle.setLCDPower(true);
+
+ m = indexPageMenu(gps);
+ });
+}
+
+function init() {
+ Bangle.setGPSPower(1);
+ drawGPSWaitPage();
+}
+
+let m;
+init();
\ No newline at end of file
diff --git a/apps/astrocalc/astrocalc-icon.js b/apps/astrocalc/astrocalc-icon.js
new file mode 100644
index 000000000..aa04c2805
--- /dev/null
+++ b/apps/astrocalc/astrocalc-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AW43GF1wwsFwYwqFwowoFw4wmFxIwdE5YAPF/4vM5nN6YAE5vMF8YtHGIgvhFpQxKF7AuOGA4vXFyAwGF63MFyIABF6xeWMC4UDLwvNGpAJG5gwSdhIIDRBLyWCIgcJHAgJJDoouQF4vMQoICBBJoeGFx6GGACIfHL6YvaX6gvZeCIdFc4gAFXogvGFxgwFDwovQCAguOGAnMMBxeG5guTGAggGGAwNKFySREcA3N5vM5gDBdpQvXEY4AKXqovGGCKbFF7AwPZQwvZGJgtGF7vGdQItG5gSIF7gASF/44WEzgwRF0wwHF1AwFF1QwDF1gvwAH4A/AFAA=="))
\ No newline at end of file
diff --git a/apps/astrocalc/astrocalc.png b/apps/astrocalc/astrocalc.png
new file mode 100644
index 000000000..c26a651ec
Binary files /dev/null and b/apps/astrocalc/astrocalc.png differ
diff --git a/apps/astrocalc/first-quarter-icon.js b/apps/astrocalc/first-quarter-icon.js
new file mode 100644
index 000000000..d88ec79b5
--- /dev/null
+++ b/apps/astrocalc/first-quarter-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("rlcgI1ygf4BZM/BZMD//wCxP/8AWJ/+ACxP+CxQ6ICwP/4AWJERAWCEQ4WCERAWCEQ4WDOg4WCNA4WD/gWKRYwWDHI4WDHIwWDHI4WDHIwWEOYwWDHIwWEKAwWD/4WKKAwWEKAoWEYgwWPM4wWEM4oWQM4oWEPwwWbPwoWESowW/C34WOZ1vACxP8Cyv4CxWACyoKFCwiUFCwhmGCwh9FCwhmGCwhmFCwhPGCwgKFCwg4GCwZPGCwg4GCwY4GCwgKGCwY4GCwZxGCwjBFCwghHCwQhHCwYhHCwQhHCwRlHCwSHHCwYKICwI3HCwQKJAFAA=="))
\ No newline at end of file
diff --git a/apps/astrocalc/full-icon.js b/apps/astrocalc/full-icon.js
new file mode 100644
index 000000000..8bc04f7fc
--- /dev/null
+++ b/apps/astrocalc/full-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("rlcgJC/AD8B//4BRILJBQP/+AKGn4LC4AKFh4KC/4KFgYKD/gLFv4LD8AKEj4KD/+AEJAiGEIgiFIYhFFOAQADOghlDNA0HBQv+Q4wADRYZaFLgg4GHIg4GHIY4GHIhxFOYhxGOYgKHKARPHKARPHKAZPHKATBFYgoWKMw5nDMw5nCCyx9IPwQKIPwIW/C34WJZ1sDBQ/8CwM/BY/ACxkfBY+AgEBBQ/4CwJ+IBQJ+IPoJnIMwRnIMwJQIJ4RQIJ4JQIJ4RQIBQQ5HHAQ5HHAY5HHARzHOIRzHOIbEHYIIACLgpaDEQwhFEQohEIopDENAplERYwKGOgZwEBYoKIAH4AXA=="))
\ No newline at end of file
diff --git a/apps/astrocalc/last-quarter-icon.js b/apps/astrocalc/last-quarter-icon.js
new file mode 100644
index 000000000..b6517f66b
--- /dev/null
+++ b/apps/astrocalc/last-quarter-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("rlcgI0xgP8BRP/4ALI/4WJv4WJj4WJg//CxA3BCxM/CxIhCCw4hCCxAhCCw4hCCxAKCCw5lBCxEDCxSHBCxA4DCw4KCCw44DCww4DCw5xCCw44DCw5PDCw0PCxQKDCwxPDCwzBDCyRmECwxmDCyRmDCwx9ECzoKDCwyUEC34W/CyDOtn4WJgYWVgIWKj4WVPwgWFSogWGM4gWGPwYWGM4gWGM4YWGKAgWGKAYWGHIgWGKAYWHHIYWGHIYWHHIYWGHIYWHOYYWHYgQWHEQYWHEQQWIEQQWHEQQWINAQWIRYIWIOgQWIHQIWJBYIWJAFI="))
\ No newline at end of file
diff --git a/apps/astrocalc/new-icon.js b/apps/astrocalc/new-icon.js
new file mode 100644
index 000000000..5d610fbe1
--- /dev/null
+++ b/apps/astrocalc/new-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("rlcgIGDh///4RHBQQLHg4KC/wKFgIKC//4BYt/BYfgBQkfBQf/wAsHFw4HCBwXwBQc/AwYLB4AhEIARIBEQn//gECgYiEIYJ2FIoQQBE4YzBDgd/NoguBNAUPKoo/BB4YhEEQIdCAYYiECQMHUwwHDEIweBLgMPWIwiBAQSlENwQTBDIQAFFQMDHAw5BOYN/HAwfB8ANCAAofCHA45B+EPHA4UBKQQAGMgMfUYQAFv+DJ45QCn5PHKAPDJ45QB/hmICwPnT4yhC/1/Mw5nBCxZmIM4P/PpB+BC34WEVZCsB/7CIYYIWWOX4WbfiwWL/gKHgf+n/ABY8/4YWJ/k/VhF/4LDIg/4j5nI/+APxEP+EPM48BCgN/KA5CBg5QHMwINCJ4/AgY5Hh4fBj45GHAKeBAQSfFMgIZCHAoqCv45GA4QOBEQsfDwQDDEIgSC/4iFv6dCg4iFj60Dn4iEEIKRCL4K5E/5uDh4QDDgKFEv4uDj4/EE4IRCDYIzEAwIvBAQKnFEQIADMIhFBAAayFNAIACMoZtDBYa9GFwbrHBQR2EBYoKEA=="))
\ No newline at end of file
diff --git a/apps/astrocalc/suncalc.js b/apps/astrocalc/suncalc.js
new file mode 100644
index 000000000..6ef5aa2d0
--- /dev/null
+++ b/apps/astrocalc/suncalc.js
@@ -0,0 +1,328 @@
+/*
+ (c) 2011-2015, Vladimir Agafonkin
+ SunCalc is a JavaScript library for calculating sun/moon position and light phases.
+ https://github.com/mourner/suncalc
+*/
+
+(function () { 'use strict';
+
+// shortcuts for easier to read formulas
+
+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;
+
+// sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas
+
+
+// date/time constants and conversions
+
+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; }
+
+
+// general calculations for position
+
+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 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 astroRefraction(h) {
+ if (h < 0) // the following formula works for positive altitudes only.
+ h = 0; // if h = -0.08901179 a div/0 would occur.
+
+ // formula 16.4 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
+ // 1.02 / tan(h + 10.26 / (h + 5.10)) h in degrees, result in arc minutes -> converted to rad:
+ return 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179));
+}
+
+// general sun calculations
+
+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
+
+ 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 SunCalc = {};
+
+
+// calculates sun position for a given date and latitude/longitude
+
+SunCalc.getPosition = function (date, lat, lng) {
+
+ var lw = rad * -lng,
+ phi = rad * lat,
+ d = toDays(date),
+
+ c = sunCoords(d),
+ H = siderealTime(d, lw) - c.ra;
+
+ return {
+ azimuth: azimuth(H, phi, c.dec),
+ altitude: altitude(H, phi, c.dec)
+ };
+};
+
+
+// sun times configuration (angle, morning name, evening name)
+
+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
+
+SunCalc.addTime = function (angle, riseName, setName) {
+ times.push([angle, riseName, setName]);
+};
+
+
+// calculations for sun times
+
+var J0 = 0.0009;
+
+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 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) {
+
+ var w = hourAngle(h, phi, dec),
+ a = approxTransit(w, lw, n);
+ return solarTransitJ(a, M, L);
+}
+
+
+// calculates sun times for a given date, latitude/longitude, and, optionally,
+// the observer height (in meters) relative to the horizon
+
+SunCalc.getTimes = function (date, lat, lng, height) {
+
+ height = height || 0;
+
+ var lw = rad * -lng,
+ phi = rad * lat,
+
+ dh = observerAngle(height),
+
+ d = toDays(date),
+ n = julianCycle(d, lw),
+ ds = approxTransit(0, lw, n),
+
+ M = solarMeanAnomaly(ds),
+ L = eclipticLongitude(M),
+ dec = declination(L, 0),
+
+ Jnoon = solarTransitJ(ds, M, L),
+
+ i, len, time, h0, Jset, Jrise;
+
+
+ var result = {
+ 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;
+
+ 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));
+ }
+
+ return result;
+};
+
+
+// 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
+
+ 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
+ };
+};
+
+
+// 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
+
+SunCalc.getMoonIllumination = function (date) {
+ let month = date.getMonth();
+ let year = date.getFullYear();
+ let day = date.getDate();
+
+ 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};
+};
+
+
+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
+
+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;
+
+ // 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;
+ }
+
+ 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;
+};
+
+
+// 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/astrocalc/waning-crescent-icon.js b/apps/astrocalc/waning-crescent-icon.js
new file mode 100644
index 000000000..8ff83ab1f
--- /dev/null
+++ b/apps/astrocalc/waning-crescent-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("rlcgJC/ABHgBRN8BRMfwAKIg/4CxP/BRM/HBMH/wKIgP/4AhJ/ghJ/5PJ/5PJj4WJgf/+AWIv5mJHAIWJ/5mJHAJ9IHAIWJn59JHAJ9JJ4IWIh4WK/4WJJ4KUIYIKUJJ4IWIMwIWgMwIWIPoLCJCwLCICxYKBCxCUBC34W/Cya3WCxr8In78JgYWhj4WJgIWKPwP8SpXAM5IWJPwIWIKAIWJM4PgKBP+CxBQBCxA5CBRBQBYZA5CBRA5BSpA5CSpA5BCxJzBPxDEBPxIiBM5MDPxJFBM5IiBKBMBKBKLBKBMAhwKJAH4ABA="))
\ No newline at end of file
diff --git a/apps/astrocalc/waning-gibbous-icon.js b/apps/astrocalc/waning-gibbous-icon.js
new file mode 100644
index 000000000..2373475f4
--- /dev/null
+++ b/apps/astrocalc/waning-gibbous-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("rlcgI0xgP/wAKJ/wWI///+AKHv4LBEQ8fBQP8BQ0HBQP/8A3HAAQWGn4KCHIwhDHIwhE/AhJ//AEJJQGBQZQGMoQABRQsDCwhQFQ4RnHHAgWGBQhnFHAhnFHAoWFOIhnFHAp+FJ4oWEh4WKBQp+EJ4qVEYIgWRMwwWEMwoWLVghmFVgh9GCzYKGCwaUGC34W/CxzOtn4WJgYKF/wWK8AKCgIWKj4WVPwwWDSo38BQZnG4B+JCwhnGCwhnF/AKDKA2AKBIWEHIwKEKAqrDHI4KEHIp9EHIqUEHIxmEOYp9EYgxmEEQpmFEQoKFEQhmFEQhPGNAhPFRYg4GOggKHHQSIFBYghIAFQ="))
\ No newline at end of file
diff --git a/apps/astrocalc/waxing-crescent-icon.js b/apps/astrocalc/waxing-crescent-icon.js
new file mode 100644
index 000000000..d89525c88
--- /dev/null
+++ b/apps/astrocalc/waxing-crescent-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("rlcgJC/ABdwBRMD8ALJj+ABREB/wWJh/wBZN/4AKIg4iKn/4KBP/ERMfERMB/5FJj//NBP//hnJ/6LJ/45Jg45Kv45JCwI5Jn5zJPwI5JCwJQICwP/CxRQISoJQJSoLEICwRQICwJnICzJnIYYJ+JCzB+ICwKVJC34W/CxbOffgIWIfgXACxP8Cyv4CxWACyUDPpU/ShIWBPpIWBPpEHMxMAv5mJCwJPICwQKIYQI4IYQJPJCwI4ISgI4JSgIKICwI4Jn5xJSgLBIMwIhJg4hJMwIKJj4hJgJlJgE+BRMHBRIA+A"))
\ No newline at end of file
diff --git a/apps/astrocalc/waxing-gibbous-icon.js b/apps/astrocalc/waxing-gibbous-icon.js
new file mode 100644
index 000000000..90ccd6f37
--- /dev/null
+++ b/apps/astrocalc/waxing-gibbous-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("rlcgI1yj/4BREH/4LJ/4LJj4LB8AKGgYKB/+ABY1/BQP+BQ0PCwQuHBQX/4A4IEQ8BCwYiGn4iJJ4YiHJ4QAB+CIGAAZoFBQn8MxCLHBQg5FMwY5GMwg5GCwo5EMwhzGPog5FCwxQECwv/PpJQFSghQFCwzEECyJnECwxnDVYoWFBQpnECwx+ECzp+DCwyVEC34W/CyDOt4AKCg4KF/gWDv4WQ/AWKwAWVBQcDShMAn5mJCwx9DCwxmEgJmJgEfJ5IWGBQasGHAisFJ4gWGHAh+FHAiVGBQhnFHAp+EOIhnGYIZnGEIpQEEIxnEEIpQEEIxQDMoo5EQ4o5FFgyKDBRAiBBRAApA="))
\ No newline at end of file
diff --git a/apps/balltastic/ChangeLog b/apps/balltastic/ChangeLog
new file mode 100644
index 000000000..5a62086c2
--- /dev/null
+++ b/apps/balltastic/ChangeLog
@@ -0,0 +1 @@
+0.01: Initial version of Balltastic released! Happy!
diff --git a/apps/balltastic/app-icon.js b/apps/balltastic/app-icon.js
new file mode 100644
index 000000000..f25b6e067
--- /dev/null
+++ b/apps/balltastic/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwwkEogAIkUzmciBpIVIkYWBAAUyCx0hiIXFAAMkCxhUBC4fzDAYWLiAXFAAP//5KKoMRC4UTC4k/DAPzJJERiKcCC5H/GA4uBWwp6DC4YwHCwMBDI0SMAYwHoIWBiXxdIwYCMJCjBiM/C46VDC4M/GAkRgMf//ySAQAEgKrDC4lBgMCHIQXHSwxICIwIuBAAIXIGAYABiQXBkEBTYcgC473FkQXBiETTQZ4IgECC4cholCiJGDMAIXIWgIXCmMkC4JGDJBbEDC4UACwn/mAtGSYsxilCgIXFSAqDBkMRiIFBkcxiUiC4sxXowIBC4QGBkIXBiJ2EFwsDBIPyC4ILBgMRiUyiCmJgSCC+YXDgAXDR4YuEcAn/MAIXEmcgBoXyFwjIEMAQXFkIOCUgoXF+J3CC4cxBwR1IQQx3BkUzmUSBQKkFC5IuBkVDJAJeGRwLhHFwUkC4Mxl6lFC48gFwYXCmcTOwomBC4swYIMikU0C4UxkJ3FC40xFoIXCogXBmaxDC5MyCwUiogXDmIXTJASSBC4kRU4oXDkgXFmQwDNwIWEBoIXFJAYKBZggWFC4YWCC4g7BkIWBkYWBBYYXCkYXDJAYjDkQUEEYZGEGA4XIIwwwGDAQuOGAomCFo4uGGARoBE4ZOGFxAABBwgAICxAABCyxJBGJJFJJRgVNPggsMA="))
diff --git a/apps/balltastic/app.js b/apps/balltastic/app.js
new file mode 100644
index 000000000..6c1de940c
--- /dev/null
+++ b/apps/balltastic/app.js
@@ -0,0 +1,186 @@
+Bangle.setLCDBrightness(1);
+Bangle.setLCDMode("doublebuffered");
+
+let points = 0;
+let level = 1;
+let levelSpeedStart = 0.8;
+let nextLevelPoints = 20;
+let levelSpeedFactor = 0.2;
+let counterWidth = 10;
+let gWidth = g.getWidth() - counterWidth;
+let gHeight = g.getHeight();
+let counter = 160;
+let counterMax = 160;
+let ballDims = 20;
+let ballx = g.getWidth() / 2 - ballDims;
+let bally = g.getHeight() / 2 - ballDims;
+let dotx = g.getWidth() / 2;
+let doty = g.getWidth() / 2;
+let ballBuzzTime = 5;
+let ballSpeedFactor = 40;
+let redrawspeed = 5;
+let dotwidth = 5;
+let running = false;
+let drawInterval;
+let xBuzzed = false;
+let yBuzzed = false;
+
+let BALL = require("heatshrink").decompress(
+ atob(
+ "ikUyAROvkQ3v4405AIYHBGq9KpMhktz1/W7feAJAtBEZ9jhkhs0ZgkQ8lKxW+jAdB516627E4X8AIPWzelmolKlpJBjMFEYIpC4kQ0YBBqWKynTFYPe7gpE3ec6gnHkNFrXL7372u2E4WjhGCAIliqWrUIPeKoIpB7h9HoUoqWq999///FIJ3BhGDEIIBBgFBAoWCoUI3vY62aQIW7ymSJooLBEoIADwkQEYVhEoInEGIOjR4O1y/OrIrBUYdr198iH/74nF88cE4gpCA4MY8k59CzBAINrx2164nBtduufPWYIlF++/xkxNoMAAIJPBoSdB52a30ZkNGE4IvBoUpwkxLIOMyWEmAmE7+MqKbEsLLBH4P3zw1BAYJFBFIMY8sQ4cx44nB0tVHYITBEoO967lDgDDC1tVQ4QBD37xBjMmJ4I3BE4IxBPoOMuSrBHYL1BJYbrDvfPLoYBD889jMlEoMhkpJBwkRE4O+jB7B405LoJPEYYUx0xPG7/3vxvBmOnrXsdIOc6jxBE4JfBvfwHIafDFoMRgh3H99+zsUDIOMqWU2YlBAAO1/AnBToN76EhgpTBFYKPBGIIhBEovOrWliuc2YlBE4oABE4etu2UyVrpqJBMoKvBEIPnjvWze97ATBE4YPBEopRC64BC27nBzn0znTAIOlimtq21y4BCEoM1HYOMqIVBE44AB0tVCYIBEigVBE4U1GYIFBymywkwEoJzHABIRBMIIXBWoIDCqOEmOEiABCmIjPAA51BFoVSEoUwAIIZNA"
+ )
+);
+
+function reset() {
+ g.clear();
+ level = 1;
+ points = 0;
+ ballx = g.getWidth() / 2 - ballDims;
+ bally = g.getHeight() / 2 - ballDims;
+ counter = counterMax;
+ createRandomDot();
+ drawInterval = setInterval(play, redrawspeed);
+ running = true;
+}
+
+function collide() {
+ try {
+ Bangle.buzz(ballBuzzTime, 0.8);
+ } catch (e) {}
+}
+
+function createRandomDot() {
+ dotx = Math.floor(
+ Math.random() * Math.floor(gWidth - dotwidth / 2) + dotwidth / 2
+ );
+ doty = Math.floor(
+ Math.random() * Math.floor(gHeight - dotwidth / 2) + dotwidth / 2
+ );
+}
+
+function checkIfDotEaten() {
+ if (
+ ballx + ballDims > dotx &&
+ ballx <= dotx + dotwidth &&
+ bally + ballDims > doty &&
+ bally <= doty + dotwidth
+ ) {
+ collide();
+ createRandomDot();
+ counter = counterMax;
+ points++;
+
+ if (points % nextLevelPoints == 0) {
+ level++;
+ }
+ }
+}
+
+function drawLevelText() {
+ g.setColor("#26b6c7");
+ g.setFontAlign(0, 0);
+ g.setFont("4x6", 5);
+ g.drawString("Level " + level, 120, 80);
+}
+
+function draw() {
+ //bg
+ g.setColor("#71c6cf");
+ g.fillRect(0, 0, g.getWidth(), g.getHeight());
+
+ //counter
+ drawCounter();
+
+ //draw level
+ drawLevelText();
+
+ //dot
+ g.setColor("#ff0000");
+ g.fillCircle(dotx, doty, dotwidth);
+
+ //ball
+ g.drawImage(BALL, ballx, bally);
+
+ g.flip();
+}
+
+function drawCounter() {
+ g.setColor("#000000");
+ g.fillRect(g.getWidth() - counterWidth, 0, g.getWidth(), gHeight);
+
+ if(counter < 40 ) g.setColor("#fc0303");
+ else if (counter < 80 ) g.setColor("#fc9803");
+ else g.setColor("#0318fc");
+
+ g.fillRect(
+ g.getWidth() - counterWidth,
+ gHeight,
+ g.getWidth(),
+ gHeight - counter
+ );
+}
+
+function checkCollision() {
+ if (ballx < 0) {
+ ballx = 0;
+ if (!xBuzzed) collide();
+ xBuzzed = true;
+ } else if (ballx > gWidth - ballDims) {
+ ballx = gWidth - ballDims;
+ if (!xBuzzed) collide();
+ xBuzzed = true;
+ } else {
+ xBuzzed = false;
+ }
+
+ if (bally < 0) {
+ bally = 0;
+ if (!yBuzzed) collide();
+ yBuzzed = true;
+ } else if (bally > gHeight - ballDims) {
+ bally = gHeight - ballDims;
+ if (!yBuzzed) collide();
+ yBuzzed = true;
+ } else {
+ yBuzzed = false;
+ }
+}
+
+function count() {
+ counter -= levelSpeedStart + level * levelSpeedFactor;
+ if (counter <= 0) {
+ running = false;
+ clearInterval(drawInterval);
+ setTimeout(function(){ E.showMessage("Press Button 1\nto restart.", "Gameover!");},50);
+ }
+}
+
+function accel(values) {
+ ballx -= values.x * ballSpeedFactor;
+ bally -= values.y * ballSpeedFactor;
+}
+
+function play() {
+ if (running) {
+ accel(Bangle.getAccel());
+ checkCollision();
+ checkIfDotEaten();
+ count();
+ draw();
+ }
+}
+
+setTimeout(() => {
+ reset();
+ drawInterval = setInterval(play, redrawspeed);
+
+ setWatch(
+ () => {
+ if(!running) reset();
+ },
+ BTN1,
+ { repeat: true }
+ );
+
+ running = true;
+}, 10);
diff --git a/apps/balltastic/app.png b/apps/balltastic/app.png
new file mode 100644
index 000000000..0f95e056f
Binary files /dev/null and b/apps/balltastic/app.png differ
diff --git a/apps/gbridge/ChangeLog b/apps/gbridge/ChangeLog
index 28789ec04..0bcf94e25 100644
--- a/apps/gbridge/ChangeLog
+++ b/apps/gbridge/ChangeLog
@@ -2,3 +2,6 @@
0.02: Increase contrast (darker notification background, white text)
0.03: Gadgetbridge widget now shows connection state
0.04: Tweaks for variable size widget system
+0.05: Show incoming call notification
+ Optimize animation, limit title length
+0.06: Gadgetbridge App 'Connected' state is no longer toggleable
diff --git a/apps/gbridge/app.js b/apps/gbridge/app.js
index 45dc0e33d..d12f0f768 100644
--- a/apps/gbridge/app.js
+++ b/apps/gbridge/app.js
@@ -4,7 +4,7 @@ function gb(j) {
var mainmenu = {
"" : { "title" : "Gadgetbridge" },
- "Connected" : { value : NRF.getSecurityStatus().connected },
+ "Connected" : { value : NRF.getSecurityStatus().connected?"Yes":"No" },
"Find Phone" : function() { E.showMenu(findPhone); },
"Exit" : ()=> {load();},
};
diff --git a/apps/gbridge/widget.js b/apps/gbridge/widget.js
index a787d7e0b..3f9c7053f 100644
--- a/apps/gbridge/widget.js
+++ b/apps/gbridge/widget.js
@@ -1,125 +1,196 @@
-(function() {
- var musicState = "stop";
- var musicInfo = {"artist":"","album":"","track":""};
- var scrollPos = 0;
- function gb(j) {
- Bluetooth.println(JSON.stringify(j));
+(() => {
+
+ const state = {
+ music: "stop",
+
+ musicInfo: {
+ artist: "",
+ album: "",
+ track: ""
+ },
+
+ scrollPos: 0
+ };
+
+ function gbSend(message) {
+ Bluetooth.println(JSON.stringify(message));
}
- function show(size,render) {
+
+ function showNotification(size, render) {
var oldMode = Bangle.getLCDMode();
+
Bangle.setLCDMode("direct");
- g.setClipRect(0,240,239,319);
+ g.setClipRect(0, 240, 239, 319);
g.setColor("#222222");
- g.fillRect(1,241,238,318);
- render(320-size);
+ g.fillRect(1, 241, 238, 318);
+
+ render(320 - size);
+
g.setColor("#ffffff");
- g.fillRect(0,240,1,319);
- g.fillRect(238,240,239,319);
- g.fillRect(2,318,238,319);
+ g.fillRect(0, 240, 1, 319);
+ g.fillRect(238, 240, 239, 319);
+ g.fillRect(2, 318, 238, 319);
+
Bangle.setLCDPower(1); // light up
Bangle.setLCDMode(oldMode); // clears cliprect
+
function anim() {
- scrollPos-=2;
- if (scrollPos<-size) scrollPos=-size;
- Bangle.setLCDOffset(scrollPos);
- if (scrollPos>-size) setTimeout(anim,10);
- }
- anim();
- }
- function hide() {
- function anim() {
- scrollPos+=4;
- if (scrollPos>0) scrollPos=0;
- Bangle.setLCDOffset(scrollPos);
- if (scrollPos<0) setTimeout(anim,10);
+ state.scrollPos -= 2;
+ if (state.scrollPos < -size) {
+ state.scrollPos = -size;
+ }
+ Bangle.setLCDOffset(state.scrollPos);
+ if (state.scrollPos > -size) setTimeout(anim, 15);
}
anim();
}
- Bangle.on('touch',function() {
- if (scrollPos) hide();
- });
- Bangle.on('swipe',function(dir) {
- if (musicState=="play") {
- gb({t:"music",n:dir>0?"next":"previous"});
+ function hideNotification() {
+ function anim() {
+ state.scrollPos += 4;
+ if (state.scrollPos > 0) state.scrollPos = 0;
+ Bangle.setLCDOffset(state.scrollPos);
+ if (state.scrollPos < 0) setTimeout(anim, 10);
}
- });
- gb({t:"status",bat:E.getBattery()});
+ anim();
+ }
- global.GB = function(j) {
- switch (j.t) {
+ function handleNotificationEvent(event) {
+
+ // split text up at word boundaries
+ var txt = event.body.split("\n");
+ var MAXCHARS = 38;
+ for (var i = 0; i < txt.length; i++) {
+ txt[i] = txt[i].trim();
+ var l = txt[i];
+ if (l.length > MAXCHARS) {
+ var p = MAXCHARS;
+ while (p > MAXCHARS - 8 && !" \t-_".includes(l[p]))
+ p--;
+ if (p == MAXCHARS - 8) p = MAXCHARS;
+ txt[i] = l.substr(0, p);
+ txt.splice(i + 1, 0, l.substr(p));
+ }
+ }
+
+ showNotification(80, (y) => {
+
+ // TODO: icon based on src?
+ var x = 120;
+ g.setFontAlign(0, 0);
+ g.setFont("6x8", 1);
+ g.setColor("#40d040");
+ g.drawString(event.src, x, y + 7);
+
+ g.setColor("#ffffff");
+ g.setFont("6x8", 2);
+ if (event.title)
+ g.drawString(event.title.slice(0,17), x, y + 25);
+
+ g.setFont("6x8", 1);
+ g.setColor("#ffffff");
+ g.setFontAlign(-1, -1);
+ g.drawString(txt.join("\n"), 10, y + 40);
+ });
+
+ Bangle.buzz();
+ }
+
+ function handleMusicStateUpdate(event) {
+ state.music = event.state
+
+ if (state.music == "play") {
+ showNotification(40, (y) => {
+ g.setColor("#ffffff");
+ g.drawImage(require("heatshrink").decompress(atob("jEYwILI/EAv/8gP/ARcMgOAASN8h+A/kfwP8n4CD/E/gHgjg/HA=")), 8, y + 8);
+
+ g.setFontAlign(-1, -1);
+ var x = 40;
+ g.setFont("4x6", 2);
+ g.setColor("#ffffff");
+ g.drawString(state.musicInfo.artist, x, y + 8);
+
+ g.setFont("6x8", 1);
+ g.setColor("#ffffff");
+ g.drawString(state.musicInfo.track, x, y + 22);
+ });
+ }
+
+ if (state.music == "pause") {
+ hideNotification();
+ }
+ }
+
+ function handleCallEvent(event) {
+
+ if (event.cmd == "accept") {
+ showNotification(40, (y) => {
+ g.setColor("#ffffff");
+ g.drawImage(require("heatshrink").decompress(atob("jEYwIMJj4CCwACJh4CCCIMOAQMGAQMHAQMDAQMBCIMB4PwgHz/EAn4CBj4CBg4CBgACCAAw=")), 8, y + 8);
+
+ g.setFontAlign(-1, -1);
+ var x = 40;
+ g.setFont("4x6", 2);
+ g.setColor("#ffffff");
+ g.drawString(event.name, x, y + 8);
+
+ g.setFont("6x8", 1);
+ g.setColor("#ffffff");
+ g.drawString(event.number, x, y + 22);
+ });
+
+ Bangle.buzz();
+ }
+ }
+
+ global.GB = (event) => {
+ switch (event.t) {
case "notify":
- show(80,function(y) {
- // TODO: icon based on src?
- var x = 120;
- g.setFontAlign(0,0);
- g.setFont("6x8",1);
- g.setColor("#40d040");
- g.drawString(j.src,x,y+7);
- g.setColor("#ffffff");
- g.setFont("6x8",2);
- g.drawString(j.title,x,y+25);
- g.setFont("6x8",1);
- g.setColor("#ffffff");
- // split text up a word boundaries
- var txt = j.body.split("\n");
- var MAXCHARS = 38;
- for (var i=0;iMAXCHARS) {
- var p = MAXCHARS;
- while (p>MAXCHARS-8 && !" \t-_".includes(l[p]))
- p--;
- if (p==MAXCHARS-8) p=MAXCHARS;
- txt[i] = l.substr(0,p);
- txt.splice(i+1,0,l.substr(p));
- }
- }
- g.setFontAlign(-1,-1);
- g.drawString(txt.join("\n"),10,y+40);
- Bangle.buzz();
- });
- break;
+ handleNotificationEvent(event);
+ break;
case "musicinfo":
- musicInfo = j;
+ state.musicInfo = event;
break;
case "musicstate":
- musicState = j.state;
- if (musicState=="play")
- show(40,function(y) {
- g.setColor("#ffffff");
- g.drawImage( require("heatshrink").decompress(atob("jEYwILI/EAv/8gP/ARcMgOAASN8h+A/kfwP8n4CD/E/gHgjg/HA=")),8,y+8);
- g.setFontAlign(-1,-1);
- g.setFont("6x8",1);
- var x = 40;
- g.setFont("4x6",2);
- g.setColor("#ffffff");
- g.drawString(musicInfo.artist,x,y+8);
- g.setFont("6x8",1);
- g.setColor("#ffffff");
- g.drawString(musicInfo.track,x,y+22);
- });
- if (musicState=="pause")
- hide();
- break;
+ handleMusicStateUpdate(event);
+ break;
+ case "call":
+ handleCallEvent(event);
+ break;
}
};
-function draw() {
- g.setColor(-1);
- if (NRF.getSecurityStatus().connected)
- g.drawImage(require("heatshrink").decompress(atob("i0WwgHExAABCIwJCBYwJEBYkIBQ2ACgvzCwoECx/z/AKDD4WD+YLBEIYKCx//+cvnAKCBwU/mc4/8/HYv//Ev+Y4EEAePn43DBQkzn4rCEIoABBIwKHO4cjmczK42I6mqlqEEBQeIBQaDED4IgDUhi6KaBbmIA==")),this.x+1,this.y+1);
- else
- g.drawImage(require("heatshrink").decompress(atob("i0WwQFC1WgAgYFDAgIFClQFCwEK1W/AoIPB1f+CAMq1f7/WqwQPB/fq1Gq1/+/4dC/2/CAIaB/YbBAAO///qAoX/B4QbBDQQ7BDQQrBAAWoIIIACIIIVC0ECB4cACAZiBAoRtCAoIDBA")),this.x+1,this.y+1);
-}
-function changed() {
- WIDGETS["gbridgew"].draw();
- g.flip();// turns screen on
-}
-NRF.on('connected',changed);
-NRF.on('disconnected',changed);
+ // Touch control
+ Bangle.on("touch", () => {
+ if (state.scrollPos) {
+ hideNotification();
+ }
+ });
-WIDGETS["gbridgew"]={area:"tl",width:24,draw:draw};
+ Bangle.on("swipe", (dir) => {
+ if (state.music == "play") {
+ const command = dir > 0 ? "next" : "previous"
+ gbSend({ t: "music", n: command });
+ }
+ });
+ function draw() {
+ g.setColor(-1);
+ if (NRF.getSecurityStatus().connected)
+ g.drawImage(require("heatshrink").decompress(atob("i0WwgHExAABCIwJCBYwJEBYkIBQ2ACgvzCwoECx/z/AKDD4WD+YLBEIYKCx//+cvnAKCBwU/mc4/8/HYv//Ev+Y4EEAePn43DBQkzn4rCEIoABBIwKHO4cjmczK42I6mqlqEEBQeIBQaDED4IgDUhi6KaBbmIA==")), this.x + 1, this.y + 1);
+ else
+ g.drawImage(require("heatshrink").decompress(atob("i0WwQFC1WgAgYFDAgIFClQFCwEK1W/AoIPB1f+CAMq1f7/WqwQPB/fq1Gq1/+/4dC/2/CAIaB/YbBAAO///qAoX/B4QbBDQQ7BDQQrBAAWoIIIACIIIVC0ECB4cACAZiBAoRtCAoIDBA")), this.x + 1, this.y + 1);
+ }
+
+ function changedConnectionState() {
+ WIDGETS["gbridgew"].draw();
+ g.flip(); // turns screen on
+ }
+
+ NRF.on("connected", changedConnectionState);
+ NRF.on("disconnected", changedConnectionState);
+
+ WIDGETS["gbridgew"] = { area: "tl", width: 24, draw: draw };
+
+ gbSend({ t: "status", bat: E.getBattery() });
})();
diff --git a/apps/heart/interface.html b/apps/heart/interface.html
index 177e2cdfb..4a21d2e27 100644
--- a/apps/heart/interface.html
+++ b/apps/heart/interface.html
@@ -11,17 +11,7 @@ var domRecords = document.getElementById("records");
function saveRecord(record,name) {
var csv = `${record.map(rec=>[rec.time, rec.bpm, rec.confidence].join(",")).join("\n")}`;
- var a = document.createElement("a"),
- file = new Blob([csv], {type: "Comma-separated value file"});
- var url = URL.createObjectURL(file);
- a.href = url;
- a.download = name+".csv";
- document.body.appendChild(a);
- a.click();
- setTimeout(function() {
- document.body.removeChild(a);
- window.URL.revokeObjectURL(url);
- }, 0);
+ Util.saveCSV(name, csv);
}
diff --git a/apps/locale/locale.html b/apps/locale/locale.html
index 5d7882e00..5cb4b4598 100644
--- a/apps/locale/locale.html
+++ b/apps/locale/locale.html
@@ -56,7 +56,14 @@ exports = { name : "en_GB", currencySym:"£",
});
var languageSelector = document.getElementById("languages");
- languageSelector.innerHTML = Object.keys(locales).map(l=>``).join("\n");
+ languageSelector.innerHTML = Object.keys(locales).map(l=>{
+ var localeParts = l.split("_"); // en_GB -> ["en","GB"]
+ var icon = "";
+ // If we have a 2 char ISO country code, use it to get the unicode flag
+ if (localeParts[1] && localeParts[1].length==2)
+ icon = localeParts[1].toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0)+127397) )+" ";
+ return ``
+ }).join("\n");
document.getElementById("upload").addEventListener("click", function() {
diff --git a/apps/locale/locales.js b/apps/locale/locales.js
index 42a2225e4..7f6fbaef9 100644
--- a/apps/locale/locales.js
+++ b/apps/locale/locales.js
@@ -370,4 +370,21 @@ var locales = {
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: "", 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" }},
};
diff --git a/apps/marioclock/ChangeLog b/apps/marioclock/ChangeLog
index 4334ad92c..74db9bc18 100644
--- a/apps/marioclock/ChangeLog
+++ b/apps/marioclock/ChangeLog
@@ -2,3 +2,4 @@
0.02: Fix day of the week and add padding
0.03: use short date format from locale, take timeout from settings
0.04: modify date to display to be more at the original idea but still localized
+0.05: use 12/24 hour clock from settings
diff --git a/apps/marioclock/marioclock-app.js b/apps/marioclock/marioclock-app.js
index ecbaba38a..2eeb21c97 100644
--- a/apps/marioclock/marioclock-app.js
+++ b/apps/marioclock/marioclock-app.js
@@ -1,14 +1,15 @@
/**********************************
- BangleJS MARIO CLOCK V0.1.0
+ BangleJS MARIO CLOCK
+ Based on Espruino Mario Clock V3 https://github.com/paulcockrell/espruino-mario-clock
+ Converting images to 1bit BMP: Image > Mode > Indexed and tick the "Use black and white (1-bit) palette", Then export as BMP.
+ Online Image convertor: https://www.espruino.com/Image+Converter
**********************************/
-var locale = require("locale");
+const locale = require("locale");
const storage = require('Storage');
-const settings = (storage.readJSON('setting.json',1)||{});
-const timeout = settings.timeout||10;
+const settings = (storage.readJSON('setting.json', 1) || {});
+const timeout = settings.timeout || 10;
+const is12Hour = settings["12hour"] || false;
// Screen dimensions
let W, H;
@@ -273,7 +274,8 @@ function drawTime() {
drawBrick(42, 25);
const t = new Date();
- const hours = ("0" + t.getHours()).substr(-2);
+ const h = t.getHours();
+ const hours = ("0" + ((is12Hour && h > 12) ? h - 12 : h)).substr(-2);
const mins = ("0" + t.getMinutes()).substr(-2);
g.setFont("6x8");
@@ -374,8 +376,9 @@ function init() {
Bangle.setLCDPower(true);
}
});
+
+ startTimers();
}
// Initialise!
init();
-startTimers();
diff --git a/apps/moonphase/ChangeLog b/apps/moonphase/ChangeLog
index 5560f00bc..baa668c3c 100644
--- a/apps/moonphase/ChangeLog
+++ b/apps/moonphase/ChangeLog
@@ -1 +1,2 @@
0.01: New App!
+0.02: Added GPS to obtain coordinates, added buttons
\ No newline at end of file
diff --git a/apps/moonphase/app.js b/apps/moonphase/app.js
index ecd4be05d..480a0e144 100644
--- a/apps/moonphase/app.js
+++ b/apps/moonphase/app.js
@@ -1,218 +1,215 @@
//Icons from https://icons8.com
//Sun and Moon calculations from https://github.com/mourner/suncalc and https://gist.github.com/endel/dfe6bb2fbe679781948c
+//varibales
+const storage = require('Storage');
+let coords;
+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;
+
+var SunCalc = {};
+
//pictures
function getImg(i) {
- 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==",
- "FirstQuarterNorth" : "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==",
- "FirstQuarterSouth" : "AD8AAH/4AH+PgD/g8B/4Dg/+AcP/gDH/4A5/+AGf/gBv/4AP/+AD//gA//4AP/+AD//gA3/4AZ/+AGf/gDj/4Aw/+AcH/gOA/4PAH+PgAf/gAA/AAA==",
- "WaxingGibbousNorth" : "AD8AAH/4AH3/gDz/8Bw//g4f/8MH//HB//5g//+YP//sD///A///wP//8D///A///wP//2D//5g//+cH//jB//w4f/8HD/+A8//AH3/gAf/gAA/AAA==",
- "WaxingGibbousSouth" : "AD8AAH/4AH/vgD/88B//Dg//4cP/+DH//g5//8Gf//Bv//wP//8D///A///wP//8D///A3//wZ//8Gf/+Dj//gw//4cH/8OA//PAH/vgAf/gAA/AAA==",
- "FullMoon" : "AD8AAH/4AH//gD//8B///g///8P///H///5///+f///v/////////////////////////3///5///+f///j///w///8H//+A///AH//gAf/gAA/AAA==",
- "WaningGibbousNorth" : "AD8AAH/4AH/vgD/88B//Dg//4cP/+DH//g5//8Gf//Bv//wP//8D///A///wP//8D///A3//wZ//8Gf/+Dj//gw//4cH/8OA//PAH/vgAf/gAA/AAA==",
- "WaningGibbousSouth" : "AD8AAH/4AH3/gDz/8Bw//g4f/8MH//HB//5g//+YP//sD///A///wP//8D///A///wP//2D//5g//+cH//jB//w4f/8HD/+A8//AH3/gAf/gAA/AAA==",
- "LastQuarterNorth" : "AD8AAH/4AH+PgD/g8B/4Dg/+AcP/gDH/4A5/+AGf/gBv/4AP/+AD//gA//4AP/+AD//gA3/4AZ/+AGf/gDj/4Aw/+AcH/gOA/4PAH+PgAf/gAA/AAA==",
- "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]))
- };
+ 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==",
+ "FirstQuarterNorth" : "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==",
+ "FirstQuarterSouth" : "AD8AAH/4AH+PgD/g8B/4Dg/+AcP/gDH/4A5/+AGf/gBv/4AP/+AD//gA//4AP/+AD//gA3/4AZ/+AGf/gDj/4Aw/+AcH/gOA/4PAH+PgAf/gAA/AAA==",
+ "WaxingGibbousNorth" : "AD8AAH/4AH3/gDz/8Bw//g4f/8MH//HB//5g//+YP//sD///A///wP//8D///A///wP//2D//5g//+cH//jB//w4f/8HD/+A8//AH3/gAf/gAA/AAA==",
+ "WaxingGibbousSouth" : "AD8AAH/4AH/vgD/88B//Dg//4cP/+DH//g5//8Gf//Bv//wP//8D///A///wP//8D///A3//wZ//8Gf/+Dj//gw//4cH/8OA//PAH/vgAf/gAA/AAA==",
+ "FullMoon" : "AD8AAH/4AH//gD//8B///g///8P///H///5///+f///v/////////////////////////3///5///+f///j///w///8H//+A///AH//gAf/gAA/AAA==",
+ "WaningGibbousNorth" : "AD8AAH/4AH/vgD/88B//Dg//4cP/+DH//g5//8Gf//Bv//wP//8D///A///wP//8D///A3//wZ//8Gf/+Dj//gw//4cH/8OA//PAH/vgAf/gAA/AAA==",
+ "WaningGibbousSouth" : "AD8AAH/4AH3/gDz/8Bw//g4f/8MH//HB//5g//+YP//sD///A///wP//8D///A///wP//2D//5g//+cH//jB//w4f/8HD/+A8//AH3/gAf/gAA/AAA==",
+ "LastQuarterNorth" : "AD8AAH/4AH+PgD/g8B/4Dg/+AcP/gDH/4A5/+AGf/gBv/4AP/+AD//gA//4AP/+AD//gA3/4AZ/+AGf/gDj/4Aw/+AcH/gOA/4PAH+PgAf/gAA/AAA==",
+ "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]))
+ };
}
-
- //coordinates (will get from GPS later on real device)
- var lat = 52.96236,
- lon = 7.62571;
-
- 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;
-
- // sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas
- // date/time constants and conversions
- var dayMs = 1000 * 60 * 60 * 24,
- J1970 = 2440588,
- J2000 = 2451545;
-
- function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
- function fromJulian(j) { return new Date((j + 0.5 - J1970) * dayMs); }
- function toDays(date) { return toJulian(date) - J2000; }
-
- // general calculations for position
- 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 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 astroRefraction(h) {
- if (h < 0) // the following formula works for positive altitudes only.
- h = 0; // if h = -0.08901179 a div/0 would occur.
-
- // formula 16.4 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
- // 1.02 / tan(h + 10.26 / (h + 5.10)) h in degrees, result in arc minutes -> converted to rad:
- return 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179));
- }
-
- // general sun calculations
- 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
-
- 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 SunCalc = {};
-
- // adds a custom time to the times config
- SunCalc.addTime = function (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
-
- 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
- };
- };
-
- // 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) {
+// sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas
+// date/time constants and conversions
+function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
+function fromJulian(j) { return new Date((j + 0.5 - J1970) * dayMs); }
+function toDays(date) { return toJulian(date) - J2000; }
+
+// general calculations for position
+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 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 astroRefraction(h) {
+ if (h < 0) // the following formula works for positive altitudes only.
+ h = 0; // if h = -0.08901179 a div/0 would occur.
+
+ // formula 16.4 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
+ // 1.02 / tan(h + 10.26 / (h + 5.10)) h in degrees, result in arc minutes -> converted to rad:
+ return 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179));
+}
+
+// general sun calculations
+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
+
+ return M + C + P + PI;
+}
+
+function sunCoords(d) {
+ 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]);
+};
+
+// 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
+
+ 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
+ };
+};
+
+// 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
- //print ({phase: b, name: Moon.phases[b]});
- return {phase: b, name: Moon.phases[b]};
+ 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);
+}
+
+// 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;
+
+ // 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;
}
- };
- return (Moon.phase(year, month, day));
- };
-
- 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
-
- 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;
-
- // 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;
- }
- 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 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());
@@ -222,9 +219,9 @@ function getImg(i) {
var yyyy = date.getFullYear();
var phase = SunCalc.getMoonIllumination(date);
return dd + "." + mm + "." + yyyy + ": "+ phase.name;
- }
-
- function getMPhaseSim (offset) {
+}
+
+function getMPhaseSim (offset) {
var date = new Date();
date.setDate(date.getDate() + offset);
var dd = String(date.getDate());
@@ -234,63 +231,123 @@ function getImg(i) {
var yyyy = date.getFullYear();
var phase = SunCalc.getMoonIllumination(date);
return phase.name;
- }
-
- function drawMoonPhase(offset, x, y){
- if (lat >= 0 && 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);}
- if (getMPhaseSim(offset) == "waxing-gibbous") {g.drawImage(getImg("WaxingGibbousNorth"), x, y);}
- if (getMPhaseSim(offset) == "full") {g.drawImage(getImg("FullMoon"), 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);}
- }
+}
+
+function drawMoonPhase(offset, x, y){
+ 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);}
+ if (getMPhaseSim(offset) == "waxing-gibbous") {g.drawImage(getImg("WaxingGibbousNorth"), x, y);}
+ if (getMPhaseSim(offset) == "full") {g.drawImage(getImg("FullMoon"), x, y);}
+ if (getMPhaseSim(offset) == "waning-gibbous") {g.drawImage(getImg("WaningGibbousNorth"), x, y);}
+ if (getMPhaseSim(offset) == "last-quarter") {g.drawImage(getImg("LastQuarterNorth"), x, y);}
+ if (getMPhaseSim(offset) == "waning-crescent") {g.drawImage(getImg("WaningCrescentNorth"), x, y);}
+}
else { //Southern hemisphere
- if (getMPhaseSim(offset) == "new") {g.drawImage(getImg("NewMoon"), x, y);}
- if (getMPhaseSim(offset) == "waxing-crescent") {g.drawImage(getImg("WaxingCrescentSouth"), x, y);}
- if (getMPhaseSim(offset) == "first-quarter") {g.drawImage(getImg("FirstQuarterSouth"), x, y);}
- if (getMPhaseSim(offset) == "waxing-gibbous") {g.drawImage(getImg("WaxingGibbousSouth"), x, y);}
- if (getMPhaseSim(offset) == "full") {g.drawImage(getImg("FullMoon"), 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);}
+ 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);}
+ if (getMPhaseSim(offset) == "waxing-gibbous") {g.drawImage(getImg("WaxingGibbousSouth"), x, y);}
+ if (getMPhaseSim(offset) == "full") {g.drawImage(getImg("FullMoon"), 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) {
+}
+
+function drawMoon(offset, x, y) {
g.setFont("6x8");
g.clear();
- g.drawString("Key1: increase day, Key3:decrease day",10,10);
- g.drawString(getMPhaseComp(offset),x,y-10);
- drawMoonPhase(offset, x, y);
+ 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+2),x,y+40);
- drawMoonPhase(offset+2, x, y+50);
+ g.drawString(getMPhaseComp(offset+2),x,y+70);
+ drawMoonPhase(offset+2, x+35, y+80);
- g.drawString(getMPhaseComp(offset+4),x,y+90);
- drawMoonPhase(offset+4, x, y+100);
+ g.drawString(getMPhaseComp(offset+4),x,y+110);
+ drawMoonPhase(offset+4, x+35, y+120);
- g.drawString(getMPhaseComp(offset+6),x,y+140);
- drawMoonPhase(offset+6, x, y+150);
- }
-
- function start() {
+ 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);
+}
+
+//set coordinates to default (city where I live)
+function resetCoords() {
+ coords = {
+ lat : 52.96236,
+ lon : 7.62571,
+ };
+ updateCoords();
+}
+
+function getGpsFix() {
+ 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);
+ }
+ });
+}
+
+function start() {
var x = 10;
- var y = 40;
+ 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() {
+ setWatch(function() { //BTN1
offsetMoon++; //jump to next day
drawMoon(offsetMoon, x, y); //offset, x, y
}, BTN1, {edge:"rising", debounce:50, repeat:true});
- setWatch(function() {
+
+ 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});
- }
-
- start();
\ No newline at end of file
+
+ 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});
+}
+
+start();
\ No newline at end of file
diff --git a/apps/rpgdice/ChangeLog b/apps/rpgdice/ChangeLog
new file mode 100755
index 000000000..7b83706bf
--- /dev/null
+++ b/apps/rpgdice/ChangeLog
@@ -0,0 +1 @@
+0.01: First release
diff --git a/apps/rpgdice/app-icon.js b/apps/rpgdice/app-icon.js
new file mode 100755
index 000000000..d6fd1fda5
--- /dev/null
+++ b/apps/rpgdice/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwwgMJgMQgMZzOREaERiERzIACiIVOAIIUCz///ORgIXNIQIAC/4ABJJYsBCogYEAYMQiAWGLAoAJJI8JLAYoCAAgJBJIIwGBohxBJI4YBJIwOFC4w5EC4hdOzIgCyLFDC45hHAAZJDgJAKMQwyBSYSOBxIXGPRTdChOfxChHbpRhBC4P5GAgAOgEZFAKjIBAz1EC5YYJxAvBJ4IXQzGIxEQB4RbPCoOIwEAOKAsCC4QvCFiAXDdwwsMC5eebogVGAALWBC42f/AWLC4zwCUgIEBCxK+DE4bsFC5+f/IrBC4RzHXwkZzATEDgP/RZAXFz5ECf4oXMCYKICC6hABMAQXOgAXBLgLrHRxZfCC6sBCo4XLLwIXBbAgXRMIQAGRxgwChIXVgEQIYimOGAZ6CSgOJC6CrCC4TZBC6IwCC4QWQPQYXKOggAFPQOfC5AWKPQgXGCpR6FOwoWOPQQXDIZYwHC4QVRAAQXBBxgA="))
\ No newline at end of file
diff --git a/apps/rpgdice/app.js b/apps/rpgdice/app.js
new file mode 100755
index 000000000..2007d6ab0
--- /dev/null
+++ b/apps/rpgdice/app.js
@@ -0,0 +1,86 @@
+const dice = [4, 6, 8, 10, 12, 20, 100];
+const nFlips = 20;
+const delay = 500;
+
+let dieIndex = 1;
+let face = 0;
+let rolling = false;
+
+let bgColor;
+let fgColor;
+
+function getDie() {
+ return dice[dieIndex];
+}
+
+function setColors(lastBounce) {
+ if (lastBounce) {
+ bgColor = 0xFFFF;
+ fgColor = 0x0000;
+ } else {
+ bgColor = 0x0000
+ fgColor = 0xFFFF;
+ }
+}
+
+function flipFace() {
+ while(true) {
+ let newFace = Math.floor(Math.random() * getDie()) + 1;
+ if (newFace !== face) {
+ face = newFace;
+ break;
+ }
+ }
+}
+
+function draw() {
+ g.setColor(bgColor);
+ g.fillRect(0, 0, g.getWidth(), g.getHeight());
+ g.setColor(fgColor);
+ g.setFontAlign(0, 0);
+ g.setFontVector(40);
+ g.drawString('d' + getDie(), 180, 30);
+ g.setFontVector(100);
+ g.drawString(face, 120, 120);
+}
+
+function roll(bounces) {
+ flipFace();
+ setColors(bounces === 0);
+ draw();
+ if (bounces > 0) {
+ setTimeout(() => roll(bounces - 1), delay / bounces);
+ } else {
+ rolling = false;
+ }
+}
+
+function startRolling() {
+ if (rolling) return;
+ rolling = true;
+ roll(nFlips);
+}
+
+function changeDie() {
+ if (rolling) return;
+ dieIndex = (dieIndex + 1) % dice.length;
+ draw();
+}
+
+Bangle.on('lcdPower',function(on) {
+ if (on) {
+ startRolling();
+ }
+});
+
+g.clear();
+Bangle.loadWidgets();
+Bangle.drawWidgets();
+startRolling();
+
+// Top button rolls the die, bottom button changes it
+setWatch(startRolling, BTN1, {repeat:true});
+setWatch(changeDie, BTN3, {repeat:true});
+
+// Show launcher when middle button pressed
+setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
diff --git a/apps/rpgdice/rpgdice.png b/apps/rpgdice/rpgdice.png
new file mode 100755
index 000000000..d14b9c836
Binary files /dev/null and b/apps/rpgdice/rpgdice.png differ
diff --git a/apps/swatch/ChangeLog b/apps/swatch/ChangeLog
index 86a782585..3246eeced 100644
--- a/apps/swatch/ChangeLog
+++ b/apps/swatch/ChangeLog
@@ -3,3 +3,5 @@
Lap log now scrolls into 2nd column after 18th entry, able to display 36 entries before going off screen
0.03: Added ability to save Lap log as a date named JSON file into memory
Fixed bug from 0.01 where BN1 (reset) could clear the lap log when timer is running
+0.04: Changed save file filename, add interface.html to allow laps to be loaded
+0.05: Added widgets
diff --git a/apps/swatch/interface.html b/apps/swatch/interface.html
new file mode 100644
index 000000000..928c5fe39
--- /dev/null
+++ b/apps/swatch/interface.html
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/apps/swatch/stopwatch.js b/apps/swatch/stopwatch.js
index d4136d8ed..6f8ad9e34 100644
--- a/apps/swatch/stopwatch.js
+++ b/apps/swatch/stopwatch.js
@@ -4,7 +4,6 @@ var started = false;
var timeY = 60;
var hsXPos = 0;
var lapTimes = [];
-var saveTimes = [];
var displayInterval;
function timeToText(t) {
@@ -14,24 +13,26 @@ function timeToText(t) {
return mins+":"+("0"+secs).substr(-2)+"."+("0"+hs).substr(-2);
}
function updateLabels() {
- g.clear();
+ g.reset(1);
+ g.clearRect(0,23,g.getWidth()-1,g.getHeight()-24);
g.setFont("6x8",2);
g.setFontAlign(0,0,3);
g.drawString(started?"STOP":"GO",230,120);
- if (!started) g.drawString("RESET",230,190);
+ if (!started) g.drawString("RESET",230,180);
g.drawString(started?"LAP":"SAVE",230,50);
g.setFont("6x8",1);
g.setFontAlign(-1,-1);
for (var i in lapTimes) {
- if (i<18)
+ if (i<16)
{g.drawString(lapTimes.length-i+": "+timeToText(lapTimes[i]),35,timeY + 30 + i*8);}
- else
- {g.drawString(lapTimes.length-i+": "+timeToText(lapTimes[i]),125,timeY + 30 + (i-18)*8);}
+ else if (i<32)
+ {g.drawString(lapTimes.length-i+": "+timeToText(lapTimes[i]),125,timeY + 30 + (i-16)*8);}
}
drawsecs();
}
function drawsecs() {
var t = tCurrent-tStart;
+ g.reset(1);
g.setFont("Vector",48);
g.setFontAlign(0,0);
var secs = Math.floor(t/1000)%60;
@@ -51,10 +52,8 @@ function drawms() {
g.clearRect(hsXPos,timeY,220,timeY+20);
g.drawString("."+("0"+hs).substr(-2),hsXPos,timeY+10);
}
-function saveconvert() {
- for (var v in lapTimes){
- saveTimes[v]=v+1+"-"+timeToText(lapTimes[(lapTimes.length-1)-v]);
- }
+function getLapTimesArray() {
+ return lapTimes.map(timeToText).reverse();
}
setWatch(function() { // Start/stop
@@ -80,16 +79,21 @@ setWatch(function() { // Start/stop
}, BTN2, {repeat:true});
setWatch(function() { // Lap
Bangle.beep();
- if (started) tCurrent = Date.now();
- lapTimes.unshift(tCurrent-tStart);
- tStart = tCurrent;
- if (!started)
- {
- var timenow= Date();
- saveconvert();
- require("Storage").writeJSON("StpWch-"+timenow.toString(), saveTimes);
+ if (started) {
+ tCurrent = Date.now();
+ lapTimes.unshift(tCurrent-tStart);
+ }
+ tStart = tCurrent;
+ if (!started) { // save
+ var timenow= Date();
+ var filename = "swatch-"+(new Date()).toISOString().substr(0,16).replace("T","_")+".json";
+ // this maxes out the 28 char maximum
+ require("Storage").writeJSON(filename, getLapTimesArray());
+ E.showMessage("Laps Saved","Stopwatch");
+ setTimeout(updateLabels, 1000);
+ } else {
+ updateLabels();
}
- updateLabels();
}, BTN1, {repeat:true});
setWatch(function() { // Reset
if (!started) {
@@ -101,3 +105,5 @@ setWatch(function() { // Reset
}, BTN3, {repeat:true});
updateLabels();
+Bangle.loadWidgets();
+Bangle.drawWidgets();
diff --git a/apps/toucher/ChangeLog b/apps/toucher/ChangeLog
new file mode 100644
index 000000000..bd3d5d225
--- /dev/null
+++ b/apps/toucher/ChangeLog
@@ -0,0 +1,2 @@
+0.01: New App!
+0.02: Add swipe support and doucle tap to run application
\ No newline at end of file
diff --git a/apps/toucher/app.js b/apps/toucher/app.js
new file mode 100644
index 000000000..2b80198c9
--- /dev/null
+++ b/apps/toucher/app.js
@@ -0,0 +1,130 @@
+g.clear();
+
+const Storage = require("Storage");
+
+function getApps(){
+ return 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;
+ });
+}
+
+const selected = 0;
+const apps = getApps();
+
+function prev(){
+ if (selected>=0) {
+ selected--;
+ }
+ drawMenu();
+}
+
+function next() {
+ if (selected+1 {
+ if(dir == 1) prev();
+ else next();
+});
\ No newline at end of file
diff --git a/apps/toucher/app.png b/apps/toucher/app.png
new file mode 100644
index 000000000..f1509dedb
Binary files /dev/null and b/apps/toucher/app.png differ
diff --git a/apps/widmp/ChangeLog b/apps/widmp/ChangeLog
new file mode 100644
index 000000000..5560f00bc
--- /dev/null
+++ b/apps/widmp/ChangeLog
@@ -0,0 +1 @@
+0.01: New App!
diff --git a/apps/widmp/widget.js b/apps/widmp/widget.js
new file mode 100644
index 000000000..be4c2bb39
--- /dev/null
+++ b/apps/widmp/widget.js
@@ -0,0 +1,33 @@
+/* jshint esversion: 6 */
+(() => {
+
+ 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);}
+ };
+
+ 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())]();
+ }
+
+ WIDGETS["widmoon"] = { area: "tr", width: 24, draw: draw };
+
+})();
diff --git a/apps/widmp/widget.png b/apps/widmp/widget.png
new file mode 100644
index 000000000..32803f474
Binary files /dev/null and b/apps/widmp/widget.png differ
diff --git a/browserconfig.xml b/browserconfig.xml
new file mode 100644
index 000000000..3b40787e9
--- /dev/null
+++ b/browserconfig.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+ #5755d9
+
+
+
diff --git a/favicon-16x16.png b/favicon-16x16.png
new file mode 100644
index 000000000..cb68aa50e
Binary files /dev/null and b/favicon-16x16.png differ
diff --git a/favicon-32x32.png b/favicon-32x32.png
new file mode 100644
index 000000000..cc7b68d98
Binary files /dev/null and b/favicon-32x32.png differ
diff --git a/favicon.ico b/favicon.ico
index 24ae65966..8b736ee82 100644
Binary files a/favicon.ico and b/favicon.ico differ
diff --git a/html_code.html b/html_code.html
new file mode 100644
index 000000000..d940fbd95
--- /dev/null
+++ b/html_code.html
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.html b/index.html
index efaf84a61..b3e78d848 100644
--- a/index.html
+++ b/index.html
@@ -6,6 +6,15 @@
+
+
+
+
+
+
+
+
+
Bangle.js App Loader