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