Subversion Repositories Projects

Rev

Rev 50 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 50 Rev 117
Line 27... Line 27...
27
#define BUTTON_SELECT 26
27
#define BUTTON_SELECT 26
28
#define BUTTON_DOWN 28
28
#define BUTTON_DOWN 28
29
#define BUTTON_UP 27
29
#define BUTTON_UP 27
Line -... Line 30...
-
 
30
 
-
 
31
 
-
 
32
// #define AXIS_ROLL 0
-
 
33
// #define AXIS_NICK 1
-
 
34
// #define AXIS_GIER 5
-
 
35
// #define AXIS_GAS  2
-
 
36
 
-
 
37
 
-
 
38
 
30
 
39
// for x52
31
 
40
/*
32
#define AXIS_ROLL 0
41
#define AXIS_ROLL 4
33
#define AXIS_NICK 1
42
#define AXIS_NICK 3
Line 34... Line 43...
34
#define AXIS_GIER 5
43
#define AXIS_GIER 5
35
#define AXIS_GAS  2
44
#define AXIS_GAS  2
36
 
45
 
37
#define INVERT_ROLL -1
46
#define INVERT_ROLL -1
-
 
47
#define INVERT_NICK -1
-
 
48
#define INVERT_GIER 1
-
 
49
#define INVERT_GAS  -1
-
 
50
*/
-
 
51
 
-
 
52
#define AXIS_ROLL 0
-
 
53
#define AXIS_NICK 1
-
 
54
#define AXIS_GIER 3
-
 
55
#define AXIS_GAS  2
-
 
56
 
-
 
57
#define INVERT_ROLL 1
-
 
58
#define INVERT_NICK -1
-
 
59
#define INVERT_GIER 1
-
 
60
#define INVERT_GAS  -1
-
 
61
 
-
 
62
 
-
 
63
#include <stdio.h>
-
 
64
#include <errno.h>
-
 
65
#include <string.h>
-
 
66
#include <sys/socket.h>
-
 
67
#include <sys/types.h>
-
 
68
#include <netinet/in.h>
-
 
69
#include <unistd.h>//for close() for socket
-
 
70
 
-
 
71
 
Line 38... Line 72...
38
#define INVERT_NICK -1
72
#define INPUT_NONE 0
39
#define INVERT_GIER 1
73
#define INPUT_JOYDEV 1
40
#define INVERT_GAS  -1
74
#define INPUT_EVDEV 2
Line 137... Line 171...
137
 
171
 
138
  free( ii );
172
  free( ii );
139
  close( sock );
173
  close( sock );
Line -... Line 174...
-
 
174
}
-
 
175
 
-
 
176
 int yalv;           /* loop counter */
-
 
177
    size_t read_bytes;  /* how many bytes were read */
-
 
178
    struct input_event ev[64]; /* the events (up to 64 at once) */
-
 
179
 
-
 
180
int evdev_fd;
-
 
181
int connect_evdev()
-
 
182
{
-
 
183
  if ((evdev_fd = open("/dev/input/event10", O_RDONLY)) < 0) {
-
 
184
        printf(" cant open evdev ");
-
 
185
        return 0;
-
 
186
    }
-
 
187
 
-
 
188
  return 1;
-
 
189
 
Line 140... Line 190...
140
}
190
 
141
 
191
}
-
 
192
 
-
 
193
int connect_joy()
-
 
194
{
-
 
195
 
-
 
196
  axis = (int *) calloc( 100, sizeof( int ) );
-
 
197
  button = (char *)calloc( 100, sizeof( char ) );
-
 
198
  button_trigger = (char *) calloc( 100, sizeof( char ) );
-
 
199
 
-
 
200
 
Line 142... Line 201...
142
 
201
  //  axis = (int *) calloc( num_of_axis, sizeof( int ) );
143
int connect_joy()
202
  // button = (char *)calloc( num_of_buttons, sizeof( char ) );
144
{
203
  // button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
Line 152... Line 211...
152
    }
211
    }
Line 153... Line 212...
153
 
212
 
154
  ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis );
213
  ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis );
155
  ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons );
214
  ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons );
156
  ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick );
-
 
157
 
-
 
158
  axis = (int *) calloc( num_of_axis, sizeof( int ) );
-
 
159
  button = (char *)calloc( num_of_buttons, sizeof( char ) );
-
 
Line 160... Line 215...
160
  button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
