waypoints: cleanups, mostly formatting / whitespace.
parent
2b7062939e
commit
de755fc78b
|
|
@ -1,7 +1,6 @@
|
||||||
/* 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
|
|
||||||
|
|
||||||
/* fmt library v0.2.2 */
|
/* fmt library v0.2.2 */
|
||||||
let fmt = {
|
let fmt = {
|
||||||
|
|
@ -28,9 +27,9 @@ let fmt = {
|
||||||
fmtSteps: function(n) { return this.fmtDist(0.001 * 0.719 * n); },
|
fmtSteps: function(n) { return this.fmtDist(0.001 * 0.719 * n); },
|
||||||
fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; },
|
fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; },
|
||||||
fmtTemp: function(c) { return c.toFixed(1) + this.icon_c; },
|
fmtTemp: function(c) { return c.toFixed(1) + this.icon_c; },
|
||||||
fmtPress: function(p) {
|
fmtPress: function(p) {
|
||||||
if (p < 900 || p > 1100)
|
if (p < 900 || p > 1100)
|
||||||
return p.toFixed(0) + this.icon_hpa;
|
return p.toFixed(0) + this.icon_hpa;
|
||||||
if (p < 1000) {
|
if (p < 1000) {
|
||||||
p -= 900;
|
p -= 900;
|
||||||
return this.icon_9 + this.add0(p.toFixed(0)) + this.icon_hpa;
|
return this.icon_9 + this.add0(p.toFixed(0)) + this.icon_hpa;
|
||||||
|
|
@ -135,7 +134,7 @@ let fmt = {
|
||||||
let gps = {
|
let gps = {
|
||||||
emulator: -1,
|
emulator: -1,
|
||||||
init: function(x) {
|
init: function(x) {
|
||||||
this.emulator = (process.env.BOARD=="EMSCRIPTEN"
|
this.emulator = (process.env.BOARD=="EMSCRIPTEN"
|
||||||
|| process.env.BOARD=="EMSCRIPTEN2")?1:0;
|
|| process.env.BOARD=="EMSCRIPTEN2")?1:0;
|
||||||
},
|
},
|
||||||
state: {},
|
state: {},
|
||||||
|
|
@ -191,7 +190,7 @@ let arrow = {
|
||||||
this.waypoint.lat = lat;
|
this.waypoint.lat = lat;
|
||||||
this.waypoint.lon = lon;
|
this.waypoint.lon = lon;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Calculate the bearing to the waypoint
|
// Calculate the bearing to the waypoint
|
||||||
bearingToWaypoint: function(currentPos) {
|
bearingToWaypoint: function(currentPos) {
|
||||||
return fmt.bearing(currentPos, this.waypoint);
|
return fmt.bearing(currentPos, this.waypoint);
|
||||||
|
|
@ -210,7 +209,7 @@ let arrow = {
|
||||||
// Display function to show arrows for waypoint, north, and sun
|
// Display function to show arrows for waypoint, north, and sun
|
||||||
displayNavigation: function(currentPos, currentHeading) {
|
displayNavigation: function(currentPos, currentHeading) {
|
||||||
g.clear().setFont("Vector", 22).setFontAlign(0, 0);
|
g.clear().setFont("Vector", 22).setFontAlign(0, 0);
|
||||||
|
|
||||||
// Calculate bearings
|
// Calculate bearings
|
||||||
let waypointBearing = this.bearingToWaypoint(currentPos);
|
let waypointBearing = this.bearingToWaypoint(currentPos);
|
||||||
let distance = this.distanceToWaypoint(currentPos);
|
let distance = this.distanceToWaypoint(currentPos);
|
||||||
|
|
@ -228,7 +227,7 @@ let arrow = {
|
||||||
this.drawArrow(waypointBearing, `${distStr}`, 3);
|
this.drawArrow(waypointBearing, `${distStr}`, 3);
|
||||||
|
|
||||||
let s;
|
let s;
|
||||||
|
|
||||||
s = sun.sunPos();
|
s = sun.sunPos();
|
||||||
// Draw sun arrow if sun is visible
|
// Draw sun arrow if sun is visible
|
||||||
if (s.altitude > 0) {
|
if (s.altitude > 0) {
|
||||||
|
|
@ -249,7 +248,7 @@ let arrow = {
|
||||||
let centerX = 88;
|
let centerX = 88;
|
||||||
let centerY = 88;
|
let centerY = 88;
|
||||||
let length = 60; // Arrow length
|
let length = 60; // Arrow length
|
||||||
|
|
||||||
g.drawCircle(centerX, centerY, length);
|
g.drawCircle(centerX, centerY, length);
|
||||||
|
|
||||||
// Calculate the rectangle's corner points for the rotated arrow
|
// Calculate the rectangle's corner points for the rotated arrow
|
||||||
|
|
@ -319,47 +318,45 @@ function mainMenu() {
|
||||||
var menu = {
|
var menu = {
|
||||||
"< Back" : () => load()
|
"< Back" : () => load()
|
||||||
};
|
};
|
||||||
if (textInputInstalled && BANGLEJS2) {
|
|
||||||
menu["Add"]=addCard;
|
|
||||||
}
|
|
||||||
menu["Show"]=showCard;
|
menu["Show"]=showCard;
|
||||||
menu["Remove"]=removeCard;
|
if (textInputInstalled) {
|
||||||
menu["Format"]=setFormat;
|
menu["Add"]=addCard;
|
||||||
if (textInputInstalled && BANGLEJS2) {
|
|
||||||
menu["Mark GPS"]=markGps;
|
menu["Mark GPS"]=markGps;
|
||||||
}
|
}
|
||||||
|
menu["Remove"]=removeCard;
|
||||||
|
menu["Format"]=setFormat;
|
||||||
g.clear();
|
g.clear();
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateGps() {
|
function updateGps() {
|
||||||
let have = false, lat = "lat ", alt = "?",
|
let have = false, lat = "lat ", alt = "?",
|
||||||
speed = "speed ", hdop = "?", adelta = "adelta ",
|
speed = "speed ", hdop = "?", adelta = "adelta ",
|
||||||
tdelta = "tdelta ";
|
tdelta = "tdelta ";
|
||||||
|
|
||||||
if (cancel_gps)
|
if (cancel_gps)
|
||||||
return;
|
return;
|
||||||
fix = gps.getGPSFix();
|
fix = gps.getGPSFix();
|
||||||
|
|
||||||
if (fix && fix.fix && fix.lat) {
|
if (fix && fix.fix && fix.lat) {
|
||||||
lat = "" + fmt.fmtPos(fix);
|
lat = "" + fmt.fmtPos(fix);
|
||||||
alt = "" + fix.alt.toFixed(0);
|
alt = "" + fix.alt.toFixed(0);
|
||||||
speed = "" + fix.speed.toFixed(1);
|
speed = "" + fix.speed.toFixed(1);
|
||||||
hdop = "" + fix.hdop.toFixed(0);
|
hdop = "" + fix.hdop.toFixed(0);
|
||||||
have = true;
|
have = true;
|
||||||
} else {
|
} else {
|
||||||
lat = "NO FIX\n"
|
lat = "NO FIX\n"
|
||||||
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
|
+ "" + (getTime() - gps_start).toFixed(0) + "s ";
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg = "";
|
let msg = "";
|
||||||
msg = lat + "\n"+ alt + "m";
|
msg = lat + "\n"+ alt + "m";
|
||||||
g.reset().setFont("Vector", 31)
|
g.reset().setFont("Vector", 31)
|
||||||
.setColor(1,1,1)
|
.setColor(1,1,1)
|
||||||
.fillRect(0, 24, 176, 100)
|
.fillRect(0, 24, 176, 100)
|
||||||
.setColor(0,0,0)
|
.setColor(0,0,0)
|
||||||
.drawString(msg, 3, 25);
|
.drawString(msg, 3, 25);
|
||||||
setTimeout(updateGps, 1000);
|
setTimeout(updateGps, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopGps() {
|
function stopGps() {
|
||||||
|
|
@ -368,22 +365,22 @@ function stopGps() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmGps(s) {
|
function confirmGps(s) {
|
||||||
key = s;
|
key = s;
|
||||||
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:""},
|
{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:"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, fix.alt, key); cancel_gps=true; mainMenu();
|
print("should mark", key, fix); createWP(fix.lat, fix.lon, fix.alt, 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: " NO", cb:l=>{ cancel_gps=true; mainMenu(); }}
|
||||||
]}
|
]}
|
||||||
], lazy:true});
|
], lazy:true});
|
||||||
g.clear();
|
g.clear();
|
||||||
la.render();
|
la.render();
|
||||||
updateGps();
|
updateGps();
|
||||||
}
|
}
|
||||||
|
|
||||||
function markGps() {
|
function markGps() {
|
||||||
|
|
@ -459,68 +456,68 @@ function showNumpad(text, key_, callback) {
|
||||||
]}
|
]}
|
||||||
], lazy:true});
|
], lazy:true});
|
||||||
g.clear();
|
g.clear();
|
||||||
numPad.render();
|
numPad.render();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
function show(pin) {
|
function show(pin) {
|
||||||
var i = wp[pin];
|
var i = wp[pin];
|
||||||
var l = fmt.fmtPos(i);
|
var l = fmt.fmtPos(i);
|
||||||
E.showPrompt(l,{
|
E.showPrompt(l,{
|
||||||
title:i["name"],
|
title:i["name"],
|
||||||
buttons : {"Ok":true}
|
buttons : {"Ok":true}
|
||||||
}).then(function(v) {
|
}).then(function(v) {
|
||||||
mainMenu();
|
mainMenu();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showCard() {
|
function showCard() {
|
||||||
var menu = {
|
var menu = {
|
||||||
"" : {title : "Select WP"},
|
"" : {title : "Select WP"},
|
||||||
"< Back" : mainMenu
|
"< Back" : mainMenu
|
||||||
};
|
};
|
||||||
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
|
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
|
||||||
else {
|
else {
|
||||||
wp.forEach((val, card) => {
|
wp.forEach((val, card) => {
|
||||||
const name = wp[card].name;
|
const name = wp[card].name;
|
||||||
menu[name]= () => show(card);
|
menu[name]= () => show(card);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(pin)
|
function remove(pin)
|
||||||
{
|
{
|
||||||
let card = wp[pin];
|
let card = wp[pin];
|
||||||
let name = card["name"];
|
let name = card["name"];
|
||||||
print("Remove?", card, name);
|
print("Remove?", card, name);
|
||||||
|
|
||||||
E.showPrompt(name,{
|
E.showPrompt(name,{
|
||||||
title:"Delete",
|
title:"Delete",
|
||||||
}).then(function(v) {
|
}).then(function(v) {
|
||||||
if (v) {
|
if (v) {
|
||||||
wp.splice(pin, 1);
|
wp.splice(pin, 1);
|
||||||
writeWP();
|
writeWP();
|
||||||
mainMenu();
|
mainMenu();
|
||||||
} else {
|
} else {
|
||||||
mainMenu();
|
mainMenu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeCard() {
|
function removeCard() {
|
||||||
var menu = {
|
var menu = {
|
||||||
"" : {title : "Select WP"},
|
"" : {title : "Select WP"},
|
||||||
"< Back" : mainMenu
|
"< Back" : mainMenu
|
||||||
};
|
};
|
||||||
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
|
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""});
|
||||||
else {
|
else {
|
||||||
wp.forEach((val, card) => {
|
wp.forEach((val, card) => {
|
||||||
const name = wp[card].name;
|
const name = wp[card].name;
|
||||||
menu[name]=()=> remove(card);
|
menu[name]=()=> remove(card);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ask01(t, cb) {
|
function ask01(t, cb) {
|
||||||
|
|
@ -598,18 +595,18 @@ function addCard() {
|
||||||
require("textinput").input({text:"wp"}).then(key => {
|
require("textinput").input({text:"wp"}).then(key => {
|
||||||
result = key;
|
result = key;
|
||||||
if (wp[result]!=undefined) {
|
if (wp[result]!=undefined) {
|
||||||
E.showMenu();
|
E.showMenu();
|
||||||
var alreadyExists = new Layout (
|
var alreadyExists = new Layout (
|
||||||
{type:"v", c: [
|
{type:"v", c: [
|
||||||
{type:"txt", font:Math.min(15,100/result.length)+"%", pad:1, fillx:1, filly:1, label:result},
|
{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:"txt", font:"12%", pad:1, fillx:1, filly:1, label:"already exists."},
|
||||||
{type:"h", c: [
|
{type:"h", c: [
|
||||||
{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: "REPLACE", cb:l=>{addCardName(result);}},
|
||||||
{type:"btn", font:"10%", pad:1, fillx:1, filly:1, label: "CANCEL", cb:l=>{mainMenu();}}
|
{type:"btn", font:"10%", pad:1, fillx:1, filly:1, label: "CANCEL", cb:l=>{mainMenu();}}
|
||||||
]}
|
]}
|
||||||
], lazy:true});
|
], lazy:true});
|
||||||
g.clear();
|
g.clear();
|
||||||
alreadyExists.render();
|
alreadyExists.render();
|
||||||
}
|
}
|
||||||
addCardName(result);
|
addCardName(result);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue