Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mylocation: Add option to set location from waypoint #2839

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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