Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1053 | - | 1 | /***************************************************************************** |
2 | * Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.net * |
||
3 | * * |
||
4 | * This program is free software; you can redistribute it and/or modify * |
||
5 | * it under the terms of the GNU General Public License as published by * |
||
6 | * the Free Software Foundation; either version 2 of the License. * |
||
7 | * * |
||
8 | * This program is distributed in the hope that it will be useful, * |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
11 | * GNU General Public License for more details. * |
||
12 | * * |
||
13 | * You should have received a copy of the GNU General Public License * |
||
14 | * along with this program; if not, write to the * |
||
15 | * Free Software Foundation, Inc., * |
||
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
17 | * * |
||
18 | *****************************************************************************/ |
||
19 | |||
20 | #include <avr/io.h> |
||
21 | #include <inttypes.h> |
||
22 | #include <stdlib.h> |
||
23 | #include <avr/pgmspace.h> |
||
24 | #include <avr/wdt.h> |
||
25 | #include "main.h" |
||
26 | #include "lcd.h" |
||
27 | #include "parameter.h" |
||
28 | #include "menu.h" |
||
29 | #include "display.h" |
||
30 | #include "motortest.h" |
||
31 | |||
32 | #if defined HWVERSION3_1 || defined HWVERSION1_3 |
||
33 | #include "motortestI2C.h" |
||
34 | #endif |
||
35 | |||
36 | |||
37 | #include "debug.h" |
||
38 | #include "settings.h" |
||
39 | #include "timer.h" |
||
40 | #include "osd.h" |
||
41 | #include "gps.h" |
||
42 | #include "pwm.h" |
||
43 | #include "eeprom.h" |
||
44 | #include "setup.h" |
||
45 | #include "uart1.h" |
||
46 | //#include "jeti.h" |
||
47 | #include "mk-data-structs.h" |
||
48 | #include "Wi232.h" |
||
49 | |||
50 | |||
51 | |||
52 | |||
53 | #define ITEMS_NC 10 |
||
54 | |||
55 | prog_char param_menuitems_nc[ITEMS_NC][15]= // zeilen,zeichen+1 |
||
56 | { |
||
57 | "OSD ", |
||
58 | "3D Lage ", |
||
59 | "Display ", |
||
60 | "Parameters ", |
||
61 | "Debug Data ", |
||
62 | "Motor Test ", |
||
63 | "GPS Info ", |
||
64 | "Setup PMK ", |
||
65 | "Version ", |
||
66 | "USB to FC ", |
||
67 | |||
68 | |||
69 | }; |
||
70 | |||
71 | #define ITEMS_FC 7 |
||
72 | |||
73 | prog_char param_menuitems_fc[ITEMS_FC][15]= // zeilen,zeichen+1 |
||
74 | { |
||
75 | "Display ", |
||
76 | "Parameters ", |
||
77 | "Debug Data ", |
||
78 | "Motor Test ", |
||
79 | "Setup PMK ", |
||
80 | "Version ", |
||
81 | "USB to FC ", |
||
82 | |||
83 | |||
84 | }; |
||
85 | |||
86 | #define ITEMS_NO 6 |
||
87 | |||
88 | prog_char param_menuitems_no[ITEMS_NO][15]= // zeilen,zeichen+1 |
||
89 | { |
||
90 | "I2C Motortest", |
||
91 | "Setup PMK ", |
||
92 | "Version ", |
||
93 | "USB to FC ", |
||
94 | "Konfig Wi.232", |
||
95 | "PKT SW-Update", |
||
96 | |||
97 | }; |
||
98 | |||
99 | //***************************************************************************** |
||
100 | // print cursor |
||
101 | void menu_set_cursor (uint8_t before, uint8_t line, uint8_t pos) |
||
102 | { |
||
103 | lcd_printp_at (pos, before, PSTR(" "), 0); |
||
104 | lcd_printp_at (pos, line, PSTR("\x1D"), 0); |
||
105 | } |
||
106 | |||
107 | |||
108 | //***************************************************************************** |
||
109 | // |
||
110 | uint8_t menu_choose (uint8_t min, uint8_t max, uint8_t pos, uint8_t start) |
||
111 | { |
||
112 | uint8_t line = start; |
||
113 | uint8_t before = start; |
||
114 | |||
115 | uint8_t k; |
||
116 | |||
117 | menu_set_cursor (line, line, pos); |
||
118 | |||
119 | do |
||
120 | { |
||
121 | if (get_key_press (1 << KEY_PLUS)) |
||
122 | { |
||
123 | if (line < max) |
||
124 | { |
||
125 | line ++; |
||
126 | } |
||
127 | else |
||
128 | { |
||
129 | line = min; |
||
130 | } |
||
131 | } |
||
132 | |||
133 | if (get_key_press (1 << KEY_MINUS)) |
||
134 | { |
||
135 | if (line > min) |
||
136 | { |
||
137 | line --; |
||
138 | } |
||
139 | else |
||
140 | { |
||
141 | line = max; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | if (line != before) |
||
146 | { |
||
147 | menu_set_cursor (before, line, pos); |
||
148 | before = line; |
||
149 | } |
||
150 | } |
||
151 | while (!(k = get_key_press ((1 << KEY_ENTER) | (1 << KEY_ESC)))); |
||
152 | if (k & (1 << KEY_ESC)) |
||
153 | { |
||
154 | line = 255; |
||
155 | } |
||
156 | |||
157 | return line; |
||
158 | } |
||
159 | |||
160 | uint8_t menu_choose2 (uint8_t min, uint8_t max,uint8_t start, uint8_t return_at_start,uint8_t return_at_end) |
||
161 | { |
||
162 | uint8_t pos = 1; |
||
163 | uint8_t line = start; |
||
164 | uint8_t before = start; |
||
165 | |||
166 | uint8_t k; |
||
167 | |||
168 | menu_set_cursor (line, line, pos); |
||
169 | |||
170 | do |
||
171 | { |
||
172 | if (get_key_press (1 << KEY_PLUS)) |
||
173 | { |
||
174 | if (line < max) |
||
175 | { |
||
176 | line ++; |
||
177 | } |
||
178 | else |
||
179 | { |
||
180 | if(return_at_end == 1) |
||
181 | { |
||
182 | return 254; |
||
183 | } |
||
184 | else |
||
185 | { |
||
186 | //line = min; |
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | |||
191 | if (get_key_press (1 << KEY_MINUS)) |
||
192 | { |
||
193 | if (line > min) |
||
194 | { |
||
195 | line --; |
||
196 | } |
||
197 | else |
||
198 | { |
||
199 | if(return_at_start == 1) |
||
200 | { |
||
201 | return 253; |
||
202 | } |
||
203 | else |
||
204 | { |
||
205 | //line = max; |
||
206 | } |
||
207 | } |
||
208 | } |
||
209 | |||
210 | if (line != before) |
||
211 | { |
||
212 | menu_set_cursor (before, line, pos); |
||
213 | before = line; |
||
214 | } |
||
215 | } |
||
216 | while (!(k = get_key_press ((1 << KEY_ENTER) | (1 << KEY_ESC)))); |
||
217 | if (k & (1 << KEY_ESC)) |
||
218 | { |
||
219 | line = 255; |
||
220 | } |
||
221 | |||
222 | return line; |
||
223 | } |
||
224 | |||
225 | uint8_t menu_choose3 (uint8_t min, uint8_t max,uint8_t start, uint8_t return_at_start,uint8_t return_at_end) |
||
226 | { |
||
227 | uint8_t pos = 1; |
||
228 | uint8_t line = start; |
||
229 | uint8_t before = start; |
||
230 | |||
231 | menu_set_cursor (line, line, pos); |
||
232 | |||
233 | do |
||
234 | { |
||
235 | if (get_key_press (1 << KEY_PLUS)) |
||
236 | { |
||
237 | if (line < max) |
||
238 | { |
||
239 | line ++; |
||
240 | } |
||
241 | else |
||
242 | { |
||
243 | if(return_at_end == 1) |
||
244 | { |
||
245 | return 254; |
||
246 | } |
||
247 | else |
||
248 | { |
||
249 | //line = min; |
||
250 | } |
||
251 | } |
||
252 | } |
||
253 | |||
254 | if (get_key_press (1 << KEY_MINUS)) |
||
255 | { |
||
256 | if (line > min) |
||
257 | { |
||
258 | line --; |
||
259 | } |
||
260 | else |
||
261 | { |
||
262 | if(return_at_start == 1) |
||
263 | { |
||
264 | return 253; |
||
265 | } |
||
266 | else |
||
267 | { |
||
268 | //line = max; |
||
269 | } |
||
270 | } |
||
271 | } |
||
272 | |||
273 | if (line != before) |
||
274 | { |
||
275 | menu_set_cursor (before, line, pos); |
||
276 | before = line; |
||
277 | } |
||
278 | } |
||
279 | while (!(get_key_press (1 << KEY_ENTER))); |
||
280 | |||
281 | return line; |
||
282 | } |
||
283 | |||
284 | |||
285 | |||
286 | |||
287 | void main_menu(void) |
||
288 | { |
||
289 | uint8_t ii = 0; |
||
290 | uint8_t offset = 0; |
||
291 | uint8_t size = 0; |
||
292 | |||
293 | if(hardware == NC) size = ITEMS_NC ; |
||
294 | if(hardware == FC) size = ITEMS_FC ; |
||
295 | if(hardware == NO) size = ITEMS_NO ; |
||
296 | |||
297 | uint8_t dmode = 0; |
||
298 | uint8_t target_pos = 1; |
||
299 | |||
300 | uint8_t val =0; |
||
301 | |||
302 | |||
303 | while(1) |
||
304 | { |
||
305 | |||
306 | lcd_cls (); |
||
307 | lcd_printp_at (0, 0, PSTR("PMK-Tool=FC "), 0); |
||
308 | lcd_printp (PSTR(FC_Version),0); |
||
309 | lcd_printpns_at (0, 7, PSTR(" \x1a \x1b \x0c"), 0); |
||
310 | |||
311 | |||
312 | while(1) |
||
313 | { |
||
314 | ii = 0; |
||
315 | if(offset > 0) |
||
316 | { |
||
317 | lcd_printp_at(1,1, PSTR("\x1a"), 0); |
||
318 | } |
||
319 | for(ii = 0;ii < 6 ; ii++) |
||
320 | { |
||
321 | if((ii+offset) < size) |
||
322 | { |
||
323 | if(hardware == NC) |
||
324 | |||
325 | { |
||
326 | lcd_printp_at(3,ii+1,param_menuitems_nc[ii+offset], 0); |
||
327 | } |
||
328 | |||
329 | else |
||
330 | |||
331 | if(hardware == FC) |
||
332 | { |
||
333 | lcd_printp_at(3,ii+1,param_menuitems_fc[ii+offset], 0); |
||
334 | } |
||
335 | |||
336 | |||
337 | else |
||
338 | { |
||
339 | lcd_printp_at(3,ii+1,param_menuitems_no[ii+offset], 0); |
||
340 | } |
||
341 | } |
||
342 | if((ii == 5)&&(ii+offset < (size-1))) |
||
343 | { |
||
344 | lcd_printp_at(1,6, PSTR("\x1b"), 0); |
||
345 | } |
||
346 | |||
347 | } |
||
348 | |||
349 | |||
350 | |||
351 | if(dmode == 0) |
||
352 | { |
||
353 | if(offset == 0) |
||
354 | { |
||
355 | if(size > 6) |
||
356 | { |
||
357 | val = menu_choose3 (1, 5, target_pos,0,1); |
||
358 | } |
||
359 | else |
||
360 | { |
||
361 | val = menu_choose3 (1, size, target_pos,0,0); |
||
362 | } |
||
363 | } |
||
364 | else |
||
365 | { |
||
366 | val = menu_choose3 (2, 5, target_pos,1,1); |
||
367 | } |
||
368 | } |
||
369 | if(dmode == 1) |
||
370 | { |
||
371 | if(offset+7 > size) |
||
372 | { |
||
373 | val = menu_choose3 (2, 6, target_pos,1,0); |
||
374 | } |
||
375 | else |
||
376 | { |
||
377 | val = menu_choose3 (2, 5, target_pos,1,1); |
||
378 | } |
||
379 | } |
||
380 | |||
381 | |||
382 | |||
383 | if(val == 254) |
||
384 | { |
||
385 | offset++; |
||
386 | dmode = 1; |
||
387 | target_pos = 5; |
||
388 | }else if(val == 253) |
||
389 | { |
||
390 | offset--; |
||
391 | dmode = 0; |
||
392 | target_pos = 2; |
||
393 | }else if(val == 255) |
||
394 | { |
||
395 | // nothing |
||
396 | } |
||
397 | else |
||
398 | { |
||
399 | break; |
||
400 | } |
||
401 | } |
||
402 | |||
403 | target_pos = val; |
||
404 | |||
405 | |||
406 | if(hardware == NC) |
||
407 | { |
||
408 | if((val+offset) == 1 ) osd(OSD_Mode); |
||
409 | if((val+offset) == 2 ) osd(THREE_D_Mode); |
||
410 | // if((val+offset) == 3 ) jeti(); |
||
411 | if((val+offset) == 3 ) display_data(); |
||
412 | if((val+offset) == 4 ) edit_parameter(); |
||
413 | if((val+offset) == 5 ) display_debug(); |
||
414 | if((val+offset) == 6 ) motor_test(); |
||
415 | if((val+offset) == 7 ) gps(); |
||
416 | if((val+offset) == 8 ) PMK_Setup(); |
||
417 | if((val+offset) == 9) Show_Version(); |
||
418 | |||
419 | #if defined HWVERSION3_1 || defined HWVERSION1_3 |
||
420 | if((val+offset) == 10) Wi232_FC(); |
||
421 | #else |
||
422 | if((val+offset) == 10) Show_Error_HW(); |
||
423 | #endif |
||
424 | |||
425 | } |
||
426 | |||
427 | if(hardware == FC) |
||
428 | { |
||
429 | if((val+offset) == 1 ) display_data(); |
||
430 | if((val+offset) == 2 ) edit_parameter(); |
||
431 | if((val+offset) == 3 ) display_debug(); |
||
432 | if((val+offset) == 4 ) motor_test(); |
||
433 | if((val+offset) == 5 ) PMK_Setup(); |
||
434 | if((val+offset) == 6 ) Show_Version(); |
||
435 | |||
436 | #if defined HWVERSION3_1 || defined HWVERSION1_3 |
||
437 | if((val+offset) == 7) Wi232_FC(); |
||
438 | #else |
||
439 | if((val+offset) == 7) Show_Error_HW(); |
||
440 | #endif |
||
441 | } |
||
442 | if(hardware == NO) |
||
443 | { |
||
444 | if((val+offset) == 1 ) ; |
||
445 | // if((val+offset) == 1 ) motor_i2c(); noch nicht freigegeben |
||
446 | if((val+offset) == 2 ) PMK_Setup(); |
||
447 | if((val+offset) == 3 ) Show_Version(); |
||
448 | |||
449 | #if defined HWVERSION3_1 || defined HWVERSION1_3 |
||
450 | if((val+offset) == 4) Wi232_FC(); |
||
451 | if((val+offset) == 5) Wi232_USB(); |
||
452 | #else |
||
453 | if((val+offset) == 4) Show_Error_HW(); |
||
454 | if((val+offset) == 5) Show_Error_HW(); |
||
455 | #endif |
||
456 | |||
457 | if((val+offset) == 6) |
||
458 | { |
||
459 | |||
460 | lcd_cls(); |
||
461 | lcd_printpns_at (0, 0, PSTR("Connect PC to PKT-USB"),0); |
||
462 | lcd_printpns_at (0, 1, PSTR("Press 'Start' on PKT"),0); |
||
463 | lcd_printpns_at (0, 2, PSTR("Then start avrdude:"),0); |
||
464 | lcd_printpns_at (0, 3, PSTR("avrdude -pm644p -cavr"),0); |
||
465 | lcd_printpns_at (0, 4, PSTR("109 -Pcom? -b115200 -"),0); |
||
466 | lcd_printpns_at (0, 5, PSTR("Uflash:w:NEWSOFTWARE"),0); |
||
467 | lcd_printpns_at (0, 6, PSTR(".hex:a"),0); |
||
468 | // avrdude -pm644p -cavr109 -P/dev/ttyUSB1 -b115200 -V -Uflash:w:GPL_PKT_V3.1L_FC0.84_HW3x.hex:a |
||
469 | lcd_printpns_at (0, 7, PSTR("Back Start"),0); |
||
470 | |||
471 | do |
||
472 | |||
473 | if ((get_key_press (1 << KEY_MINUS))) {return;} |
||
474 | |||
475 | while (!(get_key_press (1 << KEY_ENTER))); |
||
476 | { |
||
477 | /* start bootloader with Reset, Hold KEY_ENTER*/ |
||
478 | wdt_enable( WDTO_250MS ); |
||
479 | while (1) { ; } |
||
480 | } |
||
481 | |||
482 | |||
483 | } |
||
484 | } |
||
485 | } |
||
486 | } |
||
487 | |||
488 | void Show_Error_HW(void) |
||
489 | { |
||
490 | lcd_cls (); |
||
491 | lcd_printpns_at (0,0,PSTR("Mit dieser Hardware"), 0); |
||
492 | lcd_printpns_at (0,1,PSTR("nicht moeglich!"), 0); |
||
493 | lcd_printpns_at (0,7,PSTR(" zurueck"), 0); |
||
494 | while (!(get_key_press (1 << KEY_ENTER))); |
||
495 | return; |
||
496 | |||
497 | } |
||
498 | |||
499 | |||
500 | void Show_Version(void) |
||
501 | { |
||
502 | lcd_cls (); |
||
503 | |||
504 | lcd_printpns_at (0,0,PSTR("PMK Tool 3.2"), 0); |
||
505 | lcd_printpns_at (0,1,PSTR("for FC "), 0); |
||
506 | lcd_printpns_at (8,1,PSTR(FC_Version),0); |
||
507 | lcd_printpns_at (0,2,PSTR("(C) GNU GPL License"), 0); |
||
508 | lcd_printpns_at (0,3,PSTR(" NO WARRANTY"), 0); |
||
509 | lcd_printpns_at (0,4,PSTR("2008 Thomas Kaiser"), 0); |
||
510 | lcd_printpns_at (0,5,PSTR("2009-2010 Peter Mack"), 0); |
||
511 | lcd_printpns_at (0,6,PSTR("2010 Sebastian Boehm"), 0); |
||
512 | lcd_printpns_at (0,7,PSTR("2011 Chr. Brandtner "), 0); |
||
513 | |||
514 | while (!(get_key_press (1 << KEY_ENTER))); |
||
515 | return; |
||
516 | |||
517 | } |
||
518 | |||
519 | |||
520 | |||
521 |