Rev 130 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 130 | Rev 140 | ||
---|---|---|---|
Line 10... | Line 10... | ||
10 | **************************************************/ |
10 | **************************************************/ |
Line 11... | Line 11... | ||
11 | 11 | ||
Line 12... | Line -... | ||
12 | #include "riddim.h" |
- | |
13 | 12 | #include "riddim.h" |
|
Line 14... | Line -... | ||
14 | - | ||
15 | - | ||
16 | int state=STATEID_SCANNING; |
- | |
17 | - | ||
18 | - | ||
19 | - | ||
20 | - | ||
21 | - | ||
22 | - | ||
23 | - | ||
24 | 13 | ||
Line 25... | Line 14... | ||
25 | 14 | ||
26 | int x52_input_fd, num_of_axis=0, num_of_buttons=0; |
15 | int state=STATEID_SCANNING; |
Line 27... | Line 16... | ||
27 | char *button_trigger=NULL, name_of_joystick[80]; |
16 | |
28 | 17 | ||
Line 29... | Line -... | ||
29 | struct js_event x52_event_struct; |
- | |
30 | - | ||
31 | int engines_on=0; |
18 | struct js_event x52_event_struct; |
Line 32... | Line 19... | ||
32 | int old_engines_on=0; |
19 | |
Line 33... | Line -... | ||
33 | - | ||
34 | int *axis; |
- | |
35 | char *button; |
- | |
36 | - | ||
37 | 20 | int engines_on=0; |
|
38 | 21 | int old_engines_on=0; |
|
39 | struct x52 *x52_output; |
22 | |
40 | 23 | int *axis; |
|
Line 133... | Line 116... | ||
133 | } |
116 | } |
134 | } |
117 | } |
Line 135... | Line 118... | ||
135 | 118 | ||
Line -... | Line 119... | ||
- | 119 | // todo reenable bluetooth connection |
|
- | 120 | ||
- | 121 | if ((input_evdev_name)) |
|
Line 136... | Line -... | ||
136 | // todo reenable bluetooth connection |
- | |
137 | - | ||
138 | 122 | { |
|
139 | /* |
123 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
140 | printf("\nInitializing X-52 input ..\n"); |
124 | |
141 | if (connect_joy()) |
125 | if (connect_evdev(input_evdev_name)) |
142 | { |
126 | { |
143 | printf(".. done");// |
127 | printf(".. done");// |
144 | input=INPUT_JOYDEV; |
128 | input=INPUT_EVDEV; |
145 | } |
129 | } |
Line 146... | Line 130... | ||
146 | else |
130 | else |
147 | printf(".. ERROR ");// |
131 | printf(".. ERROR ");// |
148 | */ |
132 | } |
149 | - | ||
150 | if (input_evdev_name) |
133 | |
151 | { |
134 | if (input_joydev_name) |
152 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
135 | { |
153 | 136 | printf("\nInitializing joystick input from %s ..\n",input_joydev_name); |
|
154 | if (connect_evdev(input_evdev_name)) |
137 | if (connect_joy()) |
155 | { |
138 | { |
156 | printf(".. done");// |
139 | printf(".. done");// |
157 | input=INPUT_EVDEV; |
140 | input=INPUT_JOYDEV; |
Line -... | Line 141... | ||
- | 141 | } |
|
158 | } |
142 | else |
Line 159... | Line 143... | ||
159 | else |
143 | printf(".. ERROR ");// |
Line 160... | Line 144... | ||
160 | printf(".. ERROR ");// |
144 | } |
Line 215... | Line 199... | ||
215 | switch (input) |
199 | switch (input) |
216 | { |
200 | { |
Line 217... | Line 201... | ||
217 | 201 | ||
218 | 202 | ||
219 | case INPUT_NONE: |
203 | case INPUT_NONE: |
Line 220... | Line 204... | ||
220 | printf("starting input none\n"); |
204 | printf("processing input none\n"); |
221 | break; |
205 | break; |
222 | - | ||
223 | case INPUT_EVDEV: |
- | |
224 | printf("input evdev\n"); |
206 | |
Line 225... | Line 207... | ||
225 | 207 | case INPUT_EVDEV: |
|
Line 226... | Line 208... | ||
226 | 208 | printf("processing input evdev\n"); |
|
227 | poll_evdev(); |
209 | poll_evdev(); |
228 | 210 | ||
Line 229... | Line 211... | ||
229 | break; |
211 | break; |
230 | 212 | ||
231 | case INPUT_JOYDEV: |
213 | case INPUT_JOYDEV: |
Line 232... | Line 214... | ||
232 | printf("input joydev\n"); |
214 | printf("processing input joydev\n"); |
233 | // poll values from input device |
215 | // poll values from input device |
234 | 216 | ||
Line 255... | Line 237... | ||
255 | else |
237 | else |
256 | { |
238 | { |
257 | if (button_trigger[x]<100)button_trigger[x]++; |
239 | if (button_trigger[x]<100)button_trigger[x]++; |
258 | } |
240 | } |
259 | break; |
241 | break; |
260 | } |
242 | } // switch (input) |
Line 261... | Line 243... | ||
261 | 243 | ||
Line 262... | Line 244... | ||
262 | printf("input done\n"); |
244 | printf("input done\n"); |
263 | 245 | ||
264 | switch(state) |
- | |
265 | { |
- | |
266 | 246 | switch(state) |
|
Line 267... | Line 247... | ||
267 | 247 | { |
|
268 | case STATEID_SCANNING: |
248 | case STATEID_SCANNING: |
269 | 249 | ||
Line 314... | Line 294... | ||
314 | 294 | ||
Line 315... | Line 295... | ||
315 | case STATEID_CONNECTING: |
295 | case STATEID_CONNECTING: |
316 | - | ||
- | 296 | ||
317 | 297 | ||
318 | confirm_misses=0; |
298 | confirm_misses=0; |
Line 319... | Line 299... | ||
319 | printf("connected:%d",connected); |
299 | |
Line 333... | Line 313... | ||
333 | // ftime(&time_struct); |
313 | // ftime(&time_struct); |
Line 334... | Line 314... | ||
334 | 314 | ||
335 | printf("waiting for confirm frame ( confirmed:%d misses:%d )\n",complete_matches,complete_misses); |
315 | printf("waiting for confirm frame ( confirmed:%d misses:%d )\n",complete_matches,complete_misses); |
Line 336... | Line -... | ||
336 | RxBuffer[2]=0; |
- | |
337 | - | ||
338 | 316 | RxBuffer[2]=0; |
|
Line 339... | Line 317... | ||
339 | 317 | ||
340 | // r=0; |
318 | // r=0; |
341 | 319 | ||
Line 358... | Line 336... | ||
358 | else |
336 | else |
359 | printf("not connected to mk\n"); |
337 | printf("not connected to mk\n"); |
Line 360... | Line 338... | ||
360 | 338 | ||
Line 361... | Line 339... | ||
361 | gettimeofday(&time_struct2,NULL); |
339 | gettimeofday(&time_struct2,NULL); |
362 | 340 | ||
Line 363... | Line 341... | ||
363 | printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec)); |
341 | printf("last trip: %d\n",(int)(time_struct2.tv_usec-time_struct1.tv_usec)); |
Line 364... | Line 342... | ||
364 | // act_mode=button[24] | (button[25]<<1); |
342 | // act_mode=button[24] | (button[25]<<1); |
- | 343 | ||
- | 344 | ||
- | 345 | ||
- | 346 | // Step converting axis data to nick/roll/gier/gas/.. |
|
- | 347 | ||
- | 348 | // act_nick=(evdev_rel_axis[rel_axis_nick]-128)*nick_mul; |
|
- | 349 | ||
- | 350 | ||
- | 351 | ||
365 | 352 | ||
366 | 353 | switch(input) |
|
367 | 354 | { |
|
- | 355 | case INPUT_EVDEV: |
|
- | 356 | ||
- | 357 | act_nick=(evdev_rel_axis[rel_axis_nick]-nick_add)*nick_mul; |
|
- | 358 | act_roll=(evdev_rel_axis[rel_axis_roll]-nick_add)*roll_mul; |
|
- | 359 | act_gier=(evdev_rel_axis[rel_axis_gier]-nick_add)*gier_mul; |
|
- | 360 | act_gas=(evdev_rel_axis[rel_axis_gas]-nick_add)*gas_mul; |
|
- | 361 | ||
- | 362 | ||
- | 363 | break; |
|
- | 364 | ||
- | 365 | case INPUT_JOYDEV: |
|
- | 366 | act_nick=(axis[rel_axis_nick])*nick_mul; |
|
- | 367 | act_roll=(axis[rel_axis_roll])*roll_mul; |
|
- | 368 | act_gier=(axis[rel_axis_gier])*gier_mul; |
|
- | 369 | act_gas=(axis[rel_axis_gas]*-1+33000)*gas_mul; |
|
- | 370 | ||
368 | // Step converting axis data to nick/roll/gier/gas/.. |
371 | break; |
Line 369... | Line 372... | ||
369 | 372 | } |
|
370 | act_nick=evdev_rel_axis[rel_axis_nick]*nick_mul; |
373 | |
371 | act_roll=evdev_rel_axis[rel_axis_roll]*roll_mul; |
374 | // act values clipping to usefull vals |
Line 424... | Line 427... | ||
424 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
427 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
425 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
428 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
426 | ExternControl.Gier=act_gier; // ************ |
429 | ExternControl.Gier=act_gier; // ************ |
427 | ExternControl.Gas=act_gas; // ************ |
430 | ExternControl.Gas=act_gas; // ************ |
Line 428... | Line -... | ||
428 | - | ||
Line -... | Line 431... | ||
- | 431 | ||
429 | complete_matches++; |
432 | |
Line 430... | Line 433... | ||
430 | 433 | ||
431 | 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); |
434 | 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); |
- | 435 | ||
432 | 436 | if (connected) |
|
Line 433... | Line 437... | ||
433 | if (connected) |
437 | { |
434 | { |
438 | complete_matches++; |
435 | printf("sending data\n"); |
439 | printf("sending data\n"); |
Line 463... | Line 467... | ||
463 | } |
467 | } |
Line 464... | Line 468... | ||
464 | 468 | ||
465 | printf("\n"); |
469 | printf("\n"); |
466 | fflush(stdout); |
470 | fflush(stdout); |
- | 471 | printf("loop fin ( confirmed:%d misses:%d | debug_sets:%d )\n",complete_matches,complete_misses,debug_sets); |
|
Line 467... | Line 472... | ||
467 | printf("loop fin ( confirmed:%d misses:%d | debug_sets:%d )\n",complete_matches,complete_misses,debug_sets); |
472 | printf("------------------------------------------------------------------------\n"); |
Line 468... | Line 473... | ||
468 | 473 | ||
469 | } |
474 | } |
470 | 475 | ||
Line 471... | Line 476... | ||
471 | 476 | ||
472 | /******************** Cleanup **********************/ |
477 | /******************** Cleanup **********************/ |
473 | close(x52_input_fd); |
478 | close(joy_input_fd); |