Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
127 ligi 1
/**************************************************
2
 *
3
 *
4
 * Riddim
5
 * Remote Interactive Digital Drone Interface Mashup
6
 *
7
 * 2007-2008 Marcus -LiGi- Bueschleb
8
 *
9
 *
10
**************************************************/
125 ligi 11
 
127 ligi 12
#include "riddim.h"
41 ligi 13
 
127 ligi 14
#define FALSE 0
15
#define TRUE 1
41 ligi 16
 
127 ligi 17
#define test_bit(bit, array)    (array[bit/8] & (1<<(bit%8)))
50 ligi 18
 
127 ligi 19
int state=STATEID_SCANNING;
41 ligi 20
 
43 ligi 21
 
127 ligi 22
// from config 
23
char *input_evdev_name;
24
int  mk_socket_port=0;
25
int  loop_delay=0;
41 ligi 26
 
27
 
47 ligi 28
 
127 ligi 29
double nick_mul=0.3f;
30
double roll_mul=0.3f;
31
double gier_mul=0.3f;
32
double gas_mul=0.3f;
47 ligi 33
 
34
 
127 ligi 35
int rel_axis_nick=1;
36
int rel_axis_roll=0;
37
int rel_axis_gier=5;
38
int rel_axis_gas=2;
50 ligi 39
 
117 ligi 40
 
127 ligi 41
cfg_bool_t exit_after_init = cfg_false;
117 ligi 42
 
50 ligi 43
// time struct for measuring
44
struct timeval time_struct1;
45
struct timeval time_struct2;
46
 
47
 
127 ligi 48
char RxBuffer[150];
50 ligi 49
 
41 ligi 50
 
127 ligi 51
int status;
41 ligi 52
 
43 ligi 53
 
48 ligi 54
 
55
 
47 ligi 56
int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
57
char *button=NULL,*button_trigger=NULL, name_of_joystick[80];
58
 
59
struct js_event x52_event_struct;
60
 
48 ligi 61
int engines_on=0;
62
int old_engines_on=0;
63
 
64
char in_char;
65
 
127 ligi 66
struct x52 *x52_output;
47 ligi 67
 
127 ligi 68
int selected_bt_device=0;
47 ligi 69
 
127 ligi 70
 int yalv;           /* loop counter */
71
    size_t read_bytes;  /* how many bytes were read */
72
    struct input_event ev[64]; /* the events (up to 64 at once) */
47 ligi 73
 
127 ligi 74
int evdev_fd;
75
int evdev_out_fd;
43 ligi 76
 
127 ligi 77
int evdev_rw=TRUE;
43 ligi 78
 
