Subversion Repositories FlightCtrl

Rev

Rev 231 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
231 ligi 1
/***************************************************************
2
 *
3
 * minimal canvas to test Abstraction layer on various Phones
4
 *                                                          
5
 * Author:        Marcus -LiGi- Bueschleb                    
6
 * Project-Start: 9/2007                                    
7
 * Mailto:        ligi@smart4mobile.de                      
8
 * Licence:       Creative Commons / Non Commercial          
9
 * Big Up:        Holger&Ingo                                
10
 ***************************************************************/
181 ligi 11
 
12
import javax.microedition.lcdui.*;
208 ligi 13
import javax.microedition.rms.*;
181 ligi 14
 
221 ligi 15
 
181 ligi 16
public class MKMiniCanvas
231 ligi 17
    extends Canvas
18
    implements Runnable
181 ligi 19
{
20
 
303 ligi 21
    private final static String RECORD_STORE_NAME="bluetoothurl";
181 ligi 22
 
208 ligi 23
    private BTSearcher bt_scanner;
303 ligi 24
    public MKCommunicator mk=null;
208 ligi 25
    private MKStatistics mk_stat=null;
303 ligi 26
    private MKParamsEditor params_editor=null;
27
 
28
 
208 ligi 29
    private String err="";
303 ligi 30
    private DUBwise root;
181 ligi 31
 
221 ligi 32
    private Image bg_img;
33
    private Image bt_img;
34
    private Image lcd_img;
35
    private Image load_img;
36
 
37
 
38
    public int[] nick_line_pos_data;
39
    public int[] roll_line_pos_data;
40
 
41
    public int[] accnick_line_pos_data;
42
    public int[] accroll_line_pos_data;
43
 
303 ligi 44
    public int lcd_char_width=0;
45
    public int lcd_char_height=0;
221 ligi 46
 
47
    public int frame_pos=0;
48
 
49
    int line_scaler=20;
50
 
51
    public int line_middle_y;
52
 
303 ligi 53
    boolean quit=false;
54
    boolean rescan=true;
55
    int bg_offset=0;
56
 
57
    public int state=-1;
58
 
59
 
60
 
61
    public final static int STATEID_SCANNING=0;
62
    public final static int STATEID_DEVICESELECT=1;
63
    public final static int STATEID_MAINMENU=2;
64
    public final static int STATEID_MOTORTEST=3;
65
    public final static int STATEID_SELECT_PARAMSET=4;
66
    public final static int STATEID_EDIT_PARAMS=5;
67
    public final static int STATEID_FLIGHTVIEW=6;
68
 
69
 
70
    int local_max=-1;
71
 
72
    int y_off=0;
73
    int spacer=0;
74
    int[] motor_test = {0,0,0,0};
75
 
76
 
77
    String[] menu_items;
78
    int act_menu_select=0;
79
 
80
    String[] lcd_lines =null;
81
 
82
    public void paint_menu(Graphics g)
231 ligi 83
    {
303 ligi 84
        for ( int i=0;i<menu_items.length;i++)
85
            lcd_lines[i]=(act_menu_select==i?"# ":"  ") + menu_items[i];       
86
        paint_lcd(g,true);
87
    }
221 ligi 88
 
303 ligi 89
    public void menu_keypress(int keyCode)
90
    {
91
        switch (getGameAction (keyCode))
92
            {
93
            case UP:
94
                if (act_menu_select!=0) act_menu_select--;
95
                break;
96
 
97
            case DOWN:
98
                if (act_menu_select<(menu_items.length-1)) act_menu_select++;
99
                break;
100
 
101
            }
102
 
103
    }
104
 
105
 
106
 
107
    public void paint_lcd(Graphics g,boolean bottomup)
108
    {
109
        int y;
110
 
111
        for(int i=0;i<lcd_lines.length;i++)
112
            for (int pos=0;pos<20;pos++)
113
            {
114
                if (bottomup)
115
                    y=this.getHeight()-(lcd_lines.length-i)*lcd_char_height;
116
                else
117
                    y=i*lcd_char_height;
118
                g.setClip((lcd_img.getWidth()/222)*pos,y,(lcd_img.getWidth()/222),lcd_img.getHeight());
119
                g.drawImage(lcd_img,(lcd_img.getWidth()/222)*pos-((pos<lcd_lines[i].length()?lcd_lines[i].charAt(pos):' ')-' ')*(lcd_img.getWidth()/222),y,g.TOP | g.LEFT);
120
 
121
            }
122
    }
123
 
124
    public MKMiniCanvas(DUBwise _root)
125
    {
126
 
231 ligi 127
        root=_root;
181 ligi 128
 
303 ligi 129
        bt_scanner = new BTSearcher();
130
        params_editor = new MKParamsEditor(this);
131
        mk = new MKCommunicator();
132
        mk_stat= new MKStatistics(mk);
133
 
231 ligi 134
        try
135
            {
303 ligi 136
                // load all needed images
231 ligi 137
                lcd_img=Image.createImage("/lcd.png");
138
                bt_img=Image.createImage("/bt.png");
139
                bg_img=Image.createImage("/bg.jpg");               
140
                load_img=Image.createImage("/load.png");
141
            }
142
        catch (Exception e)
143
            {
144
                err+=e.toString();
145
            }
303 ligi 146
 
147
        lcd_char_width=lcd_img.getWidth()/222;
148
        lcd_char_height=lcd_img.getHeight();
221 ligi 149
 
150
 
231 ligi 151
        nick_line_pos_data=new int[bg_img.getWidth()];
152
        roll_line_pos_data=new int[bg_img.getWidth()];
153
        accnick_line_pos_data=new int[bg_img.getWidth()];
154
        accroll_line_pos_data=new int[bg_img.getWidth()];
221 ligi 155
 
231 ligi 156
        for (int c=0;c<bg_img.getWidth();c++)
157
            {
158
                nick_line_pos_data[c]=-1;
159
                roll_line_pos_data[c]=-1;
160
                accnick_line_pos_data[c]=-1;
161
                accroll_line_pos_data[c]=-1;
162
            }
221 ligi 163
 
164
 
231 ligi 165
        try
166
            {
303 ligi 167
                RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME , true );
181 ligi 168
 
303 ligi 169
                if (recStore.getNumRecords()==2)
208 ligi 170
                    {
303 ligi 171
 
172
                        //byte[] recData = new byte[recStore.getRecordSize(1)];
173
                        //int len = recStore.getRecord(1, recData, 0);
174
 
175
                        //byte[] recData2 = new byte[recStore.getRecordSize(2)];
176
                        //int len2 = recStore.getRecord(2, recData, 0);
177
 
178
                        byte[] url_data=recStore.getRecord(1);
179
                        byte[] name_data=recStore.getRecord(2);
180
 
181
                        connect_mk(new String(url_data, 0, url_data.length),new String(name_data, 0, name_data.length));
182
 
208 ligi 183
                    }
303 ligi 184
                recStore.closeRecordStore();
231 ligi 185
            }
186
        catch (Exception e)
187
            {
188
                err+=e.toString();
189
            }
181 ligi 190
 
303 ligi 191
        chg_state((mk.force_disconnect)?STATEID_SCANNING:STATEID_MAINMENU);
192
 
193
 
194
 
231 ligi 195
        new Thread(this).start();
181 ligi 196
 
231 ligi 197
    }
