Rev 224 | Rev 227 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 224 | Rev 225 | ||
---|---|---|---|
Line 62... | Line 62... | ||
62 | 62 | ||
63 | // the waypoints list |
63 | // the waypoints list |
64 | #define WPLISTLEN 21 |
64 | #define WPLISTLEN 21 |
65 | #define MAXWPNUMBER (WPLISTLEN-1) |
65 | #define MAXWPNUMBER (WPLISTLEN-1) |
66 | Waypoint_t WPList[WPLISTLEN]; |
66 | Waypoint_t WPList[WPLISTLEN]; |
- | 67 | u8 WPIndex = 0; // index of GPS point representig the WP |
|
67 | u8 WPIndex = 0; |
68 | u8 POIIndex = 0; // index of GPS Point representing the current POI |
Line 68... | Line -... | ||
68 | u8 WPNumber = 0; |
- | |
69 | 69 | u8 WPNumber = 0; |
|
70 | 70 | ||
71 | u8 WPList_Init(void) |
71 | u8 WPList_Init(void) |
72 | { |
72 | { |
Line 73... | Line 73... | ||
73 | return WPList_Clear(); |
73 | return WPList_Clear(); |
74 | } |
74 | } |
75 | 75 | ||
76 | u8 WPList_Clear(void) |
76 | u8 WPList_Clear(void) |
- | 77 | { |
|
77 | { |
78 | u8 i; |
78 | u8 i; |
79 | WPIndex = 0; // invalid index |
79 | WPIndex = 0; // invalid index |
80 | POIIndex = 0; // invalid index |
Line 80... | Line 81... | ||
80 | WPNumber = 0; // no contents |
81 | WPNumber = 0; // no contents |
81 | NaviData.WaypointNumber = WPNumber; |
82 | NaviData.WaypointNumber = WPNumber; |
82 | NaviData.WaypointIndex = WPIndex; |
83 | NaviData.WaypointIndex = WPIndex; |
83 | 84 | ||
84 | for(i = 1; i < WPLISTLEN; i++) |
85 | for(i = 0; i < WPLISTLEN; i++) |
85 | { |
86 | { |
Line 102... | Line 103... | ||
102 | 103 | ||
103 | u8 WPList_Append(Waypoint_t* pwp) |
104 | u8 WPList_Append(Waypoint_t* pwp) |
104 | { |
105 | { |
105 | if(WPNumber < MAXWPNUMBER) // there is still some space in the list |
106 | if(WPNumber < MAXWPNUMBER) // there is still some space in the list |
106 | { |
- | |
107 | WPNumber++; |
107 | { |
108 | 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 |
- | 109 | WPList[WPNumber].Position.Status = NEWDATA; // mark as new data // increment list length |
|
109 | WPList[WPNumber].Position.Status = NEWDATA; // mark as new data // increment list length |
110 | WPNumber++; |
110 | NaviData.WaypointNumber = WPNumber; |
111 | NaviData.WaypointNumber = WPNumber; |
111 | return TRUE; |
112 | return TRUE; |
112 | } |
113 | } |
113 | else return FALSE; |
114 | else return FALSE; |
Line 114... | Line 115... | ||
114 | } |
115 | } |
115 | 116 | ||
116 | // rewind to the begin of the list, and returns the first waypoint |
117 | // returns the first waypoint |
117 | Waypoint_t* WPList_Begin(void) |
118 | Waypoint_t* WPList_Begin(void) |
118 | { |
119 | { |
- | 120 | if(WPNumber > 0) |
|
- | 121 | { |
|
119 | if(WPNumber > 0) |
122 | u8 i, wp_found = 0; |
- | 123 | // search for first wp in list |
|
- | 124 | for(i = 0; i < WPNumber; i++) |
|
- | 125 | { |
|
- | 126 | if(WPList[i].Type == POINT_TYPE_WP) |
|
- | 127 | { |
|
- | 128 | wp_found = 1; |
|
- | 129 | break; |
|
- | 130 | } |
|
- | 131 | } |
|
- | 132 | if(wp_found) // found a WP in the list |
|
120 | { |
133 | { |
- | 134 | WPIndex = i+1; |
|
- | 135 | NaviData.WaypointIndex = WPIndex; |
|
121 | WPIndex = 1; // reset list index |
136 | if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
- | 137 | else POIIndex = 0; |
|
- | 138 | return(&(WPList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list |
|
- | 139 | } |
|
- | 140 | else // found no WP within the list |
|
- | 141 | { |
|
- | 142 | WPIndex = 0; |
|
- | 143 | POIIndex = 0; |
|
- | 144 | NaviData.WaypointIndex = WPIndex; |
|
122 | NaviData.WaypointIndex = WPIndex; |
145 | return NULL; |
123 | return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list |
146 | } |
124 | } |
147 | } |
125 | else |
148 | else // empty list |
- | 149 | { |
|
126 | { |
150 | WPIndex = 0; // invalid index |
127 | WPIndex = 0; // invalid index |
151 | POIIndex = 0; |
128 | NaviData.WaypointIndex = 0; |
152 | NaviData.WaypointIndex = WPIndex; |
Line 129... | Line 153... | ||
129 | return NULL; // else return NULL |
153 | return NULL; |
Line 130... | Line 154... | ||
130 | } |
154 | } |
131 | 155 | ||
132 | } |
156 | } |
133 | 157 | ||
134 | // jump to the end of the list, and returns the last waypoint |
158 | // returns the last waypoint |
- | 159 | Waypoint_t* WPList_End(void) |
|
- | 160 | { |
|
- | 161 | if(WPNumber > 0) |
|
- | 162 | { |
|
- | 163 | // search backward |
|
- | 164 | u8 i, wp_found = 0; |
|
- | 165 | for(i = 1; i <= WPNumber; i++) |
|
- | 166 | { |
|
- | 167 | if(WPList[WPNumber - i].Type == POINT_TYPE_WP) |
|
- | 168 | { |
|
- | 169 | wp_found = 1; |
|
- | 170 | break; |
|
135 | Waypoint_t* WPList_End(void) |
171 | } |
136 | { |
172 | } |
137 | if(WPNumber > 0) |
173 | if(wp_found) // found a WP within the list |
- | 174 | { |
|
- | 175 | WPIndex = WPNumber - i + 1; |
|
- | 176 | NaviData.WaypointIndex = WPIndex; |
|
- | 177 | if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
|
- | 178 | else POIIndex = 0; |
|
- | 179 | return(&(WPList[WPIndex-1])); |
|
- | 180 | } |
|
- | 181 | else |
|
- | 182 | { |
|
- | 183 | WPIndex = 0; |
|
138 | { |
184 | POIIndex = 0; |
139 | WPIndex = WPNumber; |
185 | NaviData.WaypointIndex = WPIndex; |
140 | NaviData.WaypointIndex = WPIndex; |
186 | return NULL; |
141 | return(&(WPList[WPIndex])); // if list is not empty return pointer to first waypoint in the list |
187 | } |
- | 188 | } |
|
142 | } |
189 | else |
143 | else |
190 | { |
144 | { |
191 | WPIndex = 0; |
145 | WPIndex = 0; |
- | |
146 | NaviData.WaypointIndex = WPIndex; |
192 | POIIndex = 0; |
Line 147... | Line 193... | ||
147 | return NULL; // else return NULL |
193 | NaviData.WaypointIndex = WPIndex; |
148 | } |
194 | return NULL; |
149 | 195 | } |
|
- | 196 | } |
|
150 | } |
197 | |
151 | 198 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
|
- | 199 | Waypoint_t* WPList_Next(void) |
|
- | 200 | { |
|
- | 201 | if(WPNumber == 0) return NULL; |
|
- | 202 | if((WPIndex > 0) && (WPIndex < WPNumber)) // if the next WP exist |
|
- | 203 | { |
|
- | 204 | u8 i, wp_found = 0; |
|
- | 205 | for(i = WPIndex; i < WPNumber; i++) |
|
- | 206 | { |
|
- | 207 | if(WPList[i].Type == POINT_TYPE_WP) // jump over POIs |
|
- | 208 | { |
|
- | 209 | wp_found = 1; |
|
152 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
210 | break; |
153 | Waypoint_t* WPList_Next(void) |
211 | } |
- | 212 | } |
|
- | 213 | if(wp_found) |
|
154 | { |
214 | { |
- | 215 | WPIndex = i+1; |
|
- | 216 | NaviData.WaypointIndex = WPIndex; |
|
155 | if(WPIndex < WPNumber) // if the next WPIndex exist |
217 | if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading); |
156 | { |
218 | else POIIndex = 0; |
157 | WPIndex++; // goto next |
219 | return(&(WPList[WPIndex-1])); // return pointer to this waypoint |
Line 158... | Line 220... | ||
158 | NaviData.WaypointIndex = WPIndex; |
220 | } |
159 | return(&(WPList[WPIndex])); // return pointer to this waypoint |
221 | else return NULL; |
160 | } |
222 | } |
161 | else return(NULL); |
223 | else return(NULL); |
162 | } |
224 | } |
Line 163... | Line 225... | ||
163 | 225 | ||
164 | Waypoint_t* WPList_GetAt(u8 index) |
226 | Waypoint_t* WPList_GetAt(u8 index) |
165 | { |
- | |
166 | if(index <= WPNumber) return(&(WPList[index])); // return pointer to this waypoint |
227 | { |
167 | else return(NULL); |
228 | if((index > 0) && (index <= WPNumber)) return(&(WPList[index-1])); // return pointer to this waypoint |
Line 168... | Line -... | ||
168 | } |
- | |
169 | - | ||
170 | Waypoint_t* WPList_GetPOI(void) |
- | |
171 | { |
- |