127 ligi 79
int connect_evdev()
80
{
43 ligi 81
 
127 ligi 82
  struct input_devinfo {
83
    uint16_t bustype;
84
    uint16_t vendor;
85
    uint16_t product;
86
    uint16_t version;
87
  };
88
  struct input_devinfo device_info;
41 ligi 89
 
127 ligi 90
  if ((evdev_out_fd = open(input_evdev_name, O_WRONLY)) < 0)
91
    {
92
      printf(" cant open evdev read/write - trying readonly\n");
93
      evdev_rw=FALSE;
94
    }
95
  if ((evdev_fd = open(input_evdev_name, O_RDONLY)) < 0)
96
    {
97
      printf(" cant open evdev !");
98
      return 0;
99
    }
41 ligi 100
 
127 ligi 101
  ioctl(evdev_fd,EVIOCGID,&device_info);
102
 
103
  printf("vendor 0x%04hx product 0x%04hx version 0x%04hx \n",
104
         device_info.vendor, device_info.product,
105
         device_info.version);
41 ligi 106
 
107
 
127 ligi 108
  char name[256]= "Unknown";
41 ligi 109
 
127 ligi 110
  if(ioctl(evdev_fd, EVIOCGNAME(sizeof(name)), name) < 0) {
111
    perror("evdev ioctl");
41 ligi 112
  }
113
 
127 ligi 114
  printf("EVDEV reports name: %s\n", name);
41 ligi 115
 
127 ligi 116
  /* this macro is used to tell if "bit" is set in "array"
117
   * it selects a byte from the array, and does a boolean AND
118
   * operation with a byte that only has the relevant bit set.
119
   * eg. to check for the 12th bit, we do (array[1] & 1<<4)
120
   */
41 ligi 121
 
117 ligi 122
 
127 ligi 123
    uint8_t evtype_bitmask[EV_MAX/8 + 1];
117 ligi 124
 
127 ligi 125
    if(ioctl(evdev_fd, EVIOCGBIT(0, sizeof(evtype_bitmask)), evtype_bitmask) < 0)
126
      perror("evdev ioctl");
117 ligi 127
 
127 ligi 128
     printf("Supported event types:\n");
129
     for (yalv = 0; yalv < EV_MAX; yalv++) {
130
       if (test_bit(yalv, evtype_bitmask)) {
131
         /* this means that the bit is set in the event types list */
132
         printf("  Event type 0x%02x ", yalv);
133
         switch ( yalv)
134
           {
135
           case EV_KEY :
136
             printf(" (Keys or Buttons)\n");
137
             break;
138
           case EV_ABS :
139
             printf(" (Absolute Axes)\n");
140
             break;
141
           case EV_LED :
142
             printf(" (LEDs)\n");
143
             break;
144
           case EV_REP :
145
             printf(" (Repeat)\n");
146
             break;
147
           case EV_SYN :
148
             printf(" (Sync?)\n");
149
             break;
150
           case EV_REL :
151
             printf(" (Relative Axis)\n");
152
             break;
153
           case EV_MSC :
154
             printf(" (Misc)\n");
155
             break;
156
           default:
157
             printf(" (Unknown event type: 0x%04hx)\n", yalv);
158
           }}}
159
 
160
  return 1;
117 ligi 161
}
162
 
50 ligi 163
int connect_joy()
43 ligi 164
{
117 ligi 165
 
166
  axis = (int *) calloc( 100, sizeof( int ) );
167
  button = (char *)calloc( 100, sizeof( char ) );
168
  button_trigger = (char *) calloc( 100, sizeof( char ) );
41 ligi 169
 
43 ligi 170
 
117 ligi 171
  //  axis = (int *) calloc( num_of_axis, sizeof( int ) );
172
  // button = (char *)calloc( num_of_buttons, sizeof( char ) );
173
  // button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
174
 
175
 
43 ligi 176
  if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 )
177
    {
178
      printf( "Couldn't open joystick device %s\n", JOY_DEV );
50 ligi 179
      printf( "try modprobe joydev\n"  );
180
      return 0;
43 ligi 181
    }
182
 
183
  ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis );
184
  ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons );
185
  ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick );
186
 
187
  printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
188
         , name_of_joystick
189
         , num_of_axis
190
         , num_of_buttons );
191
 
192
  fcntl( x52_input_fd, F_SETFL, O_NONBLOCK );   /* use non-blocking mode */
193
 
50 ligi 194
  return 1;
43 ligi 195
}
196
 
197
 
41 ligi 198
 
199
 
200
 
48 ligi 201
 
43 ligi 202
 
203
void write_display(int line,char* text)
204
{
205
  if (x52_output) x52_settext(x52_output, line , text, strlen(text));
206
}
207
 
208
void clear_display()
209
{
210
  write_display(0,"");
211
  write_display(1,"");
212
  write_display(2,"");
213
}
214
 
215
 
216
void output_device_list()
217
{
218
  int i;
219
  char disp_txt[20];
220
  for(i=0;i<bt_device_count;i++)
221
    {
222
      if (i<3)
223
        {
224
 
225
          if (selected_bt_device==i)
226
            sprintf(disp_txt,"#%s",names[i]);
227
          else
228
            sprintf(disp_txt," %s",names[i]);
229
          write_display(i,disp_txt);
230
        }
231
    }
232
}
233
 
127 ligi 234
 
235
void print_device_list()
43 ligi 236
{
127 ligi 237
  int i;
238
  for(i=0;i<bt_device_count;i++)
239
    printf("device%i->%s\n",i,names[i]);
43 ligi 240
}
241
 
242
 
50 ligi 243
int r=0;
244
int count=0;
245
int connected=0;
43 ligi 246
 
117 ligi 247
 
