Subversion Repositories NaviCtrl

Rev

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

Rev 286 Rev 295
Line 108... Line 108...
108
u8 PointList_GetCount(void)
108
u8 PointList_GetCount(void)
109
{
109
{
110
        return PointCount; // number of points in the list
110
        return PointCount; // number of points in the list
111
}
111
}
Line -... Line 112...
-
 
112
 
-
 
113
Point_t* PointList_GetAt(u8 index)
-
 
114
{
-
 
115
        if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint
-
 
116
        else return(NULL);
-
 
117
}
112
 
118
 
113
u8 PointList_Append(Point_t* pPoint)
119
u8 PointList_SetAt(Point_t* pPoint)
-
 
120
{
114
{
121
        // if index is in range
115
        if((PointCount < MAX_LIST_LEN) && (pPoint->Index == (PointCount + 1)) ) // there is still some space in the list and index points to next
122
        if((pPoint->Index > 0) && (pPoint->Index < MAX_LIST_LEN))
116
        {
-
 
117
                memcpy(&PointList[PointCount], pPoint, sizeof(Point_t)); // copy data to list entry                                                                             // increment list length
123
        {
118
                if(PointList[PointCount].Type == POINT_TYPE_WP) WPCount++;
124
                // check list entry before update
119
                if(PointList[PointCount].Type == POINT_TYPE_POI) POICount++;
125
                if(PointList[pPoint->Index-1].Type)
120
                NaviData.WaypointNumber = WPCount;
-
 
121
                PointCount++;
-
 
122
                if(PointCount == 1) // only for the first entry
126
                switch(PointList[pPoint->Index-1].Type)
123
                {
127
                {
124
                        // update POI index
128
                        case POINT_TYPE_INVALID: // was invalid
125
                        switch(PointList[WPIndex-1].Type)
129
                                switch(pPoint->Type)
-
 
130
                                {
-
 
131
                                        default:
-
 
132
                                        case POINT_TYPE_INVALID:
-
 
133
                                                // nothing to do
-
 
134
                                                break;
126
                        {
135
 
-
 
136
                                        case POINT_TYPE_WP:
127
                                case POINT_TYPE_WP:
137
                                                WPCount++;
-
 
138
                                                PointCount++;
-
 
139
                                                break;
128
                                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
140
                                       
-
 
141
                                        case POINT_TYPE_POI:
-
 
142
                                                POICount++;
129
                                        else POIIndex = 0;
143
                                                PointCount++;
-
 
144
                                                break;
-
 
145
                                }
Line -... Line 146...
-
 
146
                                break;
-
 
147
                               
-
 
148
                        case POINT_TYPE_WP: // was  a waypoint
-
 
149
                                switch(pPoint->Type)
-
 
150
                                {
-
 
151
                                        case POINT_TYPE_INVALID:
-
 
152
                                                WPCount--;
-
 
153
                                                PointCount--;
-
 
154
                                                break;
-
 
155
 
-
 
156
                                        default:
-
 
157
                                        case POINT_TYPE_WP:
-
 
158
                                                //nothing to do
130
                                        break;
159
                                                break;
-
 
160
                                       
-
 
161
                                        case POINT_TYPE_POI:
-
 
162
                                                POICount++;
-
 
163
                                                WPCount--;
-
 
164
                                                break;
-
 
165
                                }
-
 
166
                                break;
-
 
167
                               
-
 
168
                        case POINT_TYPE_POI: // was a poi
-
 
169
                                switch(pPoint->Type)
131
                               
170
                                {
-
 
171
                                        case POINT_TYPE_INVALID:
-
 
172
                                                POICount--;
-
 
173
                                                PointCount--;
-
 
174
                                                break;
-
 
175
 
132
                                case POINT_TYPE_POI:
176
                                        case POINT_TYPE_WP:
133
                                        POIIndex = 1;
177
                                                WPCount++;
134
                                        POICount = 1;
178
                                                POICount--;
-
 
179
                                                break;
135
                                        break;
180
                                       
136
 
181
                                        case POINT_TYPE_POI:
137
                                default:
182
                                        default:
138
                                        POIIndex = 0;
183
                                                // nothing to do
-
 
184
                                                break;
139
                                        break;
185
                                }
-
 
186
                                break;         
-
 
187
                }
140
                        }              
188
                memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry                                                                                
141
                }
189
                NaviData.WaypointNumber = WPCount;
142
                return TRUE;
190
                return pPoint->Index;
143
        }
191
        }
Line 144... Line 192...
144
        else return FALSE;
192
        else return 0;
145
}
193
}
146
 
194
 
147
// returns the pointer to the first waypoint within the list
195
// returns the pointer to the first waypoint within the list
148
Point_t* PointList_WPBegin(void)
196
Point_t* PointList_WPBegin(void)
-
 
197
{
149
{
198
        u8 i;
-
 
199
        WPIndex = 0; // set list position invalid
150
        u8 i;
200
 
151
        WPIndex = 0; // set list position invalid
201
        if(WPActive == FALSE) return(NULL);
152
        if(WPActive == FALSE) return(NULL);
202
 
153
        POIIndex = 0; // set invalid POI
203
        POIIndex = 0; // set invalid POI
154
        if(PointCount > 0)
204
        if(PointCount > 0)
155
        {
205
        {
156
                // search for first wp in list
206
                // search for first wp in list
157
                for(i = 0; i <PointCount; i++)
207
                for(i = 0; i <MAX_LIST_LEN; i++)
158
                {
208
                {
159
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID))
209
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID))
Line 172... Line 222...
172
                }
222
                }
173
                else // some points in the list but no WP found
223
                else // some points in the list but no WP found
