104,11 → 104,30 |
|
u8 WPList_Append(Waypoint_t* pwp) |
{ |
if(WPNumber < WPLISTLEN) // there is still some space in the list |
if((WPNumber < WPLISTLEN) && (pwp->Index == (WPNumber + 1)) ) // there is still some space in the list and index points to next |
{ |
memcpy(&WPList[WPNumber], pwp, sizeof(Waypoint_t)); // copy wp data to list entry // increment list length |
WPNumber++; |
NaviData.WaypointNumber = WPNumber; |
if(WPNumber == 1) // only for the first entry |
{ |
// update POI index |
switch(WPList[WPIndex-1].Type) |
{ |
case POINT_TYPE_WP: |
if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
else POIIndex = 0; |
break; |
|
case POINT_TYPE_POI: |
POIIndex = 1; |
break; |
|
default: |
POIIndex = 0; |
break; |
} |
} |
return TRUE; |
} |
else return FALSE; |
117,11 → 136,13 |
// returns the pointer to the first waypoint within the list |
Waypoint_t* WPList_Begin(void) |
{ |
u8 i; |
WPIndex = 0; // set list position invalid |
|
POIIndex = 0; // set invalid POI |
|
if(WPNumber > 0) |
{ |
u8 i; |
|
// search for first wp in list |
for(i = 0; i < WPNumber; i++) |
{ |
131,31 → 152,48 |
break; |
} |
} |
if(WPIndex) // found a WP in the list |
{ |
NaviData.WaypointIndex = WPIndex; |
// update index to POI |
if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
else POIIndex = 0; |
return(&(WPList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list |
} |
else // some points in the list but no WP found |
{ |
NaviData.WaypointIndex = WPIndex; |
//Check for an existing POI |
for(i = 0; i < WPNumber; i++) |
{ |
if((WPList[i].Type == POINT_TYPE_POI) && (WPList[i].Position.Status != INVALID)) |
{ |
POIIndex = i + 1; |
break; |
} |
} |
return NULL; |
} |
} |
if(WPIndex) // found a WP in the list |
else // no point in the list |
{ |
POIIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
// update index to POI |
if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
else POIIndex = 0; |
return(&(WPList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list |
return NULL; |
} |
else |
{ |
POIIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
return NULL; |
} |
} |
|
// returns the last waypoint |
Waypoint_t* WPList_End(void) |
{ |
|
u8 i; |
WPIndex = 0; // set list position invalid |
POIIndex = 0; // set invalid |
|
if(WPNumber > 0) |
{ |
// search backward! |
u8 i; |
for(i = 1; i <= WPNumber; i++) |
{ |
if((WPList[WPNumber - i].Type == POINT_TYPE_WP) && (WPList[WPNumber - i].Position.Status != INVALID)) |
164,20 → 202,34 |
break; |
} |
} |
if(WPIndex) // found a WP within the list |
{ |
NaviData.WaypointIndex = WPIndex; |
if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
else POIIndex = 0; |
return(&(WPList[WPIndex-1])); |
} |
else // list conbtains some points but no WP in the list |
{ |
// search backward for a POI! |
for(i = 1; i <= WPNumber; i++) |
{ |
if((WPList[WPNumber - i].Type == POINT_TYPE_POI) && (WPList[WPNumber - i].Position.Status != INVALID)) |
{ |
POIIndex = WPNumber - i + 1; |
break; |
} |
} |
NaviData.WaypointIndex = WPIndex; |
return NULL; |
} |
} |
if(WPIndex) // found a WP within the list |
else // no point in the list |
{ |
NaviData.WaypointIndex = WPIndex; |
if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
else POIIndex = 0; |
return(&(WPList[WPIndex-1])); |
POIIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
return NULL; |
} |
else |
{ |
POIIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
return NULL; |
} |
} |
|
// returns a pointer to the next waypoint or NULL if the end of the list has been reached |
205,7 → 257,12 |
else POIIndex = 0; |
return(&(WPList[WPIndex-1])); // return pointer to this waypoint |
} |
else return(NULL); |
else |
{ |
NaviData.WaypointIndex = WPIndex; |
POIIndex = 0; |
return(NULL); |
} |
} |
|
Waypoint_t* WPList_GetAt(u8 index) |