Rev 336 | Rev 344 | Go to most recent revision | Show entire file | Ignore 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; |
- | 369 | config_menu_drawings(chosen); |
|
- | 370 | break; |
|
- | 371 | case 1: // art horizon |
|
- | 372 | COSD_FLAGS ^= COSD_FLAG_ARTHORIZON; |
|
324 | case 1: // artificial horizon |
373 | config_menu_drawings(chosen); |
325 | COSD_FLAGS |= COSD_FLAG_ARTHORIZON; |
374 | break; |
- | 375 | case 2: // statistics |
|
- | 376 | COSD_FLAGS ^= COSD_FLAG_STATS; |
|
- | 377 | config_menu_drawings(chosen); |
|
- | 378 | break; |
|
326 | break; |
379 | case 3: // warnings |
327 | case 2: // everything off |
- | |
328 | COSD_FLAGS |= COSD_FLAG_NOOSD; |
380 | COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
329 | break; |
- | |
330 | case 3: // only warning |
- | |
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) |
365 | MAX_CS_HIGH |
415 | MAX_CS_HIGH |
366 | DDRA |= (1 << PA2); // PA2 output (SDIN) |
416 | DDRA |= (1 << PA2); // PA2 output (SDIN) |
Line 382... | Line 432... | ||
382 | DDRC &= ~(1 << PC4); // PC4 input (MODE) |
432 | DDRC &= ~(1 << PC4); // PC4 input (MODE) |
383 | PORTC |= (1 << PC4); // pullup |
433 | PORTC |= (1 << PC4); // pullup |
384 | DDRC &= ~(1 << PC5); // PC5 input (SET) |
434 | DDRC &= ~(1 << PC5); // PC5 input (SET) |
385 | PORTC |= (1 << PC5); // pullup |
435 | PORTC |= (1 << PC5); // pullup |
Line 386... | Line 436... | ||
386 | 436 | ||
387 | // set up top and bottom lines |
437 | // set up top and bottom lines |
388 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
438 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
389 | bottom_line = 12; |
439 | bottom_line = 12; |
390 | } else { |
440 | } else { |
391 | bottom_line = 14; |
441 | bottom_line = 14; |
Line 392... | Line 442... | ||
392 | } |
442 | } |
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 |
Line 395... | Line -... | ||
395 | MAX_RESET_LOW |
- | |
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); |
445 | MAX_RESET_LOW |
402 | } |
446 | MAX_RESET_HIGH |
403 | 447 | ||
Line 404... | Line 448... | ||
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 |
406 | _delay_ms(2000); |
450 | _delay_ms(2000); |
407 | 451 | ||
408 | LED4_OFF |
452 | LED4_OFF |
- | 453 | ||
Line 409... | Line -... | ||
409 | - | ||
410 | 454 | ||
Line 411... | Line 455... | ||
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); |
458 | spi_send_byte(0x00, 0b00000000); |
415 | 459 | #include "characters.c" |
|
416 | #include "characters.c" |
460 | |
417 | #endif |
461 | #endif |
418 | 462 | ||
Line 419... | Line 463... | ||
419 | // Setup Video Mode |
463 | // Setup Video Mode |
420 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
464 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
Line 421... | Line 465... | ||
421 | // NTSC + enable display immediately (VM0) |
465 | // NTSC + enable display immediately (VM0) |
Line 479... | Line 523... | ||
479 | 523 | ||
480 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
524 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
481 | clear(); |
525 | clear(); |
482 | write_all_chars(); |
526 | write_all_chars(); |
483 | #else |
527 | #else |
484 | // clear serial screen |
528 | // clear serial screen |
485 | //usart1_puts("\x1B[2J\x1B[H"); |
529 | //usart1_puts("\x1B[2J\x1B[H"); |
Line 486... | Line 530... | ||
486 | //usart1_puts("hello world!\r\n"); |
530 | //usart1_puts("hello world!\r\n"); |
487 | 531 | ||
488 | 532 | ||
489 | // request data ever 100ms from FC |
533 | // request data ever 100ms from FC |
490 | //unsigned char ms = 10; |
534 | //unsigned char ms = 10; |
491 | //sendMKData('d', 0, &ms, 1); |
535 | //sendMKData('d', 0, &ms, 1); |
492 | 536 | ||
493 | // request OSD Data from NC every 100ms |
537 | // request OSD Data from NC every 100ms |
494 | unsigned char ms = 10; |
538 | unsigned char ms = 10; |
495 | sendMKData('o', 1, &ms, 1); |
539 | sendMKData('o', 1, &ms, 1); |
496 | // and disable debug... |
540 | // and disable debug... |
- | 541 | //ms = 0; |
|
- | 542 | //sendMKData('d', 0, &ms, 1); |
|
- | 543 | ||
- | 544 | // disable TXD-pin |
|
- | 545 | usart1_DisableTXD(); |
|
- | 546 | ||
- | 547 | // stats for after flight |
|
- | 548 | int16_t max_Altimeter = 0; |
|
- | 549 | uint16_t max_GroundSpeed = 0; |
|
- | 550 | int16_t max_Distance = 0; |
|
Line 497... | Line 551... | ||
497 | //ms = 0; |
551 | uint8_t min_UBat = 255; |
498 | //sendMKData('d', 0, &ms, 1); |
552 | uint16_t max_FlyingTime = 0; |
Line 499... | Line -... | ||
499 | - | ||
500 | // disable TXD-pin |
- | |
501 | usart1_DisableTXD(); |
- | |
502 | - | ||
503 | // stats for after flight |
- | |
504 | int16_t max_Altimeter = 0; |
- | |
505 | uint16_t max_GroundSpeed = 0; |
- | |
506 | int16_t max_Distance = 0; |
- | |
507 | uint8_t min_UBat = 255; |
- | |
508 | uint16_t max_FlyingTime = 0; |
- | |
509 | 553 | ||
510 | // flags from last round to check for changes |
554 | // flags from last round to check for changes |
Line 511... | Line 555... | ||
511 | uint8_t old_MKFlags = 0; |
555 | uint8_t old_MKFlags = 0; |
512 | 556 | ||
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}; |
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 |
523 | write_ascii_string(6, bottom_line, "V"); // voltage |
567 | write_ascii_string(6, bottom_line, "V"); // voltage |
524 | write_char_xy(14, bottom_line, 209); // on clock |
568 | write_char_xy(14, bottom_line, 209); // on clock |
525 | write_char_xy(22, bottom_line, 210); // fly clock |
569 | write_char_xy(22, bottom_line, 210); // fly clock |
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++); |
537 | write_number_s(12, 3, debugData.Analog[0]); // AngleNick |
581 | write_number_s(12, 3, debugData.Analog[0]); // AngleNick |
538 | write_number_s(12, 4, debugData.Analog[1]); // AngleRoll |
582 | write_number_s(12, 4, debugData.Analog[1]); // AngleRoll |
539 | write_number_s(12, 5, debugData.Analog[5]); // Height |
583 | write_number_s(12, 5, debugData.Analog[5]); // Height |
540 | write_number_s(12, 6, debugData.Analog[9]); // Voltage |
584 | write_number_s(12, 6, debugData.Analog[9]); // Voltage |
541 | write_number_s(12, 7, debugData.Analog[10]);// RC Signal |
585 | write_number_s(12, 7, debugData.Analog[10]);// RC Signal |
542 | write_number_s(12, 8, debugData.Analog[11]);// Gyro compass*/ |
586 | write_number_s(12, 8, debugData.Analog[11]);// Gyro compass*/ |
543 | } else if (rxd_buffer[2] == 'O') { // NC OSD Data |
587 | } else if (rxd_buffer[2] == 'O') { // NC OSD Data |
544 | Decode64(); |
588 | Decode64(); |
545 | naviData = *((NaviData_t*) pRxData); |
589 | naviData = *((NaviData_t*) pRxData); |
546 | 590 | ||
547 | // first line |
591 | // first line |
548 | write_3digit_number_u(2, top_line, (uint16_t)(((uint32_t)naviData.GroundSpeed*36)/1000)); |
592 | write_3digit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * 36) / 1000)); |
549 | 593 | ||
550 | write_3digit_number_u(7, top_line, naviData.RC_Quality); |
594 | write_3digit_number_u(7, top_line, naviData.RC_Quality); |
551 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
595 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
552 | for (uint8_t x = 0; x < 4; x++) |
596 | for (uint8_t x = 0; x < 4; x++) |
553 | write_char_att_xy(7 + x, top_line, BLINK); |
597 | write_char_att_xy(7 + x, top_line, BLINK); |
554 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
598 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
555 | for (uint8_t x = 0; x < 4; x++) |
599 | for (uint8_t x = 0; x < 4; x++) |
556 | write_char_att_xy(7 + x, top_line, 0); |
600 | write_char_att_xy(7 + x, top_line, 0); |
557 | } |
601 | } |
558 | last_RC_Quality = naviData.RC_Quality; |
602 | last_RC_Quality = naviData.RC_Quality; |
559 | 603 | ||
560 | write_3digit_number_u(13, top_line, naviData.CompassHeading); |
604 | write_3digit_number_u(13, top_line, naviData.CompassHeading); |
561 | 605 | ||
562 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
606 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
563 | 607 | ||
564 | if (naviData.Variometer == 0) { |
608 | if (naviData.Variometer == 0) { |
565 | write_char_xy(20, top_line, 206); // plain line |
609 | write_char_xy(20, top_line, 206); // plain line |
566 | } else if (naviData.Variometer > 0 && naviData.Variometer <= 10) { |
610 | } else if (naviData.Variometer > 0 && naviData.Variometer <= 10) { |
567 | write_char_xy(20, top_line, 234); // small arrow up |
611 | write_char_xy(20, top_line, 234); // small arrow up |
568 | } else if (naviData.Variometer > 10) { |
612 | } else if (naviData.Variometer > 10) { |
569 | write_char_xy(20, top_line, 235); // big arrow up |
613 | write_char_xy(20, top_line, 235); // big arrow up |
570 | } else if (naviData.Variometer < 0 && naviData.Variometer >= -10) { |
614 | } else if (naviData.Variometer < 0 && naviData.Variometer >= -10) { |
571 | write_char_xy(20, top_line, 232); // small arrow down |
- | |
572 | } else { |
615 | write_char_xy(20, top_line, 232); // small arrow down |
573 | write_char_xy(20, top_line, 233); //big arrow down |
- | |
574 | } |
616 | } else { |
575 | 617 | write_char_xy(20, top_line, 233); //big arrow down |
|
576 | // TODO: is this really dm? |
618 | } |
577 | //note:lephisto:according to several sources it's /30 |
619 | |
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 { |
583 | // up to 10m write meters.dm |
625 | // up to 10m write meters.dm |
584 | write_number_u_10th(21, top_line, naviData.Altimeter/3); |
626 | write_number_u_10th(21, top_line, naviData.Altimeter / 3); |
585 | } |
627 | } |
586 | 628 | ||
587 | // seccond line |
629 | // seccond line |
588 | draw_compass(11, top_line + 1, naviData.CompassHeading); |
- | |
589 | 630 | draw_compass(11, top_line + 1, naviData.CompassHeading); |
|
590 | // TODO: verify correctness |
631 | |
591 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
632 | // TODO: verify correctness |
592 | write_char_xy(27, top_line + 1, arrowdir[heading_conv(heading_home)]); |
633 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
593 | 634 | write_char_xy(27, top_line + 1, arrowdir[heading_conv(heading_home)]); |
|
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 | ||
597 | // center |
638 | // center |
598 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { // should be engines running |
639 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { // should be engines running |
599 | if (!(old_MKFlags & FLAG_MOTOR_RUN)) { // motors just started, clear middle |
640 | if (!(old_MKFlags & FLAG_MOTOR_RUN)) { // motors just started, clear middle |
600 | clear(); |
641 | clear(); |
601 | // update flags to paint display again if needed |
642 | // update flags to paint display again if needed |
602 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
643 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
603 | } |
644 | } |
- | 645 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
|
604 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
646 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
605 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
647 | } |
606 | } |
648 | } else { |
607 | } else { |
649 | // stats |
608 | // 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 |
- | |
615 | write_ascii_string(2, 7, "max Distance:"); |
656 | write_char_xy(22, 6, 203); // km/h |
616 | write_number_s(17, 7, max_Distance/100); |
657 | write_ascii_string(2, 7, "max Distance:"); |
617 | write_char_xy(22, 7, 204); // small meters m |
658 | write_number_s(17, 7, max_Distance / 100); |
618 | write_ascii_string(2, 8, "min voltage :"); |
659 | write_char_xy(22, 7, 204); // small meters m |
619 | //write_number_s(17, 8, min_UBat/10); |
660 | write_ascii_string(2, 8, "min voltage :"); |
- | 661 | write_number_u_10th(16, 8, min_UBat); |
|
- | 662 | write_ascii_string(22, 8, "V"); // voltage |
|
- | 663 | write_ascii_string(2, 9, "max time :"); |
|
620 | write_number_u_10th(16, 8, min_UBat); |
664 | write_time(16, 9, max_FlyingTime); |
621 | write_ascii_string(22, 8, "V"); // voltage |
665 | write_char_xy(22, 9, 210); // fly clock |
622 | write_ascii_string(2, 9, "max time :"); |
666 | } else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
623 | write_time(16, 9, max_FlyingTime); |
667 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
624 | write_char_xy(22, 9, 210); // fly clock |
668 | } |
625 | } |
669 | } |
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); |
629 | if (naviData.UBat <= UBAT_WRN && last_UBat > UBAT_WRN) { |
673 | if (naviData.UBat <= UBAT_WRN && last_UBat > UBAT_WRN) { |
630 | for (uint8_t x = 0; x < 7; x++) |
674 | for (uint8_t x = 0; x < 7; x++) |
631 | write_char_att_xy(x, bottom_line, BLINK); |
675 | write_char_att_xy(x, bottom_line, BLINK); |
632 | } else { |
676 | } else { |
633 | for (uint8_t x = 0; x < 7; x++) |
677 | for (uint8_t x = 0; x < 7; x++) |
634 | write_char_att_xy(x, bottom_line, 0); |
678 | write_char_att_xy(x, bottom_line, 0); |
635 | } |
679 | } |
636 | 680 | ||
637 | write_time(8, bottom_line, uptime); |
681 | write_time(8, bottom_line, uptime); |
638 | write_time(16, bottom_line, naviData.FlyingTime); |
682 | write_time(16, bottom_line, naviData.FlyingTime); |
639 | 683 | ||
640 | write_3digit_number_u(23, bottom_line, naviData.SatsInUse); |
684 | write_3digit_number_u(23, bottom_line, naviData.SatsInUse); |
641 | 685 | ||
642 | if (naviData.NCFlags & NC_FLAG_CH) { |
686 | if (naviData.NCFlags & NC_FLAG_CH) { |
643 | write_char_xy(27, bottom_line, 231); // gps ch |
687 | write_char_xy(27, bottom_line, 231); // gps ch |
644 | } else if (naviData.NCFlags & NC_FLAG_PH) { |
688 | } else if (naviData.NCFlags & NC_FLAG_PH) { |
645 | write_char_xy(27, bottom_line, 230); // gps ph |
689 | write_char_xy(27, bottom_line, 230); // gps ph |
646 | } else { // (naviData.NCFlags & NC_FLAG_FREE) |
690 | } else { // (naviData.NCFlags & NC_FLAG_FREE) |
647 | write_char_xy(27, bottom_line, 201); // sat2 (free) |
691 | write_char_xy(27, bottom_line, 201); // sat2 (free) |
648 | } |
692 | } |
649 | 693 | ||
650 | //write_number_s(8, 5, RxDataLen); |
694 | //write_number_s(8, 5, RxDataLen); |
651 | //write_number_s(16, 5, setsReceived++); |
695 | //write_number_s(16, 5, setsReceived++); |
652 | 696 | ||
653 | // remember statistics |
697 | // remember statistics |
654 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
698 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
655 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
699 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
656 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
700 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
657 | max_Distance = naviData.HomePositionDeviation.Distance; |
701 | max_Distance = naviData.HomePositionDeviation.Distance; |
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; |
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 | } |
668 | // handle keypress |
712 | // handle keypress |
669 | if (s1_pressed()) { |
713 | if (s1_pressed()) { |
670 | //sendMKData('d', 1, (unsigned char*) 0, 1); |
714 | //sendMKData('d', 1, (unsigned char*) 0, 1); |
671 | // request OSD Data from NC every 100ms |
715 | // request OSD Data from NC every 100ms |
672 | /*unsigned char ms = 10; |
716 | /*unsigned char ms = 10; |
673 | sendMKData('o', 1, &ms, 1); |
717 | sendMKData('o', 1, &ms, 1); |
674 | _delay_ms(500);*/ |
718 | _delay_ms(500);*/ |
675 | config_menu(); |
719 | config_menu(); |
676 | } |
720 | } |
677 | if (s2_pressed()) { |
721 | if (s2_pressed()) { |
678 | uptime = 0; |
722 | uptime = 0; |
679 | _delay_ms(100); |
723 | _delay_ms(100); |
680 | } |
724 | } |
681 | if (seconds_since_last_data > 2) { |
725 | if (seconds_since_last_data > 2) { |
682 | // re-request OSD Data from NC |
726 | // re-request OSD Data from NC |
683 | 727 | ||
684 | // re-enable TXD pin |
728 | // re-enable TXD pin |
685 | usart1_EnableTXD(); |
- | |
686 | - | ||
687 | // every 100ms |
- | |
Line -... | Line 729... | ||
- | 729 | usart1_EnableTXD(); |
|
- | 730 | ||
- | 731 | // every 100ms |
|
688 | unsigned char ms = 10; |
732 | unsigned char ms = 10; |
689 | sendMKData('o', 1, &ms, 1); |
733 | sendMKData('o', 1, &ms, 1); |
690 | 734 | ||
691 | // disable TXD pin again |
735 | // disable TXD pin again |
692 | usart1_DisableTXD(); |
736 | usart1_DisableTXD(); |
693 | 737 |