174
                {
224
                {
175
                        NaviData.WaypointIndex = 0;
225
                        NaviData.WaypointIndex = 0;
176
                        //Check for an existing POI
226
                        //Check for an existing POI
177
                        for(i = 0; i < PointCount; i++)
227
                        for(i = 0; i < MAX_LIST_LEN; i++)
178
                        {
228
                        {
179
                                if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID))
229
                                if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID))
180
                                {
230
                                {
181
                                        POIIndex = i + 1;
231
                                        POIIndex = i + 1;
182
                                        break;
232
                                        break;
183
                                }
233
                                }
184
                        }
234
                        }
185
                        return NULL;
-
 
186
                }
235
                }
187
        }
236
        }
188
        else // no point in the list
237
        else // no point in the list
189
        {
238
        {
190
                POIIndex = 0;
239
                POIIndex = 0;
191
                NaviData.WaypointIndex = 0;
240
                NaviData.WaypointIndex = 0;    
192
                return NULL;   
-
 
193
        }
241
        }
-
 
242
 
-
 
243
        if(WPIndex) return(&(PointList[WPIndex-1]));
-
 
244
        else return(NULL);
194
}
245
}
Line 195... Line 246...
195
 
246
 
196
// returns the last waypoint
247
// returns the last waypoint
197
Point_t* PointList_WPEnd(void)
248
Point_t* PointList_WPEnd(void)
Line 204... Line 255...
204
        if(WPActive == FALSE) return(NULL);
255
        if(WPActive == FALSE) return(NULL);
Line 205... Line 256...
205
 
256
 
206
        if(PointCount > 0)
257
        if(PointCount > 0)
207
        {
258
        {
208
                // search backward!
259
                // search backward!
209
                for(i = 1; i <= PointCount; i++)
260
                for(i = 1; i <= MAX_LIST_LEN; i++)
210
                {
261
                {
211
                        if((PointList[PointCount - i].Type == POINT_TYPE_WP) && (PointList[PointCount - i].Position.Status != INVALID))
262
                        if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
212
                        {      
263
                        {      
213
                                WPIndex = PointCount - i + 1;
264
                                WPIndex = MAX_LIST_LEN - i + 1;
214
                                break;
265
                                break;
215
                        }
266
                        }
216
                }
267
                }
217
                if(WPIndex) // found a WP within the list
268
                if(WPIndex) // found a WP within the list
218
                {
269
                {
219
                        NaviData.WaypointIndex = WPCount;
270
                        NaviData.WaypointIndex = WPCount;
220
                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
271
                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
221
                        else POIIndex = 0;     
-
 
222
                        return(&(PointList[WPIndex-1]));
272
                        else POIIndex = 0;     
223
                }
273
                }
224
                else // list contains some points but no WP in the list
274
                else // list contains some points but no WP in the list
225
                {
275
                {
226
                        // search backward for a POI!
276
                        // search backward for a POI!
227
                        for(i = 1; i <= PointCount; i++)
277
                        for(i = 1; i <= MAX_LIST_LEN; i++)
228
                        {
278
                        {
229
                                if((PointList[PointCount - i].Type == POINT_TYPE_POI) && (PointList[PointCount - i].Position.Status != INVALID))
279
                                if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
230
                                {      
280
                                {      
231
                                        POIIndex = PointCount - i + 1;
281
                                        POIIndex = MAX_LIST_LEN - i + 1;
232
                                        break;
282
                                        break;
233
                                }
283
                                }
234
                        }
284
                        }
235
                        NaviData.WaypointIndex = 0;
-
 
236
                        return NULL;   
285
                        NaviData.WaypointIndex = 0;    
237
                }
286
                }
238
        }
287
        }
239
        else // no point in the list
288
        else // no point in the list
240
        {
289
        {
241
                POIIndex = 0;
290
                POIIndex = 0;
242
                NaviData.WaypointIndex = 0;
-
 
243
                return NULL;
291
                NaviData.WaypointIndex = 0;
-
 
292
        }
-
 
293
        if(WPIndex) return(&(PointList[WPIndex-1]));
244
        }
294
        else return(NULL);
Line 245... Line 295...
245
}
295
}
246
 
296
 
247
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
297
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
248
Point_t* PointList_WPNext(void)
298
Point_t* PointList_WPNext(void)
249
{
299
{
Line 250... Line 300...
250
        u8 wp_found = 0;
300
        u8 wp_found = 0;
251
        if(WPActive == FALSE) return(NULL);
301
        if(WPActive == FALSE) return(NULL);
252
               
302
               
253
        if(WPIndex < PointCount) // if there is a next entry in the list
303
        if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list
254
        {
304
        {
255
                u8 i;
305
                u8 i;
256
                for(i = WPIndex; i < PointCount; i++)   // start search for next at next list entry
306
                for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry
257
                {
307
                {
258
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs
308
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs
Line 278... Line 328...
278
        }
328
        }
279
}      
329
}      
Line 280... Line 330...
280
 
330
 
281
void PointList_WPActive(u8 set)
331
void PointList_WPActive(u8 set)
-
 
332
{
-
 
333
        if(set)
282
{
334
        {      
-
 
335
                WPActive = TRUE;
-
 
336
                PointList_WPBegin(); // uopdates POI index
-
 
337
        }
-
 
338
        else
283
        if(set) WPActive = TRUE;
339
        {
-
 
340
                WPActive = FALSE;
-
 
341
                POIIndex = 0;  // disable POI also
284
        else WPActive = FALSE;
342
        }
Line 285... Line -...
285
}
-
 
286
 
-
 
287
Point_t* PointList_GetAt(u8 index)
-
 
288
{
-
 
289
        if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint
-
 
290
        else return(NULL);
-
 
291
}
343
}
292
 
344
 
293
Point_t* PointList_GetPOI(void)
345
Point_t* PointList_GetPOI(void)
294
{
346
{