Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1471 - 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 <inttypes.h>
38
#include <stdlib.h>
39
#include <avr/pgmspace.h>
40
#include <avr/wdt.h>
41
#include <util/delay.h>
42
 
43
#include "main.h"
44
#include "lcd.h"
45
#include "parameter.h"
46
 
47
#include "menu.h"
48
#include "messages.h"
49
#include "display.h"
50
#include "debug.h"
51
#include "timer.h"
52
#include "osd.h"
53
#include "motortest.h"
54
#include "gps.h"
55
#include "eeprom.h"
56
#include "setup.h"
57
#include "uart1.h"
58
#include "mk-data-structs.h"
59
#include "Wi232.h"
60
#include "servo.h"
61
#include "tools.h"
62
#include "connect.h"
63
#include "lipo.h"
64
#include "messages.h"
65
 
66
 
67
 
68
 
69
 
70
#define ITEMS_NC 7
71
 
72
prog_char param_menuitems_nc[ITEMS_NC][NUM_LANG][18]= // zeilen,zeichen+1
73
 
74
 
75
    //    German,             English,            French,               Netherlands
76
    {
77
        {"OSD              ","OSD              ","OSD              ","OSD              "},
78
        {"3D Lage          ","3D angeles       ","3D location      ","3D locatie       "},
79
        {"MK Display       ","MK Display       ","MK Display       ","MK Display       "},
80
        {"Parameter       \x1d","Parameter       \x1d","Parameter       \x1d","Parameters      \x1d"},
81
        {"Debug Data       ","Debug Data       ","Debug Data       ","Debug Data       "},
82
        {"GPS Info         ","GPS Info         ","GPS Info         ","GPS Info         "},
83
        {"PKT Tools       \x1d","PKT Tools       \x1d","PKT Tools       \x1d","PKT Tools       \x1d"},
84
    };
85
 
86
 
87
#define ITEMS_FC 4
88
 
89
prog_char param_menuitems_fc[ITEMS_FC][NUM_LANG][18]= // zeilen,zeichen+1
90
    {
91
        {"MK Display       ","MK Display       ","MK Display       ","MK Display       "},
92
        {"Parameter       \x1d","Parameter       \x1d","Parameter       \x1d","Parameter       \x1d"},
93
        {"Debug Data       ","Debug Data       ","Debug Data       ","Debug Data       "},
94
        {"PKT Tools       \x1d","PKT Tools       \x1d","PKT Tools       \x1d","PKT Tools       \x1d"},
95
    };
96
 
97
 
98
#define ITEMS_NO 6
99
 
100
prog_char param_menuitems_no[ITEMS_NO][NUM_LANG][18]= // zeilen,zeichen+1
101
{
102
    {"BL-Ctrl. Tester ","BL-Ctrl. Tester ","BL-Ctrl. Tester ","BL-Ctrl. Tester "},
103
    {"Servo Tester     ","Servo Tester     ","Servo Tester     ","Servo Tester     "},
104
    {"PC BT  > Kopter  ","PC BT  > Kopter  ","PC BT  > Kopter  ","PC BT  > Kopter  "},
105
    {"PC USB > Kopter  ","PC USB > Kopter  ","PC USB > Kopter  ","PC USB > Kopter  "},
106
    {"PKT Setup       \x1d","PKT Setup       \x1d","PKT Setup       \x1d","PKT Setup       \x1d"},
107
    {"PKT Version      ","PKT Version      ","PKT Version      ","PKT Versie       "},
108
};
109
 
110
 
111
#define ITEMS_CR 9
112
 
113
prog_char param_copyright[ITEMS_CR][22]= // zeilen,zeichen+1
114
{
115
"                     ",
116
"(C) GNU GPL License  ",
117
"    NO WARRANTY      ",
118
"                     ",
119
"2008 Thomas Kaiser   ",
120
"2009-2010 Peter Mack ",
121
"2010 Sebastian Boehm ",
122
"2011 Chr. Brandtner &",
123
"     Harald Bongartz ",
124
};
125
 
126
 
