Subversion Repositories FlightCtrl

Rev

Rev 411 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 411 Rev 475
Line -... Line 1...
-
 
1
 
1
/***************************************************************
2
/***************************************************************
2
 *
3
 *
3
 * minimal canvas to test Abstraction layer on various Phones
4
 * minimal canvas to test Abstraction layer on various Phones
4
 *                                                          
5
 *                                                          
5
 * Author:        Marcus -LiGi- Bueschleb                    
6
 * Author:        Marcus -LiGi- Bueschleb                    
Line 64... Line 65...
64
    public final static int STATEID_MOTORTEST        =3;
65
    public final static int STATEID_MOTORTEST        =3;
65
    public final static int STATEID_SELECT_PARAMSET  =4;
66
    public final static int STATEID_SELECT_PARAMSET  =4;
66
    public final static int STATEID_EDIT_PARAMS      =5;
67
    public final static int STATEID_EDIT_PARAMS      =5;
67
    public final static int STATEID_HANDLE_PARAMS    =6;
68
    public final static int STATEID_HANDLE_PARAMS    =6;
68
    public final static int STATEID_FLIGHTVIEW       =7;
69
    public final static int STATEID_FLIGHTVIEW       =7;
-
 
70
    public final static int STATEID_RAWDEBUG         =8;
-
 
71
    //    public final static int STATEID_RAWDEBUG         =8;
-
 
72
    public final static int STATEID_KEYCONTROL       =9;
Line 69... Line 73...
69
 
73
 
70
 
74
 
71
    public boolean fullscreen=false;
75
    public boolean fullscreen=false;
72
    public int act_motor=0;
76
    public int act_motor=0;
Line 73... Line 77...
73
    public int act_motor_increase=0;
77
    public int act_motor_increase=0;
74
    public boolean motor_test_sel_all=false;
78
    public boolean motor_test_sel_all=false;
-
 
79
 
-
 
80
    public String[] main_menu_items={"Telemetry","Raw Debug", "MK-KeyControl", "Motor Test" , "Flight Settings","(NA)Tool Settings","Proxy","Change Device" , "Quit " };
75
 
81
    public final static int MAINMENU_TELEMETRY     =0;
76
    public String[] main_menu_items={"Telemetry" , "Motor Test" , "Flight Settings","(NA)Tool Settings","Proxy","Change Device" , "Quit " };
82
    public final static int MAINMENU_RAWDEBUG      =1+MAINMENU_TELEMETRY;
77
    public final static int MAINMENU_TELEMETRY     =0;
83
    public final static int MAINMENU_KEYCONTROL    =1+MAINMENU_RAWDEBUG;
78
    public final static int MAINMENU_MOTORTES      =1;
84
    public final static int MAINMENU_MOTORTEST     =1+MAINMENU_KEYCONTROL;
79
    public final static int MAINMENU_PARAMS        =2;
85
    public final static int MAINMENU_PARAMS        =1+MAINMENU_MOTORTEST;
80
    public final static int MAINMENU_SETTINGS      =3;
86
    public final static int MAINMENU_SETTINGS      =1+MAINMENU_PARAMS;
Line 81... Line 87...
81
    public final static int MAINMENU_PROXY         =4;
87
    public final static int MAINMENU_PROXY         =1+MAINMENU_SETTINGS;
Line 82... Line 88...
82
    public final static int MAINMENU_DEVICESELECT  =5;
88
    public final static int MAINMENU_DEVICESELECT  =1+MAINMENU_PROXY;
83
    public final static int MAINMENU_QUIT          =6;
89
    public final static int MAINMENU_QUIT          =1+MAINMENU_DEVICESELECT;
-
 
90
   
-
 
91
    int local_max=-1;
84
   
92
 
Line 85... Line 93...
85
    int local_max=-1;
93
    int y_off=0;
86
 
94
    int spacer=0;
Line 234... Line 242...
234
       
242
       
Line 235... Line 243...
235
                frame_pos++;
243
                frame_pos++;
236
 
244
 
-
 
245
                switch(state)
237
                switch(state)
246
                    {
Line 238... Line 247...
238
                    {
247
                       
239
                    case STATEID_MOTORTEST:
248
                    case STATEID_MOTORTEST:
240
 
249
 
Line 379... Line 388...
379
                    if (local_max<Math.abs(mk.debug_data.accroll()))
388
                    if (local_max<Math.abs(mk.debug_data.accroll()))
380
                        local_max=Math.abs(mk.debug_data.accroll());
389
                        local_max=Math.abs(mk.debug_data.accroll());
381
                    line_scaler= local_max/(this.getHeight()/2)+1;
390
                    line_scaler= local_max/(this.getHeight()/2)+1;
382
                }
391
                }
Line -... Line 392...
-
 
392
 
-
 
393
 
-
 
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);  
383
 
396
 
-
 
397
            spacer=(f1.getHeight());
-
 
398
            spacer1=(f2.getHeight());
-
 
399
 
-
 
400
            //default Font
Line 384... Line 401...
384
            spacer=(g.getFont().getHeight());
401
            g.setFont(f1);
385
 
402
 
386
            if (state==STATEID_EDIT_PARAMS)
403
            if (state==STATEID_EDIT_PARAMS)
387
                {
404
                {
Line 400... Line 417...
400
 
417
 
Line 401... Line 418...
401
            g.setColor(0x000000);
418
            g.setColor(0x000000);
402
 
419
 
-
 
420
            switch(state)
-
 
421
                {
-
 
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);
403
            switch(state)
425
                    break;
404
                {
426
 
-
 
427
                case STATEID_MOTORTEST:
405
                case STATEID_MOTORTEST:
428
                    for (int bar=0;bar<4;bar++)
406
                    for (int bar=0;bar<4;bar++)
429
 
407
                        {
430
                        {
408
                            g.setColor(((bar==act_motor)|motor_test_sel_all)?0x44CC44:0x4444DD);  
431
                            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]);
432
                            g.fillRect(this.getWidth()/(8*2)+bar*2*this.getWidth()/8,10,this.getWidth()/8,20+motor_test[bar]);
Line 422... Line 445...
422
 
445
 
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);;
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);;
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);
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);
425
                    g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER);
448
                    g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER);
-
 
449
                    break;
-
 
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;
Line 426... Line 463...
426
                    break;
463
 
427
               
464
               
428
                case STATEID_MAINMENU: 
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);
429
                    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;
430
                    y_off+=spacer;
468
                    g.setFont(f2);
431
                    g.drawString(" Name:" + mk.name,0,y_off,Graphics.TOP | Graphics.LEFT);
469
                    g.drawString(" Name:" + mk.name,0,y_off,Graphics.TOP | Graphics.LEFT);
432
                    y_off+=spacer;
470
                    y_off+=spacer1;
433
                    g.drawString(" URL:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT);
471
                    g.drawString(" URL:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT);
434
                    y_off+=spacer;
472
                    y_off+=spacer1;
-
 
473
                    g.drawString(" Version:" + mk.version.str,0,y_off,Graphics.TOP | Graphics.LEFT);
-
 
474
                    y_off+=spacer1;
435
                    g.drawString(" Version:" + mk.version.str,0,y_off,Graphics.TOP | Graphics.LEFT);
475
 
436
                    y_off+=spacer;
476
                    g.setFont(f1);
-
 
477
                    g.drawString("Packet Traffic:",0,y_off,Graphics.TOP | Graphics.LEFT);
437
                    g.drawString("Packet Traffic:",0,y_off,Graphics.TOP | Graphics.LEFT);
478
                    y_off+=spacer;
438
                    y_off+=spacer;
479
                    g.setFont(f2);
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);
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);
Line 451... Line 492...
451
                    paint_menu(g);
492
                    paint_menu(g);
452
                    break;
493
                    break;
Line 453... Line 494...
453
                   
494
                   
Line -... Line 495...
-
 
495
                case STATEID_FLIGHTVIEW:
-
 
496
                   
-
 
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;
454
                case STATEID_FLIGHTVIEW:
504
                        }
Line 455... Line 505...
455
                   
505
 
Line 456... Line 506...
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);
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);
Line 540... Line 590...
540
    }
590
    }
Line 541... Line 591...
541
 
591
 
Line 542... Line 592...
542
    /*********************************************** input Section **********************************************/
