Subversion Repositories Projects

Rev

Rev 48 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 48 Rev 50
Line 7... Line 7...
7
#include <sys/socket.h>
7
#include <sys/socket.h>
8
#include <bluetooth/bluetooth.h>
8
#include <bluetooth/bluetooth.h>
9
#include <bluetooth/hci.h>
9
#include <bluetooth/hci.h>
10
#include <bluetooth/hci_lib.h>
10
#include <bluetooth/hci_lib.h>
Line -... Line 11...
-
 
11
 
-
 
12
#include <sys/time.h>
Line 11... Line 13...
11
 
13
 
Line 12... Line 14...
12
 
14
 
Line 24... Line 26...
24
 
26
 
25
#define BUTTON_SELECT 26
27
#define BUTTON_SELECT 26
26
#define BUTTON_DOWN 28
28
#define BUTTON_DOWN 28
Line -... Line 29...
-
 
29
#define BUTTON_UP 27
-
 
30
 
-
 
31
 
-
 
32
#define AXIS_ROLL 0
-
 
33
#define AXIS_NICK 1
-
 
34
#define AXIS_GIER 5
-
 
35
#define AXIS_GAS  2
-
 
36
 
-
 
37
#define INVERT_ROLL -1
-
 
38
#define INVERT_NICK -1
-
 
39
#define INVERT_GIER 1
-
 
40
#define INVERT_GAS  -1
-
 
41
 
-
 
42
 
-
 
43
// time struct for measuring
-
 
44
struct timeval time_struct1;
-
 
45
struct timeval time_struct2;
-
 
46
 
-
 
47
 
-
 
48
int act_nick=0;
-
 
49
int act_roll=0;
-
 
50
int act_gier=0;
-
 
51
int act_gas=0;
27
#define BUTTON_UP 27
52
int act_mode=0;
Line 28... Line 53...
28
 
53
 
29
int bt_device_count=0;
54
int bt_device_count=0;
Line 41... Line 66...
41
int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
66
int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
42
char *button=NULL,*button_trigger=NULL, name_of_joystick[80];
67
char *button=NULL,*button_trigger=NULL, name_of_joystick[80];
Line 43... Line 68...
43
 
68
 
Line 44... Line -...
44
struct js_event x52_event_struct;
-
 
45
 
69
struct js_event x52_event_struct;
46
 
70
 
Line 47... Line 71...
47
int engines_on=0;
71
int engines_on=0;
Line 48... Line -...
48
int old_engines_on=0;
-
 
49
 
-
 
50
char in_char;
-
 
51
 
72
int old_engines_on=0;
52
struct
-
 
53
{
-
 
54
  char val[4];
73
 
55
} MotortestParam;
74
char in_char;
56
 
75
 
57
struct
76
struct ExternControl_s
58
{
77
{
Line 64... Line 83...
64
  unsigned char Gas;          //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum)
83
  unsigned char Gas;          //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum)
65
  signed char   Higt;        //(Höhenregler)
84
  signed char   Higt;        //(Höhenregler)
66
  unsigned char free;         // (unbenutzt)
85
  unsigned char free;         // (unbenutzt)
67
  unsigned char Frame;        // (Bestätigung)
86
  unsigned char Frame;        // (Bestätigung)
68
  unsigned char Config;
87
  unsigned char Config;
69
} ExternControl;
88
};
Line -... Line 89...
-
 
89
 
Line 70... Line 90...
70
 
90
 
Line 71... Line 91...
71
 
91
struct ExternControl_s  ExternControl ;
Line 118... Line 138...
118
  free( ii );
138
  free( ii );
119
  close( sock );
139
  close( sock );
120
}
140
}
Line 121... Line 141...
121
 
141
 
122
 
142
 
Line 123... Line 143...
123
void connect_joy()
143
int connect_joy()
124
{
144
{
125
 
145
 
-
 
146
 
126
 
147
  if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 )
127
  if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 )
148
    {
Line 128... Line 149...
128
    {
149
      printf( "Couldn't open joystick device %s\n", JOY_DEV );
129
      printf( "Couldn't open joystick device %s\n", JOY_DEV );
150
      printf( "try modprobe joydev\n"  );
130
      return ;
151
      return 0;
Line 143... Line 164...
143
         , num_of_axis
164
         , num_of_axis
144
         , num_of_buttons );
165
         , num_of_buttons );
Line 145... Line 166...
145
 
166
 
Line -... Line 167...
-
 
167
  fcntl( x52_input_fd, F_SETFL, O_NONBLOCK );   /* use non-blocking mode */
