Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1053 - 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
4
 *                                                                           *
5
 *   This program is free software; you can redistribute it and/or modify    *
6
 *   it under the terms of the GNU General Public License as published by    *
7
 *   the Free Software Foundation; either version 2 of the License.          *
8
 *                                                                           *
9
 *   This program is distributed in the hope that it will be useful,         *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
12
 *   GNU General Public License for more details.                            *
13
 *                                                                           *
14
 *   You should have received a copy of the GNU General Public License       *
15
 *   along with this program; if not, write to the                           *
16
 *   Free Software Foundation, Inc.,                                         *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
18
 *                                                                           *
19
 *****************************************************************************/
20
 
21
// @TODO: maybe choose a smaler font for the debug data. 6x6 or 6x7 would be nice and gives some additional space for status lines
22
 
23
#include <avr/io.h>
24
#include <avr/pgmspace.h>
25
#include <util/delay.h>
26
#include <string.h>
27
 
28
#include "main.h"
29
#include "menu.h"
30
#include "lcd.h"
31
#include "usart.h"
32
#include "debug.h"
33
#include "timer.h"
34
 
35
#include "mk-data-structs.h"
36
 
37
#define TIMEOUT 200             // 2 sec
38
#define ANALOGTIME 20   // 200 ms
39
 
40
// WARNING: this work for NC & FC only
41
//          if current_hardware == MK3MAG or MKGPS the access is outside of the array...
42
uint8_t AnalogNames[2][32][16 + 1];     // 32 names, 16 characters + 1 0x00
43
uint8_t AnalogNamesRead[2] = {0,0};
44
 
45
//*****************************************************************************
46
// 
47
void GetAnalogNames (void)
48
{
49
        uint8_t i = AnalogNamesRead[current_hardware - 1];
50
        uint8_t t = 0;
51
 
52
        lcd_cls ();
53
        lcd_printp_at (0, 3, PSTR("Reading"), 0);
54
        lcd_printp_at (0, 4, PSTR("Analog Names: "), 0);
55
 
56
        mode = 'A';     // read Names
57
        _delay_ms(200);
58
        rxd_buffer_locked = FALSE;
59
 
60
        timer = ANALOGTIME;
61
 
62
        while (i < 32)
63
        {
64
                SendOutData ('a', ADDRESS_ANY, 1, &i, 1);
65
                while (!rxd_buffer_locked && timer);
66
                if (timer)
67
                {
68
                        Decode64 ();
69
                        if (i == *pRxData)
70
                        {
71
                                write_ndigit_number_u(14, 4, i, 2, 0);
72
                                memcpy (AnalogNames[current_hardware - 1][*pRxData], (uint8_t *) pRxData + 1, 16);
73
                                AnalogNames[current_hardware - 1][*pRxData][16] = 0;
74
                                i++;
75
                                t = 0;
76
                        }
77
                        else
78
                        {
79
                                _delay_ms (100);
80
                        }
81
 
82
                        timer = ANALOGTIME;
83
                        rxd_buffer_locked = FALSE;
84
                }
85
                else
86
                {       // timeout occured
87
                        t++;
88
                        timer = ANALOGTIME;
89
 
90
                        if (t >= 50)
91
                        {
92
                                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
93
 
94
                                timer = 100;
95
                                while (timer > 0);
96
                                break;
97
                        }
98
                }
99
        }
100
 
101
        AnalogNamesRead[current_hardware - 1] = i;
102
 
103
#if 0
104
        if (timer)
105
        {
106
                for (page = 0; page < 4; page++)
107
                {
108
                        for (i = 0; i < 7; i++)
109
                        {
110
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
111
                        }
112
                        while (!get_key_press (1 << KEY_ESC));  // ESC
113
                }
114
        }
115
        //return;
116
#endif
117
}
118
 
119
 
