Skip to content

Commit 0048451

Browse files
authored
Merge pull request espruino#3671 from pavelmachek/m_40_waypoints
waypoints 0.06: cleanups, minor tweaks
2 parents 478a43f + c34d325 commit 0048451

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

apps/waypoints/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
Fixes for Bangle.js 1 & not installed textinput
55
0.04: Minor code improvements
66
0.05: Implement navigation to waypoint
7+
0.06: Cleanups, minor tweaks

apps/waypoints/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ "id": "waypoints",
22
"name": "Waypoints",
3-
"version": "0.05",
3+
"version": "0.06",
44
"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",
55
"icon": "app.png",
66
"tags": "tool,outdoors,gps",

apps/waypoints/waypoints.app.js

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,8 @@ var wp = require('Storage').readJSON("waypoints.json", true) || [];
305305
// Use this with corrupted waypoints
306306
//var wp = [];
307307
var key; /* Shared between functions, typically wp name */
308-
var fix; /* GPS fix */
309-
var cancel_gps;
310-
var gps_start;
308+
var fix; /* GPS fix, shared between updateGps / updateGoto functions and confirmGps */
309+
var cancel_gps; /* Shared between updateGps / updateGoto functions */
311310

312311
function writeWP() {
313312
require('Storage').writeJSON("waypoints.json", wp);
@@ -316,7 +315,7 @@ function writeWP() {
316315
function mainMenu() {
317316
let textInputInstalled = true;
318317
try {
319-
require("textinput")
318+
require("textinput");
320319
} catch(err) {
321320
textInputInstalled = false;
322321
}
@@ -348,7 +347,7 @@ function updateGps() {
348347
// hdop = "" + fix.hdop.toFixed(0);
349348
} else {
350349
lat = "NO FIX\n"
351-
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
350+
+ "" + (getTime() - gps.gps_start).toFixed(0) + "s ";
352351
}
353352

354353
let msg = "";
@@ -376,7 +375,7 @@ function updateGoto() {
376375
have = true;
377376
} else {
378377
lat = "NO FIX\n"
379-
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
378+
+ "" + (getTime() - gps.gps_start).toFixed(0) + "s ";
380379
}
381380

382381
let msg = arrow.name + "\n";
@@ -394,8 +393,8 @@ function updateGoto() {
394393
}
395394

396395
function stopGps() {
397-
cancel_gps=true;
398-
Bangle.setGPSPower(0, "waypoints");
396+
cancel_gps = true;
397+
gps.stop_gps();
399398
}
400399

401400
function confirmGps(s) {
@@ -419,8 +418,7 @@ function confirmGps(s) {
419418

420419
function markGps() {
421420
cancel_gps = false;
422-
Bangle.setGPSPower(1, "waypoints");
423-
gps_start = getTime();
421+
gps.start_gps();
424422
require("textinput").input({text:"wp"}).then(key => {
425423
confirmGps(key);
426424
});
@@ -496,9 +494,7 @@ function showNumpad(text, key_, callback) {
496494

497495
function goTo() {
498496
cancel_gps = false;
499-
Bangle.setGPSPower(1, "waypoints");
500-
gps.gps_start = getTime();
501-
gps_start = getTime();
497+
gps.start_gps();
502498

503499
var la = new Layout (
504500
{type:"v", c: [
@@ -515,8 +511,8 @@ function goTo() {
515511
updateGoto();
516512
}
517513

518-
function show(pin) {
519-
var i = wp[pin];
514+
function show(card) {
515+
var i = wp[card];
520516
var l = fmt.fmtPos(i);
521517
arrow.name = i.name;
522518
arrow.waypoint = i;
@@ -540,32 +536,28 @@ function showCard() {
540536
"" : {title : "Select WP"},
541537
"< Back" : mainMenu
542538
};
543-
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
539+
if (wp.length==0) Object.assign(menu, {"No WPs":""});
544540
else {
545541
wp.forEach((val, card) => {
546-
const name = wp[card].name;
542+
const name = val.name;
547543
menu[name]= () => show(card);
548544
});
549545
}
550546
E.showMenu(menu);
551547
}
552548

553-
function remove(pin)
554-
{
555-
let card = wp[pin];
549+
function remove(c) {
550+
let card = wp[c];
556551
let name = card["name"];
557-
print("Remove?", card, name);
558552

559553
E.showPrompt(name,{
560554
title:"Delete",
561555
}).then(function(v) {
562556
if (v) {
563-
wp.splice(pin, 1);
557+
wp.splice(c, 1);
564558
writeWP();
565-
mainMenu();
566-
} else {
567-
mainMenu();
568559
}
560+
mainMenu();
569561
});
570562
}
571563

@@ -574,10 +566,10 @@ function removeCard() {
574566
"" : {title : "Select WP"},
575567
"< Back" : mainMenu
576568
};
577-
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
569+
if (wp.length==0) Object.assign(menu, {"No WPs":""});
578570
else {
579571
wp.forEach((val, card) => {
580-
const name = wp[card].name;
572+
const name = val.name;
581573
menu[name]=()=> remove(card);
582574
});
583575
}
@@ -595,10 +587,7 @@ function ask01(t, cb) {
595587
la.render();
596588
}
597589

598-
var res;
599-
600590
function askCoordinate(t1, t2, callback) {
601-
//let sign = 1;
602591
ask01(t1, function(sign) {
603592
let d, m, s;
604593
switch (fmt.geo_mode) {
@@ -607,6 +596,7 @@ function askCoordinate(t1, t2, callback) {
607596
case 2: s = "DDD MM'ss"+'"'; break;
608597
}
609598
showNumpad(s, t2, function() {
599+
let res = 0;
610600
switch (fmt.geo_mode) {
611601
case 0:
612602
res = parseFloat(key);
@@ -649,20 +639,18 @@ function createWP(lat, lon, alt, name) {
649639
writeWP();
650640
}
651641

652-
var result;
653-
654642
function addCardName(name) {
655643
g.clear();
656644
askPosition(function(lat, lon) {
657645
print("position -- ", lat, lon);
658-
createWP(lat, lon, -9999, result);
646+
createWP(lat, lon, -9999, name);
659647
mainMenu();
660648
});
661649
}
662650

663651
function addCard() {
664652
require("textinput").input({text:"wp"}).then(key => {
665-
result = key;
653+
let result = key;
666654
if (wp[result]!=undefined) {
667655
E.showMenu();
668656
var alreadyExists = new Layout (

0 commit comments

Comments
 (0)