Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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