127
//--------------------------------------------------------------
128
// print cursor
129
void menu_set_cursor (uint8_t before, uint8_t line, uint8_t pos)
130
{
131
        lcd_printp_at (pos, before, PSTR(" "), 0);
132
        lcd_printp_at (pos, line, PSTR("\x1d"), 0);
133
}
134
 
135
 
136
// F�r Seting-Auswahl ------------------------------------------
137
//
138
uint8_t menu_choose (uint8_t min, uint8_t max, uint8_t pos, uint8_t start)
139
{
140
        uint8_t line = start;
141
        uint8_t before = start;
142
 
143
        uint8_t k;
144
 
145
        menu_set_cursor (line, line, pos);
146
 
147
        do
148
        {
149
                if (get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 1))
150
                {
151
                        if (line < max)
152
                                line ++;
153
                        else
154
                                line = max;
155
                        //      line = min; // Wenn wiederholen soll
156
                }
157
 
158
                if (get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 1))
159
                {
160
                        if (line > min)
161
                                line --;
162
                        else
163
                                line = min;
164
                        //      line = max; // Wenn wiederholen soll
165
                }
166
 
167
                if (line != before)
168
                {
169
                        menu_set_cursor (before, line, pos);
170
                        before = line;
171
                }
172
        }
173
        while (!(k = get_key_press ((1 << KEY_ENTER) | (1 << KEY_ESC))));
174
 
175
        if (k & (1 << KEY_ESC))
176
                line = 255;
177
 
178
        return line;
179
}
180
 
181
// F�r Setup und Parameter ------------------------------------------
182
//
183
uint8_t menu_choose2 (uint8_t min, uint8_t max, uint8_t start, uint8_t return_at_start, uint8_t return_at_end)
184
{
185
        uint8_t pos = 1;
186
        uint8_t line = start;
187
        uint8_t before = start;
188
 
189
        uint8_t k;
190
 
191
        menu_set_cursor (line, line, pos);
192
 
193
        do
194
        {
195
                if (get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 1))
196
                {
197
                        if (line < max)
198
                                line ++;
199
                        else
200
                        {
201
                                if(return_at_end == 1)
202
                                        return 254;
203
                                else
204
                                        line = max;
205
                                //      line = min; // Wenn wiederholen soll
206
                        }
207
                }
208
 
209
                if (get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 1))
210
                {
211
                        if (line > min)
212
                                line --;
213
                        else
214
                        {
215
                                if(return_at_start == 1)
216
                                        return 253;
217
                                else
218
                                        line = min;
219
                                //      line = max; // Wenn wiederholen soll
220
                        }
221
                }
222
 
223
                if (line != before)
224
                {
225
                        menu_set_cursor (before, line, pos);
226
                        before = line;
227
                }
228
        }
229
        while (!(k = get_key_press ((1 << KEY_ENTER) | (1 << KEY_ESC))));
230
 
231
        if (k & (1 << KEY_ESC))
232
                line = 255;
233
 
234
        return line;
235
}
236
 
237
// F�r das Hauptmenue ------------------------------------------
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
 
250
                if (get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 1))
251
                {
252
                        if (line < max)
253
                                line ++;
254
                        else
255
                        {
256
                                if(return_at_end == 1)
257
                                        return 254;
258
                                else
259
                                        line = max;
260
                                //      line = min; // Wenn wiederholen soll
261
                        }
262
                }
263
 
264
                if (get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 1))
265
                {
266
                        if (line > min)
267
                                line --;
268
                        else
269
                        {
270
                                if(return_at_start == 1)
271
                                        return 253;
272
                                else
273
                                        line = min;
274
                                //      line = max; // Wenn wiederholen soll
275
                        }
276
                }
277
 
278
                if (get_key_long (1 << KEY_ESC))
279
                {
280
                        get_key_press(KEY_ALL);
281
                        return 250;
282
                }
283
 
284
                if(get_key_long (1 << KEY_ENTER))
285
                {
286
                        get_key_press(KEY_ALL);
287
                        return 251;
288
                }
289
 
290
                if (get_key_short (1 << KEY_ESC))