181 ligi 198
 
199
 
221 ligi 200
 
303 ligi 201
    /****************************** Thread ******************/
181 ligi 202
    // ticking runnable Section
203
    public void run()
204
    {
205
 
303 ligi 206
 
181 ligi 207
        while(true)
208
            {
231 ligi 209
                repaint();
210
                serviceRepaints();
211
 
181 ligi 212
                long loopStartTime = System.currentTimeMillis();
213
                long sleeptime=0;
214
                // ticked thing
221 ligi 215
 
216
                frame_pos++;
217
 
231 ligi 218
                switch(state)
219
                    {
220
                    case STATEID_MOTORTEST:
221
 
222
                        if (motor_test_sel_all)
223
                            for (int m=0;m<4;m++)
224
                                {
225
                                    motor_test[m]+=act_motor_increase;
226
                                    if (motor_test[m]<0)motor_test[m]=0;
227
                                }
228
                        else
229
                            {
230
                                motor_test[act_motor]+=act_motor_increase;
231
                                if (motor_test[act_motor]<0)motor_test[act_motor]=0;
232
                            }
233
 
234
                        mk.motor_test(motor_test);
235
                        break;
303 ligi 236
 
237
                    case STATEID_SCANNING:
238
                        if (!bt_scanner.searching)
239
                                chg_state(STATEID_DEVICESELECT);
240
 
241
                        break;
242
 
243
 
244
 
231 ligi 245
                    }
246
 
221 ligi 247
                try {
231 ligi 248
                    nick_line_pos_data[-bg_offset] = mk.debug_data.nick_int();
249
                    roll_line_pos_data[-bg_offset] = mk.debug_data.roll_int();
250
                    accnick_line_pos_data[-bg_offset] = mk.debug_data.accnick();
251
                    accroll_line_pos_data[-bg_offset] = mk.debug_data.accroll();
221 ligi 252
                }
253
                catch (Exception e)
254
                    {
255
                        err+=e.toString();
256
                    }
257
 
181 ligi 258
 
221 ligi 259
 
260
 
208 ligi 261
                if (quit)
262
                    {
221 ligi 263
 
264
 
265
 
208 ligi 266
                        try
267
                            {
303 ligi 268
                                RecordStore.deleteRecordStore(RECORD_STORE_NAME);
269
                                RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true );
270
                                recStore.addRecord(mk.mk_url.getBytes(), 0, mk.mk_url.getBytes().length);
271
                                recStore.addRecord(mk.name.getBytes(), 0, mk.name.getBytes().length);
272
                                recStore.closeRecordStore();
208 ligi 273
 
274
                            }
275
                        catch (Exception e)
276
                            {
277
                                err+=e.toString();
278
                            }
279
 
280
                        root.quit();
281
                    }
282
                if (rescan)
283
                    {
303 ligi 284
 
285
                        rescan=false;
208 ligi 286
                    }
287
 
231 ligi 288
                try {
303 ligi 289
                    //rescan=false;
231 ligi 290
                    bg_offset--;
291
                    if (bg_offset==-bg_img.getWidth())
292
                        bg_offset=0;
293
                    com.nokia.mid.ui.DeviceControl.setLights(0,100);
294
                    //bt.tick();
295
                    // every state has sth to do in tick section
296
                }
297
                catch (Exception e)
298
                    {
299
 
300
                    }
181 ligi 301
 
302
 
231 ligi 303
                //                System.gc();
304
 
305
 
181 ligi 306
 
307
 
308
                sleeptime=1000/ 15 - (int) (System.currentTimeMillis()- loopStartTime);
309
 
310
 
311
                if (sleeptime<0)
231 ligi 312
                    sleeptime=100; // everyone has fi sleep
181 ligi 313
 
314
                try { Thread.sleep(sleeptime); }
315
                catch (Exception e)
316
                    {
231 ligi 317
                        err="Problem Sleeping ";
181 ligi 318
                    }
319
 
320
            }
