|
@@ -50,6 +50,7 @@ typedef struct
|
|
|
SDL_HIDAPI_Device *device;
|
|
|
SDL_Joystick *joystick;
|
|
|
SDL_bool is_shanwan;
|
|
|
+ SDL_bool has_analog_buttons;
|
|
|
SDL_bool report_sensors;
|
|
|
SDL_bool effects_updated;
|
|
|
int player_index;
|
|
@@ -145,6 +146,7 @@ static SDL_bool HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
|
|
|
}
|
|
|
ctx->device = device;
|
|
|
ctx->is_shanwan = is_shanwan;
|
|
|
+ ctx->has_analog_buttons = SDL_TRUE;
|
|
|
|
|
|
device->context = ctx;
|
|
|
|
|
@@ -247,7 +249,10 @@ static SDL_bool HIDAPI_DriverPS3_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy
|
|
|
|
|
|
/* Initialize the joystick capabilities */
|
|
|
joystick->nbuttons = 15;
|
|
|
- joystick->naxes = 16;
|
|
|
+ joystick->naxes = 6;
|
|
|
+ if (ctx->has_analog_buttons) {
|
|
|
+ joystick->naxes += 10;
|
|
|
+ }
|
|
|
joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
|
|
|
|
|
|
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 100.0f);
|
|
@@ -432,7 +437,7 @@ static void HIDAPI_DriverPS3_HandleStatePacket(SDL_Joystick *joystick, SDL_Drive
|
|
|
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
|
|
|
|
|
|
/* Buttons are mapped as axes in the order they appear in the button enumeration */
|
|
|
- {
|
|
|
+ if (ctx->has_analog_buttons) {
|
|
|
static int button_axis_offsets[] = {
|
|
|
24, /* SDL_CONTROLLER_BUTTON_A */
|
|
|
23, /* SDL_CONTROLLER_BUTTON_B */
|
|
@@ -617,6 +622,11 @@ static SDL_bool HIDAPI_DriverPS3ThirdParty_InitDevice(SDL_HIDAPI_Device *device)
|
|
|
return SDL_FALSE;
|
|
|
}
|
|
|
ctx->device = device;
|
|
|
+ if (device->vendor_id == USB_VENDOR_SWITCH && device->product_id == USB_PRODUCT_SWITCH_RETROBIT_CONTROLLER) {
|
|
|
+ ctx->has_analog_buttons = SDL_FALSE;
|
|
|
+ } else {
|
|
|
+ ctx->has_analog_buttons = SDL_TRUE;
|
|
|
+ }
|
|
|
|
|
|
device->context = ctx;
|
|
|
|
|
@@ -650,8 +660,17 @@ static SDL_bool HIDAPI_DriverPS3ThirdParty_OpenJoystick(SDL_HIDAPI_Device *devic
|
|
|
|
|
|
/* Initialize the joystick capabilities */
|
|
|
joystick->nbuttons = 15;
|
|
|
- joystick->naxes = 16;
|
|
|
- joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
|
|
|
+ joystick->naxes = 6;
|
|
|
+ if (ctx->has_analog_buttons) {
|
|
|
+ joystick->naxes += 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (device->vendor_id == USB_VENDOR_SWITCH && device->product_id == USB_PRODUCT_SWITCH_RETROBIT_CONTROLLER) {
|
|
|
+ // This is a wireless controller using a USB dongle
|
|
|
+ joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
|
|
|
+ } else {
|
|
|
+ joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
|
|
|
+ }
|
|
|
|
|
|
return SDL_TRUE;
|
|
|
}
|
|
@@ -762,7 +781,7 @@ static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket18(SDL_Joystick *joystic
|
|
|
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
|
|
|
|
|
|
/* Buttons are mapped as axes in the order they appear in the button enumeration */
|
|
|
- {
|
|
|
+ if (ctx->has_analog_buttons) {
|
|
|
static int button_axis_offsets[] = {
|
|
|
12, /* SDL_GAMEPAD_BUTTON_A */
|
|
|
11, /* SDL_GAMEPAD_BUTTON_B */
|
|
@@ -871,9 +890,17 @@ static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket19(SDL_Joystick *joystic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- axis = ((int)data[17] * 257) - 32768;
|
|
|
+ if (data[0] & 0x40) {
|
|
|
+ axis = 32767;
|
|
|
+ } else {
|
|
|
+ axis = ((int)data[17] * 257) - 32768;
|
|
|
+ }
|
|
|
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, axis);
|
|
|
- axis = ((int)data[18] * 257) - 32768;
|
|
|
+ if (data[0] & 0x80) {
|
|
|
+ axis = 32767;
|
|
|
+ } else {
|
|
|
+ axis = ((int)data[18] * 257) - 32768;
|
|
|
+ }
|
|
|
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, axis);
|
|
|
axis = ((int)data[3] * 257) - 32768;
|
|
|
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_LEFTX, axis);
|
|
@@ -885,7 +912,7 @@ static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket19(SDL_Joystick *joystic
|
|
|
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
|
|
|
|
|
|
/* Buttons are mapped as axes in the order they appear in the button enumeration */
|
|
|
- {
|
|
|
+ if (ctx->has_analog_buttons) {
|
|
|
static int button_axis_offsets[] = {
|
|
|
13, /* SDL_CONTROLLER_BUTTON_A */
|
|
|
12, /* SDL_CONTROLLER_BUTTON_B */
|