Subversion Repositories FlightCtrl

Rev

Rev 411 | 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
                    {
475 ligi 247
 
231 ligi 248
                    case STATEID_MOTORTEST:
249
 
250
                        if (motor_test_sel_all)
251
                            for (int m=0;m<4;m++)
252
                                {
253
                                    motor_test[m]+=act_motor_increase;
254
                                    if (motor_test[m]<0)motor_test[m]=0;
403 ligi 255
                                    if (motor_test[m]>255)motor_test[m]=255;
231 ligi 256
                                }
257
                        else
258
                            {
259
                                motor_test[act_motor]+=act_motor_increase;
403 ligi 260
                                if (motor_test[act_motor]<0) motor_test[act_motor]=0;
261
                                if (motor_test[act_motor]>255) motor_test[act_motor]=255;
231 ligi 262
                            }
263
 
264
                        mk.motor_test(motor_test);
265
                        break;
303 ligi 266
 
267
                    case STATEID_SCANNING:
390 ligi 268
                        intro_str_delay--;
269
                        if (intro_str_delay<0)
270
                            {
271
                                intro_str_delay=1;
272
                                if (intro_str_pos>intro_str.length())
273
                                    intro_str_pos=0;
274
                                lcd_lines[3]=intro_str.substring(intro_str_pos,  (((intro_str_pos+20)>intro_str.length())?intro_str.length():intro_str_pos+20));
275
                                intro_str_pos++;
276
                            }
277
 
303 ligi 278
                        if (!bt_scanner.searching)
279
                                chg_state(STATEID_DEVICESELECT);
280
 
390 ligi 281
 
303 ligi 282
                        break;
283
 
284
 
285
 
231 ligi 286
                    }
287
 
221 ligi 288
                try {
231 ligi 289
                    nick_line_pos_data[-bg_offset] = mk.debug_data.nick_int();
290
                    roll_line_pos_data[-bg_offset] = mk.debug_data.roll_int();
291
                    accnick_line_pos_data[-bg_offset] = mk.debug_data.accnick();
292
                    accroll_line_pos_data[-bg_offset] = mk.debug_data.accroll();
221 ligi 293
                }
294
                catch (Exception e)
295
                    {
296
                        err+=e.toString();
297
                    }
298
 
181 ligi 299
 
221 ligi 300
 
301
 
208 ligi 302
                if (quit)
303
                    {
221 ligi 304
 
305
 
306
 
208 ligi 307
                        try
308
                            {
303 ligi 309
                                RecordStore.deleteRecordStore(RECORD_STORE_NAME);
310
                                RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true );
311
                                recStore.addRecord(mk.mk_url.getBytes(), 0, mk.mk_url.getBytes().length);
312
                                recStore.addRecord(mk.name.getBytes(), 0, mk.name.getBytes().length);
313
                                recStore.closeRecordStore();
208 ligi 314
 
315
                            }
316
                        catch (Exception e)
317
                            {
318
                                err+=e.toString();
319
                            }
320
 
321
                        root.quit();
322
                    }
323
                if (rescan)
324
                    {
303 ligi 325
 
326
                        rescan=false;
208 ligi 327
                    }
328
 
231 ligi 329
                try {
303 ligi 330
                    //rescan=false;
231 ligi 331
                    bg_offset--;
332
                    if (bg_offset==-bg_img.getWidth())
333
                        bg_offset=0;
334
                    com.nokia.mid.ui.DeviceControl.setLights(0,100);
335
                    //bt.tick();
336
                    // every state has sth to do in tick section
337
                }
338
                catch (Exception e)
339
                    {
340
 
341
                    }
181 ligi 342
 
343
 
231 ligi 344
                //                System.gc();
345
 
346
 
181 ligi 347
 
348
 
349
                sleeptime=1000/ 15 - (int) (System.currentTimeMillis()- loopStartTime);
350
 
403 ligi 351
 
352
 
181 ligi 353
                if (sleeptime<0)
231 ligi 354
                    sleeptime=100; // everyone has fi sleep
181 ligi 355
 
356
                try { Thread.sleep(sleeptime); }
357
                catch (Exception e)
358
                    {
231 ligi 359
                        err="Problem Sleeping ";
181 ligi 360
                    }
361
 
403 ligi 362
                }
363
                catch (Exception e)
