61,7 → 61,8 |
#include "uart1.h" |
|
// the waypoints list |
#define WPLISTLEN 20 |
#define WPLISTLEN 21 |
#define MAXWPNUMBER (WPLISTLEN-1) |
Waypoint_t WPList[WPLISTLEN]; |
u8 WPIndex = 0; |
u8 WPNumber = 0; |
75,12 → 76,12 |
u8 WPList_Clear(void) |
{ |
u8 i; |
WPIndex = 0; |
WPNumber = 0; |
WPIndex = 0; // invalid index |
WPNumber = 0; // no contents |
NaviData.WaypointNumber = WPNumber; |
NaviData.WaypointIndex = WPIndex; |
|
for(i = 0; i < WPLISTLEN; i++) |
for(i = 1; i < WPLISTLEN; i++) |
{ |
WPList[i].Position.Status = INVALID; |
WPList[i].Position.Latitude = 0; |
101,11 → 102,11 |
|
u8 WPList_Append(Waypoint_t* pwp) |
{ |
if(WPNumber < WPLISTLEN) // id there is still some space in the list |
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 |
WPNumber++; // increment list length |
WPList[WPNumber].Position.Status = NEWDATA; // mark as new data // increment list length |
NaviData.WaypointNumber = WPNumber; |
return TRUE; |
} |
115,15 → 116,15 |
// rewind to the begin of the list, and returns the first waypoint |
Waypoint_t* WPList_Begin(void) |
{ |
WPIndex = 0; // reset list index |
NaviData.WaypointIndex = WPIndex + 1; |
if(WPNumber > 0) |
{ |
NaviData.WaypointIndex = WPIndex + 1; |
WPIndex = 1; // reset list index |
NaviData.WaypointIndex = WPIndex; |
return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list |
} |
else |
{ |
WPIndex = 0; // invalid index |
NaviData.WaypointIndex = 0; |
return NULL; // else return NULL |
} |
135,12 → 136,14 |
{ |
if(WPNumber > 0) |
{ |
NaviData.WaypointIndex = WPNumber; |
WPIndex = WPNumber - 1; |
WPIndex = WPNumber; |
NaviData.WaypointIndex = WPIndex; |
return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list |
} |
else |
{ |
WPIndex = 0; |
NaviData.WaypointIndex = WPIndex; |
return NULL; // else return NULL |
} |
|
149,10 → 152,10 |
// 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 + 1) < WPNumber) // if the next WPIndex exist |
if(WPIndex < WPNumber) // if the next WPIndex exist |
{ |
WPIndex++; // goto next |
NaviData.WaypointIndex = WPIndex + 1; |
NaviData.WaypointIndex = WPIndex; |
return(&(WPList[WPIndex])); // return pointer to this waypoint |
} |
else return(NULL); |
160,6 → 163,17 |
|
Waypoint_t* WPList_GetAt(u8 index) |
{ |
if(index < WPNumber) return(&(WPList[index])); // return pointer to this waypoint |
if(index <= WPNumber) return(&(WPList[index])); // 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])); |
} |
|
void WPList_SetPOI(Waypoint_t* pwp) |
{ |
memcpy(&WPList[0], pwp, sizeof(Waypoint_t)); // copy wp data to list entry |
} |