Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1734 | - | 1 | /* |
2 | * FollowMe.c |
||
3 | * |
||
4 | * Created on: 18.05.2012 |
||
5 | * Author: cebra |
||
6 | */ |
||
7 | /***************************************************************************** |
||
8 | * Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
||
9 | * * |
||
10 | * This program is free software; you can redistribute it and/or modify * |
||
11 | * it under the terms of the GNU General Public License as published by * |
||
12 | * the Free Software Foundation; either version 2 of the License. * |
||
13 | * * |
||
14 | * This program is distributed in the hope that it will be useful, * |
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
17 | * GNU General Public License for more details. * |
||
18 | * * |
||
19 | * You should have received a copy of the GNU General Public License * |
||
20 | * along with this program; if not, write to the * |
||
21 | * Free Software Foundation, Inc., * |
||
22 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
23 | * * |
||
24 | * * |
||
25 | * Credits to: * |
||
26 | * Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
||
27 | * http://www.mikrokopter.de * |
||
28 | * Gregor "killagreg" Stobrawa for his version of the MK code * |
||
29 | * Thomas Kaiser "thkais" for the original project. See * |
||
30 | * http://www.ft-fanpage.de/mikrokopter/ * |
||
31 | * http://forum.mikrokopter.de/topic-4061-1.html * |
||
32 | * Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
||
33 | * http://www.mylifesucks.de/oss/c-osd/ * |
||
34 | * Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
||
35 | *****************************************************************************/ |
||
36 | |||
37 | #include "cpu.h" |
||
38 | #include <avr/io.h> |
||
39 | #include <inttypes.h> |
||
40 | #include <stdlib.h> |
||
41 | #include <avr/pgmspace.h> |
||
42 | #include <util/delay.h> |
||
43 | |||
44 | #include "main.h" |
||
45 | #include "followme.h" |
||
46 | #include "osd.h" |
||
47 | #include "lcd.h" |
||
48 | #include "timer.h" |
||
49 | #include "usart.h" |
||
50 | #include "eeprom.h" |
||
51 | #include "messages.h" |
||
52 | #include "parameter.h" |
||
53 | #include "mk-data-structs.h" |
||
54 | |||
55 | #define COSD_WASFLYING 4 |
||
56 | #define TIMEOUT 200 // 2 sec |
||
57 | |||
58 | // global definitions and global vars |
||
59 | NaviData_t *naviData; |
||
60 | mk_param_struct_t *mk_param_struct; |
||
61 | //uint16_t old_hh = 0; |
||
62 | uint8_t Flags_ExtraConfig; |
||
63 | uint8_t Flags_GlobalConfig; |
||
64 | uint8_t Flags_GlobalConfig3; |
||
65 | unsigned char Element; |
||
66 | uint16_t heading_home; |
||
67 | |||
68 | // Hier Höhenanzeigefehler Korrigieren |
||
69 | #define AltimeterAdjust 1.5 |
||
70 | |||
71 | |||
72 | // Positionen der Anzeigeelemente im Bildschirm |
||
73 | #define OSD_ALTITUDE_CONTROL 1 |
||
74 | #define OSD_ALTITUDE 2 |
||
75 | #define OSD_BATTERY_LEVEL 3 |
||
76 | #define OSD_CAPACITY 4 |
||
77 | #define OSD_CARE_FREE 5 |
||
78 | #define OSD_COMPASS_DEGREE 6 |
||
79 | #define OSD_COMPASS_DIRECTION 7 |
||
80 | #define OSD_COMPASS_ROSE 8 |
||
81 | #define OSD_CURRENT 9 |
||
82 | #define OSD_FLYING_TIME 10 |
||
83 | #define OSD_GROUND_SPEED 11 |
||
84 | #define OSD_HOME_CIRCLE 12 |
||
85 | #define OSD_HOME_DEGREE 13 |
||
86 | #define OSD_HOME_DISTANCE 14 |
||
87 | #define OSD_LED1_OUTPUT 15 |
||
88 | #define OSD_LED2_OUTPUT 16 |
||
89 | #define OSD_MANUELL 17 |
||
90 | #define OSD_NAVI_MODE 18 |
||
91 | #define OSD_RC_INTENSITY 19 |
||
92 | #define OSD_SATS_IN_USE 20 |
||
93 | #define OSD_STATUS_FLAGS 21 |
||
94 | #define OSD_VARIOMETER 22 |
||
95 | |||
96 | // Flags |
||
97 | //uint8_t COSD_FLAGS2 = 0; |
||
98 | // |
||
99 | //GPS_Pos_t last5pos[7]; |
||
100 | uint8_t FM_error = 0; |
||
101 | |||
102 | //-------------------------------------------------------------- |
||
103 | void FollowMe (void) |
||
104 | { |
||
105 | uint8_t flag; |
||
106 | uint8_t tmp_dat; |
||
107 | // uint8_t OSD_Mode; |
||
108 | // uint8_t info_3D = 0; |
||
109 | uint8_t status; |
||
110 | |||
111 | // Clear statistics |
||
112 | // max_Altimeter = 0; |
||
113 | // max_GroundSpeed = 0; |
||
114 | // max_Distance = 0; |
||
115 | // min_UBat = 255; |
||
116 | // max_FlyingTime = 0; |
||
117 | |||
118 | // flags from last round to check for changes |
||
119 | uint8_t old_FCFlags = 0; |
||
120 | |||
121 | // uint8_t old_AngleNick = 0; |
||
122 | // uint8_t old_AngleRoll = 0; |
||
123 | lcd_cls(); |
||
124 | |||
125 | |||
126 | |||
127 | |||
128 | |||
129 | |||
130 | if (hardware == FC) |
||
131 | { |
||
132 | lcd_puts_at(0, 3, strGet(ONLY_NC), 0); // Nur mit NC |
||
133 | timer = 100; |
||
134 | while (timer > 0); |
||
135 | |||
136 | return; |
||
137 | } |
||
138 | |||
139 | SwitchToFC(); |
||
140 | |||
141 | status = load_setting(0xff); |
||
142 | if(status == 255) |
||
143 | { |
||
144 | lcd_puts_at(0, 0, strGet(NO_SETTINGS), 0); // Keine Setings |
||
145 | _delay_ms(2000); |
||
146 | } |
||
147 | Flags_ExtraConfig = mk_param_struct->ExtraConfig; |
||
148 | Flags_GlobalConfig = mk_param_struct->GlobalConfig; |
||
149 | Flags_GlobalConfig3 = mk_param_struct->GlobalConfig3; |
||
150 | |||
151 | SwitchToNC(); |
||
152 | |||
153 | mode = 'O'; |
||
154 | |||
155 | // disable debug... |
||
156 | // RS232_request_mk_data (0, 'd', 0); |
||
157 | tmp_dat = 0; |
||
158 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
159 | |||
160 | // request OSD Data from NC every 100ms |
||
161 | // RS232_request_mk_data (1, 'o', 100); |
||
162 | tmp_dat = 10; |
||
163 | // OSD_active = true; // benötigt für Navidata Ausgabe an SV2 |
||
164 | SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
165 | |||
166 | flag = 0; |
||
167 | timer = TIMEOUT; |
||
168 | abo_timer = ABO_TIMEOUT; |
||
169 | |||
170 | do |
||
171 | { |
||
172 | if (rxd_buffer_locked) |
||
173 | { |
||
174 | timer = TIMEOUT; |
||
175 | Decode64 (); |
||
176 | naviData = (NaviData_t *) pRxData; |
||
177 | |||
178 | if(FM_error == 1) |
||
179 | lcd_cls(); |
||
180 | |||
181 | FM_error = 0; |
||
182 | GPS_Pos_t currpos; |
||
183 | currpos.Latitude = naviData->CurrentPosition.Latitude; |
||
184 | currpos.Longitude = naviData->CurrentPosition.Longitude; |
||
185 | |||
186 | |||
187 | flag = 1; |
||
188 | |||
189 | |||
190 | { |
||
191 | |||
192 | |||
193 | // Altitude Control |
||
194 | OSD_Screen_Element (0, 3, OSD_ALTITUDE_CONTROL); |
||
195 | // |
||
196 | // // Altitude |
||
197 | // OSD_Screen_Element (11, 3, OSD_ALTITUDE); |
||
198 | |||
199 | // Battery level |
||
200 | OSD_Screen_Element (0, 7, OSD_BATTERY_LEVEL); |
||
201 | |||
202 | // Capacity |
||
203 | OSD_Screen_Element (13, 7, OSD_CAPACITY); |
||
204 | |||
205 | // Care Free |
||
206 | OSD_Screen_Element (12, 2, OSD_CARE_FREE); |
||
207 | |||
208 | // // Compass Degree |
||
209 | // OSD_Screen_Element (13, 0, OSD_COMPASS_DEGREE); |
||
210 | // |
||
211 | // // Compass Direction |
||
212 | // OSD_Screen_Element (18, 0, OSD_COMPASS_DIRECTION); |
||
213 | // |
||
214 | // // Compass Rose |
||
215 | // OSD_Screen_Element (12, 1, OSD_COMPASS_ROSE); |
||
216 | |||
217 | // Current |
||
218 | OSD_Screen_Element (7, 7, OSD_CURRENT); |
||
219 | |||
220 | // Flying time |
||
221 | lcd_printp_at (0, 1, PSTR("Flytime:"), 0); |
||
222 | OSD_Screen_Element (8, 1, OSD_FLYING_TIME); |
||
223 | |||
224 | // Ground Speed |
||
225 | lcd_printp_at (0, 0, PSTR("Speed:"), 0); |
||
226 | OSD_Screen_Element (6, 0, OSD_GROUND_SPEED); |
||
227 | // Sats in use |
||
228 | OSD_Screen_Element (16, 0, OSD_SATS_IN_USE); |
||
229 | |||
230 | // // Home Circle |
||
231 | // OSD_Screen_Element (16, 4, OSD_HOME_CIRCLE); |
||
232 | // |
||
233 | // // Home Degree |
||
234 | // OSD_Screen_Element (12, 4, OSD_HOME_DEGREE); |
||
235 | |||
236 | // Home Distance |
||
237 | lcd_printp_at (11, 3, PSTR("Dist:"), 0); |
||
238 | OSD_Screen_Element (17, 3, OSD_HOME_DISTANCE); |
||
239 | // |
||
240 | // // LED1 Output |
||
241 | // OSD_Screen_Element (0, 6, OSD_LED1_OUTPUT); |
||
242 | // |
||
243 | // // LED2 Output |
||
244 | // OSD_Screen_Element (5, 6, OSD_LED2_OUTPUT); |
||
245 | |||
246 | // Manuell |
||
247 | // OSD_Screen_Element (7, 0, OSD_MANUELL); |
||
248 | |||
249 | // Navi Mode |
||
250 | OSD_Screen_Element (0, 2, OSD_NAVI_MODE); |
||
251 | |||
252 | // RC Intensity |
||
253 | // OSD_Screen_Element (11, 6, OSD_RC_INTENSITY); |
||
254 | |||
255 | |||
256 | // Status Flags |
||
257 | // OSD_Screen_Element (0, 2, OSD_STATUS_FLAGS); |
||
258 | |||
259 | // // Variometer |
||
260 | // OSD_Screen_Element (9, 0, OSD_VARIOMETER); |
||
261 | |||
262 | lcd_printp_at (0, 4, PSTR("MK:"), 0); |
||
263 | write_ndigit_number_u (3, 4, (uint16_t)(currpos.Latitude/10000000), 2, 0,0); |
||
264 | lcd_printp_at (5, 4, PSTR("."), 0); |
||
265 | write_ndigit_number_u (6, 4, (uint16_t)((currpos.Latitude/1000) % 10000), 4, 1,0); |
||
266 | write_ndigit_number_u (10, 4, (uint16_t)((currpos.Latitude/10) % 100), 2, 1,0); |
||
267 | |||
268 | |||
269 | write_ndigit_number_u (12, 4, (uint16_t)(currpos.Longitude/10000000), 2, 0,0); |
||
270 | lcd_printp_at (14, 4, PSTR("."), 0); |
||
271 | write_ndigit_number_u (15, 4, (uint16_t)((currpos.Longitude/1000) % 10000), 4, 1,0); |
||
272 | write_ndigit_number_u (19, 4, (uint16_t)((currpos.Longitude/10) % 100), 2, 1,0); |
||
273 | |||
274 | lcd_printp_at (0, 5, PSTR("!!!not implemented!!!"), 2); |
||
275 | |||
276 | // Akku Warnung |
||
277 | if (naviData->UBat < MK_LowBat) |
||
278 | { //Beeper ein |
||
279 | set_beep ( 3000, 0x0020, BeepNormal); |
||
280 | } |
||
281 | if (naviData->UBat > MK_LowBat) //bei kurzzeitigen Schwankungen Beeper erst wieder aus wenn UBat 0,2 V höher als Warnschwelle |
||
282 | { //Beeper aus |
||
283 | set_beep ( 0, 0, BeepOff); |
||
284 | } |
||
285 | // Akku Warnung Ende |
||
286 | |||
287 | old_FCFlags = naviData->FCStatusFlags; |
||
288 | |||
289 | rxd_buffer_locked = FALSE; |
||
290 | } |
||
291 | |||
292 | |||
293 | if (!abo_timer) |
||
294 | { // renew abo every 3 sec |
||
295 | // request OSD Data from NC every 100ms |
||
296 | // RS232_request_mk_data (1, 'o', 100); |
||
297 | tmp_dat = 10; |
||
298 | SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
299 | |||
300 | abo_timer = ABO_TIMEOUT; |
||
301 | } |
||
302 | } |
||
303 | if (!timer) |
||
304 | { |
||
305 | OSD_Timeout(flag); |
||
306 | flag = 0; |
||
307 | FM_error = 1; |
||
308 | } |
||
309 | } |
||
310 | |||
311 | while (!get_key_press (1 << KEY_ESC)); |
||
312 | OSD_active = false; |
||
313 | |||
314 | } |
||
315 | |||
316 | |||
317 | |||
318 |