291
                {
292
                        get_key_press(KEY_ALL);
293
                        return 252;
294
                }
295
 
296
                if (line != before)
297
                {
298
                        menu_set_cursor (before, line, pos);
299
                        before = line;
300
                }
301
           show_Lipo();
302
        }
303
        while (!(get_key_short (1 << KEY_ENTER)));
304
 
305
        return line;
306
}
307
 
308
//--------------------------------------------------------------
309
//
310
void main_menu (void)
311
{
312
        uint8_t ii = 0;
313
        uint8_t offset = 0;
314
        uint8_t size = 0;
315
        uint8_t Save_hardware = 0;
316
        uint8_t dmode = 0;
317
        uint8_t target_pos = 1;
318
        uint8_t val =0;
319
 
320
        Save_hardware = hardware;
321
 
322
        get_key_press(KEY_ALL);
323
 
324
        while(1)
325
        {
326
                if (Debug==1)
327
                        hardware = NC;
328
                if (Debug==0)
329
                        hardware = Save_hardware;
330
                if(hardware == NO)
331
                        size = ITEMS_NO ;
332
                if(hardware == NC)
333
                        size = ITEMS_NC ;
334
                if(hardware == FC)
335
                        size = ITEMS_FC ;
336
 
337
                lcd_cls ();
338
                lcd_printp_at (0, 0, PSTR("PKT-Tool FC "), 2);
339
                lcd_printp_at (12, 0, PSTR(FC_Version), 2);
340
 
341
//              lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
342
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
343
//              lcd_printp_at (12, 7, PSTR("Aus "), 0);
344
                 lcd_puts_at(12, 7, strGet(OFF), 0);
345
 
346
 
347
                while(2)
348
                {
349
 
350
                        ii = 0;
351
                        if(offset > 0)
352
                                lcd_printp_at(1,1, PSTR("\x12"), 0);
353
 
354
                        for(ii = 0;ii < 6 ; ii++)
355
                        {
356
                                if((ii+offset) < size)
357
                                {
358
                                        if(hardware == NC)
359
                                                lcd_printp_at(3,ii+1,param_menuitems_nc[ii+offset][DisplayLanguage], 0);
360
                                        else if(hardware == FC)
361
                                                lcd_printp_at(3,ii+1,param_menuitems_fc[ii+offset][DisplayLanguage], 0);
362
                                        else
363
                                                lcd_printp_at(3,ii+1,param_menuitems_no[ii+offset][DisplayLanguage], 0);
364
                                }
365
 
366
                                if((ii == 5)&&(ii+offset < (size-1)))
367
                                        lcd_printp_at(1,6, PSTR("\x13"), 0);
368
                                show_Lipo();
369
                        }
370
 
371
                        if(dmode == 0)
372
                        {
373
                                if(offset == 0)
374
                                {
375
                                        if(size > 6)
376
                                                val = menu_choose3 (1, 5, target_pos,0,1); //menu_choose3 (min, max, start, return_at_start, return_at_end)
377
                                        else
378
                                                val = menu_choose3 (1, size, target_pos,0,0);
379
                                }
380
                                else
381
                                        val = menu_choose3 (2, 5, target_pos,1,1);
382
                        }
383
 
384
                        if(dmode == 1)
385
                        {
386
                                if(offset+7 > size)
387
                                        val = menu_choose3 (2, 6, target_pos,1,0);
388
                                else
389
                                        val = menu_choose3 (2, 5, target_pos,1,1);
390
                        }
391
 
392
                        if(val == 254)
393
                        {
394
                                offset++;
395
                                dmode = 1;
396
                                target_pos = 5;
397
                        }
398
                        else if(val == 253)
399
                        {
400
                                offset--;
401
                                dmode = 0;
402
                                target_pos = 2;
403
                        }
404
#if defined HWVERSION3_9
405
                        else if(val == 252)
406
                        {
407
 
408
                                lcd_cls();
409
//                              lcd_printp_at (0, 2, PSTR("  PKT ausschalten?"),0);
410
                                 lcd_puts_at(0, 2, strGet(SHUTDOWN), 0);
411
//                              lcd_printp_at (12, 7, PSTR("Nein   Ja"),0);
412
                                 lcd_puts_at(12, 7, strGet(YESNO), 0);
413
                                while(1)
414
                                {
415
                                        if (get_key_press (1 << KEY_ENTER))
416
                                                clr_V_On();     // Spannung abschalten
417
 
418
                                        if (get_key_short (1 << KEY_ESC))
419
                                        {
420
                                                get_key_press(KEY_ALL);
421
                                                lcd_cls();
422
                                                lcd_printp_at (0, 0, PSTR("PKT-Tool FC "), 2);
423
                                                lcd_printp_at (12, 0,PSTR(FC_Version), 2);
424
//                                              show_Lipo();
425
//                                              lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
426
                                                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
427
//                                              lcd_printp_at (12, 7, PSTR("Aus "), 0);
428
                                                 lcd_puts_at(12, 7, strGet(OFF), 0);
429
                                                break;
430
                                        }
431
                                }
432
                        }
433
                        else if(val == 251)
434
                        {
435
                                PC_Fast_Connect();
436
                                return;
437
                        }
438
#endif
439
                        else if(val == 250)
440
                        {
441
//                              Test_HB();
442
                                Test_Language();
443
                                return;
444
                        }
445
                        else
446
                                break;
447
                }
448
 
449
                target_pos = val;
450
 
451
 
452
                if(hardware == NC)
453
                {
454
                        if((val+offset) == 1 )
455
                                osd(OSD_Mode);
456
                        if((val+offset) == 2 )
457
                                osd(THREE_D_Mode);
458
                        if((val+offset) == 3 )
459
                                display_data();
460
                        if((val+offset) == 4 )
461
                                edit_parameter();
462
                        if((val+offset) == 5 )
463
                                display_debug();
464
                        if((val+offset) == 6 )
465
                                gps();
466
                        if((val+offset) == 7 )
467
                                PKT_Tools();
468
 
469
                }
470
 
471
 
472
                if(hardware == FC)
473
                {
474
                        if((val+offset) == 1 )
475
                                display_data();
476
                        if((val+offset) == 2 )
477
                                edit_parameter();
478
                        if((val+offset) == 3 )
479
                                display_debug();
480
                        if((val+offset) == 4 )
481
                                PKT_Tools();
482
 
483
                }
484
 
485
 
486
                if(hardware == NO)
487
                {
488
                        if((val+offset) == 1 )
489
                                motor_test(FC_Mode);
490
                        if((val+offset) == 2 )
491
                                servo_test();
492
#ifdef HWVERSION3_9
493
                        if (U02SV2 == 0)
494
                        {
495
                                if((val+offset) == 3 )
496
                                        Port_BT2Wi();
497
                                if((val+offset) == 4 )
498
                                        Port_USB2Wi();
499
                        }
500
                        else if (U02SV2 == 1)
501
                        {
502
                                if((val+offset) == 3 )
503
                                        Port_BT2FC();
504
                                if((val+offset) == 4 )
505
                                        Port_USB2FC();
506
                        }
507
#else
508
                        if((val+offset) == 3 )
509
                                Show_Error_HW();
510
                        if((val+offset) == 4 )
511
                                Show_Error_HW();
512
#endif
513
                        if((val+offset) == 5 )
514
                                PKT_Setup();
515
                        if((val+offset) == 6 )
516
                                Show_Version();
517
 
518
                }
519
 
520
 
521
        }
522
}
523
 
