Subversion Repositories Projects

Rev

Rev 43 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 43 Rev 47
1
#include <stdio.h>
1
#include <stdio.h>
2
#include <stdlib.h>
2
#include <stdlib.h>
3
#include <string.h>
3
#include <string.h>
4
#include <fcntl.h>
4
#include <fcntl.h>
5
#include "lib/x52/x52.h"
5
#include "lib/x52/x52.h"
6
#include <unistd.h>
6
#include <unistd.h>
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>
11
 
11
 
12
 
12
 
13
#include <bluetooth/rfcomm.h>
13
#include <bluetooth/rfcomm.h>
14
 
14
 
15
 
15
 
16
#include <linux/joystick.h>
16
#include <linux/joystick.h>
17
#define JOY_DEV "/dev/input/js0"
17
#define JOY_DEV "/dev/input/js0"
18
 
18
 
19
#define MAX_BT_DEVICES 3
19
#define MAX_BT_DEVICES 3
-
 
20
 
-
 
21
 
-
 
22
#define STATEID_SCANNING 0
-
 
23
#define STATEID_CONNECTING 1
-
 
24
 
-
 
25
#define BUTTON_SELECT 26
-
 
26
#define BUTTON_DOWN 28
-
 
27
#define BUTTON_UP 27
20
 
28
 
21
int bt_device_count=0;
29
int bt_device_count=0;
22
 
30
 
23
char names[MAX_BT_DEVICES][248];
31
char names[MAX_BT_DEVICES][248];
24
char addrs[MAX_BT_DEVICES][19];
32
char addrs[MAX_BT_DEVICES][19];
25
 
33
 
26
int s, status;
34
int s, status;
27
unsigned char TxBuffer[150];
35
unsigned char TxBuffer[150];
28
unsigned char _TxBuffer[150];
36
unsigned char _TxBuffer[150];
-
 
37
 
-
 
38
int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
-
 
39
char *button=NULL,*button_trigger=NULL, name_of_joystick[80];
-
 
40
 
-
 
41
struct js_event x52_event_struct;
-
 
42
 
-
 
43
struct
-
 
44
{
-
 
45
  char val[4];
-
 
46
} MotortestParam;
-
 
47
 
-
 
48
struct
-
 
49
{
-
 
50
  unsigned char Digital[2];   // (noch unbenutzt)
29
 
51
  unsigned char RemoteTasten; //(gab es schon für das virtuelle Display)
-
 
52
  signed char   Nick;
-
 
53
  signed char   Roll;
-
 
54
  signed char   Gier;
-
 
55
  unsigned char Gas;          //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum)
-
 
56
  signed char   Hight;        //(Höhenregler)
-
 
57
  unsigned char free;         // (unbenutzt)
30
#define STATEID_SCANNING 0
58
  unsigned char Frame;        // (Bestätigung)
-
 
59
  unsigned char Config;
-
 
60
} ExternControl;
-
 
61
 
-
 
62
 
31
#define STATEID_CONNECTING 1
63
 
32
int state=STATEID_SCANNING;
-
 
33
 
-
 
34
#define BUTTON_SELECT 26
-
 
35
#define BUTTON_DOWN 27
64
int state=STATEID_SCANNING;
36
#define BUTTON_UP 28
65
 
37
 
66
 
38
struct x52 *x52_output;
67
struct x52 *x52_output;
39
 
68
 
40
int selected_bt_device=0;
69
int selected_bt_device=0;
41
void scan_bt()
70
void scan_bt()
42
{
71
{
43
  inquiry_info *ii = NULL;
72
  inquiry_info *ii = NULL;
44
 
73
 
45
  int dev_id, sock, len, flags;
74
  int dev_id, sock, len, flags;
46
  int i;
75
  int i;
47
  char addr[19] = { 0 };
76
  char addr[19] = { 0 };
48
  char name[248] = { 0 };
77
  char name[248] = { 0 };
49
 
78
 
50
  dev_id = hci_get_route(NULL);
79
  dev_id = hci_get_route(NULL);
51
  sock = hci_open_dev( dev_id );
80
  sock = hci_open_dev( dev_id );
52
  if (dev_id < 0 || sock < 0) {
81
  if (dev_id < 0 || sock < 0) {
53
    perror("opening socket");
82
    perror("opening socket");
54
    exit(1);
83
    exit(1);
55
  }
84
  }
56
 
85
 
57
  len  = 8;
86
  len  = 8;
58
 
87
 
59
  flags = IREQ_CACHE_FLUSH;
88
  flags = IREQ_CACHE_FLUSH;
60
  ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info));