364
                    {
365
                        err+=e.toString();
366
                    }
181 ligi 367
            }
368
    }
369
 
370
 
371
 
231 ligi 372
 
181 ligi 373
 
374
    // drawing section
375
    public void paint(Graphics g) {
303 ligi 376
        y_off=0;
231 ligi 377
        try {
221 ligi 378
 
231 ligi 379
            if (mk!=null)
380
                {
381
                    line_middle_y=this.getHeight()/2;
382
                    if (local_max<Math.abs(mk.debug_data.nick_int()))
383
                        local_max=Math.abs(mk.debug_data.nick_int());
384
                    if (local_max<Math.abs(mk.debug_data.roll_int()))
385
                        local_max=Math.abs(mk.debug_data.roll_int());
386
                    if (local_max<Math.abs(mk.debug_data.accnick()))
387
                        local_max=Math.abs(mk.debug_data.accnick());
388
                    if (local_max<Math.abs(mk.debug_data.accroll()))
389
                        local_max=Math.abs(mk.debug_data.accroll());
390
                    line_scaler= local_max/(this.getHeight()/2)+1;
391
                }
411 ligi 392
 
221 ligi 393
 
475 ligi 394
            Font f1 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);  
395
            Font f2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);  
396
 
397
            spacer=(f1.getHeight());
398
            spacer1=(f2.getHeight());
399
 
400
            //default Font
401
            g.setFont(f1);
402
 
411 ligi 403
            if (state==STATEID_EDIT_PARAMS)
404
                {
405
                    g.setColor(0x000000);
406
                    g.fillRect(0,0,this.getWidth(),this.getHeight());
407
                }
408
                else
409
                {
410
                    g.setColor(0xFFFFFF);
411
                    g.fillRect(0,0,this.getWidth(),this.getHeight());
412
                    g.drawImage(bg_img,bg_offset,0, g.TOP | g.LEFT);
413
 
414
                    if (bg_offset+bg_img.getWidth()<this.getWidth())
415
                        g.drawImage(bg_img,bg_offset+bg_img.getWidth(),0, g.TOP | g.LEFT);
416
                }
231 ligi 417
 
303 ligi 418
            g.setColor(0x000000);
231 ligi 419
 
420
            switch(state)
421
                {
475 ligi 422
                case STATEID_KEYCONTROL:
423
                    g.drawString("bf1:"+ keycontrol_bitfield[0] ,0,10,Graphics.TOP | Graphics.LEFT);
424
                    g.drawString("bf2:"+ keycontrol_bitfield[1] ,0,30,Graphics.TOP | Graphics.LEFT);
425
                    break;
426
 
231 ligi 427
                case STATEID_MOTORTEST:
428
                    for (int bar=0;bar<4;bar++)
475 ligi 429
 
231 ligi 430
                        {
431
                            g.setColor(((bar==act_motor)|motor_test_sel_all)?0x44CC44:0x4444DD);  
432
                            g.fillRect(this.getWidth()/(8*2)+bar*2*this.getWidth()/8,10,this.getWidth()/8,20+motor_test[bar]);
433
                            g.setColor(0x000000);
434
                            g.drawString(""+motor_test[bar] ,this.getWidth()/8+bar*2*this.getWidth()/8,10,Graphics.TOP | Graphics.HCENTER);
435
                            if(bar!=4)                      g.drawString(""+mk.debug_data.motor_val(bar) ,this.getWidth()/8+bar*2*this.getWidth()/8,30,Graphics.TOP | Graphics.HCENTER);
436
                        }
437
                    break;
438
 
303 ligi 439
                case STATEID_EDIT_PARAMS:
440
                    params_editor.paint(g);
441
                    break;
221 ligi 442
 
303 ligi 443
                case STATEID_SCANNING:
444
                    paint_lcd(g,true);
445
 
446
                    g.setClip(this.getWidth()/2-load_img.getWidth()/6,this.getHeight()/2-load_img.getHeight()/8, load_img.getWidth()/4,load_img.getHeight()/3);;
447
                    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);
448
                    g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER);
449
                    break;
475 ligi 450
 
451
                case STATEID_RAWDEBUG: 
452
                    g.setFont(f2);
453
                    for (int i=0;i<16;i++)
