Subversion Repositories Projects

Rev

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

Rev 125 Rev 127
Line -... Line 1...
-
 
1
/**************************************************
-
 
2
 *
-
 
3
 *
-
 
4
 * Riddim
1
#include <confuse.h>
5
 * Remote Interactive Digital Drone Interface Mashup
-
 
6
 *
2
#include <string.h>
7
 * 2007-2008 Marcus -LiGi- Bueschleb
-
 
8
 *
-
 
9
 *
-
 
10
**************************************************/
Line 3... Line -...
3
 
-
 
4
#include <stdio.h>
11
 
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>
-
 
Line 13... Line 12...
13
#include <bluetooth/hci_lib.h>
12
#include "riddim.h"
-
 
13
 
Line -... Line 14...
-
 
14
#define FALSE 0
Line 14... Line -...
14
 
-
 
15
#include <sys/time.h>
-
 
16
 
-
 
17
 
-
 
18
#include <bluetooth/rfcomm.h>
-
 
19
 
-
 
20
 
15
#define TRUE 1
21
#include <linux/joystick.h>
-
 
Line 22... Line -...
22
#define JOY_DEV "/dev/input/js0"
-
 
23
 
-
 
Line -... Line 16...
-
 
16
 
24
#define MAX_BT_DEVICES 3
17
#define test_bit(bit, array)    (array[bit/8] & (1<<(bit%8)))
25
 
18
 
26
 
19
int state=STATEID_SCANNING;
Line 27... Line -...
27
#define STATEID_SCANNING 0
-
 
28
#define STATEID_CONNECTING 1
-
 
29
 
-
 
30
#define BUTTON_SELECT 26
-
 
Line -... Line 20...
-
 
20
 
-
 
21
 
-
 
22
// from config 
-
 
23
char *input_evdev_name;
Line 31... Line -...
31
#define BUTTON_DOWN 28
-
 
32
#define BUTTON_UP 27
-
 
33
 
24
int  mk_socket_port=0;
34
 
25
int  loop_delay=0;
35
// #define AXIS_ROLL 0
26
 
36
// #define AXIS_NICK 1
27
 
37
// #define AXIS_GIER 5
-
 
38
// #define AXIS_GAS  2
-
 
39
 
-
 
40
 
-
 
41
 
-
 
42
// for x52
-
 
Line 43... Line -...
43
/*
-
 
44
#define AXIS_ROLL 4
-
 
45
#define AXIS_NICK 3
-
 
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
-
 
53
*/
-
 
54
 
-
 
55
#define AXIS_ROLL 0
-
 
56
#define AXIS_NICK 1
-
 
57
#define AXIS_GIER 3
-
 
58
#define AXIS_GAS  2
-
 
59
 
-
 
60
#define INVERT_ROLL 1
-
 
61
#define INVERT_NICK -1
-
 
62
#define INVERT_GIER 1
-
 
63
#define INVERT_GAS  -1
-
 
64
 
-
 
65
 
-
 
Line 66... Line -...
66
#include <stdio.h>
-
 
67
#include <errno.h>
-
 
68
#include <string.h>
28
 
Line 69... Line 29...
69
#include <sys/socket.h>
29
double nick_mul=0.3f;
70
#include <sys/types.h>
30
double roll_mul=0.3f;
71
#include <netinet/in.h>
31
double gier_mul=0.3f;
Line 72... Line -...
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
 
-
 
80
// from config 
-
 
81
 char *input_evdev_name;
-
 
82
 
-
 
83
// time struct for measuring
-
 
84
struct timeval time_struct1;
-
 
85
struct timeval time_struct2;
-
 
86
 
-
 
87
 
32
double gas_mul=0.3f;
Line -... Line 33...
-
 
33
 
-
 
34
 
-
 
35
int rel_axis_nick=1;
-
 
36
int rel_axis_roll=0;
-
 
37
int rel_axis_gier=5;
88
int act_nick=0;
38
int rel_axis_gas=2;
89
int act_roll=0;
39
 
Line 90... Line 40...
90
int act_gier=0;
40
 
Line 91... Line 41...
91
int act_gas=0;
41
cfg_bool_t exit_after_init = cfg_false;
92
int act_mode=0;
42
 
Line 93... Line 43...
93
 
43
// time struct for measuring
Line 94... Line 44...
94
int bt_device_count=0;
44
struct timeval time_struct1;
95
 
-
 
96
char names[MAX_BT_DEVICES][248];
-
 
97
char addrs[MAX_BT_DEVICES][19];
-
 