321
    }
322
 
323
 
324
 
231 ligi 325
 
181 ligi 326
 
327
    // drawing section
328
    public void paint(Graphics g) {
303 ligi 329
        y_off=0;
231 ligi 330
        try {
221 ligi 331
 
231 ligi 332
            if (mk!=null)
333
                {
334
                    line_middle_y=this.getHeight()/2;
335
                    if (local_max<Math.abs(mk.debug_data.nick_int()))
336
                        local_max=Math.abs(mk.debug_data.nick_int());
337
                    if (local_max<Math.abs(mk.debug_data.roll_int()))
338
                        local_max=Math.abs(mk.debug_data.roll_int());
339
                    if (local_max<Math.abs(mk.debug_data.accnick()))
340
                        local_max=Math.abs(mk.debug_data.accnick());
341
                    if (local_max<Math.abs(mk.debug_data.accroll()))
342
                        local_max=Math.abs(mk.debug_data.accroll());
343
                    line_scaler= local_max/(this.getHeight()/2)+1;
344
                }
303 ligi 345
            spacer=(g.getFont().getHeight());
231 ligi 346
            g.setColor(0xFFFFFF);
347
            g.fillRect(0,0,this.getWidth(),this.getHeight());
348
            g.drawImage(bg_img,bg_offset,0, g.TOP | g.LEFT);
221 ligi 349
 
231 ligi 350
            if (bg_offset+bg_img.getWidth()<this.getWidth())
351
                g.drawImage(bg_img,bg_offset+bg_img.getWidth(),0, g.TOP | g.LEFT);
352
 
353
 
303 ligi 354
            g.setColor(0x000000);
231 ligi 355
 
356
            switch(state)
357
                {
358
                case STATEID_MOTORTEST:
359
                    for (int bar=0;bar<4;bar++)
360
                        {
361
                            g.setColor(((bar==act_motor)|motor_test_sel_all)?0x44CC44:0x4444DD);  
362
                            g.fillRect(this.getWidth()/(8*2)+bar*2*this.getWidth()/8,10,this.getWidth()/8,20+motor_test[bar]);
363
                            g.setColor(0x000000);
364
                            g.drawString(""+motor_test[bar] ,this.getWidth()/8+bar*2*this.getWidth()/8,10,Graphics.TOP | Graphics.HCENTER);
365
                            if(bar!=4)                      g.drawString(""+mk.debug_data.motor_val(bar) ,this.getWidth()/8+bar*2*this.getWidth()/8,30,Graphics.TOP | Graphics.HCENTER);
366
                        }
367
                    break;
368
 
303 ligi 369
                case STATEID_EDIT_PARAMS:
370
                    params_editor.paint(g);
371
                    break;
221 ligi 372
 
303 ligi 373
                case STATEID_SCANNING:
374
                    paint_lcd(g,true);
375
 
376
                    g.setClip(this.getWidth()/2-load_img.getWidth()/6,this.getHeight()/2-load_img.getHeight()/8, load_img.getWidth()/4,load_img.getHeight()/3);;
377
                    g.drawImage(load_img,this.getWidth()/2-load_img.getWidth()/8 - ((((frame_pos/3)%12)%4)*(load_img.getWidth()/4)) ,this.getHeight()/2-load_img.getHeight()/6- ((((frame_pos/3)%12)/4)*(load_img.getHeight()/3)), g.TOP | g.LEFT);
378
                    g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER);
379
                    break;
221 ligi 380
 
303 ligi 381
                case STATEID_MAINMENU: 
382
                    g.drawString("MK-Connection(" + (mk.connected?("open"+((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s"):"close")+"):",0,y_off,Graphics.TOP | Graphics.LEFT);
383
                    y_off+=spacer;
384
                    g.drawString(" Name:" + mk.name,0,y_off,Graphics.TOP | Graphics.LEFT);
385
                    y_off+=spacer;
386
                    g.drawString(" URL:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT);
387
                    y_off+=spacer;
388
                    g.drawString(" Version:" + mk.version.str,0,y_off,Graphics.TOP | Graphics.LEFT);
389
                    y_off+=spacer;
390
                    g.drawString("Packet Traffic:",0,y_off,Graphics.TOP | Graphics.LEFT);
391
                    y_off+=spacer;
392
                    g.drawString( " debug:"+mk.debug_data_count+ " LCD:" + mk.lcd_data_count + " vers:" + mk.version_data_count,0,y_off,Graphics.TOP | Graphics.LEFT);
393
                    y_off+=spacer;
394
                    g.drawString( " other:"+mk.other_data_count+" params:"+mk.params_data_count,0,y_off,Graphics.TOP | Graphics.LEFT);
221 ligi 395
 
396
 
397
 
398
 
303 ligi 399
                    // falltru wanted
400
                case STATEID_SELECT_PARAMSET:
401
 
402
                case STATEID_DEVICESELECT:
403
                    paint_menu(g);
404
                    break;
405
 
406
                case STATEID_FLIGHTVIEW:
407
 
408
                    g.drawString(mk.version.str+"(d"+mk.debug_data_count+ "l" + mk.lcd_data_count+  "v" + mk.version_data_count+"o"+mk.other_data_count+"p"+mk.params_data_count+")",0,y_off,Graphics.TOP | Graphics.LEFT);
221 ligi 409
 
303 ligi 410
                    y_off+=spacer;
221 ligi 411
 
303 ligi 412
                    g.drawString("n:"+mk.debug_data.nick_int() + " r:"+mk.debug_data.roll_int() + " an:"+mk.debug_data.accnick() + " ar:"+mk.debug_data.accroll() ,0,y_off,Graphics.TOP | Graphics.LEFT);
413
                    y_off+=spacer;
414
 
415
 
416
                    g.drawString("m1:"+mk.debug_data.motor_val(0) + " m2:"+mk.debug_data.motor_val(1)+" m3:"+mk.debug_data.motor_val(2) + " m4:"+mk.debug_data.motor_val(3) ,0,y_off,Graphics.TOP | Graphics.LEFT);
417
                    y_off+=spacer;
418
 
419
                    if (mk.connected)
420
                        {
421
                            g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
231 ligi 422
                            y_off+=spacer;
303 ligi 423
                            g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
231 ligi 424
                            y_off+=spacer;
303 ligi 425
                            g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
426
                        }
221 ligi 427
 
428
 
303 ligi 429
                    y_off=this.getHeight()-4*lcd_img.getHeight();
430
 
431
                    for ( int foo=0;foo<4;foo++)
432
                        {
433
                            for (int x=0;x<20;x++)
231 ligi 434
                                {
303 ligi 435
                                    g.setClip((lcd_img.getWidth()/222)*x,y_off,(lcd_img.getWidth()/222),lcd_img.getHeight());
231 ligi 436
                                            g.drawImage(lcd_img,(lcd_img.getWidth()/222)*x-(mk.LCD.LCD_str[foo].charAt(x)-' ')*(lcd_img.getWidth()/222),y_off, g.TOP | g.LEFT);
221 ligi 437
 
231 ligi 438
                                        }
439
                                    y_off+=lcd_img.getHeight();
440
                                }
221 ligi 441
 
231 ligi 442
                            g.setClip(0,0,this.getWidth(),this.getHeight());
221 ligi 443
 
444
 
445
 
446
 
303 ligi 447
 
231 ligi 448
                    // draw lines
221 ligi 449
 
231 ligi 450
                    for ( int x=0;x<this.getWidth();x++)
221 ligi 451
 
231 ligi 452
                        {
221 ligi 453
 
231 ligi 454
                            int p= (((-bg_offset+x-this.getWidth()-5)));
455
                            if (p<1)
456
                                p+=bg_img.getWidth();
457
                            p%=(bg_img.getWidth()-1);
221 ligi 458
 
231 ligi 459
                            g.setColor(0x156315);              
460
                            draw_graph_part(g,x,nick_line_pos_data[p]/line_scaler,nick_line_pos_data[p+1]/line_scaler);
461
                            g.setColor(0xCC1315);
462
                            draw_graph_part(g,x,roll_line_pos_data[p]/line_scaler,roll_line_pos_data[p+1]/line_scaler);
463
                            g.setColor(0xf8ef02);              
464
                            draw_graph_part(g,x,accnick_line_pos_data[p]/line_scaler,accnick_line_pos_data[p+1]/line_scaler);
465
                            g.setColor(0x19194d);
466
                            draw_graph_part(g,x,accroll_line_pos_data[p]/line_scaler,accroll_line_pos_data[p+1]/line_scaler);
221 ligi 467
 
468
 
181 ligi 469
 
231 ligi 470
                        }
471
 
472
                }
473
 
303 ligi 474
 
475
 
231 ligi 476
        } catch (Exception e) {}
181 ligi 477
    }
478
 
303 ligi 479
    private void connect_mk(String url,String name)
208 ligi 480
    {
303 ligi 481
        mk.connect_to(url,name);
221 ligi 482
 
208 ligi 483
    }
484
 
221 ligi 485
    public void draw_graph_part(Graphics g,int x,int y1,int y2)
486
    {
487
        g.fillRect(x,line_middle_y-y1,2,2 );
488
        if (y1>y2)
489
            g.fillRect(x,line_middle_y-y1,2,y1-y2);
490
        else
491
            g.fillRect(x,line_middle_y-y2,2,y2-y1);
492
    }
493
 
181 ligi 494
    /*********************************************** input Section **********************************************/
495
    // keys
221 ligi 496
    public boolean fullscreen=false;
231 ligi 497
    public int act_motor=0;
498
    public int act_motor_increase=0;
499
    public boolean motor_test_sel_all=false;
221 ligi 500
 
303 ligi 501
    public String[] main_menu_items={"Telemetry" , "Motor Test" , "Flight Settings","(NA)Tool Settings","Change Device" , "Quit " };
502
    public void chg_state(int next_state)
231 ligi 503
    {
303 ligi 504
        act_menu_select=0;
505
        // prepare next state
506
        switch(next_state)
507
            {
508
            case STATEID_SCANNING:
509
                lcd_lines=new String[3];
510
                lcd_lines[0]="Scanning for Devices";
511
                lcd_lines[1]="                    ";
512
                lcd_lines[2]="DUBwise v0.34       ";
513
                mk.close_connections(true);
514
 
515
                bt_scanner.search();
516
                break;
517
 
518
            case STATEID_SELECT_PARAMSET:
519
                menu_items=new String[5];
520
                menu_items[0]="ParamSet No 1";
521
                menu_items[1]="ParamSet No 2";
522
                menu_items[2]="ParamSet No 3";
523
                menu_items[3]="ParamSet No 4";
524
                menu_items[4]="ParamSet No 5";
525
                lcd_lines=new String[5];
526
                break;
527
 
528
            case STATEID_DEVICESELECT:
529
                menu_items=new String[bt_scanner.remote_device_count];
530
                for (int i=0;i<bt_scanner.remote_device_count;i++)
531
                    menu_items[i]=bt_scanner.remote_device_name[i];
532
                lcd_lines=new String[bt_scanner.remote_device_count];
533
                break;
534
 
535
            case STATEID_MAINMENU:
536
                menu_items=main_menu_items;
537
                lcd_lines=new String[menu_items.length];
538
                break;
539
 
540
            }
541
 
542
        // switch state
543
        state=next_state;
231 ligi 544
    }
545
 
546
 
547
    public void keyReleased(int keyCode)
548
    {
549
 
550
        switch(state)
551
            {
552
            case STATEID_MOTORTEST:
553
                act_motor_increase=0;
554
                break;
555
            }
556
 
557
    }
558
 
181 ligi 559
    public void keyPressed(int keyCode)
560
    {
561
 
303 ligi 562
        if (keyCode==KEY_STAR)
563
            {
564
                chg_state(STATEID_MAINMENU);
565
                return;
566
            }
567
        if (keyCode==KEY_POUND)
568
            {
569
                fullscreen=!fullscreen;
570
                setFullScreenMode(fullscreen);
571
                return;
572
            }
231 ligi 573
        switch(state)
208 ligi 574
            {
231 ligi 575
            case STATEID_MOTORTEST:
576
                switch (getGameAction (keyCode))
577
                            {
578
                            case UP:
579
                                act_motor_increase=-1;
580
                                break;
221 ligi 581
 
231 ligi 582
                            case DOWN:
583
                                act_motor_increase=1;
584
                                break;
208 ligi 585
 
231 ligi 586
                            case FIRE:
587
                                motor_test_sel_all=!motor_test_sel_all;
588
                                break;
589
 
590
                            case LEFT:
591
                                act_motor--;
303 ligi 592
                                if (act_motor<0) {act_motor=0; chg_state(STATEID_MAINMENU); }
231 ligi 593
                                break;
594
 
595
                            case RIGHT:
596
                                act_motor++;
597
                                act_motor%=4;
598
                                break;
599
                            }
600
 
601
                break;
303 ligi 602
            case STATEID_MAINMENU:
603
                if ( getGameAction (keyCode)==FIRE )
604
                    switch(act_menu_select)
605
                        {
606
                        case 0:
607
                            chg_state(STATEID_FLIGHTVIEW);
608
                            break;
231 ligi 609
 
303 ligi 610
                        case 1:
611
                            chg_state(STATEID_MOTORTEST);
612
                            break;
613
 
614
                        case 2:
615
                            chg_state(STATEID_SELECT_PARAMSET);
616
                            break;
617
                        case 3:
618
                            break;
619
 
620
                        case 4:
621
                            chg_state(STATEID_SCANNING);
622
                            break;
623
 
624
                        case 5:
625
                            quit=true;
626
                            break;
627
 
628
                        }
629
                else menu_keypress(keyCode);
630
                break;
631
 
632
            case STATEID_SELECT_PARAMSET:
633
                if ( getGameAction (keyCode)==FIRE )
634
                    {              
635
                        chg_state(STATEID_EDIT_PARAMS);
636
                    }
637
                else menu_keypress(keyCode);
638
                break;
639
            case STATEID_DEVICESELECT:
640
                if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count))
641
                    {
642
                    connect_mk("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1",bt_scanner.remote_device_name[keyCode-this.KEY_NUM0]);
643
                    chg_state(STATEID_MAINMENU);
644
                    }
231 ligi 645
                else
303 ligi 646
                if ( getGameAction (keyCode)==FIRE )
647
                    {              
648
                        connect_mk("btspp://"+bt_scanner.remote_device_mac[act_menu_select] + ":1",bt_scanner.remote_device_name[act_menu_select]);
649
                        chg_state(STATEID_MAINMENU);
650
                    }
651
                else menu_keypress(keyCode);
652
                break;
653
 
654
            case STATEID_EDIT_PARAMS:
655
                params_editor.keypress(keyCode,getGameAction (keyCode)) ;
656
                break;
657
 
658
            case STATEID_FLIGHTVIEW:
659
 
660
                switch (getGameAction (keyCode))
208 ligi 661
                    {
303 ligi 662
                    case UP:
663
                        mk.LCD.LCD_PREVPAGE();
664
                        break;
208 ligi 665
 
303 ligi 666
                    case DOWN:
667
                        mk.LCD.LCD_NEXTPAGE();
668
                        break;
231 ligi 669
 
303 ligi 670
                    case LEFT:
671
                        chg_state(STATEID_MAINMENU);
672
                        break;
231 ligi 673
 
208 ligi 674
                    }
303 ligi 675
                break;
208 ligi 676
            }
303 ligi 677
 
208 ligi 678
 
303 ligi 679
 
181 ligi 680
    }
681
 
682
 
683
 
684
 
685
 
686
 
687
 
688
 
689
}
690
 
691