146
  fcntl( x52_input_fd, F_SETFL, O_NONBLOCK );   /* use non-blocking mode */
168
 
Line 242... Line 264...
242
          write_display(i,disp_txt);
264
          write_display(i,disp_txt);
243
        }
265
        }
244
    }
266
    }
245
}
267
}
Line 246... Line 268...
246
 
268
 
247
void connect_mk(char dest[18])
269
int connect_mk(char dest[18])
248
{
270
{
Line 249... Line 271...
249
  struct sockaddr_rc addr ;
271
  struct sockaddr_rc addr ;
250
 
272
 
Line 257... Line 279...
257
  str2ba( dest, &addr.rc_bdaddr );
279
  str2ba( dest, &addr.rc_bdaddr );
Line 258... Line 280...
258
 
280
 
259
  // connect to server
281
  // connect to server
Line -... Line 282...
-
 
282
  status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
-
 
283
 
260
  status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
284
  return status;
Line 261... Line 285...
261
 
285
 
262
}
286
}
-
 
287
 
Line 263... Line 288...
263
 
288
 
264
 
289
 
265
 
290
 
266
 
291
int r=0;
Line -... Line 292...
-
 
292
int count=0;
267
          int r=0;
293
int connected=0;
-
 
294
 
268
          int count=0;
295
int main(int argc, char**argv)
269
 
