From 3f99acd3d565b25b281c27fea13aa4c7adb00019 Mon Sep 17 00:00:00 2001 From: "mat.lau@laposte.net" Date: Mon, 19 Sep 2011 21:00:09 +0000 Subject: [PATCH] issue 68 --- sixaxis-emu/calibration.c | 46 +++++++------ sixaxis-emu/calibration.h | 3 +- sixaxis-emu/config.c | 127 ++++++++++++++++++++++++------------ sixaxis-emu/config.h | 33 ++++++---- sixaxis-emu/config_reader.c | 26 +++++++- sixaxis-emu/sdl_tools.c | 34 +++++++--- sixaxis-emu/sdl_tools.h | 16 +++-- 7 files changed, 194 insertions(+), 91 deletions(-) diff --git a/sixaxis-emu/calibration.c b/sixaxis-emu/calibration.c index 1b8e0f6..dbf3838 100644 --- a/sixaxis-emu/calibration.c +++ b/sixaxis-emu/calibration.c @@ -17,6 +17,7 @@ #define DEFAULT_MULTIPLIER_STEP 0.01 #define EXPONENT_STEP 0.01 +#define DURATION 1000000 //1s extern int refresh; extern int mean_axis_value; @@ -43,14 +44,19 @@ static int test_time = 1000; */ s_mouse_cal mouse_cal[MAX_DEVICES][MAX_CONFIGURATIONS] = {}; -#define DURATION 1000000 //1s +int mouse_controller[MAX_DEVICES]; + +inline int cal_get_controller(int controller) +{ + return mouse_controller[controller]; +} void cal_init() { memset(mouse_cal, 0x00, sizeof(mouse_cal)); } -s_mouse_cal* cal_get_mouse(int mouse, int conf) +inline s_mouse_cal* cal_get_mouse(int mouse, int conf) { return &(mouse_cal[mouse][conf]); } @@ -368,8 +374,8 @@ void cal_key(int device_id, int sym, int down) { printf("calibrating dead zone x\n"); current_cal = DZX; - mc->merge_x[mc->merge_x_index] = 1; - mc->merge_y[mc->merge_y_index] = 0; + mc->merge_x[mc->index] = 1; + mc->merge_y[mc->index] = 0; mc->change = 1; } } @@ -381,8 +387,8 @@ void cal_key(int device_id, int sym, int down) { printf("calibrating dead zone y\n"); current_cal = DZY; - mc->merge_x[mc->merge_x_index] = 0; - mc->merge_y[mc->merge_y_index] = 1; + mc->merge_x[mc->index] = 0; + mc->merge_y[mc->index] = 1; mc->change = 1; } } @@ -394,8 +400,8 @@ void cal_key(int device_id, int sym, int down) { printf("calibrating dead zone shape\n"); current_cal = DZS; - mc->merge_x[mc->merge_x_index] = 1; - mc->merge_y[mc->merge_y_index] = 1; + mc->merge_x[mc->index] = 1; + mc->merge_y[mc->index] = 1; mc->change = 1; } } @@ -525,8 +531,8 @@ void cal_button(int which, int button) { *mcal->dzx = mean_axis_value; } - mc->merge_x[mc->merge_x_index] = 1; - mc->merge_y[mc->merge_y_index] = 0; + mc->merge_x[mc->index] = 1; + mc->merge_y[mc->index] = 0; mc->change = 1; } break; @@ -538,8 +544,8 @@ void cal_button(int which, int button) { *mcal->dzy = mean_axis_value; } - mc->merge_x[mc->merge_x_index] = 0; - mc->merge_y[mc->merge_y_index] = 1; + mc->merge_x[mc->index] = 0; + mc->merge_y[mc->index] = 1; mc->change = 1; } break; @@ -554,8 +560,8 @@ void cal_button(int which, int button) { *mcal->dzs = E_SHAPE_CIRCLE; } - mc->merge_x[mc->merge_x_index] = 1; - mc->merge_y[mc->merge_y_index] = 1; + mc->merge_x[mc->index] = 1; + mc->merge_y[mc->index] = 1; mc->change = 1; } break; @@ -620,8 +626,8 @@ void cal_button(int which, int button) { *mcal->dzx = 0; } - mc->merge_x[mc->merge_x_index] = -1; - mc->merge_y[mc->merge_y_index] = 0; + mc->merge_x[mc->index] = -1; + mc->merge_y[mc->index] = 0; mc->change = 1; } break; @@ -633,8 +639,8 @@ void cal_button(int which, int button) { *mcal->dzy = 0; } - mc->merge_x[mc->merge_x_index] = 0; - mc->merge_y[mc->merge_y_index] = -1; + mc->merge_x[mc->index] = 0; + mc->merge_y[mc->index] = -1; mc->change = 1; } break; @@ -649,8 +655,8 @@ void cal_button(int which, int button) { *mcal->dzs = E_SHAPE_CIRCLE; } - mc->merge_x[mc->merge_x_index] = -1; - mc->merge_y[mc->merge_y_index] = -1; + mc->merge_x[mc->index] = -1; + mc->merge_y[mc->index] = -1; mc->change = 1; } break; diff --git a/sixaxis-emu/calibration.h b/sixaxis-emu/calibration.h index b69b6dc..d3e3d84 100644 --- a/sixaxis-emu/calibration.h +++ b/sixaxis-emu/calibration.h @@ -10,8 +10,9 @@ void cal_button(int, int); void cal_key(int, int, int); -s_mouse_cal* cal_get_mouse(int, int); +inline s_mouse_cal* cal_get_mouse(int, int); int cal_skip_event(SDL_Event*); void cal_init(); +inline int cal_get_controller(int); #endif /* CALIBRATION_H_ */ diff --git a/sixaxis-emu/config.c b/sixaxis-emu/config.c index 496f84b..d946c42 100644 --- a/sixaxis-emu/config.c +++ b/sixaxis-emu/config.c @@ -9,17 +9,14 @@ #include #include #include "sdl_tools.h" +#include "calibration.h" extern struct sixaxis_state state[MAX_CONTROLLERS]; extern s_controller controller[MAX_CONTROLLERS]; extern int display; -extern int joystickNbButton[255]; -extern int joystickSixaxis[MAX_DEVICES]; - extern int current_mouse; extern e_current_cal current_cal; -extern s_mouse_cal mouse_cal[MAX_DEVICES][MAX_CONFIGURATIONS]; extern double axis_scale; extern double frequency_scale; @@ -48,73 +45,73 @@ static int previous_config[MAX_CONTROLLERS]; /* * This lists config triggers for all controllers. */ -s_trigger triggers[MAX_CONTROLLERS][MAX_CONFIGURATIONS]; +static s_trigger triggers[MAX_CONTROLLERS][MAX_CONFIGURATIONS]; /* * This lists controller stick intensity modifiers. */ -s_intensity left_intensity[MAX_CONTROLLERS][MAX_CONFIGURATIONS]; -s_intensity right_intensity[MAX_CONTROLLERS][MAX_CONFIGURATIONS]; +static s_intensity left_intensity[MAX_CONTROLLERS][MAX_CONFIGURATIONS]; +static s_intensity right_intensity[MAX_CONTROLLERS][MAX_CONFIGURATIONS]; /* * This lists controls of each controller configuration for all keyboards. */ -s_mapper* keyboard_buttons[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; +static s_mapper* keyboard_buttons[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; /* * This lists controls of each controller configuration for all mice. */ -s_mapper* mouse_buttons[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; +static s_mapper* mouse_buttons[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; -s_mapper* mouse_axes[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; +static s_mapper* mouse_axes[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; /* * Used to tweak mouse controls. */ -s_mouse_control mouse_control[MAX_DEVICES] = {}; +static s_mouse_control mouse_control[MAX_DEVICES] = {}; /* * This lists controls of each controller configuration for all joysticks. */ -s_mapper* joystick_buttons[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; -s_mapper* joystick_axes[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; +static s_mapper* joystick_buttons[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; +static s_mapper* joystick_axes[MAX_DEVICES][MAX_CONTROLLERS][MAX_CONFIGURATIONS]; -s_mapper** cfg_get_joystick_axes(int device, int controller, int config) +inline s_mapper** cfg_get_joystick_axes(int device, int controller, int config) { return &(joystick_axes[device][controller][config]); } -s_mapper** cfg_get_joystick_buttons(int device, int controller, int config) +inline s_mapper** cfg_get_joystick_buttons(int device, int controller, int config) { return &(joystick_buttons[device][controller][config]); } -s_mapper** cfg_get_mouse_axes(int device, int controller, int config) +inline s_mapper** cfg_get_mouse_axes(int device, int controller, int config) { return &(mouse_axes[device][controller][config]); } -s_mapper** cfg_get_mouse_buttons(int device, int controller, int config) +inline s_mapper** cfg_get_mouse_buttons(int device, int controller, int config) { return &(mouse_buttons[device][controller][config]); } -s_mapper** cfg_get_keyboard_buttons(int device, int controller, int config) +inline s_mapper** cfg_get_keyboard_buttons(int device, int controller, int config) { return &(keyboard_buttons[device][controller][config]); } -s_trigger* cfg_get_trigger(int controller, int config) +inline s_trigger* cfg_get_trigger(int controller, int config) { return &(triggers[controller][config]); } -s_intensity* cfg_get_left_intensity(int controller, int config) +inline s_intensity* cfg_get_left_intensity(int controller, int config) { return &(left_intensity[controller][config]); } -s_intensity* cfg_get_right_intensity(int controller, int config) +inline s_intensity* cfg_get_right_intensity(int controller, int config) { return &(right_intensity[controller][config]); } @@ -137,7 +134,7 @@ int cfg_is_joystick_used(int id) return used; } -s_mouse_control* cfg_get_mouse_control(int id) +inline s_mouse_control* cfg_get_mouse_control(int id) { if(id >= 0) { @@ -151,16 +148,22 @@ void cfg_process_motion_event(SDL_Event* event) s_mouse_control* mc = cfg_get_mouse_control(sdl_get_device_id(event)); if(mc) { - mc->merge_x[mc->merge_x_index] += event->motion.xrel; - mc->merge_y[mc->merge_y_index] += event->motion.yrel; + mc->merge_x[mc->index] += event->motion.xrel; + mc->merge_y[mc->index] += event->motion.yrel; mc->change = 1; } } +#define MOTION_NB 1 +#define RATIO 1 +int weight; +int divider; + void cfg_process_motion() { - int i; + int i, j, k; s_mouse_control* mc; + s_mouse_cal* mcal; SDL_Event mouse_evt = { }; /* * Process a single (merged) motion event for each mouse. @@ -168,6 +171,7 @@ void cfg_process_motion() for (i = 0; i < MAX_DEVICES; ++i) { mc = cfg_get_mouse_control(i); + mcal = cal_get_mouse(i, current_config[cal_get_controller(i)]); if (mc->changed || mc->change) { if (subpos) @@ -175,8 +179,8 @@ void cfg_process_motion() /* * Add the residual motion vector from the last iteration. */ - mc->merge_x[mc->merge_x_index++] += mc->residue_x; - mc->merge_y[mc->merge_y_index++] += mc->residue_y; + mc->merge_x[mc->index] += mc->residue_x; + mc->merge_y[mc->index] += mc->residue_y; /* * If no motion was received this iteration, the residual motion vector from the last iteration is reset. */ @@ -186,12 +190,53 @@ void cfg_process_motion() mc->residue_y = 0; } } + + if(mcal->bsx) + { + mc->x = 0; + weight = 1; + divider = 0; + for(j=0; j<*mcal->bsx; ++j) + { + k = mc->index - j; + if (k < 0) + { + k += MAX_BUFFERSIZE; + } + mc->x += (mc->merge_x[k]*weight); + divider += weight; + weight *= *mcal->fix; + } + mc->x /= divider; + } + + if(mcal->bsy) + { + mc->y = 0; + weight = 1; + divider = 0; + for(j=0; j<*mcal->bsy; ++j) + { + k = mc->index - j; + if (k < 0) + { + k += MAX_BUFFERSIZE; + } + mc->y += (mc->merge_y[k]*weight); + divider += weight; + weight *= *mcal->fiy; + } + mc->y /= divider; + } + mouse_evt.motion.which = i; mouse_evt.type = SDL_MOUSEMOTION; cfg_process_event(&mouse_evt); } - mc->merge_x[mc->merge_x_index] = 0; - mc->merge_y[mc->merge_y_index] = 0; + mc->index++; + mc->index %= MAX_BUFFERSIZE; + mc->merge_x[mc->index] = 0; + mc->merge_y[mc->index] = 0; mc->changed = mc->change; mc->change = 0; if (i == current_mouse && (current_cal == DZX || current_cal == DZY || current_cal == DZS)) @@ -665,6 +710,7 @@ void cfg_process_event(SDL_Event* event) double my; double residue; s_mouse_control* mc; + int nb_buttons; /* * 'which' should always be at that place @@ -682,52 +728,53 @@ void cfg_process_event(SDL_Event* event) { case SDL_JOYHATMOTION: event_jb.jbutton.which = event->jhat.which; + nb_buttons = sdl_get_joystick_buttons(event->jhat.which); if(event->jhat.value & SDL_HAT_UP) { event_jb.jbutton.type = SDL_JOYBUTTONDOWN; - event_jb.jbutton.button=joystickNbButton[event->jhat.which]+4*event->jhat.hat; + event_jb.jbutton.button=nb_buttons+4*event->jhat.hat; cfg_process_event(&event_jb); } else { event_jb.jbutton.type = SDL_JOYBUTTONUP; - event_jb.jbutton.button=joystickNbButton[event->jhat.which]+4*event->jhat.hat; + event_jb.jbutton.button=nb_buttons+4*event->jhat.hat; cfg_process_event(&event_jb); } if(event->jhat.value & SDL_HAT_RIGHT) { event_jb.jbutton.type = SDL_JOYBUTTONDOWN; - event_jb.jbutton.button=joystickNbButton[event->jhat.which]+4*event->jhat.hat+1; + event_jb.jbutton.button=nb_buttons+4*event->jhat.hat+1; cfg_process_event(&event_jb); } else { event_jb.jbutton.type = SDL_JOYBUTTONUP; - event_jb.jbutton.button=joystickNbButton[event->jhat.which]+4*event->jhat.hat+1; + event_jb.jbutton.button=nb_buttons+4*event->jhat.hat+1; cfg_process_event(&event_jb); } if(event->jhat.value & SDL_HAT_DOWN) { event_jb.jbutton.type = SDL_JOYBUTTONDOWN; - event_jb.jbutton.button=joystickNbButton[event->jhat.which]+4*event->jhat.hat+2; + event_jb.jbutton.button=nb_buttons+4*event->jhat.hat+2; cfg_process_event(&event_jb); } else { event_jb.jbutton.type = SDL_JOYBUTTONUP; - event_jb.jbutton.button=joystickNbButton[event->jhat.which]+4*event->jhat.hat+2; + event_jb.jbutton.button=nb_buttons+4*event->jhat.hat+2; cfg_process_event(&event_jb); } if(event->jhat.value & SDL_HAT_LEFT) { event_jb.jbutton.type = SDL_JOYBUTTONDOWN; - event_jb.jbutton.button=joystickNbButton[event->jhat.which]+4*event->jhat.hat+3; + event_jb.jbutton.button=nb_buttons+4*event->jhat.hat+3; cfg_process_event(&event_jb); } else { event_jb.jbutton.type = SDL_JOYBUTTONUP; - event_jb.jbutton.button=joystickNbButton[event->jhat.which]+4*event->jhat.hat+3; + event_jb.jbutton.button=nb_buttons+4*event->jhat.hat+3; cfg_process_event(&event_jb); } break; @@ -739,7 +786,7 @@ void cfg_process_event(SDL_Event* event) } break; case SDL_JOYAXISMOTION: - if(joystickSixaxis[device] && event->jaxis.axis > 3) + if(sdl_is_sixaxis(device) && event->jaxis.axis > 3) { event->jaxis.value = (event->jaxis.value + 32767) / 2; } @@ -1117,8 +1164,8 @@ void cfg_process_event(SDL_Event* event) mc = mouse_control + device; if(mc->change) { - mx = mc->merge_x[mc->merge_x_index]; - my = mc->merge_y[mc->merge_y_index]; + mx = mc->x; + my = mc->y; } else { diff --git a/sixaxis-emu/config.h b/sixaxis-emu/config.h index 7f63036..b52c8fa 100644 --- a/sixaxis-emu/config.h +++ b/sixaxis-emu/config.h @@ -49,6 +49,8 @@ #define X_ATTR_MULTIPLIER "multiplier" #define X_ATTR_EXPONENT "exponent" #define X_ATTR_SHAPE "shape" +#define X_ATTR_BUFFERSIZE "buffer_size" +#define X_ATTR_FILTER "filter" #define X_ATTR_SWITCH_BACK "switch_back" #define X_ATTR_DELAY "delay" #define X_ATTR_STEPS "steps" @@ -111,8 +113,9 @@ typedef struct int changed; double merge_x[MAX_BUFFERSIZE]; double merge_y[MAX_BUFFERSIZE]; - int merge_x_index; - int merge_y_index; + int index; + double x; + double y; double residue_x; double residue_y; int postpone_wheel_up; @@ -131,6 +134,10 @@ typedef struct int* dzx; int* dzy; e_shape* dzs; + unsigned int* bsx; + double* fix; + unsigned int* bsy; + double* fiy; int dpi; }s_mouse_cal; @@ -138,7 +145,7 @@ typedef struct { int change; int send_command; - int ts_axis[TS_MAX][TS_AXIS_MAX][2]; + int ts_axis[TS_MAX][TS_AXIS_MAX][2]; //issue 15 } s_controller; typedef struct @@ -152,6 +159,8 @@ typedef struct double exponent; e_shape shape; int dead_zone; + unsigned int buffer_size; + double filter; int controller_button; int controller_button_axis; @@ -187,17 +196,17 @@ void cfg_trigger_lookup(SDL_Event*); void cfg_config_activation(); void cfg_intensity_lookup(SDL_Event*); void cfg_process_event(SDL_Event*); -s_mouse_control* cfg_get_mouse_control(int); +inline s_mouse_control* cfg_get_mouse_control(int); int cfg_is_joystick_used(int); void cfg_process_motion_event(SDL_Event*); void cfg_process_motion(); -s_trigger* cfg_get_trigger(int, int); -s_intensity* cfg_get_left_intensity(int, int); -s_intensity* cfg_get_right_intensity(int, int); -s_mapper** cfg_get_joystick_axes(int, int, int); -s_mapper** cfg_get_joystick_buttons(int, int, int); -s_mapper** cfg_get_mouse_axes(int, int, int); -s_mapper** cfg_get_mouse_buttons(int, int, int); -s_mapper** cfg_get_keyboard_buttons(int, int, int); +inline s_trigger* cfg_get_trigger(int, int); +inline s_intensity* cfg_get_left_intensity(int, int); +inline s_intensity* cfg_get_right_intensity(int, int); +inline s_mapper** cfg_get_joystick_axes(int, int, int); +inline s_mapper** cfg_get_joystick_buttons(int, int, int); +inline s_mapper** cfg_get_mouse_axes(int, int, int); +inline s_mapper** cfg_get_mouse_buttons(int, int, int); +inline s_mapper** cfg_get_keyboard_buttons(int, int, int); #endif /* CONFIG_H_ */ diff --git a/sixaxis-emu/config_reader.c b/sixaxis-emu/config_reader.c index 8cc319d..027abd5 100644 --- a/sixaxis-emu/config_reader.c +++ b/sixaxis-emu/config_reader.c @@ -42,7 +42,9 @@ static e_shape r_shape; static e_device_type r_device_type; static int r_device_id; static char r_device_name[128]; -static int r_config_dpi[MAX_CONTROLLERS]; +static unsigned int r_config_dpi[MAX_CONTROLLERS]; +static unsigned int r_buffer_size; +static double r_filter; /* * Get the device name and store it into r_device_name. @@ -343,6 +345,10 @@ static int ProcessEventElement(xmlNode * a_node) } } xmlFree(shape); + r_buffer_size = 1;//default value + GetUnsignedIntProp(a_node, X_ATTR_BUFFERSIZE, &r_buffer_size); + r_filter = 0;//default value + GetDoubleProp(a_node, X_ATTR_FILTER, &r_filter); } else if (!strncmp(type, X_ATTR_VALUE_AXIS_DOWN, strlen(X_ATTR_VALUE_AXIS_DOWN))) { @@ -525,6 +531,8 @@ static int ProcessAxisElement(xmlNode * a_node) p_mapper->multiplier = r_multiplier; p_mapper->exponent = r_exponent; p_mapper->shape = r_shape; + p_mapper->buffer_size = r_buffer_size; + p_mapper->filter = r_filter; break; default: break; @@ -1008,7 +1016,7 @@ static int ProcessControllerElement(xmlNode * a_node) if(ret != -1) { /* optional */ - GetIntProp(a_node, X_ATTR_DPI, r_config_dpi+r_controller_id); + GetUnsignedIntProp(a_node, X_ATTR_DPI, r_config_dpi+r_controller_id); } for (cur_node = a_node->children; cur_node && ret != -1; cur_node = cur_node->next) @@ -1113,6 +1121,8 @@ static int read_file(char* file_path) return ret; } +extern int mouse_controller[MAX_DEVICES]; + extern int current_mouse; static void read_calibration() @@ -1121,12 +1131,14 @@ static void read_calibration() s_mapper** pp_mapper; s_mapper* p_mapper; s_mouse_cal* mcal; + int found; current_mouse = -1; for(i=0; iaxis == 0) { + found = 1; + mouse_controller[i] = j; mcal->mx = &p_mapper->multiplier; mcal->ex = &p_mapper->exponent; mcal->dzx = &p_mapper->dead_zone; mcal->dzs = &p_mapper->shape; mcal->rd = DEFAULT_RADIUS; mcal->dpi = r_config_dpi[j]; + mcal->bsx = &p_mapper->buffer_size; + mcal->fix = &p_mapper->filter; } else { + found = 1; + mouse_controller[i] = j; mcal->my = &p_mapper->multiplier; mcal->ey = &p_mapper->exponent; mcal->dzy = &p_mapper->dead_zone; + mcal->bsy = &p_mapper->buffer_size; + mcal->fiy = &p_mapper->filter; } } } diff --git a/sixaxis-emu/sdl_tools.c b/sixaxis-emu/sdl_tools.c index b2f895c..a8f54e0 100644 --- a/sixaxis-emu/sdl_tools.c +++ b/sixaxis-emu/sdl_tools.c @@ -146,7 +146,7 @@ int sdl_initialize() */ void sdl_release_unused() { - int i, j, k; + int i; int none = 1; for(i=0; i= 0) { @@ -248,7 +248,7 @@ char* sdl_get_mouse_name(int id) return NULL; } -char* sdl_get_keyboard_name(int id) +inline char* sdl_get_keyboard_name(int id) { if(id >= 0) { @@ -257,7 +257,7 @@ char* sdl_get_keyboard_name(int id) return NULL; } -char* sdl_get_joystick_name(int id) +inline char* sdl_get_joystick_name(int id) { if(id >= 0) { @@ -266,7 +266,7 @@ char* sdl_get_joystick_name(int id) return NULL; } -int sdl_get_joystick_virtual_id(int id) +inline int sdl_get_joystick_virtual_id(int id) { if(id >= 0) { @@ -275,7 +275,7 @@ int sdl_get_joystick_virtual_id(int id) return 0; } -int sdl_get_mouse_virtual_id(int id) +inline int sdl_get_mouse_virtual_id(int id) { if(id >= 0) { @@ -284,7 +284,7 @@ int sdl_get_mouse_virtual_id(int id) return 0; } -int sdl_get_keyboard_virtual_id(int id) +inline int sdl_get_keyboard_virtual_id(int id) { if(id >= 0) { @@ -293,10 +293,28 @@ int sdl_get_keyboard_virtual_id(int id) return 0; } +inline int sdl_get_joystick_buttons(int id) +{ + if(id >= 0) + { + return joystickNbButton[id]; + } + return 0; +} + +inline int sdl_is_sixaxis(int id) +{ + if(id >= 0) + { + return joystickSixaxis[id]; + } + return 0; +} + /* * Returns the device id of a given event. */ -int sdl_get_device_id(SDL_Event* e) +inline int sdl_get_device_id(SDL_Event* e) { unsigned int device_id = ((SDL_KeyboardEvent*)e)->which; diff --git a/sixaxis-emu/sdl_tools.h b/sixaxis-emu/sdl_tools.h index 69d7ade..ca3ed2c 100644 --- a/sixaxis-emu/sdl_tools.h +++ b/sixaxis-emu/sdl_tools.h @@ -17,12 +17,14 @@ void sdl_release_unused(); void sdl_quit(); void sdl_free_mk(); -char* sdl_get_mouse_name(int); -char* sdl_get_keyboard_name(int); -int sdl_get_mouse_virtual_id(int); -int sdl_get_keyboard_virtual_id(int); -int sdl_get_device_id(SDL_Event*); -char* sdl_get_joystick_name(int); -int sdl_get_joystick_virtual_id(int); +inline char* sdl_get_mouse_name(int); +inline char* sdl_get_keyboard_name(int); +inline int sdl_get_mouse_virtual_id(int); +inline int sdl_get_keyboard_virtual_id(int); +inline int sdl_get_device_id(SDL_Event*); +inline char* sdl_get_joystick_name(int); +inline int sdl_get_joystick_virtual_id(int); +inline int sdl_get_joystick_buttons(int); +int sdl_is_sixaxis(int); #endif /* SDL_TOOLS_H_ */