215
  ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick );
161
 
216
 
162
  printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
217
  printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
163
         , name_of_joystick
218
         , name_of_joystick
Line 266... Line 321...
266
    }
321
    }
267
}
322
}
Line 268... Line 323...
268
 
323
 
269
int connect_mk(char dest[18])
324
int connect_mk(char dest[18])
-
 
325
{
-
 
326
 
-
 
327
  struct sockaddr_rc addr ;
-
 
328
  struct sockaddr_in sa;
-
 
329
 
-
 
330
 sa.sin_family = AF_INET;
-
 
331
  sa.sin_addr.s_addr = htonl(0x0);
-
 
332
  sa.sin_port = htons(54321);
-
 
333
 
-
 
334
  // allocate a socket
-
 
335
  //  s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
-
 
336
  s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
-
 
337
  //);
-
 
338
 
-
 
339
  // set the connection parameters (who to connect to)
-
 
340
  addr.rc_family = AF_BLUETOOTH;
-
 
341
  addr.rc_channel = 1;
-
 
342
  str2ba( dest, &addr.rc_bdaddr );
-
 
343
 
-
 
344
  // connect to server
-
 
345
  //  status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
-
 
346
  status = connect(s,(struct sockaddr*) &sa, sizeof(struct sockaddr_in));
-
 
347
 
-
 
348
  return status;
-
 
349
 
270
{
350
  /*
Line 271... Line 351...
271
  struct sockaddr_rc addr ;
351
  struct sockaddr_rc addr ;
272
 
352
 
Line 280... Line 360...
280
 
360
 
281
  // connect to server
361
  // connect to server
Line 282... Line 362...
282
  status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
362
  status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
283
 
363
 
284
  return status;
364
  return status;
Line 285... Line 365...
285
 
365
  */
286
}
366
}
287
 
367
 
Line -... Line 368...
-
 
368
 
-
 
369
 
-
 
370
 
288
 
371
int r=0;
289
 
372
int count=0;
290
 
373
int connected=0;
291
int r=0;
374
 
Line 307... Line 390...
307
        }
390
        }
308
        printf("connected to QC at adress: %s\n",argv[1]);
391
        printf("connected to QC at adress: %s\n",argv[1]);
309
        connected=1;
392
        connected=1;
310
    }
393
    }
311
  int i;
394
  int i;
-
 
395
 
-
 
396
 
-
 
397
 
Line 312... Line -...
312
 
-
 
313
  printf("\nInitializing X-52 input ..\n");
-
 
314
  if (!connect_joy()) return 0;
-
 
Line -... Line 398...
-
 
398
 
-
 
399
 
-
 
400
 
-
 
401
  printf("\nInitializing X-52 input ..\n");
-
 
402
  if (connect_joy())
-
 
403
    {
-
 
404
    printf(".. done");//
-
 
405
    input=INPUT_JOYDEV;
-
 
406
    }
-
 
407
  else
-
 
408
    printf(".. ERROR ");//
-
 
409
 
-
 
410
  /*  printf("\nInitializing evdev input ..\n");
-
 
411
  if (connect_evdev())
-
 
412
    {
-
 
413
    printf(".. done");//
-
 
414
    input=INPUT_EVDEV;
-
 
415
    }
315
  printf(".. done");//
416
  else
Line 316... Line 417...
316
 
417
    printf(".. ERROR ");//
Line 317... Line 418...
317
 
418
  */
Line 338... Line 439...
338
      printf(" %d Devices found \n",bt_device_count);  
439
      printf(" %d Devices found \n",bt_device_count);  
339
    }
440
    }
Line 340... Line 441...
340
 
441
 
-
 
442
 
-
 
443
  int v_old;
-
 
444
  int polls=0;
-
 
445
  printf("starting loop ..\n");
-
 
446
 
341
 
447
 
342
  int v_old;
448
 
343
  while( 1 )    
-
 
-
 
449
  while( 1 )    
