Merge branch 'master' into call-notifications
|
@ -0,0 +1,6 @@
|
||||||
|
App Loader ChangeLog
|
||||||
|
====================
|
||||||
|
|
||||||
|
Changed for individual apps are listed in `apps/appname/ChangeLog`
|
||||||
|
|
||||||
|
* `Remove All Apps` now doesn't perform a reset before erase - fixes inability to update firmware if settings are wrong
|
14
README.md
|
@ -3,7 +3,8 @@ Bangle.js App Loader (and Apps)
|
||||||
|
|
||||||
[](https://travis-ci.org/espruino/BangleApps)
|
[](https://travis-ci.org/espruino/BangleApps)
|
||||||
|
|
||||||
Try it live at [banglejs.com/apps](https://banglejs.com/apps)
|
* Try the **release version** at [banglejs.com/apps](https://banglejs.com/apps)
|
||||||
|
* Try the **development version** at [github.io](https://espruino.github.io/BangleApps/)
|
||||||
|
|
||||||
## How does it work?
|
## How does it work?
|
||||||
|
|
||||||
|
@ -14,6 +15,14 @@ it with the files it sees in the watch's storage.
|
||||||
* To upload an app, BangleAppLoader checks the files that are
|
* To upload an app, BangleAppLoader checks the files that are
|
||||||
listed in `apps.json`, loads them, and sends them over Web Bluetooth.
|
listed in `apps.json`, loads them, and sends them over Web Bluetooth.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Check out:
|
||||||
|
|
||||||
|
* [Building your first Bangle.js Application](https://www.espruino.com/Bangle.js+First+App)
|
||||||
|
* [Adding an app to the Bangle.js App Loader](https://www.espruino.com/Bangle.js+App+Loader)
|
||||||
|
* [Customising the App Loader](https://www.espruino.com/Bangle.js+App+Loader+Custom)
|
||||||
|
|
||||||
## What filenames are used
|
## What filenames are used
|
||||||
|
|
||||||
Filenames in storage are limited to 8 characters. To
|
Filenames in storage are limited to 8 characters. To
|
||||||
|
@ -21,8 +30,9 @@ easily distinguish between file types, we use the following:
|
||||||
|
|
||||||
* `stuff.info` is JSON that describes an app - this is auto-generated by the App Loader
|
* `stuff.info` is JSON that describes an app - this is auto-generated by the App Loader
|
||||||
* `stuff.img` is an image
|
* `stuff.img` is an image
|
||||||
* `stuff.app.js` is JS code
|
* `stuff.app.js` is JS code for applications
|
||||||
* `stuff.wid.js` is JS code for widgets
|
* `stuff.wid.js` is JS code for widgets
|
||||||
|
* `stuff.boot.js` is JS code that automatically gets run at boot time
|
||||||
* `stuff.json` is used for JSON settings for an app
|
* `stuff.json` is used for JSON settings for an app
|
||||||
|
|
||||||
## Developing your own app
|
## Developing your own app
|
||||||
|
|
238
apps.json
|
@ -2,7 +2,7 @@
|
||||||
{ "id": "boot",
|
{ "id": "boot",
|
||||||
"name": "Bootloader",
|
"name": "Bootloader",
|
||||||
"icon": "bootloader.png",
|
"icon": "bootloader.png",
|
||||||
"version":"0.11",
|
"version":"0.13",
|
||||||
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
|
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
|
||||||
"tags": "tool,system",
|
"tags": "tool,system",
|
||||||
"type":"bootloader",
|
"type":"bootloader",
|
||||||
|
@ -12,6 +12,31 @@
|
||||||
],
|
],
|
||||||
"sortorder" : -10
|
"sortorder" : -10
|
||||||
},
|
},
|
||||||
|
{ "id": "moonphase",
|
||||||
|
"name": "Moonphase",
|
||||||
|
"icon": "app.png",
|
||||||
|
"version":"0.02",
|
||||||
|
"description": "Shows current moon phase. Now with GPS function.",
|
||||||
|
"tags": "",
|
||||||
|
"allow_emulator":true,
|
||||||
|
"storage": [
|
||||||
|
{"name":"moonphase.app.js","url":"app.js"},
|
||||||
|
{"name":"moonphase.img","url":"app-icon.js","evaluate":true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "id": "daysl",
|
||||||
|
"name": "Days left",
|
||||||
|
"icon": "app.png",
|
||||||
|
"version":"0.02",
|
||||||
|
"description": "Shows you the days left until a certain date. Date can be set with a settings app and is written to a file.",
|
||||||
|
"tags": "",
|
||||||
|
"allow_emulator":false,
|
||||||
|
"storage": [
|
||||||
|
{"name":"daysl.app.js","url":"app.js"},
|
||||||
|
{"name":"daysl.img","url":"app-icon.js","evaluate":true},
|
||||||
|
{"name":"daysl.wid.js","url":"widget.js"}
|
||||||
|
]
|
||||||
|
},
|
||||||
{ "id": "launch",
|
{ "id": "launch",
|
||||||
"name": "Default Launcher",
|
"name": "Default Launcher",
|
||||||
"shortName":"Launcher",
|
"shortName":"Launcher",
|
||||||
|
@ -40,7 +65,7 @@
|
||||||
{ "id": "locale",
|
{ "id": "locale",
|
||||||
"name": "Languages",
|
"name": "Languages",
|
||||||
"icon": "locale.png",
|
"icon": "locale.png",
|
||||||
"version":"0.01",
|
"version":"0.05",
|
||||||
"description": "Translations for different countries",
|
"description": "Translations for different countries",
|
||||||
"tags": "tool,system,locale,translate",
|
"tags": "tool,system,locale,translate",
|
||||||
"type": "locale",
|
"type": "locale",
|
||||||
|
@ -106,11 +131,12 @@
|
||||||
"name": "Default Alarm",
|
"name": "Default Alarm",
|
||||||
"shortName":"Alarms",
|
"shortName":"Alarms",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"version":"0.04",
|
"version":"0.05",
|
||||||
"description": "Set and respond to alarms",
|
"description": "Set and respond to alarms",
|
||||||
"tags": "tool,alarm,widget",
|
"tags": "tool,alarm,widget",
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"alarm.app.js","url":"app.js"},
|
{"name":"alarm.app.js","url":"app.js"},
|
||||||
|
{"name":"alarm.boot.js","url":"boot.js"},
|
||||||
{"name":"alarm.js","url":"alarm.js"},
|
{"name":"alarm.js","url":"alarm.js"},
|
||||||
{"name":"alarm.json","content":"[]"},
|
{"name":"alarm.json","content":"[]"},
|
||||||
{"name":"alarm.img","url":"app-icon.js","evaluate":true},
|
{"name":"alarm.img","url":"app-icon.js","evaluate":true},
|
||||||
|
@ -133,7 +159,7 @@
|
||||||
{ "id": "aclock",
|
{ "id": "aclock",
|
||||||
"name": "Analog Clock",
|
"name": "Analog Clock",
|
||||||
"icon": "clock-analog.png",
|
"icon": "clock-analog.png",
|
||||||
"version":"0.02",
|
"version":"0.10",
|
||||||
"description": "An Analog Clock",
|
"description": "An Analog Clock",
|
||||||
"tags": "clock",
|
"tags": "clock",
|
||||||
"type":"clock",
|
"type":"clock",
|
||||||
|
@ -308,6 +334,17 @@
|
||||||
{"name":"widbat.wid.js","url":"widget.js"}
|
{"name":"widbat.wid.js","url":"widget.js"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{ "id": "widbatpc",
|
||||||
|
"name": "Battery Level Widget (with percentage)",
|
||||||
|
"icon": "widget.png",
|
||||||
|
"version":"0.06",
|
||||||
|
"description": "Show the current battery level and charging status in the top right of the clock, with charge percentage",
|
||||||
|
"tags": "widget,battery",
|
||||||
|
"type":"widget",
|
||||||
|
"storage": [
|
||||||
|
{"name":"widbatpc.wid.js","url":"widget.js"}
|
||||||
|
]
|
||||||
|
},
|
||||||
{ "id": "widbt",
|
{ "id": "widbt",
|
||||||
"name": "Bluetooth Widget",
|
"name": "Bluetooth Widget",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
|
@ -355,8 +392,8 @@
|
||||||
{ "id": "swatch",
|
{ "id": "swatch",
|
||||||
"name": "Stopwatch",
|
"name": "Stopwatch",
|
||||||
"icon": "stopwatch.png",
|
"icon": "stopwatch.png",
|
||||||
"version":"0.01",
|
"version":"0.03",
|
||||||
"description": "Simple stopwatch with Lap Time recording",
|
"description": "Simple stopwatch with Lap Time logging to a JSON file",
|
||||||
"tags": "health",
|
"tags": "health",
|
||||||
"allow_emulator":true,
|
"allow_emulator":true,
|
||||||
"storage": [
|
"storage": [
|
||||||
|
@ -508,6 +545,19 @@
|
||||||
{"name":"sclock.img","url":"clock-simple-icon.js","evaluate":true}
|
{"name":"sclock.img","url":"clock-simple-icon.js","evaluate":true}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{ "id": "dclock",
|
||||||
|
"name": "Dev Clock",
|
||||||
|
"icon": "clock-dev.png",
|
||||||
|
"version":"0.09",
|
||||||
|
"description": "A Digital Clock including timestamp (tst), beats(@), days in current month (dm) and days since new moon (l)",
|
||||||
|
"tags": "clock",
|
||||||
|
"type":"clock",
|
||||||
|
"allow_emulator":true,
|
||||||
|
"storage": [
|
||||||
|
{"name":"dclock.app.js","url":"clock-dev.js"},
|
||||||
|
{"name":"dclock.img","url":"clock-dev-icon.js","evaluate":true}
|
||||||
|
]
|
||||||
|
},
|
||||||
{ "id": "gesture",
|
{ "id": "gesture",
|
||||||
"name": "Gesture Test",
|
"name": "Gesture Test",
|
||||||
"icon": "gesture.png",
|
"icon": "gesture.png",
|
||||||
|
@ -611,7 +661,7 @@
|
||||||
{ "id": "miclock",
|
{ "id": "miclock",
|
||||||
"name": "Mixed Clock",
|
"name": "Mixed Clock",
|
||||||
"icon": "clock-mixed.png",
|
"icon": "clock-mixed.png",
|
||||||
"version":"0.02",
|
"version":"0.03",
|
||||||
"description": "A mix of analog and digital Clock",
|
"description": "A mix of analog and digital Clock",
|
||||||
"tags": "clock",
|
"tags": "clock",
|
||||||
"type":"clock",
|
"type":"clock",
|
||||||
|
@ -790,7 +840,7 @@
|
||||||
"id": "pipboy",
|
"id": "pipboy",
|
||||||
"name": "Pipboy",
|
"name": "Pipboy",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"version": "0.01",
|
"version": "0.02",
|
||||||
"description": "Pipboy themed clock",
|
"description": "Pipboy themed clock",
|
||||||
"tags": "clock",
|
"tags": "clock",
|
||||||
"type":"clock",
|
"type":"clock",
|
||||||
|
@ -823,5 +873,177 @@
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"widid.wid.js","url":"widget.js"}
|
{"name":"widid.wid.js","url":"widget.js"}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "grocery",
|
||||||
|
"name": "Grocery",
|
||||||
|
"icon": "grocery.png",
|
||||||
|
"version":"0.01",
|
||||||
|
"description": "Simple grocery list - Display a list of product and track if you already put them in your cart.",
|
||||||
|
"tags": "tool,outdoors",
|
||||||
|
"type": "app",
|
||||||
|
"custom":"grocery.html",
|
||||||
|
"storage": [
|
||||||
|
{"name":"grocery"},
|
||||||
|
{"name":"grocery.app.js"},
|
||||||
|
{"name":"grocery.img","url":"grocery-icon.js","evaluate":true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "id": "marioclock",
|
||||||
|
"name": "Mario Clock",
|
||||||
|
"icon": "marioclock.png",
|
||||||
|
"version":"0.05",
|
||||||
|
"description": "Animated Mario clock, jumps to change the time!",
|
||||||
|
"tags": "clock,mario,retro",
|
||||||
|
"type": "clock",
|
||||||
|
"allow_emulator":true,
|
||||||
|
"storage": [
|
||||||
|
{"name":"marioclock.app.js","url":"marioclock-app.js"},
|
||||||
|
{"name":"marioclock.img","url":"marioclock-icon.js","evaluate":true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "id": "cliock",
|
||||||
|
"name": "Commandline-Clock",
|
||||||
|
"shortName":"CLI-Clock",
|
||||||
|
"icon": "app.png",
|
||||||
|
"version":"0.07",
|
||||||
|
"description": "Simple CLI-Styled Clock",
|
||||||
|
"tags": "clock,cli,command,bash,shell",
|
||||||
|
"type":"clock",
|
||||||
|
"allow_emulator":true,
|
||||||
|
"storage": [
|
||||||
|
{"name":"cliock.app.js","url":"app.js"},
|
||||||
|
{"name":"cliock.img","url":"app-icon.js","evaluate":true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "id": "widver",
|
||||||
|
"name": "Firmware Version Widget",
|
||||||
|
"icon": "widget.png",
|
||||||
|
"version":"0.01",
|
||||||
|
"description": "Display the version of the installed firmware in the top widget section.",
|
||||||
|
"tags": "widget,tool,system",
|
||||||
|
"type":"widget",
|
||||||
|
"storage": [
|
||||||
|
{"name":"widver.wid.js","url":"widget.js"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "id": "barclock",
|
||||||
|
"name": "Bar Clock",
|
||||||
|
"icon": "clock-bar.png",
|
||||||
|
"version":"0.04",
|
||||||
|
"description": "A simple digital clock showing seconds as a bar",
|
||||||
|
"tags": "clock",
|
||||||
|
"type":"clock",
|
||||||
|
"allow_emulator":true,
|
||||||
|
"storage": [
|
||||||
|
{"name":"barclock.app.js","url":"clock-bar.js"},
|
||||||
|
{"name":"barclock.img","url":"clock-bar-icon.js","evaluate":true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "id": "widtbat",
|
||||||
|
"name": "Tiny Battery Widget",
|
||||||
|
"icon": "widget.png",
|
||||||
|
"version":"0.01",
|
||||||
|
"description": "Tiny blueish battery widget, vibs and changes level color when charging",
|
||||||
|
"tags": "widget,tool,system",
|
||||||
|
"type":"widget",
|
||||||
|
"storage": [
|
||||||
|
{"name":"widtbat.wid.js","url":"widget.js"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "id": "chrono",
|
||||||
|
"name": "Chrono",
|
||||||
|
"shortName":"Chrono",
|
||||||
|
"icon": "chrono.png",
|
||||||
|
"version":"0.01",
|
||||||
|
"description": "Single click BTN1 to add 5 minutes. Single click BTN2 to add 30 seconds. Single click BTN3 to add 5 seconds. Tap to pause or play to timer. Double click BTN1 to reset. When timer finishes the watch vibrates.",
|
||||||
|
"tags": "Tools",
|
||||||
|
"storage": [
|
||||||
|
{"name":"chrono.app.js","url":"chrono.js"},
|
||||||
|
{"name":"chrono.img","url":"chrono-icon.js","evaluate":true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "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",
|
||||||
|
"description": "Swipe your wrist over the watch face to start your personal Bangle.js hand wash timer for 35 sec. Start washing after the short buzz and stop after the long buzz.",
|
||||||
|
"tags": "widget,tool",
|
||||||
|
"type":"widget",
|
||||||
|
"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"}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1 +1,7 @@
|
||||||
0.02: Modified for use with new bootloader and firmware
|
0.02: Modified for use with new bootloader and firmware
|
||||||
|
0.03: add hour ticks, remove timers
|
||||||
|
0.04: add day-date display
|
||||||
|
0.07: make date and face bigger
|
||||||
|
0.08: make dots bigger and date more readable
|
||||||
|
0.09: center date, remove box around it, internal refactor to remove redundant code.
|
||||||
|
0.10: remove debug, refactor seconds to show elapsed secs each time app is displayed
|
||||||
|
|
|
@ -1,94 +1,146 @@
|
||||||
const p = Math.PI/2;
|
let g;
|
||||||
const PRad = Math.PI/180;
|
let Bangle;
|
||||||
|
|
||||||
let intervalRefMin = null;
|
// http://forum.espruino.com/conversations/345155/#comment15172813
|
||||||
let intervalRefSec = null;
|
const locale = require('locale');
|
||||||
|
const p = Math.PI / 2;
|
||||||
|
const pRad = Math.PI / 180;
|
||||||
|
const faceWidth = 100; // watch face radius
|
||||||
|
let timer = null;
|
||||||
|
let currentDate = new Date();
|
||||||
|
const centerPx = g.getWidth() / 2;
|
||||||
|
|
||||||
let minuteDate = new Date();
|
const seconds = (angle) => {
|
||||||
let secondDate = new Date();
|
const a = angle * pRad;
|
||||||
|
const x = centerPx + Math.sin(a) * faceWidth;
|
||||||
|
const y = centerPx - Math.cos(a) * faceWidth;
|
||||||
|
|
||||||
function seconds(angle, r) {
|
// if 15 degrees, make hour marker larger
|
||||||
const a = angle*PRad;
|
const radius = (angle % 15) ? 2 : 4;
|
||||||
const x = 120+Math.sin(a)*r;
|
g.fillCircle(x, y, radius);
|
||||||
const y = 120-Math.cos(a)*r;
|
};
|
||||||
g.fillRect(x-1,y-1,x+1,y+1);
|
|
||||||
}
|
const hand = (angle, r1, r2) => {
|
||||||
function hand(angle, r1,r2) {
|
const a = angle * pRad;
|
||||||
const a = angle*PRad;
|
|
||||||
const r3 = 3;
|
const r3 = 3;
|
||||||
g.fillPoly([
|
|
||||||
120+Math.sin(a)*r1,
|
|
||||||
120-Math.cos(a)*r1,
|
|
||||||
120+Math.sin(a+p)*r3,
|
|
||||||
120-Math.cos(a+p)*r3,
|
|
||||||
120+Math.sin(a)*r2,
|
|
||||||
120-Math.cos(a)*r2,
|
|
||||||
120+Math.sin(a-p)*r3,
|
|
||||||
120-Math.cos(a-p)*r3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawAll() {
|
g.fillPoly([
|
||||||
|
Math.round(centerPx + Math.sin(a) * r1),
|
||||||
|
Math.round(centerPx - Math.cos(a) * r1),
|
||||||
|
Math.round(centerPx + Math.sin(a + p) * r3),
|
||||||
|
Math.round(centerPx - Math.cos(a + p) * r3),
|
||||||
|
Math.round(centerPx + Math.sin(a) * r2),
|
||||||
|
Math.round(centerPx - Math.cos(a) * r2),
|
||||||
|
Math.round(centerPx + Math.sin(a - p) * r3),
|
||||||
|
Math.round(centerPx - Math.cos(a - p) * r3)
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawAll = () => {
|
||||||
g.clear();
|
g.clear();
|
||||||
secondDate = minuteDate = new Date();
|
currentDate = new Date();
|
||||||
// draw hands first
|
// draw hands first
|
||||||
onMinute();
|
onMinute();
|
||||||
// draw seconds
|
// draw seconds
|
||||||
g.setColor(0,0,0.6);
|
const currentSec = currentDate.getSeconds();
|
||||||
for (let i=0;i<60;i++)
|
// draw all secs
|
||||||
seconds(360*i/60, 90);
|
|
||||||
|
for (let i = 0; i < 60; i++) {
|
||||||
|
if (i > currentSec) {
|
||||||
|
g.setColor(0, 0, 0.6);
|
||||||
|
} else {
|
||||||
|
g.setColor(0.3, 0.3, 1);
|
||||||
|
}
|
||||||
|
seconds((360 * i) / 60);
|
||||||
|
}
|
||||||
onSecond();
|
onSecond();
|
||||||
}
|
};
|
||||||
|
|
||||||
function onSecond() {
|
const resetSeconds = () => {
|
||||||
g.setColor(0,0,0.6);
|
g.setColor(0, 0, 0.6);
|
||||||
seconds(360*secondDate.getSeconds()/60, 90);
|
for (let i = 0; i < 60; i++) {
|
||||||
g.setColor(1,0,0);
|
seconds((360 * i) / 60);
|
||||||
secondDate = new Date();
|
}
|
||||||
seconds(360*secondDate.getSeconds()/60, 90);
|
};
|
||||||
g.setColor(1,1,1);
|
|
||||||
|
|
||||||
}
|
const onSecond = () => {
|
||||||
|
g.setColor(0.3, 0.3, 1);
|
||||||
|
seconds((360 * currentDate.getSeconds()) / 60);
|
||||||
|
if (currentDate.getSeconds() === 59) {
|
||||||
|
resetSeconds();
|
||||||
|
onMinute();
|
||||||
|
}
|
||||||
|
g.setColor(1, 0.7, 0.2);
|
||||||
|
currentDate = new Date();
|
||||||
|
seconds((360 * currentDate.getSeconds()) / 60);
|
||||||
|
g.setColor(1, 1, 1);
|
||||||
|
};
|
||||||
|
|
||||||
function onMinute() {
|
const drawDate = () => {
|
||||||
g.setColor(0,0,0);
|
g.reset();
|
||||||
hand(360*(minuteDate.getHours() + (minuteDate.getMinutes()/60))/12, -10, 50);
|
g.setColor(1, 0, 0);
|
||||||
hand(360*minuteDate.getMinutes()/60, -10, 82);
|
g.setFont('6x8', 2);
|
||||||
minuteDate = new Date();
|
|
||||||
g.setColor(1,1,1);
|
const dayString = locale.dow(currentDate, true);
|
||||||
hand(360*(minuteDate.getHours() + (minuteDate.getMinutes()/60))/12, -10, 50);
|
// pad left date
|
||||||
hand(360*minuteDate.getMinutes()/60, -10, 82);
|
const dateString = (currentDate.getDate() < 10) ? '0' : '' + currentDate.getDate().toString();
|
||||||
if(minuteDate.getHours() >= 0 && minuteDate.getMinutes() === 0) {
|
const dateDisplay = `${dayString}-${dateString}`;
|
||||||
|
// console.log(`${dayString}|${dateString}`);
|
||||||
|
// center date
|
||||||
|
const l = (g.getWidth() - g.stringWidth(dateDisplay)) / 2;
|
||||||
|
const t = centerPx + 37;
|
||||||
|
g.drawString(dateDisplay, l, t);
|
||||||
|
// console.log(l, t);
|
||||||
|
};
|
||||||
|
const onMinute = () => {
|
||||||
|
if (currentDate.getHours() === 0 && currentDate.getMinutes() === 0) {
|
||||||
|
g.clear();
|
||||||
|
resetSeconds();
|
||||||
|
}
|
||||||
|
// clear existing hands
|
||||||
|
g.setColor(0, 0, 0);
|
||||||
|
// Hour
|
||||||
|
hand((360 * (currentDate.getHours() + currentDate.getMinutes() / 60)) / 12, -8, faceWidth - 35);
|
||||||
|
// Minute
|
||||||
|
hand((360 * currentDate.getMinutes()) / 60, -8, faceWidth - 10);
|
||||||
|
|
||||||
|
// get new date, then draw new hands
|
||||||
|
currentDate = new Date();
|
||||||
|
g.setColor(1, 0.9, 0.9);
|
||||||
|
// Hour
|
||||||
|
hand((360 * (currentDate.getHours() + currentDate.getMinutes() / 60)) / 12, -8, faceWidth - 35);
|
||||||
|
g.setColor(1, 1, 0.9);
|
||||||
|
// Minute
|
||||||
|
hand((360 * currentDate.getMinutes()) / 60, -8, faceWidth - 10);
|
||||||
|
if (currentDate.getHours() >= 0 && currentDate.getMinutes() === 0) {
|
||||||
Bangle.buzz();
|
Bangle.buzz();
|
||||||
}
|
}
|
||||||
}
|
drawDate();
|
||||||
|
};
|
||||||
|
|
||||||
function clearTimers() {
|
const startTimers = () => {
|
||||||
if(intervalRefMin) {clearInterval(intervalRefMin);}
|
timer = setInterval(onSecond, 1000);
|
||||||
if(intervalRefSec) {clearInterval(intervalRefSec);}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function startTimers() {
|
Bangle.on('lcdPower', (on) => {
|
||||||
minuteDate = new Date();
|
|
||||||
secondDate = new Date();
|
|
||||||
intervalRefSec = setInterval(onSecond,1000);
|
|
||||||
intervalRefMin = setInterval(onMinute,60*1000);
|
|
||||||
drawAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
Bangle.on('lcdPower',function(on) {
|
|
||||||
if (on) {
|
if (on) {
|
||||||
g.clear();
|
// g.clear();
|
||||||
Bangle.drawWidgets();
|
drawAll();
|
||||||
startTimers();
|
startTimers();
|
||||||
}else {
|
Bangle.drawWidgets();
|
||||||
clearTimers();
|
} else {
|
||||||
|
if (timer) {
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
g.clear();
|
g.clear();
|
||||||
|
resetSeconds();
|
||||||
|
startTimers();
|
||||||
|
drawAll();
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
drawAll();
|
|
||||||
startTimers();
|
|
||||||
// Show launcher when middle button pressed
|
// Show launcher when middle button pressed
|
||||||
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
|
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
0.02: Fix issues with alarm scheduling
|
0.02: Fix issues with alarm scheduling
|
||||||
0.03: More alarm scheduling issues
|
0.03: More alarm scheduling issues
|
||||||
0.04: Tweaks for variable size widget system
|
0.04: Tweaks for variable size widget system
|
||||||
|
0.05: Add alarm.boot.js and move code from the bootloader
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
// check for alarms
|
||||||
|
(function() {
|
||||||
|
var alarms = require('Storage').readJSON('alarm.json',1)||[];
|
||||||
|
var time = new Date();
|
||||||
|
var active = alarms.filter(a=>a.on&&(a.last!=time.getDate()));
|
||||||
|
if (active.length) {
|
||||||
|
active = active.sort((a,b)=>a.hr-b.hr);
|
||||||
|
var hr = time.getHours()+(time.getMinutes()/60)+(time.getSeconds()/3600);
|
||||||
|
if (!require('Storage').read("alarm.js")) {
|
||||||
|
console.log("No alarm app!");
|
||||||
|
require('Storage').write('alarm.json',"[]")
|
||||||
|
} else {
|
||||||
|
var t = 3600000*(active[0].hr-hr);
|
||||||
|
if (t<1000) t=1000;
|
||||||
|
/* execute alarm at the correct time. We avoid execing immediately
|
||||||
|
since this code will get called AGAIN when alarm.js is loaded. alarm.js
|
||||||
|
will then clearInterval() to get rid of this call so it can proceed
|
||||||
|
normally. */
|
||||||
|
setTimeout(function() {
|
||||||
|
load("alarm.js");
|
||||||
|
},t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
|
@ -0,0 +1 @@
|
||||||
|
0.01: Create astrocalc app
|
|
@ -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();
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AW43GF1wwsFwYwqFwowoFw4wmFxIwdE5YAPF/4vM5nN6YAE5vMF8YtHGIgvhFpQxKF7AuOGA4vXFyAwGF63MFyIABF6xeWMC4UDLwvNGpAJG5gwSdhIIDRBLyWCIgcJHAgJJDoouQF4vMQoICBBJoeGFx6GGACIfHL6YvaX6gvZeCIdFc4gAFXogvGFxgwFDwovQCAguOGAnMMBxeG5guTGAggGGAwNKFySREcA3N5vM5gDBdpQvXEY4AKXqovGGCKbFF7AwPZQwvZGJgtGF7vGdQItG5gSIF7gASF/44WEzgwRF0wwHF1AwFF1QwDF1gvwAH4A/AFAA=="))
|
After Width: | Height: | Size: 952 B |
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("rlcgI1ygf4BZM/BZMD//wCxP/8AWJ/+ACxP+CxQ6ICwP/4AWJERAWCEQ4WCERAWCEQ4WDOg4WCNA4WD/gWKRYwWDHI4WDHIwWDHI4WDHIwWEOYwWDHIwWEKAwWD/4WKKAwWEKAoWEYgwWPM4wWEM4oWQM4oWEPwwWbPwoWESowW/C34WOZ1vACxP8Cyv4CxWACyoKFCwiUFCwhmGCwh9FCwhmGCwhmFCwhPGCwgKFCwg4GCwZPGCwg4GCwY4GCwgKGCwY4GCwZxGCwjBFCwghHCwQhHCwYhHCwQhHCwRlHCwSHHCwYKICwI3HCwQKJAFAA=="))
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("rlcgJC/AD8B//4BRILJBQP/+AKGn4LC4AKFh4KC/4KFgYKD/gLFv4LD8AKEj4KD/+AEJAiGEIgiFIYhFFOAQADOghlDNA0HBQv+Q4wADRYZaFLgg4GHIg4GHIY4GHIhxFOYhxGOYgKHKARPHKARPHKAZPHKATBFYgoWKMw5nDMw5nCCyx9IPwQKIPwIW/C34WJZ1sDBQ/8CwM/BY/ACxkfBY+AgEBBQ/4CwJ+IBQJ+IPoJnIMwRnIMwJQIJ4RQIJ4JQIJ4RQIBQQ5HHAQ5HHAY5HHARzHOIRzHOIbEHYIIACLgpaDEQwhFEQohEIopDENAplERYwKGOgZwEBYoKIAH4AXA=="))
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("rlcgI0xgP8BRP/4ALI/4WJv4WJj4WJg//CxA3BCxM/CxIhCCw4hCCxAhCCw4hCCxAKCCw5lBCxEDCxSHBCxA4DCw4KCCw44DCww4DCw5xCCw44DCw5PDCw0PCxQKDCwxPDCwzBDCyRmECwxmDCyRmDCwx9ECzoKDCwyUEC34W/CyDOtn4WJgYWVgIWKj4WVPwgWFSogWGM4gWGPwYWGM4gWGM4YWGKAgWGKAYWGHIgWGKAYWHHIYWGHIYWHHIYWGHIYWHOYYWHYgQWHEQYWHEQQWIEQQWHEQQWINAQWIRYIWIOgQWIHQIWJBYIWJAFI="))
|
|
@ -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=="))
|
|
@ -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;
|
||||||
|
|
||||||
|
}());
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("rlcgJC/ABHgBRN8BRMfwAKIg/4CxP/BRM/HBMH/wKIgP/4AhJ/ghJ/5PJ/5PJj4WJgf/+AWIv5mJHAIWJ/5mJHAJ9IHAIWJn59JHAJ9JJ4IWIh4WK/4WJJ4KUIYIKUJJ4IWIMwIWgMwIWIPoLCJCwLCICxYKBCxCUBC34W/Cya3WCxr8In78JgYWhj4WJgIWKPwP8SpXAM5IWJPwIWIKAIWJM4PgKBP+CxBQBCxA5CBRBQBYZA5CBRA5BSpA5CSpA5BCxJzBPxDEBPxIiBM5MDPxJFBM5IiBKBMBKBKLBKBMAhwKJAH4ABA="))
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("rlcgI0xgP/wAKJ/wWI///+AKHv4LBEQ8fBQP8BQ0HBQP/8A3HAAQWGn4KCHIwhDHIwhE/AhJ//AEJJQGBQZQGMoQABRQsDCwhQFQ4RnHHAgWGBQhnFHAhnFHAoWFOIhnFHAp+FJ4oWEh4WKBQp+EJ4qVEYIgWRMwwWEMwoWLVghmFVgh9GCzYKGCwaUGC34W/CxzOtn4WJgYKF/wWK8AKCgIWKj4WVPwwWDSo38BQZnG4B+JCwhnGCwhnF/AKDKA2AKBIWEHIwKEKAqrDHI4KEHIp9EHIqUEHIxmEOYp9EYgxmEEQpmFEQoKFEQhmFEQhPGNAhPFRYg4GOggKHHQSIFBYghIAFQ="))
|
|
@ -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"))
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("rlcgI1yj/4BREH/4LJ/4LJj4LB8AKGgYKB/+ABY1/BQP+BQ0PCwQuHBQX/4A4IEQ8BCwYiGn4iJJ4YiHJ4QAB+CIGAAZoFBQn8MxCLHBQg5FMwY5GMwg5GCwo5EMwhzGPog5FCwxQECwv/PpJQFSghQFCwzEECyJnECwxnDVYoWFBQpnECwx+ECzp+DCwyVEC34W/CyDOt4AKCg4KF/gWDv4WQ/AWKwAWVBQcDShMAn5mJCwx9DCwxmEgJmJgEfJ5IWGBQasGHAisFJ4gWGHAh+FHAiVGBQhnFHAp+EOIhnGYIZnGEIpQEEIxnEEIpQEEIxQDMoo5EQ4o5FFgyKDBRAiBBRAApA="))
|
|
@ -0,0 +1 @@
|
||||||
|
0.01: Initial version of Balltastic released! Happy!
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwwkEogAIkUzmciBpIVIkYWBAAUyCx0hiIXFAAMkCxhUBC4fzDAYWLiAXFAAP//5KKoMRC4UTC4k/DAPzJJERiKcCC5H/GA4uBWwp6DC4YwHCwMBDI0SMAYwHoIWBiXxdIwYCMJCjBiM/C46VDC4M/GAkRgMf//ySAQAEgKrDC4lBgMCHIQXHSwxICIwIuBAAIXIGAYABiQXBkEBTYcgC473FkQXBiETTQZ4IgECC4cholCiJGDMAIXIWgIXCmMkC4JGDJBbEDC4UACwn/mAtGSYsxilCgIXFSAqDBkMRiIFBkcxiUiC4sxXowIBC4QGBkIXBiJ2EFwsDBIPyC4ILBgMRiUyiCmJgSCC+YXDgAXDR4YuEcAn/MAIXEmcgBoXyFwjIEMAQXFkIOCUgoXF+J3CC4cxBwR1IQQx3BkUzmUSBQKkFC5IuBkVDJAJeGRwLhHFwUkC4Mxl6lFC48gFwYXCmcTOwomBC4swYIMikU0C4UxkJ3FC40xFoIXCogXBmaxDC5MyCwUiogXDmIXTJASSBC4kRU4oXDkgXFmQwDNwIWEBoIXFJAYKBZggWFC4YWCC4g7BkIWBkYWBBYYXCkYXDJAYjDkQUEEYZGEGA4XIIwwwGDAQuOGAomCFo4uGGARoBE4ZOGFxAABBwgAICxAABCyxJBGJJFJJRgVNPggsMA="))
|
|
@ -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);
|
After Width: | Height: | Size: 14 KiB |
|
@ -0,0 +1,4 @@
|
||||||
|
0.01: Created Bar Clock
|
||||||
|
0.02: Apply locale, 12-hour setting
|
||||||
|
0.03: Fix dates drawing over each other at midnight
|
||||||
|
0.04: Small bugfix
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwgJC/AD8Mgfwh/AhgFFngHBOIM8AovMDIXA5gFFDoUAmYjDAocMSoMz/4FF//P/g1CAopTLDAIABwAFGAH4AfA"))
|
|
@ -0,0 +1,166 @@
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
/**
|
||||||
|
* A simple digital clock showing seconds as a bar
|
||||||
|
**/
|
||||||
|
{
|
||||||
|
// Check settings for what type our clock should be
|
||||||
|
const is12Hour = (require('Storage').readJSON('setting.json', 1) || {})['12hour']
|
||||||
|
let locale = require('locale')
|
||||||
|
{ // add some more info to locale
|
||||||
|
let date = new Date()
|
||||||
|
date.setFullYear(1111)
|
||||||
|
date.setMonth(1, 3) // februari: months are zero-indexed
|
||||||
|
const localized = locale.date(date, true)
|
||||||
|
locale.dayFirst = /3.*2/.test(localized)
|
||||||
|
locale.hasMeridian = (locale.meridian(date) !== '')
|
||||||
|
}
|
||||||
|
const screen = {
|
||||||
|
width: g.getWidth(),
|
||||||
|
height: g.getWidth(),
|
||||||
|
middle: g.getWidth() / 2,
|
||||||
|
center: g.getHeight() / 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
// hardcoded "settings"
|
||||||
|
const settings = {
|
||||||
|
time: {
|
||||||
|
color: -1,
|
||||||
|
font: '6x8',
|
||||||
|
size: (is12Hour && locale.hasMeridian) ? 6 : 8,
|
||||||
|
middle: screen.middle,
|
||||||
|
center: screen.center,
|
||||||
|
ampm: {
|
||||||
|
color: -1,
|
||||||
|
font: '6x8',
|
||||||
|
size: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
date: {
|
||||||
|
color: -1,
|
||||||
|
font: 'Vector',
|
||||||
|
size: 20,
|
||||||
|
middle: screen.height - 20, // at bottom of screen
|
||||||
|
center: screen.center,
|
||||||
|
},
|
||||||
|
bar: {
|
||||||
|
color: -1,
|
||||||
|
top: 155, // just below time
|
||||||
|
thickness: 6, // matches 24h time "pixel" size
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const SECONDS_PER_MINUTE = 60
|
||||||
|
|
||||||
|
const timeText = function (date) {
|
||||||
|
if (!is12Hour) {
|
||||||
|
return locale.time(date, true)
|
||||||
|
}
|
||||||
|
const date12 = new Date(date.getTime())
|
||||||
|
const hours = date12.getHours()
|
||||||
|
if (hours === 0) {
|
||||||
|
date12.setHours(12)
|
||||||
|
} else if (hours > 12) {
|
||||||
|
date12.setHours(hours - 12)
|
||||||
|
}
|
||||||
|
return locale.time(date12, true)
|
||||||
|
}
|
||||||
|
const ampmText = function (date) {
|
||||||
|
return is12Hour ? locale.meridian(date) : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateText = function (date) {
|
||||||
|
const dayName = locale.dow(date, true),
|
||||||
|
month = locale.month(date, true),
|
||||||
|
day = date.getDate()
|
||||||
|
const dayMonth = locale.dayFirst ? `${day} ${month}` : `${month} ${day}`
|
||||||
|
return `${dayName} ${dayMonth}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const drawDateTime = function (date) {
|
||||||
|
const t = settings.time
|
||||||
|
g.setColor(t.color)
|
||||||
|
g.setFont(t.font, t.size)
|
||||||
|
g.setFontAlign(0, 0) // centered
|
||||||
|
g.drawString(timeText(date), t.center, t.middle, true)
|
||||||
|
if (is12Hour && locale.hasMeridian) {
|
||||||
|
const a = settings.time.ampm
|
||||||
|
g.setColor(a.color)
|
||||||
|
g.setFont(a.font, a.size)
|
||||||
|
g.setFontAlign(1, -1) // right top
|
||||||
|
// at right edge of screen, aligned with time bottom
|
||||||
|
const left = screen.width - a.size * 2,
|
||||||
|
top = t.middle + t.size - a.size
|
||||||
|
g.drawString(ampmText(date), left, top, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const d = settings.date
|
||||||
|
g.setColor(d.color)
|
||||||
|
g.setFont(d.font, d.size)
|
||||||
|
g.setFontAlign(0, 0) // centered
|
||||||
|
g.drawString(dateText(date), d.center, d.middle, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const drawBar = function (date) {
|
||||||
|
const b = settings.bar
|
||||||
|
const seconds = date.getSeconds()
|
||||||
|
if (seconds === 0) {
|
||||||
|
// zero-size rect stills draws one line of pixels, we don't want that
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const fraction = seconds / SECONDS_PER_MINUTE,
|
||||||
|
width = fraction * screen.width
|
||||||
|
g.setColor(b.color)
|
||||||
|
g.fillRect(0, b.top, width, b.top + b.thickness)
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearScreen = function () {
|
||||||
|
g.setColor(0)
|
||||||
|
const timeTop = settings.time.middle - (settings.time.size * 4)
|
||||||
|
g.fillRect(0, timeTop, screen.width, screen.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
let lastSeconds
|
||||||
|
const tick = function () {
|
||||||
|
g.reset()
|
||||||
|
const date = new Date()
|
||||||
|
const seconds = date.getSeconds()
|
||||||
|
if (lastSeconds > seconds) {
|
||||||
|
// new minute
|
||||||
|
clearScreen()
|
||||||
|
drawDateTime(date)
|
||||||
|
}
|
||||||
|
// the bar only gets larger, so drawing on top of the previous one is fine
|
||||||
|
drawBar(date)
|
||||||
|
|
||||||
|
lastSeconds = seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
let iTick
|
||||||
|
const start = function () {
|
||||||
|
lastSeconds = 99 // force redraw
|
||||||
|
tick()
|
||||||
|
iTick = setInterval(tick, 1000)
|
||||||
|
}
|
||||||
|
const stop = function () {
|
||||||
|
if (iTick) {
|
||||||
|
clearInterval(iTick)
|
||||||
|
iTick = undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean app screen
|
||||||
|
g.clear()
|
||||||
|
Bangle.loadWidgets()
|
||||||
|
Bangle.drawWidgets()
|
||||||
|
// Show launcher when middle button pressed
|
||||||
|
setWatch(Bangle.showLauncher, BTN2, {repeat: false, edge: 'falling'})
|
||||||
|
|
||||||
|
Bangle.on('lcdPower', function (on) {
|
||||||
|
if (on) {
|
||||||
|
start()
|
||||||
|
} else {
|
||||||
|
stop()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
start()
|
||||||
|
}
|
After Width: | Height: | Size: 159 B |
|
@ -9,3 +9,6 @@
|
||||||
0.10: Stop users calling save() (fix #125)
|
0.10: Stop users calling save() (fix #125)
|
||||||
If Debug info is set to 'show' don't move to Terminal if connected!
|
If Debug info is set to 'show' don't move to Terminal if connected!
|
||||||
0.11: Added vibrate as beep workaround
|
0.11: Added vibrate as beep workaround
|
||||||
|
0.12: Add an event on BTN2 to open launcher when no clock detected (fix #147)
|
||||||
|
0.13: Now automatically load *.boot.js at startup
|
||||||
|
Move alarm code into alarm.boot.js
|
||||||
|
|
|
@ -39,25 +39,7 @@ E.setTimeZone(s.timezone);
|
||||||
delete s;
|
delete s;
|
||||||
// stop users doing bad things!
|
// stop users doing bad things!
|
||||||
global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); }
|
global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); }
|
||||||
// check for alarms
|
// Load *.boot.js files
|
||||||
var alarms = require('Storage').readJSON('alarm.json',1)||[];
|
var clockApps = require('Storage').list(/\.boot\.js/).map(bootFile=>{
|
||||||
var time = new Date();
|
eval(require('Storage').read(bootFile));
|
||||||
var active = alarms.filter(a=>a.on&&(a.last!=time.getDate()));
|
});
|
||||||
if (active.length) {
|
|
||||||
active = active.sort((a,b)=>a.hr-b.hr);
|
|
||||||
var hr = time.getHours()+(time.getMinutes()/60)+(time.getSeconds()/3600);
|
|
||||||
if (!require('Storage').read("alarm.js")) {
|
|
||||||
console.log("No alarm app!");
|
|
||||||
require('Storage').write('alarm.json',"[]")
|
|
||||||
} else {
|
|
||||||
var t = 3600000*(active[0].hr-hr);
|
|
||||||
if (t<1000) t=1000;
|
|
||||||
/* execute alarm at the correct time. We avoid execing immediately
|
|
||||||
since this code will get called AGAIN when alarm.js is loaded. alarm.js
|
|
||||||
will then clearInterval() to get rid of this call so it can proceed
|
|
||||||
normally. */
|
|
||||||
setTimeout(function() {
|
|
||||||
load("alarm.js");
|
|
||||||
},t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,7 +12,11 @@ if (!settings.welcomed && require("Storage").read("welcome.js")!==undefined) {
|
||||||
clockApp = require("Storage").read(clockApps[0].src);
|
clockApp = require("Storage").read(clockApps[0].src);
|
||||||
delete clockApps;
|
delete clockApps;
|
||||||
}
|
}
|
||||||
if (!clockApp) clockApp='E.showMessage("No Clock Found")';
|
if (!clockApp) clockApp=`E.showMessage("No Clock Found");
|
||||||
|
setWatch(() => {
|
||||||
|
Bangle.showLauncher();
|
||||||
|
}, BTN2, {repeat:false,edge:"falling"});)
|
||||||
|
`;
|
||||||
delete settings;
|
delete settings;
|
||||||
// check to see if our clock is wrong - if it is use GPS time
|
// check to see if our clock is wrong - if it is use GPS time
|
||||||
if ((new Date()).getFullYear()==1970) {
|
if ((new Date()).getFullYear()==1970) {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwwglihGIxAWUwADBDCYTDhAXSFwQEGIxowBL4QXTx///AXWF6qnBwCTDO6EIF4KnEDwLWO/4QFx7FNdwQQEGwP4GBYUB/4QBDIYXMIgQAEDIIKCVwItJFggFEx4uKCAQUBX4QDC/B2KhASCAQP/AQQcDLpQlCLgQsCCoIGBC5IkCFon/xwxCDgIXJFwYxFHIR3ILwIkBCIeIFwQHBHgReIJAgCBOoP+MYZIHhB1EDgIRBA4ZIJC4LrEMYvoAgQXJxHvI4gtDC5OIF4QSDbYY3EC5QAKG4QXNPwg0BSBAJCIQhLCDwgXKIAwXUMo4XPFwrwKC4YOCUooVCR453DIxIXJU4IqDxwXJa45FDdgxnEC40IC4TbINQYXIRQZwDAAXv/xuBCwoXBVAgXDA4wXGSARcEC4o7BRwx4DOon+C4YiCLwxIDDAobDEYJGIGAYYBxDAD9AJDC5IwCDIYACJARGIDAapDaooWLDAZhEAoIWNMggADCqAAPA"))
|
|
@ -0,0 +1,73 @@
|
||||||
|
function msToTime(duration) {
|
||||||
|
var milliseconds = parseInt((duration % 1000) / 100),
|
||||||
|
seconds = Math.floor((duration / 1000) % 60),
|
||||||
|
minutes = Math.floor((duration / (1000 * 60)) % 60),
|
||||||
|
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
|
||||||
|
|
||||||
|
hours = (hours < 10) ? "0" + hours : hours;
|
||||||
|
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
||||||
|
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
||||||
|
|
||||||
|
return hours + ":" + minutes + ":" + seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
|
var started = false;
|
||||||
|
|
||||||
|
function drawInterface() {
|
||||||
|
g.clear();
|
||||||
|
g.setFontAlign(0, 0);
|
||||||
|
g.setFont("6x8", 2);
|
||||||
|
g.drawString("+5m", g.getWidth() - 30, 30);
|
||||||
|
g.drawString("+30s", g.getWidth() - 30, g.getHeight() / 2);
|
||||||
|
g.drawString("+5s", g.getWidth() - 30, g.getHeight() - 30);
|
||||||
|
|
||||||
|
g.setFontAlign(0, 0); // center font
|
||||||
|
g.setFont("6x8", 3);
|
||||||
|
// draw the current counter value
|
||||||
|
|
||||||
|
g.drawString(msToTime(counter * 1000), g.getWidth() / 2 - 30, g.getHeight() / 2);
|
||||||
|
// optional - this keeps the watch LCD lit up
|
||||||
|
g.flip();
|
||||||
|
}
|
||||||
|
|
||||||
|
function countDown() {
|
||||||
|
if (counter > 0) {
|
||||||
|
if (started) {
|
||||||
|
counter--;
|
||||||
|
drawInterface();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (started) {
|
||||||
|
Bangle.buzz();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setWatch((p) => {
|
||||||
|
if (p.time - p.lastTime < 0.1) {
|
||||||
|
counter = 0;
|
||||||
|
started = false;
|
||||||
|
} else {
|
||||||
|
counter += 60 * 5;
|
||||||
|
}
|
||||||
|
drawInterface();
|
||||||
|
}, BTN1, { repeat: true });
|
||||||
|
|
||||||
|
setWatch(() => {
|
||||||
|
counter += 30;
|
||||||
|
drawInterface();
|
||||||
|
}, BTN2, { repeat: true });
|
||||||
|
|
||||||
|
setWatch(() => {
|
||||||
|
counter += 5;
|
||||||
|
drawInterface();
|
||||||
|
}, BTN3, { repeat: true });
|
||||||
|
|
||||||
|
Bangle.on('touch', function (button) {
|
||||||
|
started = !started;
|
||||||
|
});
|
||||||
|
|
||||||
|
var interval = setInterval(countDown, 1000);
|
||||||
|
drawInterface();
|
After Width: | Height: | Size: 3.5 KiB |
|
@ -0,0 +1 @@
|
||||||
|
0.07: Submitted to App Loader
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("kEgwkBiIA/ACBhLB6gqKB6g//B6I4DiDqCB40QB4MBAoIXDB40BAIIPNG44PLAoQvMB5RPEB5JvEBAav1f7wA/ABoA=="))
|
|
@ -0,0 +1,51 @@
|
||||||
|
var fontsize = 3;
|
||||||
|
var locale = require("locale");
|
||||||
|
var marginTop = 40;
|
||||||
|
var flag = false;
|
||||||
|
var WeekDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
|
||||||
|
|
||||||
|
function drawAll(){
|
||||||
|
g.clear();
|
||||||
|
Bangle.loadWidgets();
|
||||||
|
Bangle.drawWidgets();
|
||||||
|
updateTime();
|
||||||
|
updateRest(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateRest(now){
|
||||||
|
let date = locale.date(now,false);
|
||||||
|
writeLine(WeekDays[now.getDay()],1);
|
||||||
|
writeLine(date,2);
|
||||||
|
}
|
||||||
|
function updateTime(){
|
||||||
|
if (!Bangle.isLCDOn()) return;
|
||||||
|
let now = new Date();
|
||||||
|
let h = now.getHours();
|
||||||
|
let m = now.getMinutes();
|
||||||
|
h = h>=10?h:"0"+h;
|
||||||
|
m = m>=10?m:"0"+m;
|
||||||
|
writeLine(h+":"+m,0);
|
||||||
|
writeLine(flag?" ":"_",3);
|
||||||
|
flag = !flag;
|
||||||
|
if(now.getMinutes() == 0)
|
||||||
|
updateRest(now);
|
||||||
|
}
|
||||||
|
function writeLineStart(line){
|
||||||
|
g.drawString(">",4,marginTop+line*30);
|
||||||
|
}
|
||||||
|
function writeLine(str,line){
|
||||||
|
g.setFont("6x8",fontsize);
|
||||||
|
g.setColor(0,1,0);
|
||||||
|
g.setFontAlign(-1,-1);
|
||||||
|
g.clearRect(0,marginTop+line*30,((str.length+1)*20),marginTop+25+line*30);
|
||||||
|
writeLineStart(line);
|
||||||
|
g.drawString(str,25,marginTop+line*30);
|
||||||
|
}
|
||||||
|
|
||||||
|
drawAll();
|
||||||
|
Bangle.on('lcdPower',function(on) {
|
||||||
|
if (on)
|
||||||
|
drawAll();
|
||||||
|
});
|
||||||
|
var click = setInterval(updateTime, 1000);
|
||||||
|
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
|
After Width: | Height: | Size: 305 B |
|
@ -0,0 +1,2 @@
|
||||||
|
0.01: New Widget!
|
||||||
|
0.02: Improved calculation, new image for app
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwgmIAH4A/AH4A/AEEAAAgGOC/4XLAgoGIDgYXTwEIBY4JEAw8YCIOAEY4+EAwwTCL44XNO5IX/C6i6LC8YABa5AXOF67vIwA5DAw5GDMhg7HjAXWIwQLFZIoGNC/4XKAH4A/AH4A/ADoA="))
|
|
@ -0,0 +1,67 @@
|
||||||
|
g.clear();
|
||||||
|
Bangle.loadWidgets();
|
||||||
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
|
const storage = require('Storage');
|
||||||
|
let settings;
|
||||||
|
|
||||||
|
function updateSettings() {
|
||||||
|
storage.write('daysleft.json', settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetSettings() {
|
||||||
|
settings = {
|
||||||
|
day : 17,
|
||||||
|
month : 6,
|
||||||
|
year: 1981
|
||||||
|
};
|
||||||
|
updateSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
settings = storage.readJSON('daysleft.json',1);
|
||||||
|
if (!settings) resetSettings();
|
||||||
|
|
||||||
|
function showMenu() {
|
||||||
|
const datemenu = {
|
||||||
|
'': {
|
||||||
|
'title': 'Set Date',
|
||||||
|
'predraw': function() {
|
||||||
|
datemenu.Date.value = settings.day;
|
||||||
|
datemenu.Month.value = settings.month;
|
||||||
|
datemenu.Year.value = settings.year;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'Day': {
|
||||||
|
value: settings.day,
|
||||||
|
min: 1,
|
||||||
|
max: 31,
|
||||||
|
step: 1,
|
||||||
|
onchange: v => {
|
||||||
|
settings.day = v;
|
||||||
|
updateSettings();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'Month': {
|
||||||
|
value: settings.month,
|
||||||
|
min: 1,
|
||||||
|
max: 12,
|
||||||
|
step: 1,
|
||||||
|
onchange: v => {
|
||||||
|
settings.month = v;
|
||||||
|
updateSettings();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'Year': {
|
||||||
|
value: settings.year,
|
||||||
|
step: 1,
|
||||||
|
onchange: v => {
|
||||||
|
settings.year = v;
|
||||||
|
updateSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
datemenu['-Exit-'] = ()=>{load();};
|
||||||
|
return E.showMenu(datemenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
showMenu();
|
After Width: | Height: | Size: 468 B |
|
@ -0,0 +1,39 @@
|
||||||
|
const storage = require('Storage');
|
||||||
|
let settings;
|
||||||
|
|
||||||
|
function updateSettings() {
|
||||||
|
storage.write('daysleft.json', settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetSettings() {
|
||||||
|
settings = {
|
||||||
|
day : 17,
|
||||||
|
month : 6,
|
||||||
|
year: 2020
|
||||||
|
};
|
||||||
|
updateSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
settings = storage.readJSON('daysleft.json',1);
|
||||||
|
if (!settings) resetSettings();
|
||||||
|
|
||||||
|
var dd = settings.day,
|
||||||
|
mm = settings.month-1, //month is zero-based
|
||||||
|
yy = settings.year;
|
||||||
|
|
||||||
|
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
|
||||||
|
const targetDate = new Date(yy, mm, dd);
|
||||||
|
const today = new Date();
|
||||||
|
|
||||||
|
//create date object with today, but 00:00:00
|
||||||
|
const currentYear = today.getFullYear();
|
||||||
|
const currentMonth = today.getMonth();
|
||||||
|
const currentDay = today.getDate();
|
||||||
|
const todayMorning = new Date (currentYear, currentMonth, currentDay, 0, 0, 0);
|
||||||
|
|
||||||
|
const diffDays = (targetDate - todayMorning) / oneDay;
|
||||||
|
|
||||||
|
WIDGETS["daysl"]={area:"tl",width:40,draw:function(){
|
||||||
|
g.setFont("6x8", 1);
|
||||||
|
g.drawString(diffDays,this.x+12,this.y+12);
|
||||||
|
}};
|
|
@ -0,0 +1,9 @@
|
||||||
|
0.01: branched from simple clock and added seconds
|
||||||
|
0.02: add timestamp (tst)
|
||||||
|
0.03: fix timestamp round to whole number
|
||||||
|
0.04: add iso datetime and move day of the week (d) / month names (m)
|
||||||
|
0.05: add beats (@)
|
||||||
|
0.06: tidy up
|
||||||
|
0.07: add days in current month (md) and days since new moon (l)
|
||||||
|
0.08: update icon
|
||||||
|
0.09: Use localised month and day of the week from locale
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwwkEIf4A5/8wgf/AwUB/8gh/zA4QMCl/xA4cAichgIaBiEDgMgmECDQMAkMA+EgiYvDkQJBkcQgMQDwMggUiiECG4MikEBmQWCgURiEREQIXBCIMxkIIBAoMSiQ4BGoIABKgPykRSBI4JfC+c/iARBl8zmBfEAAUvIgIAUkbAtgalB+ADDBIKSBHgUgmYJCAAa6BmCoBAYMiBIMRC4UQmEAAoQvFmUDAYUSmcxWIKMBEQKrBOw0yh8wmcyj4nBIYQDB+cwBAQA/ABUxgUDkBqBgchkMiiUikMRgSOBkR3BkEhC4MgiQHBiADBC4UQAYMRiUxkECAAITBC4MSiUQF4MTiQTBBAIDBkcCiMxkUTAYIvCAH4A/AH4AKiIPPgMxiESgUQgECgMBdAMiiUgC48ikUBiEBiIXDGQURiIbBF48RkAvCEwIvCkERgQMBRHpDBOoRhBNoJOBJIkiKYMjgcTOoMhLQMQmMDDIMjQQInEC4MhiUSkQHCC4MAkAXCiUjiZ5UiR5jLwLaBAQJ1BAgIAMCgMxMwMgkciAoMjC5pqBRwPxCoMiiUyGBsgiBBBiESVAKzBf+YACA=="))
|
|
@ -0,0 +1,112 @@
|
||||||
|
var locale = require("locale");
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
const timeFontSize = 4;
|
||||||
|
const dateFontSize = 3;
|
||||||
|
const smallFontSize = 2;
|
||||||
|
const font = "6x8";
|
||||||
|
|
||||||
|
const xyCenter = g.getWidth() / 2;
|
||||||
|
const yposTime = 50;
|
||||||
|
const yposDate = 85;
|
||||||
|
const yposTst = 115;
|
||||||
|
const yposDml = 170;
|
||||||
|
const yposDayMonth = 195;
|
||||||
|
const yposGMT = 220;
|
||||||
|
|
||||||
|
// Check settings for what type our clock should be
|
||||||
|
var is12Hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"];
|
||||||
|
|
||||||
|
function getUTCTime(d) {
|
||||||
|
return d.toUTCString().split(' ')[4].split(':').map(function(d){return Number(d)});
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawSimpleClock() {
|
||||||
|
// get date
|
||||||
|
var d = new Date();
|
||||||
|
var da = d.toString().split(" ");
|
||||||
|
var dutc = getUTCTime(d);
|
||||||
|
|
||||||
|
g.reset(); // default draw styles
|
||||||
|
// drawSting centered
|
||||||
|
g.setFontAlign(0, 0);
|
||||||
|
|
||||||
|
// draw time
|
||||||
|
var time = da[4].split(":");
|
||||||
|
var hours = time[0],
|
||||||
|
minutes = time[1],
|
||||||
|
seconds = time[2];
|
||||||
|
|
||||||
|
var meridian = "";
|
||||||
|
if (is12Hour) {
|
||||||
|
hours = parseInt(hours,10);
|
||||||
|
meridian = "AM";
|
||||||
|
if (hours == 0) {
|
||||||
|
hours = 12;
|
||||||
|
meridian = "AM";
|
||||||
|
} else if (hours >= 12) {
|
||||||
|
meridian = "PM";
|
||||||
|
if (hours>12) hours -= 12;
|
||||||
|
}
|
||||||
|
hours = (" "+hours).substr(-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time
|
||||||
|
g.setFont(font, timeFontSize);
|
||||||
|
g.drawString(`${hours}:${minutes}:${seconds}`, xyCenter, yposTime, true);
|
||||||
|
g.setFont(font, smallFontSize);
|
||||||
|
g.drawString(meridian, xyCenter + 102, yposTime + 10, true);
|
||||||
|
|
||||||
|
// Date String
|
||||||
|
g.setFont(font, dateFontSize);
|
||||||
|
g.drawString(`${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}`, xyCenter, yposDate, true);
|
||||||
|
|
||||||
|
// Timestamp
|
||||||
|
var tst = Math.round(d.getTime());
|
||||||
|
g.setFont(font, smallFontSize);
|
||||||
|
g.drawString(`tst:${tst}`, xyCenter, yposTst, true);
|
||||||
|
|
||||||
|
//Days in month
|
||||||
|
var dom = new Date(d.getFullYear(), d.getMonth()+1, 0).getDate();
|
||||||
|
|
||||||
|
//Days since full moon
|
||||||
|
var knownnew = new Date(2020,02,24,09,28,0);
|
||||||
|
|
||||||
|
// Get millisecond difference and divide down to cycles
|
||||||
|
var cycles = (d.getTime()-knownnew.getTime())/1000/60/60/24/29.53;
|
||||||
|
|
||||||
|
// Multiply decimal component back into days since new moon
|
||||||
|
var sincenew = (cycles % 1)*29.53;
|
||||||
|
|
||||||
|
// Draw days in month and sime since new moon
|
||||||
|
g.setFont(font, smallFontSize);
|
||||||
|
g.drawString(`md:${dom} l:${sincenew.toFixed(2)}`, xyCenter, yposDml, true);
|
||||||
|
|
||||||
|
// draw Month name, Day of the week and beats
|
||||||
|
var beats = Math.floor((((dutc[0] + 1) % 24) + dutc[1] / 60 + dutc[2] / 3600) * 1000 / 24);
|
||||||
|
g.setFont(font, smallFontSize);
|
||||||
|
g.drawString(`m:${locale.month(d,true)} d:${locale.dow(d,true)} @${beats}`, xyCenter, yposDayMonth, true);
|
||||||
|
|
||||||
|
// draw gmt
|
||||||
|
var gmt = da[5];
|
||||||
|
g.setFont(font, smallFontSize);
|
||||||
|
g.drawString(gmt, xyCenter, yposGMT, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle switch display on by pressing BTN1
|
||||||
|
Bangle.on('lcdPower', function(on) {
|
||||||
|
if (on) drawSimpleClock();
|
||||||
|
});
|
||||||
|
|
||||||
|
// clean app screen
|
||||||
|
g.clear();
|
||||||
|
Bangle.loadWidgets();
|
||||||
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
|
// refesh every 100 milliseconds
|
||||||
|
setInterval(drawSimpleClock, 100);
|
||||||
|
|
||||||
|
// draw now
|
||||||
|
drawSimpleClock();
|
||||||
|
|
||||||
|
// Show launcher when middle button pressed
|
||||||
|
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
|
After Width: | Height: | Size: 2.5 KiB |
|
@ -2,4 +2,5 @@
|
||||||
0.02: Increase contrast (darker notification background, white text)
|
0.02: Increase contrast (darker notification background, white text)
|
||||||
0.03: Gadgetbridge widget now shows connection state
|
0.03: Gadgetbridge widget now shows connection state
|
||||||
0.04: Tweaks for variable size widget system
|
0.04: Tweaks for variable size widget system
|
||||||
0.05: Show incoming call notification
|
0.05: Show incoming call notification
|
||||||
|
Optimize animation, limit title length
|
||||||
|
|
|
@ -0,0 +1,178 @@
|
||||||
|
# Watch -> Phone
|
||||||
|
|
||||||
|
## show toast
|
||||||
|
|
||||||
|
```
|
||||||
|
{ "t": "info", "msg": "message" }
|
||||||
|
```
|
||||||
|
|
||||||
|
t can be one of "info", "warn", "error"
|
||||||
|
|
||||||
|
## report battery level
|
||||||
|
|
||||||
|
```
|
||||||
|
{ "t": "status", "bat": 30, "volt": 30 }
|
||||||
|
```
|
||||||
|
|
||||||
|
* bat is in range 0 to 100
|
||||||
|
* volt is optional and should be greater than 0
|
||||||
|
|
||||||
|
## find phone
|
||||||
|
|
||||||
|
```
|
||||||
|
{ "t": "findPhone", "n": true }
|
||||||
|
```
|
||||||
|
|
||||||
|
n is an boolean and toggles the find phone function
|
||||||
|
|
||||||
|
## control music player
|
||||||
|
|
||||||
|
```
|
||||||
|
{ "t": "music", "n": "play" }
|
||||||
|
```
|
||||||
|
|
||||||
|
n can be one of "play", "pause", "playpause", "next", "previous", "volumeup", "volumedown", "forward", "rewind"
|
||||||
|
|
||||||
|
## control phone call
|
||||||
|
|
||||||
|
```
|
||||||
|
{ "t": "call", "n": "accept"}
|
||||||
|
```
|
||||||
|
|
||||||
|
n can be one of "accept", "end", "incoming", "outcoming", "reject", "start", "ignore"
|
||||||
|
|
||||||
|
## react to notifications
|
||||||
|
|
||||||
|
Send a response to a notification from phone
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "notify",
|
||||||
|
"n": "dismiss",
|
||||||
|
"id": 2,
|
||||||
|
"tel": "+491234",
|
||||||
|
"msg": "message",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* n can be one of "dismiss", "dismiss all", "open", "mute", "reply"
|
||||||
|
* id, tel and message are optional
|
||||||
|
|
||||||
|
# Phone -> Watch
|
||||||
|
|
||||||
|
## show notification
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "notify",
|
||||||
|
"id": 2,
|
||||||
|
"src": "app",
|
||||||
|
"title": "titel",
|
||||||
|
"subject": "subject",
|
||||||
|
"body": "message body",
|
||||||
|
"sender": "sender",
|
||||||
|
"tel": "+491234"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## notification deleted
|
||||||
|
|
||||||
|
This event is send when the user skipped a notification
|
||||||
|
|
||||||
|
```
|
||||||
|
{ "t": "notify-", "id": 2 }
|
||||||
|
```
|
||||||
|
|
||||||
|
## set alarm
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "alarm",
|
||||||
|
"d": [
|
||||||
|
{ "h": 13, "m": 37 },
|
||||||
|
{ "h": 8, "m": 0 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## call state changed
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "call",
|
||||||
|
"cmd": "accept",
|
||||||
|
"name": "name",
|
||||||
|
"number": "+491234"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
cmd can be one of "", "undefined", "accept", "incoming", "outgoing", "reject", "start", "end"
|
||||||
|
|
||||||
|
## music state changed
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "musicstate",
|
||||||
|
"state": "play",
|
||||||
|
"position": 40,
|
||||||
|
"shuffle": 0,
|
||||||
|
"repeat": 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## set music info
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "musicinfo",
|
||||||
|
"artist": "artist",
|
||||||
|
"album": "album",
|
||||||
|
"track": "track",
|
||||||
|
"dur": 1,
|
||||||
|
"c": 2,
|
||||||
|
"n" 3
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* dur is the duration of the track
|
||||||
|
* c is the track count
|
||||||
|
* n is the track number
|
||||||
|
|
||||||
|
## find device
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "find",
|
||||||
|
"n": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
n toggles find device functionality
|
||||||
|
|
||||||
|
## set constant vibration
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "vibrate",
|
||||||
|
"n": 2
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
n is the intensity
|
||||||
|
|
||||||
|
## send weather
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"t": "weather",
|
||||||
|
"temp": 10,
|
||||||
|
"hum": 71,
|
||||||
|
"txt": "condition",
|
||||||
|
"wind": 13,
|
||||||
|
"loc": "location"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* hum is the humidity
|
||||||
|
* txt is the weather condition
|
||||||
|
* loc is the location
|
|
@ -40,7 +40,7 @@
|
||||||
state.scrollPos = -size;
|
state.scrollPos = -size;
|
||||||
}
|
}
|
||||||
Bangle.setLCDOffset(state.scrollPos);
|
Bangle.setLCDOffset(state.scrollPos);
|
||||||
if (state.scrollPos > -size) setTimeout(anim, 10);
|
if (state.scrollPos > -size) setTimeout(anim, 15);
|
||||||
}
|
}
|
||||||
anim();
|
anim();
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,8 @@
|
||||||
|
|
||||||
g.setColor("#ffffff");
|
g.setColor("#ffffff");
|
||||||
g.setFont("6x8", 2);
|
g.setFont("6x8", 2);
|
||||||
g.drawString(event.title, x, y + 25);
|
if (event.title)
|
||||||
|
g.drawString(event.title.slice(0,17), x, y + 25);
|
||||||
|
|
||||||
g.setFont("6x8", 1);
|
g.setFont("6x8", 1);
|
||||||
g.setColor("#ffffff");
|
g.setColor("#ffffff");
|
||||||
|
|
|
@ -5,32 +5,9 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="tracks"></div>
|
<div id="tracks"></div>
|
||||||
|
|
||||||
<div class="modal active" id="status-modal">
|
|
||||||
<div class="modal-overlay"></div>
|
|
||||||
<div class="modal-container">
|
|
||||||
<div class="modal-header">
|
|
||||||
<div class="modal-title h5">Please wait</div>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<div class="content">
|
|
||||||
Loading...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="../../lib/interface.js"></script>
|
<script src="../../lib/interface.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var domTracks = document.getElementById("tracks");
|
var domTracks = document.getElementById("tracks");
|
||||||
var domModal = document.getElementById("status-modal");
|
|
||||||
|
|
||||||
function showModal(title) {
|
|
||||||
domModal.querySelector(".content").innerHTML = title;
|
|
||||||
domModal.classList.add("active");
|
|
||||||
}
|
|
||||||
function hideModal(title) {
|
|
||||||
domModal.classList.remove("active");
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveKML(track,title) {
|
function saveKML(track,title) {
|
||||||
var kml = `<?xml version="1.0" encoding="UTF-8"?>
|
var kml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
@ -107,19 +84,15 @@ function trackLineToObject(l, hasTrackNumber) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadTrack(trackid, callback) {
|
function downloadTrack(trackid, callback) {
|
||||||
showModal("Downloading Track...");
|
Util.showModal("Downloading Track...");
|
||||||
Puck.write(`\x10(function() {
|
Util.readStorageFile(`.gpsrc${trackid.toString(36)}`,data=>{
|
||||||
var f = require("Storage").open(".gpsrc${trackid.toString(36)}","r");
|
Util.hideModal();
|
||||||
var l = f.readLine();
|
var track = data.trim().split("\n").map(l=>trackLineToObject(l,false));
|
||||||
while (l!==undefined) { Bluetooth.print(l); l = f.readLine(); }
|
|
||||||
})()\n`,tracklist=>{
|
|
||||||
hideModal();
|
|
||||||
var track = tracklist.trim().split("\n").map(l=>trackLineToObject(l,false));
|
|
||||||
callback(track);
|
callback(track);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getTrackList() {
|
function getTrackList() {
|
||||||
showModal("Loading Tracks...");
|
Util.showModal("Loading Tracks...");
|
||||||
domTracks.innerHTML = "";
|
domTracks.innerHTML = "";
|
||||||
Puck.write(`\x10(function() {
|
Puck.write(`\x10(function() {
|
||||||
for (var n=0;n<36;n++) {
|
for (var n=0;n<36;n++) {
|
||||||
|
@ -171,7 +144,7 @@ function getTrackList() {
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
domTracks.innerHTML = html;
|
domTracks.innerHTML = html;
|
||||||
hideModal();
|
Util.hideModal();
|
||||||
var buttons = domTracks.querySelectorAll("button");
|
var buttons = domTracks.querySelectorAll("button");
|
||||||
for (var i=0;i<buttons.length;i++) {
|
for (var i=0;i<buttons.length;i++) {
|
||||||
buttons[i].addEventListener("click",event => {
|
buttons[i].addEventListener("click",event => {
|
||||||
|
@ -179,9 +152,9 @@ function getTrackList() {
|
||||||
var trackid = parseInt(button.getAttribute("trackid"));
|
var trackid = parseInt(button.getAttribute("trackid"));
|
||||||
var task = button.getAttribute("task");
|
var task = button.getAttribute("task");
|
||||||
if (task=="delete") {
|
if (task=="delete") {
|
||||||
showModal("Deleting Track...");
|
Util.showModal("Deleting Track...");
|
||||||
Puck.write(`\x10require("Storage").open(".gpsrc${trackid.toString(36)}","r").erase()\n`,()=>{
|
Util.eraseStorageFile(`.gpsrc${trackid.toString(36)}`,()=>{
|
||||||
hideModal();
|
Util.hideModal();
|
||||||
getTrackList();
|
getTrackList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwwhC/AFEEolAC6lN7vdDCcECwPd6guVGCYuDC4cCBQMikQXQJAMjkECmcyIx4XDmUjmYvLC4XUDARHBIoIWLgATCGQdA7tEonQC5ouDDYg0BOxgSEAggwKRwgUCC6ZIDSwoXNogWDDgNCAgIWIkUEoUk6kiCgMkokipsiBIQXIki2CAgNCAoYADC5Eic4Mic4ICCAIIJCC5MzAAcykYGEAAIXOABAXTmUzGoIXVAIIXLB4SICDIovjO76PZbYR3PDI4XiI6530MIh3SC6R33C/oAOC48CCxsgC44A/ADY="))
|
|
@ -0,0 +1,163 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h4>List of products</h4>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>name</th>
|
||||||
|
<th>quantity</th>
|
||||||
|
<th>actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="products">
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br><br>
|
||||||
|
<h4>Add a new product</h4>
|
||||||
|
<form id="add_product_form">
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column col-4 col-xs-12">
|
||||||
|
<input class="form-input input-sm" type="text" id="add_product_name" placeholder="Name">
|
||||||
|
</div>
|
||||||
|
<div class="column col-4 col-xs-12">
|
||||||
|
<input class="form-input input-sm" value="1" type="number" id="add_product_quantity" placeholder="Quantity">
|
||||||
|
</div>
|
||||||
|
<div class="column col-4 col-xs-12">
|
||||||
|
<button id="add_product_button" class="btn btn-primary btn-sm">Add</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<br><br>
|
||||||
|
<button id="reset" class="btn btn-error">Reset</button> <button id="upload" class="btn btn-primary">Upload</button>
|
||||||
|
|
||||||
|
<script src="../../lib/customize.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
var products = []
|
||||||
|
try{
|
||||||
|
var stored = localStorage.getItem('grocery-product-list')
|
||||||
|
if(stored) products = JSON.parse(stored);
|
||||||
|
}catch(e){}
|
||||||
|
|
||||||
|
var $name = document.getElementById('add_product_name')
|
||||||
|
var $form = document.getElementById('add_product_form')
|
||||||
|
var $button = document.getElementById('add_product_button')
|
||||||
|
var $quantity = document.getElementById('add_product_quantity')
|
||||||
|
var $list = document.getElementById('products')
|
||||||
|
var $reset = document.getElementById('reset')
|
||||||
|
|
||||||
|
renderProducts()
|
||||||
|
|
||||||
|
$reset.addEventListener('click', reset)
|
||||||
|
|
||||||
|
$form.addEventListener('submit', event => {
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
var name = $name.value.trim()
|
||||||
|
if(!name) return;
|
||||||
|
|
||||||
|
var quantity = parseInt($quantity.value)
|
||||||
|
|
||||||
|
products.push({
|
||||||
|
name, quantity,
|
||||||
|
ok: false
|
||||||
|
})
|
||||||
|
|
||||||
|
renderProducts()
|
||||||
|
$name.value = ''
|
||||||
|
$quantity.value = 1
|
||||||
|
save()
|
||||||
|
})
|
||||||
|
|
||||||
|
function save(){
|
||||||
|
localStorage.setItem('grocery-product-list',JSON.stringify(products));
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset(){
|
||||||
|
products = []
|
||||||
|
save()
|
||||||
|
renderProducts()
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeProduct(index){
|
||||||
|
products = products.filter((p,i) => i!==index)
|
||||||
|
save()
|
||||||
|
renderProducts()
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderProducts(){
|
||||||
|
$list.innerHTML = ''
|
||||||
|
products.forEach((product,index) => {
|
||||||
|
var $product = document.createElement('tr')
|
||||||
|
|
||||||
|
$product.innerHTML = `<td>${product.name}</td><td>${product.quantity}</td><td><button class="btn btn-error" onclick="removeProduct(${index})">remove</button></td>`
|
||||||
|
$list.appendChild($product)
|
||||||
|
})
|
||||||
|
|
||||||
|
$name.focus()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("upload").addEventListener("click", function() {
|
||||||
|
|
||||||
|
|
||||||
|
var app = `
|
||||||
|
var newTime = ${Date.now()}
|
||||||
|
var products = ${JSON.stringify(products)}
|
||||||
|
var newTime = newTime;
|
||||||
|
var filename = 'grocery';
|
||||||
|
var settings = require("Storage").readJSON(filename,1)|| null;
|
||||||
|
function getSettings(){
|
||||||
|
return {
|
||||||
|
products : products,
|
||||||
|
date: newTime
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if(!settings || !settings.date || settings.date < newTime){
|
||||||
|
settings = getSettings();
|
||||||
|
Bangle.buzz(500);
|
||||||
|
}
|
||||||
|
function updateSettings() {
|
||||||
|
require("Storage").writeJSON(filename, settings);
|
||||||
|
Bangle.buzz();
|
||||||
|
}
|
||||||
|
function twoChat(n){
|
||||||
|
if(n<10) return '0'+n;
|
||||||
|
return ''+n;
|
||||||
|
}
|
||||||
|
const mainMenu = settings.products.reduce(function(m, p, i){
|
||||||
|
const name = twoChat(p.quantity)+' '+p.name;
|
||||||
|
m[name] = {
|
||||||
|
value: p.ok,
|
||||||
|
format: v => v?'[x]':'[ ]',
|
||||||
|
onchange: v => {
|
||||||
|
settings.products[i].ok = v;
|
||||||
|
updateSettings();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return m;
|
||||||
|
}, {
|
||||||
|
'': { 'title': 'Grocery list' }
|
||||||
|
});
|
||||||
|
mainMenu['< Back'] = ()=>{load();};
|
||||||
|
E.showMenu(mainMenu);
|
||||||
|
`;
|
||||||
|
|
||||||
|
var icon = `require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AQ0QACF1nGAAIxpFoYwqFwwwnRggwGB4eFAggACLzwHCMAeF1WGAgOGw2x2IGCLzYGEF4YpBwotCFwJfWFwo1GSAYtBAIIABRq4vFMhAwBzoAFdzIuKAAOc4IAGGC4qEMZOiF44wXFxovleBYvIGCwmB0WjE4V/AgfG1IvCzujFQOjwoECF6WFwovBDYOFEwN/AgIwCAgOFBwYrBBAQEBzodCF6AAHww1CBpIODAAYvRDAWG2IEBAYYJFBxICCF6Ox1WxAAQfBAYQlCAAIOJAQIvUADQvn1WGR4RfbP4gAFBwgFCF7a5EdwQADF46/cL9wAQF94AGF85bB1TvmF47vdJ4bvFF8qPRFgLv/L7jPCaQq/fYYrvgJgoAGd/7v/F/4v/F5oAdF54weFyAA/AH4A3A="))`;
|
||||||
|
sendCustomizedApp({
|
||||||
|
storage:[
|
||||||
|
{name:"grocery.app.js", content:app},
|
||||||
|
{name:"grocery.img", content:icon, evaluate:true},
|
||||||
|
{name:"grocery"}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
After Width: | Height: | Size: 1.8 KiB |
|
@ -5,32 +5,9 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="records"></div>
|
<div id="records"></div>
|
||||||
|
|
||||||
<div class="modal active" id="status-modal">
|
|
||||||
<div class="modal-overlay"></div>
|
|
||||||
<div class="modal-container">
|
|
||||||
<div class="modal-header">
|
|
||||||
<div class="modal-name h5">Please wait</div>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<div class="content">
|
|
||||||
Loading...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="../../lib/interface.js"></script>
|
<script src="../../lib/interface.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var domRecords = document.getElementById("records");
|
var domRecords = document.getElementById("records");
|
||||||
var domModal = document.getElementById("status-modal");
|
|
||||||
|
|
||||||
function showModal(name) {
|
|
||||||
domModal.querySelector(".content").innerHTML = name;
|
|
||||||
domModal.classList.add("active");
|
|
||||||
}
|
|
||||||
function hideModal(name) {
|
|
||||||
domModal.classList.remove("active");
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveRecord(record,name) {
|
function saveRecord(record,name) {
|
||||||
var csv = `${record.map(rec=>[rec.time, rec.bpm, rec.confidence].join(",")).join("\n")}`;
|
var csv = `${record.map(rec=>[rec.time, rec.bpm, rec.confidence].join(",")).join("\n")}`;
|
||||||
|
@ -62,20 +39,16 @@ function recordLineToObject(l, hasRecordNbr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadRecord(recordNbr, callback) {
|
function downloadRecord(recordNbr, callback) {
|
||||||
showModal("Downloading heart rate record...");
|
Util.showModal("Downloading heart rate record...");
|
||||||
Puck.write(`\x10(function() {
|
Util.readStorageFile(`.heart${recordNbr.toString(36)}`,data=>{
|
||||||
var f = require("Storage").open(".heart${recordNbr.toString(36)}","r");
|
Util.hideModal();
|
||||||
var l = f.readLine();
|
var record = data.trim().split("\n").map(l=>recordLineToObject(l,false));
|
||||||
while (l!==undefined) { Bluetooth.print(l); l = f.readLine(); }
|
|
||||||
})()\n`,recordList=>{
|
|
||||||
hideModal();
|
|
||||||
var record = recordList.trim().split("\n").map(l=>recordLineToObject(l,false));
|
|
||||||
callback(record);
|
callback(record);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRecordList() {
|
function getRecordList() {
|
||||||
showModal("Loading heart rate records...");
|
Util.showModal("Loading heart rate records...");
|
||||||
domRecords.innerHTML = "";
|
domRecords.innerHTML = "";
|
||||||
Puck.write(`\x10(function() {
|
Puck.write(`\x10(function() {
|
||||||
for (var n=0;n<36;n++) {
|
for (var n=0;n<36;n++) {
|
||||||
|
@ -118,7 +91,7 @@ function getRecordList() {
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
domRecords.innerHTML = html;
|
domRecords.innerHTML = html;
|
||||||
hideModal();
|
Util.hideModal();
|
||||||
var buttons = domRecords.querySelectorAll("button");
|
var buttons = domRecords.querySelectorAll("button");
|
||||||
for (var i=0;i<buttons.length;i++) {
|
for (var i=0;i<buttons.length;i++) {
|
||||||
buttons[i].addEventListener("click",event => {
|
buttons[i].addEventListener("click",event => {
|
||||||
|
@ -126,9 +99,9 @@ function getRecordList() {
|
||||||
var recordNbr = parseInt(button.getAttribute("recordNbr"));
|
var recordNbr = parseInt(button.getAttribute("recordNbr"));
|
||||||
var task = button.getAttribute("task");
|
var task = button.getAttribute("task");
|
||||||
if (task=="delete") {
|
if (task=="delete") {
|
||||||
showModal("Deleting record...");
|
Util.showModal("Deleting record...");
|
||||||
Puck.write(`\x10require("Storage").open(".heart${recordNbr.toString(36)}","r").erase()\n`,()=>{
|
Util.eraseStorageFile(`.heart${recordNbr.toString(36)}`,()=>{
|
||||||
hideModal();
|
Util.hideModal();
|
||||||
getRecordList();
|
getRecordList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,6 @@
|
||||||
0.01: New App!
|
0.01: New App!
|
||||||
|
0.02: Fix locale.currencySym
|
||||||
|
0.03: Fix global 'locale' variable
|
||||||
|
0.04: Add function meridian
|
||||||
|
0.05: Inline locale details - faster, less memory overhead
|
||||||
|
Add correct scaling for speed/distance/temperature
|
||||||
|
|
|
@ -15,9 +15,55 @@
|
||||||
<script src="locales.js"></script>
|
<script src="locales.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
/*
|
||||||
|
eg. the built-in en_GB is:
|
||||||
|
|
||||||
|
exports = { name : "en_GB", currencySym:"£",
|
||||||
|
translate : str=>str, // as-is
|
||||||
|
date : (d,short) => short?("0"+d.getDate()).substr(-2)+"/"+("0"+(d.getMonth()+1)).substr(-2)+"/"+d.getFullYear():d.toString().substr(4,11), // Date to "Feb 28 2020" or "28/02/2020"(short)
|
||||||
|
time : (d,short) => { // Date to "4:15.28 pm" or "15:42"(short)
|
||||||
|
if (short)
|
||||||
|
return d.toString().substr(16,5);
|
||||||
|
else {
|
||||||
|
var h = d.getHours(), m = d.getMinutes(), r = "am";
|
||||||
|
if (h==0) { h=12; }
|
||||||
|
else if (h>=12) {
|
||||||
|
if (h>12) h-=12;
|
||||||
|
r = "pm";
|
||||||
|
}
|
||||||
|
return (" "+h).substr(-2)+":"+("0"+m).substr(-2)+"."+("0"+d.getSeconds()).substr(-2)+" "+r;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dow : (d,short) => short?d.toString().substr(0,3):"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(",")[d.getDay()], // Date to "Monday" or "Mon"(short)
|
||||||
|
month : (d,short) => short?d.toString().substr(4,3):"January,February,March,April,May,June,July,August,September,October,November,December".split(",")[d.getMonth()], // Date to "February" or "Feb"(short)
|
||||||
|
number : n => n.toString(), // more fancy?
|
||||||
|
currency : n => "£"+n.toFixed(2), // number to "£1.00"
|
||||||
|
distance : m => (m<1000)?Math.round(m)+"m":Math.round(m/160.934)/10+"mi", // meters to "123m" or "1.2mi" depending on size
|
||||||
|
speed : s => Math.round(s*0.621371)+"mph",// kph to "123mph"
|
||||||
|
temp : t => Math.round(t)+"'C" // degrees C to degrees C
|
||||||
|
meridian: d => (d.getHours() <= 12) ? "am":"pm",
|
||||||
|
};
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// do some sanity checks
|
||||||
|
Object.keys(locales).forEach(function(localeName) {
|
||||||
|
var locale = locales[localeName];
|
||||||
|
if (distanceUnits[locale.distance[0]]===undefined) console.error(localeName+": Unknown distance unit "+locale.distance[0]);
|
||||||
|
if (distanceUnits[locale.distance[1]]===undefined) console.error(localeName+": Unknown distance unit "+locale.distance[1]);
|
||||||
|
if (speedUnits[locale.speed]===undefined) console.error(localeName+": Unknown speed unit "+locale.speed);
|
||||||
|
});
|
||||||
|
|
||||||
var languageSelector = document.getElementById("languages");
|
var languageSelector = document.getElementById("languages");
|
||||||
languageSelector.innerHTML = Object.keys(locales).map(l=>`<option value="${l}">${l}</option>`).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 `<option value="${l}">${icon}${l}</option>`
|
||||||
|
}).join("\n");
|
||||||
|
|
||||||
document.getElementById("upload").addEventListener("click", function() {
|
document.getElementById("upload").addEventListener("click", function() {
|
||||||
|
|
||||||
|
@ -30,22 +76,25 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function js(x) { return JSON.stringify(x); }
|
||||||
|
|
||||||
var replaceList = {
|
var replaceList = {
|
||||||
"%Y": "${d.getFullYear()}",
|
"%Y": "d.getFullYear()",
|
||||||
"%y": "${(d.getFullYear().toString()).substr(-2)}",
|
"%y": "(d.getFullYear().toString()).substr(-2)",
|
||||||
"%m": "${('0'+(d.getMonth()+1).toString()).substr(-2)}",
|
"%m": "('0'+(d.getMonth()+1).toString()).substr(-2)",
|
||||||
"%-m": "${d.getMonth()+1}",
|
"%-m": "d.getMonth()+1",
|
||||||
"%d": "${('0'+d.getDate()).substr(-2)}",
|
"%d": "('0'+d.getDate()).substr(-2)",
|
||||||
"%-d": "${d.getDate()}",
|
"%-d": "d.getDate()",
|
||||||
"%HH": "${('0'+d.getHours()).substr(-2)}",
|
"%HH": "('0'+d.getHours()).substr(-2)",
|
||||||
"%MM": "${('0'+d.getMinutes()).substr(-2)}",
|
"%MM": "('0'+d.getMinutes()).substr(-2)",
|
||||||
"%SS": "${('0'+d.getSeconds()).substr(-2)}",
|
"%SS": "('0'+d.getSeconds()).substr(-2)",
|
||||||
"%A": "${locale.day.split(',')[d.getDay()]}",
|
"%A": "l.day.split(',')[d.getDay()]",
|
||||||
"%a": "${locale.abday.split(',')[d.getDay()]}",
|
"%a": "l.abday.split(',')[d.getDay()]",
|
||||||
"%B": "${locale.month.split(',')[d.getMonth()]}",
|
"%B": "l.month.split(',')[d.getMonth()]",
|
||||||
"%b": "${locale.abmonth.split(',')[d.getMonth()]}",
|
"%b": "l.abmonth.split(',')[d.getMonth()]",
|
||||||
"%p": "${(d.getHours()<12)?locale.ampm[0].toUpperCase():locale.ampm[1].toUpperCase()}",
|
"%p": `(d.getHours()<12)?${js(locale.ampm[0].toUpperCase())}:${js(locale.ampm[1].toUpperCase())}`,
|
||||||
"%P": "${(d.getHours()<12)?locale.ampm[0].toLowerCase():locale.ampm[1].toLowerCase()}"
|
"%P": `(d.getHours()<12)?${js(locale.ampm[0].toLowerCase())}:${js(locale.ampm[1].toLowerCase())}`
|
||||||
};
|
};
|
||||||
|
|
||||||
var timeN = locales[lang].timePattern[0];
|
var timeN = locales[lang].timePattern[0];
|
||||||
|
@ -53,33 +102,51 @@
|
||||||
var dateN = locales[lang].datePattern[0];
|
var dateN = locales[lang].datePattern[0];
|
||||||
var dateS = locales[lang].datePattern[1];
|
var dateS = locales[lang].datePattern[1];
|
||||||
Object.keys(replaceList).forEach(e => {
|
Object.keys(replaceList).forEach(e => {
|
||||||
timeN = timeN.replace(e,replaceList[e]);
|
timeN = timeN.replace(e,"${"+replaceList[e]+"}");
|
||||||
timeS = timeS.replace(e,replaceList[e]);
|
timeS = timeS.replace(e,"${"+replaceList[e]+"}");
|
||||||
dateN = dateN.replace(e,replaceList[e]);
|
dateN = dateN.replace(e,"${"+replaceList[e]+"}");
|
||||||
dateS = dateS.replace(e,replaceList[e]);
|
dateS = dateS.replace(e,"${"+replaceList[e]+"}");
|
||||||
});
|
});
|
||||||
|
var currency = locale.currency_first ?
|
||||||
|
`${js(locale.currency_symbol)} + n.toFixed(2)`:
|
||||||
|
`n.toFixed(2) + ${js(locale.currency_symbol)}`;
|
||||||
|
var temperature;
|
||||||
|
if (locale.temperature=='°C') temperature="t";
|
||||||
|
else if (locale.temperature=='°F') temperature="(t*9/5)+32";
|
||||||
|
else throw new Error("Unknown temperature unit "+locale.temperature);
|
||||||
|
|
||||||
|
var localeModule = `var l = ${JSON.stringify({
|
||||||
|
abday : locale.abday,
|
||||||
|
day : locale.day,
|
||||||
|
abmonth : locale.abmonth,
|
||||||
|
month : locale.month,
|
||||||
|
})};
|
||||||
|
exports = {
|
||||||
|
name: ${js(locale.lang)},
|
||||||
|
currencySym: ${js(locale.currency_symbol)},
|
||||||
|
dow: (d,short) => {day = d.getDay();return (short) ? l.abday.split(",")[day] : l.day.split(",")[day];},
|
||||||
|
month: (d,short) => { month = d.getMonth(); return (short) ? l.abmonth.split(",")[month] : l.month.split(",")[month];},
|
||||||
|
number: n => n.toString(),
|
||||||
|
currency: n => ${currency},
|
||||||
|
distance: n => (n < ${distanceUnits[locale.distance[1]]}) ? Math.round(n/${distanceUnits[locale.distance[0]]}) + ${js(locale.distance[0])} : Math.round(n/${distanceUnits[locale.distance[1]]}) + ${js(locale.distance[1])},
|
||||||
|
speed: s => Math.round(s/${speedUnits[locale.speed]}) + ${js(locale.speed)},
|
||||||
|
temp: t => Math.round(${temperature}) + ${js(locale.temperature)},
|
||||||
|
translate: s => {var t=${js(locale.trans)};s=""+s;return t[s]||t[s.toLowerCase()]||s;},
|
||||||
|
date: (d,short) => (short) ? \`${dateS}\`: \`${dateN}\`,
|
||||||
|
time: (d,short) => (short) ? \`${timeS}\`: \`${timeN}\`,
|
||||||
|
meridian: d => (d.getHours() <= 12) ? ${js(locale.ampm[0])}:${js(locale.ampm[1])},
|
||||||
|
};`;
|
||||||
|
console.log("Locale Module is:",localeModule);
|
||||||
|
/*
|
||||||
|
FIXME:
|
||||||
|
|
||||||
var app = `
|
* Number/Currency need to add thousands separators: .replace(${js(locale.thousands_sep)}, ${js(locale.decimal_point)}) won't cut it as toString doesn't add separators itself
|
||||||
locale = ${JSON.stringify(locales[lang])};
|
* distance (and speed) should probably use 1 decimal point for numbers less than 10
|
||||||
exports = {
|
*/
|
||||||
lang: locale.lang,
|
|
||||||
currencySym: String.fromCharCode(locale.currency_symbol),
|
|
||||||
dow: (d,short) => {day = d.getDay();return (short) ? locale.abday.split(",")[day] : locale.day.split(",")[day];},
|
|
||||||
month: (d,short) => { month = d.getMonth(); return (short) ? locale.abmonth.split(",")[month] : locale.month.split(",")[month];},
|
|
||||||
number: n => n.toString().replace(locale.thousands_sep, locale.decimal_point),
|
|
||||||
currency: n => n.toFixed(2).replace(locale.thousands_sep, locale.decimal_point) + locale.currency_symbol,
|
|
||||||
distance: n => (n < 1000) ? Math.round(n) + locale.distance[0] : Math.round(n/1000) + locale.distance[1],
|
|
||||||
speed: s => Math.round(s) +locale.speed,
|
|
||||||
temp: t => Math.round(t) + locale.temperature,
|
|
||||||
translate: s => {s=""+s;return locale.trans[s]||locale.trans[s.toLowerCase()]||s},
|
|
||||||
date: (d,short) => (short) ? \`${dateS}\`: \`${dateN}\`,
|
|
||||||
time: (d,short) => (short) ? \`${timeS}\`: \`${timeN}\`,
|
|
||||||
};`;
|
|
||||||
|
|
||||||
sendCustomizedApp({
|
sendCustomizedApp({
|
||||||
storage:[
|
storage:[
|
||||||
{name:"locale", content:app}
|
{name:"locale", content:localeModule}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,20 @@
|
||||||
|
|
||||||
|
const distanceUnits = { // how many meters per X?
|
||||||
|
"m" : 1,
|
||||||
|
"yd" : 0.9144,
|
||||||
|
"mi" : 1609.34,
|
||||||
|
"km" : 1000,
|
||||||
|
"kmi" : 1000
|
||||||
|
};
|
||||||
|
const speedUnits = { // how many kph per X?
|
||||||
|
"kmh" : 1,
|
||||||
|
"kph" : 1,
|
||||||
|
"mph" : 1.60934
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
timePattern / datePattern:
|
||||||
|
|
||||||
%Y year four digits
|
%Y year four digits
|
||||||
%y last two digits of year (00..99)
|
%y last two digits of year (00..99)
|
||||||
%m month (01..12)
|
%m month (01..12)
|
||||||
|
@ -21,10 +37,10 @@ var locales = {
|
||||||
lang: "en_GB",
|
lang: "en_GB",
|
||||||
decimal_point: ".",
|
decimal_point: ".",
|
||||||
thousands_sep: ",",
|
thousands_sep: ",",
|
||||||
currency_symbol: "£",
|
currency_symbol: "£", currency_first:true,
|
||||||
int_curr_symbol: "GBP",
|
int_curr_symbol: "GBP",
|
||||||
speed: 'mph',
|
speed: 'mph',
|
||||||
distance: { "0": "mi", "1": "kmi" },
|
distance: { "0": "yd", "1": "mi" },
|
||||||
temperature: '°C',
|
temperature: '°C',
|
||||||
ampm: {0:"am",1:"pm"},
|
ampm: {0:"am",1:"pm"},
|
||||||
timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
|
timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
|
||||||
|
@ -55,10 +71,10 @@ var locales = {
|
||||||
lang: "en_US",
|
lang: "en_US",
|
||||||
decimal_point: ".",
|
decimal_point: ".",
|
||||||
thousands_sep: ",",
|
thousands_sep: ",",
|
||||||
currency_symbol: "$",
|
currency_symbol: "$", currency_first:true,
|
||||||
int_curr_symbol: "USD",
|
int_curr_symbol: "USD",
|
||||||
speed: "mph",
|
speed: "mph",
|
||||||
distance: { 0: "mi", 1: "kmi" },
|
distance: { 0: "yd", 1: "mi" },
|
||||||
temperature: "°F",
|
temperature: "°F",
|
||||||
ampm: {0:"am",1:"pm"},
|
ampm: {0:"am",1:"pm"},
|
||||||
timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
|
timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
|
||||||
|
@ -348,10 +364,27 @@ var locales = {
|
||||||
temperature: '°C',
|
temperature: '°C',
|
||||||
ampm: {0:"de",1:"du"},
|
ampm: {0:"de",1:"du"},
|
||||||
timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
|
timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
|
||||||
datePattern: { 0: "%Y %d %b", 1: "%Y.%m.%d" }, // 2020 Feb 28" // "2020.03.01."(short)
|
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",
|
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",
|
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",
|
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",
|
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" }},
|
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" }},
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
0.01: Create mario app
|
||||||
|
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
|
|
@ -0,0 +1,384 @@
|
||||||
|
/**********************************
|
||||||
|
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
|
||||||
|
**********************************/
|
||||||
|
|
||||||
|
const locale = require("locale");
|
||||||
|
const storage = require('Storage');
|
||||||
|
const settings = (storage.readJSON('setting.json', 1) || {});
|
||||||
|
const timeout = settings.timeout || 10;
|
||||||
|
const is12Hour = settings["12hour"] || false;
|
||||||
|
|
||||||
|
// Screen dimensions
|
||||||
|
let W, H;
|
||||||
|
|
||||||
|
let intervalRef, displayTimeoutRef = null;
|
||||||
|
|
||||||
|
// Space to draw watch widgets (e.g battery, bluetooth status)
|
||||||
|
const WIDGETS_GUTTER = 10;
|
||||||
|
|
||||||
|
// Colours
|
||||||
|
const LIGHTEST = "#effedd";
|
||||||
|
const LIGHT = "#add795";
|
||||||
|
const DARK = "#588d77";
|
||||||
|
const DARKEST = "#122d3e";
|
||||||
|
|
||||||
|
// Mario Images
|
||||||
|
const marioRunningImage1 = {
|
||||||
|
width : 15, height : 20, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("B8AfwH+B/8f/z4M+KExcnAUSCw87w4L8CJQRNB/YH+AxgCEAPAA="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const marioRunningImage1Neg = {
|
||||||
|
width : 15, height : 20, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("AAAAAAAAAAAAAHwB0DOgY/jt8PDAPAEAB2gOyAAgAAAOAB4AAAA="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const marioRunningImage2 = {
|
||||||
|
width : 15, height : 20, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("B8AfwH+B/8f/z4M+KExcnAUSCw87w4J6BEsPnSfyT+S+OMAAAAA="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const marioRunningImage2Neg = {
|
||||||
|
width : 15, height : 20, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("AAAAAAAAAAAAAHwB0DOgY/jt8PDAPAGEA7QAYhgMMBhAAAAAAAA="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const pyramid = {
|
||||||
|
width : 20, height : 20, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAkAAQgAIEAEAgCAEBAAggAEQAAoAAE="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const pipe = {
|
||||||
|
width : 9, height : 6, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("/8BxaCRSCA=="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const floor = {
|
||||||
|
width : 8, height : 3, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("/6pE"))
|
||||||
|
};
|
||||||
|
|
||||||
|
const sky = {
|
||||||
|
width : 128, height : 30, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("VVVVVVVVVVVVVVVVVVVVVQAAAAAAAAAAAAAAAAAAAABVVVVVVVVVVVVVVVVVVVVVIiIiIiIiIiIiIiIiIiIiIlVVVVVVVVVVVVVVVVVVVVWIiIiIiIiIiIiIiIiIiIiIVVVVVVVVVVVVVVVVVVVVVSIiIiIiIiICIiIiIiIiIiJVVVVVVVVVAVVVVVVVVVVViIiIiIiIiACIiIiIiIiIiFVVVVVVVVQAVVVVVVVVVVUiIiIiIiIgACIiIiIiIiIiVVVVVVVVUAAVVVUBVVVVUKqqqqqqqggAKCqqAKqqqoBVUBVVVVQAABAVVABVVVUAIiACIiIgAAAgAiAAIiIiAFVABVVVUAAAUAVUABRVVQCqgAKCqqAAACAAAAAgCqoAVUABAVVAAAAAAAAAAAVQAKqAAACqoAAAAAAAAAACgABAAAAAUEAAAAAAAAAABQAAgAAAACAAAAAAAAAAAAIAAAAAAABQAAAAAAAAAAAEAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))
|
||||||
|
};
|
||||||
|
|
||||||
|
const brick = {
|
||||||
|
width : 21, height : 15, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("f//0AABoAAsAABgAAMAABgAAMAABgAAMAABgAAMAABoAAsAABf//wA=="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const flower = {
|
||||||
|
width : 7, height : 7, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("fY3wjW+OAA=="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const pipePlant = {
|
||||||
|
width : 9, height : 15, bpp : 1,
|
||||||
|
transparent : 0,
|
||||||
|
buffer : E.toArrayBuffer(atob("FBsNhsHDWPn/gOLQSKQSKQQ="))
|
||||||
|
};
|
||||||
|
|
||||||
|
const marioSprite = {
|
||||||
|
frameIdx: 0,
|
||||||
|
frames: [
|
||||||
|
marioRunningImage1,
|
||||||
|
marioRunningImage2
|
||||||
|
],
|
||||||
|
negFrames: [
|
||||||
|
marioRunningImage1Neg,
|
||||||
|
marioRunningImage2Neg
|
||||||
|
],
|
||||||
|
x: 35,
|
||||||
|
y: 55,
|
||||||
|
jumpCounter: 0,
|
||||||
|
jumpIncrement: Math.PI / 10,
|
||||||
|
isJumping: false
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATIC_TILES = {
|
||||||
|
"_": {img: floor, x: 16 * 8, y: 75},
|
||||||
|
"X": {img: sky, x: 0, y: 10},
|
||||||
|
"#": {img: brick, x: 0, y: 0},
|
||||||
|
};
|
||||||
|
|
||||||
|
const TILES = {
|
||||||
|
"T": {img: pipe, x: 16 * 8, y: 69},
|
||||||
|
"^": {img: pyramid, x: 16 * 8, y: 55},
|
||||||
|
"*": {img: flower, x: 16 * 8, y: 68},
|
||||||
|
"V": {img: pipePlant, x: 16 * 8, y: 60}
|
||||||
|
};
|
||||||
|
|
||||||
|
const ONE_SECOND = 1000;
|
||||||
|
|
||||||
|
let timer = 0;
|
||||||
|
let backgroundArr = [];
|
||||||
|
|
||||||
|
function incrementTimer() {
|
||||||
|
if (timer > 1000) {
|
||||||
|
timer = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timer += 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawTile(sprite) {
|
||||||
|
g.drawImage(sprite.img, sprite.x, sprite.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawBackground() {
|
||||||
|
g.setColor(LIGHTEST);
|
||||||
|
g.fillRect(0, 10, W, H);
|
||||||
|
|
||||||
|
// draw floor
|
||||||
|
g.setColor(DARK);
|
||||||
|
for (var x = 0; x < 16; x++) {
|
||||||
|
var floorSprite = Object.assign({}, STATIC_TILES._, {x: x * 8});
|
||||||
|
drawTile(floorSprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw sky
|
||||||
|
var skySprite = STATIC_TILES.X;
|
||||||
|
g.setColor(LIGHT);
|
||||||
|
drawTile(skySprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawScenery() {
|
||||||
|
// new random sprite
|
||||||
|
const spriteKeys = Object.keys(TILES);
|
||||||
|
const key = spriteKeys[Math.floor(Math.random() * spriteKeys.length)];
|
||||||
|
let newSprite = Object.assign({}, TILES[key]);
|
||||||
|
|
||||||
|
// remove first sprite if offscreen
|
||||||
|
let firstBackgroundSprite = backgroundArr[0];
|
||||||
|
if (firstBackgroundSprite) {
|
||||||
|
if (firstBackgroundSprite.x < -20) backgroundArr.splice(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set background sprite if array empty
|
||||||
|
var lastBackgroundSprite = backgroundArr[backgroundArr.length - 1];
|
||||||
|
if (!lastBackgroundSprite) {
|
||||||
|
lastBackgroundSprite = newSprite;
|
||||||
|
backgroundArr.push(lastBackgroundSprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add random sprites
|
||||||
|
if (backgroundArr.length < 6 && lastBackgroundSprite.x < (16 * 7)) {
|
||||||
|
var randIdx = Math.floor(Math.random() * 25);
|
||||||
|
if (randIdx < spriteKeys.length - 1) {
|
||||||
|
backgroundArr.push(newSprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x = 0; x < backgroundArr.length; x++) {
|
||||||
|
let scenerySprite = backgroundArr[x];
|
||||||
|
|
||||||
|
// clear sprite at previous position
|
||||||
|
g.setColor(LIGHTEST);
|
||||||
|
drawTile(scenerySprite);
|
||||||
|
|
||||||
|
// draw sprite in new position
|
||||||
|
g.setColor(LIGHT);
|
||||||
|
scenerySprite.x -= 5;
|
||||||
|
drawTile(scenerySprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawMario() {
|
||||||
|
// clear old mario frame
|
||||||
|
g.setColor(LIGHTEST);
|
||||||
|
g.drawImage(
|
||||||
|
marioSprite.negFrames[marioSprite.frameIdx],
|
||||||
|
marioSprite.x,
|
||||||
|
marioSprite.y
|
||||||
|
);
|
||||||
|
g.drawImage(
|
||||||
|
marioSprite.frames[marioSprite.frameIdx],
|
||||||
|
marioSprite.x,
|
||||||
|
marioSprite.y
|
||||||
|
);
|
||||||
|
|
||||||
|
// calculate jumping
|
||||||
|
const t = new Date(),
|
||||||
|
seconds = t.getSeconds(),
|
||||||
|
milliseconds = t.getMilliseconds();
|
||||||
|
|
||||||
|
if (seconds == 59 && milliseconds > 800 && !marioSprite.isJumping) {
|
||||||
|
marioSprite.isJumping = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (marioSprite.isJumping) {
|
||||||
|
marioSprite.y = (Math.sin(marioSprite.jumpCounter) * -10) + 50 /* Mario Y base value */;
|
||||||
|
marioSprite.jumpCounter += marioSprite.jumpIncrement;
|
||||||
|
|
||||||
|
if (marioSprite.jumpCounter.toFixed(1) >= 4) {
|
||||||
|
marioSprite.jumpCounter = 0;
|
||||||
|
marioSprite.isJumping = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate animation timing
|
||||||
|
if (timer % 100 === 0) {
|
||||||
|
// shift to next frame
|
||||||
|
marioSprite.frameIdx ^= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// colour in mario
|
||||||
|
g.setColor(LIGHT);
|
||||||
|
g.drawImage(
|
||||||
|
marioSprite.negFrames[marioSprite.frameIdx],
|
||||||
|
marioSprite.x,
|
||||||
|
marioSprite.y
|
||||||
|
);
|
||||||
|
|
||||||
|
// draw mario
|
||||||
|
g.setColor(DARKEST);
|
||||||
|
g.drawImage(
|
||||||
|
marioSprite.frames[marioSprite.frameIdx],
|
||||||
|
marioSprite.x,
|
||||||
|
marioSprite.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function drawBrick(x, y) {
|
||||||
|
const brickSprite = Object.assign({}, STATIC_TILES['#'], {x: x, y: y});
|
||||||
|
|
||||||
|
// draw brick background colour
|
||||||
|
g.setColor(LIGHT);
|
||||||
|
g.fillRect(x, y, x + 20, y+14);
|
||||||
|
|
||||||
|
// draw brick sprite
|
||||||
|
g.setColor(DARK);
|
||||||
|
drawTile(brickSprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawTime() {
|
||||||
|
// draw hour brick
|
||||||
|
drawBrick(20, 25);
|
||||||
|
// draw minute brick
|
||||||
|
drawBrick(42, 25);
|
||||||
|
|
||||||
|
const t = new Date();
|
||||||
|
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");
|
||||||
|
g.setColor(DARKEST);
|
||||||
|
g.drawString(hours, 25, 29);
|
||||||
|
g.drawString(mins, 47, 29);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawDate() {
|
||||||
|
g.setFont("6x8");
|
||||||
|
g.setColor(LIGHTEST);
|
||||||
|
let d = new Date();
|
||||||
|
let dateStr = locale.date(d, true);
|
||||||
|
dateStr = dateStr.replace(d.getFullYear(), "").trim().replace(/\/$/i,"");
|
||||||
|
dateStr = locale.dow(d, true) + " " + dateStr;
|
||||||
|
g.drawString(dateStr, (W - g.stringWidth(dateStr))/2, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function redraw() {
|
||||||
|
// Update timers
|
||||||
|
incrementTimer();
|
||||||
|
|
||||||
|
// Draw frame
|
||||||
|
drawScenery();
|
||||||
|
drawTime();
|
||||||
|
drawDate();
|
||||||
|
drawMario();
|
||||||
|
|
||||||
|
// Render new frame
|
||||||
|
g.flip();
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearTimers(){
|
||||||
|
if(intervalRef) {
|
||||||
|
clearInterval(intervalRef);
|
||||||
|
intervalRef = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(displayTimeoutRef) {
|
||||||
|
clearInterval(displayTimeoutRef);
|
||||||
|
displayTimeoutRef = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetDisplayTimeout() {
|
||||||
|
if (displayTimeoutRef) clearInterval(displayTimeoutRef);
|
||||||
|
|
||||||
|
displayTimeoutRef = setInterval(() => {
|
||||||
|
if (Bangle.isLCDOn()) Bangle.setLCDPower(false);
|
||||||
|
clearTimers();
|
||||||
|
}, ONE_SECOND * timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
function startTimers(){
|
||||||
|
if(intervalRef) clearTimers();
|
||||||
|
intervalRef = setInterval(redraw, 50);
|
||||||
|
|
||||||
|
resetDisplayTimeout();
|
||||||
|
|
||||||
|
drawBackground();
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main
|
||||||
|
function init() {
|
||||||
|
clearInterval();
|
||||||
|
|
||||||
|
// Initialise display
|
||||||
|
Bangle.setLCDMode("80x80");
|
||||||
|
g.clear();
|
||||||
|
|
||||||
|
// Store screen dimensions
|
||||||
|
W = g.getWidth();
|
||||||
|
H = g.getHeight();
|
||||||
|
|
||||||
|
// Get Mario to jump!
|
||||||
|
setWatch(() => {
|
||||||
|
if (intervalRef && !marioSprite.isJumping) marioSprite.isJumping = true;
|
||||||
|
resetDisplayTimeout();
|
||||||
|
}, BTN1, {repeat:true});
|
||||||
|
|
||||||
|
setWatch(() => {
|
||||||
|
Bangle.setLCDMode();
|
||||||
|
Bangle.showLauncher();
|
||||||
|
}, BTN2, {repeat:false,edge:"falling"});
|
||||||
|
|
||||||
|
Bangle.on('lcdPower', (on) => {
|
||||||
|
if (on) {
|
||||||
|
startTimers();
|
||||||
|
} else {
|
||||||
|
clearTimers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Bangle.on('faceUp',function(up){
|
||||||
|
if (up && !Bangle.isLCDOn()) {
|
||||||
|
clearTimers();
|
||||||
|
Bangle.setLCDPower(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
startTimers();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialise!
|
||||||
|
init();
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwxH+AAmBAEgrFAAZelFo+s1krAEgnBFwo5BBIIAi64nBSQgvnE4QvCwMAM4SRCXsAlFqwvGdsPXF5QHBRsYvJBYXWAD4vdw4ABF9gRBF8xYGF4plLF6xYMw4NBF74SBF9ocHAATvpFwgwOF6J9IFwwNIUIgvZFw4xGF7IABFxwwECxC/WE4gkCAALBMF64uHAYLvfC4xXDF4pflF4aPFBIQvZVo5bFAQYvIDQgvYFIjEFSIwvVAALwJGQyKGDQi/XSIYyDdhjvaYBIwNF8AwOF6LBHRoqVDXpIvUWQ4wGBpAvhSQaNHF7DCNdxwvcSIgRNF659GAAqUJF/4vIXAQGJBgy/hMxov/F6QARF/es64NBAD/XEwQvCqwvBBIYvhEgQvD/3+RoYAkFoOBFoIvqE4IvE/2BwMrAEgnBFwgACXsIADFo4ABeoIAjFQgA="))
|
After Width: | Height: | Size: 11 KiB |
|
@ -1 +1,2 @@
|
||||||
0.02: Modified for use with new bootloader and firmware
|
0.02: Modified for use with new bootloader and firmware
|
||||||
|
0.03: Localization
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
var locale = require("locale");
|
||||||
/* jshint esversion: 6 */
|
/* jshint esversion: 6 */
|
||||||
const Radius = { "center": 8, "hour": 78, "min": 95, "dots": 102 };
|
const Radius = { "center": 8, "hour": 78, "min": 95, "dots": 102 };
|
||||||
const Center = { "x": 120, "y": 132 };
|
const Center = { "x": 120, "y": 132 };
|
||||||
|
@ -16,6 +17,7 @@ function drawMixedClock() {
|
||||||
|
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
var dateArray = date.toString().split(" ");
|
var dateArray = date.toString().split(" ");
|
||||||
|
var isEn = locale.name.startsWith("en");
|
||||||
var point = [];
|
var point = [];
|
||||||
var minute = date.getMinutes();
|
var minute = date.getMinutes();
|
||||||
var hour = date.getHours();
|
var hour = date.getHours();
|
||||||
|
@ -25,10 +27,10 @@ function drawMixedClock() {
|
||||||
g.setColor(0x7be0);
|
g.setColor(0x7be0);
|
||||||
g.setFont("6x8", 2);
|
g.setFont("6x8", 2);
|
||||||
g.setFontAlign(-1, 0);
|
g.setFontAlign(-1, 0);
|
||||||
g.drawString(dateArray[0] + ' ', 4, 35, true);
|
g.drawString(locale.dow(date,true) + ' ', 4, 35, true);
|
||||||
g.drawString(' ' + dateArray[2], 4, 225, true);
|
g.drawString(isEn?(' ' + dateArray[2]):locale.month(date,true), 4, 225, true);
|
||||||
g.setFontAlign(1, 0);
|
g.setFontAlign(1, 0);
|
||||||
g.drawString(dateArray[1], 237, 35, true);
|
g.drawString(isEn?locale.month(date,true):(' ' + dateArray[2]), 237, 35, true);
|
||||||
g.drawString(dateArray[3], 237, 225, true);
|
g.drawString(dateArray[3], 237, 225, true);
|
||||||
|
|
||||||
// draw hour and minute dots
|
// draw hour and minute dots
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
0.01: New App!
|
||||||
|
0.02: Added GPS to obtain coordinates, added buttons
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwgIifh/wAod//wECgP//+AAoMHAoPgCwQFBDAUfw///AFBjkD//8AoMYgPnEgUQgPB/4qCgeB/YFDwHxGAeA+AFEvHAAocdAoQCBh4CBgJFBh4CBAoNwg4FBhHA+AIBgkcgJSBAoMIg5SBAoIpB/E58EGAoP8n4FD/8f8EDAoQvBgfANYOfAYPwAoP/4AtBAoWAgP4SARfBAoZYB/0/Aod/AgKJCBQSVCj4FBUIStFXIrFFaIrdGADYA=="))
|
|
@ -0,0 +1,353 @@
|
||||||
|
//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]))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// 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
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.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+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);
|
||||||
|
}
|
||||||
|
|
||||||
|
//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 = 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});
|
||||||
|
|
||||||
|
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() { //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();
|
After Width: | Height: | Size: 1.7 KiB |
|
@ -0,0 +1,2 @@
|
||||||
|
0.01: New Watch!
|
||||||
|
0.02: Changed colors for better readability and added current date
|
|
@ -29,17 +29,23 @@ function topLine() {
|
||||||
|
|
||||||
function bottomLine() {
|
function bottomLine() {
|
||||||
|
|
||||||
g.setColor(darkGreen);
|
//first line
|
||||||
g.fillRect(5, 175, 60, 185);
|
g.setColor(darkerGreen);
|
||||||
g.fillRect(67, 175, 140, 185);
|
g.fillRect(5, 175, 100, 185); //DATE
|
||||||
|
g.fillRect(105, 175, 160, 185);//STIM
|
||||||
|
g.fillRect(166, 175, 239, 185); // RADAWAY
|
||||||
|
|
||||||
|
g.setColor(green);
|
||||||
|
g.setFont("6x8", tinyFont);
|
||||||
|
g.drawString("DATE", 20, 177);
|
||||||
|
g.drawString("STIM (3)", 135, 177);
|
||||||
|
g.drawString("RADAWAY (8)", 205, 177);
|
||||||
|
|
||||||
|
//second line
|
||||||
g.setColor(darkerGreen);
|
g.setColor(darkerGreen);
|
||||||
g.fillRect(5, 190, 70, 200);
|
g.fillRect(5, 190, 70, 200);
|
||||||
g.fillRect(75, 190, 239, 200);
|
g.fillRect(75, 190, 239, 200);
|
||||||
|
|
||||||
g.setFont("6x8", tinyFont);
|
|
||||||
g.drawString("STIM (0)", 32, 177);
|
|
||||||
g.drawString("RADAWAY (0)", 105, 177);
|
|
||||||
g.setColor(green);
|
g.setColor(green);
|
||||||
g.drawString("HP 115/115", 38, 192);
|
g.drawString("HP 115/115", 38, 192);
|
||||||
g.drawString("LEVEL 6", 100, 192);
|
g.drawString("LEVEL 6", 100, 192);
|
||||||
|
@ -55,7 +61,15 @@ function drawClock() {
|
||||||
var t = new Date();
|
var t = new Date();
|
||||||
var h = t.getHours();
|
var h = t.getHours();
|
||||||
var m = t.getMinutes();
|
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 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;
|
||||||
|
|
||||||
g.setFont("6x8",bigFont);
|
g.setFont("6x8",bigFont);
|
||||||
g.setColor(green);
|
g.setColor(green);
|
||||||
|
@ -63,6 +77,10 @@ function drawClock() {
|
||||||
|
|
||||||
g.clearRect(0, 110, 150, 140);
|
g.clearRect(0, 110, 150, 140);
|
||||||
g.drawString(time, 70, 110);
|
g.drawString(time, 70, 110);
|
||||||
|
|
||||||
|
//draw date
|
||||||
|
g.setFont("6x8", tinyFont);
|
||||||
|
g.drawString(date, 67, 177);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawAll() {
|
function drawAll() {
|
||||||
|
@ -83,4 +101,3 @@ setInterval(drawClock, 1E4);
|
||||||
drawAll();
|
drawAll();
|
||||||
|
|
||||||
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
|
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
0.01: First release
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwwgMJgMQgMZzOREaERiERzIACiIVOAIIUCz///ORgIXNIQIAC/4ABJJYsBCogYEAYMQiAWGLAoAJJI8JLAYoCAAgJBJIIwGBohxBJI4YBJIwOFC4w5EC4hdOzIgCyLFDC45hHAAZJDgJAKMQwyBSYSOBxIXGPRTdChOfxChHbpRhBC4P5GAgAOgEZFAKjIBAz1EC5YYJxAvBJ4IXQzGIxEQB4RbPCoOIwEAOKAsCC4QvCFiAXDdwwsMC5eebogVGAALWBC42f/AWLC4zwCUgIEBCxK+DE4bsFC5+f/IrBC4RzHXwkZzATEDgP/RZAXFz5ECf4oXMCYKICC6hABMAQXOgAXBLgLrHRxZfCC6sBCo4XLLwIXBbAgXRMIQAGRxgwChIXVgEQIYimOGAZ6CSgOJC6CrCC4TZBC6IwCC4QWQPQYXKOggAFPQOfC5AWKPQgXGCpR6FOwoWOPQQXDIZYwHC4QVRAAQXBBxgA="))
|
|
@ -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"});
|
After Width: | Height: | Size: 6.3 KiB |
|
@ -0,0 +1,5 @@
|
||||||
|
0.01: Original App
|
||||||
|
0.02: Lap log now counts up from 1
|
||||||
|
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
|
|
@ -4,6 +4,7 @@ var started = false;
|
||||||
var timeY = 60;
|
var timeY = 60;
|
||||||
var hsXPos = 0;
|
var hsXPos = 0;
|
||||||
var lapTimes = [];
|
var lapTimes = [];
|
||||||
|
var saveTimes = [];
|
||||||
var displayInterval;
|
var displayInterval;
|
||||||
|
|
||||||
function timeToText(t) {
|
function timeToText(t) {
|
||||||
|
@ -17,12 +18,15 @@ function updateLabels() {
|
||||||
g.setFont("6x8",2);
|
g.setFont("6x8",2);
|
||||||
g.setFontAlign(0,0,3);
|
g.setFontAlign(0,0,3);
|
||||||
g.drawString(started?"STOP":"GO",230,120);
|
g.drawString(started?"STOP":"GO",230,120);
|
||||||
if (!started) g.drawString("RESET",230,50);
|
if (!started) g.drawString("RESET",230,190);
|
||||||
g.drawString("LAP",230,190);
|
g.drawString(started?"LAP":"SAVE",230,50);
|
||||||
g.setFont("6x8",1);
|
g.setFont("6x8",1);
|
||||||
g.setFontAlign(-1,-1);
|
g.setFontAlign(-1,-1);
|
||||||
for (var i in lapTimes) {
|
for (var i in lapTimes) {
|
||||||
g.drawString(i+": "+timeToText(lapTimes[i]),10,timeY + 30 + i*8);
|
if (i<18)
|
||||||
|
{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);}
|
||||||
}
|
}
|
||||||
drawsecs();
|
drawsecs();
|
||||||
}
|
}
|
||||||
|
@ -47,6 +51,11 @@ function drawms() {
|
||||||
g.clearRect(hsXPos,timeY,220,timeY+20);
|
g.clearRect(hsXPos,timeY,220,timeY+20);
|
||||||
g.drawString("."+("0"+hs).substr(-2),hsXPos,timeY+10);
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setWatch(function() { // Start/stop
|
setWatch(function() { // Start/stop
|
||||||
started = !started;
|
started = !started;
|
||||||
|
@ -69,19 +78,25 @@ setWatch(function() { // Start/stop
|
||||||
drawms();
|
drawms();
|
||||||
}, 20);
|
}, 20);
|
||||||
}, BTN2, {repeat:true});
|
}, BTN2, {repeat:true});
|
||||||
setWatch(function() { // Reset
|
|
||||||
Bangle.beep();
|
|
||||||
if (!started) {
|
|
||||||
tStart = tCurrent = Date.now();
|
|
||||||
}
|
|
||||||
lapTimes = [];
|
|
||||||
updateLabels();
|
|
||||||
}, BTN1, {repeat:true});
|
|
||||||
setWatch(function() { // Lap
|
setWatch(function() { // Lap
|
||||||
Bangle.beep();
|
Bangle.beep();
|
||||||
if (started) tCurrent = Date.now();
|
if (started) tCurrent = Date.now();
|
||||||
lapTimes.unshift(tCurrent-tStart);
|
lapTimes.unshift(tCurrent-tStart);
|
||||||
tStart = tCurrent;
|
tStart = tCurrent;
|
||||||
|
if (!started)
|
||||||
|
{
|
||||||
|
var timenow= Date();
|
||||||
|
saveconvert();
|
||||||
|
require("Storage").writeJSON("StpWch-"+timenow.toString(), saveTimes);
|
||||||
|
}
|
||||||
|
updateLabels();
|
||||||
|
}, BTN1, {repeat:true});
|
||||||
|
setWatch(function() { // Reset
|
||||||
|
if (!started) {
|
||||||
|
Bangle.beep();
|
||||||
|
tStart = tCurrent = Date.now();
|
||||||
|
lapTimes = [];
|
||||||
|
}
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}, BTN3, {repeat:true});
|
}, BTN3, {repeat:true});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
0.01: New App!
|
||||||
|
0.02: Add swipe support and doucle tap to run application
|
|
@ -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.name<b.name) return -1;
|
||||||
|
if (a.name>b.name) return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const selected = 0;
|
||||||
|
const apps = getApps();
|
||||||
|
|
||||||
|
function prev(){
|
||||||
|
if (selected>=0) {
|
||||||
|
selected--;
|
||||||
|
}
|
||||||
|
drawMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
function next() {
|
||||||
|
if (selected+1<apps.length) {
|
||||||
|
selected++;
|
||||||
|
}
|
||||||
|
drawMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
function run() {
|
||||||
|
if(selected < 0) return load();
|
||||||
|
if (!apps[selected].src) return;
|
||||||
|
if (Storage.read(apps[selected].src)===undefined) {
|
||||||
|
E.showMessage("App Source\nNot found");
|
||||||
|
setTimeout(drawMenu, 2000);
|
||||||
|
} else {
|
||||||
|
E.showMessage("Loading...");
|
||||||
|
load(apps[selected].src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentApp(){
|
||||||
|
return apps[selected];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNextApp(){
|
||||||
|
return apps[selected+1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawFallbackIcon(){
|
||||||
|
g.setColor(1,1,1);
|
||||||
|
g.fillRect(72, 40, 168, 136);
|
||||||
|
g.setColor(0,0,0);
|
||||||
|
g.setFont('6x8', 8);
|
||||||
|
g.drawString('?', 124, 88);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawArrow(x, y, size, dir){
|
||||||
|
size = size || 10;
|
||||||
|
dir = dir || 1;
|
||||||
|
g.moveTo(x, y).lineTo(x+(size*dir), y-size).lineTo(x+(size*dir),y+size).lineTo(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawMenu(){
|
||||||
|
|
||||||
|
if(selected < 0){
|
||||||
|
g.clear();
|
||||||
|
g.setFontAlign(0,0);
|
||||||
|
g.setFont('6x8', 2);
|
||||||
|
g.drawString('Back', 120, 120);
|
||||||
|
drawArrow(220, 120, 10, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const app = getCurrentApp();
|
||||||
|
g.clear();
|
||||||
|
g.setFontAlign(0,0);
|
||||||
|
g.setFont('6x8', 2);
|
||||||
|
if(!app) return g.drawString('???', 120, 120);
|
||||||
|
g.drawString(app.name, 120, 160);
|
||||||
|
if (app.icon) icon = Storage.read(app.icon);
|
||||||
|
if (icon) try {g.drawImage(icon, 120-48, 40, { scale: 2 });} catch(e){ drawFallbackIcon(); }
|
||||||
|
else drawFallbackIcon();
|
||||||
|
|
||||||
|
g.setFont('6x8', 1);
|
||||||
|
|
||||||
|
const type = app.type ? app.type : 'App';
|
||||||
|
const version = app.version ? app.version : '0.00';
|
||||||
|
const info = type+' v'+version;
|
||||||
|
g.setFontAlign(-1,1);
|
||||||
|
g.drawString(info, 20, 220);
|
||||||
|
|
||||||
|
const count = (selected+1)+'/'+apps.length;
|
||||||
|
g.setFontAlign(1,1);
|
||||||
|
g.drawString(count, 220, 220);
|
||||||
|
|
||||||
|
drawArrow(20, 120, 10, 1);
|
||||||
|
if(getNextApp()) drawArrow(220, 120, 10, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
drawMenu();
|
||||||
|
|
||||||
|
// Physical buttons
|
||||||
|
setWatch(prev, BTN1, {repeat:true});
|
||||||
|
setWatch(next, BTN3, {repeat:true});
|
||||||
|
setWatch(run, BTN2, {repeat:true,edge:"falling"});
|
||||||
|
|
||||||
|
// Screen event
|
||||||
|
Bangle.on('touch', function(button){
|
||||||
|
switch(button){
|
||||||
|
case 1:
|
||||||
|
prev();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
next();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
run();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Bangle.on('swipe', dir => {
|
||||||
|
if(dir == 1) prev();
|
||||||
|
else next();
|
||||||
|
});
|
After Width: | Height: | Size: 695 B |
|
@ -0,0 +1,5 @@
|
||||||
|
0.02: Now refresh battery monitor every minute if LCD on
|
||||||
|
0.03: Tweaks for variable size widget system
|
||||||
|
0.04: Ensure redrawing works with variable size widget system
|
||||||
|
0.05: Change color depending on battery level, cloned from widbat
|
||||||
|
0.06: Show battery percentage as text
|
|
@ -0,0 +1,59 @@
|
||||||
|
(function(){
|
||||||
|
const levelColor = (l) => {
|
||||||
|
if (Bangle.isCharging()) return 0x07E0; // "Green"
|
||||||
|
if (l >= 50) return 0x05E0; // slightly darker green
|
||||||
|
if (l >= 15) return 0xFD20; // "Orange"
|
||||||
|
return 0xF800; // "Red"
|
||||||
|
}
|
||||||
|
|
||||||
|
function setWidth() {
|
||||||
|
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
|
||||||
|
}
|
||||||
|
function draw() {
|
||||||
|
var s = 39;
|
||||||
|
var x = this.x, y = this.y;
|
||||||
|
const l = E.getBattery(), c = levelColor(l);
|
||||||
|
if (Bangle.isCharging()) {
|
||||||
|
g.setColor(c).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,x+4+l*(s-12)/100,y+17);
|
||||||
|
g.setColor(-1);
|
||||||
|
g.setFontAlign(-1,-1);
|
||||||
|
if (l >= 100) {
|
||||||
|
g.setFont('4x6', 2);
|
||||||
|
g.drawString(l, x + 6, y + 7);
|
||||||
|
} else {
|
||||||
|
if (l < 10) x+=6;
|
||||||
|
g.setFont('6x8', 2);
|
||||||
|
g.drawString(l, x + 6, y + 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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(draw, 60000);
|
||||||
|
} else {
|
||||||
|
if (batteryInterval) {
|
||||||
|
clearInterval(batteryInterval);
|
||||||
|
batteryInterval = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
WIDGETS["bat"]={area:"tr",width:40,draw:draw};
|
||||||
|
setWidth();
|
||||||
|
})()
|
After Width: | Height: | Size: 297 B |
|
@ -0,0 +1 @@
|
||||||
|
0.01: New Widget!
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
(() => {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
});
|
||||||
|
})();
|
After Width: | Height: | Size: 3.5 KiB |
|
@ -0,0 +1 @@
|
||||||
|
0.01: New App!
|
|
@ -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 };
|
||||||
|
|
||||||
|
})();
|
After Width: | Height: | Size: 2.0 KiB |
|
@ -0,0 +1 @@
|
||||||
|
0.01: New Widget!
|
|
@ -0,0 +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;
|
||||||
|
|
||||||
|
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 };
|
||||||
|
})();
|
After Width: | Height: | Size: 911 B |
|
@ -0,0 +1 @@
|
||||||
|
0.01: New Widget
|
|
@ -0,0 +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 };
|
||||||
|
})();
|
After Width: | Height: | Size: 344 B |
|
@ -51,7 +51,9 @@ apps.forEach((app,addIdx) => {
|
||||||
if (app.version != "0.01")
|
if (app.version != "0.01")
|
||||||
WARN(`App ${app.id} has no ChangeLog`);
|
WARN(`App ${app.id} has no ChangeLog`);
|
||||||
} else {
|
} else {
|
||||||
var versions = fs.readFileSync(appDir+"ChangeLog").toString().match(/\d+\.\d+:/g);
|
var changeLog = fs.readFileSync(appDir+"ChangeLog").toString();
|
||||||
|
var versions = changeLog.match(/\d+\.\d+:/g);
|
||||||
|
if (!versions) ERROR(`No versions found in ${app.id} ChangeLog (${appDir}ChangeLog)`);
|
||||||
var lastChangeLog = versions.pop().slice(0,-1);
|
var lastChangeLog = versions.pop().slice(0,-1);
|
||||||
if (lastChangeLog != app.version)
|
if (lastChangeLog != app.version)
|
||||||
WARN(`App ${app.id} app version (${app.version}) and ChangeLog (${lastChangeLog}) don't agree`);
|
WARN(`App ${app.id} app version (${app.version}) and ChangeLog (${lastChangeLog}) don't agree`);
|
||||||
|
|
32
firmware.js
|
@ -128,10 +128,9 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://www.puck-js.com/puck.js"></script>
|
<script src="https://www.puck-js.com/puck.js"></script>
|
||||||
<script src="utils.js"></script>
|
<script src="js/utils.js"></script>
|
||||||
<script src="comms.js"></script>
|
<script src="js/comms.js"></script>
|
||||||
<script src="appinfo.js"></script>
|
<script src="js/appinfo.js"></script>
|
||||||
<script src="index.js"></script>
|
<script src="js/index.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/file-saver@2.0.2/dist/FileSaver.min.js" type="application/javascript"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -27,14 +27,19 @@ var AppInfo = {
|
||||||
// then map each file to a command to load into storage
|
// then map each file to a command to load into storage
|
||||||
fileContents.forEach(storageFile => {
|
fileContents.forEach(storageFile => {
|
||||||
// format ready for Espruino
|
// format ready for Espruino
|
||||||
var js;
|
|
||||||
if (storageFile.evaluate) {
|
if (storageFile.evaluate) {
|
||||||
js = storageFile.content.trim();
|
let js = storageFile.content.trim();
|
||||||
if (js.endsWith(";"))
|
if (js.endsWith(";"))
|
||||||
js = js.slice(0,-1);
|
js = js.slice(0,-1);
|
||||||
} else
|
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`;
|
||||||
js = toJS(storageFile.content);
|
} else {
|
||||||
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`;
|
let code = storageFile.content;
|
||||||
|
// write code in chunks, in case it is too big to fit in RAM (fix #157)
|
||||||
|
var CHUNKSIZE = 4096;
|
||||||
|
storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${toJS(code.substr(0,CHUNKSIZE))},0,${code.length});`;
|
||||||
|
for (var i=CHUNKSIZE;i<code.length;i+=CHUNKSIZE)
|
||||||
|
storageFile.cmd += `\n\x10require('Storage').write(${toJS(storageFile.name)},${toJS(code.substr(i,CHUNKSIZE))},${i});`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
resolve(fileContents);
|
resolve(fileContents);
|
||||||
}).catch(err => reject(err));
|
}).catch(err => reject(err));
|
|
@ -73,13 +73,13 @@ removeApp : app => { // expects an app structure
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
removeAllApps : () => {
|
removeAllApps : () => {
|
||||||
return Comms.reset("wipe").then(() => new Promise((resolve,reject) => {
|
return new Promise((resolve,reject) => {
|
||||||
// Use write with newline here so we wait for it to finish
|
// Use write with newline here so we wait for it to finish
|
||||||
Puck.write('\x10E.showMessage("Erasing...");require("Storage").eraseAll();Bluetooth.println("OK")\n', (result,err) => {
|
Puck.write('\x10E.showMessage("Erasing...");require("Storage").eraseAll();Bluetooth.println("OK");reset()\n', (result,err) => {
|
||||||
if (!result || result.trim()!="OK") return reject(err || "");
|
if (!result || result.trim()!="OK") return reject(err || "");
|
||||||
resolve();
|
resolve();
|
||||||
}, true /* wait for newline */);
|
}, true /* wait for newline */);
|
||||||
}));
|
});
|
||||||
},
|
},
|
||||||
setTime : () => {
|
setTime : () => {
|
||||||
return new Promise((resolve,reject) => {
|
return new Promise((resolve,reject) => {
|
||||||
|
@ -147,5 +147,50 @@ readFile : (file) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
readStorageFile : (filename) => { // StorageFiles are different to normal storage entries
|
||||||
|
return new Promise((resolve,reject) => {
|
||||||
|
// Use "\xFF" to signal end of file (can't occur in files anyway)
|
||||||
|
var fileContent = "";
|
||||||
|
var fileSize = undefined;
|
||||||
|
var connection = Puck.getConnection();
|
||||||
|
connection.received = "";
|
||||||
|
connection.cb = function(d) {
|
||||||
|
var finished = false;
|
||||||
|
var eofIndex = d.indexOf("\xFF");
|
||||||
|
if (eofIndex>=0) {
|
||||||
|
finished = true;
|
||||||
|
d = d.substr(0,eofIndex);
|
||||||
|
}
|
||||||
|
fileContent += d;
|
||||||
|
if (fileSize === undefined) {
|
||||||
|
var newLineIdx = fileContent.indexOf("\n");
|
||||||
|
if (newLineIdx>=0) {
|
||||||
|
fileSize = parseInt(fileContent.substr(0,newLineIdx));
|
||||||
|
console.log("File size is "+fileSize);
|
||||||
|
fileContent = fileContent.substr(newLineIdx+1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showProgress(undefined,100*fileContent.length / (fileSize||1000000));
|
||||||
|
}
|
||||||
|
if (finished) {
|
||||||
|
hideProgress();
|
||||||
|
connection.received = "";
|
||||||
|
connection.cb = undefined;
|
||||||
|
resolve(fileContent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(`Reading StorageFile ${JSON.stringify(filename)}`);
|
||||||
|
connection.write(`\x03\x10(function() {
|
||||||
|
var f = require("Storage").open(${JSON.stringify(filename)},"r");
|
||||||
|
Bluetooth.println(f.getLength());
|
||||||
|
var l = f.readLine();
|
||||||
|
while (l!==undefined) { Bluetooth.print(l); l = f.readLine(); }
|
||||||
|
Bluetooth.print("\xFF");
|
||||||
|
})()\n`,() => {
|
||||||
|
showProgress(`Reading ${JSON.stringify(filename)}`,0);
|
||||||
|
console.log(`StorageFile read started...`);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -11,6 +11,7 @@ httpGet("apps.json").then(apps=>{
|
||||||
}
|
}
|
||||||
appJSON.sort(appSorter);
|
appJSON.sort(appSorter);
|
||||||
refreshLibrary();
|
refreshLibrary();
|
||||||
|
refreshFilter();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
|
@ -228,6 +229,14 @@ function handleAppInterface(app) {
|
||||||
id : msg.id
|
id : msg.id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else if (msg.type=="readstoragefile") {
|
||||||
|
Comms.readStorageFile(msg.data/*filename*/).then(function(result) {
|
||||||
|
iwin.postMessage({
|
||||||
|
type : "readstoragefilersp",
|
||||||
|
data : result,
|
||||||
|
id : msg.id
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
iwin.postMessage({type:"init"});
|
iwin.postMessage({type:"init"});
|
||||||
|
@ -250,9 +259,18 @@ function showTab(tabname) {
|
||||||
|
|
||||||
// =========================================== Library
|
// =========================================== Library
|
||||||
|
|
||||||
var activeFilter = '';
|
var chips = Array.from(document.querySelectorAll('.chip')).map(chip => chip.attributes.filterid.value)
|
||||||
|
var hash = window.location.hash ? window.location.hash.slice(1) : '';
|
||||||
|
|
||||||
|
var activeFilter = !!~chips.indexOf(hash) ? hash : '';
|
||||||
var currentSearch = '';
|
var currentSearch = '';
|
||||||
|
|
||||||
|
function refreshFilter(){
|
||||||
|
var filtersContainer = document.querySelector("#librarycontainer .filter-nav");
|
||||||
|
filtersContainer.querySelector('.active').classList.remove('active');
|
||||||
|
if(activeFilter) filtersContainer.querySelector('.chip[filterid="'+activeFilter+'"]').classList.add('active')
|
||||||
|
else filtersContainer.querySelector('.chip[filterid]').classList.add('active')
|
||||||
|
}
|
||||||
function refreshLibrary() {
|
function refreshLibrary() {
|
||||||
var panelbody = document.querySelector("#librarycontainer .panel-body");
|
var panelbody = document.querySelector("#librarycontainer .panel-body");
|
||||||
var visibleApps = appJSON;
|
var visibleApps = appJSON;
|
||||||
|
@ -333,22 +351,9 @@ function refreshLibrary() {
|
||||||
});
|
});
|
||||||
} else if (icon.classList.contains("icon-menu")) {
|
} else if (icon.classList.contains("icon-menu")) {
|
||||||
// custom HTML update
|
// custom HTML update
|
||||||
if (app.custom) {
|
icon.classList.remove("icon-menu");
|
||||||
icon.classList.remove("icon-menu");
|
icon.classList.add("loading");
|
||||||
icon.classList.add("loading");
|
customApp(app);
|
||||||
handleCustomApp(app).then((appJSON) => {
|
|
||||||
if (appJSON) appsInstalled.push(appJSON);
|
|
||||||
showToast(app.name+" Uploaded!", "success");
|
|
||||||
icon.classList.remove("loading");
|
|
||||||
icon.classList.add("icon-delete");
|
|
||||||
refreshMyApps();
|
|
||||||
refreshLibrary();
|
|
||||||
}).catch(err => {
|
|
||||||
showToast("Customise failed, "+err, "error");
|
|
||||||
icon.classList.remove("loading");
|
|
||||||
icon.classList.add("icon-menu");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (icon.classList.contains("icon-delete")) {
|
} else if (icon.classList.contains("icon-delete")) {
|
||||||
// Remove app
|
// Remove app
|
||||||
icon.classList.remove("icon-delete");
|
icon.classList.remove("icon-delete");
|
||||||
|
@ -366,6 +371,7 @@ function refreshLibrary() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshFilter();
|
||||||
refreshLibrary();
|
refreshLibrary();
|
||||||
// =========================================== My Apps
|
// =========================================== My Apps
|
||||||
|
|
||||||
|
@ -382,9 +388,23 @@ function removeApp(app) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function customApp(app) {
|
||||||
|
return handleCustomApp(app).then((appJSON) => {
|
||||||
|
if (appJSON) appsInstalled.push(appJSON);
|
||||||
|
showToast(app.name+" Uploaded!", "success");
|
||||||
|
refreshMyApps();
|
||||||
|
refreshLibrary();
|
||||||
|
}).catch(err => {
|
||||||
|
showToast("Customise failed, "+err, "error");
|
||||||
|
refreshMyApps();
|
||||||
|
refreshLibrary();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function updateApp(app) {
|
function updateApp(app) {
|
||||||
|
if (app.custom) return customApp(app);
|
||||||
showProgress(`Upgrading ${app.name}`,undefined,"sticky");
|
showProgress(`Upgrading ${app.name}`,undefined,"sticky");
|
||||||
Comms.removeApp(app).then(()=>{
|
return Comms.removeApp(app).then(()=>{
|
||||||
showToast(app.name+" removed successfully. Updating...",);
|
showToast(app.name+" removed successfully. Updating...",);
|
||||||
appsInstalled = appsInstalled.filter(a=>a.id!=app.id);
|
appsInstalled = appsInstalled.filter(a=>a.id!=app.id);
|
||||||
return Comms.uploadApp(app);
|
return Comms.uploadApp(app);
|
||||||
|
@ -397,10 +417,13 @@ function updateApp(app) {
|
||||||
}, err=>{
|
}, err=>{
|
||||||
hideProgress("sticky");
|
hideProgress("sticky");
|
||||||
showToast(app.name+" update failed, "+err,"error");
|
showToast(app.name+" update failed, "+err,"error");
|
||||||
|
refreshMyApps();
|
||||||
|
refreshLibrary();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function appNameToApp(appName) {
|
function appNameToApp(appName) {
|
||||||
var app = appJSON.find(app=>app.id==appName);
|
var app = appJSON.find(app=>app.id==appName);
|
||||||
if (app) return app;
|
if (app) return app;
|
||||||
|
@ -506,13 +529,12 @@ Comms.watchConnectionChange(handleConnectionChange);
|
||||||
|
|
||||||
var filtersContainer = document.querySelector("#librarycontainer .filter-nav");
|
var filtersContainer = document.querySelector("#librarycontainer .filter-nav");
|
||||||
filtersContainer.addEventListener('click', ({ target }) => {
|
filtersContainer.addEventListener('click', ({ target }) => {
|
||||||
if (!target.hasAttribute('filterid')) return;
|
|
||||||
if (target.classList.contains('active')) return;
|
if (target.classList.contains('active')) return;
|
||||||
|
|
||||||
activeFilter = target.getAttribute('filterid');
|
activeFilter = target.getAttribute('filterid') || '';
|
||||||
filtersContainer.querySelector('.active').classList.remove('active');
|
refreshFilter();
|
||||||
target.classList.add('active');
|
|
||||||
refreshLibrary();
|
refreshLibrary();
|
||||||
|
window.location.hash = activeFilter
|
||||||
});
|
});
|
||||||
|
|
||||||
var librarySearchInput = document.querySelector("#searchform input");
|
var librarySearchInput = document.querySelector("#searchform input");
|