joystick: Plumb SDL_JoystickSendEffect() for the Shield HIDAPI driver

The effect data format consists of one command byte followed by zero or more
payload bytes.
This commit is contained in:
Cameron Gutman 2022-07-11 19:37:25 -05:00
parent deca77c166
commit a0d8848baa
1 changed files with 13 additions and 3 deletions
src/joystick/hidapi

View File

@ -103,13 +103,13 @@ HIDAPI_DriverShield_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_Joystick
} }
static int static int
HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd, Uint8* data, int size) HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd, const void *data, int size)
{ {
SDL_DriverShield_Context *ctx = device->context; SDL_DriverShield_Context *ctx = device->context;
Uint8 cmd_pkt[HID_REPORT_SIZE]; Uint8 cmd_pkt[HID_REPORT_SIZE];
if (size >= sizeof(cmd_pkt) - 3) { if (size >= sizeof(cmd_pkt) - 3) {
return SDL_SetError("Invalid command data"); return SDL_SetError("Command data exceeds HID report size");
} }
if (SDL_HIDAPI_LockRumble() < 0) { if (SDL_HIDAPI_LockRumble() < 0) {
@ -221,7 +221,17 @@ HIDAPI_DriverShield_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joys
static int static int
HIDAPI_DriverShield_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) HIDAPI_DriverShield_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
{ {
return SDL_Unsupported(); const Uint8 *data_bytes = data;
if (size > 1) {
/* Single command byte followed by a variable length payload */
return HIDAPI_DriverShield_SendCommand(device, data_bytes[0], &data_bytes[1], size - 1);
} else if (size == 1) {
/* Single command byte with no payload */
return HIDAPI_DriverShield_SendCommand(device, data_bytes[0], NULL, 0);
} else {
return SDL_SetError("Effect data must at least contain a command byte");
}
} }
static int static int