Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
475 ligi 1
 
231 ligi 2
/***************************************************************
3
 *
4
 * minimal canvas to test Abstraction layer on various Phones
5
 *                                                          
6
 * Author:        Marcus -LiGi- Bueschleb                    
403 ligi 7
 *
8
 * see README for further Infos
9
 *
231 ligi 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
 
390 ligi 21
    // name/handle for the recordStore to memorize some stuff
303 ligi 22
    private final static String RECORD_STORE_NAME="bluetoothurl";
181 ligi 23
 
208 ligi 24
    private BTSearcher bt_scanner;
303 ligi 25
    public MKCommunicator mk=null;
208 ligi 26
    private MKStatistics mk_stat=null;
303 ligi 27
    private MKParamsEditor params_editor=null;
28
 
29
 
208 ligi 30
    private String err="";
303 ligi 31
    private DUBwise root;
181 ligi 32
 
221 ligi 33
    private Image bg_img;
34
    private Image bt_img;
35
    private Image lcd_img;
36
    private Image load_img;
37
 
38
 
39
    public int[] nick_line_pos_data;
40
    public int[] roll_line_pos_data;
41
 
42
    public int[] accnick_line_pos_data;
43
    public int[] accroll_line_pos_data;
44
 
303 ligi 45
    public int lcd_char_width=0;
46
    public int lcd_char_height=0;
221 ligi 47
 
48
    public int frame_pos=0;
49
 
50
    int line_scaler=20;
51
 
52
    public int line_middle_y;
53
 
303 ligi 54
    boolean quit=false;
55
    boolean rescan=true;
56
    int bg_offset=0;
57
 
390 ligi 58
    // variable to hold the current state
303 ligi 59
    public int state=-1;
390 ligi 60
 
61
    // id  for each state - must just be uniq - order isnt important
314 ligi 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;
475 ligi 70
    public final static int STATEID_RAWDEBUG         =8;
71
    //    public final static int STATEID_RAWDEBUG         =8;
72
    public final static int STATEID_KEYCONTROL       =9;
303 ligi 73
 
314 ligi 74
 
75
    public boolean fullscreen=false;
76
    public int act_motor=0;
77
    public int act_motor_increase=0;
78
    public boolean motor_test_sel_all=false;
79
 
475 ligi 80
    public String[] main_menu_items={"Telemetry","Raw Debug", "MK-KeyControl", "Motor Test" , "Flight Settings","(NA)Tool Settings","Proxy","Change Device" , "Quit " };
314 ligi 81
    public final static int MAINMENU_TELEMETRY     =0;
475 ligi 82
    public final static int MAINMENU_RAWDEBUG      =1+MAINMENU_TELEMETRY;
83
    public final static int MAINMENU_KEYCONTROL    =1+MAINMENU_RAWDEBUG;
84
    public final static int MAINMENU_MOTORTEST     =1+MAINMENU_KEYCONTROL;
85
    public final static int MAINMENU_PARAMS        =1+MAINMENU_MOTORTEST;
86
    public final static int MAINMENU_SETTINGS      =1+MAINMENU_PARAMS;
87
    public final static int MAINMENU_PROXY         =1+MAINMENU_SETTINGS;
88
    public final static int MAINMENU_DEVICESELECT  =1+MAINMENU_PROXY;
89
    public final static int MAINMENU_QUIT          =1+MAINMENU_DEVICESELECT;
303 ligi 90
 
91
    int local_max=-1;
92
 
93
    int y_off=0;
94
    int spacer=0;
475 ligi 95
    int spacer1=0;
96
 
303 ligi 97
    int[] motor_test = {0,0,0,0};
98
 
99
 
100
    String[] menu_items;
101
    int act_menu_select=0;
102
 
103
    String[] lcd_lines =null;
104
 
105
    public void paint_menu(Graphics g)
231 ligi 106
    {
303 ligi 107
        for ( int i=0;i<menu_items.length;i++)
108
            lcd_lines[i]=(act_menu_select==i?"# ":"  ") + menu_items[i];       
109
        paint_lcd(g,true);
110
    }
221 ligi 111
 
303 ligi 112
    public void menu_keypress(int keyCode)
113
    {
114
        switch (getGameAction (keyCode))
115
            {
116
            case UP:
117
                if (act_menu_select!=0) act_menu_select--;
390 ligi 118
                else
119
                    act_menu_select=menu_items.length-1;
303 ligi 120
                break;
121
 
122
            case DOWN:
123
                if (act_menu_select<(menu_items.length-1)) act_menu_select++;
390 ligi 124
                else act_menu_select=0;
303 ligi 125
                break;
126
 
127
            }
128
 
129
    }
130
 
131
    public void paint_lcd(Graphics g,boolean bottomup)
132
    {
403 ligi 133
 
303 ligi 134
        int y;
135
 
136
        for(int i=0;i<lcd_lines.length;i++)
137
            for (int pos=0;pos<20;pos++)
138
            {
139
                if (bottomup)
140
                    y=this.getHeight()-(lcd_lines.length-i)*lcd_char_height;
141
                else
142
                    y=i*lcd_char_height;
143
                g.setClip((lcd_img.getWidth()/222)*pos,y,(lcd_img.getWidth()/222),lcd_img.getHeight());
144
                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);
145
 
146
            }
147
    }
148
 
149
    public MKMiniCanvas(DUBwise _root)
150
    {
151
 
231 ligi 152
        root=_root;
181 ligi 153
 
303 ligi 154
        bt_scanner = new BTSearcher();
155
        params_editor = new MKParamsEditor(this);
156
        mk = new MKCommunicator();
157
        mk_stat= new MKStatistics(mk);
158
 
231 ligi 159
        try
160
            {
303 ligi 161
                // load all needed images
231 ligi 162
                lcd_img=Image.createImage("/lcd.png");
163
                bt_img=Image.createImage("/bt.png");
164
                bg_img=Image.createImage("/bg.jpg");               
165
                load_img=Image.createImage("/load.png");
166
            }
167
        catch (Exception e)
168
            {
169
                err+=e.toString();
170
            }
303 ligi 171
 
172
        lcd_char_width=lcd_img.getWidth()/222;
173
        lcd_char_height=lcd_img.getHeight();
221 ligi 174
 
175
 
231 ligi 176
        nick_line_pos_data=new int[bg_img.getWidth()];
177
        roll_line_pos_data=new int[bg_img.getWidth()];
178
        accnick_line_pos_data=new int[bg_img.getWidth()];
179
        accroll_line_pos_data=new int[bg_img.getWidth()];
221 ligi 180
 
231 ligi 181
        for (int c=0;c<bg_img.getWidth();c++)
182
            {
183
                nick_line_pos_data[c]=-1;
184
                roll_line_pos_data[c]=-1;
185
                accnick_line_pos_data[c]=-1;
186
                accroll_line_pos_data[c]=-1;
187
            }
221 ligi 188
 
189
 
231 ligi 190
        try
191
            {
303 ligi 192
                RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME , true );
181 ligi 193
 
303 ligi 194
                if (recStore.getNumRecords()==2)
208 ligi 195
                    {
303 ligi 196
 
197
                        //byte[] recData = new byte[recStore.getRecordSize(1)];
198
                        //int len = recStore.getRecord(1, recData, 0);
199
 
200
                        //byte[] recData2 = new byte[recStore.getRecordSize(2)];
201
                        //int len2 = recStore.getRecord(2, recData, 0);
202
 
203
                        byte[] url_data=recStore.getRecord(1);
204
                        byte[] name_data=recStore.getRecord(2);
205
 
206
                        connect_mk(new String(url_data, 0, url_data.length),new String(name_data, 0, name_data.length));
207
 
208 ligi 208
                    }
303 ligi 209
                recStore.closeRecordStore();
231 ligi 210
            }
211
        catch (Exception e)
212
            {
213
                err+=e.toString();
214
            }
181 ligi 215
 
303 ligi 216
        chg_state((mk.force_disconnect)?STATEID_SCANNING:STATEID_MAINMENU);
217
 
218
 
219
 
231 ligi 220
        new Thread(this).start();
181 ligi 221
 
231 ligi 222
    }
181 ligi 223
 
224
 
221 ligi 225
 
303 ligi 226
    /****************************** Thread ******************/
