Subversion Repositories Projects

Rev

Rev 454 | Rev 457 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 454 Rev 455
Line 112... Line 112...
112
}
112
}
Line 113... Line 113...
113
 
113
 
114
/* ##########################################################################
114
/* ##########################################################################
115
 * Interrupt handler
115
 * Interrupt handler
-
 
116
 * ##########################################################################*/
116
 * ##########################################################################*/
117
 
117
/**
118
/**
118
 * handler for undefined Interrupts
119
 * handler for undefined Interrupts
119
 * if not defined AVR will reset in case any unhandled interrupts occur
120
 * if not defined AVR will reset in case any unhandled interrupts occur
120
 */
121
 */
Line 124... Line 125...
124
 
125
 
125
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
126
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
126
/* ##########################################################################
127
/* ##########################################################################
127
 * timer stuff
128
 * timer stuff
-
 
129
 * ##########################################################################*/
128
 * ##########################################################################*/
130
 
129
/**
131
/**
130
 * timer kicks in every 1000uS ^= 1ms
132
 * timer kicks in every 1000uS ^= 1ms
131
 */
133
 */
132
ISR(TIMER0_OVF_vect) {
134
ISR(TIMER0_OVF_vect) {
Line 293... Line 295...
293
 
295
 
294
        // enable interrupts again
296
    // enable interrupts again
295
        sei();
297
    sei();
Line -... Line 298...
-
 
298
}
-
 
299
 
-
 
300
/**
-
 
301
 * auto config some stuff on startup, currently only battery cells
-
 
302
 * TODO: this is testing stuff, strings should go progmem and so on...
-
 
303
 */
-
 
304
void auto_config(uint8_t UBat, uint8_t* min_UBat) {
-
 
305
    clear();
-
 
306
    // fix for min_bat glitch caused by data only gathered during motors up
-
 
307
    *min_UBat = UBat;
-
 
308
    write_ascii_string(2, 2, "C-OSD Initialisation");
-
 
309
#if FCONLY
-
 
310
    write_ascii_string(2, 3, "FC only Mode");
-
 
311
#else
-
 
312
    write_ascii_string(2, 3, "NaviCtrl Mode");
-
 
313
#endif
-
 
314
    uint8_t cellnum = 0;
-
 
315
    if (CELL_NUM == -1) {
-
 
316
        write_ascii_string(2, 5, "Guessing Number of Cells");
-
 
317
        do {
-
 
318
            cellnum++;
-
 
319
        } while (UBat > ((cellnum * CELL_VOLT_MAX) + 10));
-
 
320
    } else {
-
 
321
        cellnum = CELL_NUM;
-
 
322
    }
-
 
323
    min_voltage = cellnum * CELL_VOLT_MIN;
-
 
324
    max_voltage = cellnum * CELL_VOLT_MAX;
-
 
325
    write_ascii_string(2, 7, "Number of Cells:");
-
 
326
    write_ndigit_number_u(21, 7, cellnum, 1, 0);
-
 
327
    write_ascii_string(2, 8, "Warn Voltage   :");
-
 
328
    write_ndigit_number_s_10th(20, 8, min_voltage, 100, 0);
-
 
329
    write_ascii_string(2, 9, "Max Voltage    :");
-
 
330
    write_ndigit_number_s_10th(20, 9, max_voltage, 100, 0);
-
 
331
    _delay_ms(200);
-
 
332
    clear();
-
 
333
    // update flags to paint display again because of clear
-
 
334
    COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
296
}
335
}
-
 
336
 
297
 
337
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
298
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
338
 
299
/* ##########################################################################
339
/* ##########################################################################
300
 * MAIN
340
 * MAIN
301
 * ##########################################################################*/
341
 * ##########################################################################*/
Line 353... Line 393...
353
    //Pushing NEW chars to the MAX7456
393
    //Pushing NEW chars to the MAX7456
354
#if (WRITECHARS != -1)
394
#if (WRITECHARS != -1)
355
    // DISABLE display (VM0)
395
    // DISABLE display (VM0)
356
    spi_send_byte(0x00, 0b00000000);
396
    spi_send_byte(0x00, 0b00000000);
357
#include "characters.c"
397
    #include "characters.c"
358
 
-
 
359
#endif 
398
#endif
Line 360... Line 399...
360
 
399
 
361
    // Setup Video Mode
400
    // Setup Video Mode
