From 689cd6322fba69cebca7f95511349dfc4bada330 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 9 Sep 2014 18:15:17 +0200 Subject: [PATCH] Indenting / style nits --- input/android_input_joypad.c | 16 +- input/apple_joypad.c | 81 ++++-- input/dinput.c | 180 ++++++++----- input/gx_input.c | 29 ++- input/gx_input_joypad.c | 17 +- input/gx_input_sicksaxis.c | 443 +++++++++++++++++--------------- input/gx_input_sicksaxis.h | 20 +- input/input_common.c | 17 +- input/keyboard_line.h | 3 +- input/nullinput.c | 7 +- input/ps3_input_joypad.c | 24 +- input/psp_input.c | 6 +- input/psp_input_joypad.c | 24 +- input/qnx_input.c | 249 ++++++++++++------ input/qnx_input_joypad.c | 22 +- input/wiimote.c | 103 +++++--- input/wiimote.h | 4 +- input/winxinput_joypad.c | 67 +++-- input/x11_input.c | 26 +- input/xdk_xinput_input.c | 33 ++- input/xdk_xinput_input_joypad.c | 23 +- 21 files changed, 877 insertions(+), 517 deletions(-) diff --git a/input/android_input_joypad.c b/input/android_input_joypad.c index 089375d555..a00c6b9fef 100644 --- a/input/android_input_joypad.c +++ b/input/android_input_joypad.c @@ -64,13 +64,19 @@ static bool android_joypad_button(unsigned port_num, uint16_t joykey) unsigned h = GET_HAT(joykey); if (h > 0) return false; + switch (GET_HAT_DIR(joykey)) { - case HAT_LEFT_MASK: return android->hat_state[port_num][0] == -1; - case HAT_RIGHT_MASK: return android->hat_state[port_num][0] == 1; - case HAT_UP_MASK: return android->hat_state[port_num][1] == -1; - case HAT_DOWN_MASK: return android->hat_state[port_num][1] == 1; - default: return false; + case HAT_LEFT_MASK: + return android->hat_state[port_num][0] == -1; + case HAT_RIGHT_MASK: + return android->hat_state[port_num][0] == 1; + case HAT_UP_MASK: + return android->hat_state[port_num][1] == -1; + case HAT_DOWN_MASK: + return android->hat_state[port_num][1] == 1; + default: + return false; } } return joykey < LAST_KEYCODE && get_bit(android->pad_state[port_num], diff --git a/input/apple_joypad.c b/input/apple_joypad.c index 24c17c1243..ef085de9fd 100644 --- a/input/apple_joypad.c +++ b/input/apple_joypad.c @@ -35,24 +35,31 @@ struct apple_pad_connection static IOHIDManagerRef g_hid_manager; -static void apple_pad_send_control(struct apple_pad_connection* connection, uint8_t* data, size_t size) +static void apple_pad_send_control(struct apple_pad_connection* connection, + uint8_t* data, size_t size) { - IOHIDDeviceSetReport(connection->device, kIOHIDReportTypeOutput, 0x01, data + 1, size - 1); + IOHIDDeviceSetReport(connection->device, + kIOHIDReportTypeOutput, 0x01, data + 1, size - 1); } -// NOTE: I pieced this together through trial and error, any corrections are welcome -static void hid_device_input_callback(void* context, IOReturn result, void* sender, IOHIDValueRef value) +/* NOTE: I pieced this together through trial and error, + * any corrections are welcome. */ + +static void hid_device_input_callback(void* context, IOReturn result, + void* sender, IOHIDValueRef value) { IOHIDElementRef element; uint32_t type, page, use; - struct apple_pad_connection* connection = (struct apple_pad_connection*)context; + struct apple_pad_connection* connection = (struct apple_pad_connection*) + context; element = IOHIDValueGetElement(value); type = IOHIDElementGetType(element); page = IOHIDElementGetUsagePage(element); use = IOHIDElementGetUsage(element); - // Joystick handler: TODO: Can GamePad work the same? + /* Joystick handler. + * TODO: Can GamePad work the same? */ if (type == kIOHIDElementTypeInput_Button && page == kHIDPage_Button) { CFIndex state = IOHIDValueGetIntegerValue(value); @@ -79,7 +86,8 @@ static void hid_device_input_callback(void* context, IOReturn result, void* send state = IOHIDValueGetIntegerValue(value) - min; val = (float)state / (float)max; - g_current_input_data.pad_axis[connection->slot][i] = ((val * 2.0f) - 1.0f) * 32767.0f; + g_current_input_data.pad_axis[connection->slot][i] = + ((val * 2.0f) - 1.0f) * 32767.0f; } } } @@ -87,12 +95,14 @@ static void hid_device_input_callback(void* context, IOReturn result, void* send static void hid_device_removed(void* context, IOReturn result, void* sender) { - struct apple_pad_connection* connection = (struct apple_pad_connection*)context; + struct apple_pad_connection* connection = (struct apple_pad_connection*) + context; if (connection && connection->slot < MAX_PLAYERS) { g_current_input_data.pad_buttons[connection->slot] = 0; - memset(g_current_input_data.pad_axis[connection->slot], 0, sizeof(g_current_input_data.pad_axis)); + memset(g_current_input_data.pad_axis[connection->slot], + 0, sizeof(g_current_input_data.pad_axis)); apple_joypad_disconnect(connection->slot); free(connection); @@ -101,49 +111,63 @@ static void hid_device_removed(void* context, IOReturn result, void* sender) IOHIDDeviceClose(sender, kIOHIDOptionsTypeNone); } -static void hid_device_report(void* context, IOReturn result, void *sender, IOHIDReportType type, uint32_t reportID, uint8_t *report, CFIndex reportLength) +static void hid_device_report(void* context, IOReturn result, void *sender, + IOHIDReportType type, uint32_t reportID, uint8_t *report, + CFIndex reportLength) { - struct apple_pad_connection* connection = (struct apple_pad_connection*)context; + struct apple_pad_connection* connection = (struct apple_pad_connection*) + context; apple_joypad_packet(connection->slot, connection->data, reportLength + 1); } -static void hid_manager_device_attached(void* context, IOReturn result, void* sender, IOHIDDeviceRef device) +static void hid_manager_device_attached(void* context, IOReturn result, + void* sender, IOHIDDeviceRef device) { char device_name[1024]; CFStringRef device_name_ref; - struct apple_pad_connection* connection = (struct apple_pad_connection*)calloc(1, sizeof(*connection)); + struct apple_pad_connection* connection = (struct apple_pad_connection*) + calloc(1, sizeof(*connection)); connection->device = device; connection->slot = MAX_PLAYERS; IOHIDDeviceOpen(device, kIOHIDOptionsTypeNone); - IOHIDDeviceScheduleWithRunLoop(device, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); + IOHIDDeviceScheduleWithRunLoop(device, CFRunLoopGetCurrent(), + kCFRunLoopCommonModes); IOHIDDeviceRegisterRemovalCallback(device, hid_device_removed, connection); device_name_ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); - CFStringGetCString(device_name_ref, device_name, sizeof(device_name), kCFStringEncodingUTF8); + CFStringGetCString(device_name_ref, device_name, + sizeof(device_name), kCFStringEncodingUTF8); connection->slot = apple_joypad_connect(device_name, connection); if (apple_joypad_has_interface(connection->slot)) - IOHIDDeviceRegisterInputReportCallback(device, connection->data + 1, sizeof(connection->data) - 1, hid_device_report, connection); + IOHIDDeviceRegisterInputReportCallback(device, + connection->data + 1, sizeof(connection->data) - 1, + hid_device_report, connection); else - IOHIDDeviceRegisterInputValueCallback(device, hid_device_input_callback, connection); + IOHIDDeviceRegisterInputValueCallback(device, + hid_device_input_callback, connection); if (device_name[0] != '\0') { - strlcpy(g_settings.input.device_names[connection->slot], device_name, sizeof(g_settings.input.device_names)); - input_config_autoconfigure_joypad(connection->slot, device_name, apple_joypad.ident); + strlcpy(g_settings.input.device_names[connection->slot], + device_name, sizeof(g_settings.input.device_names)); + input_config_autoconfigure_joypad(connection->slot, + device_name, apple_joypad.ident); RARCH_LOG("Port %d: %s.\n", connection->slot, device_name); } } -static void append_matching_dictionary(CFMutableArrayRef array, uint32_t page, uint32_t use) +static void append_matching_dictionary(CFMutableArrayRef array, + uint32_t page, uint32_t use) { CFNumberRef pagen, usen; CFMutableDictionaryRef matcher; - matcher = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + matcher = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, + &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); pagen = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page); CFDictionarySetValue(matcher, CFSTR(kIOHIDDeviceUsagePageKey), pagen); @@ -188,7 +212,8 @@ static int32_t find_empty_slot(void) return -1; } -int32_t apple_joypad_connect(const char* name, struct apple_pad_connection* connection) +int32_t apple_joypad_connect(const char* name, + struct apple_pad_connection* connection) { int32_t slot; slot = find_empty_slot(); @@ -276,7 +301,8 @@ static bool apple_joypad_init(void) if (!g_hid_manager) { - g_hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); + g_hid_manager = IOHIDManagerCreate( + kCFAllocatorDefault, kIOHIDOptionsTypeNone); matcher = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); append_matching_dictionary(matcher, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick); @@ -316,7 +342,8 @@ static void apple_joypad_destroy(void) if (g_hid_manager) { IOHIDManagerClose(g_hid_manager, kIOHIDOptionsTypeNone); - IOHIDManagerUnscheduleFromRunLoop(g_hid_manager, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); + IOHIDManagerUnscheduleFromRunLoop(g_hid_manager, + CFRunLoopGetCurrent(), kCFRunLoopCommonModes); CFRelease(g_hid_manager); } @@ -333,7 +360,8 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey) if (GET_HAT_DIR(joykey)) return false; // Check the button - return (port < MAX_PLAYERS && joykey < 32) ? (g_current_input_data.pad_buttons[port] & (1 << joykey)) != 0 : false; + return (port < MAX_PLAYERS && joykey < 32) ? + (g_current_input_data.pad_buttons[port] & (1 << joykey)) != 0 : false; } static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis) @@ -363,7 +391,8 @@ static void apple_joypad_poll(void) { } -static bool apple_joypad_rumble(unsigned pad, enum retro_rumble_effect effect, uint16_t strength) +static bool apple_joypad_rumble(unsigned pad, + enum retro_rumble_effect effect, uint16_t strength) { if (pad < MAX_PLAYERS && slots[pad].used && slots[pad].iface && slots[pad].iface->set_rumble) diff --git a/input/dinput.c b/input/dinput.c index b19b43dba2..b1873bbdba 100644 --- a/input/dinput.c +++ b/input/dinput.c @@ -29,7 +29,7 @@ #include #include -// Context has to be global as joypads also ride on this context. +/* Context has to be global as joypads also ride on this context. */ static LPDIRECTINPUT8 g_ctx; struct pointer_status @@ -52,7 +52,7 @@ struct dinput_input int mouse_x; int mouse_y; bool mouse_l, mouse_r, mouse_m, mouse_wu, mouse_wd; - struct pointer_status pointer_head; // dummy head for easier iteration + struct pointer_status pointer_head; /* dummy head for easier iteration */ }; struct dinput_joypad @@ -81,7 +81,7 @@ static bool dinput_init_context(void) CoInitialize(NULL); - // Who said we shouldn't have same call signature in a COM API? <_< + /* Who said we shouldn't have same call signature in a COM API? <_< */ #ifdef __cplusplus if (FAILED(DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, @@ -165,10 +165,12 @@ static void dinput_poll(void *data) memset(di->state, 0, sizeof(di->state)); if (di->keyboard) { - if (FAILED(IDirectInputDevice8_GetDeviceState(di->keyboard, sizeof(di->state), di->state))) + if (FAILED(IDirectInputDevice8_GetDeviceState( + di->keyboard, sizeof(di->state), di->state))) { IDirectInputDevice8_Acquire(di->keyboard); - if (FAILED(IDirectInputDevice8_GetDeviceState(di->keyboard, sizeof(di->state), di->state))) + if (FAILED(IDirectInputDevice8_GetDeviceState( + di->keyboard, sizeof(di->state), di->state))) memset(di->state, 0, sizeof(di->state)); } } @@ -178,10 +180,12 @@ static void dinput_poll(void *data) DIMOUSESTATE2 mouse_state; memset(&mouse_state, 0, sizeof(mouse_state)); - if (FAILED(IDirectInputDevice8_GetDeviceState(di->mouse, sizeof(mouse_state), &mouse_state))) + if (FAILED(IDirectInputDevice8_GetDeviceState( + di->mouse, sizeof(mouse_state), &mouse_state))) { IDirectInputDevice8_Acquire(di->mouse); - if (FAILED(IDirectInputDevice8_GetDeviceState(di->mouse, sizeof(mouse_state), &mouse_state))) + if (FAILED(IDirectInputDevice8_GetDeviceState( + di->mouse, sizeof(mouse_state), &mouse_state))) memset(&mouse_state, 0, sizeof(mouse_state)); } @@ -193,7 +197,8 @@ static void dinput_poll(void *data) di->mouse_wu = mouse_state.rgbButtons[3]; di->mouse_wd = mouse_state.rgbButtons[4]; - // No simple way to get absolute coordinates for RETRO_DEVICE_POINTER. Just use Win32 APIs. + /* No simple way to get absolute coordinates + * for RETRO_DEVICE_POINTER. Just use Win32 APIs. */ POINT point = {0}; GetCursorPos(&point); ScreenToClient((HWND)driver.video_window, &point); @@ -214,14 +219,16 @@ static bool dinput_keyboard_pressed(struct dinput_input *di, unsigned key) return di->state[sym] & 0x80; } -static bool dinput_is_pressed(struct dinput_input *di, const struct retro_keybind *binds, +static bool dinput_is_pressed(struct dinput_input *di, + const struct retro_keybind *binds, unsigned port, unsigned id) { if (id >= RARCH_BIND_LIST_END) return false; const struct retro_keybind *bind = &binds[id]; - return dinput_keyboard_pressed(di, bind->key) || input_joypad_pressed(di->joypad, port, binds, id); + return dinput_keyboard_pressed(di, bind->key) || + input_joypad_pressed(di->joypad, port, binds, id); } static int16_t dinput_pressed_analog(struct dinput_input *di, @@ -237,14 +244,17 @@ static int16_t dinput_pressed_analog(struct dinput_input *di, if (!bind_minus->valid || !bind_plus->valid) return 0; - int16_t pressed_minus = dinput_keyboard_pressed(di, bind_minus->key) ? -0x7fff : 0; - int16_t pressed_plus = dinput_keyboard_pressed(di, bind_plus->key) ? 0x7fff : 0; + int16_t pressed_minus = + dinput_keyboard_pressed(di, bind_minus->key) ? -0x7fff : 0; + int16_t pressed_plus = + dinput_keyboard_pressed(di, bind_plus->key) ? 0x7fff : 0; return pressed_plus + pressed_minus; } static bool dinput_key_pressed(void *data, int key) { - return dinput_is_pressed((struct dinput_input*)data, g_settings.input.binds[0], 0, key); + return dinput_is_pressed((struct dinput_input*)data, + g_settings.input.binds[0], 0, key); } static int16_t dinput_lightgun_state(struct dinput_input *di, unsigned id) @@ -265,9 +275,9 @@ static int16_t dinput_lightgun_state(struct dinput_input *di, unsigned id) return di->mouse_m && di->mouse_r; case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: return di->mouse_m && di->mouse_l; - default: - return 0; } + + return 0; } static int16_t dinput_mouse_state(struct dinput_input *di, unsigned id) @@ -288,12 +298,13 @@ static int16_t dinput_mouse_state(struct dinput_input *di, unsigned id) return di->mouse_wd; case RETRO_DEVICE_ID_MOUSE_MIDDLE: return di->mouse_m; - default: - return 0; } + + return 0; } -static int16_t dinput_pointer_state(struct dinput_input *di, unsigned index, unsigned id, bool screen) +static int16_t dinput_pointer_state(struct dinput_input *di, + unsigned index, unsigned id, bool screen) { int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0; unsigned num = 0; @@ -303,7 +314,7 @@ static int16_t dinput_pointer_state(struct dinput_input *di, unsigned index, uns num++; check_pos = check_pos->next; } - if (!check_pos && index > 0) // index = 0 has mouse fallback + if (!check_pos && index > 0) /* index = 0 has mouse fallback. */ return 0; int x = check_pos ? check_pos->pointer_x : di->mouse_x; @@ -358,7 +369,8 @@ static int16_t dinput_input_state(void *data, case RETRO_DEVICE_ANALOG: ret = dinput_pressed_analog(di, binds[port], index, id); if (!ret) - ret = input_joypad_analog(di->joypad, port, index, id, g_settings.input.binds[port]); + ret = input_joypad_analog(di->joypad, port, + index, id, g_settings.input.binds[port]); return ret; case RETRO_DEVICE_MOUSE: @@ -366,7 +378,8 @@ static int16_t dinput_input_state(void *data, case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: - return dinput_pointer_state(di, index, id, device == RARCH_DEVICE_POINTER_SCREEN); + return dinput_pointer_state(di, index, id, + device == RARCH_DEVICE_POINTER_SCREEN); case RETRO_DEVICE_LIGHTGUN: return dinput_lightgun_state(di, id); @@ -376,7 +389,7 @@ static int16_t dinput_input_state(void *data, } } -// these are defined in later SDKs, thus ifdeffed +/* these are defined in later SDKs, thus ifdeffed. */ #ifndef WM_POINTERUPDATE #define WM_POINTERUPDATE 0x0245 #endif @@ -387,10 +400,10 @@ static int16_t dinput_input_state(void *data, #define WM_POINTERUP 0x0247 #endif #ifndef GET_POINTERID_WPARAM -#define GET_POINTERID_WPARAM(wParam) (LOWORD(wParam)) +#define GET_POINTERID_WPARAM(wParam) (LOWORD(wParam)) #endif -// stores x/y in client coordinates +/* Stores x/y in client coordinates. */ void dinput_pointer_store_pos(struct pointer_status *pointer, WPARAM lParam) { POINT point; @@ -401,7 +414,8 @@ void dinput_pointer_store_pos(struct pointer_status *pointer, WPARAM lParam) pointer->pointer_y = point.y; } -void dinput_add_pointer(struct dinput_input *di, struct pointer_status *new_pointer) +void dinput_add_pointer(struct dinput_input *di, + struct pointer_status *new_pointer) { new_pointer->next = NULL; struct pointer_status *insert_pos = &di->pointer_head; @@ -425,7 +439,8 @@ void dinput_delete_pointer(struct dinput_input *di, int pointer_id) } } -struct pointer_status *dinput_find_pointer(struct dinput_input *di, int pointer_id) +struct pointer_status *dinput_find_pointer(struct dinput_input *di, + int pointer_id) { struct pointer_status *check_pos = di->pointer_head.next; while (check_pos) @@ -454,15 +469,20 @@ extern "C" bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lParam) { struct dinput_input *di = (struct dinput_input *)dinput; - /* WM_POINTERDOWN arrives for each new touch event with a new id - add to list - WM_POINTERUP arrives once the pointer is no longer down - remove from list - WM_POINTERUPDATE arrives for both pressed and hovering pointers - ignore hovering + /* WM_POINTERDOWN : Arrives for each new touch event + * with a new ID - add to list. + * WM_POINTERUP : Arrives once the pointer is no + * longer down - remove from list. + * WM_POINTERUPDATE : arrives for both pressed and + * hovering pointers - ignore hovering */ + switch (message) { case WM_POINTERDOWN: { - struct pointer_status *new_pointer = (struct pointer_status *)malloc(sizeof(struct pointer_status)); + struct pointer_status *new_pointer = + (struct pointer_status *)malloc(sizeof(struct pointer_status)); new_pointer->pointer_id = GET_POINTERID_WPARAM(wParam); dinput_pointer_store_pos(new_pointer, lParam); dinput_add_pointer(di, new_pointer); @@ -500,12 +520,14 @@ static void dinput_free(void *data) if (di) { - g_ctx = NULL; // Prevent a joypad driver to kill our context prematurely. + /* Prevent a joypad driver to kill our context prematurely. */ + g_ctx = NULL; if (di->joypad) di->joypad->destroy(); g_ctx = hold_ctx; - dinput_clear_pointers(di); // clear any leftover pointers + /* Clear any leftover pointers. */ + dinput_clear_pointers(di); if (di->keyboard) IDirectInputDevice8_Release(di->keyboard); @@ -531,7 +553,8 @@ static void dinput_grab_mouse(void *data, bool state) IDirectInputDevice8_Acquire(di->mouse); } -static bool dinput_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, uint16_t strength) +static bool dinput_set_rumble(void *data, unsigned port, + enum retro_rumble_effect effect, uint16_t strength) { struct dinput_input *di = (struct dinput_input*)data; return input_joypad_set_rumble(di->joypad, port, effect, strength); @@ -573,9 +596,11 @@ const input_driver_t input_dinput = { dinput_get_joypad_driver, }; -// Keep track of which pad indexes are 360 controllers -// not static, will be read in winxinput_joypad.c -// -1 = not xbox pad, otherwise 0..3 +/* Keep track of which pad indexes are 360 controllers. + * Not static, will be read in winxinput_joypad.c + * -1 = not xbox pad, otherwise 0..3 + */ + int g_xinput_pad_indexes[MAX_PLAYERS]; bool g_xinput_block_pads; @@ -598,11 +623,12 @@ static void dinput_joypad_destroy(void) g_joypad_cnt = 0; memset(g_pads, 0, sizeof(g_pads)); - // Can be blocked by global Dinput context. + /* Can be blocked by global Dinput context. */ dinput_destroy_context(); } -static BOOL CALLBACK enum_axes_cb(const DIDEVICEOBJECTINSTANCE *inst, void *p) +static BOOL CALLBACK enum_axes_cb( + const DIDEVICEOBJECTINSTANCE *inst, void *p) { LPDIRECTINPUTDEVICE8 joypad = (LPDIRECTINPUTDEVICE8)p; @@ -625,15 +651,20 @@ static const GUID common_xinput_guids[] = { {MAKELONG(0x045E, 0x028E),0x0000,0x0000,{0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44}} // wireless 360 pad }; -// Based on SDL2's implementation +/* Based on SDL2's implementation. */ static bool guid_is_xinput_device(const GUID* product_guid) { PRAWINPUTDEVICELIST raw_devs = NULL; unsigned num_raw_devs = 0; unsigned i; - // Check for well known XInput device GUIDs, thereby removing the need for the IG_ check. - // This lets us skip RAWINPUT for popular devices. Also, we need to do this for the Valve Streaming Gamepad because it's virtualized and doesn't show up in the device list. + /* Check for well known XInput device GUIDs, + * thereby removing the need for the IG_ check. + * This lets us skip RAWINPUT for popular devices. + * + * Also, we need to do this for the Valve Streaming Gamepad + * because it's virtualized and doesn't show up in the device list. */ + for (i = 0; i < ARRAY_SIZE(common_xinput_guids); ++i) { if (memcmp(product_guid, &common_xinput_guids[i], sizeof(GUID)) == 0) @@ -643,14 +674,17 @@ static bool guid_is_xinput_device(const GUID* product_guid) /* Go through RAWINPUT (WinXP and later) to find HID devices. */ if (!raw_devs) { - if ((GetRawInputDeviceList(NULL, &num_raw_devs, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) || (!num_raw_devs)) + if ((GetRawInputDeviceList(NULL, &num_raw_devs, + sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) || (!num_raw_devs)) return false; - raw_devs = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * num_raw_devs); + raw_devs = (PRAWINPUTDEVICELIST) + malloc(sizeof(RAWINPUTDEVICELIST) * num_raw_devs); if (!raw_devs) return false; - if (GetRawInputDeviceList(raw_devs, &num_raw_devs, sizeof (RAWINPUTDEVICELIST)) == (UINT)-1) + if (GetRawInputDeviceList(raw_devs, &num_raw_devs, + sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) { free(raw_devs); raw_devs = NULL; @@ -683,8 +717,9 @@ static bool guid_is_xinput_device(const GUID* product_guid) return false; } -// Forward declaration +/* Forward declaration */ static const char *dinput_joypad_name(unsigned pad); + static unsigned g_last_xinput_pad_index; static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) @@ -696,17 +731,23 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) LPDIRECTINPUTDEVICE8 *pad = &g_pads[g_joypad_cnt].joypad; #ifdef __cplusplus - if (FAILED(IDirectInput8_CreateDevice(g_ctx, inst->guidInstance, pad, NULL))) + if (FAILED(IDirectInput8_CreateDevice( + g_ctx, inst->guidInstance, pad, NULL))) #else - if (FAILED(IDirectInput8_CreateDevice(g_ctx, &inst->guidInstance, pad, NULL))) + if (FAILED(IDirectInput8_CreateDevice( + g_ctx, &inst->guidInstance, pad, NULL))) #endif return DIENUM_CONTINUE; g_pads[g_joypad_cnt].joy_name = strdup(inst->tszProductName); #ifdef HAVE_WINXINPUT - //bool is_xinput_pad = g_xinput_block_pads && name_is_xinput_pad(inst->tszProductName); - bool is_xinput_pad = g_xinput_block_pads && guid_is_xinput_device(&inst->guidProduct); +#if 0 + bool is_xinput_pad = g_xinput_block_pads + && name_is_xinput_pad(inst->tszProductName); +#endif + bool is_xinput_pad = g_xinput_block_pads + && guid_is_xinput_device(&inst->guidProduct); if (is_xinput_pad) { @@ -727,8 +768,12 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) if (!is_xinput_pad) #endif { - strlcpy(g_settings.input.device_names[g_joypad_cnt], dinput_joypad_name(g_joypad_cnt), sizeof(g_settings.input.device_names[g_joypad_cnt])); - input_config_autoconfigure_joypad(g_joypad_cnt, dinput_joypad_name(g_joypad_cnt), dinput_joypad.ident); + strlcpy(g_settings.input.device_names[g_joypad_cnt], + dinput_joypad_name(g_joypad_cnt), + sizeof(g_settings.input.device_names[g_joypad_cnt])); + input_config_autoconfigure_joypad(g_joypad_cnt, + dinput_joypad_name(g_joypad_cnt), + dinput_joypad.ident); } enum_iteration_done: @@ -771,7 +816,9 @@ static bool dinput_joypad_button(unsigned port_num, uint16_t joykey) { unsigned hat = GET_HAT(joykey); - unsigned elems = sizeof(pad->joy_state.rgdwPOV) / sizeof(pad->joy_state.rgdwPOV[0]); + unsigned elems = sizeof(pad->joy_state.rgdwPOV) / + sizeof(pad->joy_state.rgdwPOV[0]); + if (hat >= elems) return false; @@ -797,7 +844,8 @@ static bool dinput_joypad_button(unsigned port_num, uint16_t joykey) } else { - unsigned elems = sizeof(pad->joy_state.rgbButtons) / sizeof(pad->joy_state.rgbButtons[0]); + unsigned elems = sizeof(pad->joy_state.rgbButtons) / + sizeof(pad->joy_state.rgbButtons[0]); if (joykey < elems) return pad->joy_state.rgbButtons[joykey]; @@ -834,12 +882,24 @@ static int16_t dinput_joypad_axis(unsigned port_num, uint32_t joyaxis) switch (axis) { - case 0: val = pad->joy_state.lX; break; - case 1: val = pad->joy_state.lY; break; - case 2: val = pad->joy_state.lZ; break; - case 3: val = pad->joy_state.lRx; break; - case 4: val = pad->joy_state.lRy; break; - case 5: val = pad->joy_state.lRz; break; + case 0: + val = pad->joy_state.lX; + break; + case 1: + val = pad->joy_state.lY; + break; + case 2: + val = pad->joy_state.lZ; + break; + case 3: + val = pad->joy_state.lRx; + break; + case 4: + val = pad->joy_state.lRy; + break; + case 5: + val = pad->joy_state.lRz; + break; } if (is_neg && val > 0) @@ -869,7 +929,7 @@ static void dinput_joypad_poll(void) continue; } - // If this fails, something *really* bad must have happened. + /* If this fails, something *really* bad must have happened. */ if (FAILED(IDirectInputDevice8_Poll(pad->joypad))) { memset(&pad->joy_state, 0, sizeof(DIJOYSTATE2)); diff --git a/input/gx_input.c b/input/gx_input.c index 17d0a04ab0..35290b9407 100644 --- a/input/gx_input.c +++ b/input/gx_input.c @@ -89,7 +89,9 @@ enum GX_WIIMOTE_2 = 46, GX_WIIMOTE_PLUS = 47, GX_WIIMOTE_MINUS = 48, - //GX_WIIMOTE_HOME = 49, +#if 0 + GX_WIIMOTE_HOME = 49, +#endif GX_WIIMOTE_UP = 50, GX_WIIMOTE_DOWN = 51, GX_WIIMOTE_LEFT = 52, @@ -101,7 +103,7 @@ enum GX_NUNCHUK_LEFT = 58, GX_NUNCHUK_RIGHT = 59, #endif - GX_WIIMOTE_HOME = 49, // needed on GameCube as "fake" menu button + GX_WIIMOTE_HOME = 49, /* needed on GameCube as "fake" menu button. */ GX_QUIT_KEY = 60, }; @@ -250,8 +252,12 @@ static void *gx_input_init(void) for (autoconf_pad = 0; autoconf_pad < MAX_PADS; autoconf_pad++) { gx->ptype[autoconf_pad] = WPAD_EXP_GAMECUBE; - strlcpy(g_settings.input.device_names[autoconf_pad], gx_joypad_name_static(gx, autoconf_pad), sizeof(g_settings.input.device_names[autoconf_pad])); - input_config_autoconfigure_joypad(autoconf_pad, gx_joypad_name_static(gx, autoconf_pad), gx->joypad->ident); + strlcpy(g_settings.input.device_names[autoconf_pad], + gx_joypad_name_static(gx, autoconf_pad), + sizeof(g_settings.input.device_names[autoconf_pad])); + input_config_autoconfigure_joypad(autoconf_pad, + gx_joypad_name_static(gx, autoconf_pad), + gx->joypad->ident); } driver.input_data_own = true; @@ -267,8 +273,11 @@ static void handle_hotplug(void *data, unsigned port, uint32_t ptype) if (!g_settings.input.autodetect_enable) return; - strlcpy(g_settings.input.device_names[port], gx_joypad_name(port), sizeof(g_settings.input.device_names[port])); - input_config_autoconfigure_joypad(port, gx_joypad_name(port), gx_joypad.ident); + strlcpy(g_settings.input.device_names[port], + gx_joypad_name(port), + sizeof(g_settings.input.device_names[port])); + input_config_autoconfigure_joypad(port, + gx_joypad_name(port), gx_joypad.ident); } static void gx_input_poll(void *data) @@ -314,7 +323,7 @@ static void gx_input_poll(void *data) if (ptype != WPAD_EXP_NUNCHUK) { - // rotated d-pad on Wiimote + /* Rotated d-pad on Wiimote. */ *state_cur |= (down & WPAD_BUTTON_UP) ? (1ULL << GX_WIIMOTE_LEFT) : 0; *state_cur |= (down & WPAD_BUTTON_DOWN) ? (1ULL << GX_WIIMOTE_RIGHT) : 0; *state_cur |= (down & WPAD_BUTTON_LEFT) ? (1ULL << GX_WIIMOTE_DOWN) : 0; @@ -375,7 +384,8 @@ static void gx_input_poll(void *data) } else if (ptype == WPAD_EXP_NUNCHUK) { - // wiimote is held upright with nunchuk, do not change d-pad orientation + /* Wiimote is held upright with nunchuk, + * do not change d-pad orientation. */ *state_cur |= (down & WPAD_BUTTON_UP) ? (1ULL << GX_WIIMOTE_UP) : 0; *state_cur |= (down & WPAD_BUTTON_DOWN) ? (1ULL << GX_WIIMOTE_DOWN) : 0; *state_cur |= (down & WPAD_BUTTON_LEFT) ? (1ULL << GX_WIIMOTE_LEFT) : 0; @@ -511,7 +521,8 @@ static void gx_input_poll(void *data) static bool gx_input_key_pressed(void *data, int key) { - return (g_extern.lifecycle_state & (1ULL << key)) || input_joypad_pressed(&gx_joypad, 0, g_settings.input.binds[0], key); + return (g_extern.lifecycle_state & (1ULL << key)) || + input_joypad_pressed(&gx_joypad, 0, g_settings.input.binds[0], key); } static uint64_t gx_input_get_capabilities(void *data) diff --git a/input/gx_input_joypad.c b/input/gx_input_joypad.c index 479e551879..36f6533f51 100644 --- a/input/gx_input_joypad.c +++ b/input/gx_input_joypad.c @@ -29,7 +29,6 @@ static bool gx_joypad_init(void) ss_initialize(&dev[i]); #endif - return true; } @@ -68,10 +67,18 @@ static int16_t gx_joypad_axis(unsigned port_num, uint32_t joyaxis) switch (axis) { - case 0: val = gx->analog_state[port_num][0][0]; break; - case 1: val = gx->analog_state[port_num][0][1]; break; - case 2: val = gx->analog_state[port_num][1][0]; break; - case 3: val = gx->analog_state[port_num][1][1]; break; + case 0: + val = gx->analog_state[port_num][0][0]; + break; + case 1: + val = gx->analog_state[port_num][0][1]; + break; + case 2: + val = gx->analog_state[port_num][1][0]; + break; + case 3: + val = gx->analog_state[port_num][1][1]; + break; } if (is_neg && val > 0) diff --git a/input/gx_input_sicksaxis.c b/input/gx_input_sicksaxis.c index 0ae6198290..01caf3f33c 100644 --- a/input/gx_input_sicksaxis.c +++ b/input/gx_input_sicksaxis.c @@ -36,312 +36,329 @@ static int _ss_send_attributes_payload(struct ss_device *dev); int ss_init(void) { - if (!_ss_inited) - { - _ss_heap_id = iosCreateHeap(SS_HEAP_SIZE); - _ss_inited = 1; - } - return 1; + if (!_ss_inited) + { + _ss_heap_id = iosCreateHeap(SS_HEAP_SIZE); + _ss_inited = 1; + } + return 1; } int ss_initialize(struct ss_device *dev) { - dev->device_id = -1; - dev->fd = -1; - dev->connected = 0; - dev->enabled = 0; - dev->reading = 0; - dev->removal_callback = NULL; - dev->removal_usrdata = NULL; - dev->read_callback = NULL; - dev->read_usrdata = NULL; - memset(&dev->pad, 0x0, sizeof(struct SS_GAMEPAD)); - memset(&dev->attributes, 0x0, sizeof(struct SS_ATTRIBUTES)); - return 1; + dev->device_id = -1; + dev->fd = -1; + dev->connected = 0; + dev->enabled = 0; + dev->reading = 0; + dev->removal_callback = NULL; + dev->removal_usrdata = NULL; + dev->read_callback = NULL; + dev->read_usrdata = NULL; + memset(&dev->pad, 0x0, sizeof(struct SS_GAMEPAD)); + memset(&dev->attributes, 0x0, sizeof(struct SS_ATTRIBUTES)); + return 1; } int ss_open(struct ss_device *dev) { - if (!_ss_inited) return -1; - if (dev->connected) ss_close(dev); - - usb_device_entry dev_entry[8]; - unsigned char dev_count; - if (USB_GetDeviceList(dev_entry, 8, USB_CLASS_HID, &dev_count) < 0) { - return -2; - } - - int i; - for (i = 0; i < dev_count; ++i) { - - if ((dev_entry[i].vid == SS_VENDOR_ID) && (dev_entry[i].pid == SS_PRODUCT_ID)) { - - if (!_ss_dev_id_list_exists(dev_entry[i].device_id)) { - if (USB_OpenDevice(dev_entry[i].device_id, SS_VENDOR_ID, SS_PRODUCT_ID, &dev->fd) < 0) { - return -3; - } - - dev->device_id = dev_entry[i].device_id; - dev->connected = 1; - dev->enabled = 0; - dev->reading = 0; - - _ss_set_operational(dev); - ss_set_led(dev, _ss_dev_number); - - _ss_dev_id_list_add(dev_entry[i].device_id); - _ss_dev_number++; - - USB_DeviceRemovalNotifyAsync(dev->fd, &_ss_removal_cb, dev); - return 1; - } - } - } - return -4; + usb_device_entry dev_entry[8]; + unsigned char dev_count; + if (!_ss_inited) + return -1; + if (dev->connected) + ss_close(dev); + + if (USB_GetDeviceList(dev_entry, 8, USB_CLASS_HID, &dev_count) < 0) + return -2; + + int i; + for (i = 0; i < dev_count; ++i) + { + if ((dev_entry[i].vid == SS_VENDOR_ID) && + (dev_entry[i].pid == SS_PRODUCT_ID)) + { + if (!_ss_dev_id_list_exists(dev_entry[i].device_id)) + { + if (USB_OpenDevice(dev_entry[i].device_id, + SS_VENDOR_ID, SS_PRODUCT_ID, &dev->fd) < 0) + return -3; + + dev->device_id = dev_entry[i].device_id; + dev->connected = 1; + dev->enabled = 0; + dev->reading = 0; + + _ss_set_operational(dev); + ss_set_led(dev, _ss_dev_number); + + _ss_dev_id_list_add(dev_entry[i].device_id); + _ss_dev_number++; + + USB_DeviceRemovalNotifyAsync(dev->fd, &_ss_removal_cb, dev); + return 1; + } + } + } + return -4; } int ss_close(struct ss_device *dev) { - if (dev && dev->fd > 0) { - USB_CloseDevice(&dev->fd); - } - return 1; + if (dev && dev->fd > 0) + USB_CloseDevice(&dev->fd); + return 1; } int ss_is_connected(struct ss_device *dev) { - return dev->connected; + return dev->connected; } -int ss_set_read_cb(struct ss_device *dev,ss_usb_callback cb, void *usrdata) +int ss_set_read_cb(struct ss_device *dev,ss_usb_callback cb, + void *userdata) { - dev->read_callback = cb; - dev->read_usrdata = usrdata; - return 1; + dev->read_callback = cb; + dev->read_usrdata = userdata; + return 1; } -int ss_set_removal_cb(struct ss_device *dev, ss_usb_callback cb, void *usrdata) +int ss_set_removal_cb(struct ss_device *dev, ss_usb_callback cb, + void *usrdata) { dev->removal_callback = cb; - dev->removal_usrdata = usrdata; + dev->removal_usrdata = userdata; return 1; } int ss_start_reading(struct ss_device *dev) { - if (dev) { - dev->reading = 1; - if (dev->enabled) { - _ss_read(dev); - } - return 1; - } - return 0; + if (dev) + { + dev->reading = 1; + if (dev->enabled) + _ss_read(dev); + return 1; + } + return 0; } - int ss_stop_reading(struct ss_device *dev) { - if (dev) { - dev->reading = 0; - return 1; - } - return 0; + if (dev) + { + dev->reading = 0; + return 1; + } + return 0; } static int _ss_build_attributes_payload(struct ss_device *dev) { - _ss_attributes_payload[1] = dev->attributes.rumble.duration_right; - _ss_attributes_payload[2] = dev->attributes.rumble.power_right; - _ss_attributes_payload[3] = dev->attributes.rumble.duration_left; - _ss_attributes_payload[4] = dev->attributes.rumble.power_left; - _ss_attributes_payload[9] = _ss_led_pattern[dev->attributes.led]; - return 1; + _ss_attributes_payload[1] = dev->attributes.rumble.duration_right; + _ss_attributes_payload[2] = dev->attributes.rumble.power_right; + _ss_attributes_payload[3] = dev->attributes.rumble.duration_left; + _ss_attributes_payload[4] = dev->attributes.rumble.power_left; + _ss_attributes_payload[9] = _ss_led_pattern[dev->attributes.led]; + return 1; } static int _ss_send_attributes_payload(struct ss_device *dev) { - if (!dev->connected) return 0; - _ss_build_attributes_payload(dev); - return USB_WriteCtrlMsgAsync(dev->fd, - USB_REQTYPE_INTERFACE_SET, - USB_REQ_SETREPORT, - (USB_REPTYPE_OUTPUT<<8) | 0x01, - 0x0, - sizeof(_ss_attributes_payload), - _ss_attributes_payload, - NULL, NULL); + if (!dev->connected) + return 0; + + _ss_build_attributes_payload(dev); + + return USB_WriteCtrlMsgAsync(dev->fd, + USB_REQTYPE_INTERFACE_SET, + USB_REQ_SETREPORT, + (USB_REPTYPE_OUTPUT<<8) | 0x01, + 0x0, + sizeof(_ss_attributes_payload), + _ss_attributes_payload, + NULL, NULL); } inline int ss_set_led(struct ss_device *dev, int led) { - dev->attributes.led = led; - return _ss_send_attributes_payload(dev); + dev->attributes.led = led; + return _ss_send_attributes_payload(dev); } -inline int ss_set_rumble(struct ss_device *dev, uint8_t duration_right, uint8_t power_right, uint8_t duration_left, uint8_t power_left) +inline int ss_set_rumble(struct ss_device *dev, uint8_t duration_right, + uint8_t power_right, uint8_t duration_left, uint8_t power_left) { - dev->attributes.rumble.duration_right = duration_right; - dev->attributes.rumble.power_right = power_right; - dev->attributes.rumble.duration_left = duration_left; - dev->attributes.rumble.power_left = power_left; - return _ss_send_attributes_payload(dev); + dev->attributes.rumble.duration_right = duration_right; + dev->attributes.rumble.power_right = power_right; + dev->attributes.rumble.duration_left = duration_left; + dev->attributes.rumble.power_left = power_left; + return _ss_send_attributes_payload(dev); } int ss_get_bd_address(struct ss_device *dev, uint8_t *mac) { - uint8_t ATTRIBUTE_ALIGN(32) msg[17]; - int ret = USB_WriteCtrlMsgAsync(dev->fd, - USB_REQTYPE_INTERFACE_GET, - USB_REQ_GETREPORT, - (USB_REPTYPE_FEATURE<<8) | 0xf2, - 0, - sizeof(msg), - msg, - NULL, NULL); + uint8_t ATTRIBUTE_ALIGN(32) msg[17]; + int ret = USB_WriteCtrlMsgAsync(dev->fd, + USB_REQTYPE_INTERFACE_GET, + USB_REQ_GETREPORT, + (USB_REPTYPE_FEATURE<<8) | 0xf2, + 0, + sizeof(msg), + msg, + NULL, NULL); - mac[0] = msg[4]; - mac[1] = msg[5]; - mac[2] = msg[6]; - mac[3] = msg[7]; - mac[4] = msg[8]; - mac[5] = msg[9]; - return ret; + mac[0] = msg[4]; + mac[1] = msg[5]; + mac[2] = msg[6]; + mac[3] = msg[7]; + mac[4] = msg[8]; + mac[5] = msg[9]; + return ret; } int ss_get_mac(struct ss_device *dev, uint8_t *mac) { - uint8_t ATTRIBUTE_ALIGN(32) msg[8]; - int ret = USB_WriteCtrlMsgAsync(dev->fd, - USB_REQTYPE_INTERFACE_GET, - USB_REQ_GETREPORT, - (USB_REPTYPE_FEATURE<<8) | 0xf5, - 0, - sizeof(msg), - msg, - NULL, NULL); + uint8_t ATTRIBUTE_ALIGN(32) msg[8]; + int ret = USB_WriteCtrlMsgAsync(dev->fd, + USB_REQTYPE_INTERFACE_GET, + USB_REQ_GETREPORT, + (USB_REPTYPE_FEATURE<<8) | 0xf5, + 0, + sizeof(msg), + msg, + NULL, NULL); - mac[0] = msg[2]; - mac[1] = msg[3]; - mac[2] = msg[4]; - mac[3] = msg[5]; - mac[4] = msg[6]; - mac[5] = msg[7]; - return ret; + mac[0] = msg[2]; + mac[1] = msg[3]; + mac[2] = msg[4]; + mac[3] = msg[5]; + mac[4] = msg[6]; + mac[5] = msg[7]; + return ret; } int ss_set_mac(struct ss_device *dev, const uint8_t *mac) { - uint8_t ATTRIBUTE_ALIGN(32) msg[] = {0x01, 0x00, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]}; - int ret = USB_WriteCtrlMsgAsync(dev->fd, - USB_REQTYPE_INTERFACE_SET, - USB_REQ_SETREPORT, - (USB_REPTYPE_FEATURE<<8) | 0xf5, - 0, - sizeof(msg), - msg, - NULL, NULL); - return ret; + uint8_t ATTRIBUTE_ALIGN(32) msg[] = {0x01, 0x00, mac[0], mac[1], + mac[2], mac[3], mac[4], mac[5]}; + int ret = USB_WriteCtrlMsgAsync(dev->fd, + USB_REQTYPE_INTERFACE_SET, + USB_REQ_SETREPORT, + (USB_REPTYPE_FEATURE<<8) | 0xf5, + 0, + sizeof(msg), + msg, + NULL, NULL); + return ret; } static int _ss_read(struct ss_device *dev) { - return USB_WriteCtrlMsgAsync( - dev->fd, - USB_REQTYPE_INTERFACE_GET, - USB_REQ_GETREPORT, - (USB_REPTYPE_INPUT<<8) | 0x01, - 0x0, - SS_PAYLOAD_SIZE, - &dev->pad, - &_ss_read_cb, - dev); + return USB_WriteCtrlMsgAsync( + dev->fd, + USB_REQTYPE_INTERFACE_GET, + USB_REQ_GETREPORT, + (USB_REPTYPE_INPUT<<8) | 0x01, + 0x0, + SS_PAYLOAD_SIZE, + &dev->pad, + &_ss_read_cb, + dev); } static int _ss_removal_cb(int result, void *usrdata) { - struct ss_device *dev = (struct ss_device*)usrdata; - if (dev->device_id > 0) { - _ss_dev_id_list_remove(dev->device_id); - _ss_dev_number--; - if (dev->removal_callback) - dev->removal_callback(dev->removal_usrdata); - ss_initialize(dev); - return 1; - } - return 0; + struct ss_device *dev = (struct ss_device*)usrdata; + if (dev->device_id > 0) + { + _ss_dev_id_list_remove(dev->device_id); + _ss_dev_number--; + if (dev->removal_callback) + dev->removal_callback(dev->removal_usrdata); + ss_initialize(dev); + return 1; + } + return 0; } static int _ss_set_operational(struct ss_device *dev) { - uint8_t ATTRIBUTE_ALIGN(32) buf[17]; - return USB_WriteCtrlMsgAsync( - dev->fd, - USB_REQTYPE_INTERFACE_GET, - USB_REQ_GETREPORT, - (USB_REPTYPE_FEATURE<<8) | 0xf2, - 0x0, - 17, - buf, - &_ss_operational_cb, - dev); + uint8_t ATTRIBUTE_ALIGN(32) buf[17]; + return USB_WriteCtrlMsgAsync( + dev->fd, + USB_REQTYPE_INTERFACE_GET, + USB_REQ_GETREPORT, + (USB_REPTYPE_FEATURE<<8) | 0xf2, + 0x0, + 17, + buf, + &_ss_operational_cb, + dev); } -static int _ss_read_cb(int result, void *usrdata) +static int _ss_read_cb(int result, void *userdata) { - if (usrdata) { - struct ss_device *dev = (struct ss_device*)usrdata; - if (dev->reading) { - _ss_read(dev); - if (dev->read_callback) + if (userdata) + { + struct ss_device *dev = (struct ss_device*)userdata; + if (dev->reading) + { + _ss_read(dev); + if (dev->read_callback) dev->read_callback(dev->read_usrdata); - } - } - return 1; + } + } + return 1; } -static int _ss_operational_cb(int result, void *usrdata) +static int _ss_operational_cb(int result, void *userdata) { - struct ss_device *dev = (struct ss_device*)usrdata; - dev->enabled = 1; - if (dev->reading) { - _ss_read(dev); - } - return 1; + struct ss_device *dev = (struct ss_device*)userdata; + dev->enabled = 1; + if (dev->reading) + _ss_read(dev); + return 1; } static int _ss_dev_id_list_exists(int id) { - int i; - for (i = 0; i < SS_MAX_DEV; ++i) { - if (_ss_dev_id_list[i] == id) return 1; - } - return 0; + int i; + for (i = 0; i < SS_MAX_DEV; ++i) + { + if (_ss_dev_id_list[i] == id) + return 1; + } + return 0; } static int _ss_dev_id_list_add(int id) { - int i; - for (i = 0; i < SS_MAX_DEV; ++i) { - if (_ss_dev_id_list[i] == 0) { - _ss_dev_id_list[i] = id; - return 1; - } - } - return 0; + int i; + for (i = 0; i < SS_MAX_DEV; ++i) + { + if (_ss_dev_id_list[i] == 0) + { + _ss_dev_id_list[i] = id; + return 1; + } + } + return 0; } static int _ss_dev_id_list_remove(int id) { - int i; - for (i = 0; i < SS_MAX_DEV; ++i) { - if (_ss_dev_id_list[i] == id) { - _ss_dev_id_list[i] = 0; - return 1; - } - } - return 0; + int i; + for (i = 0; i < SS_MAX_DEV; ++i) + { + if (_ss_dev_id_list[i] == id) + { + _ss_dev_id_list[i] = 0; + return 1; + } + } + return 0; } diff --git a/input/gx_input_sicksaxis.h b/input/gx_input_sicksaxis.h index 5dfe5222a2..13f5436316 100644 --- a/input/gx_input_sicksaxis.h +++ b/input/gx_input_sicksaxis.h @@ -122,20 +122,34 @@ struct ss_device { int ss_init(void); + int ss_initialize(struct ss_device *dev); + int ss_open(struct ss_device *dev); + int ss_close(struct ss_device *dev); + int ss_is_connected(struct ss_device *dev); -int ss_set_read_cb(struct ss_device *dev, ss_usb_callback cb, void *usrdata); -int ss_set_removal_cb(struct ss_device *dev, ss_usb_callback cb, void *usrdata); +int ss_set_read_cb(struct ss_device *dev, + ss_usb_callback cb, void *usrdata); + +int ss_set_removal_cb(struct ss_device *dev, + ss_usb_callback cb, void *usrdata); int ss_start_reading(struct ss_device *dev); + int ss_stop_reading(struct ss_device *dev); + int ss_set_led(struct ss_device *dev, int led); -int ss_set_rumble(struct ss_device *dev, uint8_t duration_right, uint8_t power_right, uint8_t duration_left, uint8_t power_left); + +int ss_set_rumble(struct ss_device *dev, uint8_t duration_right, + uint8_t power_right, uint8_t duration_left, uint8_t power_left); + int ss_get_bd_address(struct ss_device *dev, uint8_t *mac); + int ss_get_paired_mac(struct ss_device *dev, uint8_t *mac); + int ss_set_paired_mac(struct ss_device *dev, const uint8_t *mac); diff --git a/input/input_common.c b/input/input_common.c index c528549df9..0d36c36cd4 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -275,9 +275,9 @@ bool input_translate_coord_viewport(int mouse_x, int mouse_y, int scaled_screen_x = (2 * mouse_x * 0x7fff) / (int)vp.full_width - 0x7fff; int scaled_screen_y = (2 * mouse_y * 0x7fff) / (int)vp.full_height - 0x7fff; if (scaled_screen_x < -0x7fff || scaled_screen_x > 0x7fff) - scaled_screen_x = -0x8000; // OOB + scaled_screen_x = -0x8000; /* OOB */ if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff) - scaled_screen_y = -0x8000; // OOB + scaled_screen_y = -0x8000; /* OOB */ mouse_x -= vp.x; mouse_y -= vp.y; @@ -285,9 +285,9 @@ bool input_translate_coord_viewport(int mouse_x, int mouse_y, int scaled_x = (2 * mouse_x * 0x7fff) / (int)vp.width - 0x7fff; int scaled_y = (2 * mouse_y * 0x7fff) / (int)vp.height - 0x7fff; if (scaled_x < -0x7fff || scaled_x > 0x7fff) - scaled_x = -0x8000; // OOB + scaled_x = -0x8000; /* OOB */ if (scaled_y < -0x7fff || scaled_y > 0x7fff) - scaled_y = -0x8000; // OOB + scaled_y = -0x8000; /* OOB */ *res_x = scaled_x; *res_y = scaled_y; @@ -1193,7 +1193,8 @@ const struct input_key_map input_config_key_map[] = { { "rctrl", RETROK_RCTRL }, { "ralt", RETROK_RALT }, - /* Keys not referenced in any keyboard mapping (except perhaps apple_key_map_hidusage) */ + /* Keys not referenced in any keyboard mapping + * (except perhaps apple_key_map_hidusage) */ { "caret", RETROK_CARET }, { "underscore", RETROK_UNDERSCORE }, { "exclaim", RETROK_EXCLAIM }, @@ -1450,8 +1451,10 @@ void input_config_autoconfigure_joypad(unsigned index, /* First internal */ for (i = 0; input_builtin_autoconfs[i]; i++) { - config_file_t *conf = config_file_new_from_string(input_builtin_autoconfs[i]); - bool success = input_try_autoconfigure_joypad_from_conf(conf, index, name, driver, block_osd_spam); + config_file_t *conf = (config_file_t*) + config_file_new_from_string(input_builtin_autoconfs[i]); + bool success = input_try_autoconfigure_joypad_from_conf(conf, + index, name, driver, block_osd_spam); config_file_free(conf); if (success) break; diff --git a/input/keyboard_line.h b/input/keyboard_line.h index eb3693228c..68c95cd6ac 100644 --- a/input/keyboard_line.h +++ b/input/keyboard_line.h @@ -54,7 +54,8 @@ void input_keyboard_line_free(input_keyboard_line_t *state); void input_keyboard_event(bool down, unsigned code, uint32_t character, uint16_t mod); -const char **input_keyboard_start_line(void *userdata, input_keyboard_line_complete_t cb); +const char **input_keyboard_start_line(void *userdata, + input_keyboard_line_complete_t cb); /* Wait for keys to be pressed (used for binding keys in the menu). * Callback returns false when all polling is done. */ diff --git a/input/nullinput.c b/input/nullinput.c index 27b546c6c9..92ad65b69b 100644 --- a/input/nullinput.c +++ b/input/nullinput.c @@ -26,7 +26,9 @@ static void nullinput_input_poll(void *data) (void)data; } -static int16_t nullinput_input_state(void *data, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id) +static int16_t nullinput_input_state(void *data, + const struct retro_keybind **retro_keybinds, unsigned port, + unsigned device, unsigned index, unsigned id) { (void)data; (void)retro_keybinds; @@ -60,7 +62,8 @@ static uint64_t nullinput_get_capabilities(void *data) return caps; } -static bool nullinput_set_sensor_state(void *data, unsigned port, enum retro_sensor_action action, unsigned event_rate) +static bool nullinput_set_sensor_state(void *data, + unsigned port, enum retro_sensor_action action, unsigned event_rate) { return false; } diff --git a/input/ps3_input_joypad.c b/input/ps3_input_joypad.c index 6e85a9c1dc..3ce0892b75 100644 --- a/input/ps3_input_joypad.c +++ b/input/ps3_input_joypad.c @@ -25,8 +25,12 @@ static bool ps3_joypad_init(void) for (autoconf_pad = 0; autoconf_pad < MAX_PLAYERS; autoconf_pad++) { - strlcpy(g_settings.input.device_names[autoconf_pad], "SixAxis Controller", sizeof(g_settings.input.device_names[autoconf_pad])); - input_config_autoconfigure_joypad(autoconf_pad, ps3_joypad_name(autoconf_pad), ps3_joypad.ident); + strlcpy(g_settings.input.device_names[autoconf_pad], + "SixAxis Controller", + sizeof(g_settings.input.device_names[autoconf_pad])); + input_config_autoconfigure_joypad(autoconf_pad, + ps3_joypad_name(autoconf_pad), + ps3_joypad.ident); } return true; @@ -68,10 +72,18 @@ static int16_t ps3_joypad_axis(unsigned port_num, uint32_t joyaxis) switch (axis) { - case 0: val = ps3->analog_state[port_num][0][0]; break; - case 1: val = ps3->analog_state[port_num][0][1]; break; - case 2: val = ps3->analog_state[port_num][1][0]; break; - case 3: val = ps3->analog_state[port_num][1][1]; break; + case 0: + val = ps3->analog_state[port_num][0][0]; + break; + case 1: + val = ps3->analog_state[port_num][0][1]; + break; + case 2: + val = ps3->analog_state[port_num][1][0]; + break; + case 3: + val = ps3->analog_state[port_num][1][1]; + break; } if (is_neg && val > 0) diff --git a/input/psp_input.c b/input/psp_input.c index 1d6dacec47..3ca94101a4 100644 --- a/input/psp_input.c +++ b/input/psp_input.c @@ -60,7 +60,8 @@ static void psp_input_poll(void *data) #endif (void)ret; - psp->analog_state[0][0][0] = psp->analog_state[0][0][1] = psp->analog_state[0][1][0] = psp->analog_state[0][1][1] = 0; + psp->analog_state[0][0][0] = psp->analog_state[0][0][1] = + psp->analog_state[0][1][0] = psp->analog_state[0][1][1] = 0; psp->pad_state = 0; psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_LEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_DOWN) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; @@ -146,7 +147,8 @@ static void* psp_input_initialize(void) static bool psp_input_key_pressed(void *data, int key) { psp_input_t *psp = (psp_input_t*)data; - return (g_extern.lifecycle_state & (1ULL << key)) || input_joypad_pressed(psp->joypad, 0, g_settings.input.binds[0], key); + return (g_extern.lifecycle_state & (1ULL << key)) || + input_joypad_pressed(psp->joypad, 0, g_settings.input.binds[0], key); } static uint64_t psp_input_get_capabilities(void *data) diff --git a/input/psp_input_joypad.c b/input/psp_input_joypad.c index 634581c682..46138c7b9c 100644 --- a/input/psp_input_joypad.c +++ b/input/psp_input_joypad.c @@ -25,8 +25,12 @@ static bool psp_joypad_init(void) for (autoconf_pad = 0; autoconf_pad < MAX_PADS; autoconf_pad++) { - strlcpy(g_settings.input.device_names[autoconf_pad], psp_joypad_name(autoconf_pad), sizeof(g_settings.input.device_names[autoconf_pad])); - input_config_autoconfigure_joypad(autoconf_pad, psp_joypad_name(autoconf_pad), psp_joypad.ident); + strlcpy(g_settings.input.device_names[autoconf_pad], + psp_joypad_name(autoconf_pad), + sizeof(g_settings.input.device_names[autoconf_pad])); + input_config_autoconfigure_joypad(autoconf_pad, + psp_joypad_name(autoconf_pad), + psp_joypad.ident); } return true; @@ -67,10 +71,18 @@ static int16_t psp_joypad_axis(unsigned port_num, uint32_t joyaxis) switch (axis) { - case 0: val = psp->analog_state[port_num][0][0]; break; - case 1: val = psp->analog_state[port_num][0][1]; break; - case 2: val = psp->analog_state[port_num][1][0]; break; - case 3: val = psp->analog_state[port_num][1][1]; break; + case 0: + val = psp->analog_state[port_num][0][0]; + break; + case 1: + val = psp->analog_state[port_num][0][1]; + break; + case 2: + val = psp->analog_state[port_num][1][0]; + break; + case 3: + val = psp->analog_state[port_num][1][1]; + break; } if (is_neg && val > 0) diff --git a/input/qnx_input.c b/input/qnx_input.c index 8278b3d247..9e32a23803 100644 --- a/input/qnx_input.c +++ b/input/qnx_input.c @@ -67,7 +67,9 @@ typedef struct qnx_input unsigned pointer_count; int touch_map[MAX_TOUCH]; - /*The first pointer_count indices of touch_map will be a valid, active index in pointer array. + /* + * The first pointer_count indices of touch_map will be a valid, + * active index in pointer array. * Saves us from searching through pointer array when polling state. */ input_device_t *port_device[MAX_PADS]; @@ -77,11 +79,14 @@ typedef struct qnx_input uint64_t pad_state[MAX_PADS]; } qnx_input_t; -static void qnx_input_autodetect_gamepad(void *data, input_device_t* controller, int port); +static void qnx_input_autodetect_gamepad(void *data, + input_device_t* controller, int port); + static void initController(void *data, input_device_t* controller); #ifdef HAVE_BB10 -static void process_gamepad_event(void *data, screen_event_t screen_event, int type) +static void process_gamepad_event(void *data, + screen_event_t screen_event, int type) { int i; screen_device_t device; @@ -90,7 +95,8 @@ static void process_gamepad_event(void *data, screen_event_t screen_event, int t qnx_input_t *qnx = (qnx_input_t*)data; (void)type; - screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device); + screen_get_event_property_pv(screen_event, + SCREEN_PROPERTY_DEVICE, (void**)&device); for (i = 0; i < MAX_PADS; ++i) { @@ -104,25 +110,30 @@ static void process_gamepad_event(void *data, screen_event_t screen_event, int t if (!controller) return; - // Store the controller's new state. - screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &controller->buttons); + /* Store the controller's new state. */ + screen_get_event_property_iv(screen_event, + SCREEN_PROPERTY_BUTTONS, &controller->buttons); uint64_t *state_cur = (uint64_t*)&qnx->pad_state[controller->port]; - //int i; *state_cur = 0; for (i = 0; i < 20; i++) *state_cur |= (controller->buttons & (1 << i) ? (1 << i) : 0); if (controller->analogCount > 0) - screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ANALOG0, controller->analog0); + screen_get_event_property_iv(screen_event, + SCREEN_PROPERTY_ANALOG0, controller->analog0); if (controller->analogCount == 2) - screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ANALOG1, controller->analog1); + screen_get_event_property_iv(screen_event, + SCREEN_PROPERTY_ANALOG1, controller->analog1); - //Only player 1 - //TODO: Am I missing something? Is there a better way? - if((controller->port == 0) && (controller->buttons & g_settings.input.binds[0][RARCH_MENU_TOGGLE].joykey)) + /* Only player 1 + * TODO: Am I missing something? Is there a better way? + */ + if((controller->port == 0) && + (controller->buttons & + g_settings.input.binds[0][RARCH_MENU_TOGGLE].joykey)) g_extern.lifecycle_state ^= (1ULL << RARCH_MENU_TOGGLE); } @@ -136,25 +147,34 @@ static void loadController(void *data, input_device_t* controller) if (!qnx) return; - // Query libscreen for information about this device. - screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_TYPE, &controller->type); - screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_ID_STRING, sizeof(controller->id), controller->id); - screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_VENDOR, sizeof(controller->id), controller->vendor); - screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_PRODUCT, sizeof(controller->id), controller->product); + /* Query libscreen for information about this device. */ + screen_get_device_property_iv(controller->handle, + SCREEN_PROPERTY_TYPE, &controller->type); + screen_get_device_property_cv(controller->handle, + SCREEN_PROPERTY_ID_STRING, sizeof(controller->id), controller->id); + screen_get_device_property_cv(controller->handle, + SCREEN_PROPERTY_VENDOR, sizeof(controller->id), controller->vendor); + screen_get_device_property_cv(controller->handle, + SCREEN_PROPERTY_PRODUCT, sizeof(controller->id), controller->product); - if (controller->type == SCREEN_EVENT_GAMEPAD || controller->type == SCREEN_EVENT_JOYSTICK) + if (controller->type == SCREEN_EVENT_GAMEPAD || + controller->type == SCREEN_EVENT_JOYSTICK) { - screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_BUTTON_COUNT, &controller->buttonCount); + screen_get_device_property_iv(controller->handle, + SCREEN_PROPERTY_BUTTON_COUNT, &controller->buttonCount); - // Check for the existence of analog sticks. - if (!screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_ANALOG0, controller->analog0)) + /* Check for the existence of analog sticks. */ + if (!screen_get_device_property_iv(controller->handle, + SCREEN_PROPERTY_ANALOG0, controller->analog0)) ++controller->analogCount; - if (!screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_ANALOG1, controller->analog1)) + if (!screen_get_device_property_iv(controller->handle, + SCREEN_PROPERTY_ANALOG1, controller->analog1)) ++controller->analogCount; } - //Screen service will map supported controllers, we still might need to adjust. + /* Screen service will map supported controllers, + * we still might need to adjust. */ qnx_input_autodetect_gamepad(qnx, controller, controller->port); if (controller->type == SCREEN_EVENT_GAMEPAD) @@ -175,7 +195,7 @@ extern screen_context_t screen_ctx; static void discoverControllers(void *data) { - // Get an array of all available devices. + /* Get an array of all available devices. */ int deviceCount; unsigned i; screen_event_t *event; @@ -183,11 +203,14 @@ static void discoverControllers(void *data) (void)event; - screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount); - screen_device_t* devices_found = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t)); - screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices_found); + screen_get_context_property_iv(screen_ctx, + SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount); + screen_device_t* devices_found = (screen_device_t*) + calloc(deviceCount, sizeof(screen_device_t)); + screen_get_context_property_pv(screen_ctx, + SCREEN_PROPERTY_DEVICES, (void**)devices_found); - // Scan the list for gamepad and joystick devices. + /* Scan the list for gamepad and joystick devices. */ for(i = 0; i < qnx->pads_connected; ++i) initController(qnx, &qnx->devices[i]); @@ -196,9 +219,13 @@ static void discoverControllers(void *data) for (i = 0; i < deviceCount; i++) { int type; - screen_get_device_property_iv(devices_found[i], SCREEN_PROPERTY_TYPE, &type); + screen_get_device_property_iv( + devices_found[i], SCREEN_PROPERTY_TYPE, &type); - if (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD) + if ( + type == SCREEN_EVENT_GAMEPAD || + type == SCREEN_EVENT_JOYSTICK || + type == SCREEN_EVENT_KEYBOARD) { qnx->devices[qnx->pads_connected].handle = devices_found[i]; qnx->devices[qnx->pads_connected].index = qnx->pads_connected; @@ -219,7 +246,7 @@ static void initController(void *data, input_device_t* controller) if (qnx) { - // Initialize controller values. + /* Initialize controller values. */ #ifdef HAVE_BB10 controller->handle = 0; #endif @@ -227,8 +254,12 @@ static void initController(void *data, input_device_t* controller) controller->analogCount = 0; controller->buttonCount = 0; controller->buttons = 0; - controller->analog0[0] = controller->analog0[1] = controller->analog0[2] = 0; - controller->analog1[0] = controller->analog1[1] = controller->analog1[2] = 0; + controller->analog0[0] = 0; + controller->analog0[1] = 0; + controller->analog0[2] = 0; + controller->analog1[0] = 0; + controller->analog1[1] = 0; + controller->analog1[2] = 0; controller->port = -1; controller->device = -1; controller->index = -1; @@ -237,7 +268,8 @@ static void initController(void *data, input_device_t* controller) } } -static void qnx_input_autodetect_gamepad(void *data, input_device_t* controller, int port) +static void qnx_input_autodetect_gamepad(void *data, + input_device_t* controller, int port) { char name_buf[256]; qnx_input_t *qnx = (qnx_input_t*)data; @@ -247,11 +279,13 @@ static void qnx_input_autodetect_gamepad(void *data, input_device_t* controller, name_buf[0] = '\0'; - //ID: A-BBBB-CCCC-D.D - //A is the device's index in the array returned by screen_get_context_property_pv() - //BBBB is the device's Vendor ID (in hexadecimal) - //CCCC is the device's Product ID (also in hexadecimal) - //D.D is the device's version number + /* ID: A-BBBB-CCCC-D.D + * A is the device's index in the array + * returned by screen_get_context_property_pv() + * BBBB is the device's Vendor ID (in hexadecimal) + * CCCC is the device's Product ID (also in hexadecimal) + * D.D is the device's version number + */ if (controller) { #ifdef HAVE_BB10 @@ -269,7 +303,8 @@ static void qnx_input_autodetect_gamepad(void *data, input_device_t* controller, if (name_buf[0] != '\0') { - strlcpy(g_settings.input.device_names[port], name_buf, sizeof(g_settings.input.device_names[port])); + strlcpy(g_settings.input.device_names[port], + name_buf, sizeof(g_settings.input.device_names[port])); input_config_autoconfigure_joypad(port, name_buf, qnx->joypad); controller->port = port; @@ -293,18 +328,24 @@ static void process_keyboard_event(void *data, screen_event_t event, int type) scan = 0; cap = 0; - //Get Keyboard state - screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SYM, &sym); - screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_MODIFIERS, &modifiers); - screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_FLAGS, &flags); - screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SCAN, &scan); - screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap); + /* Get Keyboard state. */ + screen_get_event_property_iv(event, + SCREEN_PROPERTY_KEY_SYM, &sym); + screen_get_event_property_iv(event, + SCREEN_PROPERTY_KEY_MODIFIERS, &modifiers); + screen_get_event_property_iv(event, + SCREEN_PROPERTY_KEY_FLAGS, &flags); + screen_get_event_property_iv(event, + SCREEN_PROPERTY_KEY_SCAN, &scan); + screen_get_event_property_iv(event, + SCREEN_PROPERTY_KEY_CAP, &cap); #ifdef HAVE_BB10 - //Find device that pressed the key + /* Find device that pressed the key. */ screen_device_t device; - screen_get_event_property_pv(event, SCREEN_PROPERTY_DEVICE, (void**)&device); + screen_get_event_property_pv(event, + SCREEN_PROPERTY_DEVICE, (void**)&device); for (i = 0; i < MAX_PADS; ++i) { @@ -329,7 +370,9 @@ static void process_keyboard_event(void *data, screen_event_t event, int type) for (b = 0; b < RARCH_FIRST_CUSTOM_BIND; ++b) { - if ((unsigned int)g_settings.input.binds[controller->port][b].joykey == (unsigned int)(sym & 0xFF)) + if ((unsigned int) + g_settings.input.binds[controller->port][b].joykey + == (unsigned int)(sym & 0xFF)) { if (flags & KEY_DOWN) { @@ -341,8 +384,10 @@ static void process_keyboard_event(void *data, screen_event_t event, int type) } } - //TODO: Am I missing something? Is there a better way? - if((controller->port == 0) && ((unsigned int)g_settings.input.binds[0][RARCH_MENU_TOGGLE].joykey == (unsigned int)(sym&0xFF))) + /* TODO: Am I missing something? Is there a better way? */ + if((controller->port == 0) && ((unsigned int) + g_settings.input.binds[0][RARCH_MENU_TOGGLE].joykey + == (unsigned int)(sym&0xFF))) { if (flags & KEY_DOWN) g_extern.lifecycle_state ^= (1ULL << RARCH_MENU_TOGGLE); @@ -355,13 +400,15 @@ static void process_touch_event(void *data, screen_event_t event, int type) unsigned i, j; qnx_input_t *qnx = (qnx_input_t*)data; - screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, (int*)&contact_id); - screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, pos); + screen_get_event_property_iv(event, + SCREEN_PROPERTY_TOUCH_ID, (int*)&contact_id); + screen_get_event_property_iv(event, + SCREEN_PROPERTY_SOURCE_POSITION, pos); switch(type) { case SCREEN_EVENT_MTOUCH_TOUCH: - //Find a free touch struct + /* Find a free touch struct. */ for(i = 0; i < MAX_TOUCH; ++i) { if(qnx->pointer[i].contact_id == -1) @@ -370,25 +417,34 @@ static void process_touch_event(void *data, screen_event_t event, int type) input_translate_coord_viewport(pos[0], pos[1], &qnx->pointer[i].x, &qnx->pointer[i].y, &qnx->pointer[i].full_x, &qnx->pointer[i].full_y); - //Add this pointer to the map to signal it's valid + + /* Add this pointer to the map to signal it's valid. */ qnx->pointer[i].map = qnx->pointer_count; qnx->touch_map[qnx->pointer_count] = i; qnx->pointer_count++; break; } } - //printf("New Touch: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); - //printf("Map: %d %d %d %d %d %d\n", qnx->touch_map[0], qnx->touch_map[1], qnx->touch_map[2], qnx->touch_map[3], qnx->touch_map[4], qnx->touch_map[5]);fflush(stdout); +#if 0 + printf("New Touch: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id); + fflush(stdout); + printf("Map: %d %d %d %d %d %d\n", qnx->touch_map[0], qnx->touch_map[1], + qnx->touch_map[2], qnx->touch_map[3], qnx->touch_map[4], + qnx->touch_map[5]); + fflush(stdout); +#endif break; + case SCREEN_EVENT_MTOUCH_RELEASE: for(i = 0; i < MAX_TOUCH; ++i) { if(qnx->pointer[i].contact_id == contact_id) { - //Invalidate the finger + /* Invalidate the finger. */ qnx->pointer[i].contact_id = -1; - //Remove pointer from map and shift remaining valid ones to the front + /* Remove pointer from map and shift + * remaining valid ones to the front. */ qnx->touch_map[qnx->pointer[i].map] = -1; for(j = qnx->pointer[i].map; j < qnx->pointer_count; ++j) { @@ -400,19 +456,29 @@ static void process_touch_event(void *data, screen_event_t event, int type) break; } } - //printf("Release: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); - //printf("Map: %d %d %d %d %d %d\n", qnx->touch_map[0], qnx->touch_map[1], qnx->touch_map[2], qnx->touch_map[3], qnx->touch_map[4], qnx->touch_map[5]);fflush(stdout); +#if 0 + printf("Release: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id); + fflush(stdout); + printf("Map: %d %d %d %d %d %d\n", qnx->touch_map[0], qnx->touch_map[1], + qnx->touch_map[2], qnx->touch_map[3], qnx->touch_map[4], + qnx->touch_map[5]); + fflush(stdout); +#endif break; + case SCREEN_EVENT_MTOUCH_MOVE: - //Find the finger we're tracking and update + /* Find the finger we're tracking and update. */ for(i = 0; i < qnx->pointer_count; ++i) { if(qnx->pointer[i].contact_id == contact_id) { gl_t *gl = (gl_t*)driver.video_data; - //During a move, we can go ~30 pixel into the bezel which gives negative - //numbers or numbers larger than the screen res. Normalize. + /*During a move, we can go ~30 pixel into the + * bezel which gives negative numbers or + * numbers larger than the screen resolution. + * + * Normalize. */ if(pos[0] < 0) pos[0] = 0; if(pos[0] > gl->full_x) @@ -426,7 +492,11 @@ static void process_touch_event(void *data, screen_event_t event, int type) input_translate_coord_viewport(pos[0], pos[1], &qnx->pointer[i].x, &qnx->pointer[i].y, &qnx->pointer[i].full_x, &qnx->pointer[i].full_y); - //printf("Move: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); +#if 0 + printf("Move: x:%d, y:%d, id:%d\n", pos[0], pos[1], + contact_id); + fflush(stdout); +#endif break; } } @@ -459,7 +529,7 @@ static void handle_screen_event(void *data, bps_event_t *event) break; case SCREEN_EVENT_DEVICE: { - // A device was attached or removed. + /* A device was attached or removed. */ screen_device_t device; int attached, type, i; @@ -472,7 +542,11 @@ static void handle_screen_event(void *data, bps_event_t *event) screen_get_device_property_iv(device, SCREEN_PROPERTY_TYPE, &type); - if (attached && (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD)) + if (attached && ( + type == SCREEN_EVENT_GAMEPAD || + type == SCREEN_EVENT_JOYSTICK || + type == SCREEN_EVENT_KEYBOARD) + ) { for (i = 0; i < MAX_PADS; ++i) { @@ -490,7 +564,8 @@ static void handle_screen_event(void *data, bps_event_t *event) { if (device == qnx->devices[i].handle) { - RARCH_LOG("Device %s: Disconnected.\n", qnx->devices[i].id); + RARCH_LOG("Device %s: Disconnected.\n", + qnx->devices[i].id); initController(data, &qnx->devices[i]); break; } @@ -519,7 +594,7 @@ static void handle_navigator_event(void *data, bps_event_t *event) g_extern.lifecycle_state ^= (1ULL << RARCH_MENU_TOGGLE); break; case NAVIGATOR_EXIT: - //Catch this in thumbnail loop + /* Catch this in thumbnail loop. */ break; case NAVIGATOR_WINDOW_STATE: state = navigator_event_get_window_state(event); @@ -529,7 +604,7 @@ static void handle_navigator_event(void *data, bps_event_t *event) case NAVIGATOR_WINDOW_THUMBNAIL: for(;;) { - //Block until we get a resume or exit event + /* Block until we get a resume or exit event. */ rc = bps_get_event(&event_pause, -1); if(bps_event_get_code(event_pause) == NAVIGATOR_WINDOW_STATE) @@ -556,7 +631,6 @@ static void handle_navigator_event(void *data, bps_event_t *event) } } -//External Functions static void *qnx_input_init(void) { int i; @@ -579,11 +653,12 @@ static void *qnx_input_init(void) } #ifdef HAVE_BB10 - //Find currently connected gamepads + /* Find currently connected gamepads. */ discoverControllers(qnx); #else - //Initialize Playbook keyboard - strlcpy(qnx->devices[0].id, "0A5C-8502", sizeof(qnx->devices[0].id)); + /* Initialize Playbook keyboard. */ + strlcpy(qnx->devices[0].id, "0A5C-8502", + sizeof(qnx->devices[0].id)); qnx_input_autodetect_gamepad(qnx, &qnx->devices[0], 0); qnx->pads_connected = 1; #endif @@ -594,7 +669,7 @@ static void *qnx_input_init(void) static void qnx_input_poll(void *data) { (void)data; - //Request and process all available BPS events + /* Request and process all available BPS events. */ int rc, domain; @@ -620,19 +695,23 @@ static void qnx_input_poll(void *data) } } -static int16_t qnx_input_state(void *data, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id) +static int16_t qnx_input_state(void *data, + const struct retro_keybind **retro_keybinds, + unsigned port, unsigned device, unsigned index, unsigned id) { qnx_input_t *qnx = (qnx_input_t*)data; switch (device) { case RETRO_DEVICE_JOYPAD: - return input_joypad_pressed(qnx->joypad, port, (unsigned int)g_settings.input.binds[port], id); + return input_joypad_pressed(qnx->joypad, port, + (unsigned int)g_settings.input.binds[port], id); #ifdef HAVE_BB10 case RETRO_DEVICE_ANALOG: - //Need to return [-0x8000, 0x7fff] - //Gamepad API gives us [-128, 127] with (0,0) center - //Untested + /* Need to return [-0x8000, 0x7fff]. + * Gamepad API gives us [-128, 127] with (0,0) center + * Untested + */ if(qnx->port_device[port]) { switch ((index << 1) | id) @@ -659,7 +738,10 @@ static int16_t qnx_input_state(void *data, const struct retro_keybind **retro_ke case RETRO_DEVICE_ID_POINTER_Y: return qnx->pointer[qnx->touch_map[index]].full_y; case RETRO_DEVICE_ID_POINTER_PRESSED: - return (index < qnx->pointer_count) && (qnx->pointer[index].full_x != -0x8000) && (qnx->pointer[index].full_y != -0x8000); + return ( + index < qnx->pointer_count) + && (qnx->pointer[index].full_x != -0x8000) + && (qnx->pointer[index].full_y != -0x8000); default: return 0; } @@ -672,7 +754,10 @@ static int16_t qnx_input_state(void *data, const struct retro_keybind **retro_ke case RETRO_DEVICE_ID_POINTER_Y: return qnx->pointer[qnx->touch_map[index]].y; case RETRO_DEVICE_ID_POINTER_PRESSED: - return (index < qnx->pointer_count) && (qnx->pointer[index].x != -0x8000) && (qnx->pointer[index].y != -0x8000); + return ( + index < qnx->pointer_count) + && (qnx->pointer[index].x != -0x8000) + && (qnx->pointer[index].y != -0x8000); default: return 0; } diff --git a/input/qnx_input_joypad.c b/input/qnx_input_joypad.c index d268401bab..fead02ab6b 100644 --- a/input/qnx_input_joypad.c +++ b/input/qnx_input_joypad.c @@ -26,8 +26,10 @@ static bool qnx_joypad_init(void) for (autoconf_pad = 0; autoconf_pad < MAX_PLAYERS; autoconf_pad++) { - strlcpy(g_settings.input.device_names[autoconf_pad], "None", sizeof(g_settings.input.device_names[autoconf_pad])); - input_config_autoconfigure_joypad(autoconf_pad, qnx_joypad_name(autoconf_pad), qnx_joypad.ident); + strlcpy(g_settings.input.device_names[autoconf_pad], "None", + sizeof(g_settings.input.device_names[autoconf_pad])); + input_config_autoconfigure_joypad(autoconf_pad, + qnx_joypad_name(autoconf_pad), qnx_joypad.ident); } return true; @@ -69,10 +71,18 @@ static int16_t qnx_joypad_axis(unsigned port_num, uint32_t joyaxis) switch (axis) { - case 0: val = qnx->analog_state[port_num][0][0]; break; - case 1: val = qnx->analog_state[port_num][0][1]; break; - case 2: val = qnx->analog_state[port_num][1][0]; break; - case 3: val = qnx->analog_state[port_num][1][1]; break; + case 0: + val = qnx->analog_state[port_num][0][0]; + break; + case 1: + val = qnx->analog_state[port_num][0][1]; + break; + case 2: + val = qnx->analog_state[port_num][1][0]; + break; + case 3: + val = qnx->analog_state[port_num][1][1]; + break; } if (is_neg && val > 0) diff --git a/input/wiimote.c b/input/wiimote.c index df733c988a..9bd1b4a2b6 100644 --- a/input/wiimote.c +++ b/input/wiimote.c @@ -48,10 +48,18 @@ #include "wiimote.h" int wiimote_send(struct wiimote_t* wm, byte report_type, byte* msg, int len); -int wiimote_read_data(struct wiimote_t* wm, unsigned int addr, unsigned short len); -int wiimote_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len); + +int wiimote_read_data(struct wiimote_t* wm, unsigned int addr, + unsigned short len); + +int wiimote_write_data(struct wiimote_t* wm, unsigned int addr, + byte* data, byte len); + void wiimote_set_leds(struct wiimote_t* wm, int leds); -int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len); + +int classic_ctrl_handshake(struct wiimote_t* wm, + struct classic_ctrl_t* cc, byte* data, unsigned short len); + void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg); /** @@ -94,7 +102,8 @@ void wiimote_data_report(struct wiimote_t* wm, byte type) * @param wm Pointer to a wiimote_t structure. * @param leds What LEDs to enable. * - * \a leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, WIIMOTE_LED_3, or WIIMOTE_LED_4. + * \a leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, + * WIIMOTE_LED_3, or WIIMOTE_LED_4. */ void wiimote_set_leds(struct wiimote_t* wm, int leds) { @@ -159,7 +168,8 @@ void wiimote_handle_expansion(struct wiimote_t* wm, byte* msg) * The handshake will be concluded when the wiimote responds * with this data. */ -int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned short len) +int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, + unsigned short len) { if (!wm) return 0; @@ -171,8 +181,11 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned sh #endif switch (wm->handshake_state) { - case 0://no ha habido nunca handshake, debemos forzar un mensaje de staus para ver que pasa. + case 0: { + /* no ha habido nunca handshake, debemos forzar un + * mensaje de staus para ver que pasa. */ + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); wiimote_set_leds(wm, WIIMOTE_LED_NONE); @@ -182,19 +195,23 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned sh wm->handshake_state=1; return 0; } - case 1://estamos haciendo handshake o bien se necesita iniciar un nuevo handshake ya que se inserta(quita una expansion. + case 1: { + /* estamos haciendo handshake o bien se necesita iniciar un + * nuevo handshake ya que se inserta(quita una expansion. */ int attachment = 0; if(event != WM_RPT_CTRL_STATUS) return 0; /* is an attachment connected to the expansion port? */ - if ((data[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT) + if ((data[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == + WM_CTRL_STATUS_BYTE1_ATTACHMENT) attachment = 1; #ifdef WIIMOTE_DBG - printf("attachment %d %d\n",attachment,WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)); + printf("attachment %d %d\n",attachment, + WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)); #endif /* expansion port */ @@ -213,25 +230,33 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned sh printf("rehandshake\n"); #endif WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);//forzamos un handshake por si venimos de un hanshake completo + /* forzamos un handshake por si venimos + * de un hanshake completo. */ + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); } byte buf; - //Old way. initialize the extension was by writing the single encryption byte 0x00 to 0x(4)A40040 - //buf = 0x00; - //wiimote_write_data(wm, WM_EXP_MEM_ENABLE, &buf, 1); + /*Old way. initialize the extension was by writing the + * single encryption byte 0x00 to 0x(4)A40040. */ +#if 0 + buf = 0x00; + wiimote_write_data(wm, WM_EXP_MEM_ENABLE, &buf, 1); +#endif - //NEW WAY 0x55 to 0x(4)A400F0, then writing 0x00 to 0x(4)A400FB. (support clones) + /* NEW WAY 0x55 to 0x(4)A400F0, then writing + * 0x00 to 0x(4)A400FB. (support clones) */ buf = 0x55; wiimote_write_data(wm, 0x04A400F0, &buf, 1); usleep(100000); buf = 0x00; wiimote_write_data(wm, 0x04A400FB, &buf, 1); - //check extension type! + /* check extension type! */ usleep(100000); wiimote_read_data(wm, WM_EXP_MEM_CALIBR+220, 4); - //wiimote_read_data(wm, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); +#if 0 + wiimote_read_data(wm, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); +#endif wm->handshake_state = 4; return 0; @@ -249,7 +274,9 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned sh printf("rehandshake\n"); #endif WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);//forzamos un handshake por si venimos de un hanshake completo + /* forzamos un handshake por si venimos + * de un hanshake completo. */ + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); } } @@ -261,8 +288,9 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned sh return 0; } - case 2://find handshake no expansion + case 2: { + /* find handshake no expansion. */ #ifdef WIIMOTE_DBG printf("Finalizado HANDSHAKE SIN EXPANSION\n"); #endif @@ -270,8 +298,9 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned sh wm->handshake_state = 6; continue; } - case 3://find handshake expansion + case 3: { + /* Find handshake expansion. */ #ifdef WIIMOTE_DBG printf("Finalizado HANDSHAKE CON EXPANSION\n"); #endif @@ -289,17 +318,20 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned sh #ifdef WIIMOTE_DBG printf("Expansion id=0x%04x\n",id); #endif - - if(id!=/*EXP_ID_CODE_CLASSIC_CONTROLLER*/0xa4200101) + /*EXP_ID_CODE_CLASSIC_CONTROLLER*/ + if(id != 0xa4200101) { wm->handshake_state = 2; - //WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); +#if 0 + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); +#endif continue; } else { usleep(100000); - wiimote_read_data(wm, WM_EXP_MEM_CALIBR, 16);//pedimos datos de calibracion del JOY! + /* pedimos datos de calibracion del JOY! */ + wiimote_read_data(wm, WM_EXP_MEM_CALIBR, 16); wm->handshake_state = 5; } @@ -384,13 +416,14 @@ int wiimote_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) * to a pending list and be sent out when the previous * finishes. */ -int wiimote_read_data(struct wiimote_t* wm, unsigned int addr, unsigned short len) +int wiimote_read_data(struct wiimote_t* wm, unsigned int addr, + unsigned short len) { - //No puden ser mas de 16 lo leido o vendra en trozos! + /* No puden ser mas de 16 lo leido o vendra en trozos! */ if (!wm || !WIIMOTE_IS_CONNECTED(wm)) return 0; - if (!len /*|| len > 16*/) + if (!len) return 0; byte buf[6]; @@ -417,7 +450,8 @@ int wiimote_read_data(struct wiimote_t* wm, unsigned int addr, unsigned short le * @param data The data to be written to the memory location. * @param len The length of the block to be written. */ -int wiimote_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len) +int wiimote_write_data(struct wiimote_t* wm, + unsigned int addr, byte* data, byte len) { byte buf[21] = {0}; /* the payload is always 23 */ @@ -449,10 +483,8 @@ int wiimote_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte return 1; } - -/////////////////////// CLASSIC ///////////////// - -int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) +int classic_ctrl_handshake(struct wiimote_t* wm, + struct classic_ctrl_t* cc, byte* data, unsigned short len) { memset(cc, 0, sizeof(*cc)); wm->exp.type = EXP_CLASSIC; @@ -479,9 +511,11 @@ static void process_axis(struct axis_t* axis, byte raw) axis->raw_value = raw; if (raw < axis->center) - axis->value = -normalize_and_interpolate(axis->center, axis->min, raw); + axis->value = -normalize_and_interpolate( + axis->center, axis->min, raw); else if (raw > axis->center) - axis->value = normalize_and_interpolate(axis->center, axis->max, raw); + axis->value = normalize_and_interpolate( + axis->center, axis->max, raw); else axis->value = 0; } @@ -491,6 +525,7 @@ void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg) cc->btns = ~BIG_ENDIAN_SHORT(*(short*)(msg + 4)) & CLASSIC_CTRL_BUTTON_ALL; process_axis(&cc->ljs.x, (msg[0] & 0x3F)); process_axis(&cc->ljs.y, (msg[1] & 0x3F)); - process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) | ((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7)); + process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) | + ((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7)); process_axis(&cc->rjs.y, (msg[2] & 0x1F)); } diff --git a/input/wiimote.h b/input/wiimote.h index fa9a5d5f1e..129e0cdc22 100644 --- a/input/wiimote.h +++ b/input/wiimote.h @@ -188,7 +188,9 @@ extern "C" { #define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s)) #define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) -int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned short len); +int wiimote_handshake(struct wiimote_t* wm, + byte event, byte* data, unsigned short len); + void wiimote_status(struct wiimote_t* wm); void wiimote_data_report(struct wiimote_t* wm, byte type); void wiimote_pressed_buttons(struct wiimote_t* wm, byte* msg); diff --git a/input/winxinput_joypad.c b/input/winxinput_joypad.c index 70b1078bb9..5d37d42319 100644 --- a/input/winxinput_joypad.c +++ b/input/winxinput_joypad.c @@ -291,24 +291,26 @@ static bool winxinput_joypad_button (unsigned port_num, uint16_t joykey) if (!(g_winxinput_states[xplayer].connected)) return false; - //return false; - uint16_t btn_word = g_winxinput_states[xplayer].xstate.Gamepad.wButtons; if (GET_HAT_DIR(joykey)) { switch (GET_HAT_DIR(joykey)) { - case HAT_UP_MASK: return btn_word & XINPUT_GAMEPAD_DPAD_UP; - case HAT_DOWN_MASK: return btn_word & XINPUT_GAMEPAD_DPAD_DOWN; - case HAT_LEFT_MASK: return btn_word & XINPUT_GAMEPAD_DPAD_LEFT; - case HAT_RIGHT_MASK: return btn_word & XINPUT_GAMEPAD_DPAD_RIGHT; + case HAT_UP_MASK: + return btn_word & XINPUT_GAMEPAD_DPAD_UP; + case HAT_DOWN_MASK: + return btn_word & XINPUT_GAMEPAD_DPAD_DOWN; + case HAT_LEFT_MASK: + return btn_word & XINPUT_GAMEPAD_DPAD_LEFT; + case HAT_RIGHT_MASK: + return btn_word & XINPUT_GAMEPAD_DPAD_RIGHT; } - return false; // hat requested and no hat button down + return false; /* hat requested and no hat button down. */ } else { - // non-hat button + /* non-hat button. */ unsigned num_buttons = g_winxinput_guide_button_supported ? 11 : 10; if (joykey < num_buttons) @@ -336,7 +338,8 @@ static int16_t winxinput_joypad_axis (unsigned port_num, uint32_t joyaxis) bool is_neg = false; bool is_pos = false; - if (AXIS_NEG_GET(joyaxis) <= 3) // triggers (axes 4,5) cannot be negative + /* triggers (axes 4,5) cannot be negative */ + if (AXIS_NEG_GET(joyaxis) <= 3) { axis = AXIS_NEG_GET(joyaxis); is_neg = true; @@ -351,13 +354,24 @@ static int16_t winxinput_joypad_axis (unsigned port_num, uint32_t joyaxis) switch (axis) { - case 0: val = pad->sThumbLX; break; - case 1: val = pad->sThumbLY; break; - case 2: val = pad->sThumbRX; break; - case 3: val = pad->sThumbRY; break; - - case 4: val = pad->bLeftTrigger * 32767 / 255; break; // map 0..255 to 0..32767 - case 5: val = pad->bRightTrigger * 32767 / 255; break; + case 0: + val = pad->sThumbLX; + break; + case 1: + val = pad->sThumbLY; + break; + case 2: + val = pad->sThumbRX; + break; + case 3: + val = pad->sThumbRY; + break; + case 4: + val = pad->bLeftTrigger * 32767 / 255; + break; /* map 0..255 to 0..32767 */ + case 5: + val = pad->bRightTrigger * 32767 / 255; + break; } if (is_neg && val > 0) @@ -365,7 +379,7 @@ static int16_t winxinput_joypad_axis (unsigned port_num, uint32_t joyaxis) else if (is_pos && val < 0) val = 0; - // Clamp to avoid overflow error + /* Clamp to avoid overflow error. */ if (val == -32768) val = -32767; @@ -376,14 +390,23 @@ static void winxinput_joypad_poll(void) { unsigned i; for (i = 0; i < 4; ++i) + { if (g_winxinput_states[i].connected) - if (g_XInputGetStateEx(i, &(g_winxinput_states[i].xstate)) == ERROR_DEVICE_NOT_CONNECTED) + { + if (g_XInputGetStateEx(i, + &(g_winxinput_states[i].xstate)) + == ERROR_DEVICE_NOT_CONNECTED) + { g_winxinput_states[i].connected = false; + } + } + } dinput_joypad.poll(); } -static bool winxinput_joypad_rumble(unsigned pad, enum retro_rumble_effect effect, uint16_t strength) +static bool winxinput_joypad_rumble(unsigned pad, + enum retro_rumble_effect effect, uint16_t strength) { int xplayer = pad_index_to_xplayer_index(pad); if (xplayer == -1) @@ -393,14 +416,14 @@ static bool winxinput_joypad_rumble(unsigned pad, enum retro_rumble_effect effec return false; } - - // Consider the low frequency (left) motor the "strong" one. + /* Consider the low frequency (left) motor the "strong" one. */ if (effect == RETRO_RUMBLE_STRONG) g_xinput_rumble_states[xplayer].wLeftMotorSpeed = strength; else if (effect == RETRO_RUMBLE_WEAK) g_xinput_rumble_states[xplayer].wRightMotorSpeed = strength; - return g_XInputSetState(xplayer, &g_xinput_rumble_states[xplayer]) == ERROR_SUCCESS; + return g_XInputSetState(xplayer, &g_xinput_rumble_states[xplayer]) + == ERROR_SUCCESS; } const rarch_joypad_driver_t winxinput_joypad = { diff --git a/input/x11_input.c b/input/x11_input.c index ed2e1d666e..b6f04e92d1 100644 --- a/input/x11_input.c +++ b/input/x11_input.c @@ -53,7 +53,7 @@ static void *x_input_init(void) if (!x11) return NULL; - // Borrow the active X window ... + /* Borrow the active X window ... */ x11->display = (Display*)driver.video_display; x11->win = (Window)driver.video_window; @@ -74,7 +74,8 @@ static bool x_key_pressed(x11_input_t *x11, int key) return ret; } -static bool x_is_pressed(x11_input_t *x11, const struct retro_keybind *binds, unsigned id) +static bool x_is_pressed(x11_input_t *x11, + const struct retro_keybind *binds, unsigned id) { if (id < RARCH_BIND_LIST_END) { @@ -84,7 +85,8 @@ static bool x_is_pressed(x11_input_t *x11, const struct retro_keybind *binds, un return false; } -static int16_t x_pressed_analog(x11_input_t *x11, const struct retro_keybind *binds, unsigned index, unsigned id) +static int16_t x_pressed_analog(x11_input_t *x11, + const struct retro_keybind *binds, unsigned index, unsigned id) { unsigned id_minus = 0; unsigned id_plus = 0; @@ -125,7 +127,8 @@ static int16_t x_mouse_state(x11_input_t *x11, unsigned id) } } -static int16_t x_pointer_state(x11_input_t *x11, unsigned index, unsigned id, bool screen) +static int16_t x_pointer_state(x11_input_t *x11, + unsigned index, unsigned id, bool screen) { if (index != 0) return 0; @@ -184,7 +187,9 @@ static int16_t x_lightgun_state(x11_input_t *x11, unsigned id) } } -static int16_t x_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id) +static int16_t x_input_state(void *data, + const struct retro_keybind **binds, unsigned port, + unsigned device, unsigned index, unsigned id) { x11_input_t *x11 = (x11_input_t*)data; int16_t ret; @@ -201,7 +206,8 @@ static int16_t x_input_state(void *data, const struct retro_keybind **binds, uns case RETRO_DEVICE_ANALOG: ret = x_pressed_analog(x11, binds[port], index, id); if (!ret) - ret = input_joypad_analog(x11->joypad, port, index, id, binds[port]); + ret = input_joypad_analog(x11->joypad, port, index, + id, binds[port]); return ret; case RETRO_DEVICE_MOUSE: @@ -209,7 +215,8 @@ static int16_t x_input_state(void *data, const struct retro_keybind **binds, uns case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: - return x_pointer_state(x11, index, id, device == RARCH_DEVICE_POINTER_SCREEN); + return x_pointer_state(x11, index, id, + device == RARCH_DEVICE_POINTER_SCREEN); case RETRO_DEVICE_LIGHTGUN: return x_lightgun_state(x11, id); @@ -253,7 +260,7 @@ static void x_input_poll_mouse(x11_input_t *x11) x11->mouse_wu = mask & Button4Mask; x11->mouse_wd = mask & Button5Mask; - // Somewhat hacky, but seem to do the job. + /* Somewhat hacky, but seem to do the job. */ if (x11->grab_mouse && driver.video->focus(driver.video_data)) { struct rarch_viewport vp = {0}; @@ -295,7 +302,8 @@ static void x_grab_mouse(void *data, bool state) x11->grab_mouse = state; } -static bool x_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, uint16_t strength) +static bool x_set_rumble(void *data, unsigned port, + enum retro_rumble_effect effect, uint16_t strength) { x11_input_t *x11 = (x11_input_t*)data; return input_joypad_set_rumble(x11->joypad, port, effect, strength); diff --git a/input/xdk_xinput_input.c b/input/xdk_xinput_input.c index 8b7d4783db..64590089f1 100644 --- a/input/xdk_xinput_input.c +++ b/input/xdk_xinput_input.c @@ -46,7 +46,9 @@ static void xdk_input_poll(void *data) #if defined(_XBOX1) unsigned int dwInsertions, dwRemovals; - XGetDeviceChanges(XDEVICE_TYPE_GAMEPAD, reinterpret_cast(&dwInsertions), reinterpret_cast(&dwRemovals)); + XGetDeviceChanges(XDEVICE_TYPE_GAMEPAD, + reinterpret_cast(&dwInsertions), + reinterpret_cast(&dwRemovals)); #endif for (unsigned port = 0; port < MAX_PADS; port++) @@ -54,13 +56,15 @@ static void xdk_input_poll(void *data) #ifdef _XBOX1 XINPUT_CAPABILITIES caps[MAX_PADS]; (void)caps; - // handle removed devices + + /* handle removed devices. */ xdk->bRemoved[port] = (dwRemovals & (1 << port)) ? true : false; if(xdk->bRemoved[port]) { - // if the controller was removed after XGetDeviceChanges but before - // XInputOpen, the device handle will be NULL + /* if the controller was removed after + * XGetDeviceChanges but before + * XInputOpen, the device handle will be NULL. */ if(xdk->gamepads[port]) XInputClose(xdk->gamepads[port]); @@ -68,7 +72,7 @@ static void xdk_input_poll(void *data) xdk->pad_state[port] = 0; } - // handle inserted devices + /* handle inserted devices. */ xdk->bInserted[port] = (dwInsertions & (1 << port)) ? true : false; if(xdk->bInserted[port]) @@ -78,14 +82,16 @@ static void xdk_input_poll(void *data) m_pollingParameters.fInterruptOut = TRUE; m_pollingParameters.bInputInterval = 8; m_pollingParameters.bOutputInterval = 8; - xdk->gamepads[port] = XInputOpen(XDEVICE_TYPE_GAMEPAD, port, XDEVICE_NO_SLOT, NULL); + xdk->gamepads[port] = XInputOpen(XDEVICE_TYPE_GAMEPAD, port, + XDEVICE_NO_SLOT, NULL); } if (!xdk->gamepads[port]) continue; - // if the controller is removed after XGetDeviceChanges but before - // XInputOpen, the device handle will be NULL + /* if the controller is removed after + * XGetDeviceChanges but before XInputOpen, + * the device handle will be NULL. */ #endif XINPUT_STATE state_tmp; @@ -194,7 +200,7 @@ static void *xdk_input_init(void) xdk->dwDeviceMask = XGetDevices(XDEVICE_TYPE_GAMEPAD); - //Check the device status + /* Check the device status. */ switch(XGetDeviceEnumerationStatus()) { case XDEVICE_ENUMERATION_IDLE: @@ -215,7 +221,8 @@ static void *xdk_input_init(void) static bool xdk_input_key_pressed(void *data, int key) { xdk_input_t *xdk = (xdk_input_t*)data; - return (g_extern.lifecycle_state & (1ULL << key)) || input_joypad_pressed(xdk->joypad, 0, g_settings.input.binds[0], key); + return (g_extern.lifecycle_state & (1ULL << key)) || + input_joypad_pressed(xdk->joypad, 0, g_settings.input.binds[0], key); } static uint64_t xdk_input_get_capabilities(void *data) @@ -228,9 +235,11 @@ static uint64_t xdk_input_get_capabilities(void *data) return caps; } -// FIXME - are we sure about treating low frequency motor as the "strong" motor? Does it apply for Xbox too? +/* FIXME - are we sure about treating low frequency motor as the + * "strong" motor? Does it apply for Xbox too? */ -static bool xdk_input_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, uint16_t strength) +static bool xdk_input_set_rumble(void *data, unsigned port, + enum retro_rumble_effect effect, uint16_t strength) { xdk_input_t *xdk = (xdk_input_t*)data; (void)xdk; diff --git a/input/xdk_xinput_input_joypad.c b/input/xdk_xinput_input_joypad.c index 8e0381807c..36b7b45bac 100644 --- a/input/xdk_xinput_input_joypad.c +++ b/input/xdk_xinput_input_joypad.c @@ -33,8 +33,11 @@ static bool xdk_joypad_init(void) for (autoconf_pad = 0; autoconf_pad < MAX_PLAYERS; autoconf_pad++) { - strlcpy(g_settings.input.device_names[autoconf_pad], "XInput Controller", sizeof(g_settings.input.device_names[autoconf_pad])); - input_config_autoconfigure_joypad(autoconf_pad, xdk_joypad_name(autoconf_pad), xdk_joypad.ident); + strlcpy(g_settings.input.device_names[autoconf_pad], + "XInput Controller", + sizeof(g_settings.input.device_names[autoconf_pad])); + input_config_autoconfigure_joypad(autoconf_pad, + xdk_joypad_name(autoconf_pad), xdk_joypad.ident); } return true; @@ -75,10 +78,18 @@ static int16_t xdk_joypad_axis(unsigned port_num, uint32_t joyaxis) switch (axis) { - case 0: val = xdk->analog_state[port_num][0][0]; break; - case 1: val = xdk->analog_state[port_num][0][1]; break; - case 2: val = xdk->analog_state[port_num][1][0]; break; - case 3: val = xdk->analog_state[port_num][1][1]; break; + case 0: + val = xdk->analog_state[port_num][0][0]; + break; + case 1: + val = xdk->analog_state[port_num][0][1]; + break; + case 2: + val = xdk->analog_state[port_num][1][0]; + break; + case 3: + val = xdk->analog_state[port_num][1][1]; + break; } if (is_neg && val > 0)