592
    /*********************************************** input Section **********************************************/
Line 543... Line 593...
543
 
593
 
544
 
594
 
Line 545... Line 595...
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) ";
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) ";
Line 555... Line 605...
555
            {
605
            {
556
            case STATEID_SCANNING:
606
            case STATEID_SCANNING:
557
                lcd_lines=new String[4];
607
                lcd_lines=new String[4];
558
                lcd_lines[0]="Scanning for Devices";
608
                lcd_lines[0]="Scanning for Devices";
559
                lcd_lines[1]="                    ";
609
                lcd_lines[1]="                    ";
-
 
610
 
560
                lcd_lines[2]="DUBwise v0.40       ";
611
//#expand lcd_lines[2]="DUBwise v%VERSION%       ";
561
                lcd_lines[3]=intro_str.substring(0,20);
612
                lcd_lines[3]=intro_str.substring(0,20);
562
                mk.close_connections(true);
613
                mk.close_connections(true);
Line 563... Line 614...
563
               
614
               
564
                bt_scanner.search();
615
                bt_scanner.search();
Line 606... Line 657...
606
        switch(state)
657
        switch(state)
607
            {
658
            {
608
            case STATEID_MOTORTEST:
659
            case STATEID_MOTORTEST:
609
                act_motor_increase=0;
660
                act_motor_increase=0;
610
                break;
661
                break;
-
 
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;
611
            }
697
            }
Line 612... Line 698...
612
 
698
 
Line -... Line 699...
-
 
699
    }
-
 
700
 
-
 
701
 
613
    }