89
  ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info));
61
 
90
 
62
  bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags);
91
  bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags);
63
  if(  bt_device_count < 0 ) perror("hci_inquiry");
92
  if(  bt_device_count < 0 ) perror("hci_inquiry");
64
 
93
 
65
  for (i = 0; i <  bt_device_count; i++) {
94
  for (i = 0; i <  bt_device_count; i++) {
66
    ba2str(&(ii+i)->bdaddr, addr);
95
    ba2str(&(ii+i)->bdaddr, addr);
67
    sprintf(addrs[i],"%s",addr);
96
    sprintf(addrs[i],"%s",addr);
68
 
97
 
69
    memset(name, 0, sizeof(name));
98
    memset(name, 0, sizeof(name));
70
   
99
   
71
    if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
100
    if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
72
                             name, 0) < 0)
101
                             name, 0) < 0)
73
      sprintf(names[i],"[unknown]");
102
      sprintf(names[i],"[unknown]");
74
    else
103
    else
75
      sprintf(names[i],"%s",name);
104
      sprintf(names[i],"%s",name);
76
 
105
 
77
  }
106
  }
78
 
107
 
79
 
108
 
80
  free( ii );
109
  free( ii );
81
  close( sock );
110
  close( sock );
82
}
111
}
83
 
-
 
84
int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
-
 
85
char *button=NULL,*button_trigger=NULL, name_of_joystick[80];
-
 
86
 
-
 
87
struct js_event x52_event_struct;
112
 
88
 
113
 
89
void connect_joy()
114
void connect_joy()
90
{
115
{
91
 
116
 
92
 
117
 
93
  if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 )
118
  if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 )
94
    {
119
    {
95
      printf( "Couldn't open joystick device %s\n", JOY_DEV );
120
      printf( "Couldn't open joystick device %s\n", JOY_DEV );
96
      return ;
121
      return ;
97
    }
122
    }
98
 
123
 
99
  ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis );
124
  ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis );
100
  ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons );
125
  ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons );
101
  ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick );
126
  ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick );
102
 
127
 
103
  axis = (int *) calloc( num_of_axis, sizeof( int ) );
128
  axis = (int *) calloc( num_of_axis, sizeof( int ) );
104
  button = (char *)calloc( num_of_buttons, sizeof( char ) );
129
  button = (char *)calloc( num_of_buttons, sizeof( char ) );
105
  button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
130
  button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
106
 
131
 
107
  printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
132
  printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
108
         , name_of_joystick
133
         , name_of_joystick
109
         , num_of_axis
134
         , num_of_axis
110
         , num_of_buttons );
135
         , num_of_buttons );
111
 
136
 
112
  fcntl( x52_input_fd, F_SETFL, O_NONBLOCK );   /* use non-blocking mode */
137
  fcntl( x52_input_fd, F_SETFL, O_NONBLOCK );   /* use non-blocking mode */
113
 
138
 
114
}
139
}
115
 
140
 
116
 
-
 
117
struct
-
 
118
{
-
 
119
  char val[4];
-
 
120
} MotortestParam;
141
 
121
 
142
 
122
 
143
 
123
void AddCRC(unsigned int wieviele)
144
void AddCRC(unsigned int wieviele)
124
{
145
{
125
  unsigned int tmpCRC = 0,i;
146
  unsigned int tmpCRC = 0,i;
126
  for(i = 0; i < wieviele;i++)
147
  for(i = 0; i < wieviele;i++)
127
    {
148
    {
128
      tmpCRC += TxBuffer[i];
149
      tmpCRC += TxBuffer[i];
129
    }
150
    }
130
  tmpCRC %= 4096;
151
  tmpCRC %= 4096;
131
  TxBuffer[i++] = '=' + tmpCRC / 64;
152
  TxBuffer[i++] = '=' + tmpCRC / 64;
132
  TxBuffer[i++] = '=' + tmpCRC % 64;
153
  TxBuffer[i++] = '=' + tmpCRC % 64;
133
  TxBuffer[i++] = '\r';
154
  TxBuffer[i++] = '\r';
134
}
155
}
135
 
156
 
