Merge pull request #3671 from pavelmachek/m_40_waypoints
waypoints 0.06: cleanups, minor tweaksmaster
commit
0048451a04
|
|
@ -4,3 +4,4 @@
|
||||||
Fixes for Bangle.js 1 & not installed textinput
|
Fixes for Bangle.js 1 & not installed textinput
|
||||||
0.04: Minor code improvements
|
0.04: Minor code improvements
|
||||||
0.05: Implement navigation to waypoint
|
0.05: Implement navigation to waypoint
|
||||||
|
0.06: Cleanups, minor tweaks
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{ "id": "waypoints",
|
{ "id": "waypoints",
|
||||||
"name": "Waypoints",
|
"name": "Waypoints",
|
||||||
"version": "0.05",
|
"version": "0.06",
|
||||||
"description": "Provides 'waypoints.json' used by various navigation apps, as well as a way to edit it from the App Loader or from the device",
|
"description": "Provides 'waypoints.json' used by various navigation apps, as well as a way to edit it from the App Loader or from the device",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"tags": "tool,outdoors,gps",
|
"tags": "tool,outdoors,gps",
|
||||||
|
|
|
||||||
|
|
@ -305,9 +305,8 @@ var wp = require('Storage').readJSON("waypoints.json", true) || [];
|
||||||
// Use this with corrupted waypoints
|
// Use this with corrupted waypoints
|
||||||
//var wp = [];
|
//var wp = [];
|
||||||
var key; /* Shared between functions, typically wp name */
|
var key; /* Shared between functions, typically wp name */
|
||||||
var fix; /* GPS fix */
|
var fix; /* GPS fix, shared between updateGps / updateGoto functions and confirmGps */
|
||||||
var cancel_gps;
|
var cancel_gps; /* Shared between updateGps / updateGoto functions */
|
||||||
var gps_start;
|
|
||||||
|
|
||||||
function writeWP() {
|
function writeWP() {
|
||||||
require('Storage').writeJSON("waypoints.json", wp);
|
require('Storage').writeJSON("waypoints.json", wp);
|
||||||
|
|
@ -316,7 +315,7 @@ function writeWP() {
|
||||||
function mainMenu() {
|
function mainMenu() {
|
||||||
let textInputInstalled = true;
|
let textInputInstalled = true;
|
||||||
try {
|
try {
|
||||||
require("textinput")
|
require("textinput");
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
textInputInstalled = false;
|
textInputInstalled = false;
|
||||||
}
|
}
|
||||||
|
|
@ -348,7 +347,7 @@ function updateGps() {
|
||||||
// hdop = "" + fix.hdop.toFixed(0);
|
// hdop = "" + fix.hdop.toFixed(0);
|
||||||
} else {
|
} else {
|
||||||
lat = "NO FIX\n"
|
lat = "NO FIX\n"
|
||||||
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
|
+ "" + (getTime() - gps.gps_start).toFixed(0) + "s ";
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg = "";
|
let msg = "";
|
||||||
|
|
@ -376,7 +375,7 @@ function updateGoto() {
|
||||||
have = true;
|
have = true;
|
||||||
} else {
|
} else {
|
||||||
lat = "NO FIX\n"
|
lat = "NO FIX\n"
|
||||||
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
|
+ "" + (getTime() - gps.gps_start).toFixed(0) + "s ";
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg = arrow.name + "\n";
|
let msg = arrow.name + "\n";
|
||||||
|
|
@ -395,7 +394,7 @@ function updateGoto() {
|
||||||
|
|
||||||
function stopGps() {
|
function stopGps() {
|
||||||
cancel_gps = true;
|
cancel_gps = true;
|
||||||
Bangle.setGPSPower(0, "waypoints");
|
gps.stop_gps();
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmGps(s) {
|
function confirmGps(s) {
|
||||||
|
|
@ -419,8 +418,7 @@ function confirmGps(s) {
|
||||||
|
|
||||||
function markGps() {
|
function markGps() {
|
||||||
cancel_gps = false;
|
cancel_gps = false;
|
||||||
Bangle.setGPSPower(1, "waypoints");
|
gps.start_gps();
|
||||||
gps_start = getTime();
|
|
||||||
require("textinput").input({text:"wp"}).then(key => {
|
require("textinput").input({text:"wp"}).then(key => {
|
||||||
confirmGps(key);
|
confirmGps(key);
|
||||||
});
|
});
|
||||||
|
|
@ -496,9 +494,7 @@ function showNumpad(text, key_, callback) {
|
||||||
|
|
||||||
function goTo() {
|
function goTo() {
|
||||||
cancel_gps = false;
|
cancel_gps = false;
|
||||||
Bangle.setGPSPower(1, "waypoints");
|
gps.start_gps();
|
||||||
gps.gps_start = getTime();
|
|
||||||
gps_start = getTime();
|
|
||||||
|
|
||||||
var la = new Layout (
|
var la = new Layout (
|
||||||
{type:"v", c: [
|
{type:"v", c: [
|
||||||
|
|
@ -515,8 +511,8 @@ function goTo() {
|
||||||
updateGoto();
|
updateGoto();
|
||||||
}
|
}
|
||||||
|
|
||||||
function show(pin) {
|
function show(card) {
|
||||||
var i = wp[pin];
|
var i = wp[card];
|
||||||
var l = fmt.fmtPos(i);
|
var l = fmt.fmtPos(i);
|
||||||
arrow.name = i.name;
|
arrow.name = i.name;
|
||||||
arrow.waypoint = i;
|
arrow.waypoint = i;
|
||||||
|
|
@ -540,32 +536,28 @@ function showCard() {
|
||||||
"" : {title : "Select WP"},
|
"" : {title : "Select WP"},
|
||||||
"< Back" : mainMenu
|
"< Back" : mainMenu
|
||||||
};
|
};
|
||||||
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
|
if (wp.length==0) Object.assign(menu, {"No WPs":""});
|
||||||
else {
|
else {
|
||||||
wp.forEach((val, card) => {
|
wp.forEach((val, card) => {
|
||||||
const name = wp[card].name;
|
const name = val.name;
|
||||||
menu[name]= () => show(card);
|
menu[name]= () => show(card);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(pin)
|
function remove(c) {
|
||||||
{
|
let card = wp[c];
|
||||||
let card = wp[pin];
|
|
||||||
let name = card["name"];
|
let name = card["name"];
|
||||||
print("Remove?", card, name);
|
|
||||||
|
|
||||||
E.showPrompt(name,{
|
E.showPrompt(name,{
|
||||||
title:"Delete",
|
title:"Delete",
|
||||||
}).then(function(v) {
|
}).then(function(v) {
|
||||||
if (v) {
|
if (v) {
|
||||||
wp.splice(pin, 1);
|
wp.splice(c, 1);
|
||||||
writeWP();
|
writeWP();
|
||||||
mainMenu();
|
|
||||||
} else {
|
|
||||||
mainMenu();
|
|
||||||
}
|
}
|
||||||
|
mainMenu();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -574,10 +566,10 @@ function removeCard() {
|
||||||
"" : {title : "Select WP"},
|
"" : {title : "Select WP"},
|
||||||
"< Back" : mainMenu
|
"< Back" : mainMenu
|
||||||
};
|
};
|
||||||
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
|
if (wp.length==0) Object.assign(menu, {"No WPs":""});
|
||||||
else {
|
else {
|
||||||
wp.forEach((val, card) => {
|
wp.forEach((val, card) => {
|
||||||
const name = wp[card].name;
|
const name = val.name;
|
||||||
menu[name]=()=> remove(card);
|
menu[name]=()=> remove(card);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -595,10 +587,7 @@ function ask01(t, cb) {
|
||||||
la.render();
|
la.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
var res;
|
|
||||||
|
|
||||||
function askCoordinate(t1, t2, callback) {
|
function askCoordinate(t1, t2, callback) {
|
||||||
//let sign = 1;
|
|
||||||
ask01(t1, function(sign) {
|
ask01(t1, function(sign) {
|
||||||
let d, m, s;
|
let d, m, s;
|
||||||
switch (fmt.geo_mode) {
|
switch (fmt.geo_mode) {
|
||||||
|
|
@ -607,6 +596,7 @@ function askCoordinate(t1, t2, callback) {
|
||||||
case 2: s = "DDD MM'ss"+'"'; break;
|
case 2: s = "DDD MM'ss"+'"'; break;
|
||||||
}
|
}
|
||||||
showNumpad(s, t2, function() {
|
showNumpad(s, t2, function() {
|
||||||
|
let res = 0;
|
||||||
switch (fmt.geo_mode) {
|
switch (fmt.geo_mode) {
|
||||||
case 0:
|
case 0:
|
||||||
res = parseFloat(key);
|
res = parseFloat(key);
|
||||||
|
|
@ -649,20 +639,18 @@ function createWP(lat, lon, alt, name) {
|
||||||
writeWP();
|
writeWP();
|
||||||
}
|
}
|
||||||
|
|
||||||
var result;
|
|
||||||
|
|
||||||
function addCardName(name) {
|
function addCardName(name) {
|
||||||
g.clear();
|
g.clear();
|
||||||
askPosition(function(lat, lon) {
|
askPosition(function(lat, lon) {
|
||||||
print("position -- ", lat, lon);
|
print("position -- ", lat, lon);
|
||||||
createWP(lat, lon, -9999, result);
|
createWP(lat, lon, -9999, name);
|
||||||
mainMenu();
|
mainMenu();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCard() {
|
function addCard() {
|
||||||
require("textinput").input({text:"wp"}).then(key => {
|
require("textinput").input({text:"wp"}).then(key => {
|
||||||
result = key;
|
let result = key;
|
||||||
if (wp[result]!=undefined) {
|
if (wp[result]!=undefined) {
|
||||||
E.showMenu();
|
E.showMenu();
|
||||||
var alreadyExists = new Layout (
|
var alreadyExists = new Layout (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue