Subversion Repositories NaviCtrl

Rev

Rev 171 | Rev 225 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 171 Rev 224
Line 59... Line 59...
59
#include "91x_lib.h"
59
#include "91x_lib.h"
60
#include "waypoints.h"
60
#include "waypoints.h"
61
#include "uart1.h"
61
#include "uart1.h"
Line 62... Line 62...
62
 
62
 
63
// the waypoints list
63
// the waypoints list
-
 
64
#define WPLISTLEN 21
64
#define WPLISTLEN 20
65
#define MAXWPNUMBER (WPLISTLEN-1)
65
Waypoint_t WPList[WPLISTLEN];
66
Waypoint_t WPList[WPLISTLEN];
66
u8 WPIndex = 0;
67
u8 WPIndex = 0;
Line 73... Line 74...
73
}
74
}
Line 74... Line 75...
74
 
75
 
75
u8 WPList_Clear(void)
76
u8 WPList_Clear(void)
76
{
77
{
77
        u8 i;
78
        u8 i;
78
        WPIndex = 0;
79
        WPIndex = 0; // invalid index
79
        WPNumber = 0;
80
        WPNumber = 0; // no contents
80
        NaviData.WaypointNumber = WPNumber;
81
        NaviData.WaypointNumber = WPNumber;
Line 81... Line 82...
81
        NaviData.WaypointIndex = WPIndex;
82
        NaviData.WaypointIndex = WPIndex;
82
 
83
 
83
        for(i = 0; i < WPLISTLEN; i++)
84
        for(i = 1; i < WPLISTLEN; i++)
84
        {
85
        {
85
                WPList[i].Position.Status = INVALID;
86
                WPList[i].Position.Status = INVALID;
86
                WPList[i].Position.Latitude = 0;
87
                WPList[i].Position.Latitude = 0;
Line 99... Line 100...
99
        return WPNumber;
100
        return WPNumber;
100
}
101
}
Line 101... Line 102...
101
 
102
 
102
u8 WPList_Append(Waypoint_t* pwp)
103
u8 WPList_Append(Waypoint_t* pwp)
103
{
104
{
104
        if(WPNumber < WPLISTLEN) // id there is still some space in the list
105
        if(WPNumber < MAXWPNUMBER) // there is still some space in the list
-
 
106
        {
105
        {
107
                WPNumber++;
106
                memcpy(&WPList[WPNumber], pwp, sizeof(Waypoint_t)); // copy wp data to list entry
108
                memcpy(&WPList[WPNumber], pwp, sizeof(Waypoint_t)); // copy wp data to list entry
107
                WPList[WPNumber].Position.Status = NEWDATA;             // mark as new data
-
 
108
                WPNumber++;                                                                             // increment list length
109
                WPList[WPNumber].Position.Status = NEWDATA;             // mark as new data                                                                             // increment list length
109
                NaviData.WaypointNumber = WPNumber;
110
                NaviData.WaypointNumber = WPNumber;
110
                return TRUE;
111
                return TRUE;
111
        }
112
        }
112
        else return FALSE;
113
        else return FALSE;
Line 113... Line 114...
113
}
114
}
114
 
115
 
115
// rewind to the begin of the list, and returns the first waypoint
116
// rewind to the begin of the list, and returns the first waypoint
116
Waypoint_t* WPList_Begin(void)
-
 
117
{
-
 
118
        WPIndex = 0; // reset list index
117
Waypoint_t* WPList_Begin(void)
119
        NaviData.WaypointIndex = WPIndex + 1;
118
{
-
 
119
        if(WPNumber > 0)
120
        if(WPNumber > 0)
120
        {
121
        {
121
                WPIndex = 1; // reset list index
122
                NaviData.WaypointIndex = WPIndex + 1;  
122
                NaviData.WaypointIndex = WPIndex;      
123
                return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list
123
                return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list
124
        }
124
        }
-
 
125
        else
125
        else
126
        {
126
        {
127
                WPIndex = 0; // invalid index
127
                NaviData.WaypointIndex = 0;
128
                NaviData.WaypointIndex = 0;
Line 128... Line 129...
128
                return NULL; // else return NULL
129
                return NULL; // else return NULL
Line 133... Line 134...
133
// jump to the end of the list, and returns the last waypoint
134
// jump to the end of the list, and returns the last waypoint
134
Waypoint_t* WPList_End(void)
135
Waypoint_t* WPList_End(void)
135
{
136
{
136
        if(WPNumber > 0)
137
        if(WPNumber > 0)
137
        {
138
        {
138
                NaviData.WaypointIndex = WPNumber;
139
                WPIndex = WPNumber;
139
                WPIndex = WPNumber - 1;
140
                NaviData.WaypointIndex = WPIndex;
140
                return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list
141
                return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list
141
        }
142
        }
142
        else
143
        else
143
        {
144
        {
-
 
145
                WPIndex = 0;
-
 
146
                NaviData.WaypointIndex = WPIndex;
144
                return NULL; // else return NULL
147
                return NULL; // else return NULL
145
        }
148
        }
Line 146... Line 149...
146
 
149
 
Line 147... Line 150...
147
}
150
}
148
 
151
 
149
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
152
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
150
Waypoint_t* WPList_Next(void)
153
Waypoint_t* WPList_Next(void)
151
{
154
{
152
        if((WPIndex + 1) < WPNumber) // if the next WPIndex exist
155
        if(WPIndex < WPNumber) // if the next WPIndex exist
153
        {
156
        {
154
                WPIndex++; // goto next
157
                WPIndex++; // goto next
155
                NaviData.WaypointIndex = WPIndex + 1;
158
                NaviData.WaypointIndex = WPIndex;
156
                return(&(WPList[WPIndex]));     // return pointer to this waypoint
159
                return(&(WPList[WPIndex]));     // return pointer to this waypoint
157
        }
160
        }
Line 158... Line 161...
158
        else return(NULL);
161
        else return(NULL);
159
}      
162
}      
160
 
163
 
161
Waypoint_t* WPList_GetAt(u8 index)
164
Waypoint_t* WPList_GetAt(u8 index)
162
{
165
{
-
 
166
        if(index <= WPNumber) return(&(WPList[index])); // return pointer to this waypoint
-
 
167
        else return(NULL);
-
 
168
}
-
 
169
 
-
 
170
Waypoint_t* WPList_GetPOI(void)
-
 
171
{
-
 
172
        if(WPList[0].Position.Status == INVALID) return(NULL);
-
 
173
        else return(&(WPList[0]));
-
 
174
}
-
 
175
 
-
 
176
void WPList_SetPOI(Waypoint_t* pwp)