0,0 → 1,332 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
*****************************************************************************/ |
|
// @TODO: maybe choose a smaler font for the debug data. 6x6 or 6x7 would be nice and gives some additional space for status lines |
|
#include <avr/io.h> |
#include <avr/pgmspace.h> |
#include <util/delay.h> |
#include <string.h> |
|
#include "main.h" |
#include "menu.h" |
#include "lcd.h" |
#include "usart.h" |
#include "debug.h" |
#include "timer.h" |
|
#include "mk-data-structs.h" |
|
#define TIMEOUT 200 // 2 sec |
#define ANALOGTIME 20 // 200 ms |
|
// WARNING: this work for NC & FC only |
// if current_hardware == MK3MAG or MKGPS the access is outside of the array... |
#if defined (__AVR_ATmega32__) |
uint8_t AnalogNames[32][16 + 1]; // 32 names, 16 characters + 1 0x00 |
uint8_t AnalogNamesRead = 0; |
// um noch mehr Speicherplatz zu sparen, könnte man auch nur die jeweils benötigten Labels anfordern... |
#else |
uint8_t AnalogNames[2][32][16 + 1]; // 32 names, 16 characters + 1 0x00 |
uint8_t AnalogNamesRead[2] = {0,0}; |
#endif |
|
//***************************************************************************** |
// |
void GetAnalogNames (void) |
{ |
#if defined (__AVR_ATmega32__) |
uint8_t i = AnalogNamesRead; |
#else |
uint8_t i = AnalogNamesRead[current_hardware - 1]; |
#endif |
uint8_t t = 0; |
|
lcd_cls (); |
lcd_printp_at (0, 3, PSTR("Reading"), 0); |
lcd_printp_at (0, 4, PSTR("Analog Names: "), 0); |
|
mode = 'A'; // read Names |
_delay_ms(200); |
rxd_buffer_locked = FALSE; |
|
timer = ANALOGTIME; |
|
while (i < 32) |
{ |
SendOutData ('a', ADDRESS_ANY, 1, &i, 1); |
while (!rxd_buffer_locked && timer); |
if (timer) |
{ |
Decode64 (); |
if (i == *pRxData) |
{ |
write_ndigit_number_u(14, 4, i, 2, 0); |
#if defined (__AVR_ATmega32__) |
memcpy (AnalogNames[*pRxData], (uint8_t *) pRxData + 1, 16); |
AnalogNames[*pRxData][16] = 0; |
#else |
memcpy (AnalogNames[current_hardware - 1][*pRxData], (uint8_t *) pRxData + 1, 16); |
AnalogNames[current_hardware - 1][*pRxData][16] = 0; |
#endif |
i++; |
t = 0; |
} |
else |
{ |
_delay_ms (100); |
} |
|
timer = ANALOGTIME; |
rxd_buffer_locked = FALSE; |
} |
else |
{ // timeout occured |
t++; |
timer = ANALOGTIME; |
|
if (t >= 50) |
{ |
lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0); |
|
timer = 100; |
while (timer > 0); |
break; |
} |
} |
} |
|
#if defined (__AVR_ATmega32__) |
AnalogNamesRead = i; |
#else |
AnalogNamesRead[current_hardware - 1] = i; |
#endif |
|
#if 0 |
if (timer) |
{ |
for (page = 0; page < 4; page++) |
{ |
for (i = 0; i < 7; i++) |
{ |
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
} |
while (!get_key_press (1 << KEY_ESC)); // ESC |
} |
} |
//return; |
#endif |
} |
|
|
//***************************************************************************** |
// |
void display_debug (void) |
{ |
uint8_t i = 0; |
uint8_t tmp_dat; |
uint8_t page = 0; |
|
DebugData_t *DebugData; |
|
lcd_cls (); |
|
timer = TIMEOUT; |
|
#if defined (__AVR_ATmega32__) |
if (AnalogNamesRead < 32) { |
#else |
if (AnalogNamesRead[current_hardware - 1] < 32) { |
#endif |
GetAnalogNames (); |
} |
|
if (!timer) |
{ |
return; |
} |
|
mode = 'D'; // Debug Data |
rxd_buffer_locked = FALSE; |
timer = TIMEOUT; |
|
tmp_dat = 10; |
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
abo_timer = ABO_TIMEOUT; |
|
for (i = 0; i < 8; i++) |
{ |
#if defined (__AVR_ATmega32__) |
lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
#else |
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
#endif |
} |
|
do |
{ |
if (rxd_buffer_locked) |
{ |
Decode64 (); |
DebugData = (DebugData_t *) pRxData; |
|
//lcd_printp_at (0,6,PSTR("Page"),0); |
lcd_write_number_u_at (20, 0, page); |
switch (current_hardware) |
{ |
case FC: |
lcd_printp_at (20, 1, PSTR("F"), 0); |
break; |
|
case NC: |
lcd_printp_at (20, 1, PSTR("N"), 0); |
break; |
|
default: |
lcd_printp_at (20, 1, PSTR("?"), 0); |
break; |
} |
|
|
for (i = 0; i < 8; i++) |
{ |
//lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
if (current_hardware == NC) |
{ |
write_ndigit_number_u (14, i, DebugData->Analog[i + page * 8], 5, 0); |
} |
else |
{ |
write_ndigit_number_s (14, i, DebugData->Analog[i + page * 8], 5, 0); |
} |
} |
timer = TIMEOUT; |
rxd_buffer_locked = FALSE; |
} |
|
if (!abo_timer) |
{ // renew abo every 3 sec |
// request OSD Data from NC every 100ms |
// RS232_request_mk_data (1, 'o', 100); |
tmp_dat = 10; |
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
|
abo_timer = ABO_TIMEOUT; |
} |
|
if (get_key_press (1 << KEY_MINUS)) |
{ |
page--; |
page &= 0x03; |
lcd_cls (); |
for (i = 0; i < 8; i++) |
{ |
#if defined (__AVR_ATmega32__) |
lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
#else |
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
#endif |
} |
} |
else if (get_key_press (1 << KEY_PLUS)) |
{ |
page++; |
page &= 0x03; |
lcd_cls (); |
for (i = 0; i < 8; i++) |
{ |
#if defined (__AVR_ATmega32__) |
lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
#else |
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
#endif |
} |
} |
|
if ((hardware == NC) && get_key_press (1 << KEY_ENTER)) |
{ |
tmp_dat = 0; |
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
|
_delay_ms (200); |
|
if (current_hardware == NC) |
{ |
SwitchToFC(); |
|
timer = TIMEOUT; |
//lcd_printpns_at (0, 7, PSTR(" \x1c \x1d Exit NC"), 0); |
} |
else |
{ |
SwitchToNC(); |
|
timer = TIMEOUT; |
//lcd_printpns_at (0, 7, PSTR(" \x1c \x1d Exit FC"), 0); |
} |
|
_delay_ms (200); |
|
#if defined (__AVR_ATmega32__) |
AnalogNamesRead = 0; |
GetAnalogNames (); |
#else |
if (AnalogNamesRead[current_hardware - 1] < 32) { |
GetAnalogNames (); |
} |
#endif |
|
mode = 'D'; // Debug Data |
rxd_buffer_locked = FALSE; |
timer = TIMEOUT; |
|
tmp_dat = 10; |
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
|
lcd_cls (); |
page = 0; |
|
for (i = 0; i < 8; i++) |
{ |
#if defined (__AVR_ATmega32__) |
lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
#else |
lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
#endif |
} |
} |
} |
while (!get_key_press (1 << KEY_ESC) && timer); // ESC |
|
tmp_dat = 0; |
SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
|
mode = 0; |
rxd_buffer_locked = FALSE; |
|
if (!timer) |
{ // timeout occured |
lcd_cls (); |
lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0); |
|
timer = 100; |
while (timer > 0); |
} |
} |