98
 
-
 
99
int s, status;
-
 
100
unsigned char TxBuffer[150];
-
 
101
unsigned char _TxBuffer[150];
-
 
102
 
-
 
103
char RxBuffer[150];
-
 
104
 
-
 
105
 
-
 
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];
-
 
Line 108... Line 45...
108
 
45
struct timeval time_struct2;
Line 109... Line 46...
109
struct js_event x52_event_struct;
46
 
-
 
47
 
-
 
48
char RxBuffer[150];
Line -... Line 49...
-
 
49
 
-
 
50
 
Line 110... Line 51...
110
 
51
int status;
Line 111... Line 52...
111
int engines_on=0;
52
 
112
int old_engines_on=0;
-
 
113
 
53
 
114
char in_char;
-
 
Line 115... Line 54...
115
 
54
 
-
 
55
 
116
struct ExternControl_s
56
int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
117
{
57
char *button=NULL,*button_trigger=NULL, name_of_joystick[80];
118
  unsigned char Digital[2];   // (noch unbenutzt)
58
 
-
 
59
struct js_event x52_event_struct;
-
 
60
 
Line 119... Line 61...
119
  unsigned char RemoteTasten; //(gab es schon für das virtuelle Display)
61
int engines_on=0;
-
 
62
int old_engines_on=0;
-
 
63
 
120
  signed char   Nick;
64
char in_char;
-
 
65
 
121
  signed char   Roll;
66
struct x52 *x52_output;
-
 
67
 
122
  signed char   Gier;
68
int selected_bt_device=0;
123
  unsigned char Gas;          //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum)
69
 
124
  signed char   Higt;        //(Höhenregler)
70
 int yalv;           /* loop counter */
Line 125... Line 71...
125
  unsigned char free;         // (unbenutzt)
71
    size_t read_bytes;  /* how many bytes were read */
Line 126... Line 72...
126
  unsigned char Frame;        // (Bestätigung)
72
    struct input_event ev[64]; /* the events (up to 64 at once) */
127
  unsigned char Config;
73
 
-
 
74
int evdev_fd;
Line 128... Line -...
128
};
-
 
129
 
-
 
Line 130... Line -...
130
 
-
 
131
struct ExternControl_s  ExternControl ;
-
 
132
 
75
int evdev_out_fd;
Line -... Line 76...
-
 
76
 
133
int state=STATEID_SCANNING;
77
int evdev_rw=TRUE;
-
 
78
 
Line 134... Line -...
134
 
-
 
135
 
-
 
136
struct x52 *x52_output;
-
 
137
 
-
 
138
int selected_bt_device=0;
79
int connect_evdev()
Line -... Line 80...
-
 
80
{
-
 
81
 
-
 
82
  struct input_devinfo {
-
 
83
    uint16_t bustype;
139
void scan_bt()
84
    uint16_t vendor;
Line 140... Line -...
140
{
-
 
141
  inquiry_info *ii = NULL;
85
    uint16_t product;
142
 
-
 
Line 143... Line -...
143
  int dev_id, sock, len, flags;
-
 
144
  int i;
86
    uint16_t version;
145
  char addr[19] = { 0 };
87
  };
Line 146... Line 88...
146
  char name[248] = { 0 };
88
  struct input_devinfo device_info;
-
 
89
 
-
 
90
  if ((evdev_out_fd = open(input_evdev_name, O_WRONLY)) < 0)
-
 
91
    {
-
 
92
      printf(" cant open evdev read/write - trying readonly\n");
147
 
93
      evdev_rw=FALSE;
148
  dev_id = hci_get_route(NULL);
94
    }
-
 
95
  if ((evdev_fd = open(input_evdev_name, O_RDONLY)) < 0)
149
  sock = hci_open_dev( dev_id );
96
    {
-
 
97
      printf(" cant open evdev !");
-
 
98
      return 0;
-
 
99
    }
-
 
100
 
-
 
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);
-
 
106
 
-
 
107
 
-
 
108
  char name[256]= "Unknown";
-
 
109
 
-
 
110
  if(ioctl(evdev_fd, EVIOCGNAME(sizeof(name)), name) < 0) {
150
  if (dev_id < 0 || sock < 0) {
111
    perror("evdev ioctl");
-
 
112
  }
-
 
113
 
-
 
114
  printf("EVDEV reports name: %s\n", name);
151
    perror("opening socket");
115
 
-
 
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
152
    exit(1);
118
   * operation with a byte that only has the relevant bit set.
Line 153... Line 119...
153
  }
119
   * eg. to check for the 12th bit, we do (array[1] & 1<<4)
154
 
-
 
155
  len  = 8;
-
 
156
 
120
   */
Line 157... Line 121...
157
  flags = IREQ_CACHE_FLUSH;
121
 
158
  ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info));
