Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1159 | - | 1 | /***************************************************************************** |
2 | * Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
||
3 | * based on the C-OSD code from CaScAdE * |
||
4 | * http://www.mylifesucks.de/oss/c-osd/ * |
||
5 | * * |
||
6 | * This program is free software; you can redistribute it and/or modify * |
||
7 | * it under the terms of the GNU General Public License as published by * |
||
8 | * the Free Software Foundation; either version 2 of the License. * |
||
9 | * * |
||
10 | * This program is distributed in the hope that it will be useful, * |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
13 | * GNU General Public License for more details. * |
||
14 | * * |
||
15 | * You should have received a copy of the GNU General Public License * |
||
16 | * along with this program; if not, write to the * |
||
17 | * Free Software Foundation, Inc., * |
||
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
19 | * * |
||
20 | *****************************************************************************/ |
||
21 | |||
22 | #include <avr/io.h> |
||
23 | #include <inttypes.h> |
||
24 | #include <stdlib.h> |
||
25 | #include <avr/pgmspace.h> |
||
26 | |||
27 | #include "main.h" |
||
28 | #include "osd.h" |
||
29 | #include "lcd.h" |
||
30 | #include "timer.h" |
||
31 | #include "usart.h" |
||
32 | #include "eeprom.h" |
||
33 | |||
34 | #include "mk-data-structs.h" |
||
35 | |||
36 | #define COSD_WASFLYING 4 |
||
37 | |||
38 | /* ########################################################################## |
||
39 | * global definitions and global vars |
||
40 | * ##########################################################################*/ |
||
41 | NaviData_t *naviData; |
||
42 | |||
43 | // stats for after flight |
||
44 | int16_t max_Altimeter = 0; |
||
45 | uint16_t max_GroundSpeed = 0; |
||
46 | int16_t max_Distance = 0; |
||
47 | uint8_t min_UBat = 255; |
||
48 | uint16_t max_FlyingTime = 0; |
||
49 | uint16_t max_Current = 0; |
||
50 | uint16_t max_Capacity = 0; |
||
51 | |||
52 | // cache old vars for blinking attribute, checkup is faster than full |
||
53 | // attribute write each time |
||
54 | volatile uint8_t last_UBat = 255; |
||
55 | volatile uint8_t last_RC_Quality = 255; |
||
56 | |||
57 | volatile uint16_t ftimer = 0; |
||
58 | |||
59 | // store stats description in progmem to save space |
||
60 | const char stats_item_0[] PROGMEM = "max Altitude:"; |
||
61 | const char stats_item_1[] PROGMEM = "max Speed :"; |
||
62 | const char stats_item_2[] PROGMEM = "max Distance:"; |
||
63 | const char stats_item_3[] PROGMEM = "min Voltage :"; |
||
64 | const char stats_item_4[] PROGMEM = "max Time :"; |
||
65 | #if 1 |
||
66 | const char stats_item_5[] PROGMEM = "max Current :"; |
||
67 | const char stats_item_6[] PROGMEM = "UsedCapacity:"; |
||
68 | #else |
||
69 | const char stats_item_5[] PROGMEM = "Long. :"; |
||
70 | const char stats_item_6[] PROGMEM = "Lat. :"; |
||
71 | #endif |
||
72 | const char *stats_item_pointers[] PROGMEM = { |
||
73 | stats_item_0, |
||
74 | stats_item_1, |
||
75 | stats_item_2, |
||
76 | stats_item_3, |
||
77 | stats_item_4, |
||
78 | stats_item_5, |
||
79 | stats_item_6 |
||
80 | }; |
||
81 | |||
82 | //char* rose = "-+-N-+-O-+-S-+-W-+-N-+-O-+-S-+-W-+-N-+-O-+-S-+-W"; |
||
83 | const char rose[48] PROGMEM = { |
||
84 | 0x0e, 0x0f, 0x0e, 'N', 0x0e, 0x0f, 0x0e, 'O', 0x0e, 0x0f, 0x0e, 'S', |
||
85 | 0x0e, 0x0f, 0x0e, 'W', 0x0e, 0x0f, 0x0e, 'N', 0x0e, 0x0f, 0x0e, 'O', |
||
86 | 0x0e, 0x0f, 0x0e, 'S', 0x0e, 0x0f, 0x0e, 'W', 0x0e, 0x0f, 0x0e, 'N', |
||
87 | 0x0e, 0x0f, 0x0e, 'O', 0x0e, 0x0f, 0x0e, 'S', 0x0e, 0x0f, 0x0e, 'W'}; |
||
88 | // the center is char 19 (north), we add the current heading in 8th |
||
89 | // which would be 22.5 degrees, but float would bloat up the code |
||
90 | // and *10 / 225 would take ages... so we take the uncorrect way |
||
91 | |||
92 | |||
93 | const char str_NE[] PROGMEM = "NE"; |
||
94 | const char str_E[] PROGMEM = "E "; |
||
95 | const char str_SE[] PROGMEM = "SE"; |
||
96 | const char str_S[] PROGMEM = "S "; |
||
97 | const char str_SW[] PROGMEM = "SW"; |
||
98 | const char str_W[] PROGMEM = "W "; |
||
99 | const char str_NW[] PROGMEM = "NW"; |
||
100 | const char str_N[] PROGMEM = "N "; |
||
101 | const char *directions_p[8] PROGMEM = { |
||
102 | str_NE, |
||
103 | str_E, |
||
104 | str_SE, |
||
105 | str_S, |
||
106 | str_SW, |
||
107 | str_W, |
||
108 | str_NW, |
||
109 | str_N |
||
110 | }; |
||
111 | |||
112 | // Flags |
||
113 | uint8_t COSD_FLAGS2 = 0; |
||
114 | |||
115 | |||
116 | |||
117 | GPS_Pos_t last5pos[7]; |
||
118 | uint8_t error = 0; |
||
119 | |||
120 | |||
121 | /** |
||
122 | * convert the <heading> gotton from NC into an index |
||
123 | */ |
||
124 | uint8_t heading_conv (uint16_t heading) |
||
125 | { |
||
126 | if (heading > 23 && heading < 68) |
||
127 | { |
||
128 | return 0; //direction = "NE"; |
||
129 | } |
||
130 | else if (heading > 67 && heading < 113) |
||
131 | { |
||
132 | return 1; //direction = "E "; |
||
133 | } |
||
134 | else if (heading > 112 && heading < 158) |
||
135 | { |
||
136 | return 2; //direction = "SE"; |
||
137 | } |
||
138 | else if (heading > 157 && heading < 203) |
||
139 | { |
||
140 | return 3; //direction = "S "; |
||
141 | } |
||
142 | else if (heading > 202 && heading < 248) |
||
143 | { |
||
144 | return 4; //direction = "SW"; |
||
145 | } |
||
146 | else if (heading > 247 && heading < 293) |
||
147 | { |
||
148 | return 5; //direction = "W "; |
||
149 | } |
||
150 | else if (heading > 292 && heading < 338) |
||
151 | { |
||
152 | return 6; //direction = "NW"; |
||
153 | } |
||
154 | return 7; //direction = "N "; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * draw a compass rose at <x>/<y> for <heading> |
||
159 | */ |
||
160 | void draw_compass (uint8_t x, uint8_t y, uint16_t heading) |
||
161 | { |
||
162 | uint8_t front = 19 + (heading / 22); |
||
163 | for (uint8_t i = 0; i < 9; i++) |
||
164 | { |
||
165 | lcd_putc (x++, y, pgm_read_byte(&rose[front - 4 + i]), 0); |
||
166 | } |
||
167 | } |
||
168 | |||
169 | void D_Position(void) |
||
170 | { |
||
171 | return; |
||
172 | |||
173 | } |
||
174 | |||
175 | |||
176 | |||
177 | /* ########################################################################## |
||
178 | * variometer |
||
179 | * ##########################################################################*/ |
||
180 | /** |
||
181 | * draw variometer arrows at <x>/<y> according to <variometer> |
||
182 | */ |
||
183 | void draw_variometer (uint8_t x, uint8_t y, uint8_t width_x, uint8_t width_y, int16_t variometer) |
||
184 | { |
||
185 | lcd_rect (x, y - ((width_y - 1) / 2), width_x, width_y, 1); |
||
186 | lcd_frect (x + 1, y - ((width_y - 1) / 2) + 1, width_x - 2, width_y - 2, 0); |
||
187 | lcd_line (x, y, x + width_x, y, 1); |
||
188 | |||
189 | if (variometer > 0) |
||
190 | { // gain height |
||
191 | switch (variometer / 5) |
||
192 | { |
||
193 | case 0: |
||
194 | lcd_frect (x + 3, y - 1, 3, 1, 1); |
||
195 | break; |
||
196 | case 1: |
||
197 | lcd_frect (x + 2, y - 3, 5, 3, 1); |
||
198 | break; |
||
199 | case 2: |
||
200 | lcd_frect (x + 2, y - 4, 5, 4, 1); |
||
201 | break; |
||
202 | default: |
||
203 | lcd_frect (x + 1, y - 5, 7, 5, 1); |
||
204 | break; |
||
205 | } |
||
206 | } |
||
207 | else |
||
208 | { // sink |
||
209 | switch (variometer / -5) |
||
210 | { |
||
211 | case 0: |
||
212 | lcd_frect (x + 3, y, 3, 1, 1); |
||
213 | break; |
||
214 | case 1: |
||
215 | lcd_frect (x + 2, y, 5, 3, 1); |
||
216 | break; |
||
217 | case 2: |
||
218 | lcd_frect (x + 2, y, 5, 4, 1); |
||
219 | break; |
||
220 | default: |
||
221 | lcd_frect (x + 1, y, 7, 5, 1); |
||
222 | break; |
||
223 | } |
||
224 | } |
||
225 | } |
||
226 | |||
227 | |||
228 | #define TIMEOUT 200 // 2 sec |
||
229 | |||
230 | void print_statistics (void) |
||
231 | { |
||
232 | uint8_t line = 0; |
||
233 | lcd_cls (); |
||
234 | |||
235 | // max Altitude |
||
236 | lcd_printpns_at (0, line, stats_item_pointers[0], 0); |
||
237 | write_ndigit_number_s (13, line, max_Altimeter / 30, 4, 0); |
||
238 | lcd_putc (17, line, 'm', 0); |
||
239 | |||
240 | // max Speed |
||
241 | lcd_printpns_at (0, ++line, stats_item_pointers[1], 0); |
||
242 | write_ndigit_number_u (14, line, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0); |
||
243 | lcd_printpns_at(17, line, PSTR("km/h"), 0); |
||
244 | |||
245 | // max Distance |
||
246 | lcd_printpns_at (0, ++line, stats_item_pointers[2], 0); |
||
247 | write_ndigit_number_u (14, line, max_Distance / 10, 3, 0); |
||
248 | lcd_putc (17, line, 'm', 0); |
||
249 | |||
250 | // max time |
||
251 | lcd_printpns_at (0, ++line, stats_item_pointers[4], 0); |
||
252 | write_time (13, line, max_FlyingTime); |
||
253 | |||
254 | // min voltage |
||
255 | lcd_printpns_at (0, ++line, stats_item_pointers[3], 0); |
||
256 | write_ndigit_number_u_10th (13, line, min_UBat, 3, 0); |
||
257 | lcd_putc (17, line, 'V', 0); |
||
258 | |||
259 | #if 1 |
||
260 | // max Current |
||
261 | lcd_printpns_at (0, ++line, stats_item_pointers[5], 0); |
||
262 | write_ndigit_number_u_10th (13, line, max_Current, 3, 0); |
||
263 | lcd_putc (17, line, 'A', 0); |
||
264 | |||
265 | // Used Capacity |
||
266 | lcd_printpns_at (0, ++line, stats_item_pointers[6], 0); |
||
267 | write_ndigit_number_u (13, line, max_Capacity, 4, 0); |
||
268 | lcd_printpns_at(17, line, PSTR("mAh"), 0); |
||
269 | #else |
||
270 | // longitude |
||
271 | lcd_printpns_at (0, ++line, stats_item_pointers[5], 0); |
||
272 | write_gps_pos (8, line, naviData->CurrentPosition.Longitude); |
||
273 | |||
274 | // latitude |
||
275 | lcd_printpns_at (0, ++line, stats_item_pointers[6], 0); |
||
276 | write_gps_pos (8, line, naviData->CurrentPosition.Latitude); |
||
277 | #endif |
||
278 | while (!get_key_press (1 << KEY_ESC)) |
||
279 | timer = TIMEOUT; |
||
280 | COSD_FLAGS2 &= ~COSD_WASFLYING; |
||
281 | get_key_press(KEY_ALL); |
||
282 | lcd_cls(); |
||
283 | } |
||
284 | |||
285 | void print_position (void) |
||
286 | { |
||
287 | lcd_cls (); |
||
288 | |||
289 | |||
290 | uint8_t ij =0; |
||
291 | |||
292 | for(ij=0;ij<7;ij++) |
||
293 | { |
||
294 | |||
295 | uint32_t lon = last5pos[ij].Longitude; |
||
296 | write_ndigit_number_u (0, ij+1, (uint16_t)(lon/10000000), 3, 0); |
||
297 | lcd_printp_at (3,ij+1, PSTR("."), 0); |
||
298 | write_ndigit_number_u (4, ij+1, (uint16_t)((lon/1000) % 10000), 4, 1); |
||
299 | write_ndigit_number_u (8, ij+1, (uint16_t)((lon/10) % 100), 2, 1); |
||
300 | |||
301 | uint32_t lat = last5pos[ij].Latitude; |
||
302 | write_ndigit_number_u (10, ij+1, (uint16_t)(lat/10000000), 3, 0); |
||
303 | lcd_printp_at (13,ij+1, PSTR("."), 0); |
||
304 | write_ndigit_number_u (14, ij+1, (uint16_t)((lat/1000) % 10000), 4, 1); |
||
305 | write_ndigit_number_u (18, ij+1, (uint16_t)((lat/10) % 100), 2, 1); |
||
306 | } |
||
307 | |||
308 | |||
309 | |||
310 | while (!get_key_press (1 << KEY_MINUS) && !get_key_press (1 << KEY_ESC) && !get_key_press (1 << KEY_ENTER)) |
||
311 | timer = TIMEOUT; |
||
312 | get_key_press(KEY_ALL); |
||
313 | lcd_cls(); |
||
314 | } |
||
315 | |||
316 | void osd (uint8_t ShowMode) |
||
317 | { |
||
318 | uint8_t flag; |
||
319 | uint8_t tmp_dat; |
||
320 | uint8_t OSD_Mode; |
||
321 | |||
322 | // Clear statistics |
||
323 | max_Altimeter = 0; |
||
324 | max_GroundSpeed = 0; |
||
325 | max_Distance = 0; |
||
326 | min_UBat = 255; |
||
327 | max_FlyingTime = 0; |
||
328 | |||
329 | // flags from last round to check for changes |
||
330 | uint8_t old_FCFlags = 0; |
||
331 | |||
332 | uint16_t old_hh = 0; |
||
333 | uint8_t old_AngleNick = 0; |
||
334 | uint8_t old_AngleRoll = 0; |
||
335 | |||
336 | OSD_Mode = ShowMode; |
||
337 | if(error == 0) lcd_cls(); |
||
338 | if(error == 1) lcd_printp_at (0, 0, PSTR(" "), 0); |
||
339 | |||
340 | |||
341 | if (hardware == FC) |
||
342 | { |
||
343 | lcd_printp_at(0, 3, PSTR("Only with NC !"), 0); |
||
344 | timer = 100; |
||
345 | while (timer > 0); |
||
346 | return; |
||
347 | } |
||
348 | |||
349 | SwitchToNC(); |
||
350 | |||
351 | mode = 'O'; |
||
352 | |||
353 | // disable debug... |
||
354 | // RS232_request_mk_data (0, 'd', 0); |
||
355 | tmp_dat = 0; |
||
356 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
357 | |||
358 | // request OSD Data from NC every 100ms |
||
359 | // RS232_request_mk_data (1, 'o', 100); |
||
360 | tmp_dat = 10; |
||
361 | SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
362 | |||
363 | flag = 0; |
||
364 | timer = TIMEOUT; |
||
365 | abo_timer = ABO_TIMEOUT; |
||
366 | |||
367 | |||
368 | do |
||
369 | { |
||
370 | if (rxd_buffer_locked) |
||
371 | { |
||
372 | timer = TIMEOUT; |
||
373 | Decode64 (); |
||
374 | naviData = (NaviData_t *) pRxData; |
||
375 | |||
376 | if(error == 1) lcd_cls(); |
||
377 | error = 0; |
||
378 | |||
379 | |||
380 | |||
381 | GPS_Pos_t currpos; |
||
382 | currpos.Latitude = naviData->CurrentPosition.Latitude; |
||
383 | currpos.Longitude = naviData->CurrentPosition.Longitude; |
||
384 | |||
385 | if((currpos.Latitude != last5pos[0].Latitude)&&(currpos.Longitude != last5pos[0].Longitude)) |
||
386 | { |
||
387 | last5pos[6] = last5pos[5]; |
||
388 | last5pos[5] = last5pos[4]; |
||
389 | last5pos[4] = last5pos[3]; |
||
390 | last5pos[3] = last5pos[2]; |
||
391 | last5pos[2] = last5pos[1]; |
||
392 | last5pos[1] = last5pos[0]; |
||
393 | last5pos[0] = currpos; |
||
394 | } |
||
395 | |||
396 | flag = 1; |
||
397 | if (OSD_Mode == 1) |
||
398 | { |
||
399 | if (naviData->FCFlags & FCFLAG_MOTOR_RUN) |
||
400 | { // should be engines running |
||
401 | // motors are on, assume we were/are flying |
||
402 | COSD_FLAGS2 |= COSD_WASFLYING; |
||
403 | } |
||
404 | else |
||
405 | { // stats |
||
406 | // if ((COSD_FLAGS2 & COSD_WASFLYING) || (get_key_press (1 << KEY_ENTER))) |
||
407 | if (get_key_press (1 << KEY_ENTER)) |
||
408 | { |
||
409 | print_statistics (); |
||
410 | } |
||
411 | if (get_key_press (1 << KEY_PLUS)) |
||
412 | { |
||
413 | print_position (); |
||
414 | } |
||
415 | } |
||
416 | |||
417 | // lcd_printpns_at (0, 3, PSTR("012345678901234567890"), 0); |
||
418 | lcd_ecircle(22, 35, 16, 1); |
||
419 | |||
420 | // Ground Speed |
||
421 | write_ndigit_number_u (1, 0, (uint16_t) (((uint32_t) naviData->GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0); |
||
422 | lcd_printpns_at(4, 0, PSTR("km/h"), 0); |
||
423 | |||
424 | |||
425 | |||
426 | |||
427 | // Compass |
||
428 | write_ndigit_number_u (14, 0, naviData->CompassHeading, 3, 0); |
||
429 | lcd_putc (17, 0, 0x1E, 0); // degree symbol |
||
430 | lcd_printpns_at (18, 0, (const char *) (pgm_read_word ( &(directions_p[heading_conv(naviData->CompassHeading)]))), 0); |
||
431 | |||
432 | draw_compass (12, 1, naviData->CompassHeading); |
||
433 | |||
434 | |||
435 | |||
436 | // Altitude |
||
437 | //note:lephisto:according to several sources it's /30 |
||
438 | if (naviData->Altimeter > 300 || naviData->Altimeter < -300) |
||
439 | { |
||
440 | // above 10m only write full meters |
||
441 | write_ndigit_number_s (0, 1, naviData->Altimeter / 30, 4, 0); |
||
442 | } |
||
443 | else |
||
444 | { |
||
445 | // up to 10m write meters.dm |
||
446 | write_ndigit_number_s_10th (0, 1, naviData->Altimeter / 3, 3, 0); |
||
447 | } |
||
448 | lcd_putc (4, 1, 'm', 0); |
||
449 | |||
450 | draw_variometer (55, 7, 9, 13, naviData->Variometer); |
||
451 | |||
452 | // TODO: verify correctness |
||
453 | uint16_t heading_home = (naviData->HomePositionDeviation.Bearing + 360 - naviData->CompassHeading) % 360; |
||
454 | lcd_ecirc_line (22, 35, 15, old_hh, 0); |
||
455 | old_hh = heading_home; |
||
456 | lcd_ecirc_line (22, 35, 15, heading_home, 1); |
||
457 | |||
458 | write_ndigit_number_u (7, 3, heading_home, 3, 0); |
||
459 | lcd_putc (10, 3, 0x1e, 0); // degree symbol |
||
460 | |||
461 | write_ndigit_number_u (7, 2, naviData->HomePositionDeviation.Distance / 10, 3, 0); |
||
462 | lcd_putc (10, 2, 'm', 0); |
||
463 | |||
464 | // Sats in use |
||
465 | lcd_printp_at(10, 4, PSTR("Sats"), 0); |
||
466 | write_ndigit_number_u (8, 4, naviData->SatsInUse, 2, 0); |
||
467 | |||
468 | if (naviData->NCFlags & NC_FLAG_MANUAL_CONTROL) |
||
469 | { |
||
470 | lcd_putc (19, 4, 'M', 0); // rc transmitter |
||
471 | } |
||
472 | else |
||
473 | { |
||
474 | lcd_putc (19, 4, 'X', 0); // clear |
||
475 | } |
||
476 | #if 0 |
||
477 | lcd_printp_at(11, 5, PSTR("Mode:"), 0); |
||
478 | if (naviData->NCFlags & NC_FLAG_CH) |
||
479 | { |
||
480 | lcd_printpns_at (17, 5, PSTR("CH "), 0); |
||
481 | } |
||
482 | else if (naviData->NCFlags & NC_FLAG_PH) |
||
483 | { |
||
484 | lcd_printpns_at (17, 5, PSTR("PH "), 0); |
||
485 | } |
||
486 | else |
||
487 | { // (naviData->NCFlags & NC_FLAG_FREE) |
||
488 | lcd_printpns_at (17, 5, PSTR("Free"), 0); // sat2 (free) |
||
489 | } |
||
490 | #endif |
||
491 | if (naviData->NCFlags & NC_FLAG_CH) |
||
492 | { |
||
493 | lcd_printpns_at (10, 5, PSTR("Coming Home"), 0); |
||
494 | } |
||
495 | else if (naviData->NCFlags & NC_FLAG_PH) |
||
496 | { |
||
497 | lcd_printpns_at (10, 5, PSTR("Pos. Hold "), 0); |
||
498 | } |
||
499 | else |
||
500 | { // (naviData->NCFlags & NC_FLAG_FREE) |
||
501 | lcd_printpns_at (10, 5, PSTR("Free "), 0); |
||
502 | } |
||
503 | |||
504 | // Flying time |
||
505 | write_time (7, 6, naviData->FlyingTime); |
||
506 | // lcd_printp_at (7, 6, PSTR("Fly"), 0); |
||
507 | |||
508 | // RC |
||
509 | write_ndigit_number_u (15, 6, naviData->RC_Quality, 3, 0); |
||
510 | lcd_putc (18, 6, 0x1F, 0); // RC-transmitter |
||
511 | if (naviData->NCFlags & NC_FLAG_NOSERIALLINK) |
||
512 | { |
||
513 | lcd_printpns_at(19, 6, PSTR(" "), 0); // clear |
||
514 | } |
||
515 | else |
||
516 | { |
||
517 | lcd_printpns_at(19, 6, PSTR("PC"), 0); |
||
518 | } |
||
519 | |||
520 | // Battery level |
||
521 | write_ndigit_number_u_10th (0, 7, naviData->UBat, 3, 0); |
||
522 | lcd_putc (4, 7, 'V', 0); |
||
523 | // Akku Warnung |
||
524 | if (naviData->UBat < MK_LowBat) |
||
525 | { //Beeper ein |
||
526 | |||
527 | #ifdef HWVERSION1_2 |
||
528 | PORTC &= ~(1<<PORTC7); |
||
529 | #endif |
||
530 | #ifdef HWVERSION1_3 |
||
531 | PORTC &= ~(1<<PORTC7); |
||
532 | #endif |
||
533 | #ifdef HWVERSION3_1 |
||
534 | set_BEEP(); |
||
535 | |||
536 | #endif |
||
537 | |||
538 | } |
||
539 | |||
540 | |||
541 | if (naviData->UBat > MK_LowBat+2) //bei kurzzeitigen Schwankungen Beeper erst wieder aus wenn UBat 0,2 V höher als Warnschwelle |
||
542 | {//Beeper aus |
||
543 | |||
544 | #ifdef HWVERSION1_2 |
||
545 | PORTC |= (1<<PORTC7); |
||
546 | #endif |
||
547 | #ifdef HWVERSION1_3 |
||
548 | PORTC |= (1<<PORTC7); |
||
549 | #endif |
||
550 | #ifdef HWVERSION3_1 |
||
551 | clr_BEEP(); |
||
552 | #endif |
||
553 | } |
||
554 | // Akku Warnung Ende |
||
555 | // Current |
||
556 | write_ndigit_number_u_10th (7, 7, naviData->Current, 3, 0); |
||
557 | lcd_putc (11, 7, 'A', 0); |
||
558 | |||
559 | // Capacity |
||
560 | write_ndigit_number_u (14, 7, naviData->UsedCapacity, 4, 0); |
||
561 | lcd_printpns_at(18, 7, PSTR("mAh"), 0); |
||
562 | |||
563 | // remember statistics (only when engines running) |
||
564 | if (naviData->FCFlags & FCFLAG_MOTOR_RUN) |
||
565 | { |
||
566 | if (naviData->Altimeter > max_Altimeter) max_Altimeter = naviData->Altimeter; |
||
567 | if (naviData->GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData->GroundSpeed; |
||
568 | if (naviData->HomePositionDeviation.Distance > max_Distance) max_Distance = naviData->HomePositionDeviation.Distance; |
||
569 | if (naviData->UBat < min_UBat) min_UBat = naviData->UBat; |
||
570 | if (naviData->FlyingTime > max_FlyingTime) max_FlyingTime = naviData->FlyingTime; |
||
571 | if (naviData->Current > max_Current) max_Current = naviData->Current; |
||
572 | if (naviData->UsedCapacity > max_Capacity) max_Capacity = naviData->UsedCapacity; |
||
573 | } |
||
574 | |||
575 | // remember last values |
||
576 | last_RC_Quality = naviData->RC_Quality; |
||
577 | last_UBat = naviData->UBat; |
||
578 | old_FCFlags = naviData->FCFlags; |
||
579 | |||
580 | rxd_buffer_locked = FALSE; |
||
581 | } |
||
582 | |||
583 | else |
||
584 | { |
||
585 | lcd_printpns_at(0, 0, PSTR("N:"), 0); |
||
586 | lcd_printpns_at(0, 1, PSTR("R:"), 0); |
||
587 | write_ndigit_number_s (2, 0, naviData->AngleNick, 3, 0); |
||
588 | write_ndigit_number_s (2, 1, naviData->AngleRoll, 3, 0); |
||
589 | |||
590 | |||
591 | lcd_line(0,32,128,32,1); |
||
592 | lcd_line(64,0,64,64,1); |
||
593 | |||
594 | uint8_t Nick = ((naviData->AngleNick/2)+32); |
||
595 | uint8_t Roll = -naviData->AngleRoll+64; |
||
596 | uint16_t head_home = (naviData->HomePositionDeviation.Bearing + 360 - naviData->CompassHeading) % 360; |
||
597 | write_ndigit_number_s (2, 2,head_home, 5, 0); |
||
598 | lcd_printpns_at(0, 2, PSTR("K:"), 0); |
||
599 | lcd_ecircle(old_AngleRoll,old_AngleNick, 10, 0); |
||
600 | lcd_ecirc_line (old_AngleRoll, old_AngleNick, 9, old_hh, 0); |
||
601 | |||
602 | lcd_ecircle(Roll, Nick, 10, 1); |
||
603 | lcd_ecirc_line (Roll, Nick, 9, head_home, 1); |
||
604 | |||
605 | |||
606 | old_hh = head_home; |
||
607 | old_AngleNick = Nick; |
||
608 | old_AngleRoll = Roll; |
||
609 | // remember last values |
||
610 | last_RC_Quality = naviData->RC_Quality; |
||
611 | last_UBat = naviData->UBat; |
||
612 | old_FCFlags = naviData->FCFlags; |
||
613 | rxd_buffer_locked = FALSE; |
||
614 | } |
||
615 | |||
616 | if (!abo_timer) |
||
617 | { // renew abo every 3 sec |
||
618 | // request OSD Data from NC every 100ms |
||
619 | // RS232_request_mk_data (1, 'o', 100); |
||
620 | tmp_dat = 10; |
||
621 | SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
622 | |||
623 | abo_timer = ABO_TIMEOUT; |
||
624 | } |
||
625 | } |
||
626 | } |
||
627 | while (!get_key_press (1 << KEY_ESC) && timer); |
||
628 | |||
629 | // Falls Spannungswarnung an war Beeper aus// |
||
630 | |||
631 | #ifdef HWVERSION1_2 |
||
632 | PORTC |= (1<<PORTC7); |
||
633 | #endif |
||
634 | #ifdef HWVERSION1_3 |
||
635 | PORTC |= (1<<PORTC7); |
||
636 | #endif |
||
637 | #ifdef HWVERSION3_1 |
||
638 | clr_BEEP(); |
||
639 | #endif |
||
640 | |||
641 | |||
642 | |||
643 | |||
644 | // disable OSD Data from NC |
||
645 | // RS232_request_mk_data (1, 'o', 0); |
||
646 | tmp_dat = 0; |
||
647 | SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
648 | |||
649 | mode = 0; |
||
650 | rxd_buffer_locked = FALSE; |
||
651 | |||
652 | if (!timer) |
||
653 | { // timeout occured |
||
654 | if (flag) |
||
655 | { |
||
656 | lcd_cls (); |
||
657 | } |
||
658 | |||
659 | error = 1; |
||
660 | |||
661 | uint8_t ij =0; |
||
662 | |||
663 | for(ij=0;ij<7;ij++) |
||
664 | { |
||
665 | |||
666 | uint32_t lon = last5pos[ij].Longitude; |
||
667 | write_ndigit_number_u (0, ij+1, (uint16_t)(lon/10000000), 3, 0); |
||
668 | lcd_printp_at (3,ij+1, PSTR("."), 0); |
||
669 | write_ndigit_number_u (4, ij+1, (uint16_t)((lon/1000) % 10000), 4, 1); |
||
670 | write_ndigit_number_u (8, ij+1, (uint16_t)((lon/10) % 100), 2, 1); |
||
671 | |||
672 | uint32_t lat = last5pos[ij].Latitude; |
||
673 | write_ndigit_number_u (10, ij+1, (uint16_t)(lat/10000000), 3, 0); |
||
674 | lcd_printp_at (13,ij+1, PSTR("."), 0); |
||
675 | write_ndigit_number_u (14, ij+1, (uint16_t)((lat/1000) % 10000), 4, 1); |
||
676 | write_ndigit_number_u (18, ij+1, (uint16_t)((lat/10) % 100), 2, 1); |
||
677 | } |
||
678 | |||
679 | |||
680 | lcd_printp_at (0, 0, PSTR("ERROR: no data"), 0); |
||
681 | |||
682 | timer = 100; |
||
683 | while (timer > 0); |
||
684 | if (get_key_press (1 << KEY_PLUS)) |
||
685 | { |
||
686 | print_position (); |
||
687 | } |
||
688 | osd(OSD_Mode); |
||
689 | } |
||
690 | } |