Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
41 ligi 1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include <fcntl.h>
5
#include "lib/x52/x52.h"
6
#include <unistd.h>
7
#include <sys/socket.h>
8
#include <bluetooth/bluetooth.h>
9
#include <bluetooth/hci.h>
10
#include <bluetooth/hci_lib.h>
11
 
50 ligi 12
#include <sys/time.h>
41 ligi 13
 
50 ligi 14
 
43 ligi 15
#include <bluetooth/rfcomm.h>
41 ligi 16
 
43 ligi 17
 
41 ligi 18
#include <linux/joystick.h>
19
#define JOY_DEV "/dev/input/js0"
20
 
21
#define MAX_BT_DEVICES 3
22
 
47 ligi 23
 
24
#define STATEID_SCANNING 0
25
#define STATEID_CONNECTING 1
26
 
27
#define BUTTON_SELECT 26
28
#define BUTTON_DOWN 28
29
#define BUTTON_UP 27
30
 
50 ligi 31
 
117 ligi 32
// #define AXIS_ROLL 0
33
// #define AXIS_NICK 1
34
// #define AXIS_GIER 5
35
// #define AXIS_GAS  2
36
 
37
 
38
 
39
// for x52
40
/*
41
#define AXIS_ROLL 4
42
#define AXIS_NICK 3
50 ligi 43
#define AXIS_GIER 5
44
#define AXIS_GAS  2
45
 
46
#define INVERT_ROLL -1
47
#define INVERT_NICK -1
48
#define INVERT_GIER 1
49
#define INVERT_GAS  -1
117 ligi 50
*/
50 ligi 51
 
117 ligi 52
#define AXIS_ROLL 0
53
#define AXIS_NICK 1
54
#define AXIS_GIER 3
55
#define AXIS_GAS  2
50 ligi 56
 
117 ligi 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
 
72
#define INPUT_NONE 0
73
#define INPUT_JOYDEV 1
74
#define INPUT_EVDEV 2
75
 
76
 
50 ligi 77
// time struct for measuring
78
struct timeval time_struct1;
79
struct timeval time_struct2;
80
 
81
 
82
int act_nick=0;
83
int act_roll=0;
84
int act_gier=0;
85
int act_gas=0;
86
int act_mode=0;
87
 
41 ligi 88
int bt_device_count=0;
89
 
90
char names[MAX_BT_DEVICES][248];
91
char addrs[MAX_BT_DEVICES][19];
92
 
43 ligi 93
int s, status;
94
unsigned char TxBuffer[150];
95
unsigned char _TxBuffer[150];
96
 
48 ligi 97
char RxBuffer[150];
98
 
99
 
47 ligi 100
int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
101
char *button=NULL,*button_trigger=NULL, name_of_joystick[80];
102
 
103
struct js_event x52_event_struct;
104
 
48 ligi 105
int engines_on=0;
106
int old_engines_on=0;
107
 
108
char in_char;
109
 
50 ligi 110
struct ExternControl_s
47 ligi 111
{
112
  unsigned char Digital[2];   // (noch unbenutzt)
113
  unsigned char RemoteTasten; //(gab es schon für das virtuelle Display)
114
  signed char   Nick;
115
  signed char   Roll;
116
  signed char   Gier;
117
  unsigned char Gas;          //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum)
48 ligi 118
  signed char   Higt;        //(Höhenregler)
47 ligi 119
  unsigned char free;         // (unbenutzt)
120
  unsigned char Frame;        // (Bestätigung)
121
  unsigned char Config;
50 ligi 122
};
47 ligi 123
 
124
 
50 ligi 125
struct ExternControl_s  ExternControl ;
47 ligi 126
 
43 ligi 127
int state=STATEID_SCANNING;
128
 
129
 
130
struct x52 *x52_output;
131
 
132
int selected_bt_device=0;
41 ligi 133
void scan_bt()
134
{
135
  inquiry_info *ii = NULL;
136
 
137
  int dev_id, sock, len, flags;
138
  int i;
139
  char addr[19] = { 0 };
140
  char name[248] = { 0 };
141
 
142
  dev_id = hci_get_route(NULL);
143
  sock = hci_open_dev( dev_id );
144
  if (dev_id < 0 || sock < 0) {
145
    perror("opening socket");
146
    exit(1);
147
  }
148
 
149
  len  = 8;
150
 
151
  flags = IREQ_CACHE_FLUSH;
152
  ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info));
