Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 223 → Rev 224

/trunk/uart1.c
437,24 → 437,32
 
case 'w':// Append Waypoint to List
{
static u8 oldIndex = 0x00;
static u8 nextIndex = 0x00;
 
pWaypoint = (Waypoint_t*)SerialMsg.pData;
if(pWaypoint->Position.Status == INVALID)
{ // clear WP List
WPList_Clear();
oldIndex = 0x00;
 
if (pWaypoint->Index == 0) // is the POI
{
WPList_SetPOI(pWaypoint); //update POI also when invalid
WPList_Clear(); //delete the WP List
GPS_pWaypoint = WPList_Begin();
nextIndex = 0x01;
BeepTime = 300;
UART1_Request_NewWaypoint = TRUE;
// the POI is not a WP therefore the WPNumber is not increased
// and the command returns a 0 as WP number
}
else if (pWaypoint->Position.Status == NEWDATA)
{ // app current WP to the list
if (pWaypoint->Index == oldIndex + 1)
{
WPList_Append(pWaypoint);
BeepTime = 500;
oldIndex = pWaypoint->Index;
UART1_Request_NewWaypoint = TRUE;
else // normal WP
{
if (pWaypoint->Position.Status == NEWDATA)
{ // app current WP to the list
if (pWaypoint->Index == nextIndex)
{
WPList_Append(pWaypoint);
BeepTime = 500;
nextIndex = pWaypoint->Index+1;
UART1_Request_NewWaypoint = TRUE; // return new WP number
}
}
}
}
/trunk/waypoints.c
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
}
/trunk/waypoints.h
22,5 → 22,7
Waypoint_t* WPList_End(void);
Waypoint_t* WPList_Next(void);
Waypoint_t* WPList_GetAt(u8 index);
Waypoint_t* WPList_GetPOI(void);
void WPList_SetPOI(Waypoint_t* pwp);
 
#endif // _WAYPOINTS_H