181 ligi 227
    // ticking runnable Section
228
    public void run()
229
    {
230
 
303 ligi 231
 
181 ligi 232
        while(true)
233
            {
403 ligi 234
                try {
235
 
231 ligi 236
                repaint();
237
                serviceRepaints();
238
 
181 ligi 239
                long loopStartTime = System.currentTimeMillis();
240
                long sleeptime=0;
241
                // ticked thing
221 ligi 242
 
243
                frame_pos++;
244
 
231 ligi 245
                switch(state)
246
                    {
483 ligi 247
                    case STATEID_KEYCONTROL:
248
                        mk.send_keys(keycontrol_bitfield);     
249
                        break;
250
 
231 ligi 251
                    case STATEID_MOTORTEST:
252
 
253
                        if (motor_test_sel_all)
254
                            for (int m=0;m<4;m++)
255
                                {
256
                                    motor_test[m]+=act_motor_increase;
257
                                    if (motor_test[m]<0)motor_test[m]=0;
403 ligi 258
                                    if (motor_test[m]>255)motor_test[m]=255;
231 ligi 259
                                }
260
                        else
261
                            {
262
                                motor_test[act_motor]+=act_motor_increase;
403 ligi 263
                                if (motor_test[act_motor]<0) motor_test[act_motor]=0;
264
                                if (motor_test[act_motor]>255) motor_test[act_motor]=255;
231 ligi 265
                            }
266
 
267
                        mk.motor_test(motor_test);
268
                        break;
303 ligi 269
 
270
                    case STATEID_SCANNING:
390 ligi 271
                        intro_str_delay--;
272
                        if (intro_str_delay<0)
273
                            {
274
                                intro_str_delay=1;
275
                                if (intro_str_pos>intro_str.length())
276
                                    intro_str_pos=0;
277
                                lcd_lines[3]=intro_str.substring(intro_str_pos,  (((intro_str_pos+20)>intro_str.length())?intro_str.length():intro_str_pos+20));
278
                                intro_str_pos++;
279
                            }
280
 
303 ligi 281
                        if (!bt_scanner.searching)
282
                                chg_state(STATEID_DEVICESELECT);
283
 
390 ligi 284
 
303 ligi 285
                        break;
286
 
287
 
288
 
231 ligi 289
                    }
290
 
221 ligi 291
                try {
231 ligi 292
                    nick_line_pos_data[-bg_offset] = mk.debug_data.nick_int();
293
                    roll_line_pos_data[-bg_offset] = mk.debug_data.roll_int();
294
                    accnick_line_pos_data[-bg_offset] = mk.debug_data.accnick();
295
                    accroll_line_pos_data[-bg_offset] = mk.debug_data.accroll();
221 ligi 296
                }
297
                catch (Exception e)
298
                    {
299
                        err+=e.toString();
300
                    }
301
 
181 ligi 302
 
221 ligi 303
 
304
 
208 ligi 305
                if (quit)
306
                    {
221 ligi 307
 
308
 
309
 
208 ligi 310
                        try
311
                            {
303 ligi 312
                                RecordStore.deleteRecordStore(RECORD_STORE_NAME);
313
                                RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true );
314
                                recStore.addRecord(mk.mk_url.getBytes(), 0, mk.mk_url.getBytes().length);
315
                                recStore.addRecord(mk.name.getBytes(), 0, mk.name.getBytes().length);
316
                                recStore.closeRecordStore();
208 ligi 317
 
318
                            }
319
                        catch (Exception e)
320
                            {
321
                                err+=e.toString();
322
                            }
323
 
324
                        root.quit();
325
                    }
326
                if (rescan)
327
                    {
303 ligi 328
 
329
                        rescan=false;
208 ligi 330
                    }
331
 
231 ligi 332
                try {
303 ligi 333
                    //rescan=false;
231 ligi 334
                    bg_offset--;
335
                    if (bg_offset==-bg_img.getWidth())
336
                        bg_offset=0;
337
                    com.nokia.mid.ui.DeviceControl.setLights(0,100);
338
                    //bt.tick();
339
                    // every state has sth to do in tick section
340
                }
341
                catch (Exception e)
342
                    {
343
 
344
                    }
181 ligi 345
 
346
 
231 ligi 347
                //                System.gc();
348
 
349
 
181 ligi 350
 
351
 
352
                sleeptime=1000/ 15 - (int) (System.currentTimeMillis()- loopStartTime);
353
 
403 ligi 354
 
355
 
181 ligi 356
                if (sleeptime<0)
231 ligi 357
                    sleeptime=100; // everyone has fi sleep
181 ligi 358
 
359
                try { Thread.sleep(sleeptime); }
360
                catch (Exception e)
361
                    {
231 ligi 362
                        err="Problem Sleeping ";
181 ligi 363
                    }
364
 
403 ligi 365
                }
366
                catch (Exception e)
367
                    {
368
                        err+=e.toString();
369
                    }
181 ligi 370
            }
