mirror of https://github.com/espruino/BangleApps
trail: start using zoom library. I guess it is still buggy.
parent
1f567f0bcd
commit
80e519fad9
|
@ -16,3 +16,5 @@ them (actually uses openstreetmap data for most of the world).
|
|||
"gpx2egt.sh < file.gpx > t.name.egt" can be used to prepare data, then
|
||||
upload it to watch.
|
||||
|
||||
# [rt].*.egt
|
||||
# deal with "end of trail"
|
|
@ -279,6 +279,81 @@ let egt = {
|
|||
},
|
||||
};
|
||||
|
||||
/* zoom library v0.0.4 */
|
||||
var zoom = {
|
||||
buf : 0,
|
||||
/* y coordinate is "strange" -- positive values go north */
|
||||
/* x1 -- left, x2 -- right of simulated canvas.
|
||||
we want x1 < x2, y1 < y2. */
|
||||
x1 : 0, x2 : 0, y1 : 0, y2 : 0,
|
||||
/* screen size in pixels */
|
||||
ss : 176,
|
||||
/* size in pixels */
|
||||
init : function(size) {
|
||||
this.size = size;
|
||||
this.buf = Graphics.createArrayBuffer(size, size, 2, { msb: true });
|
||||
},
|
||||
clear : function() {
|
||||
this.buf.reset().clear();
|
||||
},
|
||||
/* output: 0..1 */
|
||||
xrel : function(i) {
|
||||
let r = {};
|
||||
r.x = ((i.x - this.x1) / (this.x2 - this.x1));
|
||||
r.y = ((i.y - this.y1) / (this.y2 - this.y1));
|
||||
return r;
|
||||
},
|
||||
/* input: meters, output: pixels in buf*/
|
||||
xform : function(p) {
|
||||
let r = this.xrel(p);
|
||||
r.x *= this.size;
|
||||
r.y *= -this.size;
|
||||
r.y += this.size;
|
||||
return r;
|
||||
},
|
||||
/* takes x, y with lat/lon m */
|
||||
geoLine : function(i1, i2) {
|
||||
this.drawLine(Bangle.project(i1), Bangle.project(i2));
|
||||
},
|
||||
/* takes x, y in m */
|
||||
drawLine : function(i1, i2) {
|
||||
let p1 = this.xform(i1);
|
||||
let p2 = this.xform(i2);
|
||||
print("line", p1, p2);
|
||||
this.buf.drawLine(p1.x, p1.y, p2.x, p2.y);
|
||||
},
|
||||
geoPaint : function(i, head, z) {
|
||||
this.mPaint(Bangle.project(i), head, z);
|
||||
},
|
||||
/* vx, vy: viewpoint in meters,
|
||||
head: which heading to display as up,
|
||||
zoom: how many meters from center of screen to edge */
|
||||
mPaint : function(v, head, z) {
|
||||
let sh = this.xrel(v);
|
||||
sh.x = sh.x - 0.5;
|
||||
sh.y = 0.5 - sh.y;
|
||||
let scale = ((this.y2-this.y1)/(z*2)) * this.ss/this.size;
|
||||
let dist = Math.sqrt(sh.x*sh.x + sh.y*sh.y) * this.ss * scale;
|
||||
let theta = Math.atan2(-sh.y, sh.x);
|
||||
let rad = (head / 360) * 2 * Math.PI;
|
||||
let ox = Math.sin(theta - rad + 1.5*Math.PI) * dist;
|
||||
let oy = Math.cos(theta - rad + 1.5*Math.PI) * dist;
|
||||
/*
|
||||
print("scale", scale);
|
||||
print("dist", dist);
|
||||
print("o", ox, oy);
|
||||
*/
|
||||
|
||||
/* drawimage... takes middle of the image, and rotates around it.
|
||||
... in pixels
|
||||
scale is pixels to pixels */
|
||||
g.drawImage(zoom.buf, 176/2 + ox, 176/2 + oy,
|
||||
{ rotate: rad,
|
||||
scale: scale });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function toCartesian(v) {
|
||||
const R = 6371; // Poloměr Země v km
|
||||
const latRad = v.lat * Math.PI / 180;
|
||||
|
@ -365,10 +440,13 @@ function toxy(pp, p) {
|
|||
}
|
||||
|
||||
function paint(pp, p1, p2, thick) {
|
||||
if (0) {
|
||||
let d1 = toxy(pp, p1);
|
||||
let d2 = toxy(pp, p2);
|
||||
//print(d1, d2);
|
||||
drawThickLine(pp.g, d1.x, d1.y, d2.x, d2.y, thick);
|
||||
} else
|
||||
zoom.geoLine(p1, p2);
|
||||
}
|
||||
|
||||
var destination = {}, num = 0, dist = 0;
|
||||
|
@ -376,11 +454,11 @@ var destination = {}, num = 0, dist = 0;
|
|||
//{ rotate: Math.PI / 4 + i/100, scale: 1-i/100 }
|
||||
function flip(pp) {
|
||||
// pp.g.flip();
|
||||
g.drawImage(g_over, 0, 0, {});
|
||||
//g.flip();
|
||||
}
|
||||
|
||||
function read(pp, n) {
|
||||
g.reset().clear();
|
||||
zoom.buf.reset().clear();
|
||||
let f = require("Storage").open(n+".st", "r");
|
||||
let l = f.readLine();
|
||||
let prev = 0;
|
||||
|
@ -393,6 +471,12 @@ function read(pp, n) {
|
|||
if (pp.g)
|
||||
paint(pp, prev, p, 1);
|
||||
} else {
|
||||
let i = Bangle.project(p);
|
||||
let is = 1000; /* meters */
|
||||
zoom.x1 = i.x - is;
|
||||
zoom.x2 = i.x + is;
|
||||
zoom.y1 = i.y - is;
|
||||
zoom.y2 = i.y + is;
|
||||
pp.lat = p.lat;
|
||||
pp.lon = p.lon;
|
||||
}
|
||||
|
@ -413,7 +497,7 @@ function read(pp, n) {
|
|||
destination = prev;
|
||||
}
|
||||
|
||||
var g_over = Graphics.createArrayBuffer(176, 176, 2, { msb: true });
|
||||
zoom.init(176);
|
||||
|
||||
function time_read(n) {
|
||||
print("Converting...");
|
||||
|
@ -425,7 +509,7 @@ function time_read(n) {
|
|||
pp.course = 0;
|
||||
pp.x = 176/2;
|
||||
pp.y = 176/2;
|
||||
pp.g = g_over;
|
||||
pp.g = zoom.buf;
|
||||
read(pp, n);
|
||||
// { rotate: Math.PI / 4 + i/100, scale: 1-i/100 }
|
||||
flip(pp);
|
||||
|
@ -434,7 +518,7 @@ function time_read(n) {
|
|||
print("Read took", (v2-v1), "seconds");
|
||||
step_init();
|
||||
print(num, "points", dist, "distance");
|
||||
setTimeout(step, 5000);
|
||||
setTimeout(step, 100);
|
||||
}
|
||||
|
||||
var track_name = "", inf, point_num, track = [], track_points = 30, north = {};
|
||||
|
@ -453,8 +537,7 @@ function load_next() {
|
|||
let l = inf.readLine();
|
||||
if (l === undefined) {
|
||||
print("End of track");
|
||||
ui.drawMsg("End of track");
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
let p = egt.parse(l);
|
||||
if (!p.lat) {
|
||||
|
@ -466,6 +549,7 @@ function load_next() {
|
|||
print("Loading ", p.point_num);
|
||||
track.push(p);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
function paint_all(pp) {
|
||||
|
@ -527,14 +611,16 @@ function step_to(pp, pass_all) {
|
|||
|
||||
let quiet = paint_all(pp);
|
||||
|
||||
if ((pass_all || track[0].passed) && distSegment(track[0], track[1], pp) > 150) {
|
||||
if ((pass_all || track[0].passed)
|
||||
&& distSegment(track[0], track[1], pp) > 150
|
||||
&& track.length > 10) {
|
||||
print("Dropping ", track[0].point_num);
|
||||
track.shift();
|
||||
}
|
||||
return quiet;
|
||||
}
|
||||
|
||||
var demo_mode = 0;
|
||||
var demo_mode = 1; //fixme
|
||||
|
||||
function step() {
|
||||
const fast = 0;
|
||||
|
@ -543,13 +629,13 @@ function step() {
|
|||
|
||||
let fix = gps.getGPSFix();
|
||||
|
||||
load_next();
|
||||
let have_more = load_next();
|
||||
|
||||
let pp = fix;
|
||||
pp.ppm = 0.08 * 3; /* Pixels per meter */
|
||||
pp.g = g;
|
||||
|
||||
if (!fix.fix) {
|
||||
if (demo_mode || !fix.fix) {
|
||||
let i = 2;
|
||||
pp.lat = track[i].lat;
|
||||
pp.lon = track[i].lon;
|
||||
|
@ -557,11 +643,17 @@ function step() {
|
|||
}
|
||||
|
||||
let quiet = step_to(pp, 1);
|
||||
if (1) {
|
||||
zoom.geoPaint(pp, -pp.course, 500);
|
||||
}
|
||||
|
||||
if (!fast) {
|
||||
g.setFont("Vector", 31);
|
||||
g.setFontAlign(-1, -1);
|
||||
let msg = "\noff " + fmt.fmtDist(quiet.offtrack/1000);
|
||||
if (!have_more) {
|
||||
msg += "\nEnd!";
|
||||
}
|
||||
g.drawString(fmt.fmtFix(fix, getTime()-gps.gps_start) + msg, 3, 3);
|
||||
}
|
||||
if (!fast) {
|
||||
|
@ -580,7 +672,7 @@ function step() {
|
|||
track.shift();
|
||||
let v2 = getTime();
|
||||
print("Step took", (v2-v1), "seconds");
|
||||
setTimeout(step, 100);
|
||||
setTimeout(step, 1000);
|
||||
}
|
||||
|
||||
function recover() {
|
||||
|
|
Loading…
Reference in New Issue