Rev 127 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 127 | Rev 130 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | * Remote Interactive Digital Drone Interface Mashup |
5 | * Remote Interactive Digital Drone Interface Mashup |
6 | * |
6 | * |
7 | * 2007-2008 Marcus -LiGi- Bueschleb |
7 | * 2007-2008 Marcus -LiGi- Bueschleb |
8 | * |
8 | * |
9 | * |
9 | * |
10 | **************************************************/ |
10 | **************************************************/ |
Line 11... | Line 11... | ||
11 | 11 | ||
Line 12... | Line -... | ||
12 | #include "riddim.h" |
- | |
13 | - | ||
Line 14... | Line -... | ||
14 | #define FALSE 0 |
- | |
Line 15... | Line 12... | ||
15 | #define TRUE 1 |
12 | #include "riddim.h" |
Line 16... | Line -... | ||
16 | - | ||
17 | #define test_bit(bit, array) (array[bit/8] & (1<<(bit%8))) |
- | |
18 | - | ||
19 | int state=STATEID_SCANNING; |
- | |
Line 20... | Line -... | ||
20 | - | ||
21 | - | ||
22 | // from config |
- | |
23 | char *input_evdev_name; |
- | |
Line 24... | Line -... | ||
24 | int mk_socket_port=0; |
- | |
25 | int loop_delay=0; |
- | |
26 | - | ||
27 | - | ||
Line 28... | Line -... | ||
28 | - | ||
29 | double nick_mul=0.3f; |
- | |
30 | double roll_mul=0.3f; |
- | |
31 | double gier_mul=0.3f; |
- | |
32 | double gas_mul=0.3f; |
- | |
33 | - | ||
34 | - | ||
35 | int rel_axis_nick=1; |
- | |
36 | int rel_axis_roll=0; |
- | |
37 | int rel_axis_gier=5; |
- | |
38 | int rel_axis_gas=2; |
- | |
39 | - | ||
40 | - | ||
41 | cfg_bool_t exit_after_init = cfg_false; |
- | |
42 | - | ||
43 | // time struct for measuring |
13 | |
44 | struct timeval time_struct1; |
14 | |
Line 45... | Line 15... | ||
45 | struct timeval time_struct2; |
15 | |
Line 46... | Line 16... | ||
46 | 16 | int state=STATEID_SCANNING; |
|
47 | 17 | ||
Line 48... | Line -... | ||
48 | char RxBuffer[150]; |
- | |
49 | - | ||
50 | - | ||
51 | int status; |
- | |
52 | - | ||
53 | - | ||
54 | - | ||
55 | - | ||
56 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
- | |
57 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
- | |
58 | 18 | ||
59 | struct js_event x52_event_struct; |
- | |
60 | - | ||
61 | int engines_on=0; |
- | |
62 | int old_engines_on=0; |
- | |
63 | - | ||
64 | char in_char; |
- | |
65 | - | ||
66 | struct x52 *x52_output; |
- | |
67 | - | ||
68 | int selected_bt_device=0; |
- | |
69 | - | ||
70 | int yalv; /* loop counter */ |
- | |
71 | size_t read_bytes; /* how many bytes were read */ |
- | |
72 | struct input_event ev[64]; /* the events (up to 64 at once) */ |
- | |
73 | - | ||
74 | int evdev_fd; |
- | |
75 | int evdev_out_fd; |
- | |
76 | - | ||
77 | int evdev_rw=TRUE; |
- | |
78 | - | ||
79 | int connect_evdev() |
- | |
80 | { |
- | |
81 | - | ||
82 | struct input_devinfo { |
- | |
83 | uint16_t bustype; |
- | |
84 | uint16_t vendor; |
- | |
85 | uint16_t product; |
- | |
86 | uint16_t version; |
- | |
87 | }; |
- | |
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"); |
- | |
93 | evdev_rw=FALSE; |
- | |
94 | } |
- | |
95 | if ((evdev_fd = open(input_evdev_name, O_RDONLY)) < 0) |
- | |
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) { |
- | |
111 | perror("evdev ioctl"); |
- | |
112 | } |
- | |
113 | - | ||
114 | printf("EVDEV reports name: %s\n", name); |
- | |
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 |
- | |
118 | * operation with a byte that only has the relevant bit set. |
- | |
119 | * eg. to check for the 12th bit, we do (array[1] & 1<<4) |
- | |
120 | */ |
- | |
121 | - | ||
122 | - | ||
123 | uint8_t evtype_bitmask[EV_MAX/8 + 1]; |
- | |
124 | - | ||
125 | if(ioctl(evdev_fd, EVIOCGBIT(0, sizeof(evtype_bitmask)), evtype_bitmask) < 0) |
- | |
126 | perror("evdev ioctl"); |
- | |
127 | - | ||
128 | printf("Supported event types:\n"); |
- | |
129 | for (yalv = 0; yalv < EV_MAX; yalv++) { |
- | |
130 | if (test_bit(yalv, evtype_bitmask)) { |
- | |
131 | /* this means that the bit is set in the event types list */ |
- | |
132 | printf(" Event type 0x%02x ", yalv); |
- | |
133 | switch ( yalv) |
- | |
134 | { |
- | |
135 | case EV_KEY : |
- | |
136 | printf(" (Keys or Buttons)\n"); |
- | |
137 | break; |
- | |
138 | case EV_ABS : |
- | |
139 | printf(" (Absolute Axes)\n"); |
- | |
140 | break; |
- | |
141 | case EV_LED : |
- | |
142 | printf(" (LEDs)\n"); |
- | |
143 | break; |
- | |
144 | case EV_REP : |
- | |
145 | printf(" (Repeat)\n"); |
- | |
146 | break; |
- | |
147 | case EV_SYN : |
- | |
148 | printf(" (Sync?)\n"); |
- | |
149 | break; |
- | |
150 | case EV_REL : |
- | |
151 | printf(" (Relative Axis)\n"); |
- | |
152 | break; |
- | |
153 | case EV_MSC : |
- | |
154 | printf(" (Misc)\n"); |
- | |
155 | break; |
- | |
156 | default: |
- | |
157 | printf(" (Unknown event type: 0x%04hx)\n", yalv); |
- | |
158 | }}} |
- | |
159 | - | ||
160 | return 1; |
- | |
161 | } |
- | |
162 | - | ||
163 | int connect_joy() |
- | |
164 | { |
19 | |
165 | - | ||
166 | axis = (int *) calloc( 100, sizeof( int ) ); |
- | |
167 | button = (char *)calloc( 100, sizeof( char ) ); |
- | |
168 | button_trigger = (char *) calloc( 100, sizeof( char ) ); |
- | |
169 | - | ||
170 | - | ||
171 | // axis = (int *) calloc( num_of_axis, sizeof( int ) ); |
- | |
172 | // button = (char *)calloc( num_of_buttons, sizeof( char ) ); |
- | |
173 | // button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) ); |
- | |
174 | - | ||
175 | - | ||
176 | if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
- | |
177 | { |
- | |
178 | printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
- | |
179 | printf( "try modprobe joydev\n" ); |
- | |
Line -... | Line 20... | ||
- | 20 | ||
Line -... | Line 21... | ||
- | 21 | ||
Line -... | Line 22... | ||
- | 22 | ||
- | 23 | ||
Line 180... | Line 24... | ||
180 | return 0; |
24 | |
181 | } |
25 | |
182 | 26 | int x52_input_fd, num_of_axis=0, num_of_buttons=0; |
|
Line 238... | Line 82... | ||
238 | for(i=0;i<bt_device_count;i++) |
82 | for(i=0;i<bt_device_count;i++) |
239 | printf("device%i->%s\n",i,names[i]); |
83 | printf("device%i->%s\n",i,names[i]); |
240 | } |
84 | } |
Line 241... | Line 85... | ||
241 | 85 | ||
242 | 86 | ||
243 | int r=0; |
87 | |
Line 244... | Line 88... | ||
244 | int count=0; |
88 | int count=0; |
Line 253... | Line 97... | ||
253 | 97 | ||
254 | printf("Starting Riddim \n"); |
98 | printf("Starting Riddim \n"); |
255 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
99 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
256 | printf("\nusage:\n"); |
100 | printf("\nusage:\n"); |
257 | printf("\t riddim [config_file]\n\n"); |
- | |
Line 258... | Line 101... | ||
258 | 101 | printf("\t riddim [config_file]\n\n"); |
|
Line 259... | Line -... | ||
259 | - | ||
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), |
- | |
274 | CFG_SIMPLE_INT("rel_axis_gier", &rel_axis_gier), |
- | |
275 | CFG_SIMPLE_INT("rel_axis_gas", &rel_axis_gas), |
- | |
276 | - | ||
277 | CFG_END() |
- | |
278 | }; |
- | |
279 | - | ||
280 | cfg_t *cfg; |
- | |
281 | - | ||
282 | // input_evdev_name=strdup("/dev/event0"); |
- | |
Line 283... | Line 102... | ||
283 | printf("Parsing config file "); |
102 | |
284 | - | ||
285 | cfg = cfg_init(opts, 0); |
- | |
286 | 103 | // bt_host_init(); |
|
287 | if (argv[1]) |
- | |
288 | { |
104 | |
289 | printf("%s\n ",argv[1]); |
- | |
290 | cfg_parse(cfg, argv[1]); |
- | |
291 | } |
105 | |
292 | else |
106 | if (argv[1]) |
293 | { |
- | |
- | 107 | parse_config(argv[1]); |
|
Line 294... | Line 108... | ||
294 | printf("/etc/riddim.conf\n"); |
108 | else |
- | 109 | parse_config("/etc/riddim.conf"); |
|
- | 110 | ||
- | 111 | ||
Line -... | Line 112... | ||
- | 112 | ||
- | 113 | printf("input %s:\n",input_evdev_name); |
|
- | 114 | /* |
|
- | 115 | if (bluetooth_mac) |
|
- | 116 | { |
|
295 | cfg_parse(cfg, "/etc/riddim.conf"); |
117 | |
296 | } |
118 | printf("Connecting via Bluetooth to %s\n",bluetooth_mac); |
297 | printf("input %s:\n",input_evdev_name); |
119 | if (connect_mk_bluetooth(bluetooth_mac));; |
298 | 120 | connected=TRUE; |
|
299 | // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips ) |
121 | } |
300 | 122 | */ |
|
301 | if (mk_socket_port) |
123 | if (mk_socket_port) |
302 | { |
124 | { |
303 | printf("connecting to local port: %i\n",mk_socket_port); |
125 | printf("connecting to local port: %i\n",mk_socket_port); |
304 | 126 | ||
305 | if (connect_mk_localhost_socket(mk_socket_port)==-1) |
127 | if (connect_mk_localhost_socket(mk_socket_port)==-1) |
306 | printf("cant connect !!"); |
128 | printf("cant connect !!"); |
Line 307... | Line 129... | ||
307 | else |
129 | else |
Line -... | Line 130... | ||
- | 130 | { |
|
- | 131 | printf("connected !-)"); |
|
308 | { |
132 | connected=TRUE; |
309 | printf("connected to QC at adress: %s\n",argv[1]); |
133 | } |
310 | connected=TRUE; |
134 | } |
311 | } |
135 | |
312 | } |
136 | // todo reenable bluetooth connection |
313 | 137 | ||
314 | int i; |
138 | |
315 | 139 | /* |
|
- | 140 | printf("\nInitializing X-52 input ..\n"); |
|
Line 316... | Line -... | ||
316 | printf("\nInitializing X-52 input ..\n"); |
- | |
317 | if (connect_joy()) |
141 | if (connect_joy()) |
318 | { |
142 | { |
- | 143 | printf(".. done");// |
|
- | 144 | input=INPUT_JOYDEV; |
|
- | 145 | } |
|
- | 146 | else |
|
319 | printf(".. done");// |
147 | printf(".. ERROR ");// |
320 | input=INPUT_JOYDEV; |
148 | */ |
- | 149 | ||
- | 150 | if (input_evdev_name) |
|
- | 151 | { |
|
321 | } |
152 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
322 | else |
- | |
323 | printf(".. ERROR ");// |
- | |
324 | 153 | ||
325 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
154 | if (connect_evdev(input_evdev_name)) |
Line 326... | Line 155... | ||
326 | if (connect_evdev()) |
155 | { |
Line 327... | Line 156... | ||
327 | { |
156 | printf(".. done");// |
Line 344... | Line 173... | ||
344 | printf(" done \n"); |
173 | printf(" done \n"); |
345 | else |
174 | else |
346 | printf(" not found \n"); |
175 | printf(" not found \n"); |
Line 347... | Line 176... | ||
347 | 176 | ||
348 | /* |
177 | /* |
349 | if (!connected) |
178 | if (!connected) |
350 | { |
179 | { |
351 | printf("Scanning for Bluetooth Devices ..\n"); |
180 | printf("Scanning for Bluetooth Devices ..\n"); |
352 | write_display(1,"Bluetooth Scan"); |
181 | write_display(1,"Bluetooth Scan"); |
353 | scan_bt(); |
182 | scan_bt(); |
354 | printf(" done \n"); |
183 | printf(" done \n"); |
355 | printf(" %d Devices found \n",bt_device_count); |
184 | printf(" %d Devices found \n",bt_device_count); |
356 | print_device_list() ; |
185 | print_device_list() ; |
357 | } |
186 | } |
Line 358... | Line 187... | ||
358 | */ |
187 | */ |
359 | 188 | ||
Line 360... | Line 189... | ||
360 | int v_old; |
189 | // int v_old; |
361 | int polls=0; |
190 | int polls=0; |
362 | 191 | ||
363 | int retval; |
192 | |
Line 364... | Line -... | ||
364 | if (exit_after_init) |
- | |
365 | exit(0); |
- | |
- | 193 | if (exit_after_init) |
|
Line 366... | Line 194... | ||
366 | printf("starting loop ..\n"); |
194 | exit(0); |
367 | - | ||
368 | struct input_event led_event; |
- | |
369 | led_event.type=EV_LED; |
- | |
370 | 195 | printf("starting loop ..\n"); |
|
371 | int complete_misses=0; |
- | |
372 | if (evdev_out_fd) |
196 | |
Line 373... | Line 197... | ||
373 | { |
197 | |
374 | led_event.code = LED_MISC; |
- | |
375 | led_event.value = 1; |
- | |
Line 376... | Line -... | ||
376 | retval = write(evdev_out_fd, &led_event, sizeof(struct input_event)); |
- | |
377 | } |
- | |
378 | - | ||
379 | int confirm_misses; |
- | |
380 | while( 1 ) |
- | |
381 | { |
- | |
382 | - | ||
383 | if (evdev_out_fd) |
- | |
Line -... | Line 198... | ||
- | 198 | ||
- | 199 | int complete_misses=0; |
|
- | 200 | int complete_matches=0; |
|
- | 201 | ||
- | 202 | ||
- | 203 | int confirm_misses; |
|
- | 204 | ||
- | 205 | ||
384 | { |
206 | |
385 | if (led_event.value) |
207 | init_evdevstatus_led(); |
386 | led_event.value = 0; |
208 | |
Line 387... | Line 209... | ||
387 | else |
209 | while( TRUE ) |
388 | led_event.value = 1 ; |
210 | { |
389 | retval = write(evdev_out_fd, &led_event, sizeof(struct input_event)); |
211 | |
Line 390... | Line 212... | ||
390 | } |
212 | blink_evdev_led(); |
391 | 213 | // bt_host_tick(mk_socket); |
|
392 | usleep(loop_delay); |
- | |
393 | switch (input) |
- | |
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); |
- | |
409 | - | ||
410 | tv.tv_sec = 0; |
- | |
411 | tv.tv_usec = 5; |
- | |
412 | - | ||
413 | retval = select(evdev_fd+1, &rfds, NULL, NULL, &tv); |
- | |
414 | - | ||
415 | if (retval==-1) |
- | |
416 | printf("error in select!!!!!!!!\n"); |
- | |
417 | else if (retval) |
- | |
418 | { |
- | |
419 | read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64); |
- | |
420 | - | ||
421 | if (read_bytes < (int) sizeof(struct input_event)) { |
- | |
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 | } |
- | |
433 | - | ||
Line -... | Line 214... | ||
- | 214 | usleep(loop_delay); |
|
- | 215 | switch (input) |
|
- | 216 | { |
|
434 | 217 | ||
Line 435... | Line 218... | ||
435 | for (yalv=0;yalv<10;yalv++) |
218 | |
436 | printf("A%d %d -" , yalv, axis[yalv] ); |
219 | case INPUT_NONE: |
437 | printf("\n"); |
220 | printf("starting input none\n"); |
Line 463... | Line 246... | ||
463 | case JS_EVENT_BUTTON: |
246 | case JS_EVENT_BUTTON: |
464 | button [ x52_event_struct.number ] = x52_event_struct.value; |
247 | button [ x52_event_struct.number ] = x52_event_struct.value; |
465 | break; |
248 | break; |
466 | } |
249 | } |
467 | } |
250 | } |
468 | 251 | int x; |
|
469 | for( x=0 ; x<num_of_buttons ; ++x ) |
252 | for( x=0 ; x<num_of_buttons ; ++x ) |
470 | if( button[x]==0) |
253 | if( button[x]==0) |
471 | button_trigger[x]=0; |
254 | button_trigger[x]=0; |
472 | else |
255 | else |
473 | { |
256 | { |
Line 481... | Line 264... | ||
481 | switch(state) |
264 | switch(state) |
482 | { |
265 | { |
Line 483... | Line 266... | ||
483 | 266 | ||
484 | 267 | ||
485 | case STATEID_SCANNING: |
268 | case STATEID_SCANNING: |
486 | 269 | ||
487 | state=STATEID_CONNECTING; |
270 | state=STATEID_CONNECTING; |
488 | 271 | /* |
|
489 | ExternControl.Digital[0]=0; |
272 | ExternControl.Digital[0]=0; |
490 | ExternControl.Digital[1]=0; |
273 | ExternControl.Digital[1]=0; |
Line 524... | Line 307... | ||
524 | if (button_trigger[BUTTON_UP]==1) |
307 | if (button_trigger[BUTTON_UP]==1) |
525 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
308 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
Line 526... | Line 309... | ||
526 | 309 | |
|
- | 310 | ||
527 | 311 | } |
|
Line 528... | Line 312... | ||
528 | } |
312 | */ |
Line 529... | Line 313... | ||
529 | break; |
313 | break; |
530 | 314 | ||
- | 315 | case STATEID_CONNECTING: |
|
- | 316 | ||
- | 317 | ||
- | 318 | confirm_misses=0; |
|
531 | case STATEID_CONNECTING: |
319 | printf("connected:%d",connected); |
532 | 320 | RxBuffer[1]=0; |
|
Line 533... | Line 321... | ||
533 | 321 | if (connected) |
|
- | 322 | ||
- | 323 | ||
- | 324 | while (RxBuffer[1]!='t') |
|
Line 534... | Line 325... | ||
534 | confirm_misses=0; |
325 | { |
- | 326 | ||
535 | printf("connected:%d",connected); |
327 | RxBuffer[1]=0; |
536 | if (connected) while (RxBuffer[1]!='t') |
328 | read_from_mk(); |
Line 537... | Line 329... | ||
537 | { |
329 | // bt_host_send(RxBuffer,rx_last_length); |
538 | - | ||
Line 539... | Line -... | ||
539 | RxBuffer[1]=0; |
- | |
540 | - | ||
541 | - | ||
542 | // ftime(&time_struct); |
- | |
543 | printf("waiting for confirm frame ( misses:%d )\n",confirm_misses); |
- | |
544 | RxBuffer[2]=0; |
- | |
545 | - | ||
546 | - | ||
547 | - | ||
548 | r=0; |
- | |
549 | in_char='#'; |
- | |
550 | - | ||
551 | while(in_char!='\n') |
- | |
552 | { |
- | |
553 | count=read(mk_socket,&in_char,1); |
- | |
554 | if (in_char!=0) |
330 | printf("sending to host: %s",PrintableRxBuffer); |
- | 331 | ||
555 | { |
332 | |
556 | RxBuffer[r++]=in_char; |
333 | // ftime(&time_struct); |
557 | } |
334 | |
558 | else |
335 | printf("waiting for confirm frame ( confirmed:%d misses:%d )\n",complete_matches,complete_misses); |
559 | { |
336 | RxBuffer[2]=0; |
- | 337 | ||
- | 338 | ||
560 | RxBuffer[r++]='0'; |
339 | |
561 | } |
340 | // r=0; |
562 | // printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char); |
341 | |
563 | } |
342 | // new |
564 | RxBuffer[r++]='\0'; |
343 | /* |
565 | printf("%d--->%s\n",complete_misses,RxBuffer); |
344 | if (button_trigger[12]>1) |
566 | // new |
345 | { |
567 | if (button_trigger[12]>1) |
346 | SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
568 | { |
347 | button_trigger[12]=0; |
- | 348 | } |
|
569 | SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
349 | */ |
Line 570... | Line 350... | ||
570 | button_trigger[12]=0; |
350 | ExternControl.Frame='t'; |
571 | } |
351 | if (++confirm_misses>4) |
Line 572... | Line 352... | ||
572 | if (++confirm_misses>4) |
352 | { |
Line 573... | Line 353... | ||
573 | { |
353 | complete_misses++; |
574 | complete_misses++; |
354 | printf("sending again\n"); |
575 | printf("sending again\n"); |
355 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
576 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
356 | } |
577 | } |
357 | } |
Line 578... | Line 358... | ||
578 | } |
358 | else |
579 | else |
359 | printf("not connected to mk\n"); |
580 | printf("not connected to mk\n"); |
360 | |
581 | gettimeofday(&time_struct2,NULL); |
361 | gettimeofday(&time_struct2,NULL); |
Line 582... | Line 362... | ||
582 | 362 | ||
583 | printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec)); |
363 | printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec)); |
584 | act_mode=button[24] | (button[25]<<1); |
364 | // act_mode=button[24] | (button[25]<<1); |
585 | 365 | ||
Line 586... | Line 366... | ||
586 | 366 | ||
587 | 367 | ||
Line 588... | Line 368... | ||
588 | // Step converting axis data to nick/roll/gier/gas/.. |
368 | // Step converting axis data to nick/roll/gier/gas/.. |
Line 589... | Line 369... | ||
589 | 369 | ||
590 | act_nick=axis[rel_axis_nick]*nick_mul; |
370 | act_nick=evdev_rel_axis[rel_axis_nick]*nick_mul; |
Line 591... | Line 371... | ||
591 | act_roll=axis[rel_axis_roll]*roll_mul; |
371 | act_roll=evdev_rel_axis[rel_axis_roll]*roll_mul; |
592 | act_gier=axis[rel_axis_gier]*gier_mul; |
372 | act_gier=evdev_rel_axis[rel_axis_gier]*gier_mul; |
593 | act_gas=axis[rel_axis_gas]*gas_mul; |
373 | act_gas=evdev_rel_axis[rel_axis_gas]*gas_mul; |
594 | act_gas=255; |
374 | act_gas=255; |
595 | 375 | ||
Line 596... | Line 376... | ||
596 | 376 | ||
Line 597... | Line 377... | ||
597 | /* |
377 | /* |
598 | switch (act_mode) |
378 | switch (act_mode) |
599 | { |
379 | { |
600 | case 0: |
380 | case 0: |
601 | 381 | ||
Line 602... | Line 382... | ||
602 | 382 | ||
Line 603... | Line 383... | ||
603 | act_nick=(axis[AXIS_NICK])*(INVERT_NICK); |
383 | act_nick=(axis[AXIS_NICK])*(INVERT_NICK); |
604 | act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL); |
384 | act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL); |
605 | act_gier=(axis[AXIS_GIER])*(INVERT_GIER); |
385 | act_gier=(axis[AXIS_GIER])*(INVERT_GIER); |
606 | act_gas=((axis[AXIS_GAS])-128)*(-1); |
386 | act_gas=((axis[AXIS_GAS])-128)*(-1); |
607 | |
387 | |
608 | // clip gas |
- | |
609 | if (act_gas<0) act_gas=0; |
- | |
610 | - | ||
611 | if (act_gas>250) act_gas=250; |
- | |
612 | - | ||
613 | //////// act_gas=0; |
- | |
614 | break; |
- | |
615 | - | ||
616 | case 1: |
388 | // clip gas |
617 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
389 | if (act_gas<0) act_gas=0; |
618 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
390 | |
619 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
- | |
620 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
391 | if (act_gas>250) act_gas=250; |
621 | - | ||
Line -... | Line 392... | ||
- | 392 | ||
- | 393 | //////// act_gas=0; |
|
- | 394 | break; |
|
- | 395 | ||
- | 396 | case 1: |
|
- | 397 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
|
- | 398 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
|
- | 399 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
|
Line 622... | Line 400... | ||
622 | break; |
400 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
623 | |
401 | |
624 | case 2: |
402 | break; |
Line 625... | Line 403... | ||
625 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
403 | |
626 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
404 | case 2: |
627 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
405 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
628 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
406 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
Line 629... | Line 407... | ||
629 | 407 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
|
630 | 408 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
|
631 | break; |
409 | |
Line 632... | Line 410... | ||
632 | 410 | ||
633 | } |
411 | break; |
634 | */ |
412 | |
Line 635... | Line 413... | ||
635 | ExternControl.Digital[0]=0; |
413 | } |
Line -... | Line 414... | ||
- | 414 | */ |
|
636 | ExternControl.Digital[1]=0; |
415 | ExternControl.Digital[0]=0; |
637 | ExternControl.RemoteTasten=0; |
416 | ExternControl.Digital[1]=0; |
Line 638... | Line 417... | ||
638 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
417 | ExternControl.RemoteTasten=0; |
Line 639... | Line 418... | ||
639 | // printf("nick%d\n",ExternControl.Nick); |
418 | ExternControl.Higt=0; |
- | 419 | ExternControl.free=0; |
|
640 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
420 | ExternControl.Frame='t'; |
641 | ExternControl.Gier=(axis[5]>>8); |
421 | ExternControl.Config=1; |
642 | ExternControl.Gier=act_gier; // ************ |
422 | |
Line 643... | Line 423... | ||
643 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
423 | |
644 | ExternControl.Gas=act_gas; // ************ |
424 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
645 | // ExternControl.Gas=0; // ************ |
425 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
Line 646... | Line 426... | ||
646 | ExternControl.Higt=0; |
426 | ExternControl.Gier=act_gier; // ************ |
Line 647... | Line 427... | ||
647 | ExternControl.free=0; |
427 | ExternControl.Gas=act_gas; // ************ |