371
    }
372
 
373
 
374
 
231 ligi 375
 
181 ligi 376
 
377
    // drawing section
378
    public void paint(Graphics g) {
303 ligi 379
        y_off=0;
231 ligi 380
        try {
221 ligi 381
 
231 ligi 382
            if (mk!=null)
383
                {
384
                    line_middle_y=this.getHeight()/2;
385
                    if (local_max<Math.abs(mk.debug_data.nick_int()))
386
                        local_max=Math.abs(mk.debug_data.nick_int());
387
                    if (local_max<Math.abs(mk.debug_data.roll_int()))
388
                        local_max=Math.abs(mk.debug_data.roll_int());
389
                    if (local_max<Math.abs(mk.debug_data.accnick()))
390
                        local_max=Math.abs(mk.debug_data.accnick());
391
                    if (local_max<Math.abs(mk.debug_data.accroll()))
392
                        local_max=Math.abs(mk.debug_data.accroll());
393
                    line_scaler= local_max/(this.getHeight()/2)+1;
394
                }
411 ligi 395
 
221 ligi 396
 
475 ligi 397
            Font f1 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);  
398
            Font f2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);  
399
 
400
            spacer=(f1.getHeight());
401
            spacer1=(f2.getHeight());
402
 
403
            //default Font
404
            g.setFont(f1);
