[] waypoints: use fmt to format position.

master
Pavel Machek 2024-06-24 23:20:23 +02:00
parent 75f64e8004
commit f55056b69c
1 changed files with 63 additions and 100 deletions

View File

@ -178,31 +178,31 @@ function updateGps() {
function stopGps() { function stopGps() {
cancel_gps=true; cancel_gps=true;
Bangle.setGPSPower(0, "waypoint_editor"); Bangle.setGPSPower(0, "waypoints");
} }
function confirmGps(s) { function confirmGps(s) {
key = s; key = s;
var la = new Layout ( var la = new Layout (
{type:"v", c: [ {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:"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:"h", c: [
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "YES", cb:l=>{ {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(); 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(); }} {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: " NO", cb:l=>{ cancel_gps=true; mainMenu(); }}
]} ]}
], lazy:true}); ], lazy:true});
g.clear(); g.clear();
la.render(); la.render();
updateGps(); updateGps();
} }
function markGps() { function markGps() {
cancel_gps = false; cancel_gps = false;
Bangle.setGPSPower(1, "waypoint_editor"); Bangle.setGPSPower(1, "waypoints");
gps_start = getTime(); gps_start = getTime();
require("textinput").input({text:"wp"}).then(key => { require("textinput").input({text:"wp"}).then(key => {
confirmGps(key); confirmGps(key);
@ -221,53 +221,6 @@ function setFormat() {
la.render(); la.render();
} }
function format(x) {
switch (fmt.geo_mode) {
case 0:
return "" + x;
case 1:
d = Math.floor(x);
m = x - d;
m = m*60;
return "" + d + " " + m + "'";
case 2:
d = Math.floor(x);
m = x - d;
m = m*60;
mf = Math.floor(m);
s = m - mf;
s = s*60;
return "" + d + " " + mf + "'" + s + '"';
}
}
function lat(x) {
c = "N";
if (x<0) {
c = "S";
x = -x;
}
return c+format(x);
}
function lon(x) {
c = "E";
if (x<0) {
c = "W";
x = -x;
}
return c+format(x);
}
function show(pin) {
var i = wp[pin];
var l = lat(i["lat"]) + "\n" + lon(i["lon"]);
E.showPrompt(l,{
title:i["name"],
buttons : {"Ok":true}
}).then(function(v) {
mainMenu();
});
}
function showNumpad(text, key_, callback) { function showNumpad(text, key_, callback) {
key = key_; key = key_;
E.showMenu(); E.showMenu();
@ -324,54 +277,64 @@ function showNumpad(text, key_, callback) {
update(); update();
} }
function showCard() { function show(pin) {
var menu = { var i = wp[pin];
"" : {title : "Select WP"}, var l = fmt.fmtPos(i);
"< Back" : mainMenu E.showPrompt(l,{
}; title:i["name"],
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""}); buttons : {"Ok":true}
else { }).then(function(v) {
wp.forEach((val, card) => { mainMenu();
const name = wp[card].name;
menu[name]= () => show(card);
}); });
} }
E.showMenu(menu);
function showCard() {
var menu = {
"" : {title : "Select WP"},
"< Back" : mainMenu
};
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
else {
wp.forEach((val, card) => {
const name = wp[card].name;
menu[name]= () => show(card);
});
}
E.showMenu(menu);
} }
function remove(pin) function remove(pin)
{ {
let card = wp[pin]; let card = wp[pin];
let name = card["name"]; let name = card["name"];
print("Remove?", 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(pin, 1);
writeWP(); writeWP();
mainMenu(); mainMenu();
} else { } else {
mainMenu(); mainMenu();
}
} }
); });
} }
function removeCard() { function removeCard() {
var menu = { var menu = {
"" : {title : "Select WP"}, "" : {title : "Select WP"},
"< Back" : mainMenu "< Back" : mainMenu
}; };
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""}); if (Object.keys(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 = wp[card].name;
menu[name]=()=> remove(card); menu[name]=()=> remove(card);
}); });
} }
E.showMenu(menu); E.showMenu(menu);
} }
function ask01(t, cb) { function ask01(t, cb) {