344
    {
450
    {
345
      // poll values from input device
-
 
346
      int polls=0;
451
 
-
 
452
      switch (input)
-
 
453
        {
347
      for (polls=0;polls<100;polls++) // FIXME - better Polling
454
         
-
 
455
        case INPUT_NONE:
348
        {
456
          printf("input none\n");
-
 
457
          usleep(10000);
Line -... Line 458...
-
 
458
         
349
          read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
459
          break;
-
 
460
 
-
 
461
        case INPUT_EVDEV:
-
 
462
           printf("input evdev\n");
-
 
463
          usleep(30000);
-
 
464
 
350
               
465
 
-
 
466
        read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64);
-
 
467
           printf("read done\n");
-
 
468
        if (read_bytes < (int) sizeof(struct input_event)) {
-
 
469
            perror("evtest: short read");
-
 
470
            exit (1);
351
 
471
        }
352
          /* see what to do with the event */
472
 
353
          switch (x52_event_struct.type & ~JS_EVENT_INIT)
473
        for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++)
354
            {
474
            {
355
            case JS_EVENT_AXIS:
475
              // 1 -> nick
356
              axis   [ x52_event_struct.number ] = x52_event_struct.value;
476
              // 2 -> gas
-
 
477
              // 4->roll
-
 
478
              // 5-> gier
-
 
479
              axis[ ev[yalv].code]= ev[yalv].value;
-
 
480
             
-
 
481
              printf("nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]);
-
 
482
              /*if ( ev[yalv].code==5)
357
              break;
483
                printf("Event: time %ld.%06ld, type %d, code %d, value %d\n",
358
            case JS_EVENT_BUTTON:
484
                       ev[yalv].time.tv_sec, ev[yalv].time.tv_usec, ev[yalv].type,
359
              button [ x52_event_struct.number ] = x52_event_struct.value;
-
 
360
              break;
-
 
361
            }
-
 
362
        }
-
 
363
               
-
 
364
      for( x=0 ; x<num_of_buttons ; ++x )
-
 
365
        if( button[x]==0)
-
 
366
          button_trigger[x]=0;
-
 
367
        else
-
 
Line -... Line 485...
-
 
485
                       ev[yalv].code, ev[yalv].value);
-
 
486
              */
-
 
487
            }
-
 
488
 
-
 
489
 
-
 
490
          break;
-
 
491
        case INPUT_JOYDEV:
-
 
492
          printf("input joydev\n");      
-
 
493
          // poll values from input device
-
 
494
         
-
 
495
          for (polls=0;polls<100;polls++) // FIXME - better Polling
-
 
496
            {
-
 
497
              read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
-
 
498
             
-
 
499
             
-
 
500
              /* see what to do with the event */
-
 
501
              switch (x52_event_struct.type & ~JS_EVENT_INIT)
-
 
502
                {
-
 
503
                case JS_EVENT_AXIS:
-
 
504
                  axis   [ x52_event_struct.number ] = x52_event_struct.value;
-
 
505
                  break;
-
 
506
                case JS_EVENT_BUTTON:
-
 
507
                  button [ x52_event_struct.number ] = x52_event_struct.value;
-
 
508
                  break;
-
 
509
                }
-
 
510
            }
-
 
511
         
-
 
512
          for( x=0 ; x<num_of_buttons ; ++x )
-
 
513
            if( button[x]==0)
-
 
514
              button_trigger[x]=0;
-
 
515
            else
-
 
516
              {
-
 
517
                if (button_trigger[x]<100)button_trigger[x]++;
Line 368... Line 518...
368
          {
518
              }
369
            if (button_trigger[x]<100)button_trigger[x]++;
519
          break;
Line 425... Line 575...
425
 
575
 
Line 426... Line 576...
426
          RxBuffer[1]=0;
576
          RxBuffer[1]=0;
427
 
577
 
-
 
578
 
-
 
579
          //      ftime(&time_struct);
-
 
580
          printf("waiting for confirm frame\n");
428
 
581
          RxBuffer[2]=0;
429
          //      ftime(&time_struct);
582
          int confirm_misses=0;
Line 430... Line 583...
430
          //printf("t:%d",time_struct.millitm);
583
 
431
          while (RxBuffer[1]!='t')
584
          while (RxBuffer[2]!='t')
Line 432... Line 585...
432
            {
585
            {
433
 
586
 
434
              r=0;
587
              r=0;
435
              in_char='#';
588
              in_char='#';
436
 
589
 
437
              while(in_char!='\r')
590
              while(in_char!='\n')
438
                {
591
                {
439
                  count=read(s,&in_char,1);
592
                  count=read(s,&in_char,1);
440
                  if (in_char!=0)
593
                  if (in_char!=0)
441
                    {
594
                    {
442
                      RxBuffer[r++]=in_char;
595
                      RxBuffer[r++]=in_char;
443
                    }
596
                    }
444
                  else
597
                  else
445
                    {
598
                    {
446
                      RxBuffer[r++]='0';
599
                      RxBuffer[r++]='0';
-
 
600
                    }
-
 
601
                  //               printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char);
-
 
602
                }
-
 
603
              RxBuffer[r++]='\0';
-
 
604
              printf("--->%s\n",RxBuffer);
-
 
605
              // new
-
 
606
              if (button_trigger[12]>1)
-
 
607
                {
447
                    }
608
                  SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
448
                  //  printf("count:%d r:%d %d %c \n",count , r, in_char, in_char);
609
                  button_trigger[12]=0;
449
                }
610
                }
Line 450... Line 611...
450
              RxBuffer[r++]='\0';
611
              if (++confirm_misses>4)
451
              printf("--->%s\n",RxBuffer);
612
              SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
Line 452... Line 613...
452
 
613
               
453
            }
614
            }
454
          gettimeofday(&time_struct2,NULL);
615
          gettimeofday(&time_struct2,NULL);
-
 
616
 
-
 
617
          printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
455
 
618
          act_mode=button[24] | (button[25]<<1);
456
          printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
619
 
457
          act_mode=button[24] | (button[25]<<1);
620
          switch (act_mode)
458
 
621
            {
-
 
622
            case 0:
-
 
623
 
-
 
624
 
-
 
625
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK);
-
 
626
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL);
Line -... Line 627...
-
 
627
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER);
459
          switch (act_mode)
628
              act_gas=((axis[AXIS_GAS]>>8)-128)*(-1);
Line 460... Line 629...
460
            {
629
             
461
            case 0:
630
              // clip gas      
462
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK);
631
              if (act_gas<0) act_gas=0;
Line 488... Line 657...
488
          ExternControl.Digital[0]=0;
657
          ExternControl.Digital[0]=0;
489
          ExternControl.Digital[1]=0;
658
          ExternControl.Digital[1]=0;
490
          ExternControl.RemoteTasten=0;
659
          ExternControl.RemoteTasten=0;
491
          ExternControl.Nick=act_nick;  //(axis[1]>>8)*(-1)/2;
660
          ExternControl.Nick=act_nick;  //(axis[1]>>8)*(-1)/2;
492
          //      printf("nick%d\n",ExternControl.Nick);         
661
          //      printf("nick%d\n",ExternControl.Nick);         
493
          ExternControl.Roll=act_roll; //(axis[0]>>8)*(-1)/2;
662
          ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2;
494
          ExternControl.Gier=(axis[5]>>8);
663
          ExternControl.Gier=(axis[5]>>8);
-
 
664
          ExternControl.Gier=act_gier; // ************
495
          ExternControl.Gas=(axis[2]>>8)*(-1)+127;
665
          ExternControl.Gas=(axis[2]>>8)*(-1)+127;
-
 
666
          ExternControl.Gas=act_gas; // ************
-
 
667
          //      ExternControl.Gas=0; // ************
496
          ExternControl.Higt=0;
668
          ExternControl.Higt=0;
497
          ExternControl.free=0;
669
          ExternControl.free=0;
498
          ExternControl.Frame='t';
670
          ExternControl.Frame='t';
Line 499... Line 671...
499
         
671
         
500
          ExternControl.Config=1;
672
          ExternControl.Config=1;
Line 501... Line 673...
501
          printf("act_mode %d , act_nick %d , act_roll %d , act_gier %d , act_gas %d",act_mode , act_nick  , act_roll  , act_gier , act_gas);
673
          printf("---+++act_mode %d , act_nick %d , act_roll %d , act_gier %d , act_gas %d",act_mode , act_nick  , act_roll  , act_gier , act_gas);
Line 508... Line 680...
508
          gettimeofday(&time_struct1,NULL);
680
          gettimeofday(&time_struct1,NULL);
509
          printf("sent data\n");
681
          printf("sent data\n");
Line 510... Line 682...
510
 
682
 
511
         
683
         
512
          // printf("sleeping\n");
684
          // printf("sleeping\n");
Line 513... Line 685...
513
          // usleep(10000);
685
          //      for (polls=0;polls<100;polls++) // FIXME - better Polling
514
          // printf("end_sleep\n");
686
          // printf("end_sleep\n");
515
 
687