Subversion Repositories NaviCtrl

Rev

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

Rev 230 Rev 277
Line 102... Line 102...
102
        return WPNumber; // number of points in the list
102
        return WPNumber; // number of points in the list
103
}
103
}
Line 104... Line 104...
104
 
104
 
105
u8 WPList_Append(Waypoint_t* pwp)
105
u8 WPList_Append(Waypoint_t* pwp)
106
{
106
{
107
        if(WPNumber < WPLISTLEN) // there is still some space in the list
107
        if((WPNumber < WPLISTLEN) && (pwp->Index == (WPNumber + 1)) ) // there is still some space in the list and index points to next
108
        {
108
        {
109
                memcpy(&WPList[WPNumber], pwp, sizeof(Waypoint_t)); // copy wp data to list entry                                                                               // increment list length
109
                memcpy(&WPList[WPNumber], pwp, sizeof(Waypoint_t)); // copy wp data to list entry                                                                               // increment list length
110
                WPNumber++;
110
                WPNumber++;
-
 
111
                NaviData.WaypointNumber = WPNumber;
-
 
112
                if(WPNumber == 1) // only for the first entry
-
 
113
                {
-
 
114
                        // update POI index
-
 
115
                        switch(WPList[WPIndex-1].Type)
-
 
116
                        {
-
 
117
                                case POINT_TYPE_WP:
-
 
118
                                        if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
-
 
119
                                        else POIIndex = 0;
-
 
120
                                        break;
-
 
121
                               
-
 
122
                                case POINT_TYPE_POI:
-
 
123
                                        POIIndex = 1;
-
 
124
                                        break;
-
 
125
 
-
 
126
                                default:
-
 
127
                                        POIIndex = 0;
-
 
128
                                        break;
-
 
129
                        }              
111
                NaviData.WaypointNumber = WPNumber;
130
                }
112
                return TRUE;
131
                return TRUE;
113
        }
132
        }
114
        else return FALSE;
133
        else return FALSE;
Line 115... Line 134...
115
}
134
}
116
 
135
 
117
// returns the pointer to the first waypoint within the list
136
// returns the pointer to the first waypoint within the list
-
 
