gpstrek - Automatically search for new waypoint

master
Martin Boonk 2023-05-12 10:13:01 +02:00
parent c1f2ca5b78
commit aa9672c29b
1 changed files with 21 additions and 9 deletions

View File

@ -419,7 +419,7 @@ let parseRouteData = function(filename, progressMonitor){
routeInfo.up = 0; routeInfo.up = 0;
routeInfo.down = 0; routeInfo.down = 0;
let size = getApproxFileSize(filename); let size = getApproxFileSize(filename);
while ((scanOffset = getEntry(filename, scanOffset, waypoint)) > 0) { while ((scanOffset = getEntry(filename, scanOffset, waypoint)) > 0) {
@ -526,7 +526,7 @@ let showRouteSelector = function(){
}; };
STORAGE.list(/\.trf$/).forEach((file)=>{ STORAGE.list(/\.trf$/).forEach((file)=>{
menu[file] = ()=>{handleLoading(file);}; menu[file] = ()=>{handleLoading(file);};
}); });
E.showMenu(menu); E.showMenu(menu);
@ -740,15 +740,15 @@ const compassSliceData = {
}, },
getPoints: function (){ getPoints: function (){
let points = []; let points = [];
if (WIDGETS.gpstrek.getState().currentPos && WIDGETS.gpstrek.getState().currentPos.lon && WIDGETS.gpstrek.getState().route && WIDGETS.gpstrek.getState().route.currentWaypoint){
points.push({bearing:bearing(WIDGETS.gpstrek.getState().currentPos, WIDGETS.gpstrek.getState().route.currentWaypoint), color:"#0f0"});
}
if (WIDGETS.gpstrek.getState().currentPos && WIDGETS.gpstrek.getState().currentPos.lon && WIDGETS.gpstrek.getState().route){ if (WIDGETS.gpstrek.getState().currentPos && WIDGETS.gpstrek.getState().currentPos.lon && WIDGETS.gpstrek.getState().route){
points.push({bearing:bearing(WIDGETS.gpstrek.getState().currentPos, getLast(WIDGETS.gpstrek.getState().route)), icon: finishIcon}); points.push({bearing:bearing(WIDGETS.gpstrek.getState().currentPos, getLast(WIDGETS.gpstrek.getState().route)), icon: finishIcon});
} }
if (WIDGETS.gpstrek.getState().currentPos && WIDGETS.gpstrek.getState().currentPos.lon && WIDGETS.gpstrek.getState().waypoint){ if (WIDGETS.gpstrek.getState().currentPos && WIDGETS.gpstrek.getState().currentPos.lon && WIDGETS.gpstrek.getState().waypoint){
points.push({bearing:bearing(WIDGETS.gpstrek.getState().currentPos, WIDGETS.gpstrek.getState().waypoint), icon: finishIcon}); points.push({bearing:bearing(WIDGETS.gpstrek.getState().currentPos, WIDGETS.gpstrek.getState().waypoint), icon: finishIcon});
} }
if (WIDGETS.gpstrek.getState().currentPos && WIDGETS.gpstrek.getState().currentPos.lon && WIDGETS.gpstrek.getState().route && WIDGETS.gpstrek.getState().route.currentWaypoint){
points.push({bearing:bearing(WIDGETS.gpstrek.getState().currentPos, WIDGETS.gpstrek.getState().route.currentWaypoint), color:"#0f0"});
}
return points; return points;
}, },
getMarkers: function (){ getMarkers: function (){
@ -758,14 +758,26 @@ const compassSliceData = {
const waypointData = { const waypointData = {
icon: atob("EBCBAAAAAAAAAAAAcIB+zg/uAe4AwACAAAAAAAAAAAAAAAAA"), icon: atob("EBCBAAAAAAAAAAAAcIB+zg/uAe4AwACAAAAAAAAAAAAAAAAA"),
minimumDistance: Number.MAX_VALUE,
getProgress: function() { getProgress: function() {
return (WIDGETS.gpstrek.getState().route.index + 1) + "/" + WIDGETS.gpstrek.getState().route.count; return (WIDGETS.gpstrek.getState().route.index + 1) + "/" + WIDGETS.gpstrek.getState().route.count;
}, },
getTarget: function (){ getTarget: function (){
if (distance(WIDGETS.gpstrek.getState().currentPos,WIDGETS.gpstrek.getState().route.currentWaypoint) < 30 && hasNext(WIDGETS.gpstrek.getState().route)){ let currentDistanceToTarget = distance(WIDGETS.gpstrek.getState().currentPos,WIDGETS.gpstrek.getState().route.currentWaypoint);
next(WIDGETS.gpstrek.getState().route); if (currentDistanceToTarget < this.minimumDistance){
Bangle.buzz(1000); this.minimumDistance = currentDistanceToTarget;
} }
let nextAvailable = hasNext(WIDGETS.gpstrek.getState().route);
if (currentDistanceToTarget < 30 && nextAvailable){
next(WIDGETS.gpstrek.getState().route);
this.minimumDistance = Number.MAX_VALUE;
} else if (this.minimumDistance < currentDistanceToTarget - 30){
stopDrawing();
setClosestWaypoint(WIDGETS.gpstrek.getState().route, WIDGETS.gpstrek.getState().route.index, showProgress);
Bangle.buzz(1000);
removeMenu();
}
return WIDGETS.gpstrek.getState().route.currentWaypoint; return WIDGETS.gpstrek.getState().route.currentWaypoint;
}, },
getStart: function (){ getStart: function (){
@ -885,7 +897,7 @@ let draw = function(){
ypos += sliceHeight+1; ypos += sliceHeight+1;
g.drawLine(0,ypos-1,g.getWidth(),ypos-1); g.drawLine(0,ypos-1,g.getWidth(),ypos-1);
} }
if (scheduleDraw){ if (scheduleDraw){
drawInTimeout(); drawInTimeout();
} }