454
                        {
455
                            g.drawString("#"+i+"->" + mk.debug_data.analog[i] ,0,y_off,Graphics.TOP | Graphics.LEFT);
456
                            g.drawString("#"+(16+i)+"->" + mk.debug_data.analog[16+i] ,this.getWidth()/2,y_off,Graphics.TOP | Graphics.LEFT);
457
                            y_off+=spacer1;
458
                        }
459
 
460
 
461
 
462
                    break;
463
 
221 ligi 464
 
303 ligi 465
                case STATEID_MAINMENU: 
466
                    g.drawString("MK-Connection(" + (mk.connected?("open"+((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s"):"close")+"):",0,y_off,Graphics.TOP | Graphics.LEFT);
467
                    y_off+=spacer;
475 ligi 468
                    g.setFont(f2);
303 ligi 469
                    g.drawString(" Name:" + mk.name,0,y_off,Graphics.TOP | Graphics.LEFT);
475 ligi 470
                    y_off+=spacer1;
303 ligi 471
                    g.drawString(" URL:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT);
475 ligi 472
                    y_off+=spacer1;
303 ligi 473
                    g.drawString(" Version:" + mk.version.str,0,y_off,Graphics.TOP | Graphics.LEFT);
475 ligi 474
                    y_off+=spacer1;
475
 
476
                    g.setFont(f1);
477
                    g.drawString("Packet Traffic:",0,y_off,Graphics.TOP | Graphics.LEFT);
303 ligi 478
                    y_off+=spacer;
475 ligi 479
                    g.setFont(f2);
303 ligi 480
                    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 481
                    y_off+=spacer1;
303 ligi 482
                    g.drawString( " other:"+mk.other_data_count+" params:"+mk.params_data_count,0,y_off,Graphics.TOP | Graphics.LEFT);
221 ligi 483
 
484
 
485
 
486
 
303 ligi 487
                    // falltru wanted
488
                case STATEID_SELECT_PARAMSET:
325 ligi 489
                case STATEID_HANDLE_PARAMS:
303 ligi 490
 
491
                case STATEID_DEVICESELECT:
492
                    paint_menu(g);
493
                    break;
494
 
495
                case STATEID_FLIGHTVIEW:
496
 
475 ligi 497
 
498
                    // !!TODO!! check exactly which version those Datas where introduced
499
                    if (mk.version.compare(0,60)==mk.version.VERSION_PREVIOUS)
500
                        {
501
                            g.drawString("Power: " + (mk.debug_data.UBatt()/10) + "," +(mk.debug_data.UBatt()%10)+"V" ,0,y_off,Graphics.TOP | Graphics.LEFT);
502
                            g.drawString("Sender: " + mk.debug_data.SenderOkay(),this.getWidth()/2,y_off,Graphics.TOP | Graphics.LEFT);
503
                            y_off+=spacer;
504
                        }
505
 
303 ligi 506
                    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 507
 
303 ligi 508
                    y_off+=spacer;
221 ligi 509
 
303 ligi 510
                    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);
511
                    y_off+=spacer;
512
 
513
 
514
                    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);
515
                    y_off+=spacer;
516
 
517
                    if (mk.connected)
518
                        {
519
                            g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
231 ligi 520
                            y_off+=spacer;
303 ligi 521
                            g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
231 ligi 522
                            y_off+=spacer;
303 ligi 523
                            g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
524
                        }
221 ligi 525
 
526
 
303 ligi 527
                    y_off=this.getHeight()-4*lcd_img.getHeight();
528
 
529
                    for ( int foo=0;foo<4;foo++)
530
                        {
531
                            for (int x=0;x<20;x++)
231 ligi 532
                                {
303 ligi 533
                                    g.setClip((lcd_img.getWidth()/222)*x,y_off,(lcd_img.getWidth()/222),lcd_img.getHeight());
231 ligi 534
                                            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 535
 
231 ligi 536
                                        }
537
                                    y_off+=lcd_img.getHeight();
538
                                }
221 ligi 539
 
231 ligi 540
                            g.setClip(0,0,this.getWidth(),this.getHeight());
221 ligi 541
 
542
 
543
 
544
 
303 ligi 545
 
231 ligi 546
                    // draw lines
221 ligi 547
 
231 ligi 548
                    for ( int x=0;x<this.getWidth();x++)
221 ligi 549
 
231 ligi 550
                        {
221 ligi 551
 
231 ligi 552
                            int p= (((-bg_offset+x-this.getWidth()-5)));
553
                            if (p<1)
554
                                p+=bg_img.getWidth();
555
                            p%=(bg_img.getWidth()-1);
221 ligi 556
 
231 ligi 557
                            g.setColor(0x156315);              
558
                            draw_graph_part(g,x,nick_line_pos_data[p]/line_scaler,nick_line_pos_data[p+1]/line_scaler);
559
                            g.setColor(0xCC1315);
560
                            draw_graph_part(g,x,roll_line_pos_data[p]/line_scaler,roll_line_pos_data[p+1]/line_scaler);
561
                            g.setColor(0xf8ef02);              
562
                            draw_graph_part(g,x,accnick_line_pos_data[p]/line_scaler,accnick_line_pos_data[p+1]/line_scaler);
563
                            g.setColor(0x19194d);
564
                            draw_graph_part(g,x,accroll_line_pos_data[p]/line_scaler,accroll_line_pos_data[p+1]/line_scaler);
221 ligi 565
 
566
 
181 ligi 567
 
231 ligi 568
                        }
569
 
570
                }
571
 
303 ligi 572
 
573
 
231 ligi 574
        } catch (Exception e) {}
181 ligi 575
    }
