Blame |
Last modification |
View Log
| RSS feed
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* Copyright (C) 2011 Harald Bongartz *
* *
* 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. *
* *
* *
* Credits to: *
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN *
* http://www.mikrokopter.de *
* Gregor "killagreg" Stobrawa for his version of the MK code *
* Thomas Kaiser "thkais" for the original project. See *
* http://www.ft-fanpage.de/mikrokopter/ *
* http://forum.mikrokopter.de/topic-4061-1.html *
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
* http://www.mylifesucks.de/oss/c-osd/ *
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
*****************************************************************************/
#include "cpu.h"
#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 "messages.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...
uint8_t AnalogNames
[2][32][16 + 1]; // 32 names, 16 characters + 1 0x00
uint8_t AnalogNamesRead
[2] = {0,0};
//--------------------------------------------------------------
//
void GetAnalogNames
(void)
{
uint8_t i
= AnalogNamesRead
[current_hardware
- 1];
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);
memcpy (AnalogNames
[current_hardware
- 1][*pRxData
], (uint8_t *) pRxData
+ 1, 16);
AnalogNames
[current_hardware
- 1][*pRxData
][16] = 0;
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;
}
}
}
AnalogNamesRead
[current_hardware
- 1] = i
;
#if 0
if (timer
)
{
for (page
= 0; page
< 5; page
++)
{
for (i
= 0; i
< 7; i
++)
{
lcd_print_at
(0, i
, AnalogNames
[current_hardware
- 1][i
+ page
* 7], 0);
}
while (!get_key_press
(1 << KEY_ESC
)); // ESC
get_key_press
(KEY_ALL
);
}
}
//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 (AnalogNamesRead
[current_hardware
- 1] < 32)
{
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
< 7; i
++)
{
lcd_print_at
(0, i
, AnalogNames
[current_hardware
- 1][i
+ page
* 7], 0);
if (page
== 4 && i
> 3)
{
for (i
= 4; i
< 7; i
++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line
(0, i
, 21);
}
i
= 7;
}
}
do
{
if (rxd_buffer_locked
)
{
Decode64
();
DebugData
= (DebugData_t
*) pRxData
;
// lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0);
lcd_puts_at
(0, 7, strGet
(KEYLINE3
), 0);
lcd_write_number_u_at
(5, 7, page
+ 1);
switch (current_hardware
)
{
case FC
:
lcd_printp_at
(3, 7, PSTR
("FC"), 0);
lcd_printp_at
(19, 7, PSTR
("NC"), 0);
break;
case NC
:
lcd_printp_at
(3, 7, PSTR
("NC"), 0);
lcd_printp_at
(19, 7, PSTR
("FC"), 0);
break;
default:
lcd_printp_at
(19, 7, PSTR
("?"), 0);
break;
}
for (i
= 0; i
< 7; i
++)
{
//lcd_print_at (0, i, AnalogNames[i + page * 7], 0);
uint8_t size
=0;
if( DebugData
->Analog
[i
+ page
* 7] < -9999)
{
size
= 6;
}
else if ( DebugData
->Analog
[i
+ page
* 7] < -999)
{
size
= 5;
}
else if ( DebugData
->Analog
[i
+ page
* 7] < -99)
{
size
= 4;
}
else if ( DebugData
->Analog
[i
+ page
* 7] < 999)
{
size
= 3;
}
else if ( DebugData
->Analog
[i
+ page
* 7] < 9999)
{
size
= 4;
}
else
{
size
= 5;
}
write_ndigit_number_s
(21-size
, i
, DebugData
->Analog
[i
+ page
* 7], size
, 0);
if (page
== 4 && i
> 3)
{
for (i
= 4; i
< 7; i
++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line
(0, i
, 21);
}
i
= 7;
}
}
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
--;
if (page
> 4)
{
page
= 4;
}
lcd_cls
();
for (i
= 0; i
< 7; i
++)
{
lcd_print_at
(0, i
, AnalogNames
[current_hardware
- 1][i
+ page
* 7], 0);
if (page
== 4 && i
> 3)
{
for (i
= 4; i
< 7; i
++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line
(0, i
, 21);
}
i
= 7;
}
}
}
else if (get_key_press
(1 << KEY_PLUS
))
{
page
++;
if (page
> 4)
{
page
= 0;
}
lcd_cls
();
for (i
= 0; i
< 7; i
++)
{
lcd_print_at
(0, i
, AnalogNames
[current_hardware
- 1][i
+ page
* 7], 0);
if (page
== 4 && i
> 3)
{
for (i
= 4; i
< 7; i
++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line
(0, i
, 21);
}
i
= 7;
}
}
}
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
;
}
else
{
SwitchToNC
();
timer
= TIMEOUT
;
}
_delay_ms
(200);
if (AnalogNamesRead
[current_hardware
- 1] < 32)
{
GetAnalogNames
();
}
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
< 7; i
++)
{
lcd_print_at
(0, i
, AnalogNames
[current_hardware
- 1][i
+ page
* 7], 0);
if (page
== 4 && i
> 3)
{
for (i
= 4; i
< 7; i
++) // Linie 4, 5, 6 loeschen
{
lcd_cls_line
(0, i
, 21);
}
i
= 7;
}
}
}
}
while (!get_key_press
(1 << KEY_ESC
) && timer
); // ESC
get_key_press
(KEY_ALL
);
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);
}
SwitchToNC
();
}