405
 
411 ligi 406
            if (state==STATEID_EDIT_PARAMS)
407
                {
408
                    g.setColor(0x000000);
409
                    g.fillRect(0,0,this.getWidth(),this.getHeight());
410
                }
411
                else
412
                {
413
                    g.setColor(0xFFFFFF);
414
                    g.fillRect(0,0,this.getWidth(),this.getHeight());
415
                    g.drawImage(bg_img,bg_offset,0, g.TOP | g.LEFT);
416
 
417
                    if (bg_offset+bg_img.getWidth()<this.getWidth())
418
                        g.drawImage(bg_img,bg_offset+bg_img.getWidth(),0, g.TOP | g.LEFT);
419
                }
231 ligi 420
 
303 ligi 421
            g.setColor(0x000000);
231 ligi 422
 
423
            switch(state)
424
                {
475 ligi 425
                case STATEID_KEYCONTROL:
426
                    g.drawString("bf1:"+ keycontrol_bitfield[0] ,0,10,Graphics.TOP | Graphics.LEFT);
427
                    g.drawString("bf2:"+ keycontrol_bitfield[1] ,0,30,Graphics.TOP | Graphics.LEFT);
428
                    break;
429
 
231 ligi 430
                case STATEID_MOTORTEST:
431
                    for (int bar=0;bar<4;bar++)
475 ligi 432
 
231 ligi 433
                        {
434
                            g.setColor(((bar==act_motor)|motor_test_sel_all)?0x44CC44:0x4444DD);  
435
                            g.fillRect(this.getWidth()/(8*2)+bar*2*this.getWidth()/8,10,this.getWidth()/8,20+motor_test[bar]);
436
                            g.setColor(0x000000);
437
                            g.drawString(""+motor_test[bar] ,this.getWidth()/8+bar*2*this.getWidth()/8,10,Graphics.TOP | Graphics.HCENTER);
438
                            if(bar!=4)                      g.drawString(""+mk.debug_data.motor_val(bar) ,this.getWidth()/8+bar*2*this.getWidth()/8,30,Graphics.TOP | Graphics.HCENTER);
439
                        }
440
                    break;
441
 
303 ligi 442
                case STATEID_EDIT_PARAMS:
443
                    params_editor.paint(g);
444
                    break;
221 ligi 445
 
303 ligi 446
                case STATEID_SCANNING:
447
                    paint_lcd(g,true);
448
 
449
                    g.setClip(this.getWidth()/2-load_img.getWidth()/6,this.getHeight()/2-load_img.getHeight()/8, load_img.getWidth()/4,load_img.getHeight()/3);;
450
                    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);
451
                    g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER);
452
                    break;
475 ligi 453
 
454
                case STATEID_RAWDEBUG: 
455
                    g.setFont(f2);
456
                    for (int i=0;i<16;i++)
