diff --git a/apps.json b/apps.json index a7a74f4cb..8b1fb586e 100644 --- a/apps.json +++ b/apps.json @@ -4456,5 +4456,20 @@ "storage": [ {"name":"timecal.app.js","url":"timecal.app.js"} ] + }, + { "id": "mylocation", + "name": "My Location", + "shortName":"My Location", + "icon": "mylocation.png", + "screenshots": [{"url":"screenshot_1.png"}], + "version":"0.01", + "description": "My Locations adds a menu in the Settings app to set your preferred City or it can be set from the GPS. mylocation.json can be used by other apps that need your main location lat and lon. See README", + "readme": "README.md", + "tags": "tool,utility", + "type": "app", + "supports": ["BANGLEJS", "BANGLEJS2"], + "storage": [ + {"name":"mylocation.settings.js","url":"mylocation.settings.js"} + ] } ] diff --git a/apps/mylocation/ChangeLog b/apps/mylocation/ChangeLog new file mode 100644 index 000000000..7b83706bf --- /dev/null +++ b/apps/mylocation/ChangeLog @@ -0,0 +1 @@ +0.01: First release diff --git a/apps/mylocation/README.md b/apps/mylocation/README.md new file mode 100644 index 000000000..3b39aa947 --- /dev/null +++ b/apps/mylocation/README.md @@ -0,0 +1,44 @@ +# My Location + + *a adds a My Location settings menu, stores GPS lat and lon of your preferred city* + +* My Location is a service app that adds a 'My Location' menu to the settings menu +* Select one of the preset Cities or setup through the GPS +* Other Apps can read this information to do calculations based on location +* When the City shows ??? it means the location has been set through the GPS + +## Example Code + + const LOCATION_FILE = "mylocation.json"; + let location; + + // requires the myLocation app + function loadLocation() { + location = require("Storage").readJSON(LOCATION_FILE,1)||{"lat":51.5072,"lon":0.1276,"location":"London"}; + } + +## Screenshots + +### Select one of the Preset Cities + +* The presets are London, Newcastle, Edinbrough, Paris, New York, Tokyo + +![](screenshot_1.png) + +### Or select 'Set By GPS' to start the GPS + +![](screenshot_2.png) + +### While the GPS is running you will see: + +![](screenshot_3.png) + +### When a GPS fix is received you will see: + +![](screenshot_4.png) + + + +## Creator + +[Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/) diff --git a/apps/mylocation/mylocation.png b/apps/mylocation/mylocation.png new file mode 100644 index 000000000..7148990a4 Binary files /dev/null and b/apps/mylocation/mylocation.png differ diff --git a/apps/mylocation/mylocation.settings.js b/apps/mylocation/mylocation.settings.js new file mode 100644 index 000000000..6936e9e69 --- /dev/null +++ b/apps/mylocation/mylocation.settings.js @@ -0,0 +1,73 @@ +(function(back) { + const SETTINGS_FILE = "mylocation.json"; + + // initialize with default settings... + let s = { + 'lat': 51.5072, + 'lon': 0.1276, + 'location': "London" + } + + // ...and overwrite them with any saved values + // This way saved values are preserved if a new version adds more settings + const storage = require('Storage') + let settings = storage.readJSON(SETTINGS_FILE, 1) || {} + const saved = settings || {} + for (const key in saved) { + s[key] = saved[key] + } + + function save() { + settings = s + storage.write(SETTINGS_FILE, settings) + } + + const locations = ["London", "Newcastle", "Edinburgh", "Paris", "New York", "Tokyo","???"]; + const lats = [51.5072 ,54.9783 ,55.9533 ,48.8566 ,40.7128 ,35.6762, 0.0]; + const lons = [-0.1276 ,-1.6178 ,-3.1883 ,2.3522 , -74.0060 ,139.6503, 0.0]; + + E.showMenu({ + '': { 'title': 'My Location' }, + '< Back': back, + 'City': { + value: 0 | locations.indexOf(s.location), + min: 0, max: 6, + format: v => locations[v], + onchange: v => { + if (v != 6) { + s.location = locations[v]; + s.lat = lats[v]; + s.lon = lons[v]; + save(); + } + }, + }, + 'Set From GPS': ()=>setFromGPS() + }) + + function setFromGPS() { + console.log("set from GPS"); + Bangle.setGPSPower(1); + E.showMessage("Waiting for GPS fix. Place watch in the open. Could take 10 minutes. Long press to abort", "GPS Running"); + Bangle.setUI("updown", undefined); + } + + Bangle.on('GPS', (gps) => { + //console.log("."); + if (gps.fix === 0) return; + //console.log("fix from GPS"); + s = {'lat': gps.lat, 'lon': gps.lon, 'location': '???' } + Bangle.buzz(1500); // buzz on first position + Bangle.setGPSPower(0); + save(); + + Bangle.setUI("updown", ()=>{ load() }); + E.showPrompt("Location has been saved from the GPS fix",{ + title:"Location Saved", + buttons : {"OK":1} + }).then(function(v) { + load(); // load default clock + }); + }); + +}) diff --git a/apps/mylocation/screenshot_1.png b/apps/mylocation/screenshot_1.png new file mode 100644 index 000000000..a9c61b6b3 Binary files /dev/null and b/apps/mylocation/screenshot_1.png differ diff --git a/apps/mylocation/screenshot_2.png b/apps/mylocation/screenshot_2.png new file mode 100644 index 000000000..4c4404540 Binary files /dev/null and b/apps/mylocation/screenshot_2.png differ diff --git a/apps/mylocation/screenshot_3.png b/apps/mylocation/screenshot_3.png new file mode 100644 index 000000000..81570670b Binary files /dev/null and b/apps/mylocation/screenshot_3.png differ diff --git a/apps/mylocation/screenshot_4.png b/apps/mylocation/screenshot_4.png new file mode 100644 index 000000000..ffae679c9 Binary files /dev/null and b/apps/mylocation/screenshot_4.png differ diff --git a/apps/pastel/pastel.app.js b/apps/pastel/pastel.app.js index 013a010cf..8007ac031 100644 --- a/apps/pastel/pastel.app.js +++ b/apps/pastel/pastel.app.js @@ -1,6 +1,9 @@ +var SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js"); require("f_latosmall").add(Graphics); const SETTINGS_FILE = "pastel.json"; +const LOCATION_FILE = "mylocation.json"; let settings; +let location; function loadSettings() { settings = require("Storage").readJSON(SETTINGS_FILE,1)||{}; @@ -8,6 +11,28 @@ function loadSettings() { settings.font = settings.font||"Lato"; } +// requires the myLocation app +function loadLocation() { + location = require("Storage").readJSON(LOCATION_FILE,1)||{"lat":51.5072,"lon":0.1276,"location":"London"}; +} + +function extractTime(d){ + var h = d.getHours(), m = d.getMinutes(); + return(("0"+h).substr(-2) + ":" + ("0"+m).substr(-2)); +} + +var sunRise = "00:00"; +var sunSet = "00:00"; + +function updateSunRiseSunSet(now, lat, lon, line){ + // get today's sunlight times for lat/lon + var times = SunCalc.getTimes(new Date(), lat, lon); + + // format sunrise time from the Date object + sunRise = extractTime(times.sunrise); + sunSet = extractTime(times.sunset); +} + function loadFonts() { // load font files based on settings.font if (settings.font == "Architect") @@ -39,6 +64,8 @@ const infoData = { ID_BLANK: { calc: () => '' }, ID_DATE: { calc: () => {var d = (new Date).toString().split(" "); return d[2] + ' ' + d[1] + ' ' + d[3];} }, ID_DAY: { calc: () => {var d = require("locale").dow(new Date).toLowerCase(); return d[0].toUpperCase() + d.substring(1);} }, + ID_SR: { calc: () => 'Sunrise: ' + sunRise }, + ID_SS: { calc: () => 'Sunset: ' + sunSet }, ID_STEP: { calc: () => 'Steps: ' + stepsWidget().getSteps() }, ID_BATT: { calc: () => 'Battery: ' + E.getBattery() + '%' }, ID_MEM: { calc: () => {var val = process.memory(); return 'Ram: ' + Math.round(val.usage*100/val.total) + '%';} }, @@ -169,6 +196,9 @@ Bangle.setUI("clockupdown", btn=> { loadSettings(); loadFonts(); +loadLocation(); +updateSunRiseSunSet(new Date(), location.lat, location.lon); + g.clear(); var secondInterval = setInterval(draw, 1000); draw();