Subversion Repositories FlightCtrl

Rev

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