Rev 296 | Rev 360 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 296 | Rev 351 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
42 | // + clearly linked as origin |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | 57 | ||
58 | #include <string.h> |
58 | #include <string.h> |
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" |
62 | 62 | ||
63 | // the waypoints list |
63 | // the waypoints list |
64 | #define MAX_LIST_LEN 31 |
64 | #define MAX_LIST_LEN 101 |
65 | 65 | ||
66 | Point_t PointList[MAX_LIST_LEN]; |
66 | Point_t PointList[MAX_LIST_LEN]; |
67 | u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount |
67 | u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount |
68 | u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount |
68 | u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount |
69 | u8 WPCount = 0; // number of waypoints |
69 | u8 WPCount = 0; // number of waypoints |
70 | u8 PointCount = 0; // number of wp in the list can be maximal equal to MAX_LIST_LEN |
70 | u8 PointCount = 0; // number of wp in the list can be maximal equal to MAX_LIST_LEN |
71 | u8 POICount = 0; |
71 | u8 POICount = 0; |
72 | 72 | ||
73 | u8 WPActive = FALSE; |
73 | u8 WPActive = FALSE; |
74 | 74 | ||
75 | u8 PointList_Init(void) |
75 | u8 PointList_Init(void) |
76 | { |
76 | { |
77 | return PointList_Clear(); |
77 | return PointList_Clear(); |
78 | } |
78 | } |
79 | 79 | ||
80 | u8 PointList_Clear(void) |
80 | u8 PointList_Clear(void) |
81 | { |
81 | { |
82 | u8 i; |
82 | u8 i; |
83 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
83 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
84 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
84 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
85 | WPCount = 0; // no waypoints |
85 | WPCount = 0; // no waypoints |
86 | POICount = 0; |
86 | POICount = 0; |
87 | PointCount = 0; // no contents |
87 | PointCount = 0; // no contents |
88 | WPActive = FALSE; |
88 | WPActive = FALSE; |
89 | NaviData.WaypointNumber = WPCount; |
89 | NaviData.WaypointNumber = WPCount; |
90 | NaviData.WaypointIndex = 0; |
90 | NaviData.WaypointIndex = 0; |
91 | 91 | ||
92 | for(i = 0; i < MAX_LIST_LEN; i++) |
92 | for(i = 0; i < MAX_LIST_LEN; i++) |
93 | { |
93 | { |
94 | PointList[i].Position.Status = INVALID; |
94 | PointList[i].Position.Status = INVALID; |
95 | PointList[i].Position.Latitude = 0; |
95 | PointList[i].Position.Latitude = 0; |
96 | PointList[i].Position.Longitude = 0; |
96 | PointList[i].Position.Longitude = 0; |
97 | PointList[i].Position.Altitude = 0; |
97 | PointList[i].Position.Altitude = 0; |
98 | PointList[i].Heading = 361; // invalid value |
98 | PointList[i].Heading = 361; // invalid value |
99 | PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered |
99 | PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered |
100 | PointList[i].HoldTime = 0; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
100 | PointList[i].HoldTime = 0; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
101 | PointList[i].Type = POINT_TYPE_INVALID; |
101 | PointList[i].Type = POINT_TYPE_INVALID; |
102 | PointList[i].Event_Flag = 0; // future implementation |
102 | PointList[i].Event_Flag = 0; // future implementation |
103 | PointList[i].AltitudeRate = 0; // no change of setpoint |
103 | PointList[i].AltitudeRate = 0; // no change of setpoint |
104 | } |
104 | } |
105 | return TRUE; |
105 | return TRUE; |
106 | } |
106 | } |
107 | 107 | ||
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 | } |
112 | 112 | ||
113 | Point_t* PointList_GetAt(u8 index) |
113 | Point_t* PointList_GetAt(u8 index) |
114 | { |
114 | { |
115 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
115 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
116 | else return(NULL); |
116 | else return(NULL); |
117 | } |
117 | } |
118 | 118 | ||
119 | u8 PointList_SetAt(Point_t* pPoint) |
119 | u8 PointList_SetAt(Point_t* pPoint) |
120 | { |
120 | { |
121 | // if index is in range |
121 | // if index is in range |
122 | if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN)) |
122 | if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN)) |
123 | { |
123 | { |
124 | // check list entry before update |
124 | // check list entry before update |
125 | switch(PointList[pPoint->Index-1].Type) |
125 | switch(PointList[pPoint->Index-1].Type) |
126 | { |
126 | { |
127 | case POINT_TYPE_INVALID: // was invalid |
127 | case POINT_TYPE_INVALID: // was invalid |
128 | switch(pPoint->Type) |
128 | switch(pPoint->Type) |
129 | { |
129 | { |
130 | default: |
130 | default: |
131 | case POINT_TYPE_INVALID: |
131 | case POINT_TYPE_INVALID: |
132 | // nothing to do |
132 | // nothing to do |
133 | break; |
133 | break; |
134 | 134 | ||
135 | case POINT_TYPE_WP: |
135 | case POINT_TYPE_WP: |
136 | WPCount++; |
136 | WPCount++; |
137 | PointCount++; |
137 | PointCount++; |
138 | break; |
138 | break; |
139 | 139 | ||
140 | case POINT_TYPE_POI: |
140 | case POINT_TYPE_POI: |
141 | POICount++; |
141 | POICount++; |
142 | PointCount++; |
142 | PointCount++; |
143 | break; |
143 | break; |
144 | } |
144 | } |
145 | break; |
145 | break; |
146 | 146 | ||
147 | case POINT_TYPE_WP: // was a waypoint |
147 | case POINT_TYPE_WP: // was a waypoint |
148 | switch(pPoint->Type) |
148 | switch(pPoint->Type) |
149 | { |
149 | { |
150 | case POINT_TYPE_INVALID: |
150 | case POINT_TYPE_INVALID: |
151 | WPCount--; |
151 | WPCount--; |
152 | PointCount--; |
152 | PointCount--; |
153 | break; |
153 | break; |
154 | 154 | ||
155 | default: |
155 | default: |
156 | case POINT_TYPE_WP: |
156 | case POINT_TYPE_WP: |
157 | //nothing to do |
157 | //nothing to do |
158 | break; |
158 | break; |
159 | 159 | ||
160 | case POINT_TYPE_POI: |
160 | case POINT_TYPE_POI: |
161 | POICount++; |
161 | POICount++; |
162 | WPCount--; |
162 | WPCount--; |
163 | break; |
163 | break; |
164 | } |
164 | } |
165 | break; |
165 | break; |
166 | 166 | ||
167 | case POINT_TYPE_POI: // was a poi |
167 | case POINT_TYPE_POI: // was a poi |
168 | switch(pPoint->Type) |
168 | switch(pPoint->Type) |
169 | { |
169 | { |
170 | case POINT_TYPE_INVALID: |
170 | case POINT_TYPE_INVALID: |
171 | POICount--; |
171 | POICount--; |
172 | PointCount--; |
172 | PointCount--; |
173 | break; |
173 | break; |
174 | 174 | ||
175 | case POINT_TYPE_WP: |
175 | case POINT_TYPE_WP: |
176 | WPCount++; |
176 | WPCount++; |
177 | POICount--; |
177 | POICount--; |
178 | break; |
178 | break; |
179 | 179 | ||
180 | case POINT_TYPE_POI: |
180 | case POINT_TYPE_POI: |
181 | default: |
181 | default: |
182 | // nothing to do |
182 | // nothing to do |
183 | break; |
183 | break; |
184 | } |
184 | } |
185 | break; |
185 | break; |
186 | } |
186 | } |
187 | memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry |
187 | memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry |
188 | NaviData.WaypointNumber = WPCount; |
188 | NaviData.WaypointNumber = WPCount; |
189 | return pPoint->Index; |
189 | return pPoint->Index; |
190 | } |
190 | } |
191 | else return(0); |
191 | else return(0); |
192 | } |
192 | } |
193 | 193 | ||
194 | // returns the pointer to the first waypoint within the list |
194 | // returns the pointer to the first waypoint within the list |
195 | Point_t* PointList_WPBegin(void) |
195 | Point_t* PointList_WPBegin(void) |
196 | { |
196 | { |
197 | u8 i; |
197 | u8 i; |
198 | WPIndex = 0; // set list position invalid |
198 | WPIndex = 0; // set list position invalid |
199 | 199 | ||
200 | if(WPActive == FALSE) return(NULL); |
200 | if(WPActive == FALSE) return(NULL); |
201 | 201 | ||
202 | POIIndex = 0; // set invalid POI |
202 | POIIndex = 0; // set invalid POI |
203 | if(PointCount > 0) |
203 | if(PointCount > 0) |
204 | { |
204 | { |
205 | // search for first wp in list |
205 | // search for first wp in list |
206 | for(i = 0; i <MAX_LIST_LEN; i++) |
206 | for(i = 0; i <MAX_LIST_LEN; i++) |
207 | { |
207 | { |
208 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
208 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
209 | { |
209 | { |
210 | WPIndex = i + 1; |
210 | WPIndex = i + 1; |
211 | break; |
211 | break; |
212 | } |
212 | } |
213 | } |
213 | } |
214 | if(WPIndex) // found a WP in the list |
214 | if(WPIndex) // found a WP in the list |
215 | { |
215 | { |
216 | NaviData.WaypointIndex = 1; |
216 | NaviData.WaypointIndex = 1; |
217 | // update index to POI |
217 | // update index to POI |
218 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
218 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
219 | else POIIndex = 0; |
219 | else POIIndex = 0; |
220 | } |
220 | } |
221 | else // some points in the list but no WP found |
221 | else // some points in the list but no WP found |
222 | { |
222 | { |
223 | NaviData.WaypointIndex = 0; |
223 | NaviData.WaypointIndex = 0; |
224 | //Check for an existing POI |
224 | //Check for an existing POI |
225 | for(i = 0; i < MAX_LIST_LEN; i++) |
225 | for(i = 0; i < MAX_LIST_LEN; i++) |
226 | { |
226 | { |
227 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
227 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
228 | { |
228 | { |
229 | POIIndex = i + 1; |
229 | POIIndex = i + 1; |
230 | break; |
230 | break; |
231 | } |
231 | } |
232 | } |
232 | } |
233 | } |
233 | } |
234 | } |
234 | } |
235 | else // no point in the list |
235 | else // no point in the list |
236 | { |
236 | { |
237 | POIIndex = 0; |
237 | POIIndex = 0; |
238 | NaviData.WaypointIndex = 0; |
238 | NaviData.WaypointIndex = 0; |
239 | } |
239 | } |
240 | 240 | ||
241 | if(WPIndex) return(&(PointList[WPIndex-1])); |
241 | if(WPIndex) return(&(PointList[WPIndex-1])); |
242 | else return(NULL); |
242 | else return(NULL); |
243 | } |
243 | } |
244 | 244 | ||
245 | // returns the last waypoint |
245 | // returns the last waypoint |
246 | Point_t* PointList_WPEnd(void) |
246 | Point_t* PointList_WPEnd(void) |
247 | { |
247 | { |
248 | 248 | ||
249 | u8 i; |
249 | u8 i; |
250 | WPIndex = 0; // set list position invalid |
250 | WPIndex = 0; // set list position invalid |
251 | POIIndex = 0; // set invalid |
251 | POIIndex = 0; // set invalid |
252 | 252 | ||
253 | if(WPActive == FALSE) return(NULL); |
253 | if(WPActive == FALSE) return(NULL); |
254 | 254 | ||
255 | if(PointCount > 0) |
255 | if(PointCount > 0) |
256 | { |
256 | { |
257 | // search backward! |
257 | // search backward! |
258 | for(i = 1; i <= MAX_LIST_LEN; i++) |
258 | for(i = 1; i <= MAX_LIST_LEN; i++) |
259 | { |
259 | { |
260 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
260 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
261 | { |
261 | { |
262 | WPIndex = MAX_LIST_LEN - i + 1; |
262 | WPIndex = MAX_LIST_LEN - i + 1; |
263 | break; |
263 | break; |
264 | } |
264 | } |
265 | } |
265 | } |
266 | if(WPIndex) // found a WP within the list |
266 | if(WPIndex) // found a WP within the list |
267 | { |
267 | { |
268 | NaviData.WaypointIndex = WPCount; |
268 | NaviData.WaypointIndex = WPCount; |
269 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
269 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
270 | else POIIndex = 0; |
270 | else POIIndex = 0; |
271 | } |
271 | } |
272 | else // list contains some points but no WP in the list |
272 | else // list contains some points but no WP in the list |
273 | { |
273 | { |
274 | // search backward for a POI! |
274 | // search backward for a POI! |
275 | for(i = 1; i <= MAX_LIST_LEN; i++) |
275 | for(i = 1; i <= MAX_LIST_LEN; i++) |
276 | { |
276 | { |
277 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
277 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
278 | { |
278 | { |
279 | POIIndex = MAX_LIST_LEN - i + 1; |
279 | POIIndex = MAX_LIST_LEN - i + 1; |
280 | break; |
280 | break; |
281 | } |
281 | } |
282 | } |
282 | } |
283 | NaviData.WaypointIndex = 0; |
283 | NaviData.WaypointIndex = 0; |
284 | } |
284 | } |
285 | } |
285 | } |
286 | else // no point in the list |
286 | else // no point in the list |
287 | { |
287 | { |
288 | POIIndex = 0; |
288 | POIIndex = 0; |
289 | NaviData.WaypointIndex = 0; |
289 | NaviData.WaypointIndex = 0; |
290 | } |
290 | } |
291 | if(WPIndex) return(&(PointList[WPIndex-1])); |
291 | if(WPIndex) return(&(PointList[WPIndex-1])); |
292 | else return(NULL); |
292 | else return(NULL); |
293 | } |
293 | } |
294 | 294 | ||
295 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
295 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
296 | Point_t* PointList_WPNext(void) |
296 | Point_t* PointList_WPNext(void) |
297 | { |
297 | { |
298 | u8 wp_found = 0; |
298 | u8 wp_found = 0; |
299 | if(WPActive == FALSE) return(NULL); |
299 | if(WPActive == FALSE) return(NULL); |
300 | 300 | ||
301 | if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list |
301 | if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list |
302 | { |
302 | { |
303 | u8 i; |
303 | u8 i; |
304 | for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry |
304 | for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry |
305 | { |
305 | { |
306 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
306 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
307 | { |
307 | { |
308 | wp_found = i+1; |
308 | wp_found = i+1; |
309 | break; |
309 | break; |
310 | } |
310 | } |
311 | } |
311 | } |
312 | } |
312 | } |
313 | if(wp_found) |
313 | if(wp_found) |
314 | { |
314 | { |
315 | WPIndex = wp_found; // update list position |
315 | WPIndex = wp_found; // update list position |
316 | NaviData.WaypointIndex++; |
316 | NaviData.WaypointIndex++; |
317 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
317 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
318 | else POIIndex = 0; |
318 | else POIIndex = 0; |
319 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
319 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
320 | } |
320 | } |
321 | else |
321 | else |
322 | { // no next wp found |
322 | { // no next wp found |
323 | NaviData.WaypointIndex = 0; |
323 | NaviData.WaypointIndex = 0; |
324 | POIIndex = 0; |
324 | POIIndex = 0; |
325 | return(NULL); |
325 | return(NULL); |
326 | } |
326 | } |
327 | } |
327 | } |
328 | 328 | ||
329 | void PointList_WPActive(u8 set) |
329 | void PointList_WPActive(u8 set) |
330 | { |
330 | { |
331 | if(set) |
331 | if(set) |
332 | { |
332 | { |
333 | WPActive = TRUE; |
333 | WPActive = TRUE; |
334 | PointList_WPBegin(); // uopdates POI index |
334 | PointList_WPBegin(); // uopdates POI index |
335 | } |
335 | } |
336 | else |
336 | else |
337 | { |
337 | { |
338 | WPActive = FALSE; |
338 | WPActive = FALSE; |
339 | POIIndex = 0; // disable POI also |
339 | POIIndex = 0; // disable POI also |
340 | } |
340 | } |
341 | } |
341 | } |
342 | 342 | ||
343 | Point_t* PointList_GetPOI(void) |
343 | Point_t* PointList_GetPOI(void) |
344 | { |
344 | { |
345 | return PointList_GetAt(POIIndex); |
345 | return PointList_GetAt(POIIndex); |
346 | } |
346 | } |
347 | 347 | ||
348 | 348 |