Rev 43 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 43 | Rev 47 | ||
---|---|---|---|
Line 16... | Line 16... | ||
16 | #include <linux/joystick.h> |
16 | #include <linux/joystick.h> |
17 | #define JOY_DEV "/dev/input/js0" |
17 | #define JOY_DEV "/dev/input/js0" |
Line 18... | Line 18... | ||
18 | 18 | ||
Line -... | Line 19... | ||
- | 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 |
|
19 | #define MAX_BT_DEVICES 3 |
27 | #define BUTTON_UP 27 |
Line 20... | Line 28... | ||
20 | 28 | ||
21 | int bt_device_count=0; |
29 | int bt_device_count=0; |
Line 22... | Line 30... | ||
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]; |
Line -... | Line 33... | ||
- | 33 | ||
- | 34 | int s, status; |
|
- | 35 | 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; |
|
25 | 47 | ||
- | 48 | struct |
|
- | 49 | { |
|
- | 50 | unsigned char Digital[2]; // (noch unbenutzt) |
|
- | 51 | unsigned char RemoteTasten; //(gab es schon für das virtuelle Display) |
|
- | 52 | signed char Nick; |
|
- | 53 | signed char Roll; |
|
26 | int s, status; |
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) |
|
- | 58 | unsigned char Frame; // (Bestätigung) |
|
27 | unsigned char TxBuffer[150]; |
59 | unsigned char Config; |
Line 28... | Line -... | ||
28 | unsigned char _TxBuffer[150]; |
- | |
29 | - | ||
30 | #define STATEID_SCANNING 0 |
- | |
Line 31... | Line 60... | ||
31 | #define STATEID_CONNECTING 1 |
60 | } ExternControl; |
Line 32... | Line 61... | ||
32 | int state=STATEID_SCANNING; |
61 | |
33 | 62 | ||
Line 79... | Line 108... | ||
79 | 108 | ||
80 | free( ii ); |
109 | free( ii ); |
81 | close( sock ); |
110 | close( sock ); |
Line 82... | Line -... | ||
82 | } |
- | |
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]; |
- | |
Line 86... | Line 111... | ||
86 | 111 | } |
|
87 | struct js_event x52_event_struct; |
112 | |
Line 112... | Line 137... | ||
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 */ |
Line 113... | Line 138... | ||
113 | 138 | ||
Line 114... | Line -... | ||
114 | } |
- | |
115 | - | ||
116 | - | ||
117 | struct |
- | |
Line 118... | Line 139... | ||
118 | { |
139 | } |
119 | char val[4]; |
140 | |
120 | } MotortestParam; |
141 | |
Line 233... | Line 254... | ||
233 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
254 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
Line 234... | Line 255... | ||
234 | 255 | ||
235 | //int tmp=2; |
256 | //int tmp=2; |
Line 236... | Line -... | ||
236 | // 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); |
- | |
Line 266... | Line -... | ||
266 | } |
- | |
267 | */ |
- | |
268 | - | ||
Line 269... | Line 257... | ||
269 | 257 | // connect_mk("00:0B:CE:01:6B:4F"); |
|
270 | if( status < 0 ) perror("uh oh"); |
- | |
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; |
258 | |
279 | MotortestParam.val[2]=2; |
- | |
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); |
259 | |
291 | } |
260 | |
292 | */ |
261 | |
Line 293... | Line 262... | ||
293 | 262 | int i; |
|
Line 294... | Line 263... | ||
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"); |
- | |
306 | - | ||
Line 307... | Line 274... | ||
307 | if (x52_output) x52_setbri(x52_output, 1,128); |
274 | write_display(0, "RIDDIM active"); |
308 | if (x52_output) |
275 | |
Line 309... | Line -... | ||
309 | printf(" done \n"); |
- | |
310 | else |
276 | if (x52_output) x52_setbri(x52_output, 1,128); |
311 | printf(" not found \n"); |
277 | if (x52_output) |
312 | 278 | printf(" done \n"); |
|
Line 332... | Line 298... | ||
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 | { |
Line 339... | Line 305... | ||
339 | read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
305 | read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
Line 348... | Line 314... | ||
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 | } |
Line 365... | Line 327... | ||
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]); |
Line 377... | Line 339... | ||
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 | ||
Line 389... | Line 351... | ||
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; |
Line 397... | Line 359... | ||
397 | 359 | ||
398 | _TxBuffer[1]=_TxBuffer[0]; |
360 | _TxBuffer[1]=_TxBuffer[0]; |
Line 399... | Line 361... | ||
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 | ||
Line 404... | Line 366... | ||
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; |
Line 410... | Line 372... | ||
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; |
- | |
412 | - | ||
413 | printf("v: %d \r",v); |
- | |
414 | - | ||
415 | - | ||
416 | for (i=0;i<num_of_axis;i++) |
- | |
417 | printf("A%d: %d ", i,axis[i]>>8 ); |
- | |
418 | - | ||
419 | for( x=0 ; x<num_of_buttons ; ++x ) |
- | |
420 | - | ||
421 | printf("B%d: %d ", x, button[x] ); |
- | |
422 | 373 | v_old=v; |
|
- | 374 | ||
- | 375 | printf("v: %d \r",v); |
|
- | 376 | ||
- | 377 | ||
- | 378 | for (i=0;i<num_of_axis;i++) |
|
- | 379 | printf("A%d: %d ", i,axis[i]>>8 ); |
|
Line 423... | Line 380... | ||
423 | break; |
380 | |
424 | } |
381 | for( x=0 ; x<num_of_buttons ; ++x ) |
425 | /* |
382 | |
Line 426... | Line -... | ||
426 | - | ||
427 | */ |
- | |
428 | printf("\r"); |
- | |
429 | fflush(stdout); |
- | |
430 | - | ||
431 | /* |
383 | printf("B%d: %d ", x, button[x] ); |
432 | if( read( x52_input_fd, &x52_input_struct, JS_RETURN ) != JS_RETURN ) |
384 | |
433 | { |
385 | break; |