153
 
154
  bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags);
155
  if(  bt_device_count < 0 ) perror("hci_inquiry");
156
 
157
  for (i = 0; i <  bt_device_count; i++) {
158
    ba2str(&(ii+i)->bdaddr, addr);
159
    sprintf(addrs[i],"%s",addr);
160
 
161
    memset(name, 0, sizeof(name));
162
 
163
    if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
164
                             name, 0) < 0)
165
      sprintf(names[i],"[unknown]");
166
    else
167
      sprintf(names[i],"%s",name);
168
 
169
  }
170
 
171
 
172
  free( ii );
173
  close( sock );
174
}
175
 
117 ligi 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) */
41 ligi 179
 
117 ligi 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
 
190
 
191
}
192
 
50 ligi 193
int connect_joy()
43 ligi 194
{
117 ligi 195
 
196
  axis = (int *) calloc( 100, sizeof( int ) );
197
  button = (char *)calloc( 100, sizeof( char ) );
198
  button_trigger = (char *) calloc( 100, sizeof( char ) );
41 ligi 199
 
43 ligi 200
 
117 ligi 201
  //  axis = (int *) calloc( num_of_axis, sizeof( int ) );
202
  // button = (char *)calloc( num_of_buttons, sizeof( char ) );
203
  // button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
204
 
205
 
43 ligi 206
  if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 )
207
    {
208
      printf( "Couldn't open joystick device %s\n", JOY_DEV );
50 ligi 209
      printf( "try modprobe joydev\n"  );
210
      return 0;
43 ligi 211
    }
212
 
213
  ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis );
214
  ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons );
215
  ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick );
216
 
217
  printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
218
         , name_of_joystick
219
         , num_of_axis
220
         , num_of_buttons );
221
 
222
  fcntl( x52_input_fd, F_SETFL, O_NONBLOCK );   /* use non-blocking mode */
223
 
50 ligi 224
  return 1;
43 ligi 225
}
226
 
227
 
41 ligi 228
 
229
 
43 ligi 230
void AddCRC(unsigned int wieviele)
231
{
232
  unsigned int tmpCRC = 0,i;
233
  for(i = 0; i < wieviele;i++)
234
    {
235
      tmpCRC += TxBuffer[i];
236
    }
237
  tmpCRC %= 4096;
238
  TxBuffer[i++] = '=' + tmpCRC / 64;
239
  TxBuffer[i++] = '=' + tmpCRC % 64;
240
  TxBuffer[i++] = '\r';
241
}
41 ligi 242
 
48 ligi 243
 
244
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
43 ligi 245
{
50 ligi 246
  unsigned int pt = 0;
247
  unsigned char a,b,c;
248
  unsigned char ptr = 0;
43 ligi 249
 
50 ligi 250
  TxBuffer[pt++] = '#';               // Startzeichen
251
  TxBuffer[pt++] = modul;             // Adresse (a=0; b=1,...)
252
  TxBuffer[pt++] = cmd;                 // Commando
48 ligi 253
 
50 ligi 254
  while(len)
255
    {
256
      if(len) { a = snd[ptr++]; len--;} else a = 0;
257
      if(len) { b = snd[ptr++]; len--;} else b = 0;
258
      if(len) { c = snd[ptr++]; len--;} else c = 0;
259
      TxBuffer[pt++] = '=' + (a >> 2);
260
      TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
261
      TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
262
      TxBuffer[pt++] = '=' + ( c & 0x3f);
263
    }
43 ligi 264
 
48 ligi 265
 
266
 
267
  AddCRC(pt);
268
  printf("Sending to MK %d \n" , pt);
269
 
43 ligi 270
  status = send(s,"\r" , 1, 0);
48 ligi 271
 
272
 
273
  //  for (c=0;c<pt+2;c++)
274
  // {
50 ligi 275
  status = write(s,&TxBuffer , pt+3);
276
  //   printf("Send to MK %d \n" , TxBuffer[c] );
277
  // }
48 ligi 278
  /*while(TxBuffer[i] !='\r' && i<150)
43 ligi 279
    {
50 ligi 280
    //     TxBuffer[i]='#';
281
    status = send(s,&TxBuffer[i] , 1, 0);
282
    printf(" +%d%c ",i,TxBuffer[i]);
283
    i++;
43 ligi 284
    }
48 ligi 285
 
50 ligi 286
    status = send(s,"\r" , 1, 0);
48 ligi 287
  */
288
  // status = send(s,"\r" , 1, 0);
43 ligi 289
  printf("\n");
290
}
41 ligi 291
 
