Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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