Skip to content

Commit

Permalink
Merge pull request #2839 from nxdefiant/master
Browse files Browse the repository at this point in the history
mylocation: Add option to set location from waypoint
  • Loading branch information
gfwilliams authored Jun 26, 2023
2 parents 2ac8660 + 712d316 commit 7dfabf9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions apps/mylocation/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
0.07: Move mylocation app into 'Settings -> Apps'
0.08: Allow setting location from webinterface in the AppLoader
0.09: Fix web interface so app can be installed (replaced custom with interface html)
0.10: Add waypoints as location source
2 changes: 1 addition & 1 deletion apps/mylocation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ next to it - and you can choose your location on a map.

**On Bangle.js** go to `Settings -> Apps -> My Location`

* Select one of the preset Cities, setup through the GPS or use the webinterface from the AppLoader
* Select one of the preset Cities, setup through the GPS, waypoints (if installed) or use the webinterface from the AppLoader
* 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

Expand Down
4 changes: 2 additions & 2 deletions apps/mylocation/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"icon": "app.png",
"type": "settings",
"screenshots": [{"url":"screenshot_1.png"}],
"version":"0.09",
"description": "Sets and stores the latitude and longitude of your preferred City. It can be set from GPS or webinterface. `mylocation.json` can be used by other apps that need your main location. See README for details.",
"version":"0.10",
"description": "Sets and stores the latitude and longitude of your preferred City. It can be set from GPS, waypoints or webinterface. `mylocation.json` can be used by other apps that need your main location. See README for details.",
"readme": "README.md",
"tags": "tool,utility",
"supports": ["BANGLEJS", "BANGLEJS2"],
Expand Down
37 changes: 34 additions & 3 deletions apps/mylocation/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let s = {
function loadSettings() {
settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {};
for (const key in settings) {
s[key] = settings[key]
s[key] = settings[key];
}
}

Expand All @@ -31,7 +31,7 @@ function setFromGPS() {
//console.log(".");
if (gps.fix === 0) return;
//console.log("fix from GPS");
s = {'lat': gps.lat, 'lon': gps.lon, 'location': '???' };
s = {'lat': gps.lat, 'lon': gps.lon, 'location': 'GPS' };
Bangle.buzz(1500); // buzz on first position
Bangle.setGPSPower(0, "mylocation");
saveSettings();
Expand All @@ -50,6 +50,25 @@ function setFromGPS() {
Bangle.setUI("updown", undefined);
}

function setFromWaypoint() {
wpmenu = {
'': { 'title': /*LANG*/'Waypoint' },
'< Back': ()=>{ showMainMenu(); },
};
require("waypoints").load().forEach(wp => {
if (typeof(wp.lat) === 'number' && typeof(wp.lon) === 'number') {
wpmenu[wp.name] = ()=>{
s.location = wp.name;
s.lat = parseFloat(wp.lat);
s.lon = parseFloat(wp.lon);
saveSettings();
showMainMenu();
};
}
});
return E.showMenu(wpmenu);
}

function showMainMenu() {
//console.log("showMainMenu");
const mainmenu = {
Expand All @@ -58,7 +77,13 @@ function showMainMenu() {
/*LANG*/'City': {
value: 0 | locations.indexOf(s.location),
min: 0, max: locations.length - 1,
format: v => locations[v],
format: v => {
if (v === -1) {
return s.location;
} else {
return locations[v];
}
},
onchange: v => {
if (locations[v] !== "???") {
s.location = locations[v];
Expand All @@ -70,6 +95,12 @@ function showMainMenu() {
},
/*LANG*/'Set From GPS': ()=>{ setFromGPS(); }
};
try {
require("waypoints");
mainmenu[/*LANG*/'Set From Waypoint'] = ()=>{ setFromWaypoint(); };
} catch(err) {
// waypoints not installed, thats ok
}
return E.showMenu(mainmenu);
}

Expand Down

0 comments on commit 7dfabf9

Please sign in to comment.