292
 
43 ligi 293
void write_display(int line,char* text)
294
{
295
  if (x52_output) x52_settext(x52_output, line , text, strlen(text));
296
}
297
 
298
void clear_display()
299
{
300
  write_display(0,"");
301
  write_display(1,"");
302
  write_display(2,"");
303
}
304
 
305
 
306
void output_device_list()
307
{
308
  int i;
309
  char disp_txt[20];
310
  for(i=0;i<bt_device_count;i++)
311
    {
312
      if (i<3)
313
        {
314
 
315
          if (selected_bt_device==i)
316
            sprintf(disp_txt,"#%s",names[i]);
317
          else
318
            sprintf(disp_txt," %s",names[i]);
319
          write_display(i,disp_txt);
320
        }
321
    }
322
}
323
 
50 ligi 324
int connect_mk(char dest[18])
43 ligi 325
{
117 ligi 326
 
43 ligi 327
  struct sockaddr_rc addr ;
117 ligi 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
  //);
43 ligi 338
 
117 ligi 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
 
350
  /*
351
  struct sockaddr_rc addr ;
352
 
43 ligi 353
  // allocate a socket
354
  s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
355
 
356
  // set the connection parameters (who to connect to)
357
  addr.rc_family = AF_BLUETOOTH;
358
  addr.rc_channel = 1;
359
  str2ba( dest, &addr.rc_bdaddr );
360
 
361
  // connect to server
362
  status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
363
 
50 ligi 364
  return status;
117 ligi 365
  */
43 ligi 366
}
367
 
368
 
369
 
370
 
50 ligi 371
int r=0;
372
int count=0;
373
int connected=0;
43 ligi 374
 
117 ligi 375
 
376
int input=INPUT_NONE;
377
 
43 ligi 378
int main(int argc, char**argv)
379
{
380
  printf("Starting Riddim \n");
381
  printf("\tRemote Interactive Digital Drone Interface Mashup\n");
50 ligi 382
 
383
  // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips )
384
  if (argv[1])
385
    {
386
      if (connect_mk(argv[1])==-1)
387
        {
388
          printf("cant connect to QC at adress: %s\n",argv[1]);
389
          return 0;
390
        }
391
        printf("connected to QC at adress: %s\n",argv[1]);
392
        connected=1;
393
    }
47 ligi 394
  int i;
117 ligi 395
 
396
 
397
 
47 ligi 398
 
117 ligi 399
 
400
 
43 ligi 401
  printf("\nInitializing X-52 input ..\n");
117 ligi 402
  if (connect_joy())
403
    {
404
    printf(".. done");//
405
    input=INPUT_JOYDEV;
406
    }
407
  else
408
    printf(".. ERROR ");//
43 ligi 409
 
117 ligi 410
  /*  printf("\nInitializing evdev input ..\n");
411
  if (connect_evdev())
412
    {
413
    printf(".. done");//
414
    input=INPUT_EVDEV;
415
    }
416
  else
417
    printf(".. ERROR ");//
418
  */
43 ligi 419
  printf("\nInitializing X-52 output ..");
420
 
47 ligi 421
  x52_output = x52_init();
422
 
423
  clear_display();
43 ligi 424
 
47 ligi 425
  write_display(0, "RIDDIM active");
43 ligi 426
 
47 ligi 427
  if (x52_output) x52_setbri(x52_output, 1,128);  
428
  if (x52_output)
429
    printf(" done \n");  
430
  else
431
    printf(" not found \n");      
43 ligi 432
 
50 ligi 433
  if (!connected)
43 ligi 434
    {
50 ligi 435
      printf("Scanning for Bluetooth Devices ..\n");
436
      write_display(1,"Bluetooth Scan");
437
      scan_bt();
438
      printf(" done \n");  
439
      printf(" %d Devices found \n",bt_device_count);  
43 ligi 440
    }
41 ligi 441
 
50 ligi 442
 
43 ligi 443
  int v_old;
117 ligi 444
  int polls=0;
445
  printf("starting loop ..\n");
446
 
447
 
448
 
41 ligi 449
  while( 1 )    
450
    {
117 ligi 451
 
452
      switch (input)
43 ligi 453
        {
117 ligi 454
 
455
        case INPUT_NONE:
456
          printf("input none\n");
457
          usleep(10000);
458
 
459
          break;
43 ligi 460
 
117 ligi 461
        case INPUT_EVDEV:
462
           printf("input evdev\n");
463
          usleep(30000);
464
 
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);
471
        }
472
 
473
        for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++)
