Subversion Repositories FlightCtrl

Rev

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