64,10 → 64,10 |
#define WPLISTLEN 21 |
#define MAXWPNUMBER (WPLISTLEN-1) |
Waypoint_t WPList[WPLISTLEN]; |
u8 WPIndex = 0; |
u8 WPIndex = 0; // index of GPS point representig the WP |
u8 POIIndex = 0; // index of GPS Point representing the current POI |
u8 WPNumber = 0; |
|
|
u8 WPList_Init(void) |
{ |
return WPList_Clear(); |
76,12 → 76,13 |
u8 WPList_Clear(void) |
{ |
u8 i; |
WPIndex = 0; // invalid index |
WPNumber = 0; // no contents |
WPIndex = 0; // invalid index |
POIIndex = 0; // invalid index |
WPNumber = 0; // no contents |
NaviData.WaypointNumber = WPNumber; |
NaviData.WaypointIndex = WPIndex; |
|
for(i = 1; i < WPLISTLEN; i++) |
for(i = 0; i < WPLISTLEN; i++) |
{ |
WPList[i].Position.Status = INVALID; |
WPList[i].Position.Latitude = 0; |
104,9 → 105,9 |
{ |
if(WPNumber < MAXWPNUMBER) // there is still some space in the list |
{ |
WPNumber++; |
memcpy(&WPList[WPNumber], pwp, sizeof(Waypoint_t)); // copy wp data to list entry |
WPList[WPNumber].Position.Status = NEWDATA; // mark as new data // increment list length |
WPNumber++; |
NaviData.WaypointNumber = WPNumber; |
return TRUE; |
} |
113,50 → 114,111 |
else return FALSE; |
} |
|
// rewind to the begin of the list, and returns the first waypoint |
// returns the first waypoint |
Waypoint_t* WPList_Begin(void) |
{ |
if(WPNumber > 0) |
{ |
WPIndex = 1; // reset list index |
NaviData.WaypointIndex = WPIndex; |
return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list |
u8 i, wp_found = 0; |
// search for first wp in list |
for(i = 0; i < WPNumber; i++) |
{ |
if(WPList[i].Type == POINT_TYPE_WP) |
{ |
wp_found = 1; |
break; |
} |
} |
if(wp_found) // found a WP in the list |
{ |
WPIndex = i+1; |
NaviData.WaypointIndex = WPIndex; |
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 // found no WP within the list |
{ |
WPIndex = 0; |
POIIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
return NULL; |
} |
} |
else |
else // empty list |
{ |
WPIndex = 0; // invalid index |
NaviData.WaypointIndex = 0; |
return NULL; // else return NULL |
POIIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
return NULL; |
} |
|
} |
|
// jump to the end of the list, and returns the last waypoint |
// returns the last waypoint |
Waypoint_t* WPList_End(void) |
{ |
if(WPNumber > 0) |
{ |
WPIndex = WPNumber; |
NaviData.WaypointIndex = WPIndex; |
return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list |
// search backward |
u8 i, wp_found = 0; |
for(i = 1; i <= WPNumber; i++) |
{ |
if(WPList[WPNumber - i].Type == POINT_TYPE_WP) |
{ |
wp_found = 1; |
break; |
} |
} |
if(wp_found) // found a WP within the list |
{ |
WPIndex = WPNumber - i + 1; |
NaviData.WaypointIndex = WPIndex; |
if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
else POIIndex = 0; |
return(&(WPList[WPIndex-1])); |
} |
else |
{ |
WPIndex = 0; |
POIIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
return NULL; |
} |
} |
else |
{ |
WPIndex = 0; |
POIIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
return NULL; // else return NULL |
return NULL; |
} |
|
} |
|
// returns a pointer to the next waypoint or NULL if the end of the list has been reached |
Waypoint_t* WPList_Next(void) |
{ |
if(WPIndex < WPNumber) // if the next WPIndex exist |
if(WPNumber == 0) return NULL; |
if((WPIndex > 0) && (WPIndex < WPNumber)) // if the next WP exist |
{ |
WPIndex++; // goto next |
NaviData.WaypointIndex = WPIndex; |
return(&(WPList[WPIndex])); // return pointer to this waypoint |
u8 i, wp_found = 0; |
for(i = WPIndex; i < WPNumber; i++) |
{ |
if(WPList[i].Type == POINT_TYPE_WP) // jump over POIs |
{ |
wp_found = 1; |
break; |
} |
} |
if(wp_found) |
{ |
WPIndex = i+1; |
NaviData.WaypointIndex = WPIndex; |
if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
else POIIndex = 0; |
return(&(WPList[WPIndex-1])); // return pointer to this waypoint |
} |
else return NULL; |
} |
else return(NULL); |
} |
163,17 → 225,12 |
|
Waypoint_t* WPList_GetAt(u8 index) |
{ |
if(index <= WPNumber) return(&(WPList[index])); // return pointer to this waypoint |
if((index > 0) && (index <= WPNumber)) return(&(WPList[index-1])); // return pointer to this waypoint |
else return(NULL); |
} |
|
Waypoint_t* WPList_GetPOI(void) |
{ |
if(WPList[0].Position.Status == INVALID) return(NULL); |
else return(&(WPList[0])); |
return WPList_GetAt(POIIndex); |
} |
|
void WPList_SetPOI(Waypoint_t* pwp) |
{ |
memcpy(&WPList[0], pwp, sizeof(Waypoint_t)); // copy wp data to list entry |
} |