From 9690e8128b5d184a5c3606415057acd9eb6b9479 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 12 Oct 2023 14:30:30 +0200 Subject: [PATCH 1/7] [] wp_edit: implement marking. These are changes from devel_wp branch. Graphical cleanups would be good, otherwise it should work. --- apps/waypoint_editor/app.js | 104 ++++++++++++++++++++++++----- apps/waypoint_editor/metadata.json | 1 + 2 files changed, 87 insertions(+), 18 deletions(-) diff --git a/apps/waypoint_editor/app.js b/apps/waypoint_editor/app.js index 48a956d82..6bba59a1d 100644 --- a/apps/waypoint_editor/app.js +++ b/apps/waypoint_editor/app.js @@ -13,6 +13,10 @@ var wp = require('Storage').readJSON("waypoints.json", true) || []; 2 .. DD MM'ss" */ var mode = 1; +var key; /* Shared between functions, typically wp name */ +var fix; /* GPS fix */ +var cancel_gps; +var gps_start; function writeWP() { require('Storage').writeJSON("waypoints.json", wp); @@ -30,12 +34,72 @@ function mainMenu() { menu["Add"]=addCard; menu["Remove"]=removeCard; menu["Format"]=setFormat; + menu["Mark GPS"]=markGps; g.clear(); E.showMenu(menu); } +function updateGps() { + let have = false, lat = "lat", lon = "lon", alt = "alt", speed = "speed"; + + if (cancel_gps) + return; + fix = Bangle.getGPSFix(); + + speed = getTime() - gps_start; + + if (fix && fix.fix && fix.lat) { + lat = "" + fix.lat; + lon = "" + fix.lon; + alt = "" + fix.alt; + speed = "" + fix.speed; + have = true; + } + + g.reset().setFont("Vector", 20) + .setColor(1,1,1) + .fillRect(0, 0, 176, 120) + .setColor(0,0,0) + .drawString(key, 0, 0) + .drawString(lat, 0, 20) + .drawString(lon, 0, 40) + .drawString(alt, 0, 60) + .drawString(speed, 0, 80); + + setTimeout(updateGps, 100); +} + +function stopGps() { + cancel_gps=true; + Bangle.setGPSPower(0, "waypoint_editor"); +} + +function confirmGps() { + var la = new Layout ( + {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:"h", c: [ + {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "YES", cb:l=>{ + print("should mark", key, fix); createWP(fix.lat, fix.lon, key); cancel_gps=true; mainMenu(); + }}, + {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: " NO", cb:l=>{ cancel_gps=true; mainMenu(); }} + ]} + ], lazy:true}); + g.clear(); + la.render(); + updateGps(); +} + +function markGps() { + cancel_gps = false; + Bangle.setGPSPower(1, "waypoint_editor"); + gps_start = getTime(); + showNumpad("mkXX", "mark", confirmGps); +} + function setFormat() { - var confirmRemove = new Layout ( + var la = new Layout ( {type:"v", c: [ {type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Format"}, {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD.dddd", cb:l=>{ mode = 0; mainMenu(); }}, @@ -43,7 +107,7 @@ function setFormat() { {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM'ss"+'"', cb:l=>{ mode = 2; mainMenu(); }}, ], lazy:true}); g.clear(); - confirmRemove.render(); + la.render(); } function format(x) { @@ -87,14 +151,14 @@ function lon(x) { function decode(pin) { print(pin); var i = wp[pin]; - var pinDecrypted=i["name"] + "\n" + lat(i["lat"]) + "\n" + lon(i["lon"]); - var showPin = new Layout ({ + var l = i["name"] + "\n" + lat(i["lat"]) + "\n" + lon(i["lon"]); + var la = new Layout ({ type:"v", c: [ - {type:"txt", font:"10%", pad:1, fillx:1, filly:1, label: pinDecrypted}, + {type:"txt", font:"10%", pad:1, fillx:1, filly:1, label: l}, {type:"btn", font:"10%", pad:1, fillx:1, filly:1, label:"OK", cb:l=>{mainMenu();}} ], lazy:true}); g.clear(); - showPin.render(); + la.render(); } function showNumpad(text, key_, callback) { @@ -155,10 +219,10 @@ function showNumpad(text, key_, callback) { function removeCard() { var menu = { - "" : {title : "select card"}, + "" : {title : "Select WP"}, "< Back" : mainMenu }; - if (Object.keys(wp).length==0) Object.assign(menu, {"NO CARDS":""}); + if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""}); else { wp.forEach((val, card) => { const name = wp[card].name; @@ -186,14 +250,14 @@ function removeCard() { } function ask01(t, cb) { - var confirmRemove = new Layout ( + var la = new Layout ( {type:"v", c: [ - {type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Format"}, + {type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Select"}, {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: t[0], cb:l=>{ cb(1); }}, {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: t[1], cb:l=>{ cb(-1); }}, ], lazy:true}); g.clear(); - confirmRemove.render(); + la.render(); } @@ -237,6 +301,16 @@ function askPosition(callback) { }); } +function createWP(lat, lon, name) { + let n = {}; + n["name"] = name; + n["lat"] = lat; + n["lon"] = lon; + wp.push(n); + print("add -- waypoints", wp); + writeWP(); +} + function addCard() { showNumpad("wpXX", "wp", function() { result = key; @@ -257,13 +331,7 @@ function addCard() { g.clear(); askPosition(function(lat, lon) { print("position -- ", lat, lon); - let n = {}; - n["name"] = result; - n["lat"] = lat; - n["lon"] = lon; - wp.push(n); - print("add -- waypoints", wp); - writeWP(); + createWP(lat, lon, result); mainMenu(); }); }); diff --git a/apps/waypoint_editor/metadata.json b/apps/waypoint_editor/metadata.json index 12ff6e095..be3e14d76 100644 --- a/apps/waypoint_editor/metadata.json +++ b/apps/waypoint_editor/metadata.json @@ -5,6 +5,7 @@ "icon": "app.png", "readme": "README.md", "supports" : ["BANGLEJS2"], + "allow_emulator": true, "tags": "tool,outdoors,gps", "storage": [ {"name":"waypoint_editor.app.js","url":"app.js"}, From 73375ebe964bc1bf72b8506869fa0e6b6718239a Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 1 Nov 2023 11:36:59 +0100 Subject: [PATCH 2/7] [] wp_edit: use text entry for waypoint names --- apps/waypoint_editor/app.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/apps/waypoint_editor/app.js b/apps/waypoint_editor/app.js index 6bba59a1d..cdc752c79 100644 --- a/apps/waypoint_editor/app.js +++ b/apps/waypoint_editor/app.js @@ -26,8 +26,10 @@ function mainMenu() { var menu = { "< Back" : Bangle.load }; - if (Object.keys(wp).length==0) Object.assign(menu, {"NO WPs":""}); - else for (let id in wp) { + if (Object.keys(wp).length==0) { + //Object.assign(menu, {"NO WPs":""}); + print("(no waypoints)"); + } else for (let id in wp) { let i = id; menu[wp[id]["name"]]=()=>{ decode(i); }; } @@ -74,7 +76,8 @@ function stopGps() { Bangle.setGPSPower(0, "waypoint_editor"); } -function confirmGps() { +function confirmGps(s) { + key = s; var la = new Layout ( {type:"v", c: [ {type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:""}, @@ -95,7 +98,9 @@ function markGps() { cancel_gps = false; Bangle.setGPSPower(1, "waypoint_editor"); gps_start = getTime(); - showNumpad("mkXX", "mark", confirmGps); + require("textinput").input({text:"wp"}).then(key => { + confirmGps(key); + }); } function setFormat() { @@ -311,8 +316,17 @@ function createWP(lat, lon, name) { writeWP(); } +function addCardName(name) { + g.clear(); + askPosition(function(lat, lon) { + print("position -- ", lat, lon); + createWP(lat, lon, result); + mainMenu(); + }); +} + function addCard() { - showNumpad("wpXX", "wp", function() { + require("textinput").input({text:"wp"}).then(key => { result = key; if (wp[result]!=undefined) { E.showMenu(); @@ -321,19 +335,14 @@ function addCard() { {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:"h", c: [ - {type:"btn", font:"10%", pad:1, fillx:1, filly:1, label: "REPLACE", cb:l=>{encodeCard(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();}} ]} ], lazy:true}); g.clear(); alreadyExists.render(); - } - g.clear(); - askPosition(function(lat, lon) { - print("position -- ", lat, lon); - createWP(lat, lon, result); - mainMenu(); - }); + } + addCardName(result); }); } From dbde4923c61566ca64db33def196332625c4f1c8 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 3 Nov 2023 21:56:10 +0100 Subject: [PATCH 3/7] [] wp_editor: reindent, minor cleanups. --- apps/waypoint_editor/app.js | 87 ++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/apps/waypoint_editor/app.js b/apps/waypoint_editor/app.js index cdc752c79..c9327d621 100644 --- a/apps/waypoint_editor/app.js +++ b/apps/waypoint_editor/app.js @@ -31,7 +31,7 @@ function mainMenu() { print("(no waypoints)"); } else for (let id in wp) { let i = id; - menu[wp[id]["name"]]=()=>{ decode(i); }; + menu[wp[id]["name"]]=()=>{ show(i); }; } menu["Add"]=addCard; menu["Remove"]=removeCard; @@ -78,17 +78,17 @@ function stopGps() { function confirmGps(s) { key = s; - var la = new Layout ( - {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:"h", c: [ - {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "YES", cb:l=>{ - print("should mark", key, fix); createWP(fix.lat, fix.lon, key); cancel_gps=true; mainMenu(); - }}, - {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: " NO", cb:l=>{ cancel_gps=true; mainMenu(); }} - ]} - ], lazy:true}); + var la = new Layout ( + {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:"h", c: [ + {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "YES", cb:l=>{ + print("should mark", key, fix); createWP(fix.lat, fix.lon, key); cancel_gps=true; mainMenu(); + }}, + {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: " NO", cb:l=>{ cancel_gps=true; mainMenu(); }} + ]} + ], lazy:true}); g.clear(); la.render(); updateGps(); @@ -105,12 +105,12 @@ function markGps() { function setFormat() { var la = new Layout ( - {type:"v", c: [ - {type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Format"}, - {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD.dddd", cb:l=>{ mode = 0; mainMenu(); }}, - {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM.mmm'", cb:l=>{ mode = 1; mainMenu(); }}, - {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM'ss"+'"', cb:l=>{ mode = 2; mainMenu(); }}, - ], lazy:true}); + {type:"v", c: [ + {type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:"Format"}, + {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD.dddd", cb:l=>{ mode = 0; mainMenu(); }}, + {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM.mmm'", cb:l=>{ mode = 1; mainMenu(); }}, + {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM'ss"+'"', cb:l=>{ mode = 2; mainMenu(); }}, + ], lazy:true}); g.clear(); la.render(); } @@ -134,7 +134,6 @@ function format(x) { return "" + d + " " + mf + "'" + s + '"'; } } - function lat(x) { c = "N"; if (x<0) { @@ -143,7 +142,6 @@ function lat(x) { } return c+format(x); } - function lon(x) { c = "E"; if (x<0) { @@ -153,17 +151,17 @@ function lon(x) { return c+format(x); } -function decode(pin) { - print(pin); - var i = wp[pin]; - var l = i["name"] + "\n" + lat(i["lat"]) + "\n" + lon(i["lon"]); - var la = new Layout ({ - type:"v", c: [ - {type:"txt", font:"10%", pad:1, fillx:1, filly:1, label: l}, - {type:"btn", font:"10%", pad:1, fillx:1, filly:1, label:"OK", cb:l=>{mainMenu();}} - ], lazy:true}); - g.clear(); - la.render(); +function show(pin) { + print(pin); + var i = wp[pin]; + var l = i["name"] + "\n" + lat(i["lat"]) + "\n" + lon(i["lon"]); + var la = new Layout ({ + type:"v", c: [ + {type:"txt", font:"10%", pad:1, fillx:1, filly:1, label: l}, + {type:"btn", font:"10%", pad:1, fillx:1, filly:1, label:"OK", cb:l=>{mainMenu();}} + ], lazy:true}); + g.clear(); + la.render(); } function showNumpad(text, key_, callback) { @@ -307,22 +305,22 @@ function askPosition(callback) { } function createWP(lat, lon, name) { - let n = {}; - n["name"] = name; - n["lat"] = lat; - n["lon"] = lon; - wp.push(n); - print("add -- waypoints", wp); - writeWP(); + let n = {}; + n["name"] = name; + n["lat"] = lat; + n["lon"] = lon; + wp.push(n); + print("add -- waypoints", wp); + writeWP(); } function addCardName(name) { - g.clear(); - askPosition(function(lat, lon) { - print("position -- ", lat, lon); - createWP(lat, lon, result); - mainMenu(); - }); + g.clear(); + askPosition(function(lat, lon) { + print("position -- ", lat, lon); + createWP(lat, lon, result); + mainMenu(); + }); } function addCard() { @@ -346,7 +344,6 @@ function addCard() { }); } - g.reset(); Bangle.setUI(); mainMenu(); From b814454d90f70e9d839c492364840f7dda1e6286 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 3 Nov 2023 22:03:44 +0100 Subject: [PATCH 4/7] [] wp_edit: Graphical fixes for waypoint marking. --- apps/waypoint_editor/app.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/waypoint_editor/app.js b/apps/waypoint_editor/app.js index c9327d621..db77cf794 100644 --- a/apps/waypoint_editor/app.js +++ b/apps/waypoint_editor/app.js @@ -48,13 +48,13 @@ function updateGps() { return; fix = Bangle.getGPSFix(); - speed = getTime() - gps_start; + speed = "no fix for " + (getTime() - gps_start).toFixed(0) + "s"; if (fix && fix.fix && fix.lat) { - lat = "" + fix.lat; - lon = "" + fix.lon; - alt = "" + fix.alt; - speed = "" + fix.speed; + lat = "" + lat(fix.lat); + lon = "" + lon(fix.lon); + alt = "alt " + fix.alt.toFixed(0) + "m"; + speed = "speed " + fix.speed.toFixed(1) + "kt"; have = true; } @@ -80,6 +80,7 @@ function confirmGps(s) { key = s; var la = new Layout ( {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:"h", c: [ @@ -263,7 +264,6 @@ function ask01(t, cb) { la.render(); } - function askCoordinate(t1, t2, callback) { let sign = 1; ask01(t1, function(sign) { From 9dd09945a1d06498bcbb03e2be9f93752a16f8ab Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 3 Nov 2023 22:05:47 +0100 Subject: [PATCH 5/7] [] wp_edit: mark this as v0.03 --- apps/waypoint_editor/ChangeLog | 1 + apps/waypoint_editor/metadata.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/waypoint_editor/ChangeLog b/apps/waypoint_editor/ChangeLog index 0ec5d2df8..0f45b79cc 100644 --- a/apps/waypoint_editor/ChangeLog +++ b/apps/waypoint_editor/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! 0.02: Display waypoint name instead of its index in remove menu and fix icon +0.03: Use text input for waypoint names, allow marking waypoint with current GPS position diff --git a/apps/waypoint_editor/metadata.json b/apps/waypoint_editor/metadata.json index be3e14d76..d43c6b6bf 100644 --- a/apps/waypoint_editor/metadata.json +++ b/apps/waypoint_editor/metadata.json @@ -1,6 +1,6 @@ { "id": "waypoint_editor", "name": "Waypoint editor", - "version":"0.02", + "version":"0.03", "description": "Allows editing waypoints on device", "icon": "app.png", "readme": "README.md", From b735ae13e46bd0273b6903b2fe4367511c2b3f20 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 3 Nov 2023 22:19:08 +0100 Subject: [PATCH 6/7] waypoint_editor: fix tabs vs. spaces. --- apps/waypoint_editor/app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/waypoint_editor/app.js b/apps/waypoint_editor/app.js index db77cf794..cbdcdbfd3 100644 --- a/apps/waypoint_editor/app.js +++ b/apps/waypoint_editor/app.js @@ -84,10 +84,10 @@ function confirmGps(s) { {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:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "YES", cb:l=>{ - print("should mark", key, fix); createWP(fix.lat, fix.lon, 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: "YES", cb:l=>{ + print("should mark", key, fix); createWP(fix.lat, fix.lon, key); cancel_gps=true; mainMenu(); + }}, + {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: " NO", cb:l=>{ cancel_gps=true; mainMenu(); }} ]} ], lazy:true}); g.clear(); From 3f064961f025ef80134702213690ef943a6fd367 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 4 Nov 2023 09:08:53 +0100 Subject: [PATCH 7/7] wp_edit: we use textinput, include it in dependencies --- apps/waypoint_editor/metadata.json | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/waypoint_editor/metadata.json b/apps/waypoint_editor/metadata.json index d43c6b6bf..87f0ed8ce 100644 --- a/apps/waypoint_editor/metadata.json +++ b/apps/waypoint_editor/metadata.json @@ -7,6 +7,7 @@ "supports" : ["BANGLEJS2"], "allow_emulator": true, "tags": "tool,outdoors,gps", + "dependencies": {"textinput":"type"}, "storage": [ {"name":"waypoint_editor.app.js","url":"app.js"}, {"name":"waypoint_editor.img","url":"app-icon.js","evaluate":true}