457
                        {
458
                            g.drawString("#"+i+"->" + mk.debug_data.analog[i] ,0,y_off,Graphics.TOP | Graphics.LEFT);
459
                            g.drawString("#"+(16+i)+"->" + mk.debug_data.analog[16+i] ,this.getWidth()/2,y_off,Graphics.TOP | Graphics.LEFT);
460
                            y_off+=spacer1;
461
                        }
462
 
463
 
464
 
465
                    break;
466
 
221 ligi 467
 
303 ligi 468
                case STATEID_MAINMENU: 
469
                    g.drawString("MK-Connection(" + (mk.connected?("open"+((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s"):"close")+"):",0,y_off,Graphics.TOP | Graphics.LEFT);
470
                    y_off+=spacer;
475 ligi 471
                    g.setFont(f2);
303 ligi 472
                    g.drawString(" Name:" + mk.name,0,y_off,Graphics.TOP | Graphics.LEFT);
475 ligi 473
                    y_off+=spacer1;
303 ligi 474
                    g.drawString(" URL:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT);
475 ligi 475
                    y_off+=spacer1;
303 ligi 476
                    g.drawString(" Version:" + mk.version.str,0,y_off,Graphics.TOP | Graphics.LEFT);
475 ligi 477
                    y_off+=spacer1;
478
 
479
                    g.setFont(f1);
480
                    g.drawString("Packet Traffic:",0,y_off,Graphics.TOP | Graphics.LEFT);
303 ligi 481
                    y_off+=spacer;
475 ligi 482
                    g.setFont(f2);
303 ligi 483
                    g.drawString( " debug:"+mk.debug_data_count+ " LCD:" + mk.lcd_data_count + " vers:" + mk.version_data_count,0,y_off,Graphics.TOP | Graphics.LEFT);
475 ligi 484
                    y_off+=spacer1;
303 ligi 485
                    g.drawString( " other:"+mk.other_data_count+" params:"+mk.params_data_count,0,y_off,Graphics.TOP | Graphics.LEFT);
221 ligi 486
 
487
 
488
 
489
 
303 ligi 490
                    // falltru wanted
491
                case STATEID_SELECT_PARAMSET:
325 ligi 492
                case STATEID_HANDLE_PARAMS:
303 ligi 493
 
494
                case STATEID_DEVICESELECT:
495
                    paint_menu(g);
496
                    break;
497
 
498
                case STATEID_FLIGHTVIEW:
499
 
475 ligi 500
 
501
                    // !!TODO!! check exactly which version those Datas where introduced
502
                    if (mk.version.compare(0,60)==mk.version.VERSION_PREVIOUS)
503
                        {
504
                            g.drawString("Power: " + (mk.debug_data.UBatt()/10) + "," +(mk.debug_data.UBatt()%10)+"V" ,0,y_off,Graphics.TOP | Graphics.LEFT);
505
                            g.drawString("Sender: " + mk.debug_data.SenderOkay(),this.getWidth()/2,y_off,Graphics.TOP | Graphics.LEFT);
506
                            y_off+=spacer;
507
                        }
508
 
303 ligi 509
                    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 510
 
303 ligi 511
                    y_off+=spacer;
221 ligi 512
 
303 ligi 513
                    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);
514
                    y_off+=spacer;
515
 
516
 
517
                    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);
518
                    y_off+=spacer;
519
 
520
                    if (mk.connected)
521
                        {
522
                            g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
231 ligi 523
                            y_off+=spacer;
303 ligi 524
                            g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
231 ligi 525
                            y_off+=spacer;
303 ligi 526
                            g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
527
                        }
221 ligi 528
 
529
 
303 ligi 530
                    y_off=this.getHeight()-4*lcd_img.getHeight();
531
 
532
                    for ( int foo=0;foo<4;foo++)
533
                        {
534
                            for (int x=0;x<20;x++)
231 ligi 535
                                {
303 ligi 536
                                    g.setClip((lcd_img.getWidth()/222)*x,y_off,(lcd_img.getWidth()/222),lcd_img.getHeight());
231 ligi 537
                                            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 538
 
231 ligi 539
                                        }
540
                                    y_off+=lcd_img.getHeight();
541
                                }
221 ligi 542
 
231 ligi 543
                            g.setClip(0,0,this.getWidth(),this.getHeight());
221 ligi 544
 
545
 
546
 
547
 
303 ligi 548
 
231 ligi 549
                    // draw lines
221 ligi 550
 
231 ligi 551
                    for ( int x=0;x<this.getWidth();x++)
221 ligi 552
 
231 ligi 553
                        {
221 ligi 554
 
231 ligi 555
                            int p= (((-bg_offset+x-this.getWidth()-5)));
556
                            if (p<1)
557
                                p+=bg_img.getWidth();
558
                            p%=(bg_img.getWidth()-1);
221 ligi 559
 
231 ligi 560
                            g.setColor(0x156315);              
561
                            draw_graph_part(g,x,nick_line_pos_data[p]/line_scaler,nick_line_pos_data[p+1]/line_scaler);
562
                            g.setColor(0xCC1315);
563
                            draw_graph_part(g,x,roll_line_pos_data[p]/line_scaler,roll_line_pos_data[p+1]/line_scaler);
564
                            g.setColor(0xf8ef02);              
565
                            draw_graph_part(g,x,accnick_line_pos_data[p]/line_scaler,accnick_line_pos_data[p+1]/line_scaler);
566
                            g.setColor(0x19194d);
567
                            draw_graph_part(g,x,accroll_line_pos_data[p]/line_scaler,accroll_line_pos_data[p+1]/line_scaler);
221 ligi 568
 
569
 
181 ligi 570
 
231 ligi 571
                        }
572
 
573
                }
574
 
303 ligi 575
 
576
 
231 ligi 577
        } catch (Exception e) {}
181 ligi 578
    }