248
int input=INPUT_NONE;
249
 
125 ligi 250
 
43 ligi 251
int main(int argc, char**argv)
252
{
125 ligi 253
 
43 ligi 254
  printf("Starting Riddim \n");
255
  printf("\tRemote Interactive Digital Drone Interface Mashup\n");
127 ligi 256
  printf("\nusage:\n");
257
  printf("\t riddim [config_file]\n\n");
125 ligi 258
 
259
 
260
  cfg_opt_t opts[] = {
127 ligi 261
 
262
    CFG_SIMPLE_BOOL("exit_after_init", &exit_after_init),
125 ligi 263
    CFG_SIMPLE_STR("input_evdev", &input_evdev_name),
127 ligi 264
    CFG_SIMPLE_INT("loop_delay", &loop_delay),
265
    CFG_SIMPLE_INT("mk_socket_port", &mk_socket_port),
266
 
267
    CFG_SIMPLE_FLOAT("nick_mul", &nick_mul),
268
    CFG_SIMPLE_FLOAT("roll_mul", &roll_mul),
269
    CFG_SIMPLE_FLOAT("gier_mul", &gier_mul),
270
    CFG_SIMPLE_FLOAT("gas_mul", &gas_mul),
271
 
272
    CFG_SIMPLE_INT("rel_axis_nick", &rel_axis_nick),
273
    CFG_SIMPLE_INT("rel_axis_roll", &rel_axis_roll),
274
    CFG_SIMPLE_INT("rel_axis_gier", &rel_axis_gier),
275
    CFG_SIMPLE_INT("rel_axis_gas", &rel_axis_gas),
276
 
125 ligi 277
    CFG_END()
278
  };
279
 
280
  cfg_t *cfg;
281
 
282
  //  input_evdev_name=strdup("/dev/event0");
127 ligi 283
  printf("Parsing config file ");
125 ligi 284
 
285
  cfg = cfg_init(opts, 0);
286
 
50 ligi 287
  if (argv[1])
288
    {
127 ligi 289
      printf("%s\n ",argv[1]);
290
      cfg_parse(cfg, argv[1]);
291
    }
292
  else
293
    {
294
      printf("/etc/riddim.conf\n");
295
      cfg_parse(cfg, "/etc/riddim.conf");
296
    }
297
  printf("input %s:\n",input_evdev_name);  
298
 
299
  // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips )
300
 
301
  if (mk_socket_port)
302
    {
303
        printf("connecting to local port: %i\n",mk_socket_port);
304
 
305
      if (connect_mk_localhost_socket(mk_socket_port)==-1)
306
        printf("cant connect !!");
307
      else
50 ligi 308
        {
127 ligi 309
          printf("connected to QC at adress: %s\n",argv[1]);
310
          connected=TRUE;
50 ligi 311
        }
312
    }
127 ligi 313
 
47 ligi 314
  int i;
117 ligi 315
 
43 ligi 316
  printf("\nInitializing X-52 input ..\n");
117 ligi 317
  if (connect_joy())
318
    {
319
    printf(".. done");//
320
    input=INPUT_JOYDEV;
321
    }
322
  else
323
    printf(".. ERROR ");//
43 ligi 324
 
125 ligi 325
    printf("\nInitializing evdev input (%s) ..\n",input_evdev_name);
117 ligi 326
  if (connect_evdev())
327
    {
328
    printf(".. done");//
329
    input=INPUT_EVDEV;
330
    }
331
  else
332
    printf(".. ERROR ");//
125 ligi 333
 
43 ligi 334
  printf("\nInitializing X-52 output ..");
335
 
47 ligi 336
  x52_output = x52_init();
337
 
338
  clear_display();
43 ligi 339
 
47 ligi 340
  write_display(0, "RIDDIM active");
43 ligi 341
 
47 ligi 342
  if (x52_output) x52_setbri(x52_output, 1,128);  
343
  if (x52_output)
344
    printf(" done \n");  
345
  else
346
    printf(" not found \n");      
43 ligi 347
 
127 ligi 348
  /*
50 ligi 349
  if (!connected)
43 ligi 350
    {
50 ligi 351
      printf("Scanning for Bluetooth Devices ..\n");
352
      write_display(1,"Bluetooth Scan");
353
      scan_bt();
354
      printf(" done \n");  
355
      printf(" %d Devices found \n",bt_device_count);  
127 ligi 356
      print_device_list() ;
43 ligi 357
    }
127 ligi 358
  */
41 ligi 359
 
43 ligi 360
  int v_old;
117 ligi 361
  int polls=0;
127 ligi 362
 
363
  int retval;
364
  if (exit_after_init)
365
    exit(0);
117 ligi 366
  printf("starting loop ..\n");
367
 
127 ligi 368
  struct input_event led_event;
369
  led_event.type=EV_LED;
117 ligi 370
 
127 ligi 371
  int complete_misses=0;
372
  if (evdev_out_fd)
373
    {
374
      led_event.code = LED_MISC;
375
      led_event.value = 1;
376
      retval = write(evdev_out_fd, &led_event, sizeof(struct input_event));
377
    }
117 ligi 378
 
127 ligi 379
  int confirm_misses;
41 ligi 380
  while( 1 )    
381
    {
117 ligi 382
 
127 ligi 383
      if (evdev_out_fd)
384
        {
385
          if (led_event.value)
386
            led_event.value = 0;
387
          else
388
            led_event.value = 1 ;
389
          retval = write(evdev_out_fd, &led_event, sizeof(struct input_event));
390
        }
391
 
392
      usleep(loop_delay);
117 ligi 393
      switch (input)
43 ligi 394
        {
127 ligi 395
 
117 ligi 396
 
397
        case INPUT_NONE:
127 ligi 398
          printf("starting input none\n");
117 ligi 399
          break;
43 ligi 400
 
117 ligi 401
        case INPUT_EVDEV:
402
           printf("input evdev\n");
403
 
127 ligi 404
           struct timeval tv;
405
           int retval;
406
           fd_set rfds;
407
           FD_ZERO(&rfds);
408
           FD_SET(evdev_fd,&rfds);
117 ligi 409
 
127 ligi 410
           tv.tv_sec = 0;
411
           tv.tv_usec = 5;
117 ligi 412
 
127 ligi 413
           retval = select(evdev_fd+1, &rfds, NULL, NULL, &tv);
117 ligi 414
 
127 ligi 415
           if (retval==-1)
416
             printf("error in select!!!!!!!!\n");
417
           else if (retval)
418
             {
419
             read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64);
117 ligi 420
 
127 ligi 421
             if (read_bytes < (int) sizeof(struct input_event)) {
422
               perror("evtest: short read");
423
               exit (1);
424
             }
425
 
426
             for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++)
427
               {
428
 
429
                 printf("%d type:%d code:%d val:%d \n",yalv,ev[yalv].type,ev[yalv].code,ev[yalv].value);
430
                 if (ev[yalv].type==EV_REL) axis[ ev[yalv].code]= ev[yalv].value;
431
                 if (ev[yalv].type==EV_KEY) button[ ev[yalv].code-256]= ev[yalv].value;
432
               }
433
 
434
 
435
             for (yalv=0;yalv<10;yalv++)
436
               printf("A%d %d -" , yalv, axis[yalv] );
437
             printf("\n");
438
 
439
             for (yalv=0;yalv<10;yalv++)
440
               printf("B%d %d -" , yalv, button[yalv] );
441
             //         printf("input read done: nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]); 
442
             }
443
           else
444
             printf("no data from evdev data from evdev: \n");
445
 
446
        break;
447
 
117 ligi 448
        case INPUT_JOYDEV:
449
          printf("input joydev\n");      
450
          // poll values from input device
451
 
452
          for (polls=0;polls<100;polls++) // FIXME - better Polling
453
            {
454
              read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
455
 
456
 
457
              /* see what to do with the event */
458
              switch (x52_event_struct.type & ~JS_EVENT_INIT)
459
                {
460
                case JS_EVENT_AXIS:
461
                  axis   [ x52_event_struct.number ] = x52_event_struct.value;
462
                  break;
463
                case JS_EVENT_BUTTON:
464
                  button [ x52_event_struct.number ] = x52_event_struct.value;
465
                  break;
466
                }
467
            }
468
 
469
          for( x=0 ; x<num_of_buttons ; ++x )
470
            if( button[x]==0)
471
              button_trigger[x]=0;
472
            else
473
              {
474
                if (button_trigger[x]<100)button_trigger[x]++;
475
              }
476
          break;
43 ligi 477
        }
