Skip to content

Commit

Permalink
Merge pull request #3671 from pavelmachek/m_40_waypoints
Browse files Browse the repository at this point in the history
waypoints 0.06: cleanups, minor tweaks
  • Loading branch information
bobrippling authored Nov 28, 2024
2 parents 478a43f + c34d325 commit 0048451
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
1 change: 1 addition & 0 deletions apps/waypoints/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion apps/waypoints/metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
56 changes: 22 additions & 34 deletions apps/waypoints/waypoints.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -316,7 +315,7 @@ function writeWP() {
function mainMenu() {
let textInputInstalled = true;
try {
require("textinput")
require("textinput");
} catch(err) {
textInputInstalled = false;
}
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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";
Expand All @@ -394,8 +393,8 @@ function updateGoto() {
}

function stopGps() {
cancel_gps=true;
Bangle.setGPSPower(0, "waypoints");
cancel_gps = true;
gps.stop_gps();
}

function confirmGps(s) {
Expand All @@ -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);
});
Expand Down Expand Up @@ -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: [
Expand All @@ -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;
Expand All @@ -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();
});
}

Expand All @@ -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);
});
}
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 0048451

Please sign in to comment.