702
    public final static int[] keycontrol_bitfield={0,0};
614
 
703
 
Line 615... Line 704...
615
    public void keyPressed(int keyCode)
704
    public void keyPressed(int keyCode)
616
    {
705
    {
Line 630... Line 719...
630
                setFullScreenMode(fullscreen);
719
                setFullScreenMode(fullscreen);
631
                return;
720
                return;
632
            }
721
            }
633
        switch(state)
722
        switch(state)
634
            {
723
            {
-
 
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
 
635
            case STATEID_MOTORTEST:
759
            case STATEID_MOTORTEST:
636
                switch (getGameAction (keyCode))
760
                switch (getGameAction (keyCode))
637
                            {
761
                            {
638
                            case UP:
762
                            case UP:
639
                                act_motor_increase=-1;
763
                                act_motor_increase=-1;
Line 673... Line 797...
673
                break;
797
                break;
674
            case STATEID_MAINMENU:
798
            case STATEID_MAINMENU:
675
                if ( getGameAction (keyCode)==FIRE )
799
                if ( getGameAction (keyCode)==FIRE )
676
                    switch(act_menu_select)
800
                    switch(act_menu_select)
677
                        {
801
                        {
-
 
802
                        case MAINMENU_KEYCONTROL:
-
 
803
                            chg_state(STATEID_KEYCONTROL);
-
 
804
                            break;
678
 
805
                           
679
                        case MAINMENU_TELEMETRY :
806
                        case MAINMENU_TELEMETRY :
680
                            chg_state(STATEID_FLIGHTVIEW);
807
                            chg_state(STATEID_FLIGHTVIEW);
681
                            break;
808
                            break;
Line 682... Line 809...
682
 
809
 
683
                        case  MAINMENU_MOTORTES :
810
                        case  MAINMENU_MOTORTEST :
684
                            chg_state(STATEID_MOTORTEST);
811
                            chg_state(STATEID_MOTORTEST);
Line 685... Line 812...
685
                            break;
812
                            break;
686
 
813
 
687
                        case MAINMENU_PARAMS :
814
                        case MAINMENU_PARAMS :
688
                            chg_state(STATEID_SELECT_PARAMSET);
815
                            chg_state(STATEID_SELECT_PARAMSET);
689
                            break;
816
                            break;
-
 
817
                        case MAINMENU_SETTINGS:
690
                        case MAINMENU_SETTINGS:
818
                            break;
691
                            break;
819
 
692
                        case MAINMENU_PROXY:
820
                        case MAINMENU_PROXY:
Line 693... Line 821...
693
                            mk.do_proxy("socket://192.168.1.42:2323");
821
                            mk.do_proxy("socket://192.168.1.42:2323");
694
                            break;
822
                            break;
695
 
823
 
Line -... Line 824...
-
 
824
                        case MAINMENU_DEVICESELECT:
-
 
825
                            chg_state(STATEID_SCANNING);
-
 
826
                            break;
-
 
827
 
696
                        case MAINMENU_DEVICESELECT:
828
                        case MAINMENU_RAWDEBUG:
-
 
829
                            chg_state(STATEID_RAWDEBUG);
697
                            chg_state(STATEID_SCANNING);
830
                            break;
698
                            break;
831
 
Line 699... Line 832...
699
 
832
                        case MAINMENU_QUIT:
700
                        case  MAINMENU_QUIT:
833
                            // set quit Flag