Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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