1
0
Fork 0

Merge pull request #3079 from pavelmachek/m_16_wpedit

waypoint_editor: allow text waypoint names, allow marking current GPS position
master
Rob Pilling 2023-11-04 17:02:04 +00:00 committed by GitHub
commit e19faff200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 125 additions and 48 deletions

View File

@ -1,2 +1,3 @@
0.01: New App!
0.02: Display waypoint name instead of its index in remove menu and fix icon
0.03: Use text input for waypoint names, allow marking waypoint with current GPS position

View File

@ -13,6 +13,10 @@ var wp = require('Storage').readJSON("waypoints.json", true) || [];
2 .. DD MM'ss"
*/
var mode = 1;
var key; /* Shared between functions, typically wp name */
var fix; /* GPS fix */
var cancel_gps;
var gps_start;
function writeWP() {
require('Storage').writeJSON("waypoints.json", wp);
@ -22,28 +26,94 @@ function mainMenu() {
var menu = {
"< Back" : Bangle.load
};
if (Object.keys(wp).length==0) Object.assign(menu, {"NO WPs":""});
else for (let id in wp) {
if (Object.keys(wp).length==0) {
//Object.assign(menu, {"NO WPs":""});
print("(no waypoints)");
} else for (let id in wp) {
let i = id;
menu[wp[id]["name"]]=()=>{ decode(i); };
menu[wp[id]["name"]]=()=>{ show(i); };
}
menu["Add"]=addCard;
menu["Remove"]=removeCard;
menu["Format"]=setFormat;
menu["Mark GPS"]=markGps;
g.clear();
E.showMenu(menu);
}
function setFormat() {
var confirmRemove = new Layout (
{type:"v", c: [
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Format"},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD.dddd", cb:l=>{ mode = 0; mainMenu(); }},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM.mmm'", cb:l=>{ mode = 1; mainMenu(); }},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM'ss"+'"', cb:l=>{ mode = 2; mainMenu(); }},
], lazy:true});
function updateGps() {
let have = false, lat = "lat", lon = "lon", alt = "alt", speed = "speed";
if (cancel_gps)
return;
fix = Bangle.getGPSFix();
speed = "no fix for " + (getTime() - gps_start).toFixed(0) + "s";
if (fix && fix.fix && fix.lat) {
lat = "" + lat(fix.lat);
lon = "" + lon(fix.lon);
alt = "alt " + fix.alt.toFixed(0) + "m";
speed = "speed " + fix.speed.toFixed(1) + "kt";
have = true;
}
g.reset().setFont("Vector", 20)
.setColor(1,1,1)
.fillRect(0, 0, 176, 120)
.setColor(0,0,0)
.drawString(key, 0, 0)
.drawString(lat, 0, 20)
.drawString(lon, 0, 40)
.drawString(alt, 0, 60)
.drawString(speed, 0, 80);
setTimeout(updateGps, 100);
}
function stopGps() {
cancel_gps=true;
Bangle.setGPSPower(0, "waypoint_editor");
}
function confirmGps(s) {
key = s;
var la = new Layout (
{type:"v", c: [
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:""},
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:""},
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:""},
{type:"h", c: [
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "YES", cb:l=>{
print("should mark", key, fix); createWP(fix.lat, fix.lon, key); cancel_gps=true; mainMenu();
}},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: " NO", cb:l=>{ cancel_gps=true; mainMenu(); }}
]}
], lazy:true});
g.clear();
confirmRemove.render();
la.render();
updateGps();
}
function markGps() {
cancel_gps = false;
Bangle.setGPSPower(1, "waypoint_editor");
gps_start = getTime();
require("textinput").input({text:"wp"}).then(key => {
confirmGps(key);
});
}
function setFormat() {
var la = new Layout (
{type:"v", c: [
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Format"},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD.dddd", cb:l=>{ mode = 0; mainMenu(); }},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM.mmm'", cb:l=>{ mode = 1; mainMenu(); }},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM'ss"+'"', cb:l=>{ mode = 2; mainMenu(); }},
], lazy:true});
g.clear();
la.render();
}
function format(x) {
@ -65,7 +135,6 @@ function format(x) {
return "" + d + " " + mf + "'" + s + '"';
}
}
function lat(x) {
c = "N";
if (x<0) {
@ -74,7 +143,6 @@ function lat(x) {
}
return c+format(x);
}
function lon(x) {
c = "E";
if (x<0) {
@ -84,17 +152,17 @@ function lon(x) {
return c+format(x);
}
function decode(pin) {
print(pin);
var i = wp[pin];
var pinDecrypted=i["name"] + "\n" + lat(i["lat"]) + "\n" + lon(i["lon"]);
var showPin = new Layout ({
type:"v", c: [
{type:"txt", font:"10%", pad:1, fillx:1, filly:1, label: pinDecrypted},
{type:"btn", font:"10%", pad:1, fillx:1, filly:1, label:"OK", cb:l=>{mainMenu();}}
], lazy:true});
g.clear();
showPin.render();
function show(pin) {
print(pin);
var i = wp[pin];
var l = i["name"] + "\n" + lat(i["lat"]) + "\n" + lon(i["lon"]);
var la = new Layout ({
type:"v", c: [
{type:"txt", font:"10%", pad:1, fillx:1, filly:1, label: l},
{type:"btn", font:"10%", pad:1, fillx:1, filly:1, label:"OK", cb:l=>{mainMenu();}}
], lazy:true});
g.clear();
la.render();
}
function showNumpad(text, key_, callback) {
@ -155,10 +223,10 @@ function showNumpad(text, key_, callback) {
function removeCard() {
var menu = {
"" : {title : "select card"},
"" : {title : "Select WP"},
"< Back" : mainMenu
};
if (Object.keys(wp).length==0) Object.assign(menu, {"NO CARDS":""});
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
else {
wp.forEach((val, card) => {
const name = wp[card].name;
@ -186,17 +254,16 @@ function removeCard() {
}
function ask01(t, cb) {
var confirmRemove = new Layout (
var la = new Layout (
{type:"v", c: [
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Format"},
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Select"},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: t[0], cb:l=>{ cb(1); }},
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: t[1], cb:l=>{ cb(-1); }},
], lazy:true});
g.clear();
confirmRemove.render();
la.render();
}
function askCoordinate(t1, t2, callback) {
let sign = 1;
ask01(t1, function(sign) {
@ -237,8 +304,27 @@ function askPosition(callback) {
});
}
function createWP(lat, lon, name) {
let n = {};
n["name"] = name;
n["lat"] = lat;
n["lon"] = lon;
wp.push(n);
print("add -- waypoints", wp);
writeWP();
}
function addCardName(name) {
g.clear();
askPosition(function(lat, lon) {
print("position -- ", lat, lon);
createWP(lat, lon, result);
mainMenu();
});
}
function addCard() {
showNumpad("wpXX", "wp", function() {
require("textinput").input({text:"wp"}).then(key => {
result = key;
if (wp[result]!=undefined) {
E.showMenu();
@ -247,29 +333,17 @@ function addCard() {
{type:"txt", font:Math.min(15,100/result.length)+"%", pad:1, fillx:1, filly:1, label:result},
{type:"txt", font:"12%", pad:1, fillx:1, filly:1, label:"already exists."},
{type:"h", c: [
{type:"btn", font:"10%", pad:1, fillx:1, filly:1, label: "REPLACE", cb:l=>{encodeCard(result);}},
{type:"btn", font:"10%", pad:1, fillx:1, filly:1, label: "REPLACE", cb:l=>{addCardName(result);}},
{type:"btn", font:"10%", pad:1, fillx:1, filly:1, label: "CANCEL", cb:l=>{mainMenu();}}
]}
], lazy:true});
g.clear();
alreadyExists.render();
}
g.clear();
askPosition(function(lat, lon) {
print("position -- ", lat, lon);
let n = {};
n["name"] = result;
n["lat"] = lat;
n["lon"] = lon;
wp.push(n);
print("add -- waypoints", wp);
writeWP();
mainMenu();
});
}
addCardName(result);
});
}
g.reset();
Bangle.setUI();
mainMenu();

View File

@ -1,11 +1,13 @@
{ "id": "waypoint_editor",
"name": "Waypoint editor",
"version":"0.02",
"version":"0.03",
"description": "Allows editing waypoints on device",
"icon": "app.png",
"readme": "README.md",
"supports" : ["BANGLEJS2"],
"allow_emulator": true,
"tags": "tool,outdoors,gps",
"dependencies": {"textinput":"type"},
"storage": [
{"name":"waypoint_editor.app.js","url":"app.js"},
{"name":"waypoint_editor.img","url":"app-icon.js","evaluate":true}