576
 
303 ligi 577
    private void connect_mk(String url,String name)
208 ligi 578
    {
303 ligi 579
        mk.connect_to(url,name);
221 ligi 580
 
208 ligi 581
    }
582
 
221 ligi 583
    public void draw_graph_part(Graphics g,int x,int y1,int y2)
584
    {
585
        g.fillRect(x,line_middle_y-y1,2,2 );
586
        if (y1>y2)
587
            g.fillRect(x,line_middle_y-y1,2,y1-y2);
588
        else
589
            g.fillRect(x,line_middle_y-y2,2,y2-y1);
590
    }
591
 
181 ligi 592
    /*********************************************** input Section **********************************************/
221 ligi 593
 
314 ligi 594
 
475 ligi 595
    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 596
 
390 ligi 597
    int intro_str_pos=0;
598
    int intro_str_delay=3;
599
 
303 ligi 600
    public void chg_state(int next_state)
231 ligi 601
    {
303 ligi 602
        act_menu_select=0;
603
        // prepare next state
604
        switch(next_state)
605
            {
606
            case STATEID_SCANNING:
390 ligi 607
                lcd_lines=new String[4];
303 ligi 608
                lcd_lines[0]="Scanning for Devices";
609
                lcd_lines[1]="                    ";
475 ligi 610
 
611
//#expand lcd_lines[2]="DUBwise v%VERSION%       ";
390 ligi 612
                lcd_lines[3]=intro_str.substring(0,20);
303 ligi 613
                mk.close_connections(true);
614
 
615
                bt_scanner.search();
616
                break;
617
 
325 ligi 618
            case STATEID_HANDLE_PARAMS:
619
                menu_items=new String[2];
620
                menu_items[0]="write to MK";
621
                menu_items[1]="Discard";
622
                lcd_lines=new String[2];
623
 
624
                break;
625
 
303 ligi 626
            case STATEID_SELECT_PARAMSET:
627
                menu_items=new String[5];
314 ligi 628
                for (int i=0;i<5;i++)
629
                    menu_items[i]=mk.params.names[i];
630
 
303 ligi 631
                lcd_lines=new String[5];
632
                break;
633
 
634
            case STATEID_DEVICESELECT:
390 ligi 635
                menu_items=new String[bt_scanner.remote_device_count+1];
303 ligi 636
                for (int i=0;i<bt_scanner.remote_device_count;i++)
637
                    menu_items[i]=bt_scanner.remote_device_name[i];
390 ligi 638
                menu_items[bt_scanner.remote_device_count]="scan again";
639
                lcd_lines=new String[bt_scanner.remote_device_count+1];
303 ligi 640
                break;
641
 
642
            case STATEID_MAINMENU:
643
                menu_items=main_menu_items;
644
                lcd_lines=new String[menu_items.length];
645
                break;
646
 
647
            }
648
 
649
        // switch state
650
        state=next_state;
231 ligi 651
    }
652
 
653
 
654
    public void keyReleased(int keyCode)