579
 
303 ligi 580
    private void connect_mk(String url,String name)
208 ligi 581
    {
303 ligi 582
        mk.connect_to(url,name);
221 ligi 583
 
208 ligi 584
    }
585
 
221 ligi 586
    public void draw_graph_part(Graphics g,int x,int y1,int y2)
587
    {
588
        g.fillRect(x,line_middle_y-y1,2,2 );
589
        if (y1>y2)
590
            g.fillRect(x,line_middle_y-y1,2,y1-y2);
591
        else
592
            g.fillRect(x,line_middle_y-y2,2,y2-y1);
593
    }
594
 
181 ligi 595
    /*********************************************** input Section **********************************************/
221 ligi 596
 
314 ligi 597
 
475 ligi 598
    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 599
 
390 ligi 600
    int intro_str_pos=0;
601
    int intro_str_delay=3;
602
 
303 ligi 603
    public void chg_state(int next_state)
231 ligi 604
    {
303 ligi 605
        act_menu_select=0;
606
        // prepare next state
607
        switch(next_state)
608
            {
609
            case STATEID_SCANNING:
390 ligi 610
                lcd_lines=new String[4];
303 ligi 611
                lcd_lines[0]="Scanning for Devices";
612
                lcd_lines[1]="                    ";
475 ligi 613
 
614
//#expand lcd_lines[2]="DUBwise v%VERSION%       ";
390 ligi 615
                lcd_lines[3]=intro_str.substring(0,20);
303 ligi 616
                mk.close_connections(true);
617
 
618
                bt_scanner.search();
619
                break;
620
 
325 ligi 621
            case STATEID_HANDLE_PARAMS:
622
                menu_items=new String[2];
623
                menu_items[0]="write to MK";
624
                menu_items[1]="Discard";
625
                lcd_lines=new String[2];
626
 
627
                break;
628
 
303 ligi 629
            case STATEID_SELECT_PARAMSET:
630
                menu_items=new String[5];
314 ligi 631
                for (int i=0;i<5;i++)
632
                    menu_items[i]=mk.params.names[i];
633
 
303 ligi 634
                lcd_lines=new String[5];
635
                break;
636
 
637
            case STATEID_DEVICESELECT:
390 ligi 638
                menu_items=new String[bt_scanner.remote_device_count+1];
303 ligi 639
                for (int i=0;i<bt_scanner.remote_device_count;i++)
640
                    menu_items[i]=bt_scanner.remote_device_name[i];
390 ligi 641
                menu_items[bt_scanner.remote_device_count]="scan again";
642
                lcd_lines=new String[bt_scanner.remote_device_count+1];
303 ligi 643
                break;
644
 
645
            case STATEID_MAINMENU:
646
                menu_items=main_menu_items;
647
                lcd_lines=new String[menu_items.length];
648
                break;
649
 
650
            }
651
 
652
        // switch state
653
        state=next_state;
231 ligi 654
    }
