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