50 ligi 474
            {
117 ligi 475
              // 1 -> nick
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)
483
                printf("Event: time %ld.%06ld, type %d, code %d, value %d\n",
484
                       ev[yalv].time.tv_sec, ev[yalv].time.tv_usec, ev[yalv].type,
485
                       ev[yalv].code, ev[yalv].value);
486
              */
50 ligi 487
            }
117 ligi 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]++;
518
              }
519
          break;
43 ligi 520
        }
521
 
117 ligi 522
      printf("input done\n");    
43 ligi 523
 
47 ligi 524
      switch(state)
525
        {
48 ligi 526
 
527
 
47 ligi 528
        case STATEID_SCANNING:
48 ligi 529
 
50 ligi 530
          state=STATEID_CONNECTING;
48 ligi 531
 
532
          ExternControl.Digital[0]=0;
533
          ExternControl.Digital[1]=0;
534
          ExternControl.RemoteTasten=0;
535
          ExternControl.Nick=(axis[1]>>8)*(-1)+127;;
536
 
537
          printf("nick%d\n",ExternControl.Nick);         
538
          ExternControl.Roll=(axis[0]>>8)*(-1)+127;;
539
          ExternControl.Gier=(axis[5]>>8)*(-1)+127;;
540
          ExternControl.Gas=(axis[2]>>8)*(-1)+127;
541
          ExternControl.Higt=0;
542
          ExternControl.free=0;
543
          ExternControl.Frame='t';
544
          ExternControl.Config=1;
545
 
546
          printf("sending data\n");
547
 
50 ligi 548
 
549
          SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
550
          gettimeofday(&time_struct1,NULL);
48 ligi 551
 
47 ligi 552
          if (button_trigger[BUTTON_SELECT]==1)
553
            {
554
              state=STATEID_CONNECTING;
555
              clear_display();
556
              write_display(0,"connecting to");
557
              write_display(1,names[selected_bt_device]);
558
              connect_mk(addrs[selected_bt_device]);
559
              write_display(0,"connected to");
560
            }
43 ligi 561
 
47 ligi 562
          if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1)
563
            {
564
              printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]);
565
              if (button_trigger[BUTTON_DOWN]==1)
566
                if (selected_bt_device>0) selected_bt_device--;
567
              if (button_trigger[BUTTON_UP]==1)
568
                if (selected_bt_device<bt_device_count-1) selected_bt_device++;
569
 
570
              output_device_list()                ;
571
            }
572
          break;
48 ligi 573
 
47 ligi 574
        case STATEID_CONNECTING:
50 ligi 575
 
48 ligi 576
          RxBuffer[1]=0;
50 ligi 577
 
578
 
579
          //      ftime(&time_struct);
117 ligi 580
          printf("waiting for confirm frame\n");
581
          RxBuffer[2]=0;
582
          int confirm_misses=0;
583
 
584
          while (RxBuffer[2]!='t')