655
 
656
 
657
    public void keyReleased(int keyCode)
658
    {
659
 
660
        switch(state)
661
            {
662
            case STATEID_MOTORTEST:
663
                act_motor_increase=0;
664
                break;
475 ligi 665
 
666
            case STATEID_KEYCONTROL:
667
                if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM8))
668
                    keycontrol_bitfield[0]&=255^( 1<<(keyCode-this.KEY_NUM0));
669
                else
670
                    if ((keyCode >= this.KEY_NUM8) && (keyCode <= this.KEY_NUM9))
671
                        keycontrol_bitfield[1]&=255^( 1<<(keyCode-this.KEY_NUM8));
672
                else
673
                    switch (getGameAction (keyCode))
674
                            {
675
                            case UP:
676
                                keycontrol_bitfield[1]&=255^4;
677
                                break;
678
 
679
                            case DOWN:
680
                                keycontrol_bitfield[1]&=255^8;
681
                                break;
682
 
683
 
684
                            case LEFT:
685
                                keycontrol_bitfield[1]&=255^16;
686
                                break;
687
 
688
                            case RIGHT:
689
                                keycontrol_bitfield[1]&=255^32;
690
                                break;
691
 
692
                            case FIRE:
693
                                keycontrol_bitfield[1]&=255^64;
694
                                break;
695
 
696
 
697
                            }
698
                mk.send_keys(keycontrol_bitfield);
699
                break;
231 ligi 700
            }
701
 
702
    }
703
 
475 ligi 704
 
705
    public final static int[] keycontrol_bitfield={0,0};
706
 
181 ligi 707
    public void keyPressed(int keyCode)
708
    {
709
 
303 ligi 710
        if (keyCode==KEY_STAR)
711
            {
325 ligi 712
                if (state==STATEID_EDIT_PARAMS)
713
                    chg_state(STATEID_HANDLE_PARAMS);
714
                else
715
                    chg_state(STATEID_MAINMENU);
716
 
303 ligi 717
                return;
718
            }
719
        if (keyCode==KEY_POUND)
720
            {
721
                fullscreen=!fullscreen;
722
                setFullScreenMode(fullscreen);
723
                return;
724
            }
231 ligi 725
        switch(state)
208 ligi 726
            {
475 ligi 727
            case STATEID_KEYCONTROL:
728
                if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM8))
729
                    keycontrol_bitfield[0]|=1<<(keyCode-this.KEY_NUM0);
730
                else
731
                if ((keyCode >= this.KEY_NUM8) && (keyCode <= this.KEY_NUM9))
732
                    keycontrol_bitfield[1]|=1<<(keyCode-this.KEY_NUM8);
733
 
734
                else
735
                    switch (getGameAction (keyCode))
736
                            {
737
                            case UP:
738
                                keycontrol_bitfield[1]|=4;
739
                                break;
740
 
741
                            case DOWN:
742
                                keycontrol_bitfield[1]|=8;
743
                                break;
744
 
745
 
746
                            case LEFT:
747
                                keycontrol_bitfield[1]|=16;
748
                                break;
749
 
750
                            case RIGHT:
751
                                keycontrol_bitfield[1]|=32;
752
                                break;
753
 
754
                            case FIRE:
755
                                keycontrol_bitfield[1]|=64;
756
                                break;
757
                            }
758
                mk.send_keys(keycontrol_bitfield);
759
                break;
760
 
761
 
231 ligi 762
            case STATEID_MOTORTEST:
763
                switch (getGameAction (keyCode))
764
                            {
765
                            case UP:
766
                                act_motor_increase=-1;
767
                                break;
221 ligi 768
 
231 ligi 769
                            case DOWN:
770
                                act_motor_increase=1;
771
                                break;
208 ligi 772
 
231 ligi 773
                            case FIRE:
774
                                motor_test_sel_all=!motor_test_sel_all;
775
                                break;
776
 
777
                            case LEFT:
778
                                act_motor--;
303 ligi 779
                                if (act_motor<0) {act_motor=0; chg_state(STATEID_MAINMENU); }
231 ligi 780
                                break;
781
 
782
                            case RIGHT:
783
                                act_motor++;
784
                                act_motor%=4;
785
                                break;
786
                            }
787
 
788
                break;
325 ligi 789
            case STATEID_HANDLE_PARAMS:
790
                if ( getGameAction (keyCode)==FIRE )