136
void SendOutData(unsigned char cmd,unsigned char modul, int len)
157
void SendOutData(unsigned char cmd,unsigned char modul, int len)
137
{
158
{
138
  unsigned int pt = 0,ptr=0,i;
159
  unsigned int pt = 0,ptr=0,i;
139
  int a,b,c;
160
  int a,b,c;
140
  TxBuffer[pt++] = '#';           // Startzeichen
161
  TxBuffer[pt++] = '#';           // Startzeichen
141
  TxBuffer[pt++] = modul;        // Adresse (a=0; b=1,...)
162
  TxBuffer[pt++] = modul;        // Adresse (a=0; b=1,...)
142
  TxBuffer[pt++] = cmd;          // Commando
163
  TxBuffer[pt++] = cmd;          // Commando
143
 
164
 
144
  while(len)
165
  while(len)
145
    {
166
    {
146
      if(len) { a = _TxBuffer[ptr++]; len--;} else a = 0;
167
      if(len) { a = _TxBuffer[ptr++]; len--;} else a = 0;
147
      if(len) { b = _TxBuffer[ptr++]; len--;} else b = 0;
168
      if(len) { b = _TxBuffer[ptr++]; len--;} else b = 0;
148
      if(len) { c = _TxBuffer[ptr++]; len--;} else c = 0;
169
      if(len) { c = _TxBuffer[ptr++]; len--;} else c = 0;
149
      TxBuffer[pt++] = '=' + (a >> 2);
170
      TxBuffer[pt++] = '=' + (a >> 2);
150
      TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
171
      TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
151
      TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
172
      TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
152
      TxBuffer[pt++] = '=' + ( c & 0x3f);
173
      TxBuffer[pt++] = '=' + ( c & 0x3f);
153
    }
174
    }
154
 
175
 
155
  status = send(s,"\r" , 1, 0);
176
  status = send(s,"\r" , 1, 0);
156
  i=0;
177
  i=0;
157
  while(TxBuffer[i] !='\r' && i<150)
178
  while(TxBuffer[i] !='\r' && i<150)
158
    {
179
    {
159
      //     TxBuffer[i]='#';
180
      //     TxBuffer[i]='#';
160
      status = send(s,&TxBuffer[i] , 1, 0);
181
      status = send(s,&TxBuffer[i] , 1, 0);
161
      printf(" +%d%c ",i,TxBuffer[i]);
182
      printf(" +%d%c ",i,TxBuffer[i]);
162
      i++;
183
      i++;
163
    }
184
    }
164
 
185
 
165
  status = send(s,"\r" , 1, 0);
186
  status = send(s,"\r" , 1, 0);
166
 
187
 
167
  printf("\n");
188
  printf("\n");
168
  AddCRC(pt);
189
  AddCRC(pt);
169
  printf("Sending to MK\n");
190
  printf("Sending to MK\n");
170
 
191
 
171
}
192
}
172
 
193
 
173
 
194
 
174
int engines_on=0;
195
int engines_on=0;
175
int old_engines_on=0;
196
int old_engines_on=0;
176
 
197
 
177
 
198
 
178
void write_display(int line,char* text)
199
void write_display(int line,char* text)
179
{
200
{
180
  if (x52_output) x52_settext(x52_output, line , text, strlen(text));
201
  if (x52_output) x52_settext(x52_output, line , text, strlen(text));
181
}
202
}
182
 
203
 
183
void clear_display()
204
void clear_display()
184
{
205
{
185
  write_display(0,"");
206
  write_display(0,"");
186
  write_display(1,"");
207
  write_display(1,"");
187
  write_display(2,"");
208
  write_display(2,"");
188
}
209
}
189
 
210
 
190
 
211
 
191
void output_device_list()
212
void output_device_list()
192
{
213
{
193
  int i;
214
  int i;
194
  char disp_txt[20];
215
  char disp_txt[20];
195
  for(i=0;i<bt_device_count;i++)
216
  for(i=0;i<bt_device_count;i++)
196
    {
217
    {
197
      if (i<3)
218
      if (i<3)
198
        {
219
        {
199
         
220
         
200
          if (selected_bt_device==i)
221
          if (selected_bt_device==i)
201
            sprintf(disp_txt,"#%s",names[i]);
222
            sprintf(disp_txt,"#%s",names[i]);
202
          else
223
          else
203
            sprintf(disp_txt," %s",names[i]);
224
            sprintf(disp_txt," %s",names[i]);
204
          write_display(i,disp_txt);
225
          write_display(i,disp_txt);
205
        }
226
        }
206
    }
227
    }
207
}
228
}
208
 
