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