waypoints: cleanups, reduce ammount of global functions

master
Pavel Machek 2024-11-20 21:59:55 +01:00
parent 20557732f3
commit 22fb1483ee
1 changed files with 13 additions and 19 deletions

View File

@ -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";
@ -394,7 +393,7 @@ function updateGoto() {
} }
function stopGps() { function stopGps() {
cancel_gps=true; cancel_gps = true;
Bangle.setGPSPower(0, "waypoints"); Bangle.setGPSPower(0, "waypoints");
} }
@ -420,7 +419,6 @@ function confirmGps(s) {
function markGps() { function markGps() {
cancel_gps = false; cancel_gps = false;
Bangle.setGPSPower(1, "waypoints"); Bangle.setGPSPower(1, "waypoints");
gps_start = getTime();
require("textinput").input({text:"wp"}).then(key => { require("textinput").input({text:"wp"}).then(key => {
confirmGps(key); confirmGps(key);
}); });
@ -498,7 +496,6 @@ function goTo() {
cancel_gps = false; cancel_gps = false;
Bangle.setGPSPower(1, "waypoints"); Bangle.setGPSPower(1, "waypoints");
gps.gps_start = getTime(); gps.gps_start = getTime();
gps_start = getTime();
var la = new Layout ( var la = new Layout (
{type:"v", c: [ {type:"v", c: [
@ -515,8 +512,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;
@ -550,9 +547,8 @@ function showCard() {
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); print("Remove?", card, name);
@ -560,7 +556,7 @@ function remove(pin)
title:"Delete", title:"Delete",
}).then(function(v) { }).then(function(v) {
if (v) { if (v) {
wp.splice(pin, 1); wp.splice(card, 1);
writeWP(); writeWP();
mainMenu(); mainMenu();
} else { } else {
@ -649,20 +645,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 (