v009
parent
1bce4cf8e0
commit
b1e3db6d81
|
|
@ -23,3 +23,4 @@
|
||||||
|
|
||||||
0.09:
|
0.09:
|
||||||
* We now display interest points.
|
* We now display interest points.
|
||||||
|
* Menu to choose which file to load.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
- it is becoming messy
|
||||||
- split on points with comments
|
- split on points with comments
|
||||||
|
|
||||||
- turn off gps when moving to next waypoint
|
- turn off gps when moving to next waypoint
|
||||||
|
|
@ -8,7 +9,6 @@
|
||||||
- buzzing does not work nicely
|
- buzzing does not work nicely
|
||||||
-> is_lost seems fishy
|
-> is_lost seems fishy
|
||||||
|
|
||||||
- store several tracks
|
|
||||||
- display average speed
|
- display average speed
|
||||||
- dynamic map rescale
|
- dynamic map rescale
|
||||||
- display scale (100m)
|
- display scale (100m)
|
||||||
|
|
|
||||||
119
apps/gipy/app.js
119
apps/gipy/app.js
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
let simulated = true;
|
let simulated = false;
|
||||||
let file_version = 2;
|
let file_version = 2;
|
||||||
let code_key = 47490;
|
let code_key = 47490;
|
||||||
|
|
||||||
|
|
@ -64,11 +64,11 @@ class Status {
|
||||||
this.position = new_position;
|
this.position = new_position;
|
||||||
|
|
||||||
// detect segment we are on now
|
// detect segment we are on now
|
||||||
let next_segment = this.path.nearest_segment(this.position, Math.max(0, this.current_segment-1), Math.min(this.current_segment+2, path.len - 1), this.cos_direction, this.sin_direction);
|
let next_segment = this.path.nearest_segment(this.position, Math.max(0, this.current_segment-1), Math.min(this.current_segment+2, this.path.len - 1), this.cos_direction, this.sin_direction);
|
||||||
|
|
||||||
if (this.is_lost(next_segment)) {
|
if (this.is_lost(next_segment)) {
|
||||||
// it did not work, try anywhere
|
// it did not work, try anywhere
|
||||||
next_segment = this.path.nearest_segment(this.position, 0, path.len - 1, this.cos_direction, this.sin_direction);
|
next_segment = this.path.nearest_segment(this.position, 0, this.path.len - 1, this.cos_direction, this.sin_direction);
|
||||||
}
|
}
|
||||||
// now check if we strayed away from path or back to it
|
// now check if we strayed away from path or back to it
|
||||||
let lost = this.is_lost(next_segment);
|
let lost = this.is_lost(next_segment);
|
||||||
|
|
@ -123,7 +123,8 @@ class Status {
|
||||||
let starting_bucket = binary_search(this.path.interests_starts, starting_group);
|
let starting_bucket = binary_search(this.path.interests_starts, starting_group);
|
||||||
let ending_bucket = binary_search(this.path.interests_starts, ending_group+0.5);
|
let ending_bucket = binary_search(this.path.interests_starts, ending_group+0.5);
|
||||||
// we have 5 points per bucket
|
// we have 5 points per bucket
|
||||||
for (let i = starting_bucket*5 ; i <= ending_bucket*5 ; i++) {
|
let end_index = Math.min(this.path.interests_types.length - 1, ending_bucket*5);
|
||||||
|
for (let i = starting_bucket*5 ; i <= end_index ; i++) {
|
||||||
let index = this.path.interests_on_path[i];
|
let index = this.path.interests_on_path[i];
|
||||||
let interest_point = this.path.interest_point(index);
|
let interest_point = this.path.interest_point(index);
|
||||||
let color = this.path.interest_color(i);
|
let color = this.path.interest_color(i);
|
||||||
|
|
@ -142,7 +143,7 @@ class Status {
|
||||||
let hours = now.getHours().toString();
|
let hours = now.getHours().toString();
|
||||||
g.setFont("6x8:2").setColor(g.theme.fg).drawString(hours + ":" + minutes, 0, g.getHeight() - 49);
|
g.setFont("6x8:2").setColor(g.theme.fg).drawString(hours + ":" + minutes, 0, g.getHeight() - 49);
|
||||||
g.drawString("d. " + rounded_distance + "/" + total, 0, g.getHeight() - 32);
|
g.drawString("d. " + rounded_distance + "/" + total, 0, g.getHeight() - 32);
|
||||||
g.drawString("seg." + (this.current_segment + 1) + "/" + path.len + " " + this.distance_to_next_point + "m", 0, g.getHeight() - 15);
|
g.drawString("seg." + (this.current_segment + 1) + "/" + this.path.len + " " + this.distance_to_next_point + "m", 0, g.getHeight() - 15);
|
||||||
}
|
}
|
||||||
display_map() {
|
display_map() {
|
||||||
// don't display all segments, only those neighbouring current segment
|
// don't display all segments, only those neighbouring current segment
|
||||||
|
|
@ -376,12 +377,64 @@ class Point {
|
||||||
|
|
||||||
|
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
let path = new Path("test.gpc");
|
|
||||||
let status = new Status(path);
|
|
||||||
|
|
||||||
let frame = 0;
|
|
||||||
let old_points = []; // remember the at most 3 previous points
|
let fake_gps_point = 0.0;
|
||||||
function set_coordinates(data) {
|
function simulate_gps(status) {
|
||||||
|
if (fake_gps_point > status.path.len -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let point_index = Math.floor(fake_gps_point);
|
||||||
|
if (point_index >= status.path.len) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let p1 = status.path.point(point_index);
|
||||||
|
let p2 = status.path.point(point_index + 1);
|
||||||
|
|
||||||
|
let alpha = fake_gps_point - point_index;
|
||||||
|
let pos = p1.times(1-alpha).plus(p2.times(alpha));
|
||||||
|
let old_pos = status.position;
|
||||||
|
|
||||||
|
fake_gps_point += 0.2; // advance simulation
|
||||||
|
let direction = Math.atan2(pos.lat - old_pos.lat, pos.lon - old_pos.lon);
|
||||||
|
status.update_position(pos, direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawMenu() {
|
||||||
|
const menu = {
|
||||||
|
'': { 'title': 'choose trace' }
|
||||||
|
};
|
||||||
|
var files = require("Storage").list(".gpc");
|
||||||
|
for (var i=0; i<files.length; ++i) {
|
||||||
|
menu[files[i]] = start.bind(null, files[i]);
|
||||||
|
}
|
||||||
|
menu['Exit'] = function() { load(); };
|
||||||
|
E.showMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function start(fn) {
|
||||||
|
console.log("loading", fn);
|
||||||
|
|
||||||
|
let path = new Path(fn);
|
||||||
|
let status = new Status(path);
|
||||||
|
|
||||||
|
if (simulated) {
|
||||||
|
status.position = new Point(status.path.point(0));
|
||||||
|
setInterval(simulate_gps, 500, status);
|
||||||
|
} else {
|
||||||
|
// let's display start while waiting for gps signal
|
||||||
|
let p1 = status.path.point(0);
|
||||||
|
let p2 = status.path.point(1);
|
||||||
|
let diff = p2.minus(p1);
|
||||||
|
let direction = Math.atan2(diff.lat, diff.lon);
|
||||||
|
Bangle.setLocked(false);
|
||||||
|
status.update_position(p1, direction);
|
||||||
|
|
||||||
|
let frame = 0;
|
||||||
|
let old_points = []; // remember the at most 3 previous points
|
||||||
|
let set_coordinates = function(data) {
|
||||||
frame += 1;
|
frame += 1;
|
||||||
let valid_coordinates = !isNaN(data.lat) && !isNaN(data.lon);
|
let valid_coordinates = !isNaN(data.lat) && !isNaN(data.lon);
|
||||||
if (valid_coordinates) {
|
if (valid_coordinates) {
|
||||||
|
|
@ -422,45 +475,21 @@ function set_coordinates(data) {
|
||||||
gps_status_color = g.theme.fg;
|
gps_status_color = g.theme.fg;
|
||||||
}
|
}
|
||||||
g.setColor(gps_status_color).setFont("6x8:2").drawString("gps", g.getWidth() - 40, 30);
|
g.setColor(gps_status_color).setFont("6x8:2").drawString("gps", g.getWidth() - 40, 30);
|
||||||
}
|
|
||||||
|
|
||||||
let fake_gps_point = 0.0;
|
|
||||||
function simulate_gps(status) {
|
|
||||||
if (fake_gps_point > status.path.len -1) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
let point_index = Math.floor(fake_gps_point);
|
|
||||||
if (point_index >= path.len) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let p1 = path.point(point_index);
|
|
||||||
let p2 = path.point(point_index + 1);
|
|
||||||
|
|
||||||
let alpha = fake_gps_point - point_index;
|
|
||||||
let pos = p1.times(1-alpha).plus(p2.times(alpha));
|
|
||||||
let old_pos = status.position;
|
|
||||||
|
|
||||||
fake_gps_point += 0.2; // advance simulation
|
|
||||||
let direction = Math.atan2(pos.lat - old_pos.lat, pos.lon - old_pos.lon);
|
|
||||||
status.update_position(pos, direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (simulated) {
|
|
||||||
status.position = new Point(status.path.point(0));
|
|
||||||
setInterval(simulate_gps, 500, status);
|
|
||||||
} else {
|
|
||||||
// let's display start while waiting for gps signal
|
|
||||||
let p1 = status.path.point(0);
|
|
||||||
let p2 = status.path.point(1);
|
|
||||||
let diff = p2.minus(p1);
|
|
||||||
let direction = Math.atan2(diff.lat, diff.lon);
|
|
||||||
Bangle.setLocked(false);
|
|
||||||
status.update_position(p1, direction);
|
|
||||||
|
|
||||||
Bangle.setGPSPower(true, "gipy");
|
Bangle.setGPSPower(true, "gipy");
|
||||||
Bangle.on('GPS', set_coordinates);
|
Bangle.on('GPS', set_coordinates);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let files = require("Storage").list(".gpc");
|
||||||
|
if (files.length <= 1) {
|
||||||
|
if (files.length == 0) {
|
||||||
|
load();
|
||||||
|
} else {
|
||||||
|
start(files[0]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
drawMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -379,7 +379,6 @@ fn save_gpc<P: AsRef<Path>>(path: P, points: &[Point], buckets: &[Bucket]) -> st
|
||||||
.try_for_each(|i| writer.write_all(&i.to_le_bytes()))?;
|
.try_for_each(|i| writer.write_all(&i.to_le_bytes()))?;
|
||||||
|
|
||||||
let starts: Vec<_> = buckets.iter().map(|b| b.start).collect();
|
let starts: Vec<_> = buckets.iter().map(|b| b.start).collect();
|
||||||
eprintln!("starts {:?} of length {}", starts, starts.len());
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -592,13 +591,6 @@ fn position_interests_along_path(
|
||||||
.chunks(groups_size)
|
.chunks(groups_size)
|
||||||
.map(|c| c.iter().flatten().unique().copied().collect::<Vec<_>>())
|
.map(|c| c.iter().flatten().unique().copied().collect::<Vec<_>>())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
eprintln!(
|
|
||||||
"group sizes are {:?}",
|
|
||||||
grouped_positions
|
|
||||||
.iter()
|
|
||||||
.map(|g| g.len())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
);
|
|
||||||
// now, group the points in buckets
|
// now, group the points in buckets
|
||||||
let chunks = grouped_positions
|
let chunks = grouped_positions
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue