Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
724 woggle 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
// 
48
void GetAnalogNames (void)
49
{
50
        uint8_t i = AnalogNamesRead[current_hardware - 1];
51
        uint8_t t = 0;
52
 
53
        lcd_cls ();
54
        lcd_printp_at (0, 3, PSTR("Reading"), 0);
55
        lcd_printp_at (0, 4, PSTR("Analog Names: "), 0);
56
 
57
        mode = 'A';     // read Names
58
        _delay_ms(200);
59
        rxd_buffer_locked = FALSE;
60
 
61
        timer = ANALOGTIME;
62
 
63
        while (i < 32)
64
        {
65
                SendOutData ('a', ADDRESS_ANY, 1, &i, 1);
66
                while (!rxd_buffer_locked && timer);
67
                if (timer)
68
                {
69
                        Decode64 ();
70
                        if (i == *pRxData)
71
                        {
72
                                write_ndigit_number_u(14, 4, i, 2, 0);
73
                                memcpy (AnalogNames[current_hardware - 1][*pRxData], (uint8_t *) pRxData + 1, 16);
74
                                AnalogNames[current_hardware - 1][*pRxData][16] = 0;
75
                                i++;
76
                                t = 0;
77
                        }
78
                        else
79
                        {
80
                                _delay_ms (100);
81
                        }
82
 
83
                        timer = ANALOGTIME;
84
                        rxd_buffer_locked = FALSE;
85
                }
86
                else
87
                {       // timeout occured
88
                        t++;
89
                        timer = ANALOGTIME;
90
 
91
                        if (t >= 50)
92
                        {
93
                                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
94
 
95
                                timer = 100;
96
                                while (timer > 0);
97
                                break;
98
                        }
99
                }
100
        }
101
 
102
        AnalogNamesRead[current_hardware - 1] = i;
103
 
104
#if 0
105
        if (timer)
106
        {
107
                for (page = 0; page < 4; page++)
108
                {
109
                        for (i = 0; i < 7; i++)
110
                        {
111
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
112
                        }
113
                        while (!get_key_press (1 << KEY_ESC));  // ESC
114
                }
115
        }
116
        //return;
117
#endif
118
}
119
 
120
 
121
//*****************************************************************************
122
// 
123
void display_debug (void)
124
{
125
        uint8_t i = 0;
126
        uint8_t tmp_dat;
127
        uint8_t page = 0;
128
 
129
        DebugData_t *DebugData;
130
 
131
        lcd_cls ();
132
 
133
        timer = TIMEOUT;
134
 
135
        if (AnalogNamesRead[current_hardware - 1] < 32) {
136
                GetAnalogNames ();
137
        }
138
 
139
        if (!timer)
140
        {
141
                return;
142
        }
143
 
144
        mode = 'D';     // Debug Data
145
        rxd_buffer_locked = FALSE;
146
        timer = TIMEOUT;
147
 
148
        tmp_dat = 10;
149
        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
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
                                        write_ndigit_number_s (14, i, DebugData->Analog[i + page * 8], 5, 0);
191
                                }
192
                        }
193
                        timer = TIMEOUT;
194
                        rxd_buffer_locked = FALSE;
195
                }
196
 
197
                if (get_key_press (1 << KEY_MINUS))
198
                {
199
                        page--;
200
                        page &= 0x03;
201
                        lcd_cls ();
202
                        for (i = 0; i < 8; i++)
203
                        {
204
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
205
                        }
206
                }
207
                else if (get_key_press (1 << KEY_PLUS))
208
                {
209
                        page++;
210
                        page &= 0x03;
211
                        lcd_cls ();
212
                        for (i = 0; i < 8; i++)
213
                        {
214
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
215
                        }
216
                }
217
 
218
                if ((hardware == NC) && get_key_press (1 << KEY_ENTER))
219
                {
220
                        tmp_dat = 0;
221
                        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
222
 
223
                        _delay_ms (200);
224
 
225
                        if (current_hardware == NC)
226
                        {
227
                                SwitchToFC();
228
 
229
                                timer = TIMEOUT;
230
                                //lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  NC"), 0);
231
                        }
232
                        else
233
                        {
234
                                SwitchToNC();
235
 
236
                                timer = TIMEOUT;
237
                                //lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  FC"), 0);
238
                        }
239
 
240
                        _delay_ms (200);
241
 
242
                        if (AnalogNamesRead[current_hardware - 1] < 32) {
243
                                GetAnalogNames ();
244
                        }
245
 
246
                        mode = 'D';     // Debug Data
247
                        rxd_buffer_locked = FALSE;
248
                        timer = TIMEOUT;
249
 
250
                        tmp_dat = 10;
251
                        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
252
 
253
                        lcd_cls ();
254
                        page = 0;
255
 
256
                        for (i = 0; i < 8; i++)
257
                        {
258
                                lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0);
259
                        }
260
                }
261
        }
262
        while (!get_key_press (1 << KEY_ESC) && timer); // ESC
263
 
264
        tmp_dat = 0;
265
        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
266
 
267
        mode = 0;
268
        rxd_buffer_locked = FALSE;
269
 
270
        if (!timer)
271
        {       // timeout occured
272
                lcd_cls ();
273
                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
274
 
275
                timer = 100;
276
                while (timer > 0);
277
        }
278
}