122
 
Line 231... Line 195...
231
}
195
}
Line 232... Line -...
232
 
-
 
233
 
-
 
234
 
-
 
235
 
-
 
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;
-
 
Line 244... Line -...
244
  TxBuffer[i++] = '=' + tmpCRC / 64;
-
 
245
  TxBuffer[i++] = '=' + tmpCRC % 64;
-
 
246
  TxBuffer[i++] = '\r';
-
 
247
}
-
 
248
 
-
 
249
 
-
 
250
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
-
 
251
{
-
 
252
  unsigned int pt = 0;
-
 
253
  unsigned char a,b,c;
-
 
254
  unsigned char ptr = 0;
-
 
255
 
-
 
256
  TxBuffer[pt++] = '#';               // Startzeichen
-
 
257
  TxBuffer[pt++] = modul;             // Adresse (a=0; b=1,...)
-
 
258
  TxBuffer[pt++] = cmd;                 // Commando
-
 
259
 
-
 
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
    }
-
 
270
 
-
 
271
 
-
 
272
 
-
 
273
  AddCRC(pt);
-
 
274
  printf("Sending to MK %d \n" , pt);
-
 
275
 
-
 
276
  status = send(s,"\r" , 1, 0);
-
 
277
 
-
 
278
 
-
 
279
  //  for (c=0;c<pt+2;c++)
-
 
280
  // {
-
 
281
  status = write(s,&TxBuffer , pt+3);
-
 
282
  //   printf("Send to MK %d \n" , TxBuffer[c] );
-
 
283
  // }
-
 
284
  /*while(TxBuffer[i] !='\r' && i<150)
-
 
285
    {
-
 
286
    //     TxBuffer[i]='#';
-
 
287
    status = send(s,&TxBuffer[i] , 1, 0);
-
 
288
    printf(" +%d%c ",i,TxBuffer[i]);
-
 
289
    i++;
-
 
290
    }
-
 
291
 
-
 
Line 292... Line 196...
292
    status = send(s,"\r" , 1, 0);
196
 
293
  */
197
 
294
  // status = send(s,"\r" , 1, 0);
198
 
295
  printf("\n");
199
 
Line 325... Line 229...
325
          write_display(i,disp_txt);
229
          write_display(i,disp_txt);
326
        }
230
        }
327
    }
231
    }
328
}
232
}
Line 329... Line -...
329
 
-
 
330
int connect_mk(char dest[18])
-
 
331
{
-
 
332
 
-
 
333
  struct sockaddr_rc addr ;
-
 
334
  struct sockaddr_in sa;
-
 
335
 
-
 
336
 sa.sin_family = AF_INET;
-
 
337
  sa.sin_addr.s_addr = htonl(0x0);
-
 
Line 338... Line -...
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
  //);
-
 
344
 
-
 
345
  // set the connection parameters (who to connect to)
233
 
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));
234
 
352
  status = connect(s,(struct sockaddr*) &sa, sizeof(struct sockaddr_in));
-
 
353
 
-
 
354
  return status;
235
void print_device_list()
355
 
236
{
356
  /*
-
 
357
  struct sockaddr_rc addr ;
-
 
358
 
-
 
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;
237
  int i;
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
 
-
 
370
  return status;
238
  for(i=0;i<bt_device_count;i++)
Line 371... Line -...
371
  */
-
 
372
}
-
 
373
 
239
    printf("device%i->%s\n",i,names[i]);
374
 
240
}
375
 
241
 
