Subversion Repositories Projects

Rev

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

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