1
0
Fork 0

Merge pull request #3671 from pavelmachek/m_40_waypoints

waypoints 0.06: cleanups, minor tweaks
master
Rob Pilling 2024-11-28 12:33:15 +00:00 committed by GitHub
commit 0048451a04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 35 deletions

View File

@ -4,3 +4,4 @@
Fixes for Bangle.js 1 & not installed textinput
0.04: Minor code improvements
0.05: Implement navigation to waypoint
0.06: Cleanups, minor tweaks

View File

@ -1,6 +1,6 @@
{ "id": "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",
"icon": "app.png",
"tags": "tool,outdoors,gps",

View File

@ -305,9 +305,8 @@ var wp = require('Storage').readJSON("waypoints.json", true) || [];
// Use this with corrupted waypoints
//var wp = [];
var key; /* Shared between functions, typically wp name */
var fix; /* GPS fix */
var cancel_gps;
var gps_start;
var fix; /* GPS fix, shared between updateGps / updateGoto functions and confirmGps */
var cancel_gps; /* Shared between updateGps / updateGoto functions */
function writeWP() {
require('Storage').writeJSON("waypoints.json", wp);
@ -316,7 +315,7 @@ function writeWP() {
function mainMenu() {
let textInputInstalled = true;
try {
require("textinput")
require("textinput");
} catch(err) {
textInputInstalled = false;
}
@ -348,7 +347,7 @@ function updateGps() {
// hdop = "" + fix.hdop.toFixed(0);
} else {
lat = "NO FIX\n"
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
+ "" + (getTime() - gps.gps_start).toFixed(0) + "s ";
}
let msg = "";
@ -376,7 +375,7 @@ function updateGoto() {
have = true;
} else {
lat = "NO FIX\n"
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
+ "" + (getTime() - gps.gps_start).toFixed(0) + "s ";
}
let msg = arrow.name + "\n";
@ -394,8 +393,8 @@ function updateGoto() {
}
function stopGps() {
cancel_gps=true;
Bangle.setGPSPower(0, "waypoints");
cancel_gps = true;
gps.stop_gps();
}
function confirmGps(s) {
@ -419,8 +418,7 @@ function confirmGps(s) {
function markGps() {
cancel_gps = false;
Bangle.setGPSPower(1, "waypoints");
gps_start = getTime();
gps.start_gps();
require("textinput").input({text:"wp"}).then(key => {
confirmGps(key);
});
@ -496,9 +494,7 @@ function showNumpad(text, key_, callback) {
function goTo() {
cancel_gps = false;
Bangle.setGPSPower(1, "waypoints");
gps.gps_start = getTime();
gps_start = getTime();
gps.start_gps();
var la = new Layout (
{type:"v", c: [
@ -515,8 +511,8 @@ function goTo() {
updateGoto();
}
function show(pin) {
var i = wp[pin];
function show(card) {
var i = wp[card];
var l = fmt.fmtPos(i);
arrow.name = i.name;
arrow.waypoint = i;
@ -540,32 +536,28 @@ function showCard() {
"" : {title : "Select WP"},
"< Back" : mainMenu
};
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
if (wp.length==0) Object.assign(menu, {"No WPs":""});
else {
wp.forEach((val, card) => {
const name = wp[card].name;
const name = val.name;
menu[name]= () => show(card);
});
}
E.showMenu(menu);
}
function remove(pin)
{
let card = wp[pin];
function remove(c) {
let card = wp[c];
let name = card["name"];
print("Remove?", card, name);
E.showPrompt(name,{
title:"Delete",
}).then(function(v) {
if (v) {
wp.splice(pin, 1);
wp.splice(c, 1);
writeWP();
mainMenu();
} else {
mainMenu();
}
mainMenu();
});
}
@ -574,10 +566,10 @@ function removeCard() {
"" : {title : "Select WP"},
"< Back" : mainMenu
};
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
if (wp.length==0) Object.assign(menu, {"No WPs":""});
else {
wp.forEach((val, card) => {
const name = wp[card].name;
const name = val.name;
menu[name]=()=> remove(card);
});
}
@ -595,10 +587,7 @@ function ask01(t, cb) {
la.render();
}
var res;
function askCoordinate(t1, t2, callback) {
//let sign = 1;
ask01(t1, function(sign) {
let d, m, s;
switch (fmt.geo_mode) {
@ -607,6 +596,7 @@ function askCoordinate(t1, t2, callback) {
case 2: s = "DDD MM'ss"+'"'; break;
}
showNumpad(s, t2, function() {
let res = 0;
switch (fmt.geo_mode) {
case 0:
res = parseFloat(key);
@ -649,20 +639,18 @@ function createWP(lat, lon, alt, name) {
writeWP();
}
var result;
function addCardName(name) {
g.clear();
askPosition(function(lat, lon) {
print("position -- ", lat, lon);
createWP(lat, lon, -9999, result);
createWP(lat, lon, -9999, name);
mainMenu();
});
}
function addCard() {
require("textinput").input({text:"wp"}).then(key => {
result = key;
let result = key;
if (wp[result]!=undefined) {
E.showMenu();
var alreadyExists = new Layout (