229
 
209
void connect_mk(char dest[18])
230
void connect_mk(char dest[18])
210
{
231
{
211
  struct sockaddr_rc addr ;
232
  struct sockaddr_rc addr ;
212
 
233
 
213
  // allocate a socket
234
  // allocate a socket
214
  s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
235
  s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
215
 
236
 
216
  // set the connection parameters (who to connect to)
237
  // set the connection parameters (who to connect to)
217
  addr.rc_family = AF_BLUETOOTH;
238
  addr.rc_family = AF_BLUETOOTH;
218
  addr.rc_channel = 1;
239
  addr.rc_channel = 1;
219
  str2ba( dest, &addr.rc_bdaddr );
240
  str2ba( dest, &addr.rc_bdaddr );
220
 
241
 
221
  // connect to server
242
  // connect to server
222
  status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
243
  status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
223
 
244
 
224
}
245
}
225
 
246
 
226
 
247
 
227
 
248
 
228
 
249
 
229
 
250
 
230
int main(int argc, char**argv)
251
int main(int argc, char**argv)
231
{
252
{
232
  printf("Starting Riddim \n");
253
  printf("Starting Riddim \n");
233
  printf("\tRemote Interactive Digital Drone Interface Mashup\n");
254
  printf("\tRemote Interactive Digital Drone Interface Mashup\n");
234
 
255
 
235
  //int tmp=2;
256
  //int tmp=2;
236
  //  connect_mk("00:0B:CE:01:6B:4F");
257
  //  connect_mk("00:0B:CE:01:6B:4F");
237
                 
-
 
238
  /*
-
 
239
 
-
 
240
  {
-
 
241
  // send a message
-
 
242
 
-
 
243
  MotortestParam.val[0]=tmp;
-
 
244
  MotortestParam.val[1]=tmp;
-
 
245
  MotortestParam.val[2]=tmp;
-
 
246
  MotortestParam.val[3]=tmp;
-
 
247
 
-
 
248
  engines_on=1;
-
 
249
                   
-
 
250
 
-
 
251
  else
-
 
252
  engines_on=0;
-
 
253
 
-
 
254
  if (engines_on!=old_engines_on)
-
 
255
  {
-
 
256
  int c;
-
 
257
 
-
 
258
  if( 0 == status )for (c=0;c<10;c++)
-
 
259
  int c;
-
 
260
  for (c=0;c<2;c++)
-
 
261
  SendOutData('t', 0,  &MotortestParam, sizeof(MotortestParam));
-
 
262
 
-
 
263
 
-
 
264
   
-
 
265
  sleep(1);
-
 
266
  }
-
 
267
        */
-
 
268
 
-
 
269
 
-
 
270
    if( status < 0 ) perror("uh oh");
258
                 
271
    printf ("send status %d",status);
-
 
272
    //    close(s);
-
 
273
 
-
 
274
 int i;
-
 
275
  /*
-
 
276
 
-
 
277
  MotortestParam.val[0]=2;
-
 
278
  MotortestParam.val[1]=2;
-
 
279
  MotortestParam.val[2]=2;
259
 
280
  MotortestParam.val[3]=2;
-
 
281
 
-
 
282
 
-
 
283
 
-
 
284
 
-
 
285
  while(1)
-
 
286
    {
-
 
287
      initSerial("/dev/rfcomm0");
-
 
288
      sleep(2);
-
 
289
      SendOutData('t', 0,  &MotortestParam, sizeof(MotortestParam));
-
 
290
      sleep(1);
-
 
291
    }
260
 
292
  */
261
 
293
 
262
  int i;
294
 
263
 
295
  printf("\nInitializing X-52 input ..\n");
264
  printf("\nInitializing X-52 input ..\n");
296
  connect_joy();
265
  connect_joy();
297
  printf(".. done");
266
  printf(".. done");
298
 
267
 
299
  printf("\nInitializing X-52 output ..");
268
  printf("\nInitializing X-52 output ..");
300
 
269
 
301
    x52_output = x52_init();
270
  x52_output = x52_init();
302
 
271
   
303
    clear_display();
272
  clear_display();
304
 
273
 
305
    write_display(0, "RIDDIM active");
274
  write_display(0, "RIDDIM active");
306
 
275
 
307
    if (x52_output) x52_setbri(x52_output, 1,128);  
276
  if (x52_output) x52_setbri(x52_output, 1,128);  
308
    if (x52_output)
277
  if (x52_output)
309
      printf(" done \n");  
278
    printf(" done \n");  
310
    else
279
  else
311
      printf(" not found \n");      
-
 
312
 
-
 
313
 
280
    printf(" not found \n");      
314
 
281
 
315
  printf("Scanning for Bluetooth Devices ..\n");
282
  printf("Scanning for Bluetooth Devices ..\n");
316
  write_display(1,"Bluetooth Scan");
283
  write_display(1,"Bluetooth Scan");
317
 
-
 
318
 
284
 
319
  scan_bt();
285
  scan_bt();
320
  printf(" done \n");  
286
  printf(" done \n");  
321
  printf(" %d Devices found \n",bt_device_count);  
287
  printf(" %d Devices found \n",bt_device_count);  
322
 
288
 
323
 
289
 
324
  for(i=0;i<bt_device_count;i++)
290
  for(i=0;i<bt_device_count;i++)
325
    {
291
    {
326
      printf(" %d -> %s (%s) \n",i,names[i],addrs[i]);  
292
      printf(" %d -> %s (%s) \n",i,names[i],addrs[i]);  
327
      if (i<3) write_display(i,names[i]);
293
      if (i<3) write_display(i,names[i]);
328
    }
294
    }
329
 
295
 
330
  output_device_list() ;
296
  output_device_list() ;
331
 
297
 
332
 
298
 
333
  int v_old;
299
  int v_old;
334
  while( 1 )    
300
  while( 1 )    
335
    {
301
    {
336
      int polls=0;
302
      int polls=0;
337
      for (polls=0;polls<1000;polls++)
303
      for (polls=0;polls<1000;polls++) // FIXME - better Polling
338
        {
304
        {
339
      read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
305
      read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
340
               
306
               
341
 
307
 
342
                        /* see what to do with the event */
308
                        /* see what to do with the event */
343
                switch (x52_event_struct.type & ~JS_EVENT_INIT)
309
                switch (x52_event_struct.type & ~JS_EVENT_INIT)
344
                {
310
                {
345
                        case JS_EVENT_AXIS:
311
                        case JS_EVENT_AXIS:
346
                                axis   [ x52_event_struct.number ] = x52_event_struct.value;
312
                                axis   [ x52_event_struct.number ] = x52_event_struct.value;
347
                                break;
313
                                break;
348
                        case JS_EVENT_BUTTON:
314
                        case JS_EVENT_BUTTON:
349
                                button [ x52_event_struct.number ] = x52_event_struct.value;
315
                                button [ x52_event_struct.number ] = x52_event_struct.value;
350
                                break;
316
                                break;
351
                }
317
                }
352
        }
318
        }
353
                if (1)
-
 
354
                  {
-
 
355
 
319
               
356
                  }
-
 
357
 
-
 
358
                for( x=0 ; x<num_of_buttons ; ++x )
320
      for( x=0 ; x<num_of_buttons ; ++x )
359
                  if( button[x]==0)
321
        if( button[x]==0)
360
                    button_trigger[x]=0;
322
          button_trigger[x]=0;
361
                  else
323
        else
362
                    {
324
          {
363
                    if (button_trigger[x]<100)button_trigger[x]++;
325
            if (button_trigger[x]<100)button_trigger[x]++;
364
                    }
326
          }
365
 
327
 
366
 
328
 
367
               
329
               
368
                switch(state)
330
      switch(state)
369
                  {
331
        {
370
                  case STATEID_SCANNING:
332
        case STATEID_SCANNING:
371
                    if (button_trigger[BUTTON_SELECT]==1)
333
          if (button_trigger[BUTTON_SELECT]==1)
372
                      {
334
            {
373
                        state=STATEID_CONNECTING;
335
              state=STATEID_CONNECTING;
374
                        clear_display();
336
              clear_display();
375
                        write_display(0,"connecting to");
337
              write_display(0,"connecting to");
376
                        write_display(1,names[selected_bt_device]);
338
              write_display(1,names[selected_bt_device]);
377
                        connect_mk(addrs[selected_bt_device]);
339
              connect_mk(addrs[selected_bt_device]);
378
                        write_display(0,"connected to");
340
              write_display(0,"connected to");
379
                      }
341
            }
380
                   
342
                   
381
                    if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1)
343
          if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1)
382
                      {
344
            {
383
                        printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]);
345
              printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]);
384
                        if (button_trigger[BUTTON_DOWN]==1)
346
              if (button_trigger[BUTTON_DOWN]==1)
385
                          if (selected_bt_device>0) selected_bt_device--;
347
                if (selected_bt_device>0) selected_bt_device--;
386
                        if (button_trigger[BUTTON_UP]==1)
348
              if (button_trigger[BUTTON_UP]==1)
387
                          if (selected_bt_device<bt_device_count-1) selected_bt_device++;
349
                if (selected_bt_device<bt_device_count-1) selected_bt_device++;
388
                       
350
             
389
                        output_device_list()              ;
351
              output_device_list()                ;
390
                      }
352
            }