362
    if (COSD_FLAGS & COSD_FLAG_NTSC) {
401
    if (COSD_FLAGS & COSD_FLAG_NTSC) {
Line 404... Line 443...
404
    write_all_chars();
443
    write_all_chars();
405
#else
444
#else
406
        // clear serial screen
445
    // clear serial screen
407
        //usart1_puts("\x1B[2J\x1B[H");
446
    //usart1_puts("\x1B[2J\x1B[H");
408
        //usart1_puts("hello world!\r\n");
447
    //usart1_puts("hello world!\r\n");
409
 
-
 
410
#if FCONLY
448
#if FCONLY
411
        // request data ever 100ms from FC;
449
    // request data ever 100ms from FC;
412
        usart1_request_mk_data(0, 'd', 100);
450
    usart1_request_mk_data(0, 'd', 100);
413
#else
451
#else
414
        // request OSD Data from NC every 100ms
452
    // request OSD Data from NC every 100ms
Line 460... Line 498...
460
            if (COSD_FLAGS & COSD_FLAG_HUD) {
498
            if (COSD_FLAGS & COSD_FLAG_HUD) {
461
#if FCONLY
499
#if FCONLY
462
                if (rxd_buffer[2] == 'D') { // FC Data
500
                if (rxd_buffer[2] == 'D') { // FC Data
463
                    Decode64();
501
                    Decode64();
464
                    debugData = *((DebugOut_t*) pRxData);
502
                    debugData = *((DebugOut_t*) pRxData);
-
 
503
 
-
 
504
                    // init on first data retrival, distinguished by last battery :)
465
                                        write_ascii_string(2,  2, "FCONLY MODE");
505
                    if (last_UBat == 255) {
-
 
506
                        auto_config(debugData.Analog[9], &min_UBat);
-
 
507
                    }
Line 466... Line 508...
466
 
508
 
467
                                        write_ndigit_number_u(7, top_line, debugData.Analog[10], 100, 0);
509
                    write_ndigit_number_u(7, top_line, debugData.Analog[10], 100, 0);
468
                                        if (debugData.Analog[10] <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) {
510
                    if (debugData.Analog[10] <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) {
469
                                            for (uint8_t x = 0; x < 4; x++)
511
                        for (uint8_t x = 0; x < 4; x++)
Line 481... Line 523...
481
                                } else {
523
                    } else {
482
                                    // up to 10m write meters.dm
524
                        // up to 10m write meters.dm
483
                                                write_ndigit_number_s_10th(23, top_line, debugData.Analog[5] / 3, 100, 0);
525
                        write_ndigit_number_s_10th(23, top_line, debugData.Analog[5] / 3, 100, 0);
484
                                        }
526
                    }
Line -... Line 527...
-
 
527
 
-
 
528
                    if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) {
-
 
529
                        draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll);
-
 
530
                    }
485
 
531
 
486
                                        draw_battery(2, bottom_line, min_voltage, debugData.Analog[9], max_voltage);
532
                    draw_battery(2, bottom_line, min_voltage, debugData.Analog[9], max_voltage);
487
                                        write_ndigit_number_u_10th(3, bottom_line, debugData.Analog[9], 100, 0);
533
                    write_ndigit_number_u_10th(3, bottom_line, debugData.Analog[9], 100, 0);
488
                    if (debugData.Analog[9] <= min_voltage && last_UBat > min_voltage) {
534
                    if (debugData.Analog[9] <= min_voltage && last_UBat > min_voltage) {
489
                        for (uint8_t x = 2; x < 8; x++)
535
                        for (uint8_t x = 2; x < 8; x++)
Line 509... Line 555...
509
                                if (rxd_buffer[2] == 'O') { // NC OSD Data
555
                if (rxd_buffer[2] == 'O') { // NC OSD Data
510
                    Decode64();
556
                    Decode64();
511
                    naviData = *((NaviData_t*) pRxData);
557
                    naviData = *((NaviData_t*) pRxData);
Line 512... Line 558...
512
                                       
558
 
513
                                        // init on first data retrival, distinguished by last battery :)
-
 
514
                                        // TODO: this is testing stuff, strings should go progmem and so on...
559
                    // init on first data retrival, distinguished by last battery :)
515
                                        if (last_UBat == 255) {
-
 
516
                                                clear();
560
                    if (last_UBat == 255) {
517
                                                // fix for min_bat glitch caused by data only gathered during motors up
-
 
518
                                                min_UBat = naviData.UBat;
-
 
519
                                                write_ascii_string(2,  2, "C-OSD Initialisation");
-
 
520
                                                uint8_t cellnum = 0;
-
 
521
                                                if (CELL_NUM == -1) {
-
 
522
                                                        write_ascii_string(2,  5, "Guessing Number of Cells");
-
 
523
                                                        do {
-
 
524
                                                                cellnum++;
-
 
525
                                                        } while (naviData.UBat > ((cellnum * CELL_VOLT_MAX) + 10));
-
 
526
                                                } else {
-
 
527
                                                        cellnum = CELL_NUM;
-
 
528
                                                }
-
 
529
                                                min_voltage = cellnum * CELL_VOLT_MIN;
-
 
530
                                                max_voltage = cellnum * CELL_VOLT_MAX;
-
 
531
                                                write_ascii_string(2,  7, "Number of Cells:");
-
 
532
                                                write_ndigit_number_u(21, 7, cellnum, 1, 0);
-
 
533
                                                write_ascii_string(2,  8, "Warn Voltage   :");
-
 
534
                                                write_ndigit_number_s_10th(20, 8, min_voltage, 100, 0);
-
 
535
                                                write_ascii_string(2,  9, "Max Voltage    :");
-
 
536
                                                write_ndigit_number_s_10th(20, 9, max_voltage, 100, 0);
-
 
537
                                                _delay_ms(200);
-
 
538
                                                clear();
-
 
539
                                                // update flags to paint display again because of clear
-
 
540
                                                COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
561
                        auto_config(naviData.UBat, &min_UBat);
Line 541... Line 562...
541
                                        }
562
                    }
542
 
563