478
 
117 ligi 479
      printf("input done\n");    
43 ligi 480
 
47 ligi 481
      switch(state)
482
        {
48 ligi 483
 
484
 
47 ligi 485
        case STATEID_SCANNING:
48 ligi 486
 
50 ligi 487
          state=STATEID_CONNECTING;
48 ligi 488
 
489
          ExternControl.Digital[0]=0;
490
          ExternControl.Digital[1]=0;
491
          ExternControl.RemoteTasten=0;
492
          ExternControl.Nick=(axis[1]>>8)*(-1)+127;;
493
 
494
          printf("nick%d\n",ExternControl.Nick);         
495
          ExternControl.Roll=(axis[0]>>8)*(-1)+127;;
496
          ExternControl.Gier=(axis[5]>>8)*(-1)+127;;
497
          ExternControl.Gas=(axis[2]>>8)*(-1)+127;
498
          ExternControl.Higt=0;
499
          ExternControl.free=0;
500
          ExternControl.Frame='t';
501
          ExternControl.Config=1;
502
 
503
          printf("sending data\n");
504
 
50 ligi 505
 
127 ligi 506
          if (connected)SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
50 ligi 507
          gettimeofday(&time_struct1,NULL);
48 ligi 508
 
47 ligi 509
          if (button_trigger[BUTTON_SELECT]==1)
510
            {
511
              state=STATEID_CONNECTING;
512
              clear_display();
513
              write_display(0,"connecting to");
514
              write_display(1,names[selected_bt_device]);
127 ligi 515
              //connect_mk(addrs[selected_bt_device]);
47 ligi 516
              write_display(0,"connected to");
517
            }
43 ligi 518
 
47 ligi 519
          if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1)
