Rev 458 | Rev 465 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 458 | Rev 459 | ||
---|---|---|---|
Line 299... | Line 299... | ||
299 | 299 | ||
300 | /** |
300 | /** |
301 | * auto config some stuff on startup, currently only battery cells |
301 | * auto config some stuff on startup, currently only battery cells |
302 | * TODO: this is testing stuff, strings should go progmem and so on... |
302 | * TODO: this is testing stuff, strings should go progmem and so on... |
303 | */ |
303 | */ |
304 | void auto_config(uint8_t UBat, uint8_t* min_UBat) { |
304 | void auto_config(uint8_t UBat) { |
305 | clear(); |
- | |
306 | // fix for min_bat glitch caused by data only gathered during motors up |
- | |
307 | *min_UBat = UBat; |
305 | clear(); |
308 | write_ascii_string(2, 2, "C-OSD Initialisation"); |
306 | write_ascii_string(2, 2, "C-OSD Initialisation"); |
309 | #if FCONLY |
307 | #if FCONLY |
310 | write_ascii_string(2, 3, "FC only Mode"); |
308 | write_ascii_string(2, 3, "FC only Mode"); |
311 | #else |
309 | #else |
312 | write_ascii_string(2, 3, "NaviCtrl Mode"); |
310 | write_ascii_string(2, 3, "NaviCtrl Mode"); |
- | 311 | #endif |
|
313 | #endif |
312 | write_ascii_string(2, 4, BUILDDATE); |
314 | uint8_t cellnum = 0; |
313 | uint8_t cellnum = 0; |
315 | if (CELL_NUM == -1) { |
314 | if (CELL_NUM == -1) { |
316 | write_ascii_string(2, 5, "Guessing Number of Cells"); |
315 | write_ascii_string(2, 6, "Guessing Number of Cells"); |
317 | do { |
316 | do { |
318 | cellnum++; |
317 | cellnum++; |
319 | } while (UBat > ((cellnum * CELL_VOLT_MAX) + 15)); |
318 | } while (UBat > ((cellnum * CELL_VOLT_MAX) + 15)); |
320 | } else { |
319 | } else { |
Line 456... | Line 455... | ||
456 | usart1_request_mk_data(0, 'd', 0); |
455 | usart1_request_mk_data(0, 'd', 0); |
457 | #endif |
456 | #endif |
Line 458... | Line 457... | ||
458 | 457 | ||
459 | // stats for after flight |
458 | // stats for after flight |
460 | int16_t max_Altimeter = 0; |
- | |
461 | uint16_t max_GroundSpeed = 0; |
- | |
462 | int16_t max_Distance = 0; |
459 | int16_t max_Altimeter = 0; |
- | 460 | uint8_t min_UBat = 255; |
|
- | 461 | #if !(FCONLY) |
|
- | 462 | uint16_t max_GroundSpeed = 0; |
|
463 | uint8_t min_UBat = 255; |
463 | int16_t max_Distance = 0; |
Line 464... | Line 464... | ||
464 | uint16_t max_FlyingTime = 0; |
464 | uint16_t max_FlyingTime = 0; |
465 | 465 | ||
Line 466... | Line 466... | ||
466 | // flags from last round to check for changes |
466 | // flags from last round to check for changes |
467 | uint8_t old_MKFlags = 0; |
467 | uint8_t old_MKFlags = 0; |
- | 468 | ||
Line 468... | Line 469... | ||
468 | 469 | char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
|
469 | char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
- | |
470 | //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
- | |
471 | - | ||
472 | while (1) { |
- | |
473 | // write icons at init or after menu/mode-switch |
- | |
474 | if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && (COSD_FLAGS & COSD_FLAG_HUD)) { |
- | |
475 | #if FCONLY |
- | |
476 | // FC Mode ICONS |
- | |
477 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
- | |
478 | write_char_xy(27, top_line, 0xCC); // small meters m height |
- | |
479 | write_char_xy(7, bottom_line, 0x9E); // small v |
- | |
480 | #else |
- | |
481 | // NAVI Mode ICONS |
- | |
482 | write_char_xy(5, top_line, 0xCB); // km/h |
- | |
483 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
- | |
484 | write_char_xy(16, top_line, 0xD0); // degree symbol |
- | |
485 | write_char_xy(27, top_line, 0xCC); // small meters m height |
- | |
486 | write_char_xy(20, top_line + 1, 0xB0); // left circle |
- | |
487 | write_char_xy(22, top_line + 1, 0xB2); // right circle |
- | |
488 | write_char_xy(27, top_line + 1, 0xCC); // small meters m home |
- | |
489 | write_char_xy(7, bottom_line, 0x9E); // small v |
- | |
490 | write_char_xy(14, bottom_line, 0xD1); // on clock |
- | |
491 | write_char_xy(21, bottom_line, 0xD2); // fly clock |
- | |
492 | write_char_xy(26, bottom_line, 0xC8); // sat1 |
- | |
493 | write_char_xy(27, bottom_line, 0xC9); // sat2 |
470 | //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
494 | COSD_FLAGS |= COSD_ICONS_WRITTEN; |
471 | #endif |
495 | #endif |
472 | |
496 | } |
473 | while (1) { |
497 | if (rxd_buffer_locked) { |
474 | if (rxd_buffer_locked) { |
498 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
475 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
Line 499... | Line 476... | ||
499 | #if FCONLY |
476 | #if FCONLY |
500 | if (rxd_buffer[2] == 'D') { // FC Data |
477 | if (rxd_buffer[2] == 'D') { // FC Data |
- | 478 | Decode64(); |
|
- | 479 | debugData = *((DebugOut_t*) pRxData); |
|
501 | Decode64(); |
480 | |
502 | debugData = *((DebugOut_t*) pRxData); |
481 | // init on first data retrival, distinguished by last battery :) |
503 | - | ||
504 | // init on first data retrival, distinguished by last battery :) |
- | |
505 | if (last_UBat == 255) { |
- | |
506 | auto_config(debugData.Analog[9], &min_UBat); |
- | |
507 | } |
- | |
508 | - | ||
509 | write_ndigit_number_u(7, top_line, debugData.Analog[10], 100, 0); |
- | |
510 | if (debugData.Analog[10] <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
- | |
511 | for (uint8_t x = 0; x < 4; x++) |
- | |
512 | write_char_att_xy(7 + x, top_line, BLINK); |
- | |
513 | } else if (debugData.Analog[10] > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
- | |
514 | for (uint8_t x = 0; x < 4; x++) |
- | |
515 | write_char_att_xy(7 + x, top_line, 0); |
- | |
516 | } |
- | |
517 | last_RC_Quality = debugData.Analog[10]; |
- | |
518 | - | ||
519 | - | ||
520 | if (debugData.Analog[5] > 300 || debugData.Analog[5] < -300) { |
- | |
521 | // above 10m only write full meters |
- | |
522 | write_ndigit_number_s(23, top_line, debugData.Analog[5] / 30, 1000, 0); |
- | |
523 | } else { |
- | |
524 | // up to 10m write meters.dm |
- | |
525 | write_ndigit_number_s_10th(23, top_line, debugData.Analog[5] / 3, 100, 0); |
- | |
526 | } |
- | |
527 | - | ||
528 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
- | |
529 | draw_artificial_horizon(top_line + 2, bottom_line - 1, debugData.Analog[0], debugData.Analog[1]); |
- | |
530 | } |
- | |
531 | - | ||
532 | draw_battery(2, bottom_line, min_voltage, debugData.Analog[9], max_voltage); |
- | |
533 | write_ndigit_number_u_10th(3, bottom_line, debugData.Analog[9], 100, 0); |
- | |
534 | if (debugData.Analog[9] <= min_voltage && last_UBat > min_voltage) { |
- | |
535 | for (uint8_t x = 2; x < 8; x++) |
- | |
536 | write_char_att_xy(x, bottom_line, BLINK); |
- | |
537 | } else if (debugData.Analog[9] > min_voltage && last_UBat < min_voltage) { |
- | |
538 | for (uint8_t x = 2; x < 8; x++) |
- | |
539 | write_char_att_xy(x, bottom_line, 0); |
- | |
540 | } |
- | |
541 | // remember last values |
- | |
542 | last_UBat = debugData.Analog[9]; |
- | |
543 | - | ||
544 | /* |
- | |
545 | debugData.Analog[0]); // AngleNick |
- | |
546 | debugData.Analog[1]); // AngleRoll |
- | |
547 | debugData.Analog[5]); // Height |
482 | if (last_UBat == 255) { |
548 | debugData.Analog[9]); // Voltage |
483 | // fix for min_UBat |
549 | debugData.Analog[10]);// RC Signal |
484 | min_UBat = debugData.Analog[9]; |
550 | debugData.Analog[11]);// Gyro compass |
485 | auto_config(debugData.Analog[9]); |
551 | */ |
486 | } |
552 | seconds_since_last_data = 0; |
487 | #include "osd_fcmode_default.c" |
553 | } |
488 | } |
554 | #else |
489 | #else |
555 | if (rxd_buffer[2] == 'O') { // NC OSD Data |
490 | if (rxd_buffer[2] == 'O') { // NC OSD Data |
556 | Decode64(); |
- | |
557 | naviData = *((NaviData_t*) pRxData); |
- | |
558 | - | ||
559 | // init on first data retrival, distinguished by last battery :) |
- | |
560 | if (last_UBat == 255) { |
- | |
561 | auto_config(naviData.UBat, &min_UBat); |
- | |
562 | } |
- | |
563 | - | ||
564 | // first line |
- | |
565 | write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 100, 0); |
- | |
566 | - | ||
567 | write_ndigit_number_u(7, top_line, naviData.RC_Quality, 100, 0); |
- | |
568 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
- | |
569 | for (uint8_t x = 0; x < 4; x++) |
- | |
570 | write_char_att_xy(7 + x, top_line, BLINK); |
- | |
571 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
- | |
572 | for (uint8_t x = 0; x < 4; x++) |
- | |
573 | write_char_att_xy(7 + x, top_line, 0); |
- | |
574 | } |
- | |
575 | last_RC_Quality = naviData.RC_Quality; |
- | |
576 | - | ||
577 | if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) { |
- | |
578 | write_char_xy(11, top_line, 0); // clear |
- | |
579 | } else { |
- | |
580 | write_char_xy(11, top_line, 0xC6); // PC icon |
- | |
581 | } |
- | |
582 | - | ||
583 | write_ndigit_number_u(13, top_line, naviData.CompassHeading, 100, 0); |
- | |
584 | - | ||
585 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
- | |
586 | - | ||
587 | draw_variometer(21, top_line, naviData.Variometer); |
- | |
588 | - | ||
589 | //note:lephisto:according to several sources it's /30 |
- | |
590 | if (naviData.Altimeter > 300 || naviData.Altimeter < -300) { |
- | |
591 | // above 10m only write full meters |
- | |
592 | write_ndigit_number_s(23, top_line, naviData.Altimeter / 30, 1000, 0); |
- | |
593 | } else { |
- | |
594 | // up to 10m write meters.dm |
- | |
595 | //write_number_u_10th(21, top_line, naviData.Altimeter / 3); |
- | |
596 | write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 100, 0); |
- | |
597 | } |
- | |
598 | - | ||
599 | // seccond line |
- | |
600 | draw_compass(11, top_line + 1, naviData.CompassHeading); |
- | |
601 | - | ||
602 | // TODO: verify correctness |
- | |
603 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
- | |
604 | //write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]); |
- | |
605 | // finer resolution, 0xa0 is first character and we add the index 0 <= index < 16 |
- | |
606 | write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home)); |
- | |
607 | - | ||
608 | write_ndigit_number_u(24, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 100, 0); |
- | |
609 | - | ||
610 | // center |
- | |
611 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { // should be engines running |
- | |
612 | if (!(old_MKFlags & FLAG_MOTOR_RUN)) { // motors just started, clear middle |
- | |
613 | clear(); |
- | |
614 | // update flags to paint display again if needed |
- | |
615 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
- | |
616 | } |
- | |
617 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
- | |
618 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
- | |
619 | } |
- | |
620 | // motors are on, assume we were/are flying |
- | |
621 | COSD_FLAGS |= COSD_WASFLYING; |
- | |
622 | } else { |
- | |
623 | // stats |
- | |
624 | if ((COSD_FLAGS & COSD_WASFLYING) && (COSD_FLAGS & COSD_FLAG_STATS)) { |
- | |
625 | write_ascii_string_pgm(2, 4, stats_item_pointers[0]); // max Altitude |
- | |
626 | write_ndigit_number_s(18, 4, max_Altimeter / 30, 1000, 0); |
- | |
627 | write_char_xy(22, 4, 204); // small meters m |
- | |
628 | write_ascii_string_pgm(2, 5, stats_item_pointers[1]); // max Speed |
- | |
629 | write_ndigit_number_u(19, 5, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 100, 0); |
- | |
630 | write_char_xy(22, 5, 203); // km/h |
- | |
631 | write_ascii_string_pgm(2, 6, stats_item_pointers[2]); // max Distance |
- | |
632 | write_ndigit_number_u(19, 6, max_Distance / 10, 100, 0); |
- | |
633 | write_char_xy(22, 6, 204); // small meters m |
- | |
634 | write_ascii_string_pgm(2, 7, stats_item_pointers[3]); // min voltage |
- | |
635 | write_ndigit_number_u_10th(18, 7, min_UBat, 100, 0); |
- | |
636 | write_char_xy(22, 7, 0x9E); // small v |
- | |
637 | write_ascii_string_pgm(2, 8, stats_item_pointers[4]); // max time |
- | |
638 | write_time(16, 8, max_FlyingTime); |
- | |
639 | write_char_xy(22, 8, 210); // fly clock |
- | |
640 | write_ascii_string_pgm(2, 9, stats_item_pointers[5]); // longitude |
- | |
641 | write_gps_pos(15, 9, naviData.CurrentPosition.Longitude); |
491 | Decode64(); |
642 | write_ascii_string_pgm(2, 10, stats_item_pointers[6]); // latitude |
- | |
643 | write_gps_pos(15, 10, naviData.CurrentPosition.Latitude); |
- | |
644 | } else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
- | |
645 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
- | |
646 | } |
- | |
647 | } |
- | |
648 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
- | |
649 | draw_big_variometer(27, 8, naviData.Variometer); |
- | |
650 | } |
- | |
651 | - | ||
652 | // bottom line |
- | |
653 | draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage); |
- | |
654 | write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 100, 0); |
- | |
655 | if (naviData.UBat <= min_voltage && last_UBat > min_voltage) { |
- | |
656 | for (uint8_t x = 2; x < 8; x++) |
- | |
657 | write_char_att_xy(x, bottom_line, BLINK); |
- | |
658 | } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) { |
492 | naviData = *((NaviData_t*) pRxData); |
659 | for (uint8_t x = 2; x < 8; x++) |
- | |
660 | write_char_att_xy(x, bottom_line, 0); |
- | |
661 | } |
- | |
662 | // remember last values |
- | |
663 | last_UBat = naviData.UBat; |
- | |
664 | - | ||
665 | write_time(8, bottom_line, uptime); |
- | |
666 | write_time(15, bottom_line, naviData.FlyingTime); |
- | |
667 | - | ||
668 | write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 10, 0); |
- | |
669 | - | ||
670 | if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) { |
- | |
671 | write_char_xy(23, bottom_line, 0xB3); // rc transmitter |
493 | |
672 | } else { |
- | |
673 | write_char_xy(23, bottom_line, 0); // clear |
- | |
674 | } |
- | |
675 | - | ||
676 | if (naviData.NCFlags & NC_FLAG_CH) { |
- | |
677 | write_char_xy(27, bottom_line, 231); // gps ch |
- | |
678 | } else if (naviData.NCFlags & NC_FLAG_PH) { |
494 | // init on first data retrival, distinguished by last battery :) |
679 | write_char_xy(27, bottom_line, 230); // gps ph |
495 | if (last_UBat == 255) { |
680 | } else { // (naviData.NCFlags & NC_FLAG_FREE) |
- | |
681 | write_char_xy(27, bottom_line, 201); // sat2 (free) |
- | |
682 | } |
- | |
683 | - | ||
684 | //write_number_s(8, 5, RxDataLen); |
- | |
685 | //write_number_s(16, 5, setsReceived++); |
- | |
686 | - | ||
687 | // remember statistics (only when engines running) |
- | |
688 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { |
- | |
689 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
- | |
690 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
- | |
691 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
- | |
692 | max_Distance = naviData.HomePositionDeviation.Distance; |
496 | // fix for min_UBat |
693 | } |
- | |
694 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
- | |
695 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
- | |
696 | } |
497 | min_UBat = naviData.UBat; |
697 | 498 | auto_config(naviData.UBat); |
|
698 | old_MKFlags = naviData.MKFlags; |
499 | } |
699 | seconds_since_last_data = 0; |
500 | #include "osd_ncmode_default.c" |
700 | } |
501 | } |