391
                    break;
353
          break;
392
                  case STATEID_CONNECTING:
354
        case STATEID_CONNECTING:
393
                   
355
                   
394
 
356
 
395
                    _TxBuffer[0]=(axis[2]>>8)*(-1)+127;
357
          _TxBuffer[0]=(axis[2]>>8)*(-1)+127;
396
                    if (button[7]!=1)_TxBuffer[0] =0;
358
          if (button[7]!=1)_TxBuffer[0] =0;
397
               
359
         
398
                    _TxBuffer[1]=_TxBuffer[0];
360
          _TxBuffer[1]=_TxBuffer[0];
399
                    _TxBuffer[2]=_TxBuffer[0];
361
          _TxBuffer[2]=_TxBuffer[0];
400
                    _TxBuffer[3]=_TxBuffer[0];
362
          _TxBuffer[3]=_TxBuffer[0];
401
               
363
         
402
                    SendOutData('t', 0, 4);
364
          SendOutData('t', 0, 4);
403
               
365
               
404
 
366
         
405
                    sleep(0.05);       
367
          sleep(0.05); 
406
 
368
 
407
 
369
 
408
 
370
 
409
                    int v=axis[6]/655+50;
371
          int v=axis[6]/655+50;
410
                    if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v );  
372
          if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v );  
