12,20 → 12,9 |
#include "riddim.h" |
|
|
|
int state=STATEID_SCANNING; |
|
|
|
|
|
|
|
|
|
int x52_input_fd, num_of_axis=0, num_of_buttons=0; |
char *button_trigger=NULL, name_of_joystick[80]; |
|
struct js_event x52_event_struct; |
|
int engines_on=0; |
34,16 → 23,10 |
int *axis; |
char *button; |
|
|
|
struct x52 *x52_output; |
|
int selected_bt_device=0; |
|
//int evdev_fd; |
//int evdev_out_fd; |
|
|
void write_display(int line,char* text) |
{ |
if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
135,31 → 118,32 |
|
// todo reenable bluetooth connection |
|
if ((input_evdev_name)) |
{ |
printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
|
/* |
printf("\nInitializing X-52 input ..\n"); |
if (connect_joy()) |
if (connect_evdev(input_evdev_name)) |
{ |
printf(".. done");// |
input=INPUT_JOYDEV; |
input=INPUT_EVDEV; |
} |
else |
printf(".. ERROR ");// |
*/ |
} |
|
if (input_evdev_name) |
if (input_joydev_name) |
{ |
printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
|
if (connect_evdev(input_evdev_name)) |
printf("\nInitializing joystick input from %s ..\n",input_joydev_name); |
if (connect_joy()) |
{ |
printf(".. done");// |
input=INPUT_EVDEV; |
input=INPUT_JOYDEV; |
} |
else |
printf(".. ERROR ");// |
} |
|
|
printf("\nInitializing X-52 output .."); |
|
x52_output = x52_init(); |
217,24 → 201,22 |
|
|
case INPUT_NONE: |
printf("starting input none\n"); |
printf("processing input none\n"); |
break; |
|
case INPUT_EVDEV: |
printf("input evdev\n"); |
|
|
printf("processing input evdev\n"); |
poll_evdev(); |
|
break; |
|
case INPUT_JOYDEV: |
printf("input joydev\n"); |
printf("processing input joydev\n"); |
// poll values from input device |
|
for (polls=0;polls<100;polls++) // FIXME - better Polling |
{ |
read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
read(joy_input_fd, &x52_event_struct, sizeof(struct js_event)); |
|
|
/* see what to do with the event */ |
257,14 → 239,12 |
if (button_trigger[x]<100)button_trigger[x]++; |
} |
break; |
} |
} // switch (input) |
|
printf("input done\n"); |
|
switch(state) |
{ |
|
|
case STATEID_SCANNING: |
|
state=STATEID_CONNECTING; |
316,7 → 296,7 |
|
|
confirm_misses=0; |
printf("connected:%d",connected); |
|
RxBuffer[1]=0; |
if (connected) |
|
335,8 → 315,6 |
printf("waiting for confirm frame ( confirmed:%d misses:%d )\n",complete_matches,complete_misses); |
RxBuffer[2]=0; |
|
|
|
// r=0; |
|
// new |
360,7 → 338,7 |
|
gettimeofday(&time_struct2,NULL); |
|
printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec)); |
printf("last trip: %d\n",(int)(time_struct2.tv_usec-time_struct1.tv_usec)); |
// act_mode=button[24] | (button[25]<<1); |
|
|
367,13 → 345,38 |
|
// Step converting axis data to nick/roll/gier/gas/.. |
|
act_nick=evdev_rel_axis[rel_axis_nick]*nick_mul; |
act_roll=evdev_rel_axis[rel_axis_roll]*roll_mul; |
act_gier=evdev_rel_axis[rel_axis_gier]*gier_mul; |
act_gas=evdev_rel_axis[rel_axis_gas]*gas_mul; |
act_gas=255; |
// act_nick=(evdev_rel_axis[rel_axis_nick]-128)*nick_mul; |
|
|
|
|
switch(input) |
{ |
case INPUT_EVDEV: |
|
act_nick=(evdev_rel_axis[rel_axis_nick]-nick_add)*nick_mul; |
act_roll=(evdev_rel_axis[rel_axis_roll]-nick_add)*roll_mul; |
act_gier=(evdev_rel_axis[rel_axis_gier]-nick_add)*gier_mul; |
act_gas=(evdev_rel_axis[rel_axis_gas]-nick_add)*gas_mul; |
|
|
break; |
|
case INPUT_JOYDEV: |
act_nick=(axis[rel_axis_nick])*nick_mul; |
act_roll=(axis[rel_axis_roll])*roll_mul; |
act_gier=(axis[rel_axis_gier])*gier_mul; |
act_gas=(axis[rel_axis_gas]*-1+33000)*gas_mul; |
|
break; |
} |
|
// act values clipping to usefull vals |
// act_gas=0; |
|
// act_gas=255; |
|
|
/* |
switch (act_mode) |
{ |
426,12 → 429,13 |
ExternControl.Gier=act_gier; // ************ |
ExternControl.Gas=act_gas; // ************ |
|
complete_matches++; |
|
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); |
|
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); |
|
if (connected) |
{ |
complete_matches++; |
printf("sending data\n"); |
|
SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
465,12 → 469,13 |
printf("\n"); |
fflush(stdout); |
printf("loop fin ( confirmed:%d misses:%d | debug_sets:%d )\n",complete_matches,complete_misses,debug_sets); |
printf("------------------------------------------------------------------------\n"); |
|
} |
|
|
/******************** Cleanup **********************/ |
close(x52_input_fd); |
close(joy_input_fd); |
close(mk_socket); |
|
if (x52_output) x52_close(x52_output); |