137
Waypoint_t* WPList_Begin(void)
118
Waypoint_t* WPList_Begin(void)
138
{
-
 
139
        u8 i;
119
{
140
        WPIndex = 0; // set list position invalid
120
        WPIndex = 0; // set list position invalid
141
        POIIndex = 0; // set invalid POI
121
       
142
 
122
        if(WPNumber > 0)
143
        if(WPNumber > 0)
123
        {
144
        {
124
                u8 i;
145
 
125
                // search for first wp in list
146
                // search for first wp in list
126
                for(i = 0; i < WPNumber; i++)
147
                for(i = 0; i < WPNumber; i++)
127
                {
148
                {
128
                        if((WPList[i].Type == POINT_TYPE_WP) && (WPList[i].Position.Status != INVALID))
149
                        if((WPList[i].Type == POINT_TYPE_WP) && (WPList[i].Position.Status != INVALID))
129
                        {
150
                        {
130
                                WPIndex = i + 1;
151
                                WPIndex = i + 1;
131
                                break;
152
                                break;
-
 
153
                        }
-
 
154
                }
-
 
155
                if(WPIndex) // found a WP in the list
-
 
156
                {
-
 
157
                        NaviData.WaypointIndex = WPIndex;
-
 
158
                        // update index to POI
-
 
159
                        if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
-
 
160
                        else POIIndex = 0;     
-
 
161
                        return(&(WPList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list              
-
 
162
                }
-
 
163
                else // some points in the list but no WP found
-
 
164
                {
-
 
165
                        NaviData.WaypointIndex = WPIndex;
-
 
166
                        //Check for an existing POI
-
 
167
                        for(i = 0; i < WPNumber; i++)
-
 
168
                        {
-
 
169
                                if((WPList[i].Type == POINT_TYPE_POI) && (WPList[i].Position.Status != INVALID))
-
 
170
                                {
-
 
171
                                        POIIndex = i + 1;
-
 
172
                                        break;
-
 
173
                                }
-
 
174
                        }
132
                        }
175
                        return NULL;
133
                }
176
                }
134
        }
-
 
135
        if(WPIndex) // found a WP in the list
-
 
136
        {
-
 
137
                NaviData.WaypointIndex = WPIndex;
-
 
138
                // update index to POI
-
 
139
                if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
-
 
140
                else POIIndex = 0;     
-
 
141
                return(&(WPList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list              
-
 
142
        }
177
        }
143
        else
178
        else // no point in the list
144
        {
179
        {
145
                POIIndex = 0;
180
                POIIndex = 0;
146
                NaviData.WaypointIndex = WPIndex;
181
                NaviData.WaypointIndex = WPIndex;
147
                return NULL;
182
                return NULL;   
Line 148... Line 183...
148
        }
183
        }
149
}
184
}
150
 
185
 
-
 
186
// returns the last waypoint
-
 
187
Waypoint_t* WPList_End(void)
151
// returns the last waypoint
188
{
-
 
189
       
-
 
190
        u8 i;
152
Waypoint_t* WPList_End(void)
191
        WPIndex = 0; // set list position invalid
153
{
192
        POIIndex = 0; // set invalid
154
        WPIndex = 0; // set list position invalid
193
 
155
        if(WPNumber > 0)
-
 
156
        {
194
        if(WPNumber > 0)
157
                // search backward!
195
        {
158
                u8 i;
196
                // search backward!
159
                for(i = 1; i <= WPNumber; i++)
197
                for(i = 1; i <= WPNumber; i++)
160
                {
198
                {
161
                        if((WPList[WPNumber - i].Type == POINT_TYPE_WP) && (WPList[WPNumber - i].Position.Status != INVALID))
199
                        if((WPList[WPNumber - i].Type == POINT_TYPE_WP) && (WPList[WPNumber - i].Position.Status != INVALID))
162
                        {      
200
                        {      
163
                                WPIndex = WPNumber - i + 1;
201
                                WPIndex = WPNumber - i + 1;
-
 
202
                                break;
-
 
203
                        }
-
 
204
                }
-
 
205
                if(WPIndex) // found a WP within the list
-
 
206
                {
-
 
207
                        NaviData.WaypointIndex = WPIndex;
-
 
208
                        if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
-
 
209
                        else POIIndex = 0;     
-
 
210
                        return(&(WPList[WPIndex-1]));
-
 
211
                }
-
 
212
                else // list conbtains some points but no WP in the list
-
 
213
                {
-
 
214
                        // search backward for a POI!
-
 
215
                        for(i = 1; i <= WPNumber; i++)
-
 
216
                        {
-
 
217
                                if((WPList[WPNumber - i].Type == POINT_TYPE_POI) && (WPList[WPNumber - i].Position.Status != INVALID))
-
 
218
                                {      
-
 
219
                                        POIIndex = WPNumber - i + 1;
-
 
220
                                        break;
-
 
221
                                }
-
 
222
                        }
164
                                break;
223
                        NaviData.WaypointIndex = WPIndex;
165
                        }
224
                        return NULL;   
166
                }
-
 
167
        }
-
 
168
        if(WPIndex) // found a WP within the list
-
 
169
        {
-
 
170
                NaviData.WaypointIndex = WPIndex;
-
 
171
                if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
-
 
172
                else POIIndex = 0;     
-
 
173
                return(&(WPList[WPIndex-1]));
225
                }
174
        }
226
        }
175
        else
227
        else // no point in the list
176
        {
228
        {
177
                POIIndex = 0;
229
                        POIIndex = 0;
178
                NaviData.WaypointIndex = WPIndex;
230
                        NaviData.WaypointIndex = WPIndex;
Line 179... Line 231...
179
                return NULL;   
231
                        return NULL;
180
        }
232
        }
Line 203... Line 255...
203
                NaviData.WaypointIndex = WPIndex;
255
                NaviData.WaypointIndex = WPIndex;
204
                if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
256
                if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
205
                else POIIndex = 0;
257
                else POIIndex = 0;
206
                return(&(WPList[WPIndex-1]));   // return pointer to this waypoint
258
                return(&(WPList[WPIndex-1]));   // return pointer to this waypoint
207
        }
259
        }
-
 
260
        else
-
 
261
        {
-
 
262
                NaviData.WaypointIndex = WPIndex;      
-
 
263
                POIIndex = 0;
208
        else return(NULL);
264
                return(NULL);
-
 
265
        }
209
}      
266
}      
Line 210... Line 267...
210
 
267
 
211
Waypoint_t* WPList_GetAt(u8 index)
268
Waypoint_t* WPList_GetAt(u8 index)
212
{
269
{