Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
127 | ligi | 1 | /************************************************** |
2 | * |
||
3 | * |
||
4 | * Riddim |
||
5 | * Remote Interactive Digital Drone Interface Mashup |
||
6 | * |
||
7 | * 2007-2008 Marcus -LiGi- Bueschleb |
||
8 | * |
||
9 | * |
||
130 | ligi | 10 | **************************************************/ |
125 | ligi | 11 | |
127 | ligi | 12 | #include "riddim.h" |
41 | ligi | 13 | |
127 | ligi | 14 | int state=STATEID_SCANNING; |
41 | ligi | 15 | |
43 | ligi | 16 | |
47 | ligi | 17 | struct js_event x52_event_struct; |
18 | |||
48 | ligi | 19 | int engines_on=0; |
20 | int old_engines_on=0; |
||
21 | |||
130 | ligi | 22 | int *axis; |
23 | char *button; |
||
48 | ligi | 24 | |
127 | ligi | 25 | struct x52 *x52_output; |
47 | ligi | 26 | |
127 | ligi | 27 | int selected_bt_device=0; |
47 | ligi | 28 | |
43 | ligi | 29 | void write_display(int line,char* text) |
30 | { |
||
31 | if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
||
32 | } |
||
33 | |||
34 | void clear_display() |
||
35 | { |
||
36 | write_display(0,""); |
||
37 | write_display(1,""); |
||
38 | write_display(2,""); |
||
39 | } |
||
40 | |||
41 | |||
42 | void output_device_list() |
||
43 | { |
||
44 | int i; |
||
45 | char disp_txt[20]; |
||
46 | for(i=0;i<bt_device_count;i++) |
||
47 | { |
||
48 | if (i<3) |
||
486 | ligi | 49 | { |
50 | |||
51 | if (selected_bt_device==i) |
||
52 | sprintf(disp_txt,"#%s",names[i]); |
||
53 | else |
||
54 | sprintf(disp_txt," %s",names[i]); |
||
55 | write_display(i,disp_txt); |
||
56 | } |
||
43 | ligi | 57 | } |
58 | } |
||
59 | |||
127 | ligi | 60 | |
61 | void print_device_list() |
||
43 | ligi | 62 | { |
127 | ligi | 63 | int i; |
64 | for(i=0;i<bt_device_count;i++) |
||
65 | printf("device%i->%s\n",i,names[i]); |
||
43 | ligi | 66 | } |
67 | |||
68 | |||
130 | ligi | 69 | |
50 | ligi | 70 | int count=0; |
71 | int connected=0; |
||
43 | ligi | 72 | |
117 | ligi | 73 | |
74 | int input=INPUT_NONE; |
||
75 | |||
125 | ligi | 76 | |
483 | ligi | 77 | |
43 | ligi | 78 | int main(int argc, char**argv) |
79 | { |
||
125 | ligi | 80 | |
483 | ligi | 81 | printf("Starting Riddim %d.%d \n",RIDDIM_VERSION_MAJOR,RIDDIM_VERSION_MINOR ); |
43 | ligi | 82 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
127 | ligi | 83 | printf("\nusage:\n"); |
84 | printf("\t riddim [config_file]\n\n"); |
||
125 | ligi | 85 | |
127 | ligi | 86 | |
87 | |||
485 | ligi | 88 | |
483 | ligi | 89 | |
486 | ligi | 90 | // bt_host_init(); |
483 | ligi | 91 | |
130 | ligi | 92 | if (argv[1]) |
93 | parse_config(argv[1]); |
||
94 | else |
||
95 | parse_config("/etc/riddim.conf"); |
||
125 | ligi | 96 | |
485 | ligi | 97 | |
98 | collect_evdev_devices(); |
||
99 | parse_config_input_sections(); |
||
483 | ligi | 100 | // exit(0); |
125 | ligi | 101 | |
130 | ligi | 102 | printf("input %s:\n",input_evdev_name); |
103 | /* |
||
104 | if (bluetooth_mac) |
||
50 | ligi | 105 | { |
130 | ligi | 106 | |
107 | printf("Connecting via Bluetooth to %s\n",bluetooth_mac); |
||
108 | if (connect_mk_bluetooth(bluetooth_mac));; |
||
109 | connected=TRUE; |
||
127 | ligi | 110 | } |
130 | ligi | 111 | */ |
483 | ligi | 112 | |
113 | if (mk_tty) |
||
114 | { |
||
115 | printf("connecting to mk via tty: %s\n",mk_tty); |
||
116 | if (!connect_mk_tty(mk_tty)) |
||
117 | printf("cant connect !!"); |
||
118 | else |
||
119 | { |
||
120 | printf("connected !-)"); |
||
121 | connected=TRUE; |
||
122 | } |
||
123 | } |
||
124 | |||
127 | ligi | 125 | if (mk_socket_port) |
126 | { |
||
483 | ligi | 127 | printf("connecting to mk via local port: %i\n",mk_socket_port); |
130 | ligi | 128 | |
127 | ligi | 129 | if (connect_mk_localhost_socket(mk_socket_port)==-1) |
130 | printf("cant connect !!"); |
||
131 | else |
||
50 | ligi | 132 | { |
130 | ligi | 133 | printf("connected !-)"); |
127 | ligi | 134 | connected=TRUE; |
50 | ligi | 135 | } |
136 | } |
||
127 | ligi | 137 | |
130 | ligi | 138 | // todo reenable bluetooth connection |
117 | ligi | 139 | |
483 | ligi | 140 | connect_evdev(); |
141 | |||
142 | /* |
||
140 | ligi | 143 | if ((input_evdev_name)) |
117 | ligi | 144 | { |
130 | ligi | 145 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
146 | |||
147 | if (connect_evdev(input_evdev_name)) |
||
148 | { |
||
149 | printf(".. done");// |
||
150 | input=INPUT_EVDEV; |
||
151 | } |
||
152 | else |
||
153 | printf(".. ERROR ");// |
||
117 | ligi | 154 | } |
483 | ligi | 155 | */ |
140 | ligi | 156 | if (input_joydev_name) |
157 | { |
||
158 | printf("\nInitializing joystick input from %s ..\n",input_joydev_name); |
||
159 | if (connect_joy()) |
||
160 | { |
||
161 | printf(".. done");// |
||
162 | input=INPUT_JOYDEV; |
||
163 | } |
||
164 | else |
||
165 | printf(".. ERROR ");// |
||
166 | } |
||
167 | |||
168 | |||
43 | ligi | 169 | printf("\nInitializing X-52 output .."); |
170 | |||
47 | ligi | 171 | x52_output = x52_init(); |
172 | |||
173 | clear_display(); |
||
43 | ligi | 174 | |
47 | ligi | 175 | write_display(0, "RIDDIM active"); |
43 | ligi | 176 | |
47 | ligi | 177 | if (x52_output) x52_setbri(x52_output, 1,128); |
178 | if (x52_output) |
||
179 | printf(" done \n"); |
||
180 | else |
||
181 | printf(" not found \n"); |
||
43 | ligi | 182 | |
127 | ligi | 183 | /* |
130 | ligi | 184 | if (!connected) |
43 | ligi | 185 | { |
130 | ligi | 186 | printf("Scanning for Bluetooth Devices ..\n"); |
187 | write_display(1,"Bluetooth Scan"); |
||
188 | scan_bt(); |
||
189 | printf(" done \n"); |
||
190 | printf(" %d Devices found \n",bt_device_count); |
||
191 | print_device_list() ; |
||
43 | ligi | 192 | } |
127 | ligi | 193 | */ |
41 | ligi | 194 | |
130 | ligi | 195 | // int v_old; |
117 | ligi | 196 | int polls=0; |
127 | ligi | 197 | |
130 | ligi | 198 | |
127 | ligi | 199 | if (exit_after_init) |
200 | exit(0); |
||
117 | ligi | 201 | printf("starting loop ..\n"); |
202 | |||
203 | |||
130 | ligi | 204 | |
127 | ligi | 205 | int complete_misses=0; |
130 | ligi | 206 | int complete_matches=0; |
117 | ligi | 207 | |
130 | ligi | 208 | |
127 | ligi | 209 | int confirm_misses; |
130 | ligi | 210 | |
211 | |||
212 | |||
483 | ligi | 213 | // init_evdevstatus_led(); |
130 | ligi | 214 | |
215 | while( TRUE ) |
||
41 | ligi | 216 | { |
117 | ligi | 217 | |
505 | ligi | 218 | gettimeofday(&loop_start_time,NULL); |
219 | |||
220 | |||
483 | ligi | 221 | // blink_evdev_led(); |
486 | ligi | 222 | // bt_host_tick(mk_socket); |
127 | ligi | 223 | usleep(loop_delay); |
483 | ligi | 224 | |
225 | poll_evdev(); |
||
226 | |||
117 | ligi | 227 | switch (input) |
43 | ligi | 228 | { |
127 | ligi | 229 | |
117 | ligi | 230 | |
231 | case INPUT_NONE: |
||
140 | ligi | 232 | printf("processing input none\n"); |
117 | ligi | 233 | break; |
43 | ligi | 234 | |
117 | ligi | 235 | case INPUT_EVDEV: |
140 | ligi | 236 | printf("processing input evdev\n"); |
483 | ligi | 237 | |
130 | ligi | 238 | |
239 | break; |
||
117 | ligi | 240 | |
241 | case INPUT_JOYDEV: |
||
140 | ligi | 242 | printf("processing input joydev\n"); |
117 | ligi | 243 | // poll values from input device |
244 | |||
245 | for (polls=0;polls<100;polls++) // FIXME - better Polling |
||
246 | { |
||
140 | ligi | 247 | read(joy_input_fd, &x52_event_struct, sizeof(struct js_event)); |
117 | ligi | 248 | |
249 | |||
250 | /* see what to do with the event */ |
||
251 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
||
252 | { |
||
253 | case JS_EVENT_AXIS: |
||
254 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
||
255 | break; |
||
256 | case JS_EVENT_BUTTON: |
||
257 | button [ x52_event_struct.number ] = x52_event_struct.value; |
||
258 | break; |
||
259 | } |
||
260 | } |
||
130 | ligi | 261 | int x; |
117 | ligi | 262 | for( x=0 ; x<num_of_buttons ; ++x ) |
263 | if( button[x]==0) |
||
264 | button_trigger[x]=0; |
||
265 | else |
||
266 | { |
||
267 | if (button_trigger[x]<100)button_trigger[x]++; |
||
268 | } |
||
269 | break; |
||
140 | ligi | 270 | } // switch (input) |
43 | ligi | 271 | |
117 | ligi | 272 | printf("input done\n"); |
43 | ligi | 273 | |
47 | ligi | 274 | switch(state) |
275 | { |
||
276 | case STATEID_SCANNING: |
||
130 | ligi | 277 | |
50 | ligi | 278 | state=STATEID_CONNECTING; |
130 | ligi | 279 | /* |
48 | ligi | 280 | ExternControl.Digital[0]=0; |
281 | ExternControl.Digital[1]=0; |
||
282 | ExternControl.RemoteTasten=0; |
||
283 | ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
||
284 | |||
285 | printf("nick%d\n",ExternControl.Nick); |
||
286 | ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
||
287 | ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
||
288 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
||
289 | ExternControl.Higt=0; |
||
290 | ExternControl.free=0; |
||
291 | ExternControl.Frame='t'; |
||
292 | ExternControl.Config=1; |
||
293 | |||
294 | printf("sending data\n"); |
||
295 | |||
50 | ligi | 296 | |
127 | ligi | 297 | if (connected)SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
50 | ligi | 298 | gettimeofday(&time_struct1,NULL); |
48 | ligi | 299 | |
47 | ligi | 300 | if (button_trigger[BUTTON_SELECT]==1) |
301 | { |
||
302 | state=STATEID_CONNECTING; |
||
303 | clear_display(); |
||
304 | write_display(0,"connecting to"); |
||
305 | write_display(1,names[selected_bt_device]); |
||
127 | ligi | 306 | //connect_mk(addrs[selected_bt_device]); |
47 | ligi | 307 | write_display(0,"connected to"); |
308 | } |
||
43 | ligi | 309 | |
47 | ligi | 310 | if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1) |
311 | { |
||
312 | printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]); |
||
313 | if (button_trigger[BUTTON_DOWN]==1) |
||
314 | if (selected_bt_device>0) selected_bt_device--; |
||
315 | if (button_trigger[BUTTON_UP]==1) |
||
316 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
||
317 | |||
127 | ligi | 318 | |
47 | ligi | 319 | } |
130 | ligi | 320 | */ |
47 | ligi | 321 | break; |
48 | ligi | 322 | |
47 | ligi | 323 | case STATEID_CONNECTING: |
127 | ligi | 324 | |
50 | ligi | 325 | |
488 | ligi | 326 | |
327 | |||
328 | |||
127 | ligi | 329 | confirm_misses=0; |
140 | ligi | 330 | |
483 | ligi | 331 | RxBuffer[2]=0; |
130 | ligi | 332 | if (connected) |
127 | ligi | 333 | { |
488 | ligi | 334 | read_from_mk(); |
335 | if (RxBuffer[2]=='B') |
||
336 | complete_misses++; |
||
337 | /*while (RxBuffer[2]!='B') |
||
338 | { |
||
50 | ligi | 339 | |
127 | ligi | 340 | RxBuffer[1]=0; |
130 | ligi | 341 | read_from_mk(); |
486 | ligi | 342 | // bt_host_send(RxBuffer,rx_last_length); |
483 | ligi | 343 | printf("sending to host: %s",PrintableRxBuffer); |
50 | ligi | 344 | |
117 | ligi | 345 | |
127 | ligi | 346 | // ftime(&time_struct); |
130 | ligi | 347 | |
483 | ligi | 348 | printf("waiting for confirm frame ( confirmed:%d misses:%d %c)\n",complete_matches,complete_misses,RxBuffer[2]); |
349 | // RxBuffer[2]=0; |
||
43 | ligi | 350 | |
130 | ligi | 351 | // r=0; |
43 | ligi | 352 | |
117 | ligi | 353 | // new |
488 | ligi | 354 | |
355 | //if (button_trigger[12]>1) |
||
356 | // { |
||
357 | // SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
||
358 | // button_trigger[12]=0; |
||
359 | // } |
||
360 | |||
130 | ligi | 361 | ExternControl.Frame='t'; |
117 | ligi | 362 | if (++confirm_misses>4) |
127 | ligi | 363 | { |
364 | complete_misses++; |
||
365 | printf("sending again\n"); |
||
366 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
||
367 | } |
||
488 | ligi | 368 | */ |
48 | ligi | 369 | } |
127 | ligi | 370 | else |
371 | printf("not connected to mk\n"); |
||
488 | ligi | 372 | |
505 | ligi | 373 | // gettimeofday(&time_struct2,NULL); |
43 | ligi | 374 | |
505 | ligi | 375 | // printf("last trip: %d\n",(int)(time_struct2.tv_usec-time_struct1.tv_usec)); |
130 | ligi | 376 | // act_mode=button[24] | (button[25]<<1); |
43 | ligi | 377 | |
127 | ligi | 378 | |
379 | |||
380 | // Step converting axis data to nick/roll/gier/gas/.. |
||
381 | |||
140 | ligi | 382 | // act_nick=(evdev_rel_axis[rel_axis_nick]-128)*nick_mul; |
127 | ligi | 383 | |
384 | |||
140 | ligi | 385 | |
386 | |||
483 | ligi | 387 | /* Mix input values */ |
388 | |||
389 | act_gas=0; |
||
390 | act_nick=0; |
||
391 | act_roll=0; |
||
392 | act_gier=0; |
||
393 | |||
394 | int act_input=0; |
||
395 | for (act_input=0;act_input<input_count;act_input++) |
||
396 | { |
||
505 | ligi | 397 | |
398 | printf("process b %d\n",inputs[act_input].nick_up_btn); |
||
483 | ligi | 399 | //process buttons |
400 | if (inputs[act_input].nick_up_btn!=-1) |
||
401 | { |
||
402 | if (inputs[act_input].evdev_button[inputs[act_input].nick_up_btn]!=0) |
||
403 | act_nick=100; |
||
404 | |||
405 | } |
||
406 | |||
505 | ligi | 407 | |
483 | ligi | 408 | if (inputs[act_input].nick_down_btn!=-1) |
409 | { |
||
410 | if (inputs[act_input].evdev_button[inputs[act_input].nick_down_btn]!=0) |
||
411 | act_nick=-100; |
||
412 | |||
413 | } |
||
414 | |||
505 | ligi | 415 | |
483 | ligi | 416 | if (inputs[act_input].roll_left_btn!=-1) |
417 | { |
||
418 | if (inputs[act_input].evdev_button[inputs[act_input].roll_left_btn]!=0) |
||
419 | act_roll=100; |
||
420 | |||
421 | } |
||
422 | |||
423 | if (inputs[act_input].roll_right_btn!=-1) |
||
424 | { |
||
425 | if (inputs[act_input].evdev_button[inputs[act_input].roll_right_btn]!=0) |
||
426 | act_roll=-100; |
||
427 | |||
505 | ligi | 428 | |
483 | ligi | 429 | } |
430 | |||
431 | // process axis |
||
432 | |||
433 | if (inputs[act_input].rel_axis_nick!=-1) |
||
434 | act_nick=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_nick]*inputs[act_input].nick_mul; |
||
435 | |||
436 | if (inputs[act_input].rel_axis_roll!=-1) |
||
437 | act_roll=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_roll]*inputs[act_input].roll_mul; |
||
438 | |||
439 | |||
440 | if (inputs[act_input].rel_axis_gier!=-1) |
||
441 | act_gier=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_gier]*inputs[act_input].gier_mul; |
||
442 | |||
443 | |||
444 | if (inputs[act_input].rel_axis_gas!=-1) |
||
445 | act_gas=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_gas]*inputs[act_input].gas_mul; |
||
446 | |||
447 | |||
448 | |||
505 | ligi | 449 | if (inputs[act_input].rel_axis_alt!=-1) |
450 | { |
||
451 | |||
452 | if (inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_alt]>300) |
||
453 | act_long_alt-=last_trip_time/100; |
||
454 | |||
455 | if (inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_alt]<-300) |
||
456 | act_long_alt+=last_trip_time/100; |
||
457 | |||
458 | act_alt=act_long_alt/1000; |
||
459 | |||
460 | if (act_alt>120)act_alt=120; |
||
461 | else if (act_alt<-120)act_alt=-120; |
||
462 | } |
||
463 | // process_events |
||
464 | |||
465 | if (inputs[act_input].engine_switch_btn!=-1) |
||
466 | { |
||
467 | |||
468 | if ((inputs[act_input].evdev_button[inputs[act_input].engine_switch_btn]==0)&&(DebugOut.Analog[16]==1)) |
||
469 | { |
||
470 | ExternEvent.key=2; |
||
471 | SendOutData('e', 0, (unsigned char *)&ExternEvent, sizeof(ExternEvent)); |
||
472 | } |
||
473 | if ((inputs[act_input].evdev_button[inputs[act_input].engine_switch_btn]!=0)&&(DebugOut.Analog[16]==0)) |
||
474 | { |
||
475 | ExternEvent.key=1; |
||
476 | SendOutData('e', 0, (unsigned char *)&ExternEvent, sizeof(ExternEvent)); |
||
477 | } |
||
478 | |||
479 | |||
480 | |||
481 | } |
||
482 | |||
483 | ligi | 483 | } |
484 | |||
140 | ligi | 485 | switch(input) |
486 | { |
||
487 | case INPUT_EVDEV: |
||
483 | ligi | 488 | /* |
140 | ligi | 489 | act_nick=(evdev_rel_axis[rel_axis_nick]-nick_add)*nick_mul; |
490 | act_roll=(evdev_rel_axis[rel_axis_roll]-nick_add)*roll_mul; |
||
491 | act_gier=(evdev_rel_axis[rel_axis_gier]-nick_add)*gier_mul; |
||
492 | act_gas=(evdev_rel_axis[rel_axis_gas]-nick_add)*gas_mul; |
||
483 | ligi | 493 | */ |
140 | ligi | 494 | |
495 | break; |
||
496 | |||
497 | case INPUT_JOYDEV: |
||
498 | act_nick=(axis[rel_axis_nick])*nick_mul; |
||
499 | act_roll=(axis[rel_axis_roll])*roll_mul; |
||
500 | act_gier=(axis[rel_axis_gier])*gier_mul; |
||
501 | act_gas=(axis[rel_axis_gas]*-1+33000)*gas_mul; |
||
502 | |||
503 | break; |
||
504 | } |
||
505 | |||
506 | // act values clipping to usefull vals |
||
507 | // act_gas=0; |
||
508 | |||
509 | // act_gas=255; |
||
510 | |||
511 | |||
127 | ligi | 512 | /* |
130 | ligi | 513 | switch (act_mode) |
50 | ligi | 514 | { |
515 | case 0: |
||
117 | ligi | 516 | |
517 | |||
130 | ligi | 518 | act_nick=(axis[AXIS_NICK])*(INVERT_NICK); |
519 | act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL); |
||
520 | act_gier=(axis[AXIS_GIER])*(INVERT_GIER); |
||
521 | act_gas=((axis[AXIS_GAS])-128)*(-1); |
||
117 | ligi | 522 | |
130 | ligi | 523 | // clip gas |
524 | if (act_gas<0) act_gas=0; |
||
50 | ligi | 525 | |
130 | ligi | 526 | if (act_gas>250) act_gas=250; |
117 | ligi | 527 | |
130 | ligi | 528 | //////// act_gas=0; |
529 | break; |
||
50 | ligi | 530 | |
531 | case 1: |
||
130 | ligi | 532 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
533 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
||
534 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
||
535 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
||
50 | ligi | 536 | |
130 | ligi | 537 | break; |
50 | ligi | 538 | |
539 | case 2: |
||
130 | ligi | 540 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
541 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
||
542 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
||
543 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
||
50 | ligi | 544 | |
545 | |||
130 | ligi | 546 | break; |
50 | ligi | 547 | |
548 | } |
||
127 | ligi | 549 | */ |
48 | ligi | 550 | ExternControl.Digital[0]=0; |
551 | ExternControl.Digital[1]=0; |
||
552 | ExternControl.RemoteTasten=0; |
||
505 | ligi | 553 | ExternControl.Higt=act_alt; |
130 | ligi | 554 | ExternControl.free=0; |
555 | ExternControl.Frame='t'; |
||
556 | ExternControl.Config=1; |
||
557 | |||
558 | |||
50 | ligi | 559 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
117 | ligi | 560 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
561 | ExternControl.Gier=act_gier; // ************ |
||
562 | ExternControl.Gas=act_gas; // ************ |
||
483 | ligi | 563 | ExternControl.Gas=255; // ************ |
50 | ligi | 564 | |
130 | ligi | 565 | |
48 | ligi | 566 | |
505 | ligi | 567 | printf("act_mode %d , act_nick %d , act_roll %d , act_gier %d , act_gas %d , act_alt %d",act_mode , act_nick , act_roll , act_gier , act_gas,act_alt); |
140 | ligi | 568 | |
127 | ligi | 569 | if (connected) |
570 | { |
||
140 | ligi | 571 | complete_matches++; |
127 | ligi | 572 | printf("sending data\n"); |
573 | |||
574 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
||
505 | ligi | 575 | // gettimeofday(&time_struct1,NULL); |
127 | ligi | 576 | printf("sent data\n"); |
577 | } |
||
48 | ligi | 578 | |
130 | ligi | 579 | // printf("sleeping\n"); |
580 | // for (polls=0;polls<100;polls++) // FIXME - better Polling |
||
581 | // printf("end_sleep\n"); |
||
127 | ligi | 582 | |
130 | ligi | 583 | // int v=axis[6]/655+50; |
584 | // if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
||
585 | // v_old=v; |
||
47 | ligi | 586 | |
130 | ligi | 587 | // printf("v: %d \n",v); |
127 | ligi | 588 | |
589 | |||
130 | ligi | 590 | /* |
591 | for (i=0;i<num_of_axis;i++) |
||
47 | ligi | 592 | printf("A%d: %d ", i,axis[i]>>8 ); |
593 | |||
130 | ligi | 594 | for( x=0 ; x<num_of_buttons ; ++x ) |
47 | ligi | 595 | |
596 | printf("B%d: %d ", x, button[x] ); |
||
130 | ligi | 597 | */ |
598 | |||
47 | ligi | 599 | break; |
600 | } |
||
127 | ligi | 601 | |
48 | ligi | 602 | printf("\n"); |
47 | ligi | 603 | fflush(stdout); |
130 | ligi | 604 | printf("loop fin ( confirmed:%d misses:%d | debug_sets:%d )\n",complete_matches,complete_misses,debug_sets); |
140 | ligi | 605 | printf("------------------------------------------------------------------------\n"); |
505 | ligi | 606 | |
607 | gettimeofday(&loop_end_time,NULL); |
||
608 | last_trip_time=(unsigned long)(loop_end_time.tv_usec-loop_start_time.tv_usec)+(unsigned long)(loop_end_time.tv_sec-loop_start_time.tv_sec)*1000000; |
||
609 | printf("last trip: %d\n",last_trip_time); |
||
610 | |||
611 | |||
50 | ligi | 612 | } |
41 | ligi | 613 | |
43 | ligi | 614 | |
47 | ligi | 615 | /******************** Cleanup **********************/ |
140 | ligi | 616 | close(joy_input_fd); |
127 | ligi | 617 | close(mk_socket); |
41 | ligi | 618 | |
619 | if (x52_output) x52_close(x52_output); |
||
620 | return 0; |
||
621 | } |