Rev 336 | Rev 344 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 336 | Rev 339 | ||
---|---|---|---|
Line 45... | Line 45... | ||
45 | #define WRITECHARS -1 // set to 2XX and flash firmware to write new char |
45 | #define WRITECHARS -1 // set to 2XX and flash firmware to write new char |
46 | // enables the allchars as well to see results |
46 | // enables the allchars as well to see results |
47 | #endif |
47 | #endif |
Line 48... | Line 48... | ||
48 | 48 | ||
49 | #ifndef NTSC // if NTSC is not thet via makefile |
49 | #ifndef NTSC // if NTSC is not thet via makefile |
50 | #define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line |
50 | #define NTSC 1 // set to 1 for NTSC mode + lifts the bottom line |
Line 51... | Line 51... | ||
51 | #endif |
51 | #endif |
52 | 52 | ||
53 | #define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon |
53 | #define HUD 1 // set to 0 to disable HUD by default |
54 | #define NOOSD 0 // set to 1 to disable OSD completely |
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 |
|
55 | #define NOOSD_BUT_WRN 0 // set to 1 to disable OSD completely but show |
56 | #define WARNINGS 1 // set to 1 to display battery+rc warning even if HUD is disabled |
56 | // battery and receive signal warnings |
57 | |
Line 57... | Line 58... | ||
57 | #define UBAT_WRN 94 // voltage for blinking warning, like FC settings |
58 | #define UBAT_WRN 94 // voltage for blinking warning, like FC settings |
58 | #define RCLVL_WRN 100 // make the RC level blink if below this number |
59 | #define RCLVL_WRN 100 // make the RC level blink if below this number |
Line 59... | Line 60... | ||
59 | 60 | ||
60 | // ### read datasheet before changing stuff below this line :) |
61 | // ### read datasheet before changing stuff below this line :) |
61 | #define BLINK 0b01001111 // attribute byte for blinking chars |
62 | #define BLINK 0b01001111 // attribute byte for blinking chars |
62 | 63 | ||
- | 64 | /* ########################################################################## |
|
63 | /* ########################################################################## |
65 | * FLAGS usable during runtime |
64 | * FLAGS usable during runtime |
66 | * ##########################################################################*/ |
65 | * ##########################################################################*/ |
67 | #define COSD_FLAG_NTSC 1 |
66 | #define COSD_FLAG_NTSC 1 |
68 | #define COSD_FLAG_HUD 2 |
Line 67... | Line 69... | ||
67 | #define COSD_FLAG_ARTHORIZON 2 |
69 | #define COSD_FLAG_ARTHORIZON 4 |
68 | #define COSD_FLAG_NOOSD 4 |
70 | #define COSD_FLAG_STATS 8 |
69 | #define COSD_FLAG_NOOSD_BUT_WRN 8 |
71 | #define COSD_FLAG_WARNINGS 16 |
70 | #define COSD_ICONS_WRITTEN 16 |
72 | #define COSD_ICONS_WRITTEN 32 |
Line 290... | Line 292... | ||
290 | } |
292 | } |
Line 291... | Line 293... | ||
291 | 293 | ||
292 | /* ########################################################################## |
294 | /* ########################################################################## |
293 | * A simple config menu for the flags |
295 | * A simple config menu for the flags |
- | 296 | * ##########################################################################*/ |
|
- | 297 | ||
- | 298 | /** |
|
- | 299 | * helper function for menu updating |
|
- | 300 | */ |
|
- | 301 | void config_menu_drawings(uint8_t chosen) { |
|
- | 302 | // clear prevoius _cursor_ |
|
- | 303 | write_ascii_string(3, (chosen + 4) % 5, " "); |
|
- | 304 | // draw current _cursor_ |
|
- | 305 | write_ascii_string(3, chosen + 6, ">"); |
|
- | 306 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
|
- | 307 | write_ascii_string(23, 6, "ON "); |
|
- | 308 | } else { |
|
- | 309 | write_ascii_string(23, 6, "OFF"); |
|
- | 310 | } |
|
- | 311 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
|
- | 312 | write_ascii_string(23, 7, "ON "); |
|
- | 313 | } else { |
|
- | 314 | write_ascii_string(23, 7, "OFF"); |
|
- | 315 | } |
|
- | 316 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
|
- | 317 | write_ascii_string(23, 8, "ON "); |
|
- | 318 | } else { |
|
- | 319 | write_ascii_string(23, 8, "OFF"); |
|
- | 320 | } |
|
- | 321 | if (COSD_FLAGS & COSD_FLAG_WARNINGS) { |
|
- | 322 | write_ascii_string(23, 9, "ON "); |
|
- | 323 | } else { |
|
- | 324 | write_ascii_string(23, 9, "OFF"); |
|
- | 325 | } |
|
- | 326 | } |
|
- | 327 | ||
- | 328 | /** |
|
- | 329 | * a simple config menu tryout |
|
294 | * ##########################################################################*/ |
330 | */ |
295 | void config_menu(void) { |
331 | void config_menu(void) { |
296 | // disable interrupts (makes the menu more smoothely) |
332 | // disable interrupts (makes the menu more smoothely) |
Line 297... | Line 333... | ||
297 | cli(); |
333 | cli(); |
298 | 334 | ||
Line 299... | Line 335... | ||
299 | // clear screen |
335 | // clear screen |
300 | clear(); |
336 | clear(); |
301 | 337 | ||
- | 338 | char* menu[5] = {"Full HUD", |
|
302 | char* menu[4] = {"Normal OSD ", |
339 | "Art.Horizon in HUD", |
Line 303... | Line 340... | ||
303 | "Art.Horizon ", |
340 | "Statistics", |
304 | "NO OSD ", |
341 | "Warnings", // TODO: do it! |
305 | "NO OSD but WRN "}; |
342 | "EXIT"}; |
306 | - | ||
307 | uint8_t inmenu = 1; |
- | |
308 | uint8_t chosen = 0; |
- | |
Line 309... | Line 343... | ||
309 | write_ascii_string(10, 4, "Config Menu"); |
343 | |
310 | 344 | uint8_t inmenu = 1; |
|
Line -... | Line 345... | ||
- | 345 | uint8_t chosen = 0; |
|
- | 346 | write_ascii_string(6, 2, "C-OSD Config Menu"); |
|
- | 347 | ||
- | 348 | // wait a bit before doing stuff so user has chance to release button |
|
- | 349 | _delay_ms(250); |
|
- | 350 | ||
- | 351 | write_ascii_string(4, 6, menu[0]); |
|
- | 352 | write_ascii_string(4, 7, menu[1]); |
|
311 | // clear all mode flags |
353 | write_ascii_string(4, 8, menu[2]); |
312 | COSD_FLAGS &= ~(COSD_FLAG_ARTHORIZON | COSD_FLAG_NOOSD | COSD_FLAG_NOOSD_BUT_WRN); |
- | |
313 | 354 | write_ascii_string(4, 9, menu[3]); |
|
- | 355 | write_ascii_string(4, 10, menu[4]); |
|
314 | // wait a bit before doing stuff so user has chance to release button |
356 | |
- | 357 | config_menu_drawings(chosen); |
|
315 | _delay_ms(250); |
358 | |
316 | 359 | while (inmenu) { |
|
317 | while (inmenu) { |
360 | if (s2_pressed()) { |
318 | write_ascii_string(2, 7, menu[chosen]); |
361 | write_ascii_string(3, chosen+6, " "); |
319 | if (s2_pressed()) { |
362 | chosen = (chosen + 1) % 5; |
- | 363 | write_ascii_string(3, chosen+6, ">"); |
|
320 | chosen = (chosen + 1) % 4; |
364 | _delay_ms(500); |
321 | _delay_ms(500); |
365 | } else if (s1_pressed()) { |
322 | } else if (s1_pressed()) { |
366 | switch (chosen) { |
- | 367 | case 0: // full HUD |
|
323 | switch (chosen) { |
368 | COSD_FLAGS ^= COSD_FLAG_HUD; |
324 | case 1: // artificial horizon |
369 | config_menu_drawings(chosen); |
325 | COSD_FLAGS |= COSD_FLAG_ARTHORIZON; |
370 | break; |
- | 371 | case 1: // art horizon |
|
326 | break; |
372 | COSD_FLAGS ^= COSD_FLAG_ARTHORIZON; |
- | 373 | config_menu_drawings(chosen); |
|
- | 374 | break; |
|
327 | case 2: // everything off |
375 | case 2: // statistics |
328 | COSD_FLAGS |= COSD_FLAG_NOOSD; |
376 | COSD_FLAGS ^= COSD_FLAG_STATS; |
329 | break; |
377 | config_menu_drawings(chosen); |
330 | case 3: // only warning |
378 | break; |
- | 379 | case 3: // warnings |
|
- | 380 | COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
|
331 | COSD_FLAGS |= COSD_FLAG_NOOSD_BUT_WRN; |
381 | config_menu_drawings(chosen); |
332 | break; |
382 | break; |
333 | //default: // normal OSD, so let the flags cleared |
383 | case 4: // exit |
Line 334... | Line 384... | ||
334 | } |
384 | inmenu = 0; |
335 | // leave menu |
385 | break; |
Line 347... | Line 397... | ||
347 | // enable interrupts again |
397 | // enable interrupts again |
348 | sei(); |
398 | sei(); |
349 | } |
399 | } |
Line 350... | Line 400... | ||
350 | 400 | ||
351 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
- | |
352 | 401 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
|
353 | /* ########################################################################## |
402 | /* ########################################################################## |
354 | * MAIN |
403 | * MAIN |
355 | * ##########################################################################*/ |
404 | * ##########################################################################*/ |
356 | int main(void) { |
405 | int main(void) { |
357 | // set up FLAGS, compiler should flatten this one |
406 | // set up FLAGS, compiler should flatten this one |
- | 407 | COSD_FLAGS = (NTSC << 0); |
|
358 | COSD_FLAGS = (NTSC << (COSD_FLAG_NTSC - 1)); |
408 | COSD_FLAGS |= (HUD << 1); |
359 | COSD_FLAGS |= (ARTHORIZON << (COSD_FLAG_ARTHORIZON - 1)); |
409 | COSD_FLAGS |= (ARTHORIZON << 2); |
360 | COSD_FLAGS |= (NOOSD << (COSD_FLAG_NOOSD - 1)); |
410 | COSD_FLAGS |= (STATS << 3); |
Line 361... | Line 411... | ||
361 | COSD_FLAGS |= (NOOSD_BUT_WRN << (COSD_FLAG_NOOSD_BUT_WRN - 1)); |
411 | COSD_FLAGS |= (WARNINGS << 4); |
362 | 412 | ||
363 | // set up Atmega162 Ports |
413 | // set up Atmega162 Ports |
364 | DDRA |= (1 << PA1); // PA1 output (/CS) |
414 | DDRA |= (1 << PA1); // PA1 output (/CS) |
Line 393... | Line 443... | ||
393 | 443 | ||
394 | // reset the MAX7456 to be sure any undefined states do no harm |
444 | // reset the MAX7456 to be sure any undefined states do no harm |
395 | MAX_RESET_LOW |
445 | MAX_RESET_LOW |
Line 396... | Line -... | ||
396 | MAX_RESET_HIGH |
- | |
397 | - | ||
398 | // check for keypress at startup |
- | |
399 | if (s2_pressed()) { // togle COSD_FLAG_ARTHORIZON |
- | |
400 | COSD_FLAGS ^= (1 << (COSD_FLAG_ARTHORIZON - 1)); |
- | |
401 | _delay_ms(100); |
- | |
402 | } |
446 | MAX_RESET_HIGH |
403 | 447 | ||
404 | // give the FC/NC and the maxim time to come up |
448 | // give the FC/NC and the maxim time to come up |
Line 405... | Line 449... | ||
405 | LED4_ON |
449 | LED4_ON |
Line 410... | Line 454... | ||
410 | 454 | ||
411 | //Pushing NEW chars to the MAX7456 |
455 | //Pushing NEW chars to the MAX7456 |
412 | #if (WRITECHARS != -1) |
456 | #if (WRITECHARS != -1) |
413 | // DISABLE display (VM0) |
457 | // DISABLE display (VM0) |
414 | spi_send_byte(0x00, 0b00000000); |
- | |
415 | 458 | spi_send_byte(0x00, 0b00000000); |
|
- | 459 | #include "characters.c" |
|
416 | #include "characters.c" |
460 | |
Line 417... | Line 461... | ||
417 | #endif |
461 | #endif |
418 | 462 | ||
419 | // Setup Video Mode |
463 | // Setup Video Mode |
Line 513... | Line 557... | ||
513 | char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
557 | char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
514 | char arrowdir[8] = { 218, 217, 224, 223, 222, 221, 220, 219}; |
558 | char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
Line 515... | Line 559... | ||
515 | 559 | ||
516 | while (1) { |
560 | while (1) { |
517 | // write icons at init or after menu/mode-switch |
561 | // write icons at init or after menu/mode-switch |
518 | if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && !(COSD_FLAGS & COSD_FLAG_NOOSD)) { |
562 | if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && (COSD_FLAGS & COSD_FLAG_HUD)) { |
519 | write_char_xy(5, top_line, 203); // km/h |
563 | write_char_xy(5, top_line, 203); // km/h |
520 | write_char_xy(10, top_line, 202); // RC-transmitter |
564 | write_char_xy(10, top_line, 202); // RC-transmitter |
521 | write_char_xy(16, top_line, 208); // degree symbol |
565 | write_char_xy(16, top_line, 208); // degree symbol |
522 | write_char_xy(27, top_line, 204); // small meters m |
566 | write_char_xy(27, top_line, 204); // small meters m |
Line 526... | Line 570... | ||
526 | write_char_xy(26, bottom_line, 200); // sat1 |
570 | write_char_xy(26, bottom_line, 200); // sat1 |
527 | write_char_xy(27, bottom_line, 201); // sat2 |
571 | write_char_xy(27, bottom_line, 201); // sat2 |
528 | COSD_FLAGS |= COSD_ICONS_WRITTEN; |
572 | COSD_FLAGS |= COSD_ICONS_WRITTEN; |
529 | } |
573 | } |
530 | if (rxd_buffer_locked) { |
574 | if (rxd_buffer_locked) { |
531 | if (!(COSD_FLAGS & COSD_FLAG_NOOSD)) { |
575 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
532 | if (rxd_buffer[2] == 'D') { // FC Data |
576 | if (rxd_buffer[2] == 'D') { // FC Data |
533 | /*Decode64(); |
577 | /*Decode64(); |
534 | debugData = *((DebugOut_t*) pRxData); |
578 | debugData = *((DebugOut_t*) pRxData); |
535 | write_number_s(12, 2, RxDataLen); |
579 | write_number_s(12, 2, RxDataLen); |
536 | write_number_s(20, 2, setsReceived++); |
580 | write_number_s(20, 2, setsReceived++); |
Line 571... | Line 615... | ||
571 | write_char_xy(20, top_line, 232); // small arrow down |
615 | write_char_xy(20, top_line, 232); // small arrow down |
572 | } else { |
616 | } else { |
573 | write_char_xy(20, top_line, 233); //big arrow down |
617 | write_char_xy(20, top_line, 233); //big arrow down |
574 | } |
618 | } |
Line 575... | Line -... | ||
575 | - | ||
576 | // TODO: is this really dm? |
619 | |
577 | //note:lephisto:according to several sources it's /30 |
- | |
578 | //write_number_s(22, top_line, naviData.Altimeter/30); |
620 | //note:lephisto:according to several sources it's /30 |
579 | if (naviData.Altimeter > 300) { |
621 | if (naviData.Altimeter > 300) { |
580 | // above 10m only write full meters |
622 | // above 10m only write full meters |
581 | write_number_s(22, top_line, naviData.Altimeter/30); |
623 | write_number_s(22, top_line, naviData.Altimeter / 30); |
582 | } else { |
624 | } else { |
Line 589... | Line 631... | ||
589 | 631 | ||
590 | // TODO: verify correctness |
632 | // TODO: verify correctness |
591 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
633 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
Line 592... | Line -... | ||
592 | write_char_xy(27, top_line + 1, arrowdir[heading_conv(heading_home)]); |
- | |
593 | 634 | write_char_xy(27, top_line + 1, arrowdir[heading_conv(heading_home)]); |
|
Line 594... | Line 635... | ||
594 | 635 | ||
595 | write_number_s(22, top_line + 1, naviData.HomePositionDeviation.Distance/100); |
636 | write_number_s(22, top_line + 1, naviData.HomePositionDeviation.Distance / 100); |
596 | 637 | ||
Line 604... | Line 645... | ||
604 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
645 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
605 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
646 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
606 | } |
647 | } |
607 | } else { |
648 | } else { |
608 | // stats |
649 | // stats |
- | 650 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
|
609 | write_ascii_string(2, 5, "max Altitude:"); |
651 | write_ascii_string(2, 5, "max Altitude:"); |
610 | write_number_s(17, 5, max_Altimeter/30); |
652 | write_number_s(17, 5, max_Altimeter / 30); |
611 | write_char_xy(22, 5, 204); // small meters m |
653 | write_char_xy(22, 5, 204); // small meters m |
612 | write_ascii_string(2, 6, "max Speed :"); |
654 | write_ascii_string(2, 6, "max Speed :"); |
613 | write_3digit_number_u(19, 6, (uint16_t)(((uint32_t)max_GroundSpeed*36)/1000)); |
655 | write_3digit_number_u(19, 6, (uint16_t) (((uint32_t) max_GroundSpeed * 36) / 1000)); |
614 | write_char_xy(22, 6, 203); // km/h |
656 | write_char_xy(22, 6, 203); // km/h |
615 | write_ascii_string(2, 7, "max Distance:"); |
657 | write_ascii_string(2, 7, "max Distance:"); |
616 | write_number_s(17, 7, max_Distance/100); |
658 | write_number_s(17, 7, max_Distance / 100); |
617 | write_char_xy(22, 7, 204); // small meters m |
659 | write_char_xy(22, 7, 204); // small meters m |
618 | write_ascii_string(2, 8, "min voltage :"); |
660 | write_ascii_string(2, 8, "min voltage :"); |
619 | //write_number_s(17, 8, min_UBat/10); |
- | |
620 | write_number_u_10th(16, 8, min_UBat); |
661 | write_number_u_10th(16, 8, min_UBat); |
621 | write_ascii_string(22, 8, "V"); // voltage |
662 | write_ascii_string(22, 8, "V"); // voltage |
622 | write_ascii_string(2, 9, "max time :"); |
663 | write_ascii_string(2, 9, "max time :"); |
623 | write_time(16, 9, max_FlyingTime); |
664 | write_time(16, 9, max_FlyingTime); |
624 | write_char_xy(22, 9, 210); // fly clock |
665 | write_char_xy(22, 9, 210); // fly clock |
- | 666 | } 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); |
|
- | 668 | } |
|
625 | } |
669 | } |
Line 626... | Line 670... | ||
626 | 670 | ||
627 | // bottom line |
671 | // bottom line |
628 | write_number_u_10th(0, bottom_line, naviData.UBat); |
672 | write_number_u_10th(0, bottom_line, naviData.UBat); |
Line 658... | Line 702... | ||
658 | } |
702 | } |
659 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
703 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
660 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
704 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
Line 661... | Line 705... | ||
661 | 705 | ||
662 | old_MKFlags = naviData.MKFlags; |
706 | old_MKFlags = naviData.MKFlags; |
663 | } // (!(COSD_FLAGS & COSD_FLAG_NOOSD)) |
707 | } |
664 | } |
708 | } |
665 | seconds_since_last_data = 0; |
709 | seconds_since_last_data = 0; |
666 | rxd_buffer_locked = 0; |
710 | rxd_buffer_locked = 0; |
667 | } |
711 | } |