520
            {
521
              printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]);
522
              if (button_trigger[BUTTON_DOWN]==1)
523
                if (selected_bt_device>0) selected_bt_device--;
524
              if (button_trigger[BUTTON_UP]==1)
525
                if (selected_bt_device<bt_device_count-1) selected_bt_device++;
526
 
127 ligi 527
 
47 ligi 528
            }
529
          break;
48 ligi 530
 
47 ligi 531
        case STATEID_CONNECTING:
127 ligi 532
 
50 ligi 533
 
127 ligi 534
          confirm_misses=0;
535
          printf("connected:%d",connected);
536
          if (connected) while (RxBuffer[1]!='t')
537
            {
50 ligi 538
 
127 ligi 539
              RxBuffer[1]=0;
50 ligi 540
 
117 ligi 541
 
127 ligi 542
              //          ftime(&time_struct);
543
              printf("waiting for confirm frame ( misses:%d )\n",confirm_misses);
544
              RxBuffer[2]=0;
43 ligi 545
 
127 ligi 546
 
547
 
50 ligi 548
              r=0;
549
              in_char='#';
43 ligi 550
 
117 ligi 551
              while(in_char!='\n')
48 ligi 552
                {
127 ligi 553
                  count=read(mk_socket,&in_char,1);
50 ligi 554
                  if (in_char!=0)
555
                    {
556
                      RxBuffer[r++]=in_char;
557
                    }
558
                  else
559
                    {
560
                      RxBuffer[r++]='0';
561
                    }
117 ligi 562
                  //               printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char);
48 ligi 563
                }
50 ligi 564
              RxBuffer[r++]='\0';
127 ligi 565
              printf("%d--->%s\n",complete_misses,RxBuffer);
117 ligi 566
              // new
567
              if (button_trigger[12]>1)
568
                {
569
                  SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
570
                  button_trigger[12]=0;
571
                }
572
              if (++confirm_misses>4)
127 ligi 573
                {
574
                  complete_misses++;
575
                  printf("sending again\n");
576
                  SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
577
                }
48 ligi 578
            }
127 ligi 579
          else
580
            printf("not connected to mk\n");
