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