524
 
525
//--------------------------------------------------------------
526
//
527
void Update_PKT (void)
528
{
529
        lcd_cls();
530
        lcd_printp_at (0, 0, PSTR(" PKT Update          "),2);
531
//      lcd_printp_at (0, 1, PSTR("Connect PC to PKT-USB"),0);
532
        lcd_puts_at(0, 1, strGet(UPDATE1), 0);
533
//      lcd_printp_at (0, 2, PSTR("Press 'Start' on PKT "),0);
534
        lcd_puts_at(0, 2, strGet(UPDATE2), 0);
535
        lcd_printp_at (0, 3, PSTR("Start avrdude.exe    "),0);
536
        lcd_printp_at (0, 4, PSTR("-pm1284p -cavr109    "),0);
537
        lcd_printp_at (0, 5, PSTR("-Pcom? -b115200      "),0);
538
        lcd_printp_at (0, 6, PSTR("-Uflash:w:FILE.hex:a "),0);
539
//      avrdude -pm1284p -cavr109 -P/dev/ttyUSB1 -b115200 -V -Uflash:w:Dateiname.hex:a
540
 
541
//      lcd_printp_at (0, 7, PSTR("           Ende Start"), 0);
542
         lcd_puts_at(0, 7, strGet(ENDSTART), 0);
543
 
544
        do
545
        {
546
                if (get_key_press (1 << KEY_ESC))
547
                {
548
                        get_key_press(KEY_ALL);
549
                        return;
550
                }
551
        }
552
        while (!(get_key_press (1 << KEY_ENTER)));
553
        {
554
 
555
                // start bootloader with Reset, Hold KEY_ENTER*/
556
                wdt_enable( WDTO_250MS );
557
                while (1)
558
                {;}
559
        }
560
}
561
 