50 ligi 585
            {
43 ligi 586
 
50 ligi 587
              r=0;
588
              in_char='#';
43 ligi 589
 
117 ligi 590
              while(in_char!='\n')
48 ligi 591
                {
50 ligi 592
                  count=read(s,&in_char,1);
593
                  if (in_char!=0)
594
                    {
595
                      RxBuffer[r++]=in_char;
596
                    }
597
                  else
598
                    {
599
                      RxBuffer[r++]='0';
600
                    }
117 ligi 601
                  //               printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char);
48 ligi 602
                }
50 ligi 603
              RxBuffer[r++]='\0';
604
              printf("--->%s\n",RxBuffer);
117 ligi 605
              // new
606
              if (button_trigger[12]>1)
607
                {
608
                  SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
609
                  button_trigger[12]=0;
610
                }
611
              if (++confirm_misses>4)
612
              SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
613
 
48 ligi 614
            }
50 ligi 615
          gettimeofday(&time_struct2,NULL);
43 ligi 616
 
50 ligi 617
          printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
618
          act_mode=button[24] | (button[25]<<1);
43 ligi 619
 
50 ligi 620
          switch (act_mode)
621
            {
622
            case 0:
117 ligi 623
 
624
 
50 ligi 625
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK);
626
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL);
627
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER);
117 ligi 628
              act_gas=((axis[AXIS_GAS]>>8)-128)*(-1);
629
 
630
              // clip gas      
631
              if (act_gas<0) act_gas=0;
50 ligi 632
 
117 ligi 633
              if (act_gas>250) act_gas=250;        
634
 
635
////////              act_gas=0;
50 ligi 636
              break;
637
 
638
            case 1:
639
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2;
640
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2;
641
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2;
642
              act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
643
 
644
              break;
645
 
646
            case 2:
647
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3;
648
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3;
649
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3;
650
              act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
651
 
652
 
653
              break;
654
 
655
            }
656
 
48 ligi 657
          ExternControl.Digital[0]=0;
658
          ExternControl.Digital[1]=0;
659
          ExternControl.RemoteTasten=0;
50 ligi 660
          ExternControl.Nick=act_nick;  //(axis[1]>>8)*(-1)/2;
661
          //      printf("nick%d\n",ExternControl.Nick);         
117 ligi 662
          ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2;
48 ligi 663
          ExternControl.Gier=(axis[5]>>8);
117 ligi 664
          ExternControl.Gier=act_gier; // ************
48 ligi 665
          ExternControl.Gas=(axis[2]>>8)*(-1)+127;
117 ligi 666
          ExternControl.Gas=act_gas; // ************
667
          //      ExternControl.Gas=0; // ************
48 ligi 668
          ExternControl.Higt=0;
669
          ExternControl.free=0;
670
          ExternControl.Frame='t';
50 ligi 671
 
48 ligi 672
          ExternControl.Config=1;
117 ligi 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);
48 ligi 674
 
675
 
676
 
677
          printf("sending data\n");
678
 
50 ligi 679
          SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
680
          gettimeofday(&time_struct1,NULL);
48 ligi 681
          printf("sent data\n");
682
 
683
 
50 ligi 684
          // printf("sleeping\n");
117 ligi 685
          //      for (polls=0;polls<100;polls++) // FIXME - better Polling
50 ligi 686
          // printf("end_sleep\n");
48 ligi 687
 
47 ligi 688
          int v=axis[6]/655+50;
689
          if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v );  
690
          v_old=v;
691
 
48 ligi 692
          printf("v: %d \n",v);
43 ligi 693
 
694
 
47 ligi 695
          for (i=0;i<num_of_axis;i++)
696
            printf("A%d: %d  ", i,axis[i]>>8 );
697
 
698
          for( x=0 ; x<num_of_buttons ; ++x )
699
 
700
            printf("B%d: %d  ", x, button[x] );            
43 ligi 701
 
47 ligi 702
          break;
703
        }
704
 
48 ligi 705
      printf("\n");
47 ligi 706
      fflush(stdout);
48 ligi 707
      printf("loop fin");
43 ligi 708
 
50 ligi 709
    }
41 ligi 710
 
43 ligi 711
 
47 ligi 712
  /******************** Cleanup **********************/
713
  close(x52_input_fd);
714
  close(s);
41 ligi 715
 
716
  if (x52_output) x52_close(x52_output);
717
  return 0;
718
}