From 1577366c3690b140c294c2762687b7793881da3f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 8 Nov 2020 23:49:03 -0800 Subject: [PATCH] Fixed duplicated switch statement processing Xbox controller dpad state --- src/joystick/hidapi/SDL_hidapi_xbox360.c | 36 ++---------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 8b27de507..4ae30e4f3 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -845,44 +845,12 @@ HIDAPI_DriverXbox360_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_bool dpad_down = SDL_FALSE; SDL_bool dpad_left = SDL_FALSE; SDL_bool dpad_right = SDL_FALSE; + Uint8 dpad_state = (((data[11] >> 2) & 0x0F) | (data[12] & 0x0F)); SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_LEFTSTICK, (data[11] & 0x01) ? SDL_PRESSED : SDL_RELEASED); SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_RIGHTSTICK, (data[11] & 0x02) ? SDL_PRESSED : SDL_RELEASED); - switch (data[11] & 0x3C) { - case 4: - dpad_up = SDL_TRUE; - break; - case 8: - dpad_up = SDL_TRUE; - dpad_right = SDL_TRUE; - break; - case 12: - dpad_right = SDL_TRUE; - break; - case 16: - dpad_right = SDL_TRUE; - dpad_down = SDL_TRUE; - break; - case 20: - dpad_down = SDL_TRUE; - break; - case 24: - dpad_left = SDL_TRUE; - dpad_down = SDL_TRUE; - break; - case 28: - dpad_left = SDL_TRUE; - break; - case 32: - dpad_up = SDL_TRUE; - dpad_left = SDL_TRUE; - break; - default: - break; - } - - switch (data[12] & 0x0F) { + switch (dpad_state) { case 1: dpad_up = SDL_TRUE; break;