655
    {
656
 
657
        switch(state)
658
            {
659
            case STATEID_MOTORTEST:
660
                act_motor_increase=0;
661
                break;
475 ligi 662
 
663
            case STATEID_KEYCONTROL:
664
                if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM8))
665
                    keycontrol_bitfield[0]&=255^( 1<<(keyCode-this.KEY_NUM0));
666
                else
667
                    if ((keyCode >= this.KEY_NUM8) && (keyCode <= this.KEY_NUM9))
668
                        keycontrol_bitfield[1]&=255^( 1<<(keyCode-this.KEY_NUM8));
669
                else
670
                    switch (getGameAction (keyCode))
671
                            {
672
                            case UP:
673
                                keycontrol_bitfield[1]&=255^4;
674
                                break;
675
 
676
                            case DOWN:
677
                                keycontrol_bitfield[1]&=255^8;
678
                                break;
679
 
680
 
681
                            case LEFT:
682
                                keycontrol_bitfield[1]&=255^16;
683
                                break;
684
 
685
                            case RIGHT:
686
                                keycontrol_bitfield[1]&=255^32;
687
                                break;
688
 
689
                            case FIRE:
690
                                keycontrol_bitfield[1]&=255^64;
691
                                break;
692
 
693
 
694
                            }
695
                mk.send_keys(keycontrol_bitfield);
696
                break;
231 ligi 697
            }
698
 
699
    }
700
 
475 ligi 701
 
702
    public final static int[] keycontrol_bitfield={0,0};
703
 
181 ligi 704
    public void keyPressed(int keyCode)
705
    {
706
 
303 ligi 707
        if (keyCode==KEY_STAR)
708
            {
325 ligi 709
                if (state==STATEID_EDIT_PARAMS)
710
                    chg_state(STATEID_HANDLE_PARAMS);
711
                else
712
                    chg_state(STATEID_MAINMENU);
713
 
303 ligi 714
                return;
715
            }
716
        if (keyCode==KEY_POUND)
717
            {
718
                fullscreen=!fullscreen;
719
                setFullScreenMode(fullscreen);
720
                return;
721
            }
231 ligi 722
        switch(state)
208 ligi 723
            {
475 ligi 724
            case STATEID_KEYCONTROL:
725
                if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM8))
726
                    keycontrol_bitfield[0]|=1<<(keyCode-this.KEY_NUM0);
727
                else
728
                if ((keyCode >= this.KEY_NUM8) && (keyCode <= this.KEY_NUM9))
729
                    keycontrol_bitfield[1]|=1<<(keyCode-this.KEY_NUM8);
730
 
731
                else
732
                    switch (getGameAction (keyCode))
733
                            {
734
                            case UP:
735
                                keycontrol_bitfield[1]|=4;
736
                                break;
737
 
738
                            case DOWN:
739
                                keycontrol_bitfield[1]|=8;
740
                                break;
741
 
742
 
743
                            case LEFT:
744
                                keycontrol_bitfield[1]|=16;
745
                                break;
746
 
747
                            case RIGHT:
748
                                keycontrol_bitfield[1]|=32;
749
                                break;
750
 
751
                            case FIRE:
752
                                keycontrol_bitfield[1]|=64;
753
                                break;
754
                            }
755
                mk.send_keys(keycontrol_bitfield);
756
                break;
757
 
758
 
231 ligi 759
            case STATEID_MOTORTEST:
760
                switch (getGameAction (keyCode))
761
                            {
762
                            case UP:
763
                                act_motor_increase=-1;
764
                                break;
221 ligi 765
 
231 ligi 766
                            case DOWN:
767
                                act_motor_increase=1;
768
                                break;
208 ligi 769
 
231 ligi 770
                            case FIRE:
771
                                motor_test_sel_all=!motor_test_sel_all;
772
                                break;
773
 
774
                            case LEFT:
775
                                act_motor--;
303 ligi 776
                                if (act_motor<0) {act_motor=0; chg_state(STATEID_MAINMENU); }
231 ligi 777
                                break;
778
 
779
                            case RIGHT:
780
                                act_motor++;
781
                                act_motor%=4;
782
                                break;
783
                            }
784
 
785
                break;
325 ligi 786
            case STATEID_HANDLE_PARAMS:
787
                if ( getGameAction (keyCode)==FIRE )
788
                    switch(act_menu_select)
