Rev 280 | Rev 286 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 280 | Rev 283 | ||
---|---|---|---|
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 31 |
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 | 72 | ||
72 | u8 WPActive = TRUE; |
73 | u8 WPActive = TRUE; |
73 | 74 | ||
74 | u8 PointList_Init(void) |
75 | u8 PointList_Init(void) |
75 | { |
76 | { |
76 | return PointList_Clear(); |
77 | return PointList_Clear(); |
77 | } |
78 | } |
78 | 79 | ||
79 | u8 PointList_Clear(void) |
80 | u8 PointList_Clear(void) |
80 | { |
81 | { |
81 | u8 i; |
82 | u8 i; |
82 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
83 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
83 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
84 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
84 | WPCount = 0; // no waypoints |
85 | WPCount = 0; // no waypoints |
- | 86 | POICount = 0; |
|
85 | PointCount = 0; // no contents |
87 | PointCount = 0; // no contents |
86 | WPActive = TRUE; |
88 | WPActive = TRUE; |
87 | NaviData.WaypointNumber = WPCount; |
89 | NaviData.WaypointNumber = WPCount; |
88 | NaviData.WaypointIndex = 0; |
90 | NaviData.WaypointIndex = 0; |
89 | 91 | ||
90 | for(i = 0; i < MAX_LIST_LEN; i++) |
92 | for(i = 0; i < MAX_LIST_LEN; i++) |
91 | { |
93 | { |
92 | PointList[i].Position.Status = INVALID; |
94 | PointList[i].Position.Status = INVALID; |
93 | PointList[i].Position.Latitude = 0; |
95 | PointList[i].Position.Latitude = 0; |
94 | PointList[i].Position.Longitude = 0; |
96 | PointList[i].Position.Longitude = 0; |
95 | PointList[i].Position.Altitude = 0; |
97 | PointList[i].Position.Altitude = 0; |
96 | PointList[i].Heading = 361; // invalid value |
98 | PointList[i].Heading = 361; // invalid value |
97 | 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 |
98 | 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 |
99 | PointList[i].Event_Flag = 0; // future implementation |
101 | PointList[i].Event_Flag = 0; // future implementation |
100 | PointList[i].Type = POINT_TYPE_INVALID; |
102 | PointList[i].Type = POINT_TYPE_INVALID; |
101 | } |
103 | } |
102 | return TRUE; |
104 | return TRUE; |
103 | } |
105 | } |
104 | 106 | ||
105 | u8 PointList_GetCount(void) |
107 | u8 PointList_GetCount(void) |
106 | { |
108 | { |
107 | return PointCount; // number of points in the list |
109 | return PointCount; // number of points in the list |
108 | } |
110 | } |
109 | 111 | ||
110 | u8 PointList_Append(Point_t* pPoint) |
112 | u8 PointList_Append(Point_t* pPoint) |
111 | { |
113 | { |
112 | if((PointCount < MAX_LIST_LEN) && (pPoint->Index == (PointCount + 1)) ) // there is still some space in the list and index points to next |
114 | if((PointCount < MAX_LIST_LEN) && (pPoint->Index == (PointCount + 1)) ) // there is still some space in the list and index points to next |
113 | { |
115 | { |
114 | memcpy(&PointList[PointCount], pPoint, sizeof(Point_t)); // copy data to list entry // increment list length |
116 | memcpy(&PointList[PointCount], pPoint, sizeof(Point_t)); // copy data to list entry // increment list length |
115 | if(PointList[PointCount].Type == POINT_TYPE_WP) WPCount++; |
117 | if(PointList[PointCount].Type == POINT_TYPE_WP) WPCount++; |
- | 118 | if(PointList[PointCount].Type == POINT_TYPE_POI) POICount++; |
|
116 | NaviData.WaypointNumber = WPCount; |
119 | NaviData.WaypointNumber = WPCount; |
117 | PointCount++; |
120 | PointCount++; |
118 | if(PointCount == 1) // only for the first entry |
121 | if(PointCount == 1) // only for the first entry |
119 | { |
122 | { |
120 | // update POI index |
123 | // update POI index |
121 | switch(PointList[WPIndex-1].Type) |
124 | switch(PointList[WPIndex-1].Type) |
122 | { |
125 | { |
123 | case POINT_TYPE_WP: |
126 | case POINT_TYPE_WP: |
124 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
127 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
125 | else POIIndex = 0; |
128 | else POIIndex = 0; |
126 | break; |
129 | break; |
127 | 130 | ||
128 | case POINT_TYPE_POI: |
131 | case POINT_TYPE_POI: |
129 | POIIndex = 1; |
132 | POIIndex = 1; |
- | 133 | POICount = 1; |
|
130 | break; |
134 | break; |
131 | 135 | ||
132 | default: |
136 | default: |
133 | POIIndex = 0; |
137 | POIIndex = 0; |
134 | break; |
138 | break; |
135 | } |
139 | } |
136 | } |
140 | } |
137 | return TRUE; |
141 | return TRUE; |
138 | } |
142 | } |
139 | else return FALSE; |
143 | else return FALSE; |
140 | } |
144 | } |
141 | 145 | ||
142 | // returns the pointer to the first waypoint within the list |
146 | // returns the pointer to the first waypoint within the list |
143 | Point_t* PointList_WPBegin(void) |
147 | Point_t* PointList_WPBegin(void) |
144 | { |
148 | { |
145 | u8 i; |
149 | u8 i; |
146 | WPIndex = 0; // set list position invalid |
150 | WPIndex = 0; // set list position invalid |
147 | POIIndex = 0; // set invalid POI |
- | |
148 | - | ||
149 | if(WPActive == FALSE) return(NULL); |
151 | if(WPActive == FALSE) return(NULL); |
150 | - | ||
- | 152 | POIIndex = 0; // set invalid POI |
|
151 | if(PointCount > 0) |
153 | if(PointCount > 0) |
152 | { |
154 | { |
153 | // search for first wp in list |
155 | // search for first wp in list |
154 | for(i = 0; i <PointCount; i++) |
156 | for(i = 0; i <PointCount; i++) |
155 | { |
157 | { |
156 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
158 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
157 | { |
159 | { |
158 | WPIndex = i + 1; |
160 | WPIndex = i + 1; |
159 | break; |
161 | break; |
160 | } |
162 | } |
161 | } |
163 | } |
162 | if(WPIndex) // found a WP in the list |
164 | if(WPIndex) // found a WP in the list |
163 | { |
165 | { |
164 | NaviData.WaypointIndex = 1; |
166 | NaviData.WaypointIndex = 1; |
165 | // update index to POI |
167 | // update index to POI |
166 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
168 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
167 | else POIIndex = 0; |
169 | else POIIndex = 0; |
168 | return(&(PointList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list |
170 | return(&(PointList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list |
169 | } |
171 | } |
170 | else // some points in the list but no WP found |
172 | else // some points in the list but no WP found |
171 | { |
173 | { |
172 | NaviData.WaypointIndex = 0; |
174 | NaviData.WaypointIndex = 0; |
173 | //Check for an existing POI |
175 | //Check for an existing POI |
174 | for(i = 0; i < PointCount; i++) |
176 | for(i = 0; i < PointCount; i++) |
175 | { |
177 | { |
176 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
178 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
177 | { |
179 | { |
178 | POIIndex = i + 1; |
180 | POIIndex = i + 1; |
179 | break; |
181 | break; |
180 | } |
182 | } |
181 | } |
183 | } |
182 | return NULL; |
184 | return NULL; |
183 | } |
185 | } |
184 | } |
186 | } |
185 | else // no point in the list |
187 | else // no point in the list |
186 | { |
188 | { |
187 | POIIndex = 0; |
189 | POIIndex = 0; |
188 | NaviData.WaypointIndex = 0; |
190 | NaviData.WaypointIndex = 0; |
189 | return NULL; |
191 | return NULL; |
190 | } |
192 | } |
191 | } |
193 | } |
192 | 194 | ||
193 | // returns the last waypoint |
195 | // returns the last waypoint |
194 | Point_t* PointList_WPEnd(void) |
196 | Point_t* PointList_WPEnd(void) |
195 | { |
197 | { |
196 | 198 | ||
197 | u8 i; |
199 | u8 i; |
198 | WPIndex = 0; // set list position invalid |
200 | WPIndex = 0; // set list position invalid |
199 | POIIndex = 0; // set invalid |
201 | POIIndex = 0; // set invalid |
- | 202 | ||
200 | if(WPActive == FALSE) return(NULL); |
203 | if(WPActive == FALSE) return(NULL); |
201 | 204 | ||
202 | if(PointCount > 0) |
205 | if(PointCount > 0) |
203 | { |
206 | { |
204 | // search backward! |
207 | // search backward! |
205 | for(i = 1; i <= PointCount; i++) |
208 | for(i = 1; i <= PointCount; i++) |
206 | { |
209 | { |
207 | if((PointList[PointCount - i].Type == POINT_TYPE_WP) && (PointList[PointCount - i].Position.Status != INVALID)) |
210 | if((PointList[PointCount - i].Type == POINT_TYPE_WP) && (PointList[PointCount - i].Position.Status != INVALID)) |
208 | { |
211 | { |
209 | WPIndex = PointCount - i + 1; |
212 | WPIndex = PointCount - i + 1; |
210 | break; |
213 | break; |
211 | } |
214 | } |
212 | } |
215 | } |
213 | if(WPIndex) // found a WP within the list |
216 | if(WPIndex) // found a WP within the list |
214 | { |
217 | { |
215 | NaviData.WaypointIndex = WPCount; |
218 | NaviData.WaypointIndex = WPCount; |
216 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
219 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
217 | else POIIndex = 0; |
220 | else POIIndex = 0; |
218 | return(&(PointList[WPIndex-1])); |
221 | return(&(PointList[WPIndex-1])); |
219 | } |
222 | } |
220 | else // list contains some points but no WP in the list |
223 | else // list contains some points but no WP in the list |
221 | { |
224 | { |
222 | // search backward for a POI! |
225 | // search backward for a POI! |
223 | for(i = 1; i <= PointCount; i++) |
226 | for(i = 1; i <= PointCount; i++) |
224 | { |
227 | { |
225 | if((PointList[PointCount - i].Type == POINT_TYPE_POI) && (PointList[PointCount - i].Position.Status != INVALID)) |
228 | if((PointList[PointCount - i].Type == POINT_TYPE_POI) && (PointList[PointCount - i].Position.Status != INVALID)) |
226 | { |
229 | { |
227 | POIIndex = PointCount - i + 1; |
230 | POIIndex = PointCount - i + 1; |
228 | break; |
231 | break; |
229 | } |
232 | } |
230 | } |
233 | } |
231 | NaviData.WaypointIndex = 0; |
234 | NaviData.WaypointIndex = 0; |
232 | return NULL; |
235 | return NULL; |
233 | } |
236 | } |
234 | } |
237 | } |
235 | else // no point in the list |
238 | else // no point in the list |
236 | { |
239 | { |
237 | POIIndex = 0; |
240 | POIIndex = 0; |
238 | NaviData.WaypointIndex = 0; |
241 | NaviData.WaypointIndex = 0; |
239 | return NULL; |
242 | return NULL; |
240 | } |
243 | } |
241 | } |
244 | } |
242 | 245 | ||
243 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
246 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
244 | Point_t* PointList_WPNext(void) |
247 | Point_t* PointList_WPNext(void) |
245 | { |
248 | { |
246 | u8 wp_found = 0; |
249 | u8 wp_found = 0; |
247 | if(WPActive == FALSE) return(NULL); |
250 | if(WPActive == FALSE) return(NULL); |
248 | 251 | ||
249 | if(WPIndex < PointCount) // if there is a next entry in the list |
252 | if(WPIndex < PointCount) // if there is a next entry in the list |
250 | { |
253 | { |
251 | u8 i; |
254 | u8 i; |
252 | for(i = WPIndex; i < PointCount; i++) // start search for next at next list entry |
255 | for(i = WPIndex; i < PointCount; i++) // start search for next at next list entry |
253 | { |
256 | { |
254 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
257 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
255 | { |
258 | { |
256 | wp_found = i+1; |
259 | wp_found = i+1; |
257 | break; |
260 | break; |
258 | } |
261 | } |
259 | } |
262 | } |
260 | } |
263 | } |
261 | if(wp_found) |
264 | if(wp_found) |
262 | { |
265 | { |
263 | WPIndex = wp_found; // update list position |
266 | WPIndex = wp_found; // update list position |
264 | NaviData.WaypointIndex++; |
267 | NaviData.WaypointIndex++; |
265 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
268 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
266 | else POIIndex = 0; |
269 | else POIIndex = 0; |
267 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
270 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
268 | } |
271 | } |
269 | else |
272 | else |
270 | { // no next wp found |
273 | { // no next wp found |
271 | NaviData.WaypointIndex = 0; |
274 | NaviData.WaypointIndex = 0; |
272 | POIIndex = 0; |
275 | POIIndex = 0; |
273 | return(NULL); |
276 | return(NULL); |
274 | } |
277 | } |
275 | } |
278 | } |
276 | 279 | ||
277 | void PointList_WPActive(u8 set) |
280 | void PointList_WPActive(u8 set) |
278 | { |
281 | { |
279 | if(set) WPActive = TRUE; |
282 | if(set) WPActive = TRUE; |
280 | else WPActive = FALSE; |
283 | else WPActive = FALSE; |
281 | } |
284 | } |
282 | 285 | ||
283 | Point_t* PointList_GetAt(u8 index) |
286 | Point_t* PointList_GetAt(u8 index) |
284 | { |
287 | { |
285 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
288 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
286 | else return(NULL); |
289 | else return(NULL); |
287 | } |
290 | } |
288 | 291 | ||
289 | Point_t* PointList_GetPOI(void) |
292 | Point_t* PointList_GetPOI(void) |
290 | { |
293 | { |
291 | return PointList_GetAt(POIIndex); |
294 | return PointList_GetAt(POIIndex); |
292 | } |
295 | } |
293 | 296 | ||
294 | 297 |