Line 385... Line 251...
385
int main(int argc, char**argv)
251
int main(int argc, char**argv)
386
{
252
{
Line 387... Line 253...
387
 
253
 
388
  printf("Starting Riddim \n");
254
  printf("Starting Riddim \n");
389
  printf("\tRemote Interactive Digital Drone Interface Mashup\n");
-
 
-
 
255
  printf("\tRemote Interactive Digital Drone Interface Mashup\n");
-
 
256
  printf("\nusage:\n");
Line 390... Line 257...
390
 
257
  printf("\t riddim [config_file]\n\n");
-
 
258
 
-
 
259
 
391
 
260
  cfg_opt_t opts[] = {
-
 
261
 
-
 
262
    CFG_SIMPLE_BOOL("exit_after_init", &exit_after_init),
-
 
263
    CFG_SIMPLE_STR("input_evdev", &input_evdev_name),
-
 
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),
392
 
274
    CFG_SIMPLE_INT("rel_axis_gier", &rel_axis_gier),
393
  cfg_opt_t opts[] = {
275
    CFG_SIMPLE_INT("rel_axis_gas", &rel_axis_gas),
Line 394... Line 276...
394
    CFG_SIMPLE_STR("input_evdev", &input_evdev_name),
276
 
Line 395... Line 277...
395
    CFG_END()
277
    CFG_END()
396
  };
278
  };
Line 397... Line 279...
397
 
279
 
398
  cfg_t *cfg;
-
 
399
 
-
 
Line 400... Line -...
400
  //  input_evdev_name=strdup("/dev/event0");
-
 
401
  printf("Parsing config file");
280
  cfg_t *cfg;
402
 
281
 
403
  cfg = cfg_init(opts, 0);
282
  //  input_evdev_name=strdup("/dev/event0");
404
  cfg_parse(cfg, "/etc/riddim.conf");
-
 
405
  printf("input %s:",input_evdev_name);  
283
  printf("Parsing config file ");
406
 
-
 
407
  // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips )
284
 
-
 
285
  cfg = cfg_init(opts, 0);
-
 
286
 
408
  if (argv[1])
287
  if (argv[1])
409
    {
288
    {
410
      if (connect_mk(argv[1])==-1)
289
      printf("%s\n ",argv[1]);
411
        {
290
      cfg_parse(cfg, argv[1]);
412
          printf("cant connect to QC at adress: %s\n",argv[1]);
-
 
Line -... Line 291...
-
 
291
    }
Line -... Line 292...
-
 
292
  else
-
 
293
    {
-
 
294
      printf("/etc/riddim.conf\n");
Line -... Line 295...
-
 
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
    {
Line -... Line 303...
-
 
303
        printf("connecting to local port: %i\n",mk_socket_port);
Line 413... Line 304...
413
          return 0;
304
       
414
        }
305
      if (connect_mk_localhost_socket(mk_socket_port)==-1)
415
        printf("connected to QC at adress: %s\n",argv[1]);
306
        printf("cant connect !!");
416
        connected=1;
307
      else
Line 452... Line 343...
452
  if (x52_output)
343
  if (x52_output)
453
    printf(" done \n");  
344
    printf(" done \n");  
454
  else
345
  else
455
    printf(" not found \n");      
346
    printf(" not found \n");      
Line -... Line 347...
-
 
347
 
456
 
348
  /*
457
  if (!connected)
349
  if (!connected)
458
    {
350
    {
459
      printf("Scanning for Bluetooth Devices ..\n");
351
      printf("Scanning for Bluetooth Devices ..\n");
460
      write_display(1,"Bluetooth Scan");
352
      write_display(1,"Bluetooth Scan");
461
      scan_bt();
353
      scan_bt();
462
      printf(" done \n");  
354
      printf(" done \n");  
-
 
355
      printf(" %d Devices found \n",bt_device_count);  
463
      printf(" %d Devices found \n",bt_device_count);  
356
      print_device_list() ;
464
    }
357
    }
Line 465... Line 358...
465
 
358
  */
466
 
359
 
-
 
360
  int v_old;
-
 
361
  int polls=0;
-
 
362
 
-
 
363
  int retval;
467
  int v_old;
364
  if (exit_after_init)
Line -... Line 365...
-
 
365
    exit(0);
-
 
366
  printf("starting loop ..\n");
Line -... Line 367...
-
 
367
 
-
 
368
  struct input_event led_event;
-
 
369
  led_event.type=EV_LED;
-
 
370
 
-
 
371
  int complete_misses=0;
-
 
372
  if (evdev_out_fd)
-
 
373
    {
Line -... Line 374...
-
 
374
      led_event.code = LED_MISC;
468
  int polls=0;
375
      led_event.value = 1;
469
  printf("starting loop ..\n");
376
      retval = write(evdev_out_fd, &led_event, sizeof(struct input_event));
Line -... Line 377...
-
 
377
    }
-
 
378
 
-
 
379
  int confirm_misses;
-
 
380
  while( 1 )    
-
 
381
    {
-
 
382
 
-
 
383
      if (evdev_out_fd)
-
 
384
        {
-
 
385
          if (led_event.value)
-
 
386
            led_event.value = 0;
470
 
387
          else
471
 
388
            led_event.value = 1 ;
Line 472... Line -...
472
 
-
 
473
  while( 1 )    
-
 
474
    {
-
 
Line -... Line 389...
-
 
389
          retval = write(evdev_out_fd, &led_event, sizeof(struct input_event));
-
 
390
        }
475
 
391
 
Line 476... Line 392...
476
      switch (input)
392
      usleep(loop_delay);
477
        {
393
      switch (input)
478
         
-
 
479
        case INPUT_NONE:
-
 
Line -... Line 394...
-
 
394
        {
-
 
395
 
-
 
396
         
-
 
397
        case INPUT_NONE:
-
 
398
          printf("starting input none\n");
-
 
399
          break;
-
 
400
 
-
 
401
        case INPUT_EVDEV:
-
 
402
           printf("input evdev\n");
-
 
403
 
-
 
404
           struct timeval tv;
-
 
405
           int retval;
-
 
406
           fd_set rfds;
-
 
407
           FD_ZERO(&rfds);
-
 
408
           FD_SET(evdev_fd,&rfds);
480
          printf("input none\n");
409
 
481
          usleep(10000);
-
 
-
 
410
           tv.tv_sec = 0;
482
         
411
           tv.tv_usec = 5;
483
          break;
412
 
484
 
413
           retval = select(evdev_fd+1, &rfds, NULL, NULL, &tv);
485
        case INPUT_EVDEV:
414
 
Line 486... Line 415...
486
           printf("input evdev\n");
415
           if (retval==-1)
487
          usleep(30000);
416
             printf("error in select!!!!!!!!\n");
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");
417
           else if (retval)
494
            exit (1);
418
             {
495
        }
-
 
496
 
-
 
497
        for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++)
419
             read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64);
498
            {
420
 
499
              // 1 -> nick
-
 
500
              // 2 -> gas
421
             if (read_bytes < (int) sizeof(struct input_event)) {
Line -... Line 422...
-
 
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
               }
501
              // 4->roll
433
 
-
 
434
 
502
              // 5-> gier
435
             for (yalv=0;yalv<10;yalv++)
503
              axis[ ev[yalv].code]= ev[yalv].value;
436
               printf("A%d %d -" , yalv, axis[yalv] );
504
             
437
             printf("\n");
Line 505... Line 438...
505
              printf("nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]);
438
 
Line 568... Line 501...
568
          ExternControl.Config=1;
501
          ExternControl.Config=1;
Line 569... Line 502...
569
 
502
 
Line 570... Line 503...
570
          printf("sending data\n");
503
          printf("sending data\n");
571
 
504
 
Line 572... Line 505...
572
         
505
         
573
          SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
506
          if (connected)SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
574
          gettimeofday(&time_struct1,NULL);
507
          gettimeofday(&time_struct1,NULL);
575
 
508
 
576
          if (button_trigger[BUTTON_SELECT]==1)
509
          if (button_trigger[BUTTON_SELECT]==1)
577
            {
510
            {
578
              state=STATEID_CONNECTING;
511
              state=STATEID_CONNECTING;
579
              clear_display();
512
              clear_display();
580
              write_display(0,"connecting to");
513
              write_display(0,"connecting to");
Line 581... Line 514...
581
              write_display(1,names[selected_bt_device]);
514
              write_display(1,names[selected_bt_device]);
582
              connect_mk(addrs[selected_bt_device]);
515
              //connect_mk(addrs[selected_bt_device]);
Line 589... Line 522...
589
              if (button_trigger[BUTTON_DOWN]==1)
522
              if (button_trigger[BUTTON_DOWN]==1)
590
                if (selected_bt_device>0) selected_bt_device--;
523
                if (selected_bt_device>0) selected_bt_device--;
591
              if (button_trigger[BUTTON_UP]==1)
524
              if (button_trigger[BUTTON_UP]==1)
592
                if (selected_bt_device<bt_device_count-1) selected_bt_device++;
525
                if (selected_bt_device<bt_device_count-1) selected_bt_device++;
Line 593... Line -...
593
             
-
 
-
 
526
             
594
              output_device_list()                ;
527
 
595
            }
528
            }
Line 596... Line 529...
596
          break;
529
          break;
Line -... Line 530...
-
 
530
       
-
 
531
        case STATEID_CONNECTING:
-
 
532
         
-
 
533
 
-
 
534
          confirm_misses=0;
-
 
535
          printf("connected:%d",connected);
597
       
536
          if (connected) while (RxBuffer[1]!='t')
Line 598... Line 537...
598
        case STATEID_CONNECTING:
537
            {
599
 
538
 
600
          RxBuffer[1]=0;
539
              RxBuffer[1]=0;
601
 
-
 
Line 602... Line -...
602
 
-
 
603
          //      ftime(&time_struct);
540
 
Line 604... Line 541...
604
          printf("waiting for confirm frame\n");
541
 
605
          RxBuffer[2]=0;
542
              //          ftime(&time_struct);
Line 606... Line 543...
606
          int confirm_misses=0;
543
              printf("waiting for confirm frame ( misses:%d )\n",confirm_misses);
607
 
544
              RxBuffer[2]=0;
608
          while (RxBuffer[2]!='t')
545
 
609
            {
546
 
610
 
547
 
611
              r=0;
548
              r=0;
612
              in_char='#';
549
              in_char='#';
613
 
550
 
Line 623... Line 560...
623
                      RxBuffer[r++]='0';
560
                      RxBuffer[r++]='0';
624
                    }
561
                    }
625
                  //               printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char);
562
                  //               printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char);
626
                }
563
                }
627
              RxBuffer[r++]='\0';
564
              RxBuffer[r++]='\0';
628
              printf("--->%s\n",RxBuffer);
565
              printf("%d--->%s\n",complete_misses,RxBuffer);
629
              // new
566
              // new
630
              if (button_trigger[12]>1)
567
              if (button_trigger[12]>1)
631
                {
568
                {
632
                  SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
569
                  SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
633
                  button_trigger[12]=0;
570
                  button_trigger[12]=0;
634
                }
571
                }
635
              if (++confirm_misses>4)
572
              if (++confirm_misses>4)
-
 
573
                {
-
 
574
                  complete_misses++;
-
 
575
                  printf("sending again\n");
636
              SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
576
                  SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
637
               
-
 
638
            }
577
                }
-
 
578
            }
-
 
579
          else
-
 
580
            printf("not connected to mk\n");
639
          gettimeofday(&time_struct2,NULL);
581
          gettimeofday(&time_struct2,NULL);
Line 640... Line 582...
640
 
582
 
641
          printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
583
          printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
Line -... Line 584...
-
 
584
          act_mode=button[24] | (button[25]<<1);
-
 
585
 
-
 
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
 
642
          act_mode=button[24] | (button[25]<<1);
596
 
643
 
597
          /*
644
          switch (act_mode)
598
          switch (act_mode)
Line 645... Line 599...
645
            {
599
            {
646
            case 0:
600
            case 0:
647
 
601
 
648
 
602
 
Line 649... Line 603...
649
              act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK);
603
              act_nick=(axis[AXIS_NICK])*(INVERT_NICK);
650
              act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL);
604
              act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL);
Line 651... Line 605...
651
              act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER);
605
              act_gier=(axis[AXIS_GIER])*(INVERT_GIER);
Line 675... Line 629...
675
 
629
 
Line 676... Line 630...
676
 
630
 
677
              break;
631
              break;
678
 
632
 
679
            }
633
            }
680
             
634
          */  
681
          ExternControl.Digital[0]=0;
635
          ExternControl.Digital[0]=0;
682
          ExternControl.Digital[1]=0;
636
          ExternControl.Digital[1]=0;
Line 696... Line 650...
696
          ExternControl.Config=1;
650
          ExternControl.Config=1;
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);
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);
Line -... Line 652...
-
 
652
 
-
 
653
 
698
 
654
 
Line 699... Line 655...
699
 
655
          if (connected)
700
 
656
            {
701
          printf("sending data\n");
657
              printf("sending data\n");
702
 
658
             
Line 703... Line 659...
703
          SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
659
              SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
704
          gettimeofday(&time_struct1,NULL);
660
              gettimeofday(&time_struct1,NULL);
705
          printf("sent data\n");
661
              printf("sent data\n");
Line 726... Line 682...
726
          break;
682
          break;
727
        }
683
        }
Line 728... Line 684...
728
                 
684
     
729
      printf("\n");
685
      printf("\n");
730
      fflush(stdout);
686
      fflush(stdout);
Line 731... Line 687...
731
      printf("loop fin");
687
      printf("loop fin ( misses:%d)\n",complete_misses);
Line 732... Line 688...
732
               
688
               
733
    }
689
    }
734
 
690
 
Line 735... Line 691...
735
 
691
 
736
  /******************** Cleanup **********************/
692
  /******************** Cleanup **********************/
737
  close(x52_input_fd);
693
  close(x52_input_fd);