789
                        {
790
                        case 0:
791
                            mk.write_params();
792
                        default:
793
                            chg_state(STATEID_MAINMENU);
794
                        }
795
                else
796
                    menu_keypress(keyCode);
797
                break;
303 ligi 798
            case STATEID_MAINMENU:
799
                if ( getGameAction (keyCode)==FIRE )
800
                    switch(act_menu_select)
801
                        {
475 ligi 802
                        case MAINMENU_KEYCONTROL:
803
                            chg_state(STATEID_KEYCONTROL);
804
                            break;
805
 
314 ligi 806
                        case MAINMENU_TELEMETRY :
303 ligi 807
                            chg_state(STATEID_FLIGHTVIEW);
808
                            break;
231 ligi 809
 
475 ligi 810
                        case  MAINMENU_MOTORTEST :
303 ligi 811
                            chg_state(STATEID_MOTORTEST);
812
                            break;
813
 
314 ligi 814
                        case MAINMENU_PARAMS :
303 ligi 815
                            chg_state(STATEID_SELECT_PARAMSET);
816
                            break;
314 ligi 817
                        case MAINMENU_SETTINGS:
303 ligi 818
                            break;
475 ligi 819
 
314 ligi 820
                        case MAINMENU_PROXY:
821
                            mk.do_proxy("socket://192.168.1.42:2323");
822
                            break;
303 ligi 823
 
314 ligi 824
                        case MAINMENU_DEVICESELECT:
303 ligi 825
                            chg_state(STATEID_SCANNING);
826
                            break;
827
 
475 ligi 828
                        case MAINMENU_RAWDEBUG:
829
                            chg_state(STATEID_RAWDEBUG);
830
                            break;
831
 
832
                        case MAINMENU_QUIT:
833
                            // set quit Flag
303 ligi 834
                            quit=true;
835
                            break;
836
 
837
                        }
838
                else menu_keypress(keyCode);
839
                break;
840
 
841
            case STATEID_SELECT_PARAMSET:
842
                if ( getGameAction (keyCode)==FIRE )
843
                    {              
314 ligi 844
                        mk.params.act_paramset=act_menu_select;
303 ligi 845
                        chg_state(STATEID_EDIT_PARAMS);
846
                    }
847
                else menu_keypress(keyCode);
848
                break;
849
            case STATEID_DEVICESELECT:
390 ligi 850
                /*
303 ligi 851
                if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count))
852
                    {
853
                    connect_mk("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1",bt_scanner.remote_device_name[keyCode-this.KEY_NUM0]);
854
                    chg_state(STATEID_MAINMENU);
855
                    }
231 ligi 856
                else
390 ligi 857
                */
858
 
303 ligi 859
                if ( getGameAction (keyCode)==FIRE )
860
                    {              
390 ligi 861
 
862
                        if (bt_scanner.remote_device_count > act_menu_select)
863
                            {
864
                                connect_mk("btspp://"+bt_scanner.remote_device_mac[act_menu_select] + ":1",bt_scanner.remote_device_name[act_menu_select]);
865
                                chg_state(STATEID_MAINMENU);
866
                            }
867
                        else
868
                            chg_state(STATEID_SCANNING);
303 ligi 869
                    }
870
                else menu_keypress(keyCode);
390 ligi 871
 
303 ligi 872
                break;
873
 
874
            case STATEID_EDIT_PARAMS:
875
                params_editor.keypress(keyCode,getGameAction (keyCode)) ;
876
                break;
877
 
878
            case STATEID_FLIGHTVIEW:
879
 
880
                switch (getGameAction (keyCode))
208 ligi 881
                    {
303 ligi 882
                    case UP:
883
                        mk.LCD.LCD_PREVPAGE();
884
                        break;
208 ligi 885
 
303 ligi 886
                    case DOWN:
887
                        mk.LCD.LCD_NEXTPAGE();
888
                        break;
231 ligi 889
 
303 ligi 890
                    case LEFT:
891
                        chg_state(STATEID_MAINMENU);
892
                        break;
231 ligi 893
 
208 ligi 894
                    }
303 ligi 895
                break;
208 ligi 896
            }
303 ligi 897
 
208 ligi 898
 
303 ligi 899
 
181 ligi 900
    }
901
 
902
 
903
 
904
 
905
 
906
 
907
 
908
 
909
}
910
 
911