Merge branch 'espruino:master' into master

pull/3675/head
gsuarezc 2024-11-28 21:42:21 +00:00 committed by GitHub
commit 5361bcc259
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 511 additions and 469 deletions

View File

@ -1,3 +1,4 @@
0.01: attempt to import 0.01: attempt to import
0.02: Minor code improvements 0.02: Minor code improvements
0.03: big rewrite, adding time-adjust and altitude-adjust functionality 0.03: big rewrite, adding time-adjust and altitude-adjust functionality
0.04: more refactoring, fix lat/lon display

View File

@ -1,6 +1,6 @@
{ "id": "skyspy", { "id": "skyspy",
"name": "Sky Spy", "name": "Sky Spy",
"version": "0.03", "version": "0.04",
"description": "Application for debugging GPS problems", "description": "Application for debugging GPS problems",
"icon": "app.png", "icon": "app.png",
"readme": "README.md", "readme": "README.md",

View File

@ -1,426 +1,493 @@
/* Sky spy */ /* Sky spy */
/* fmt library v0.1 */ /* fmt library v0.2.3 */
let fmt = { let fmt = {
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_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_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_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_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_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"
*/ */
geo_mode : 1, geo_mode : 1,
init: function() {}, init: function() {},
fmtDist: function(km) { return km.toFixed(1) + this.icon_km; }, fmtDist: function(km) {
fmtSteps: function(n) { return this.fmtDist(0.001 * 0.719 * n); }, if (km >= 1.0) return km.toFixed(1) + this.icon_km;
fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; }, return (km*1000).toFixed(0) + this.icon_m;
fmtTimeDiff: function(d) { },
if (d < 180) fmtSteps: function(n) { return this.fmtDist(0.001 * 0.719 * n); },
return ""+d.toFixed(0); fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; },
d = d/60; fmtTemp: function(c) { return c.toFixed(1) + this.icon_c; },
return ""+d.toFixed(0)+"m"; fmtPress: function(p) {
}, if (p < 900 || p > 1100)
fmtAngle: function(x) { return p.toFixed(0) + this.icon_hpa;
switch (this.geo_mode) { if (p < 1000) {
case 0: p -= 900;
return "" + x; return this.icon_9 + this.add0(p.toFixed(0)) + this.icon_hpa;
case 1: { }
let d = Math.floor(x); p -= 1000;
let m = x - d; return this.icon_10 + this.add0(p.toFixed(0)) + this.icon_hpa;
m = m*60; },
return "" + d + " " + m.toFixed(3) + "'"; draw_dot : 1,
} add0: function(i) {
case 2: { if (i > 9) {
let d = Math.floor(x); return ""+i;
let m = x - d; } else {
m = m*60; return "0"+i;
let mf = Math.floor(m); }
let s = m - mf; },
s = s*60; fmtTOD: function(now) {
return "" + d + " " + mf + "'" + s.toFixed(0) + '"'; this.draw_dot = !this.draw_dot;
} let dot = ":";
} if (!this.draw_dot)
return "bad mode?"; dot = ".";
}, return now.getHours() + dot + this.add0(now.getMinutes());
fmtPos: function(pos) { },
let x = pos.lat; fmtNow: function() { return this.fmtTOD(new Date()); },
let c = "N"; fmtTimeDiff: function(d) {
if (x<0) { if (d < 180)
c = "S"; return ""+d.toFixed(0);
x = -x; d = d/60;
} return ""+d.toFixed(0)+"m";
let s = c+this.fmtAngle(pos.lat) + "\n"; },
c = "E"; fmtAngle: function(x) {
if (x<0) { switch (this.geo_mode) {
c = "W"; case 0:
x = -x; return "" + x;
} case 1: {
return s + c + this.fmtAngle(pos.lon); 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 */ /* gps library v0.1.4 */
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: {},
on_gps: function(f) { on_gps: function(f) {
let fix = this.getGPSFix(); let fix = this.getGPSFix();
f(fix); f(fix);
/* /*
"lat": number, // Latitude in degrees "lat": number, // Latitude in degrees
"lon": number, // Longitude in degrees "lon": number, // Longitude in degrees
"alt": number, // altitude in M "alt": number, // altitude in M
"speed": number, // Speed in kph "speed": number, // Speed in kph
"course": number, // Course in degrees "course": number, // Course in degrees
"time": Date, // Current Time (or undefined if not known) "time": Date, // Current Time (or undefined if not known)
"satellites": 7, // Number of satellites "satellites": 7, // Number of satellites
"fix": 1 // NMEA Fix state - 0 is no fix "fix": 1 // NMEA Fix state - 0 is no fix
"hdop": number, // Horizontal Dilution of Precision "hdop": number, // Horizontal Dilution of Precision
*/ */
this.state.timeout = setTimeout(this.on_gps, 1000, f); this.state.timeout = setTimeout(this.on_gps, 1000, f);
}, },
off_gps: function() { off_gps: function() {
clearTimeout(this.state.timeout); clearTimeout(this.state.timeout);
}, },
getGPSFix: function() { getGPSFix: function() {
if (!this.emulator) if (!this.emulator)
return Bangle.getGPSFix(); return Bangle.getGPSFix();
let fix = {}; let fix = {};
fix.fix = 1; fix.fix = 1;
fix.lat = 50; fix.lat = 50;
fix.lon = 14; fix.lon = 14-(getTime()-this.gps_start) / 1000; /* Go West! */
fix.alt = 200; fix.alt = 200;
fix.speed = 5; fix.speed = 5;
fix.course = 30; fix.course = 30;
fix.time = Date(); fix.time = Date();
fix.satellites = 5; fix.satellites = 5;
fix.hdop = 12; fix.hdop = 12;
return fix; return fix;
} },
gps_start : -1,
start_gps: function() {
Bangle.setGPSPower(1, "libgps");
this.gps_start = getTime();
},
stop_gps: function() {
Bangle.setGPSPower(0, "libgps");
},
}; };
var display = 0; /* ui library 0.1.3 */
var debug = 0; let ui = {
var gps_start; display: 0,
var cur_altitude; numScreens: 2,
var wi = 24; drawMsg: function(msg) {
var h = 176-wi, w = 176; g.reset().setFont("Vector", 35)
var fix; .setColor(1, 1, 1)
var adj_time = 0, adj_alt = 0; .fillRect(0, this.wi, this.w, this.y2)
.setColor(0, 0, 0)
function radA(p) { return p*(Math.PI*2); } .drawString(msg, 5, 30)
function radD(d) { return d*(h/2); } .flip();
function radX(p, d) { },
let a = radA(p); drawBusy: function() {
return w/2 + Math.sin(a)*radD(d); this.drawMsg("\n.oO busy");
} },
function radY(p, d) { nextScreen: function() {
let a = radA(p); print("nextS");
return h/2 - Math.cos(a)*radD(d) + wi; this.display = this.display + 1;
} if (this.display == this.numScreens)
this.display = 0;
var qalt = -1, min_dalt, max_dalt, step; this.drawBusy();
function resetAlt() { },
min_dalt = 9999; max_dalt = -9999; step = 0; prevScreen: function() {
} print("prevS");
resetAlt(); this.display = this.display - 1;
if (this.display < 0)
function calcAlt(alt, cur_altitude) { this.display = this.numScreens - 1;
let dalt = alt - cur_altitude; this.drawBusy();
},
if (min_dalt > dalt) onSwipe: function(dir) {
min_dalt = dalt; this.nextScreen();
if (max_dalt < dalt) },
max_dalt = dalt; wi: 24,
y2: 176,
let ddalt = max_dalt - min_dalt; h: 152,
return ddalt; w: 176,
} last_b: 0,
function updateGps() { topLeft: function() { this.drawMsg("Unimpl"); },
let lat = "lat ", alt = "?", topRight: function() { this.drawMsg("Unimpl"); },
speed = "speed ", hdop = "?", adelta = "adelta ", touchHandler: function(d) {
tdelta = "tdelta ";
fix = gps.getGPSFix();
if (adj_time) {
print("Adjusting time");
setTime(fix.time.getTime()/1000);
adj_time = 0;
}
if (adj_alt) {
print("Adjust altitude");
if (qalt < 5) {
let rest_altitude = fix.alt;
let alt_adjust = cur_altitude - rest_altitude;
let abs = Math.abs(alt_adjust);
print("adj", alt_adjust);
let o = Bangle.getOptions();
if (abs > 10 && abs < 150) {
let a = 0.01;
// FIXME: draw is called often compared to alt reading
if (cur_altitude > rest_altitude)
a = -a;
o.seaLevelPressure = o.seaLevelPressure + a;
Bangle.setOptions(o);
}
msg = o.seaLevelPressure.toFixed(1) + "hPa";
print(msg);
}
}
try {
Bangle.getPressure().then((x) => {
cur_altitude = x.altitude;
}, print);
} catch (e) {
//print("Altimeter error", e);
}
//print(fix);
if (fix && fix.time) {
tdelta = "" + (getTime() - fix.time.getTime()/1000).toFixed(0);
}
if (fix && fix.fix && fix.lat) {
lat = "" + fmt.fmtPos(fix);
alt = "" + fix.alt.toFixed(0);
adelta = "" + (cur_altitude - fix.alt).toFixed(0);
speed = "" + fix.speed.toFixed(1);
hdop = "" + fix.hdop.toFixed(0);
} else {
lat = "NO FIX\n"
+ "" + (getTime() - gps_start).toFixed(0) + "s "
+ sats_used + "/" + snum;
if (cur_altitude)
adelta = "" + cur_altitude.toFixed(0);
}
let ddalt = calcAlt(alt, cur_altitude);
let msg = "";
if (display == 1) {
msg = lat +
"\ne" + hdop + "m "+tdelta+"s\n" +
speed + "km/h\n"+ alt + "m+" + adelta + "\nmsghere";
}
if (display == 2) {
/* qalt is altitude quality estimate -- over ten seconds,
computes differences between GPS and barometric altitude.
The lower the better.
ddalt is just a debugging -- same estimate, but without
waiting 10 seconds, so will be always optimistic at start
of the cycle */
msg = speed + "km/h\n" +
"e"+hdop + "m"
+"\ndd "+qalt.toFixed(0) + "\n(" + step + "/" + ddalt.toFixed(0) + ")" +
"\n"+alt + "m+" + adelta;
}
step++;
if (step == 10) {
qalt = max_dalt - min_dalt;
resetAlt();
}
if (display > 0) {
g.reset().setFont("Vector", 31)
.setColor(1,1,1)
.fillRect(0, wi, 176, 176)
.setColor(0,0,0)
.drawString(msg, 3, 25);
}
if (debug > 0)
print(fix);
setTimeout(updateGps, 1000);
}
function radLine(a1, d1, a2, d2) {
g.drawLine(radX(a1, d1), radY(a1, d1), radX(a2, d2), radY(a2, d2));
}
function radCircle(d) {
let step = 0.05;
for (let i=0; i<1; i+=0.05) {
radLine(i-step, d, i, d);
}
//g.flip();
}
function drawGrid() {
g.setColor(0,0,0);
radLine(0, 1, 0.5, 1);
radLine(0.25, 1, 0.75, 1);
radCircle(0.5);
radCircle(1.0);
}
function drawSat(s) {
let a = s.azi / 360;
let e = ((90 - s.ele) / 90);
let x = radX(a, e);
let y = radY(a, e);
if (s.snr == "")
g.setColor(1, 0.25, 0.25);
else {
//let snr = 1*s.snr;
g.setColor(0, 0, 0);
//sats_receiving ++;
}
g.drawString(s.id, x, y);
}
// Should correspond to view from below.
// https://in-the-sky.org//satmap_radar.php?year=2023&month=10&day=24&skin=1
function drawSats(sats) {
//sats_receiving = 0;
g.reset().setFont("Vector", 20)
.setColor(1,1,1)
.fillRect(0, 30, 176, 176);
drawGrid();
for (var s of sats) {
if (debug > 1)
print(s.ele, s.azi, s.snr);
drawSat(s);
}
if (fix && fix.fix && fix.lat) {
g.setColor(0, 0, 0);
g.drawString(fix.satellites + "/" + fix.hdop, 10, 150);
}
}
var sats = [];
var snum = 0;
var sats_used = 0;
function parseRaw(msg, lost) {
if (lost)
print("## data lost");
let s = msg.split(",");
if (s[0] != "$GPGSV")
return;
//print("Message", s[2], s[1]);
if (debug > 0)
print(msg);
if (s[2] == "1") {
snum = 0;
sats = [];
sats_used = 0;
}
let view = 1 * s[3];
// s[3] -- sats in view.
// id, ele, azi, snr
if (debug > 0)
print("in view:", view);
let i = 4;
let k = 4;
if (view - snum < k)
k = view - snum;
for (let j=0; j<k; j++) {
let sat = {};
sat.id = s[i++];
sat.ele = 1*s[i++];
sat.azi = 1*s[i++];
sat.snr = s[i++];
if (sat.snr != "")
sats_used++;
if (debug > 0)
print(" ", sat);
sats[snum++] = sat;
}
if (debug > 1)
print("Checksum:", s[i]);
if (s[1] == s[2]) {
print("Complete...");
//print(sats);
if (display == 0)
drawSats(sats);
}
}
function markGps() {
Bangle.setGPSPower(1, "skyspy");
Bangle.on('GPS-raw', parseRaw);
gps_start = getTime();
updateGps();
}
function drawMsg(msg) {
g.reset().setFont("Vector", 35)
.setColor(1,1,1)
.fillRect(0, wi, 176, 176)
.setColor(0,0,0)
.drawString(msg, 5, 30);
}
function drawBusy() {
drawMsg("\n.oO busy");
}
var numScreens = 3;
function nextScreen() {
display = display + 1;
if (display == numScreens)
display = 0;
drawBusy();
}
function prevScreen() {
display = display - 1;
if (display < 0)
display = numScreens - 1;
drawBusy();
}
function onSwipe(dir) {
nextScreen();
}
var last_b = 0;
function touchHandler(d) {
let x = Math.floor(d.x); let x = Math.floor(d.x);
let y = Math.floor(d.y); let y = Math.floor(d.y);
if (d.b != 1 || last_b != 0) { if (d.b != 1 || this.last_b != 0) {
last_b = d.b; this.last_b = d.b;
return; return;
} }
last_b = d.b;
print("touch", x, y, this.h, this.w);
if ((x<h/2) && (y<w/2)) { if ((x<this.w/2) && (y<this.y2/2))
drawMsg("Clock\nadjust"); this.topLeft();
adj_time = 1; if ((x>this.w/2) && (y<this.y2/2))
this.topRight();
if ((x<this.w/2) && (y>this.y2/2)) {
print("prev");
this.prevScreen();
} }
if ((x>h/2) && (y<w/2)) { if ((x>this.w/2) && (y>this.y2/2)) {
drawMsg("Alt\nadjust"); print("next");
adj_alt = 1; this.nextScreen();
} }
},
init: function() {
this.h = this.y2 - this.wi;
this.drawBusy();
}
};
if ((x<h/2) && (y>w/2))
prevScreen(); var debug = 0;
if ((x>h/2) && (y>w/2)) var cur_altitude;
nextScreen(); var fix;
var adj_time = 0, adj_alt = 0;
/* radial angle -- convert 0..1 to 0..2pi */
function radA(p) { return p*(Math.PI*2); }
/* radial distance -- convert 0..1 to something that fits on screen */
function radD(d) { return d*(ui.h/2); }
/* given angle/distance, get X coordinate */
function radX(p, d) {
let a = radA(p);
return ui.w/2 + Math.sin(a)*radD(d);
}
/* given angle/distance, get Y coordinate */
function radY(p, d) {
let a = radA(p);
return ui.h/2 - Math.cos(a)*radD(d) + ui.wi;
} }
let gps_quality = {
min_dalt: 9999,
max_dalt: -9999,
step: 0,
resetAlt: function() {
this.min_dalt = 9999;
this.max_dalt = -9999;
this.step = 0;
},
calcAlt: function(alt, cur_altitude) {
let dalt = alt - cur_altitude;
if (this.min_dalt > dalt) this.min_dalt = dalt;
if (this.max_dalt < dalt) this.max_dalt = dalt;
return this.max_dalt - this.min_dalt;
}
};
var qalt = 9999; /* global, altitude quality */
let gps_display = {
updateGps: function() {
let lat = "lat ", alt = "?", speed = "speed ", hdop = "?",
adelta = "adelta ", tdelta = "tdelta ";
fix = gps.getGPSFix();
if (adj_time) {
print("Adjusting time");
setTime(fix.time.getTime()/1000);
adj_time = 0;
}
if (adj_alt) {
print("Adjust altitude");
gps_display.adjustAltitude();
}
gps_display.updateAltitude();
gps_display.displayData(lat, alt, speed, hdop, adelta, tdelta);
setTimeout(gps_display.updateGps, 1000);
},
adjustAltitude: function() {
if (qalt < 5) {
let rest_altitude = fix.alt;
let alt_adjust = cur_altitude - rest_altitude;
let abs = Math.abs(alt_adjust);
print("adj", alt_adjust);
let o = Bangle.getOptions();
if (abs > 10 && abs < 150) {
let a = 0.01;
if (cur_altitude > rest_altitude) a = -a;
o.seaLevelPressure = o.seaLevelPressure + a;
Bangle.setOptions(o);
}
print(o.seaLevelPressure.toFixed(1) + "hPa");
}
},
updateAltitude: function() {
try {
Bangle.getPressure().then((x) => {
cur_altitude = x.altitude;
}, print);
} catch (e) {}
},
displayData: function(lat, alt, speed, hdop, adelta, tdelta) {
if (fix && fix.time) {
tdelta = "" + (getTime() - fix.time.getTime()/1000).toFixed(0);
}
if (fix && fix.fix && fix.lat) {
lat = "" + fmt.fmtPos(fix);
alt = "" + fix.alt.toFixed(0);
adelta = "" + (cur_altitude - fix.alt).toFixed(0);
speed = "" + fix.speed.toFixed(1);
hdop = "" + fix.hdop.toFixed(0);
} else {
lat = "NO FIX\n" + (getTime() - gps.gps_start).toFixed(0) + "s "
+ sky.sats_used + "/" + sky.snum;
if (cur_altitude) adelta = "" + cur_altitude.toFixed(0);
}
let ddalt = gps_quality.calcAlt(alt, cur_altitude);
let msg = this.formatDisplayMessage(lat, alt, speed, hdop, adelta, ddalt, tdelta);
if (ui.display > 0) {
g.reset().setFont("Vector", 31)
.setColor(1,1,1).fillRect(0, ui.wi, ui.w, ui.y2)
.setColor(0,0,0).drawString(msg, 3, 25);
}
if (debug > 0) print(fix);
},
formatDisplayMessage: function(lat, alt, speed, hdop, adelta, ddalt, tdelta) {
let msg = "";
if (ui.display == 1) {
msg = lat + "\ne" + hdop + "m " + tdelta + "s\n" +
speed + "km/h\n" + alt + "m+" + adelta + "\nmsghere";
} else if (ui.display == 2) {
msg = speed + "km/h\n" + "e" + hdop + "m" + "\ndd " +
qalt.toFixed(0) + "\n(" + gps_quality.step + "/" +
ddalt.toFixed(0) + ")" + "\n" + alt + "m+" + adelta;
}
gps_quality.step++;
if (gps_quality.step == 10) {
qalt = gps_quality.max_dalt - gps_quality.min_dalt;
gps_quality.resetAlt();
}
return msg;
}
};
/* sky library v0.0.1 */
let sky = {
sats: [],
snum: 0,
sats_used: 0,
drawGrid: function() {
g.setColor(0,0,0);
this.radLine(0, 1, 0.5, 1);
this.radLine(0.25, 1, 0.75, 1);
this.radCircle(0.5);
this.radCircle(1.0);
},
radLine: function(a1, d1, a2, d2) {
g.drawLine(radX(a1, d1), radY(a1, d1), radX(a2, d2), radY(a2, d2));
},
radCircle: function(d) {
/* FIXME: .. should do real circle */
g.drawCircle(radX(0, 0), radY(0, 0), radD(d));
if (1)
return;
let step = 0.05;
for (let i = 0; i < 1; i += 0.05) {
this.radLine(i - step, d, i, d);
}
},
drawSat: function(s) {
let a = s.azi / 360;
let e = ((90 - s.ele) / 90);
let x = radX(a, e);
let y = radY(a, e);
g.setColor(s.snr === "" ? 1 : 0, s.snr === "" ? 0.25 : 0, s.snr === "" ? 0.25 : 0);
g.drawString(s.id, x, y);
},
// Should correspond to view from below.
// https://in-the-sky.org//satmap_radar.php?year=2023&month=10&day=24&skin=1
drawSats: function(sats) {
g.reset()
.setColor(1, 1, 1)
.fillRect(0, ui.wi, ui.w, ui.y2)
.setFont("Vector", 20)
.setFontAlign(0, 0);
this.drawGrid();
sats.forEach(s => this.drawSat(s));
if (fix && fix.fix && fix.lat) {
g.setColor(0, 0, 0)
.setFontAlign(-1, 1);
g.drawString(fix.satellites + "/" + fix.hdop, 5, ui.y2);
}
},
parseRaw: function(msg, lost) {
if (ui.display != 0)
return;
if (lost) print("## data lost");
let s = msg.split(",");
if (s[0] !== "$GPGSV") return;
if (s[2] === "1") {
this.snum = 0;
this.sats = [];
this.sats_used = 0;
}
let view = 1 * s[3];
let k = Math.min(4, view - this.snum);
for (let i = 4, j = 0; j < k; j++) {
let sat = { id: s[i++], ele: 1 * s[i++], azi: 1 * s[i++], snr: s[i++] };
if (sat.snr !== "") this.sats_used++;
this.sats[this.snum++] = sat;
}
if (s[1] === s[2]) sky.drawSats(this.sats);
}
};
function markGps() {
gps.start_gps();
Bangle.on('GPS-raw', sky.parseRaw);
gps_display.updateGps();
}
ui.init();
ui.numScreens = 3;
gps.init(); gps.init();
gps_quality.resetAlt();
fmt.init(); fmt.init();
Bangle.on("drag", touchHandler); ui.topLeft = () => { ui.drawMsg("Clock\nadjust"); adj_time = 1; };
ui.topRight = () => { ui.drawMsg("Alt\nadjust"); adj_alt = 1; };
Bangle.on("drag", (b) => ui.touchHandler(b));
Bangle.setUI({ Bangle.setUI({
mode : "custom", mode : "custom",
swipe : onSwipe,
clock : 0 clock : 0
}); });
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
drawBusy();
markGps(); markGps();

View File

@ -4,3 +4,4 @@
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 0.05: Implement navigation to waypoint
0.06: Cleanups, minor tweaks

View File

@ -1,6 +1,6 @@
{ "id": "waypoints", { "id": "waypoints",
"name": "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", "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",

View File

@ -305,9 +305,8 @@ var wp = require('Storage').readJSON("waypoints.json", true) || [];
// Use this with corrupted waypoints // Use this with corrupted waypoints
//var wp = []; //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, shared between updateGps / updateGoto functions and confirmGps */
var cancel_gps; var cancel_gps; /* Shared between updateGps / updateGoto functions */
var gps_start;
function writeWP() { function writeWP() {
require('Storage').writeJSON("waypoints.json", wp); require('Storage').writeJSON("waypoints.json", wp);
@ -316,7 +315,7 @@ function writeWP() {
function mainMenu() { function mainMenu() {
let textInputInstalled = true; let textInputInstalled = true;
try { try {
require("textinput") require("textinput");
} catch(err) { } catch(err) {
textInputInstalled = false; textInputInstalled = false;
} }
@ -348,7 +347,7 @@ function updateGps() {
// hdop = "" + fix.hdop.toFixed(0); // hdop = "" + fix.hdop.toFixed(0);
} else { } else {
lat = "NO FIX\n" lat = "NO FIX\n"
+ "" + (getTime() - gps_start).toFixed(0) + "s "; + "" + (getTime() - gps.gps_start).toFixed(0) + "s ";
} }
let msg = ""; let msg = "";
@ -376,7 +375,7 @@ function updateGoto() {
have = true; have = true;
} else { } else {
lat = "NO FIX\n" lat = "NO FIX\n"
+ "" + (getTime() - gps_start).toFixed(0) + "s "; + "" + (getTime() - gps.gps_start).toFixed(0) + "s ";
} }
let msg = arrow.name + "\n"; let msg = arrow.name + "\n";
@ -394,8 +393,8 @@ function updateGoto() {
} }
function stopGps() { function stopGps() {
cancel_gps=true; cancel_gps = true;
Bangle.setGPSPower(0, "waypoints"); gps.stop_gps();
} }
function confirmGps(s) { function confirmGps(s) {
@ -419,8 +418,7 @@ function confirmGps(s) {
function markGps() { function markGps() {
cancel_gps = false; cancel_gps = false;
Bangle.setGPSPower(1, "waypoints"); gps.start_gps();
gps_start = getTime();
require("textinput").input({text:"wp"}).then(key => { require("textinput").input({text:"wp"}).then(key => {
confirmGps(key); confirmGps(key);
}); });
@ -496,9 +494,7 @@ function showNumpad(text, key_, callback) {
function goTo() { function goTo() {
cancel_gps = false; cancel_gps = false;
Bangle.setGPSPower(1, "waypoints"); gps.start_gps();
gps.gps_start = getTime();
gps_start = getTime();
var la = new Layout ( var la = new Layout (
{type:"v", c: [ {type:"v", c: [
@ -515,8 +511,8 @@ function goTo() {
updateGoto(); updateGoto();
} }
function show(pin) { function show(card) {
var i = wp[pin]; var i = wp[card];
var l = fmt.fmtPos(i); var l = fmt.fmtPos(i);
arrow.name = i.name; arrow.name = i.name;
arrow.waypoint = i; arrow.waypoint = i;
@ -540,32 +536,28 @@ function showCard() {
"" : {title : "Select WP"}, "" : {title : "Select WP"},
"< Back" : mainMenu "< Back" : mainMenu
}; };
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""}); if (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 = val.name;
menu[name]= () => show(card); menu[name]= () => show(card);
}); });
} }
E.showMenu(menu); E.showMenu(menu);
} }
function remove(pin) function remove(c) {
{ let card = wp[c];
let card = wp[pin];
let name = card["name"]; let name = 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(c, 1);
writeWP(); writeWP();
mainMenu();
} else {
mainMenu();
} }
mainMenu();
}); });
} }
@ -574,10 +566,10 @@ function removeCard() {
"" : {title : "Select WP"}, "" : {title : "Select WP"},
"< Back" : mainMenu "< Back" : mainMenu
}; };
if (Object.keys(wp).length==0) Object.assign(menu, {"No WPs":""}); if (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 = val.name;
menu[name]=()=> remove(card); menu[name]=()=> remove(card);
}); });
} }
@ -595,10 +587,7 @@ function ask01(t, cb) {
la.render(); la.render();
} }
var res;
function askCoordinate(t1, t2, callback) { function askCoordinate(t1, t2, callback) {
//let sign = 1;
ask01(t1, function(sign) { ask01(t1, function(sign) {
let d, m, s; let d, m, s;
switch (fmt.geo_mode) { switch (fmt.geo_mode) {
@ -607,6 +596,7 @@ function askCoordinate(t1, t2, callback) {
case 2: s = "DDD MM'ss"+'"'; break; case 2: s = "DDD MM'ss"+'"'; break;
} }
showNumpad(s, t2, function() { showNumpad(s, t2, function() {
let res = 0;
switch (fmt.geo_mode) { switch (fmt.geo_mode) {
case 0: case 0:
res = parseFloat(key); res = parseFloat(key);
@ -649,20 +639,18 @@ function createWP(lat, lon, alt, name) {
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, -9999, result); createWP(lat, lon, -9999, name);
mainMenu(); mainMenu();
}); });
} }
function addCard() { function addCard() {
require("textinput").input({text:"wp"}).then(key => { require("textinput").input({text:"wp"}).then(key => {
result = key; let result = key;
if (wp[result]!=undefined) { if (wp[result]!=undefined) {
E.showMenu(); E.showMenu();
var alreadyExists = new Layout ( var alreadyExists = new Layout (

View File

@ -10,18 +10,22 @@ apploader.init({
DEVICEID : "BANGLEJS2" DEVICEID : "BANGLEJS2"
});*/ });*/
var jsparse = (() => {
var acorn;
try {
acorn = require("acorn");
} catch (e) {
console.log("=====================================================");
console.log(" ACORN NOT FOUND");
console.log(" ---------------");
console.log("");
console.log(" This means we won't sanity-check uploaded JSON");
console.log("=====================================================");
return str => {throw new Error("no acorn")};
}
var acorn; return str => acorn.parse(str, { ecmaVersion: 2020 });
try { })();
acorn = require("acorn");
} catch (e) {
console.log("=====================================================");
console.log(" ACORN NOT FOUND");
console.log(" ---------------");
console.log("");
console.log(" This means we won't sanity-check uploaded JSON");
console.log("=====================================================");
}
var BASEDIR = __dirname+"/../"; var BASEDIR = __dirname+"/../";
var APPSDIR_RELATIVE = "apps/"; var APPSDIR_RELATIVE = "apps/";
@ -399,7 +403,7 @@ apps.forEach((app,appIdx) => {
if (file.supports && !Array.isArray(file.supports)) ERROR(`App ${app.id} file ${file.name} supports field is not an array`, {file:metadataFile}); if (file.supports && !Array.isArray(file.supports)) ERROR(`App ${app.id} file ${file.name} supports field is not an array`, {file:metadataFile});
if (file.evaluate) { if (file.evaluate) {
try { try {
acorn.parse("("+fileContents+")"); jsparse("("+fileContents+")");
} catch(e) { } catch(e) {
console.log("====================================================="); console.log("=====================================================");
console.log(" PARSE OF "+appDir+file.url+" failed."); console.log(" PARSE OF "+appDir+file.url+" failed.");
@ -415,7 +419,7 @@ apps.forEach((app,appIdx) => {
// TODO: actual lint? // TODO: actual lint?
var ast; var ast;
try { try {
ast = acorn.parse(fileContents); ast = jsparse(fileContents);
} catch(e) { } catch(e) {
console.log("====================================================="); console.log("=====================================================");
console.log(" PARSE OF "+appDir+file.url+" failed."); console.log(" PARSE OF "+appDir+file.url+" failed.");

35
package-lock.json generated
View File

@ -9,7 +9,7 @@
"version": "0.0.1", "version": "0.0.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"acorn": "^7.2.0" "acorn": "^8.0.0"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.8.0", "@typescript-eslint/eslint-plugin": "^7.8.0",
@ -444,9 +444,10 @@
"dev": true "dev": true
}, },
"node_modules/acorn": { "node_modules/acorn": {
"version": "7.4.1", "version": "8.14.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==",
"license": "MIT",
"bin": { "bin": {
"acorn": "bin/acorn" "acorn": "bin/acorn"
}, },
@ -1309,18 +1310,6 @@
"url": "https://opencollective.com/eslint" "url": "https://opencollective.com/eslint"
} }
}, },
"node_modules/espree/node_modules/acorn": {
"version": "8.11.3",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
"dev": true,
"bin": {
"acorn": "bin/acorn"
},
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/esquery": { "node_modules/esquery": {
"version": "1.5.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz",
@ -3777,9 +3766,9 @@
"dev": true "dev": true
}, },
"acorn": { "acorn": {
"version": "7.4.1", "version": "8.14.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==" "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="
}, },
"acorn-jsx": { "acorn-jsx": {
"version": "5.3.2", "version": "5.3.2",
@ -4424,14 +4413,6 @@
"acorn": "^8.9.0", "acorn": "^8.9.0",
"acorn-jsx": "^5.3.2", "acorn-jsx": "^5.3.2",
"eslint-visitor-keys": "^3.4.1" "eslint-visitor-keys": "^3.4.1"
},
"dependencies": {
"acorn": {
"version": "8.11.3",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
"dev": true
}
} }
}, },
"esquery": { "esquery": {

View File

@ -27,6 +27,6 @@
"update-local-apps": "apps/*/metadata.json" "update-local-apps": "apps/*/metadata.json"
}, },
"dependencies": { "dependencies": {
"acorn": "^7.2.0" "acorn": "^8.0.0"
} }
} }