296
{
-
 
297
  printf("Starting Riddim \n");
270
int main(int argc, char**argv)
298
  printf("\tRemote Interactive Digital Drone Interface Mashup\n");
271
{
299
 
-
 
300
  // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips )
-
 
301
  if (argv[1])
272
  printf("Starting Riddim \n");
302
    {
273
  printf("\tRemote Interactive Digital Drone Interface Mashup\n");
303
      if (connect_mk(argv[1])==-1)
Line 274... Line 304...
274
 
304
        {
275
  //int tmp=2;
305
          printf("cant connect to QC at adress: %s\n",argv[1]);
276
  connect_mk("00:0B:CE:01:6B:4F");
306
          return 0;
-
 
307
        }
Line 277... Line 308...
277
                 
308
        printf("connected to QC at adress: %s\n",argv[1]);
Line 278... Line 309...
278
 
309
        connected=1;
Line 296... Line 327...
296
  if (x52_output)
327
  if (x52_output)
297
    printf(" done \n");  
328
    printf(" done \n");  
298
  else
329
  else
299
    printf(" not found \n");      
330
    printf(" not found \n");      
Line -... Line 331...
-
 
331
 
-
 
332
  if (!connected)
300
 
333
    {
301
  printf("Scanning for Bluetooth Devices ..\n");
334
      printf("Scanning for Bluetooth Devices ..\n");
302
  write_display(1,"Bluetooth Scan");
-
 
303
 
335
      write_display(1,"Bluetooth Scan");
304
  //  scan_bt();
336
      scan_bt();
305
  printf(" done \n");  
337
      printf(" done \n");  
306
  printf(" %d Devices found \n",bt_device_count);  
-
 
307
 
-
 
308
 
-
 
309
  /*  for(i=0;i<bt_device_count;i++)
-
 
310
    {
-
 
311
      printf(" %d -> %s (%s) \n",i,names[i],addrs[i]);  
-
 
312
      if (i<3) write_display(i,names[i]);
338
      printf(" %d Devices found \n",bt_device_count);  
Line 313... Line -...
313
    }
-
 
314
 
-
 
Line 315... Line 339...
315
  output_device_list() ;
339
    }
316
  */
340
 
317
 
341
 
-
 
342
  int v_old;
318
  int v_old;
343
  while( 1 )    
319
  while( 1 )    
344
    {
320
    {
345
      // poll values from input device
321
      int polls=0;
346
      int polls=0;
Line 322... Line 347...
322
      for (polls=0;polls<1000;polls++) // FIXME - better Polling
347
      for (polls=0;polls<100;polls++) // FIXME - better Polling
Line 350... Line 375...
350
        {
375
        {
Line 351... Line 376...
351
 
376
 
Line 352... Line 377...
352
 
377
 
Line 353... Line 378...
353
        case STATEID_SCANNING:
378
        case STATEID_SCANNING:
354
 
379
 
355
          state=STATEID_CONNECTING; //e
380
          state=STATEID_CONNECTING;
356
 
381
 
Line 366... Line 391...
366
          ExternControl.Higt=0;
391
          ExternControl.Higt=0;
367
          ExternControl.free=0;
392
          ExternControl.free=0;
368
          ExternControl.Frame='t';
393
          ExternControl.Frame='t';
369
          ExternControl.Config=1;
394
          ExternControl.Config=1;
Line 370... Line -...
370
 
-
 
371
 
-
 
372
 
395
 
Line 373... Line -...
373
          printf("sending data\n");
-
 
Line -... Line 396...
-
 
396
          printf("sending data\n");
-
 
397
 
Line 374... Line 398...
374
 
398
         
375
          SendOutData('b', 0, &ExternControl, sizeof(ExternControl));
399
          SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
376
 
400
          gettimeofday(&time_struct1,NULL);
377
 
401
 
Line 396... Line 420...
396
              output_device_list()                ;
420
              output_device_list()                ;
397
            }
421
            }
398
          break;
422
          break;
Line 399... Line 423...
399
       
423
       
400
        case STATEID_CONNECTING:
-
 
-
 
424
        case STATEID_CONNECTING:
401
          //      for (polls=0;polls<10;polls++) // FIXME - better Polling
425
 
-
 
426
          RxBuffer[1]=0;
-
 
427
 
-
 
428
 
-
 
429
          //      ftime(&time_struct);
402
          RxBuffer[1]=0;
430
          //printf("t:%d",time_struct.millitm);
403
          while (RxBuffer[1]!='t')
431
          while (RxBuffer[1]!='t')
Line 404... Line 432...
404
          {
432
            {
405
 
433
 
Line 421... Line 449...
421
            }
449
                }
422
          RxBuffer[r++]='\0';
450
              RxBuffer[r++]='\0';
423
          printf("--->%s\n",RxBuffer);
451
              printf("--->%s\n",RxBuffer);
Line 424... Line 452...
424
 
452
 
-
 
453
            }
-
 
454
          gettimeofday(&time_struct2,NULL);
-
 
455
 
-
 
456
          printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
-
 
457
          act_mode=button[24] | (button[25]<<1);
-
 
458
 
-
 
459
          switch (act_mode)
-
 
460
            {
-
 
461
            case 0:
-
 
462
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK);
-
 
463
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL);
-
 
464
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER);
-
 
465
              act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
-
 
466
 
-
 
467
              break;
-
 
468
 
-
 
469
            case 1:
-
 
470
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2;
-
 
471
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2;
-
 
472
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2;
-
 
473
              act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
-
 
474
 
-
 
475
              break;
-
 
476
             
-
 
477
            case 2:
-
 
478
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3;
-
 
479
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3;
-
 
480
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3;
-
 
481
              act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
-
 
482
 
-
 
483
 
-
 
484
              break;
-
 
485
 
Line 425... Line 486...
425
          }
486
            }
426
 
487
             
427
          ExternControl.Digital[0]=0;
488
          ExternControl.Digital[0]=0;
428
          ExternControl.Digital[1]=0;
489
          ExternControl.Digital[1]=0;
429
          ExternControl.RemoteTasten=0;
490
          ExternControl.RemoteTasten=0;
430
          ExternControl.Nick=(axis[1]>>8)*(-1);
491
          ExternControl.Nick=act_nick;  //(axis[1]>>8)*(-1)/2;
431
          printf("nick%d\n",ExternControl.Nick);         
492
          //      printf("nick%d\n",ExternControl.Nick);         
432
 ExternControl.Roll=(axis[0]>>8)*(-1);
493
          ExternControl.Roll=act_roll; //(axis[0]>>8)*(-1)/2;
433
          ExternControl.Gier=(axis[5]>>8);
494
          ExternControl.Gier=(axis[5]>>8);
434
          ExternControl.Gas=(axis[2]>>8)*(-1)+127;
495
          ExternControl.Gas=(axis[2]>>8)*(-1)+127;
435
          ExternControl.Higt=0;
496
          ExternControl.Higt=0;
-
 
497
          ExternControl.free=0;
436
          ExternControl.free=0;
498
          ExternControl.Frame='t';
-
 
499
         
Line 437... Line 500...
437
          ExternControl.Frame='t';
500
          ExternControl.Config=1;
Line 438... Line 501...
438
          ExternControl.Config=1;
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);
439
 
-
 
-
 
502
 
440
 
503
 
Line 441... Line 504...
441
 
504
 
442
          printf("sending data\n");
505
          printf("sending data\n");
443
 
-
 
444
           SendOutData('b', 0, &ExternControl, sizeof(ExternControl));
506
 
Line 445... Line 507...
445
 
507
          SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
446
          printf("sent data\n");
508
          gettimeofday(&time_struct1,NULL);
447
 
509
          printf("sent data\n");