Merge pull request #3659 from pavelmachek/m_39_waypoints
waypoints 0.05: implement goto functionalitymaster
commit
4d4fe0fddc
|
|
@ -3,3 +3,4 @@
|
||||||
0.03: Do not register as type waypoint - show in launcher
|
0.03: Do not register as type waypoint - show in launcher
|
||||||
Fixes for Bangle.js 1 & not installed textinput
|
Fixes for Bangle.js 1 & not installed textinput
|
||||||
0.04: Minor code improvements
|
0.04: Minor code improvements
|
||||||
|
0.05: Implement navigation to waypoint
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{ "id": "waypoints",
|
{ "id": "waypoints",
|
||||||
"name": "Waypoints",
|
"name": "Waypoints",
|
||||||
"version": "0.04",
|
"version": "0.05",
|
||||||
"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",
|
"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",
|
"icon": "app.png",
|
||||||
"tags": "tool,outdoors,gps",
|
"tags": "tool,outdoors,gps",
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,309 @@
|
||||||
/* Thanks to pinsafe from BangleApps repository */
|
/* Thanks to pinsafe from BangleApps repository */
|
||||||
|
|
||||||
var Layout = require("Layout");
|
var Layout = require("Layout");
|
||||||
const BANGLEJS2 = process.env.HWVERSION == 2; // check for bangle 2
|
|
||||||
|
|
||||||
var wp = require('Storage').readJSON("waypoints.json", true) || [];
|
/* fmt library v0.2.3 */
|
||||||
// Use this with corrupted waypoints
|
let fmt = {
|
||||||
//var wp = [];
|
icon_alt : "\0\x08\x1a\1\x00\x00\x00\x20\x30\x78\x7C\xFE\xFF\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||||
|
icon_m : "\0\x08\x1a\1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||||
|
icon_km : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||||
|
icon_kph : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\xFF\x00\xC3\xC3\xFF\xC3\xC3",
|
||||||
|
icon_c : "\0\x08\x1a\1\x00\x00\x60\x90\x90\x60\x00\x7F\xFF\xC0\xC0\xC0\xC0\xC0\xFF\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||||
|
icon_hpa : "\x00\x08\x16\x01\x00\x80\xb0\xc8\x88\x88\x88\x00\xf0\x88\x84\x84\x88\xf0\x80\x8c\x92\x22\x25\x19\x00\x00",
|
||||||
|
icon_9 : "\x00\x08\x16\x01\x00\x00\x00\x00\x38\x44\x44\x4c\x34\x04\x04\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||||
|
icon_10 : "\x00\x08\x16\x01\x00\x08\x18\x28\x08\x08\x08\x00\x00\x18\x24\x24\x24\x24\x18\x00\x00\x00\x00\x00\x00\x00",
|
||||||
|
|
||||||
/* 0 .. DD.ddddd
|
/* 0 .. DD.ddddd
|
||||||
1 .. DD MM.mmm'
|
1 .. DD MM.mmm'
|
||||||
2 .. DD MM'ss"
|
2 .. DD MM'ss"
|
||||||
*/
|
*/
|
||||||
var mode = 1;
|
geo_mode : 1,
|
||||||
|
|
||||||
|
init: function() {},
|
||||||
|
fmtDist: function(km) {
|
||||||
|
if (km >= 1.0) return km.toFixed(1) + this.icon_km;
|
||||||
|
return (km*1000).toFixed(0) + this.icon_m;
|
||||||
|
},
|
||||||
|
fmtSteps: function(n) { return this.fmtDist(0.001 * 0.719 * n); },
|
||||||
|
fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; },
|
||||||
|
fmtTemp: function(c) { return c.toFixed(1) + this.icon_c; },
|
||||||
|
fmtPress: function(p) {
|
||||||
|
if (p < 900 || p > 1100)
|
||||||
|
return p.toFixed(0) + this.icon_hpa;
|
||||||
|
if (p < 1000) {
|
||||||
|
p -= 900;
|
||||||
|
return this.icon_9 + this.add0(p.toFixed(0)) + this.icon_hpa;
|
||||||
|
}
|
||||||
|
p -= 1000;
|
||||||
|
return this.icon_10 + this.add0(p.toFixed(0)) + this.icon_hpa;
|
||||||
|
},
|
||||||
|
draw_dot : 1,
|
||||||
|
add0: function(i) {
|
||||||
|
if (i > 9) {
|
||||||
|
return ""+i;
|
||||||
|
} else {
|
||||||
|
return "0"+i;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fmtTOD: function(now) {
|
||||||
|
this.draw_dot = !this.draw_dot;
|
||||||
|
let dot = ":";
|
||||||
|
if (!this.draw_dot)
|
||||||
|
dot = ".";
|
||||||
|
return now.getHours() + dot + this.add0(now.getMinutes());
|
||||||
|
},
|
||||||
|
fmtNow: function() { return this.fmtTOD(new Date()); },
|
||||||
|
fmtTimeDiff: function(d) {
|
||||||
|
if (d < 180)
|
||||||
|
return ""+d.toFixed(0);
|
||||||
|
d = d/60;
|
||||||
|
return ""+d.toFixed(0)+"m";
|
||||||
|
},
|
||||||
|
fmtAngle: function(x) {
|
||||||
|
switch (this.geo_mode) {
|
||||||
|
case 0:
|
||||||
|
return "" + x;
|
||||||
|
case 1: {
|
||||||
|
let d = Math.floor(x);
|
||||||
|
let m = x - d;
|
||||||
|
m = m*60;
|
||||||
|
return "" + d + " " + m.toFixed(3) + "'";
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
let d = Math.floor(x);
|
||||||
|
let m = x - d;
|
||||||
|
m = m*60;
|
||||||
|
let mf = Math.floor(m);
|
||||||
|
let s = m - mf;
|
||||||
|
s = s*60;
|
||||||
|
return "" + d + " " + mf + "'" + s.toFixed(0) + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "bad mode?";
|
||||||
|
},
|
||||||
|
fmtPos: function(pos) {
|
||||||
|
let x = pos.lat;
|
||||||
|
let c = "N";
|
||||||
|
if (x<0) {
|
||||||
|
c = "S";
|
||||||
|
x = -x;
|
||||||
|
}
|
||||||
|
let s = c+this.fmtAngle(x) + "\n";
|
||||||
|
x = pos.lon;
|
||||||
|
c = "E";
|
||||||
|
if (x<0) {
|
||||||
|
c = "W";
|
||||||
|
x = -x;
|
||||||
|
}
|
||||||
|
return s + c + this.fmtAngle(x);
|
||||||
|
},
|
||||||
|
fmtFix: function(fix, t) {
|
||||||
|
if (fix && fix.fix && fix.lat) {
|
||||||
|
return this.fmtSpeed(fix.speed) + " " +
|
||||||
|
this.fmtAlt(fix.alt);
|
||||||
|
} else {
|
||||||
|
return "N/FIX " + this.fmtTimeDiff(t);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fmtSpeed: function(kph) {
|
||||||
|
return kph.toFixed(1) + this.icon_kph;
|
||||||
|
},
|
||||||
|
radians: function(a) { return a*Math.PI/180; },
|
||||||
|
degrees: function(a) { return a*180/Math.PI; },
|
||||||
|
// distance between 2 lat and lons, in meters, Mean Earth Radius = 6371km
|
||||||
|
// https://www.movable-type.co.uk/scripts/latlong.html
|
||||||
|
// (Equirectangular approximation)
|
||||||
|
// returns value in meters
|
||||||
|
distance: function(a,b) {
|
||||||
|
var x = this.radians(b.lon-a.lon) * Math.cos(this.radians((a.lat+b.lat)/2));
|
||||||
|
var y = this.radians(b.lat-a.lat);
|
||||||
|
return Math.sqrt(x*x + y*y) * 6371000;
|
||||||
|
},
|
||||||
|
// thanks to waypointer
|
||||||
|
bearing: function(a,b) {
|
||||||
|
var delta = this.radians(b.lon-a.lon);
|
||||||
|
var alat = this.radians(a.lat);
|
||||||
|
var blat = this.radians(b.lat);
|
||||||
|
var y = Math.sin(delta) * Math.cos(blat);
|
||||||
|
var x = Math.cos(alat) * Math.sin(blat) -
|
||||||
|
Math.sin(alat)*Math.cos(blat)*Math.cos(delta);
|
||||||
|
return Math.round(this.degrees(Math.atan2(y, x)));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/* gps library v0.1.4 */
|
||||||
|
let gps = {
|
||||||
|
emulator: -1,
|
||||||
|
init: function(x) {
|
||||||
|
this.emulator = (process.env.BOARD=="EMSCRIPTEN"
|
||||||
|
|| process.env.BOARD=="EMSCRIPTEN2")?1:0;
|
||||||
|
},
|
||||||
|
state: {},
|
||||||
|
on_gps: function(f) {
|
||||||
|
let fix = this.getGPSFix();
|
||||||
|
f(fix);
|
||||||
|
|
||||||
|
/*
|
||||||
|
"lat": number, // Latitude in degrees
|
||||||
|
"lon": number, // Longitude in degrees
|
||||||
|
"alt": number, // altitude in M
|
||||||
|
"speed": number, // Speed in kph
|
||||||
|
"course": number, // Course in degrees
|
||||||
|
"time": Date, // Current Time (or undefined if not known)
|
||||||
|
"satellites": 7, // Number of satellites
|
||||||
|
"fix": 1 // NMEA Fix state - 0 is no fix
|
||||||
|
"hdop": number, // Horizontal Dilution of Precision
|
||||||
|
*/
|
||||||
|
this.state.timeout = setTimeout(this.on_gps, 1000, f);
|
||||||
|
},
|
||||||
|
off_gps: function() {
|
||||||
|
clearTimeout(this.state.timeout);
|
||||||
|
},
|
||||||
|
getGPSFix: function() {
|
||||||
|
if (!this.emulator)
|
||||||
|
return Bangle.getGPSFix();
|
||||||
|
let fix = {};
|
||||||
|
fix.fix = 1;
|
||||||
|
fix.lat = 50;
|
||||||
|
fix.lon = 14-(getTime()-this.gps_start) / 1000; /* Go West! */
|
||||||
|
fix.alt = 200;
|
||||||
|
fix.speed = 5;
|
||||||
|
fix.course = 30;
|
||||||
|
fix.time = Date();
|
||||||
|
fix.satellites = 5;
|
||||||
|
fix.hdop = 12;
|
||||||
|
return fix;
|
||||||
|
},
|
||||||
|
gps_start : -1,
|
||||||
|
start_gps: function() {
|
||||||
|
Bangle.setGPSPower(1, "libgps");
|
||||||
|
this.gps_start = getTime();
|
||||||
|
},
|
||||||
|
stop_gps: function() {
|
||||||
|
Bangle.setGPSPower(0, "libgps");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let sun = {}; /* To get rid of warnings */
|
||||||
|
|
||||||
|
/* arrow library v0.0.2 */
|
||||||
|
let arrow = {
|
||||||
|
name: "(unset)",
|
||||||
|
waypoint: { lat: 0, lon: 0 },
|
||||||
|
updateWaypoint: function(lat, lon) {
|
||||||
|
this.waypoint.lat = lat;
|
||||||
|
this.waypoint.lon = lon;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Calculate the bearing to the waypoint
|
||||||
|
bearingToWaypoint: function(currentPos) {
|
||||||
|
return fmt.bearing(currentPos, this.waypoint);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Calculate distance to the waypoint
|
||||||
|
distanceToWaypoint: function(currentPos) {
|
||||||
|
return fmt.distance(currentPos, this.waypoint);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Calculate compass heading from current GPS data
|
||||||
|
compassHeading: function(currentHeading) {
|
||||||
|
return currentHeading || Bangle.getCompass().heading;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Display function to show arrows for waypoint, north, and sun
|
||||||
|
draw: function(currentPos, currentHeading) {
|
||||||
|
g.clear().setFont("Vector", 22).setFontAlign(0, 0);
|
||||||
|
|
||||||
|
// Calculate bearings
|
||||||
|
let waypointBearing = this.bearingToWaypoint(currentPos);
|
||||||
|
let distance = this.distanceToWaypoint(currentPos);
|
||||||
|
let northHeading = this.compassHeading(currentHeading);
|
||||||
|
|
||||||
|
// Format distance
|
||||||
|
let distStr = fmt.fmtDist(distance/1000);
|
||||||
|
|
||||||
|
northHeading = 0;
|
||||||
|
// Draw compass arrow for north
|
||||||
|
this.drawArrow(northHeading, "N", 1);
|
||||||
|
|
||||||
|
// Draw arrow towards waypoint
|
||||||
|
if (1)
|
||||||
|
this.drawArrow(waypointBearing, `${distStr}`, 3);
|
||||||
|
|
||||||
|
if (0) {
|
||||||
|
let s;
|
||||||
|
s = sun.sunPos();
|
||||||
|
// Draw sun arrow if sun is visible
|
||||||
|
if (s.altitude > 0) {
|
||||||
|
this.drawArrow(s.azimuth, "Sun", 1);
|
||||||
|
}
|
||||||
|
s = sun.moonPos();
|
||||||
|
// Draw sun arrow if sun is visible
|
||||||
|
if (s.altitude > 0) {
|
||||||
|
this.drawArrow(s.azimuth, "Moon", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
drawArrow: function(angle, label, width) {
|
||||||
|
// Convert angle to radians
|
||||||
|
let rad = angle * Math.PI / 180;
|
||||||
|
|
||||||
|
// Arrow parameters
|
||||||
|
let centerX = 88;
|
||||||
|
let centerY = 88;
|
||||||
|
let length = 60; // Arrow length
|
||||||
|
|
||||||
|
g.drawCircle(centerX, centerY, length);
|
||||||
|
|
||||||
|
// Calculate the rectangle's corner points for the rotated arrow
|
||||||
|
let dx = Math.sin(rad) * length;
|
||||||
|
let dy = -Math.cos(rad) * length;
|
||||||
|
let px = Math.sin(rad + Math.PI / 2) * (width / 2);
|
||||||
|
let py = -Math.cos(rad + Math.PI / 2) * (width / 2);
|
||||||
|
|
||||||
|
// Calculate each corner of the rectangle (arrow body)
|
||||||
|
let x1 = centerX + px;
|
||||||
|
let y1 = centerY + py;
|
||||||
|
let x2 = centerX - px;
|
||||||
|
let y2 = centerY - py;
|
||||||
|
let x3 = x2 + dx * 0.9;
|
||||||
|
let y3 = y2 + dy * 0.9;
|
||||||
|
let x4 = x1 + dx * 0.9;
|
||||||
|
let y4 = y1 + dy * 0.9;
|
||||||
|
|
||||||
|
// Draw the filled rectangle for the arrow body
|
||||||
|
g.fillPoly([x1, y1, x2, y2, x3, y3, x4, y4]);
|
||||||
|
|
||||||
|
// Draw the label at the arrow's endpoint
|
||||||
|
g.setFontAlign(0, 0);
|
||||||
|
g.drawString(label, x3 + dx * 0.4, y3 + dy * 0.4);
|
||||||
|
|
||||||
|
// Draw arrowhead
|
||||||
|
this.drawArrowHead(rad, centerX + dx, centerY + dy);
|
||||||
|
},
|
||||||
|
|
||||||
|
drawArrowHead: function(rad, x, y) {
|
||||||
|
// Arrowhead parameters
|
||||||
|
let headLength = 16; // Length of each arrowhead side
|
||||||
|
let headAngle = Math.PI / 6; // Arrowhead angle
|
||||||
|
|
||||||
|
let angle = rad - Math.PI/2;
|
||||||
|
|
||||||
|
// Calculate positions for arrowhead points
|
||||||
|
let xHead1 = x - headLength * Math.cos(angle - headAngle);
|
||||||
|
let yHead1 = y - headLength * Math.sin(angle - headAngle);
|
||||||
|
let xHead2 = x - headLength * Math.cos(angle + headAngle);
|
||||||
|
let yHead2 = y - headLength * Math.sin(angle + headAngle);
|
||||||
|
|
||||||
|
// Draw the arrowhead as a filled triangle
|
||||||
|
g.fillPoly([x, y, xHead1, yHead1, xHead2, yHead2]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var wp = require('Storage').readJSON("waypoints.json", true) || [];
|
||||||
|
// Use this with corrupted waypoints
|
||||||
|
//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 */
|
||||||
var cancel_gps;
|
var cancel_gps;
|
||||||
|
|
@ -30,54 +323,79 @@ function mainMenu() {
|
||||||
var menu = {
|
var menu = {
|
||||||
"< Back" : () => load()
|
"< Back" : () => load()
|
||||||
};
|
};
|
||||||
for (let id in wp) {
|
menu["Show"]=showCard;
|
||||||
let i = id;
|
if (textInputInstalled) {
|
||||||
menu[wp[id]["name"]]=()=>{ show(i); };
|
|
||||||
}
|
|
||||||
if (textInputInstalled && BANGLEJS2) {
|
|
||||||
menu["Add"]=addCard;
|
menu["Add"]=addCard;
|
||||||
|
menu["Mark GPS"]=markGps;
|
||||||
}
|
}
|
||||||
menu["Remove"]=removeCard;
|
menu["Remove"]=removeCard;
|
||||||
menu["Format"]=setFormat;
|
menu["Format"]=setFormat;
|
||||||
if (textInputInstalled) {
|
|
||||||
menu["Mark GPS"]=markGps;
|
|
||||||
}
|
|
||||||
g.clear();
|
g.clear();
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateGps() {
|
function updateGps() {
|
||||||
let lat = "lat", lon = "lon", alt = "alt", speed = "speed";
|
let lat = "lat ", alt = "?";
|
||||||
|
|
||||||
if (cancel_gps)
|
if (cancel_gps)
|
||||||
return;
|
return;
|
||||||
fix = Bangle.getGPSFix();
|
fix = gps.getGPSFix();
|
||||||
|
|
||||||
speed = "no fix for " + (getTime() - gps_start).toFixed(0) + "s";
|
|
||||||
|
|
||||||
if (fix && fix.fix && fix.lat) {
|
if (fix && fix.fix && fix.lat) {
|
||||||
lat = "" + lat(fix.lat);
|
lat = "" + fmt.fmtPos(fix);
|
||||||
lon = "" + lon(fix.lon);
|
alt = "" + fix.alt.toFixed(0);
|
||||||
alt = "alt " + fix.alt.toFixed(0) + "m";
|
// speed = "" + fix.speed.toFixed(1);
|
||||||
speed = "speed " + fix.speed.toFixed(1) + "kt";
|
// hdop = "" + fix.hdop.toFixed(0);
|
||||||
|
} else {
|
||||||
|
lat = "NO FIX\n"
|
||||||
|
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
|
||||||
}
|
}
|
||||||
|
|
||||||
g.reset().setFont("Vector", 20)
|
let msg = "";
|
||||||
|
msg = lat + "\n"+ alt + "m";
|
||||||
|
g.reset().setFont("Vector", 31)
|
||||||
.setColor(1,1,1)
|
.setColor(1,1,1)
|
||||||
.fillRect(0, 0, 176, 120)
|
.fillRect(0, 24, 176, 100)
|
||||||
.setColor(0,0,0)
|
.setColor(0,0,0)
|
||||||
.drawString(key, 0, 0)
|
.drawString(msg, 3, 25);
|
||||||
.drawString(lat, 0, 20)
|
setTimeout(updateGps, 1000);
|
||||||
.drawString(lon, 0, 40)
|
}
|
||||||
.drawString(alt, 0, 60)
|
|
||||||
.drawString(speed, 0, 80);
|
|
||||||
|
|
||||||
setTimeout(updateGps, 100);
|
function updateGoto() {
|
||||||
|
let have = false, lat = "lat ", alt = "?";
|
||||||
|
|
||||||
|
if (cancel_gps)
|
||||||
|
return;
|
||||||
|
fix = gps.getGPSFix();
|
||||||
|
|
||||||
|
if (fix && fix.fix && fix.lat) {
|
||||||
|
lat = "" + fmt.fmtPos(fix);
|
||||||
|
alt = "" + fix.alt.toFixed(0);
|
||||||
|
// speed = "" + fix.speed.toFixed(1);
|
||||||
|
// hdop = "" + fix.hdop.toFixed(0);
|
||||||
|
have = true;
|
||||||
|
} else {
|
||||||
|
lat = "NO FIX\n"
|
||||||
|
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
|
||||||
|
}
|
||||||
|
|
||||||
|
let msg = arrow.name + "\n";
|
||||||
|
msg = lat + "\n"+ alt + "m";
|
||||||
|
if (!have) {
|
||||||
|
g.reset().setFont("Vector", 31)
|
||||||
|
.setColor(1,1,1)
|
||||||
|
.fillRect(0, 24, 176, 100)
|
||||||
|
.setColor(0,0,0)
|
||||||
|
.drawString(msg, 3, 25);
|
||||||
|
} else {
|
||||||
|
arrow.draw(fix, fix.course);
|
||||||
|
}
|
||||||
|
setTimeout(updateGoto, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopGps() {
|
function stopGps() {
|
||||||
cancel_gps=true;
|
cancel_gps=true;
|
||||||
Bangle.setGPSPower(0, "waypoint_editor");
|
Bangle.setGPSPower(0, "waypoints");
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmGps(s) {
|
function confirmGps(s) {
|
||||||
|
|
@ -88,10 +406,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:"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:"h", c: [
|
||||||
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "YES", cb:l=>{
|
{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();
|
print("should mark", key, fix); createWP(fix.lat, fix.lon, fix.alt, key); stopGps(); 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: " No", cb:l=>{ stopGps(); mainMenu(); }}
|
||||||
]}
|
]}
|
||||||
], lazy:true});
|
], lazy:true});
|
||||||
g.clear();
|
g.clear();
|
||||||
|
|
@ -101,7 +419,7 @@ function confirmGps(s) {
|
||||||
|
|
||||||
function markGps() {
|
function markGps() {
|
||||||
cancel_gps = false;
|
cancel_gps = false;
|
||||||
Bangle.setGPSPower(1, "waypoint_editor");
|
Bangle.setGPSPower(1, "waypoints");
|
||||||
gps_start = getTime();
|
gps_start = getTime();
|
||||||
require("textinput").input({text:"wp"}).then(key => {
|
require("textinput").input({text:"wp"}).then(key => {
|
||||||
confirmGps(key);
|
confirmGps(key);
|
||||||
|
|
@ -112,68 +430,21 @@ function setFormat() {
|
||||||
var la = new Layout (
|
var la = new Layout (
|
||||||
{type:"v", c: [
|
{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:"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.dddd", cb:l=>{ fmt.geo_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.mmm'", cb:l=>{ fmt.geo_mode = 1; mainMenu(); }},
|
||||||
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM'ss"+'"', cb:l=>{ mode = 2; mainMenu(); }},
|
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "DD MM'ss"+'"', cb:l=>{ fmt.geo_mode = 2; mainMenu(); }},
|
||||||
], lazy:true});
|
], lazy:true});
|
||||||
g.clear();
|
g.clear();
|
||||||
la.render();
|
la.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
function format(x) {
|
|
||||||
switch (mode) {
|
|
||||||
case 0:
|
|
||||||
return "" + x;
|
|
||||||
case 1:
|
|
||||||
d = Math.floor(x);
|
|
||||||
m = x - d;
|
|
||||||
m = m*60;
|
|
||||||
return "" + d + " " + m + "'";
|
|
||||||
case 2:
|
|
||||||
d = Math.floor(x);
|
|
||||||
m = x - d;
|
|
||||||
m = m*60;
|
|
||||||
mf = Math.floor(m);
|
|
||||||
s = m - mf;
|
|
||||||
s = s*60;
|
|
||||||
return "" + d + " " + mf + "'" + s + '"';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function lat(x) {
|
|
||||||
c = "N";
|
|
||||||
if (x<0) {
|
|
||||||
c = "S";
|
|
||||||
x = -x;
|
|
||||||
}
|
|
||||||
return c+format(x);
|
|
||||||
}
|
|
||||||
function lon(x) {
|
|
||||||
c = "E";
|
|
||||||
if (x<0) {
|
|
||||||
c = "W";
|
|
||||||
x = -x;
|
|
||||||
}
|
|
||||||
return c+format(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
function show(pin) {
|
|
||||||
var i = wp[pin];
|
|
||||||
var l = lat(i["lat"]) + "\n" + lon(i["lon"]);
|
|
||||||
E.showPrompt(l,{
|
|
||||||
title:i["name"],
|
|
||||||
buttons : {"Ok":true}
|
|
||||||
}).then(function(v) {
|
|
||||||
mainMenu();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function showNumpad(text, key_, callback) {
|
function showNumpad(text, key_, callback) {
|
||||||
key = key_;
|
key = key_;
|
||||||
E.showMenu();
|
E.showMenu();
|
||||||
function addDigit(digit) {
|
function addDigit(digit) {
|
||||||
key+=digit;
|
key+=digit;
|
||||||
if (1) {
|
if (1) {
|
||||||
l = text[key.length];
|
let l = text[key.length];
|
||||||
switch (l) {
|
switch (l) {
|
||||||
case '.': case ' ': case "'":
|
case '.': case ' ': case "'":
|
||||||
key+=l;
|
key+=l;
|
||||||
|
|
@ -188,10 +459,10 @@ function showNumpad(text, key_, callback) {
|
||||||
function update() {
|
function update() {
|
||||||
g.reset();
|
g.reset();
|
||||||
g.clearRect(0,0,g.getWidth(),23);
|
g.clearRect(0,0,g.getWidth(),23);
|
||||||
s = key + text.substr(key.length, 999);
|
let s = key + text.substr(key.length, 999);
|
||||||
g.setFont("Vector:24").setFontAlign(1,0).drawString(s,g.getWidth(),12);
|
g.setFont("Vector:24").setFontAlign(1,0).drawString(s,g.getWidth(),12);
|
||||||
}
|
}
|
||||||
ds="12%";
|
let ds="12%";
|
||||||
var numPad = new Layout ({
|
var numPad = new Layout ({
|
||||||
type:"v", c: [{
|
type:"v", c: [{
|
||||||
type:"v", c: [
|
type:"v", c: [
|
||||||
|
|
@ -223,6 +494,81 @@ function showNumpad(text, key_, callback) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function goTo() {
|
||||||
|
cancel_gps = false;
|
||||||
|
Bangle.setGPSPower(1, "waypoints");
|
||||||
|
gps.gps_start = getTime();
|
||||||
|
gps_start = getTime();
|
||||||
|
|
||||||
|
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: [
|
||||||
|
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: " Done", cb:l=>{ stopGps(); mainMenu(); }}
|
||||||
|
]}
|
||||||
|
], lazy:true});
|
||||||
|
g.clear();
|
||||||
|
la.render();
|
||||||
|
|
||||||
|
updateGoto();
|
||||||
|
}
|
||||||
|
|
||||||
|
function show(pin) {
|
||||||
|
var i = wp[pin];
|
||||||
|
var l = fmt.fmtPos(i);
|
||||||
|
arrow.name = i.name;
|
||||||
|
arrow.waypoint = i;
|
||||||
|
|
||||||
|
var la = new Layout (
|
||||||
|
{type:"v", c: [
|
||||||
|
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:arrow.name },
|
||||||
|
{type:"txt", font:"15%", pad:1, fillx:1, filly:1, label:l },
|
||||||
|
{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: "Go", cb:l=>{ goTo(); }},
|
||||||
|
{type:"btn", font:"15%", pad:1, fillx:1, filly:1, label: "Ok", cb:l=>{ mainMenu(); }}
|
||||||
|
]}
|
||||||
|
], lazy:true});
|
||||||
|
g.clear();
|
||||||
|
la.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function showCard() {
|
||||||
|
var menu = {
|
||||||
|
"" : {title : "Select WP"},
|
||||||
|
"< Back" : mainMenu
|
||||||
|
};
|
||||||
|
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
|
||||||
|
else {
|
||||||
|
wp.forEach((val, card) => {
|
||||||
|
const name = wp[card].name;
|
||||||
|
menu[name]= () => show(card);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
E.showMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove(pin)
|
||||||
|
{
|
||||||
|
let card = wp[pin];
|
||||||
|
let name = card["name"];
|
||||||
|
print("Remove?", card, name);
|
||||||
|
|
||||||
|
E.showPrompt(name,{
|
||||||
|
title:"Delete",
|
||||||
|
}).then(function(v) {
|
||||||
|
if (v) {
|
||||||
|
wp.splice(pin, 1);
|
||||||
|
writeWP();
|
||||||
|
mainMenu();
|
||||||
|
} else {
|
||||||
|
mainMenu();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function removeCard() {
|
function removeCard() {
|
||||||
var menu = {
|
var menu = {
|
||||||
"" : {title : "Select WP"},
|
"" : {title : "Select WP"},
|
||||||
|
|
@ -232,19 +578,7 @@ function removeCard() {
|
||||||
else {
|
else {
|
||||||
wp.forEach((val, card) => {
|
wp.forEach((val, card) => {
|
||||||
const name = wp[card].name;
|
const name = wp[card].name;
|
||||||
menu[name]=()=>{
|
menu[name]=()=> remove(card);
|
||||||
E.showPrompt(name,{
|
|
||||||
title:"Delete",
|
|
||||||
}).then(function(v) {
|
|
||||||
if (v) {
|
|
||||||
wp.splice(card, 1);
|
|
||||||
writeWP();
|
|
||||||
mainMenu();
|
|
||||||
} else {
|
|
||||||
mainMenu();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
|
|
@ -261,16 +595,19 @@ function ask01(t, cb) {
|
||||||
la.render();
|
la.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var res;
|
||||||
|
|
||||||
function askCoordinate(t1, t2, callback) {
|
function askCoordinate(t1, t2, callback) {
|
||||||
//let sign = 1;
|
//let sign = 1;
|
||||||
ask01(t1, function(sign) {
|
ask01(t1, function(sign) {
|
||||||
switch (mode) {
|
let d, m, s;
|
||||||
|
switch (fmt.geo_mode) {
|
||||||
case 0: s = "DDD.dddd"; break;
|
case 0: s = "DDD.dddd"; break;
|
||||||
case 1: s = "DDD MM.mmm"; break;
|
case 1: s = "DDD MM.mmm"; break;
|
||||||
case 2: s = "DDD MM'ss"+'"'; break;
|
case 2: s = "DDD MM'ss"+'"'; break;
|
||||||
}
|
}
|
||||||
showNumpad(s, t2, function() {
|
showNumpad(s, t2, function() {
|
||||||
switch (mode) {
|
switch (fmt.geo_mode) {
|
||||||
case 0:
|
case 0:
|
||||||
res = parseFloat(key);
|
res = parseFloat(key);
|
||||||
break;
|
break;
|
||||||
|
|
@ -300,21 +637,25 @@ function askPosition(callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWP(lat, lon, name) {
|
function createWP(lat, lon, alt, name) {
|
||||||
let n = {};
|
let n = {};
|
||||||
n["name"] = name;
|
n["name"] = name;
|
||||||
n["lat"] = lat;
|
n["lat"] = lat;
|
||||||
n["lon"] = lon;
|
n["lon"] = lon;
|
||||||
|
if (alt != -9999)
|
||||||
|
n["alt"] = alt;
|
||||||
wp.push(n);
|
wp.push(n);
|
||||||
print("add -- waypoints", wp);
|
print("add -- waypoints", wp);
|
||||||
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, result);
|
createWP(lat, lon, -9999, result);
|
||||||
mainMenu();
|
mainMenu();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -340,5 +681,8 @@ function addCard() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.init();
|
||||||
|
gps.init();
|
||||||
|
|
||||||
g.reset();
|
g.reset();
|
||||||
mainMenu();
|
mainMenu();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue