Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
1932 - 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
 
36
#include "cpu.h"
37
#include <avr/io.h>
38
#include <avr/pgmspace.h>
39
#include <util/delay.h>
40
#include <string.h>
41
 
42
#include "main.h"
43
#ifdef analognames
44
//#include "menu.h"
45
#include "lcd/lcd.h"
46
#include "uart/usart.h"
47
#include "debug.h"
48
#include "timer/timer.h"
49
#include "messages.h"
50
 
51
#include "mk-data-structs.h"
52
 
53
 
54
#ifdef HWVERSION3_9
55
 
56
 
57
#define TIMEOUT 200             // 2 sec
58
#define ANALOGTIME 20   // 200 ms
59
 
60
// WARNING: this work for NC & FC only
61
//          if current_hardware == MK3MAG or MKGPS the access is outside of the array...
62
uint8_t AnalogNames[2][32][16 + 1];     // 32 names, 16 characters + 1 0x00
63
uint8_t AnalogNamesRead[2] = {0,0};
64
 
65
//--------------------------------------------------------------
66
//
67
void GetAnalogNames (void)
68
{
69
        uint8_t i = AnalogNamesRead[current_hardware - 1];
70
        uint8_t t = 0;
71
 
72
        lcd_cls ();
73
        lcd_printp_at (0, 3, PSTR("Reading"), 0);
74
        lcd_printp_at (0, 4, PSTR("Analog Names: "), 0);
75
 
76
        mode = 'A';     // read Names
77
        _delay_ms(200);
78
        rxd_buffer_locked = FALSE;
79
 
80
        timer = ANALOGTIME;
81
 
82
        while (i < 32)
83
        {
84
                SendOutData ('a', ADDRESS_ANY, 1, &i, 1);
85
                while (!rxd_buffer_locked && timer);
86
                if (timer)
87
                {
88
                        Decode64 ();
89
                        if (i == *pRxData)
90
                        {
91
                                write_ndigit_number_u(14, 4, i, 2, 0,0);
92
                                memcpy (AnalogNames[current_hardware - 1][*pRxData], (uint8_t *) pRxData + 1, 16);
93
                                AnalogNames[current_hardware - 1][*pRxData][16] = 0;
94
                                i++;
95
                                t = 0;
96
                        }
97
                        else
98
                        {
99
                                _delay_ms (100);
100
                        }
101
 
102
                        timer = ANALOGTIME;
103
                        rxd_buffer_locked = FALSE;
104
                }
105
                else
106
                {       // timeout occured
107
                        t++;
108
                        timer = ANALOGTIME;
109
 
110
                        if (t >= 50)
111
                        {
112
                                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
113
 
114
                                timer = 100;
115
                                while (timer > 0);
116
                                break;
117
                        }
118
                }
119
        }
120
 
121
        AnalogNamesRead[current_hardware - 1] = i;
122
 
123
#if 0
124
        if (timer)
125
        {
126
                for (page = 0; page < 5; page++)
127
                {
128
                        for (i = 0; i < 7; i++)
129
                        {
130
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
131
                        }
132
                        while (!get_key_press (1 << KEY_ESC));  // ESC
133
                                get_key_press(KEY_ALL);
134
                }
135
        }
136
        //return;
137
#endif
138
}
139
 
140
 
141
//--------------------------------------------------------------
142
//
143
void display_debug (void)
144
{
145
        uint8_t i = 0;
146
        uint8_t tmp_dat;
147
        uint8_t page = 0;
148
 
149
        DebugData_t *DebugData;
150
 
151
        lcd_cls ();
152
 
153
        timer = TIMEOUT;
154
 
155
        if (AnalogNamesRead[current_hardware - 1] < 32)
156
        {
157
                GetAnalogNames ();
158
        }
159
 
160
        if (!timer)
161
        {
162
                return;
163
        }
164
 
165
        mode = 'D';     // Debug Data
166
        rxd_buffer_locked = FALSE;
167
        timer = TIMEOUT;
168
 
169
        tmp_dat = 10;
170
        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
171
        abo_timer = ABO_TIMEOUT;
172
 
173
        for (i = 0; i < 7; i++)
174
        {
175
                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
176
                                if (page == 4 && i > 3)
177
                                {
178
                                        for (i = 4; i < 7; i++)   // Linie 4, 5, 6 loeschen
179
                                        {
180
                                                lcd_cls_line (0, i, 21);
181
                                        }
182
                                        i = 7;
183
                                }
184
        }
185
 
186
        do
187
        {
188
                if (rxd_buffer_locked)
189
                {
190
                        Decode64 ();
191
                        DebugData = (DebugData_t *) pRxData;
192
 
193
//                      lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0);
194
                        lcd_puts_at(0, 7, strGet(KEYLINE3), 0);
195
                        lcd_write_number_u_at (5, 7, page + 1);
196
                        switch (current_hardware)
197
                        {
198
                                case FC:
199
                                        lcd_printp_at (3, 7, PSTR("FC"), 0);
200
                                        lcd_printp_at (19, 7, PSTR("NC"), 0);
201
                                        break;
202
 
203
                                case NC:
204
                                        lcd_printp_at (3, 7, PSTR("NC"), 0);
205
                                        lcd_printp_at (19, 7, PSTR("FC"), 0);
206
                                        break;
207
 
208
                                default:
209
                                        lcd_printp_at (19, 7, PSTR("?"), 0);
210
                                        break;
211
                        }
212
 
213
                        for (i = 0; i < 7; i++)
214
                        {
215
                                //lcd_print_at (0, i, AnalogNames[i + page * 7], 0);
216
                                uint8_t size =0;
217
                                if( DebugData->Analog[i + page * 7] < -9999)
218
                                {
219
                                        size = 6;
220
                                }
221
                                else if ( DebugData->Analog[i + page * 7] < -999)
222
                                {
223
                                        size = 5;
224
                                }
225
                                else if ( DebugData->Analog[i + page * 7] < -99)
226
                                {
227
                                        size = 4;
228
                                }
229
                                else if ( DebugData->Analog[i + page * 7] < 999)
230
                                {
231
                                        size = 3;
232
                                }
233
                                else if ( DebugData->Analog[i + page * 7] < 9999)
234
                                {
235
                                        size = 4;
236
                                }
237
                                else
238
                                {
239
                                        size = 5;
240
                                }
241
                                        write_ndigit_number_s (21-size, i, DebugData->Analog[i + page * 7], size, 0,0);
242
                                if (page == 4 && i > 3)
243
                                {
244
                                        for (i = 4; i < 7; i++)   // Linie 4, 5, 6 loeschen
245
                                        {
246
                                                lcd_cls_line (0, i, 21);
247
                                        }
248
                                        i = 7;
249
                                }
250
                        }
251
                        timer = TIMEOUT;
252
                        rxd_buffer_locked = FALSE;
253
                }
254
 
255
                if (!abo_timer)
256
                {       // renew abo every 3 sec
257
                        // request OSD Data from NC every 100ms
258
                        //      RS232_request_mk_data (1, 'o', 100);
259
                        tmp_dat = 10;
260
                        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
261
 
262
                        abo_timer = ABO_TIMEOUT;
263
                }
264
 
265
                if (get_key_press (1 << KEY_MINUS))
266
                {
267
                        page--;
268
                        if (page > 4)
269
                        {
270
                                page = 4;
271
                        }
272
                        lcd_cls ();
273
                        for (i = 0; i < 7; i++)
274
                        {
275
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
276
                                if (page == 4 && i > 3)
277
                                {
278
                                        for (i = 4; i < 7; i++)   // Linie 4, 5, 6 loeschen
279
                                        {
280
                                                lcd_cls_line (0, i, 21);
281
                                        }
282
                                        i = 7;
283
                                }
284
                        }
285
                }
286
                else if (get_key_press (1 << KEY_PLUS))
287
                {
288
                        page++;
289
                        if (page > 4)
290
                        {
291
                                page = 0;
292
                        }
293
                        lcd_cls ();
294
                        for (i = 0; i < 7; i++)
295
                        {
296
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
297
                                if (page == 4 && i > 3)
298
                                {
299
                                        for (i = 4; i < 7; i++)   // Linie 4, 5, 6 loeschen
300
                                        {
301
                                                lcd_cls_line (0, i, 21);
302
                                        }
303
                                        i = 7;
304
                                }
305
                        }
306
                }
307
                if ((hardware == NC) && get_key_press (1 << KEY_ENTER))
308
                {
309
                        tmp_dat = 0;
310
                        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
311
 
312
                        _delay_ms (200);
313
 
314
                        if (current_hardware == NC)
315
                        {
316
                                SwitchToFC();
317
 
318
                                timer = TIMEOUT;
319
                        }
320
                        else
321
                        {
322
                                SwitchToNC();
323
 
324
                                timer = TIMEOUT;
325
                        }
326
 
327
                        _delay_ms (200);
328
 
329
                        if (AnalogNamesRead[current_hardware - 1] < 32)
330
                        {
331
                                GetAnalogNames ();
332
                        }
333
 
334
                        mode = 'D';     // Debug Data
335
                        rxd_buffer_locked = FALSE;
336
                        timer = TIMEOUT;
337
 
338
                        tmp_dat = 10;
339
                        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
340
 
341
                        lcd_cls ();
342
                        page = 0;
343
 
344
                        for (i = 0; i < 7; i++)
345
                        {
346
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 7], 0);
347
                                if (page == 4 && i > 3)
348
                                {
349
                                        for (i = 4; i < 7; i++)   // Linie 4, 5, 6 loeschen
350
                                        {
351
                                                lcd_cls_line (0, i, 21);
352
                                        }
353
                                        i = 7;
354
                                }
355
                        }
356
                }
357
        }
358
        while (!get_key_press (1 << KEY_ESC) && timer); // ESC
359
                get_key_press(KEY_ALL);
360
 
361
        tmp_dat = 0;
362
        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
363
 
364
        mode = 0;
365
        rxd_buffer_locked = FALSE;
366
 
367
        if (!timer)
368
        {       // timeout occured
369
                lcd_cls ();
370
                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
371
 
372
                timer = 100;
373
                while (timer > 0);
374
        }
375
        SwitchToNC();
376
}
377
#endif
378
#endif