1
0
Fork 0

waypoints: cleanups, mostly formatting / whitespace.

master
Pavel Machek 2024-11-13 11:28:07 +01:00
parent 2b7062939e
commit de755fc78b
1 changed files with 110 additions and 113 deletions

View File

@ -1,7 +1,6 @@
/* Thanks to pinsafe from BangleApps repository */ /* Thanks to pinsafe from BangleApps repository */
var Layout = require("Layout"); var Layout = require("Layout");
const BANGLEJS2 = process.env.HWVERSION == 2; // check for bangle 2
/* fmt library v0.2.2 */ /* fmt library v0.2.2 */
let fmt = { let fmt = {
@ -319,47 +318,45 @@ function mainMenu() {
var menu = { var menu = {
"< Back" : () => load() "< Back" : () => load()
}; };
if (textInputInstalled && BANGLEJS2) {
menu["Add"]=addCard;
}
menu["Show"]=showCard; menu["Show"]=showCard;
menu["Remove"]=removeCard; if (textInputInstalled) {
menu["Format"]=setFormat; menu["Add"]=addCard;
if (textInputInstalled && BANGLEJS2) {
menu["Mark GPS"]=markGps; menu["Mark GPS"]=markGps;
} }
menu["Remove"]=removeCard;
menu["Format"]=setFormat;
g.clear(); g.clear();
E.showMenu(menu); E.showMenu(menu);
} }
function updateGps() { function updateGps() {
let have = false, lat = "lat ", alt = "?", let have = false, lat = "lat ", alt = "?",
speed = "speed ", hdop = "?", adelta = "adelta ", speed = "speed ", hdop = "?", adelta = "adelta ",
tdelta = "tdelta "; tdelta = "tdelta ";
if (cancel_gps) if (cancel_gps)
return; return;
fix = gps.getGPSFix(); fix = gps.getGPSFix();
if (fix && fix.fix && fix.lat) { if (fix && fix.fix && fix.lat) {
lat = "" + fmt.fmtPos(fix); lat = "" + fmt.fmtPos(fix);
alt = "" + fix.alt.toFixed(0); alt = "" + fix.alt.toFixed(0);
speed = "" + fix.speed.toFixed(1); speed = "" + fix.speed.toFixed(1);
hdop = "" + fix.hdop.toFixed(0); hdop = "" + fix.hdop.toFixed(0);
have = true; have = true;
} else { } else {
lat = "NO FIX\n" lat = "NO FIX\n"
+ "" + (getTime() - gps_start).toFixed(0) + "s "; + "" + (getTime() - gps_start).toFixed(0) + "s ";
} }
let msg = ""; let msg = "";
msg = lat + "\n"+ alt + "m"; msg = lat + "\n"+ alt + "m";
g.reset().setFont("Vector", 31) g.reset().setFont("Vector", 31)
.setColor(1,1,1) .setColor(1,1,1)
.fillRect(0, 24, 176, 100) .fillRect(0, 24, 176, 100)
.setColor(0,0,0) .setColor(0,0,0)
.drawString(msg, 3, 25); .drawString(msg, 3, 25);
setTimeout(updateGps, 1000); setTimeout(updateGps, 1000);
} }
function stopGps() { function stopGps() {
@ -368,22 +365,22 @@ function stopGps() {
} }
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, fix.alt, key); cancel_gps=true; mainMenu(); print("should mark", key, fix); createWP(fix.lat, fix.lon, fix.alt, 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() {
@ -464,63 +461,63 @@ function showNumpad(text, key_, callback) {
} }
function show(pin) { function show(pin) {
var i = wp[pin]; var i = wp[pin];
var l = fmt.fmtPos(i); var l = fmt.fmtPos(i);
E.showPrompt(l,{ E.showPrompt(l,{
title:i["name"], title:i["name"],
buttons : {"Ok":true} buttons : {"Ok":true}
}).then(function(v) { }).then(function(v) {
mainMenu(); mainMenu();
}); });
} }
function showCard() { function showCard() {
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]= () => show(card); menu[name]= () => show(card);
}); });
} }
E.showMenu(menu); 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) {
@ -598,18 +595,18 @@ function addCard() {
require("textinput").input({text:"wp"}).then(key => { require("textinput").input({text:"wp"}).then(key => {
result = key; result = key;
if (wp[result]!=undefined) { if (wp[result]!=undefined) {
E.showMenu(); E.showMenu();
var alreadyExists = new Layout ( var alreadyExists = new Layout (
{type:"v", c: [ {type:"v", c: [
{type:"txt", font:Math.min(15,100/result.length)+"%", pad:1, fillx:1, filly:1, label:result}, {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:"txt", font:"12%", pad:1, fillx:1, filly:1, label:"already exists."},
{type:"h", c: [ {type:"h", c: [
{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: "REPLACE", cb:l=>{addCardName(result);}},
{type:"btn", font:"10%", pad:1, fillx:1, filly:1, label: "CANCEL", cb:l=>{mainMenu();}} {type:"btn", font:"10%", pad:1, fillx:1, filly:1, label: "CANCEL", cb:l=>{mainMenu();}}
]} ]}
], lazy:true}); ], lazy:true});
g.clear(); g.clear();
alreadyExists.render(); alreadyExists.render();
} }
addCardName(result); addCardName(result);
}); });