Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
730 | 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 | #if defined (__AVR_ATmega32__) |
||
43 | uint8_t AnalogNames[32][16 + 1]; // 32 names, 16 characters + 1 0x00 |
||
44 | uint8_t AnalogNamesRead = 0; |
||
45 | // um noch mehr Speicherplatz zu sparen, könnte man auch nur die jeweils benötigten Labels anfordern... |
||
46 | #else |
||
47 | uint8_t AnalogNames[2][32][16 + 1]; // 32 names, 16 characters + 1 0x00 |
||
48 | uint8_t AnalogNamesRead[2] = {0,0}; |
||
49 | #endif |
||
50 | |||
51 | //***************************************************************************** |
||
52 | // |
||
53 | void GetAnalogNames (void) |
||
54 | { |
||
55 | #if defined (__AVR_ATmega32__) |
||
56 | uint8_t i = AnalogNamesRead; |
||
57 | #else |
||
58 | uint8_t i = AnalogNamesRead[current_hardware - 1]; |
||
59 | #endif |
||
60 | uint8_t t = 0; |
||
61 | |||
62 | lcd_cls (); |
||
63 | lcd_printp_at (0, 3, PSTR("Reading"), 0); |
||
64 | lcd_printp_at (0, 4, PSTR("Analog Names: "), 0); |
||
65 | |||
66 | mode = 'A'; // read Names |
||
67 | _delay_ms(200); |
||
68 | rxd_buffer_locked = FALSE; |
||
69 | |||
70 | timer = ANALOGTIME; |
||
71 | |||
72 | while (i < 32) |
||
73 | { |
||
74 | SendOutData ('a', ADDRESS_ANY, 1, &i, 1); |
||
75 | while (!rxd_buffer_locked && timer); |
||
76 | if (timer) |
||
77 | { |
||
78 | Decode64 (); |
||
79 | if (i == *pRxData) |
||
80 | { |
||
81 | write_ndigit_number_u(14, 4, i, 2, 0); |
||
82 | #if defined (__AVR_ATmega32__) |
||
83 | memcpy (AnalogNames[*pRxData], (uint8_t *) pRxData + 1, 16); |
||
84 | AnalogNames[*pRxData][16] = 0; |
||
85 | #else |
||
86 | memcpy (AnalogNames[current_hardware - 1][*pRxData], (uint8_t *) pRxData + 1, 16); |
||
87 | AnalogNames[current_hardware - 1][*pRxData][16] = 0; |
||
88 | #endif |
||
89 | i++; |
||
90 | t = 0; |
||
91 | } |
||
92 | else |
||
93 | { |
||
94 | _delay_ms (100); |
||
95 | } |
||
96 | |||
97 | timer = ANALOGTIME; |
||
98 | rxd_buffer_locked = FALSE; |
||
99 | } |
||
100 | else |
||
101 | { // timeout occured |
||
102 | t++; |
||
103 | timer = ANALOGTIME; |
||
104 | |||
105 | if (t >= 50) |
||
106 | { |
||
107 | lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0); |
||
108 | |||
109 | timer = 100; |
||
110 | while (timer > 0); |
||
111 | break; |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | |||
116 | #if defined (__AVR_ATmega32__) |
||
117 | AnalogNamesRead = i; |
||
118 | #else |
||
119 | AnalogNamesRead[current_hardware - 1] = i; |
||
120 | #endif |
||
121 | |||
122 | #if 0 |
||
123 | if (timer) |
||
124 | { |
||
125 | for (page = 0; page < 4; page++) |
||
126 | { |
||
127 | for (i = 0; i < 7; i++) |
||
128 | { |
||
129 | lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
||
130 | } |
||
131 | while (!get_key_press (1 << KEY_ESC)); // ESC |
||
132 | } |
||
133 | } |
||
134 | //return; |
||
135 | #endif |
||
136 | } |
||
137 | |||
138 | |||
139 | //***************************************************************************** |
||
140 | // |
||
141 | void display_debug (void) |
||
142 | { |
||
143 | uint8_t i = 0; |
||
144 | uint8_t tmp_dat; |
||
145 | uint8_t page = 0; |
||
146 | |||
147 | DebugData_t *DebugData; |
||
148 | |||
149 | lcd_cls (); |
||
150 | |||
151 | timer = TIMEOUT; |
||
152 | |||
153 | #if defined (__AVR_ATmega32__) |
||
154 | if (AnalogNamesRead < 32) { |
||
155 | #else |
||
156 | if (AnalogNamesRead[current_hardware - 1] < 32) { |
||
157 | #endif |
||
158 | GetAnalogNames (); |
||
159 | } |
||
160 | |||
161 | if (!timer) |
||
162 | { |
||
163 | return; |
||
164 | } |
||
165 | |||
166 | mode = 'D'; // Debug Data |
||
167 | rxd_buffer_locked = FALSE; |
||
168 | timer = TIMEOUT; |
||
169 | |||
170 | tmp_dat = 10; |
||
171 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
172 | abo_timer = ABO_TIMEOUT; |
||
173 | |||
174 | for (i = 0; i < 8; i++) |
||
175 | { |
||
176 | #if defined (__AVR_ATmega32__) |
||
177 | lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
||
178 | #else |
||
179 | lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
||
180 | #endif |
||
181 | } |
||
182 | |||
183 | do |
||
184 | { |
||
185 | if (rxd_buffer_locked) |
||
186 | { |
||
187 | Decode64 (); |
||
188 | DebugData = (DebugData_t *) pRxData; |
||
189 | |||
190 | //lcd_printp_at (0,6,PSTR("Page"),0); |
||
191 | lcd_write_number_u_at (20, 0, page); |
||
192 | switch (current_hardware) |
||
193 | { |
||
194 | case FC: |
||
195 | lcd_printp_at (20, 1, PSTR("F"), 0); |
||
196 | break; |
||
197 | |||
198 | case NC: |
||
199 | lcd_printp_at (20, 1, PSTR("N"), 0); |
||
200 | break; |
||
201 | |||
202 | default: |
||
203 | lcd_printp_at (20, 1, PSTR("?"), 0); |
||
204 | break; |
||
205 | } |
||
206 | |||
207 | |||
208 | for (i = 0; i < 8; i++) |
||
209 | { |
||
210 | //lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
||
211 | if (current_hardware == NC) |
||
212 | { |
||
213 | write_ndigit_number_u (14, i, DebugData->Analog[i + page * 8], 5, 0); |
||
214 | } |
||
215 | else |
||
216 | { |
||
217 | write_ndigit_number_s (14, i, DebugData->Analog[i + page * 8], 5, 0); |
||
218 | } |
||
219 | } |
||
220 | timer = TIMEOUT; |
||
221 | rxd_buffer_locked = FALSE; |
||
222 | } |
||
223 | |||
224 | if (!abo_timer) |
||
225 | { // renew abo every 3 sec |
||
226 | // request OSD Data from NC every 100ms |
||
227 | // RS232_request_mk_data (1, 'o', 100); |
||
228 | tmp_dat = 10; |
||
229 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
230 | |||
231 | abo_timer = ABO_TIMEOUT; |
||
232 | } |
||
233 | |||
234 | if (get_key_press (1 << KEY_MINUS)) |
||
235 | { |
||
236 | page--; |
||
237 | page &= 0x03; |
||
238 | lcd_cls (); |
||
239 | for (i = 0; i < 8; i++) |
||
240 | { |
||
241 | #if defined (__AVR_ATmega32__) |
||
242 | lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
||
243 | #else |
||
244 | lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
||
245 | #endif |
||
246 | } |
||
247 | } |
||
248 | else if (get_key_press (1 << KEY_PLUS)) |
||
249 | { |
||
250 | page++; |
||
251 | page &= 0x03; |
||
252 | lcd_cls (); |
||
253 | for (i = 0; i < 8; i++) |
||
254 | { |
||
255 | #if defined (__AVR_ATmega32__) |
||
256 | lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
||
257 | #else |
||
258 | lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
||
259 | #endif |
||
260 | } |
||
261 | } |
||
262 | |||
263 | if ((hardware == NC) && get_key_press (1 << KEY_ENTER)) |
||
264 | { |
||
265 | tmp_dat = 0; |
||
266 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
267 | |||
268 | _delay_ms (200); |
||
269 | |||
270 | if (current_hardware == NC) |
||
271 | { |
||
272 | SwitchToFC(); |
||
273 | |||
274 | timer = TIMEOUT; |
||
275 | //lcd_printpns_at (0, 7, PSTR(" \x1c \x1d Exit NC"), 0); |
||
276 | } |
||
277 | else |
||
278 | { |
||
279 | SwitchToNC(); |
||
280 | |||
281 | timer = TIMEOUT; |
||
282 | //lcd_printpns_at (0, 7, PSTR(" \x1c \x1d Exit FC"), 0); |
||
283 | } |
||
284 | |||
285 | _delay_ms (200); |
||
286 | |||
287 | #if defined (__AVR_ATmega32__) |
||
288 | AnalogNamesRead = 0; |
||
289 | GetAnalogNames (); |
||
290 | #else |
||
291 | if (AnalogNamesRead[current_hardware - 1] < 32) { |
||
292 | GetAnalogNames (); |
||
293 | } |
||
294 | #endif |
||
295 | |||
296 | mode = 'D'; // Debug Data |
||
297 | rxd_buffer_locked = FALSE; |
||
298 | timer = TIMEOUT; |
||
299 | |||
300 | tmp_dat = 10; |
||
301 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
302 | |||
303 | lcd_cls (); |
||
304 | page = 0; |
||
305 | |||
306 | for (i = 0; i < 8; i++) |
||
307 | { |
||
308 | #if defined (__AVR_ATmega32__) |
||
309 | lcd_print_at (0, i, AnalogNames[i + page * 8], 0); |
||
310 | #else |
||
311 | lcd_print_at (0, i, AnalogNames[current_hardware - 1][i + page * 8], 0); |
||
312 | #endif |
||
313 | } |
||
314 | } |
||
315 | } |
||
316 | while (!get_key_press (1 << KEY_ESC) && timer); // ESC |
||
317 | |||
318 | tmp_dat = 0; |
||
319 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
320 | |||
321 | mode = 0; |
||
322 | rxd_buffer_locked = FALSE; |
||
323 | |||
324 | if (!timer) |
||
325 | { // timeout occured |
||
326 | lcd_cls (); |
||
327 | lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0); |
||
328 | |||
329 | timer = 100; |
||
330 | while (timer > 0); |
||
331 | } |
||
332 | } |