120
//*****************************************************************************
121
// 
122
void display_debug (void)
123
{
124
        uint8_t i = 0;
125
        uint8_t tmp_dat;
126
        uint8_t page = 0;
127
 
128
        DebugData_t *DebugData;
129
 
130
        lcd_cls ();
131
 
132
        timer = TIMEOUT;
133
 
134
        if (AnalogNamesRead[current_hardware - 1] < 32) {
135
                GetAnalogNames ();
136
        }
137
 
138
        if (!timer)
139
        {
140
                return;
141
        }
142
 
143
        mode = 'D';     // Debug Data
144
        rxd_buffer_locked = FALSE;
145
        timer = TIMEOUT;
146
 
147
        tmp_dat = 10;
148
        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
149
        abo_timer = ABO_TIMEOUT;
150
 
151
        for (i = 0; i < 8; i++)
152
        {
153
                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
154
        }
155
 
156
        do
157
        {
158
                if (rxd_buffer_locked)
159
                {
160
                        Decode64 ();
161
                        DebugData = (DebugData_t *) pRxData;
162
 
163
                        //lcd_printp_at (0,6,PSTR("Page"),0);
164
                        lcd_write_number_u_at (20, 0, page);
165
                        switch (current_hardware)
166
                        {
167
                                case FC:
168
                                        lcd_printp_at (20, 1, PSTR("F"), 0);
169
                                        break;
170
 
171
                                case NC:
172
                                        lcd_printp_at (20, 1, PSTR("N"), 0);
173
                                        break;
174
 
175
                                default:
176
                                        lcd_printp_at (20, 1, PSTR("?"), 0);
177
                                        break;
178
                        }
179
 
180
 
181
                        for (i = 0; i < 8; i++)
182
                        {
183
                                //lcd_print_at (0, i, AnalogNames[i + page * 8], 0);
184
/*                              if (current_hardware == NC)
185
                                {
186
                                        write_ndigit_number_u (14, i, DebugData->Analog[i + page * 8], 5, 0);
187
                                }
188
                                else
189
                                {*/
190
                                        uint8_t size =0;
191
 
192
                                        if( DebugData->Analog[i + page * 8] < -9999)
193
                                        {
194
                                                size = 7;
195
                                        }
196
                                        else if ( DebugData->Analog[i + page * 8] < -999)
197
                                        {
198
                                                size = 6;
199
                                        }
200
                                        else if ( DebugData->Analog[i + page * 8] < -99)
201
                                        {
202
                                                size = 5;
203
                                        }
204
                                        else if ( DebugData->Analog[i + page * 8] < 999)
205
                                        {
206
                                                size = 4;
207
                                        }
208
                                        else if ( DebugData->Analog[i + page * 8] < 9999)
209
                                        {
210
                                                size = 5;
211
                                        }
212
                                        else
213
                                        {
214
                                                size = 6;
215
                                        }
216
                                                write_ndigit_number_s (19-size, i, DebugData->Analog[i + page * 8], size, 0);
217
                                /*}*/
218
                        }
219
                        timer = TIMEOUT;
220
                        rxd_buffer_locked = FALSE;
221
                }
222
 
223
                if (!abo_timer)
224
                {       // renew abo every 3 sec
225
                        // request OSD Data from NC every 100ms
226
                        //      RS232_request_mk_data (1, 'o', 100);
227
                        tmp_dat = 10;
228
                        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
229
 
230
                        abo_timer = ABO_TIMEOUT;
231
                }
232
 
233
                if (get_key_press (1 << KEY_MINUS))
234
                {
235
                        page--;
236
                        page &= 0x03;
237
                        lcd_cls ();
238
                        for (i = 0; i < 8; i++)
239
                        {
240
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
241
                        }
242
                }
243
                else if (get_key_press (1 << KEY_PLUS))
244
                {
245
                        page++;
246
                        page &= 0x03;
247
                        lcd_cls ();
248
                        for (i = 0; i < 8; i++)
249
                        {
250
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
251
                        }
252
                }
253
 
254
                if ((hardware == NC) && get_key_press (1 << KEY_ENTER))
255
                {
256
                        tmp_dat = 0;
257
                        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
258
 
259
                        _delay_ms (200);
260
 
261
                        if (current_hardware == NC)
262
                        {
263
                                SwitchToFC();
264
 
265
                                timer = TIMEOUT;
266
                                //lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  NC"), 0);
267
                        }
268
                        else
269
                        {
270
                                SwitchToNC();
271
 
272
                                timer = TIMEOUT;
273
                                //lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  FC"), 0);
274
                        }
275
 
276
                        _delay_ms (200);
277
 
278
                        if (AnalogNamesRead[current_hardware - 1] < 32) {
279
                                GetAnalogNames ();
280
                        }
281
 
282
                        mode = 'D';     // Debug Data
283
                        rxd_buffer_locked = FALSE;
284
                        timer = TIMEOUT;
285
 
286
                        tmp_dat = 10;
287
                        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
288
 
289
                        lcd_cls ();
290
                        page = 0;
291
 
292
                        for (i = 0; i < 8; i++)
293
                        {
294
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
295
                        }
296
                }
297
        }
298
        while (!get_key_press (1 << KEY_ESC) && timer); // ESC
299
 
300
        tmp_dat = 0;
301
        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
302
 
303
        mode = 0;
304
        rxd_buffer_locked = FALSE;
305
 
306
        if (!timer)
307
        {       // timeout occured
308
                lcd_cls ();
309
                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
310
 
311
                timer = 100;
312
                while (timer > 0);
313
        }
314
        SwitchToNC();
315
}