411
                    v_old=v;
373
          v_old=v;
412
               
374
         
413
                    printf("v: %d \r",v);
375
          printf("v: %d \r",v);
414
 
376
 
415
                   
377
                   
416
                    for (i=0;i<num_of_axis;i++)
378
          for (i=0;i<num_of_axis;i++)
417
                      printf("A%d: %d  ", i,axis[i]>>8 );
379
            printf("A%d: %d  ", i,axis[i]>>8 );
418
                   
380
         
419
                    for( x=0 ; x<num_of_buttons ; ++x )
381
          for( x=0 ; x<num_of_buttons ; ++x )
420
 
-
 
421
                      printf("B%d: %d  ", x, button[x] );                  
-
 
422
                   
-
 
423
                    break;
-
 
424
                  }
-
 
425
                    /*
-
 
426
 
-
 
427
*/                
-
 
428
              printf("\r");
-
 
429
fflush(stdout);
-
 
430
               
-
 
431
                /*
382
           
-
 
383
            printf("B%d: %d  ", x, button[x] );            
-
 
384
                   
-
 
385
          break;
-
 
386
        }
-
 
387
                 
-
 
388
      printf("\r");
432
      if( read( x52_input_fd, &x52_input_struct, JS_RETURN ) != JS_RETURN )
389
      fflush(stdout);
433
        {
390
     
434
          printf( "\nFailed to read from Joystick\n" );
391
               
435
        }
-
 
436
 
-
 
437
 
-
 
438
      if (x52_output) x52_setbri(x52_output, 1,x52_input_struct.y );  
-
 
439
      //      if (x52_output) x52_setbri(x52_output, 2,x52_input_struct.x );  
-
 
440
 
392
      }
441
 
393
 
442
*/
394
 
443
      }
395
  /******************** Cleanup **********************/
444
 
396
  close(x52_input_fd);
445
  close(x52_input_fd);  /* too bad we never get here */
397
  close(s);
446
 
398
 
447
  if (x52_output) x52_close(x52_output);
399
  if (x52_output) x52_close(x52_output);
448
  return 0;
400
  return 0;
449
}
401
}
450
 
402