562
 
563
//--------------------------------------------------------------
564
//
565
void Show_Error_HW (void)
566
{
567
        lcd_cls ();
568
        lcd_printp_at (0, 2, PSTR(" Mit dieser Hardware"), 0);
569
        lcd_printp_at (0, 3, PSTR(" nicht möglich!"), 0);
570
        lcd_printp_at (12, 7, PSTR("Ende"), 0);
571
 
572
        while (!get_key_press (1 << KEY_ESC));
573
        get_key_press(KEY_ALL);
574
        return;
575
}
576
 
577
 
578
//--------------------------------------------------------------
579
//
580
void Show_Version (void)
581
{
582
        uint8_t ii = 0;
583
        uint8_t size = ITEMS_CR;
584
        uint8_t page = 0;
585
 
586
        lcd_cls ();
587
 
588
//      lcd_printp_at (0, 0, PSTR("PKT Tool ver         "), 2);
589
//      lcd_printp_at (13,0, PSTR(PKTSWVersion),2);
590
//      lcdPuts(Msg(MSG_VERSION1));
591
//      lcd_printp_at (0, 0, Msg(MSG_VERSION1), 2);
592
//      lcd_printp_at (0, 1, PSTR("für FC ver           "), 2);
593
//      lcd_printp_at (12,1, PSTR(FC_Version),2);
594
         lcd_puts_at(0, 1, strGet(START_MSG2), 2);
595
//      lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
596
        lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
597
 
598
        while(1)
599
        {
600
                for(ii = 0;ii < 3 ; ii++)
601
                        if((ii + page) < size)
602
                                lcd_printp_at(0,ii + 3,param_copyright[ii + page], 0);
603
 
604
                if (page == 0)
605
                {
606
                        lcd_printp_at (0, 2, PSTR(" "), 0);
607
                        lcd_printp_at (0, 6, PSTR("\x13"), 0);
608
                }
609
 
610
                if (page > 0 && page < (size - 3))
611
                {
612
                        lcd_printp_at (0, 2, PSTR("\x12"), 0);
613
                        lcd_printp_at (0, 6, PSTR("\x13"), 0);
614
                }
615
 
616
                if (page >= (size - 3))
617
                {
618
                        lcd_printp_at (0, 2, PSTR("\x12"), 0);
619
                        lcd_printp_at (0, 6, PSTR(" "), 0);
620
                }
621
 
622
 
623
                if (get_key_press (1 << KEY_PLUS))
624
                        if (page < size - 3)
625
                                page++;
626
 
627
                if (get_key_press (1 << KEY_MINUS))
628
                        if (page > 0)
629
                                page--;
630
 
631
                if (get_key_press (1 << KEY_ESC) || get_key_press (1 << KEY_ENTER))
632
                {
633
                        get_key_press(KEY_ALL);
634
                        return;
635
                }
636
        }
637
}
638
 
639