791
                    switch(act_menu_select)
792
                        {
793
                        case 0:
794
                            mk.write_params();
795
                        default:
796
                            chg_state(STATEID_MAINMENU);
797
                        }
798
                else
799
                    menu_keypress(keyCode);
800
                break;
303 ligi 801
            case STATEID_MAINMENU:
802
                if ( getGameAction (keyCode)==FIRE )
803
                    switch(act_menu_select)
804
                        {
475 ligi 805
                        case MAINMENU_KEYCONTROL:
806
                            chg_state(STATEID_KEYCONTROL);
807
                            break;
808
 
314 ligi 809
                        case MAINMENU_TELEMETRY :
303 ligi 810
                            chg_state(STATEID_FLIGHTVIEW);
811
                            break;
231 ligi 812
 
475 ligi 813
                        case  MAINMENU_MOTORTEST :
303 ligi 814
                            chg_state(STATEID_MOTORTEST);
815
                            break;
816
 
314 ligi 817
                        case MAINMENU_PARAMS :
303 ligi 818
                            chg_state(STATEID_SELECT_PARAMSET);
819
                            break;
314 ligi 820
                        case MAINMENU_SETTINGS:
303 ligi 821
                            break;
475 ligi 822
 
314 ligi 823
                        case MAINMENU_PROXY:
824
                            mk.do_proxy("socket://192.168.1.42:2323");
825
                            break;
303 ligi 826
 
314 ligi 827
                        case MAINMENU_DEVICESELECT:
303 ligi 828
                            chg_state(STATEID_SCANNING);
829
                            break;
830
 
475 ligi 831
                        case MAINMENU_RAWDEBUG:
832
                            chg_state(STATEID_RAWDEBUG);
833
                            break;
834
 
835
                        case MAINMENU_QUIT:
836
                            // set quit Flag
303 ligi 837
                            quit=true;
838
                            break;
839
 
840
                        }
841
                else menu_keypress(keyCode);
842
                break;
843
 
844
            case STATEID_SELECT_PARAMSET:
845
                if ( getGameAction (keyCode)==FIRE )
846
                    {              
314 ligi 847
                        mk.params.act_paramset=act_menu_select;
303 ligi 848
                        chg_state(STATEID_EDIT_PARAMS);
849
                    }
850
                else menu_keypress(keyCode);
851
                break;
852
            case STATEID_DEVICESELECT:
390 ligi 853
                /*
303 ligi 854
                if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count))
855
                    {
856
                    connect_mk("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1",bt_scanner.remote_device_name[keyCode-this.KEY_NUM0]);
857
                    chg_state(STATEID_MAINMENU);
858
                    }
231 ligi 859
                else
390 ligi 860
                */
861
 
303 ligi 862
                if ( getGameAction (keyCode)==FIRE )
863
                    {              
390 ligi 864
 
865
                        if (bt_scanner.remote_device_count > act_menu_select)
866
                            {
867
                                connect_mk("btspp://"+bt_scanner.remote_device_mac[act_menu_select] + ":1",bt_scanner.remote_device_name[act_menu_select]);
868
                                chg_state(STATEID_MAINMENU);
869
                            }
870
                        else
871
                            chg_state(STATEID_SCANNING);
303 ligi 872
                    }
873
                else menu_keypress(keyCode);
390 ligi 874
 
303 ligi 875
                break;
876
 
877
            case STATEID_EDIT_PARAMS:
878
                params_editor.keypress(keyCode,getGameAction (keyCode)) ;
879
                break;
880
 
881
            case STATEID_FLIGHTVIEW:
882
 
883
                switch (getGameAction (keyCode))
208 ligi 884
                    {
303 ligi 885
                    case UP:
886
                        mk.LCD.LCD_PREVPAGE();
887
                        break;
208 ligi 888
 
303 ligi 889
                    case DOWN:
890
                        mk.LCD.LCD_NEXTPAGE();
891
                        break;
231 ligi 892
 
303 ligi 893
                    case LEFT:
894
                        chg_state(STATEID_MAINMENU);
895
                        break;
231 ligi 896
 
208 ligi 897
                    }
303 ligi 898
                break;
208 ligi 899
            }
303 ligi 900
 
208 ligi 901
 
303 ligi 902
 
181 ligi 903
    }
904
 
905
 
906
 
907
 
908
 
909
 
910
 
911
 
912
}
913
 
914