50 ligi 581
          gettimeofday(&time_struct2,NULL);
43 ligi 582
 
50 ligi 583
          printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
584
          act_mode=button[24] | (button[25]<<1);
43 ligi 585
 
127 ligi 586
 
587
 
588
          // Step converting axis data to nick/roll/gier/gas/..
589
 
590
          act_nick=axis[rel_axis_nick]*nick_mul;
591
          act_roll=axis[rel_axis_roll]*roll_mul;
592
          act_gier=axis[rel_axis_gier]*gier_mul;
593
          act_gas=axis[rel_axis_gas]*gas_mul;
594
          act_gas=255;
595
 
596
 
597
          /*
50 ligi 598
          switch (act_mode)
599
            {
600
            case 0:
117 ligi 601
 
602
 
127 ligi 603
              act_nick=(axis[AXIS_NICK])*(INVERT_NICK);
604
              act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL);
605
              act_gier=(axis[AXIS_GIER])*(INVERT_GIER);
606
              act_gas=((axis[AXIS_GAS])-128)*(-1);
117 ligi 607
 
608
              // clip gas      
609
              if (act_gas<0) act_gas=0;
50 ligi 610
 
117 ligi 611
              if (act_gas>250) act_gas=250;        
612
 
613
////////              act_gas=0;
50 ligi 614
              break;
615
 
616
            case 1:
617
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2;
618
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2;
619
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2;
620
              act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
621
 
622
              break;
623
 
624
            case 2:
625
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3;
626
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3;
627
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3;
628
              act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
629
 
630
 
631
              break;
632
 
633
            }
127 ligi 634
          */  
48 ligi 635
          ExternControl.Digital[0]=0;
636
          ExternControl.Digital[1]=0;
637
          ExternControl.RemoteTasten=0;
50 ligi 638
          ExternControl.Nick=act_nick;  //(axis[1]>>8)*(-1)/2;
639
          //      printf("nick%d\n",ExternControl.Nick);         
117 ligi 640
          ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2;
48 ligi 641
          ExternControl.Gier=(axis[5]>>8);
117 ligi 642
          ExternControl.Gier=act_gier; // ************
48 ligi 643
          ExternControl.Gas=(axis[2]>>8)*(-1)+127;
117 ligi 644
          ExternControl.Gas=act_gas; // ************
645
          //      ExternControl.Gas=0; // ************
48 ligi 646
          ExternControl.Higt=0;
647
          ExternControl.free=0;
648
          ExternControl.Frame='t';
50 ligi 649
 
48 ligi 650
          ExternControl.Config=1;
117 ligi 651
          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);
48 ligi 652
 
653
 
654
 
127 ligi 655
          if (connected)
656
            {
657
              printf("sending data\n");
658
 
659
              SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
660
              gettimeofday(&time_struct1,NULL);
661
              printf("sent data\n");
662
            }
48 ligi 663
 
127 ligi 664
              // printf("sleeping\n");
665
              //          for (polls=0;polls<100;polls++) // FIXME - better Polling
666
              // printf("end_sleep\n");
667
 
47 ligi 668
          int v=axis[6]/655+50;
669
          if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v );  
670
          v_old=v;
671
 
48 ligi 672
          printf("v: %d \n",v);
127 ligi 673
 
674
 
47 ligi 675
          for (i=0;i<num_of_axis;i++)
676
            printf("A%d: %d  ", i,axis[i]>>8 );
677
 
678
          for( x=0 ; x<num_of_buttons ; ++x )
679
 
680
            printf("B%d: %d  ", x, button[x] );            
127 ligi 681
 
47 ligi 682
          break;
683
        }
127 ligi 684
 
48 ligi 685
      printf("\n");
47 ligi 686
      fflush(stdout);
127 ligi 687
      printf("loop fin ( misses:%d)\n",complete_misses);
43 ligi 688
 
50 ligi 689
    }
41 ligi 690
 
43 ligi 691
 
47 ligi 692
  /******************** Cleanup **********************/
693
  close(x52_input_fd);
127 ligi 694
  close(mk_socket);
41 ligi 695
 
696
  if (x52_output) x52_close(x52_output);
697
  return 0;
698
}