Rev 344 | Rev 355 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 344 | Rev 346 | ||
---|---|---|---|
Line 26... | Line 26... | ||
26 | ****************************************************************************/ |
26 | ****************************************************************************/ |
Line 27... | Line 27... | ||
27 | 27 | ||
28 | #include <avr/io.h> |
28 | #include <avr/io.h> |
29 | #include <avr/interrupt.h> |
29 | #include <avr/interrupt.h> |
- | 30 | #include <util/delay.h> |
|
- | 31 | #include <avr/pgmspace.h> |
|
30 | #include <util/delay.h> |
32 | #include "main.h" |
31 | #include "max7456_software_spi.c" |
33 | #include "max7456_software_spi.h" |
Line 32... | Line 34... | ||
32 | #include "usart1.h" |
34 | #include "usart1.h" |
33 | 35 | ||
34 | /* TODO: |
36 | /* TODO: |
35 | * - verifiy correctness of values |
37 | * - verifiy correctness of values |
Line 36... | Line -... | ||
36 | * - clean up code :) |
- | |
37 | */ |
- | |
38 | - | ||
39 | /* ########################################################################## |
- | |
40 | * Debugging and general purpose definitions |
- | |
41 | * ##########################################################################*/ |
- | |
42 | #define ALLCHARSDEBUG 0 // set to 1 and flash firmware to see all chars |
- | |
43 | - | ||
44 | #ifndef WRITECHARS // if WRITECHARS not set via makefile |
- | |
45 | #define WRITECHARS -1 // set to 2XX and flash firmware to write new char |
- | |
46 | // enables the allchars as well to see results |
- | |
47 | #endif |
- | |
48 | - | ||
49 | #ifndef NTSC // if NTSC is not thet via makefile |
- | |
50 | #define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line |
- | |
51 | #endif |
- | |
52 | - | ||
53 | #define HUD 1 // set to 0 to disable HUD by default |
- | |
54 | #define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon by default |
- | |
55 | #define STATS 1 // set to 1 to enable statistics during motor off by default |
- | |
56 | #define WARNINGS 1 // set to 1 to display battery+rc warning even if HUD is disabled |
- | |
57 | - | ||
58 | #define UBAT_WRN 94 // voltage for blinking warning, like FC settings |
- | |
59 | #define RCLVL_WRN 100 // make the RC level blink if below this number |
- | |
60 | - | ||
61 | // ### read datasheet before changing stuff below this line :) |
- | |
62 | #define BLINK 0b01001111 // attribute byte for blinking chars |
- | |
63 | - | ||
64 | /* ########################################################################## |
- | |
65 | * FLAGS usable during runtime |
- | |
66 | * ##########################################################################*/ |
- | |
67 | #define COSD_FLAG_NTSC 1 |
- | |
68 | #define COSD_FLAG_HUD 2 |
- | |
69 | #define COSD_FLAG_ARTHORIZON 4 |
- | |
70 | #define COSD_FLAG_STATS 8 |
- | |
71 | #define COSD_FLAG_WARNINGS 16 |
- | |
72 | #define COSD_ICONS_WRITTEN 32 |
- | |
73 | - | ||
74 | /* ########################################################################## |
- | |
75 | * LED controll |
- | |
76 | * ##########################################################################*/ |
- | |
77 | #define LED1_ON PORTC |= (1 << PC0); |
- | |
78 | #define LED1_OFF PORTC &= ~(1 << PC0); |
- | |
79 | #define LED2_ON PORTC |= (1 << PC1); |
- | |
80 | #define LED2_OFF PORTC &= ~(1 << PC1); |
- | |
81 | #define LED3_ON PORTC |= (1 << PC2); |
- | |
82 | #define LED3_OFF PORTC &= ~(1 << PC2); |
- | |
83 | #define LED4_ON PORTC |= (1 << PC3); |
- | |
84 | #define LED4_OFF PORTC &= ~(1 << PC3); |
- | |
85 | - | ||
86 | /* ########################################################################## |
- | |
87 | * switch controll |
- | |
88 | * ##########################################################################*/ |
- | |
89 | #define S1_PRESSED !(PINC & (1<<PC5)) |
38 | * - clean up code :) |
90 | #define S2_PRESSED !(PINC & (1<<PC4)) |
39 | */ |
91 | 40 | ||
Line 92... | Line 41... | ||
92 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
41 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
93 | // data structs |
42 | // data structs not needed for character flashin |
94 | #include "mk-data-structs.h" |
43 | #include "mk-data-structs.h" |
95 | - | ||
96 | /* ########################################################################## |
- | |
97 | * global definitions and global vars |
- | |
98 | * ##########################################################################*/ |
- | |
99 | volatile uint8_t rxd_buffer_locked = 0; |
- | |
100 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
- | |
- | 44 | ||
101 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
45 | /* ########################################################################## |
Line 102... | Line 46... | ||
102 | volatile uint8_t ReceivedBytes = 0; |
46 | * global definitions and global vars |
103 | volatile uint8_t *pRxData = 0; |
47 | * ##########################################################################*/ |
Line 117... | Line 61... | ||
117 | volatile uint16_t timer = 0; |
61 | volatile uint16_t timer = 0; |
Line 118... | Line 62... | ||
118 | 62 | ||
119 | // remember last time data was received |
63 | // remember last time data was received |
Line -... | Line 64... | ||
- | 64 | volatile uint8_t seconds_since_last_data = 0; |
|
- | 65 | ||
- | 66 | // store stats description in progmem to save space |
|
- | 67 | char stats_item_0[] PROGMEM = "max Altitude:"; |
|
- | 68 | char stats_item_1[] PROGMEM = "max Speed :"; |
|
- | 69 | char stats_item_2[] PROGMEM = "max Distance:"; |
|
- | 70 | char stats_item_3[] PROGMEM = "min voltage :"; |
|
- | 71 | char stats_item_4[] PROGMEM = "max time :"; |
|
- | 72 | char* stats_item_pointers[] PROGMEM = {stats_item_0, stats_item_1, stats_item_2, stats_item_3, stats_item_4}; |
|
- | 73 | ||
- | 74 | // store more fixed strings in progmen |
|
- | 75 | char ON[] PROGMEM = "ON "; |
|
120 | volatile uint8_t seconds_since_last_data = 0; |
76 | char OFF[] PROGMEM = "OFF"; |
Line 121... | Line 77... | ||
121 | 77 | ||
122 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
78 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
123 | 79 | ||
Line 151... | Line 107... | ||
151 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
107 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
Line 152... | Line 108... | ||
152 | 108 | ||
153 | /** |
109 | /** |
154 | * serial support |
110 | * serial support |
155 | */ |
111 | */ |
Line 156... | Line 112... | ||
156 | #include "usart1.c" |
112 | //#include "usart1.c" |
157 | 113 | ||
158 | 114 | ||
Line 298... | Line 254... | ||
298 | /** |
254 | /** |
299 | * helper function for menu updating |
255 | * helper function for menu updating |
300 | */ |
256 | */ |
301 | void config_menu_drawings(uint8_t chosen) { |
257 | void config_menu_drawings(uint8_t chosen) { |
302 | // clear prevoius _cursor_ |
258 | // clear prevoius _cursor_ |
303 | write_ascii_string(3, (chosen + 4) % 5, " "); |
259 | write_ascii_string(3, (chosen + 6) % 7, " "); |
304 | // draw current _cursor_ |
260 | // draw current _cursor_ |
305 | write_ascii_string(3, chosen + 6, ">"); |
261 | write_ascii_string(3, chosen + 6, ">"); |
306 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
262 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
307 | write_ascii_string(23, 6, "ON "); |
263 | write_ascii_string_pgm(23, 6, ON); |
308 | } else { |
264 | } else { |
309 | write_ascii_string(23, 6, "OFF"); |
265 | write_ascii_string_pgm(23, 6, OFF); |
310 | } |
266 | } |
311 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
267 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
312 | write_ascii_string(23, 7, "ON "); |
268 | write_ascii_string_pgm(23, 7, ON); |
313 | } else { |
269 | } else { |
314 | write_ascii_string(23, 7, "OFF"); |
270 | write_ascii_string_pgm(23, 7, OFF); |
315 | } |
271 | } |
316 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
272 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
317 | write_ascii_string(23, 8, "ON "); |
273 | write_ascii_string_pgm(23, 8, ON); |
318 | } else { |
274 | } else { |
319 | write_ascii_string(23, 8, "OFF"); |
275 | write_ascii_string_pgm(23, 8, OFF); |
320 | } |
276 | } |
321 | if (COSD_FLAGS & COSD_FLAG_WARNINGS) { |
277 | if (COSD_FLAGS & COSD_FLAG_WARNINGS) { |
322 | write_ascii_string(23, 9, "ON "); |
278 | write_ascii_string_pgm(23, 9, ON); |
323 | } else { |
279 | } else { |
324 | write_ascii_string(23, 9, "OFF"); |
280 | write_ascii_string_pgm(23, 9, OFF); |
325 | } |
281 | } |
326 | } |
282 | } |
Line 327... | Line 283... | ||
327 | 283 | ||
- | 284 | /** |
|
- | 285 | * some sort of clicking response in the menu |
|
- | 286 | */ |
|
- | 287 | void config_menu_doclick(uint8_t chosen, char** menu) { |
|
- | 288 | write_ascii_string(4, chosen + 6, "DONE "); |
|
- | 289 | _delay_ms(1000); |
|
- | 290 | write_ascii_string(4, chosen + 6, menu[chosen]); |
|
- | 291 | } |
|
- | 292 | ||
328 | /** |
293 | /** |
329 | * a simple config menu tryout |
294 | * a simple config menu tryout |
330 | */ |
295 | */ |
331 | void config_menu(void) { |
296 | void config_menu(void) { |
332 | // disable interrupts (makes the menu more smoothely) |
297 | // disable interrupts (makes the menu more smoothely) |
Line 333... | Line 298... | ||
333 | cli(); |
298 | cli(); |
334 | 299 | ||
Line 335... | Line 300... | ||
335 | // clear screen |
300 | // clear screen |
336 | clear(); |
301 | clear(); |
337 | 302 | ||
338 | char* menu[5] = {"Full HUD", |
303 | char* menu[8] = {"Full HUD", |
- | 304 | "Art.Horizon in HUD", |
|
- | 305 | "Statistics", |
|
- | 306 | "Warnings", // TODO: do it! |
|
339 | "Art.Horizon in HUD", |
307 | "Reset uptime", |
Line 340... | Line 308... | ||
340 | "Statistics", |
308 | "Request OSD-data", |
341 | "Warnings", // TODO: do it! |
309 | "Disable Debug-data", |
342 | "EXIT"}; |
310 | "EXIT"}; |
Line 351... | Line 319... | ||
351 | write_ascii_string(4, 6, menu[0]); |
319 | write_ascii_string(4, 6, menu[0]); |
352 | write_ascii_string(4, 7, menu[1]); |
320 | write_ascii_string(4, 7, menu[1]); |
353 | write_ascii_string(4, 8, menu[2]); |
321 | write_ascii_string(4, 8, menu[2]); |
354 | write_ascii_string(4, 9, menu[3]); |
322 | write_ascii_string(4, 9, menu[3]); |
355 | write_ascii_string(4, 10, menu[4]); |
323 | write_ascii_string(4, 10, menu[4]); |
- | 324 | write_ascii_string(4, 11, menu[5]); |
|
- | 325 | write_ascii_string(4, 12, menu[6]); |
|
- | 326 | write_ascii_string(4, 13, menu[7]); |
|
Line 356... | Line 327... | ||
356 | 327 | ||
Line 357... | Line 328... | ||
357 | config_menu_drawings(chosen); |
328 | config_menu_drawings(chosen); |
358 | 329 | ||
359 | while (inmenu) { |
330 | while (inmenu) { |
360 | if (s2_pressed()) { |
331 | if (s2_pressed()) { |
361 | write_ascii_string(3, chosen+6, " "); |
332 | write_ascii_string(3, chosen+6, " "); |
362 | chosen = (chosen + 1) % 5; |
333 | chosen = (chosen + 1) % 8; |
363 | write_ascii_string(3, chosen+6, ">"); |
334 | write_ascii_string(3, chosen+6, ">"); |
364 | _delay_ms(500); |
335 | _delay_ms(500); |
365 | } else if (s1_pressed()) { |
336 | } else if (s1_pressed()) { |
Line 378... | Line 349... | ||
378 | break; |
349 | break; |
379 | case 3: // warnings |
350 | case 3: // warnings |
380 | COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
351 | COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
381 | config_menu_drawings(chosen); |
352 | config_menu_drawings(chosen); |
382 | break; |
353 | break; |
- | 354 | case 4: // reset uptime |
|
- | 355 | uptime = 0; |
|
- | 356 | config_menu_doclick(chosen, menu); |
|
- | 357 | break; |
|
- | 358 | case 5: // re-request OSD data |
|
- | 359 | // request OSD Data from NC every 100ms |
|
- | 360 | usart1_request_mk_data(1, 'o', 100); |
|
- | 361 | config_menu_doclick(chosen, menu); |
|
- | 362 | break; |
|
- | 363 | case 6: // disable debug data |
|
- | 364 | // disable sending of debug data |
|
- | 365 | // may result in smoother ddata display |
|
- | 366 | usart1_request_mk_data(0, 'd', 0); |
|
- | 367 | config_menu_doclick(chosen, menu); |
|
- | 368 | break; |
|
383 | case 4: // exit |
369 | case 7: // exit |
384 | inmenu = 0; |
370 | inmenu = 0; |
385 | break; |
371 | break; |
386 | } |
372 | } |
387 | _delay_ms(250); |
373 | _delay_ms(250); |
388 | } |
374 | } |
Line 528... | Line 514... | ||
528 | // clear serial screen |
514 | // clear serial screen |
529 | //usart1_puts("\x1B[2J\x1B[H"); |
515 | //usart1_puts("\x1B[2J\x1B[H"); |
530 | //usart1_puts("hello world!\r\n"); |
516 | //usart1_puts("hello world!\r\n"); |
Line 531... | Line 517... | ||
531 | 517 | ||
532 | - | ||
533 | // request data ever 100ms from FC |
518 | |
Line 534... | Line 519... | ||
534 | //unsigned char ms = 10; |
519 | // request data ever 100ms from FC; |
535 | //sendMKData('d', 0, &ms, 1); |
- | |
536 | 520 | //usart1_request_mk_data(0, 'd', 100); |
|
- | 521 | ||
537 | // request OSD Data from NC every 100ms |
522 | // request OSD Data from NC every 100ms |
538 | unsigned char ms = 10; |
- | |
539 | sendMKData('o', 1, &ms, 1); |
523 | usart1_request_mk_data(1, 'o', 100); |
Line 540... | Line 524... | ||
540 | // and disable debug... |
524 | |
541 | //ms = 0; |
525 | // and disable debug... |
Line 542... | Line 526... | ||
542 | //sendMKData('d', 0, &ms, 1); |
526 | //usart1_request_mk_data(0, 'd', 0); |
Line 646... | Line 630... | ||
646 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
630 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
647 | } |
631 | } |
648 | } else { |
632 | } else { |
649 | // stats |
633 | // stats |
650 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
634 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
651 | write_ascii_string(2, 5, "max Altitude:"); |
635 | write_ascii_string_pgm(2, 5, stats_item_pointers[0]); // max Altitude |
652 | write_number_s(17, 5, max_Altimeter / 30); |
636 | write_number_s(17, 5, max_Altimeter / 30); |
653 | write_char_xy(22, 5, 204); // small meters m |
637 | write_char_xy(22, 5, 204); // small meters m |
654 | write_ascii_string(2, 6, "max Speed :"); |
638 | write_ascii_string_pgm(2, 6, stats_item_pointers[1]); // max Speed |
655 | write_3digit_number_u(19, 6, (uint16_t) (((uint32_t) max_GroundSpeed * 36) / 1000)); |
639 | write_3digit_number_u(19, 6, (uint16_t) (((uint32_t) max_GroundSpeed * 36) / 1000)); |
656 | write_char_xy(22, 6, 203); // km/h |
640 | write_char_xy(22, 6, 203); // km/h |
657 | write_ascii_string(2, 7, "max Distance:"); |
641 | write_ascii_string_pgm(2, 7, stats_item_pointers[2]); // max Distance |
658 | write_number_s(17, 7, max_Distance / 100); |
642 | write_number_s(17, 7, max_Distance / 100); |
659 | write_char_xy(22, 7, 204); // small meters m |
643 | write_char_xy(22, 7, 204); // small meters m |
660 | write_ascii_string(2, 8, "min voltage :"); |
644 | write_ascii_string_pgm(2, 8, stats_item_pointers[3]); // min voltage |
661 | write_number_u_10th(16, 8, min_UBat); |
645 | write_number_u_10th(16, 8, min_UBat); |
662 | write_ascii_string(22, 8, "V"); // voltage |
646 | write_ascii_string(22, 8, "V"); // voltage |
663 | write_ascii_string(2, 9, "max time :"); |
647 | write_ascii_string_pgm(2, 9, stats_item_pointers[4]); // max time |
664 | write_time(16, 9, max_FlyingTime); |
648 | write_time(16, 9, max_FlyingTime); |
665 | write_char_xy(22, 9, 210); // fly clock |
649 | write_char_xy(22, 9, 210); // fly clock |
666 | } else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
650 | } else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
667 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
651 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
668 | } |
652 | } |
Line 709... | Line 693... | ||
709 | seconds_since_last_data = 0; |
693 | seconds_since_last_data = 0; |
710 | rxd_buffer_locked = 0; |
694 | rxd_buffer_locked = 0; |
711 | } |
695 | } |
712 | // handle keypress |
696 | // handle keypress |
713 | if (s1_pressed()) { |
697 | if (s1_pressed()) { |
714 | //sendMKData('d', 1, (unsigned char*) 0, 1); |
- | |
715 | // request OSD Data from NC every 100ms |
- | |
716 | /*unsigned char ms = 10; |
- | |
717 | sendMKData('o', 1, &ms, 1); |
- | |
718 | _delay_ms(500);*/ |
- | |
719 | config_menu(); |
698 | config_menu(); |
720 | } |
699 | } |
721 | if (s2_pressed()) { |
- | |
722 | uptime = 0; |
- | |
723 | _delay_ms(100); |
- | |
724 | } |
- | |
725 | if (seconds_since_last_data > 2) { |
700 | if (seconds_since_last_data > 2) { |
726 | // re-request OSD Data from NC |
701 | // request OSD Data from NC every 100ms |
727 | - | ||
728 | // re-enable TXD pin |
- | |
729 | usart1_EnableTXD(); |
- | |
730 | - | ||
731 | // every 100ms |
- | |
732 | unsigned char ms = 10; |
- | |
733 | sendMKData('o', 1, &ms, 1); |
702 | usart1_request_mk_data(1, 'o', 100); |
734 | - | ||
735 | // disable TXD pin again |
- | |
736 | usart1_DisableTXD(); |
- | |
737 | - | ||
738 | seconds_since_last_data = 0; |
703 | seconds_since_last_data = 0; |
739 | } |
704 | } |
740 | } |
705 | } |
741 | #endif |
706 | #endif |
742 | return 0; |
707 | return 0; |
743 | } |
708 | } |