Added infrastructure for reporting GameInput sensors

IGameInputReading::GetMotionState() isn't implemented yet, so we'll need to figure out how to interpret the motion data once it's available.
main
Sam Lantinga 2024-02-17 19:40:42 -08:00
parent 85ac0381b7
commit 419aebebda
1 changed files with 18 additions and 1 deletions

View File

@ -40,6 +40,7 @@ typedef struct GAMEINPUT_InternalDevice
SDL_JoystickGUID guid; /* generated by SDL */ SDL_JoystickGUID guid; /* generated by SDL */
SDL_JoystickID device_instance; /* generated by SDL */ SDL_JoystickID device_instance; /* generated by SDL */
SDL_bool wireless; SDL_bool wireless;
SDL_bool sensors_supported;
GameInputRumbleMotors supportedRumbleMotors; GameInputRumbleMotors supportedRumbleMotors;
SDL_bool isAdded; SDL_bool isAdded;
SDL_bool isDeleteRequested; SDL_bool isDeleteRequested;
@ -54,6 +55,7 @@ typedef struct GAMEINPUT_InternalList
typedef struct joystick_hwdata typedef struct joystick_hwdata
{ {
GAMEINPUT_InternalDevice *devref; GAMEINPUT_InternalDevice *devref;
SDL_bool report_sensors;
GameInputRumbleParams rumbleParams; GameInputRumbleParams rumbleParams;
} GAMEINPUT_InternalJoystickHwdata; } GAMEINPUT_InternalJoystickHwdata;
@ -123,6 +125,7 @@ static int GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice)
elem->guid = SDL_CreateJoystickGUID(bus, vendor, product, version, "GameInput", "Gamepad", 'g', 0); elem->guid = SDL_CreateJoystickGUID(bus, vendor, product, version, "GameInput", "Gamepad", 'g', 0);
elem->device_instance = SDL_GetNextObjectID(); elem->device_instance = SDL_GetNextObjectID();
elem->wireless = (devinfo->capabilities & GameInputDeviceCapabilityWireless); elem->wireless = (devinfo->capabilities & GameInputDeviceCapabilityWireless);
elem->sensors_supported = (devinfo->supportedInput & GameInputKindMotion);
elem->supportedRumbleMotors = devinfo->supportedRumbleMotors; elem->supportedRumbleMotors = devinfo->supportedRumbleMotors;
g_GameInputList.devices = devicelist; g_GameInputList.devices = devicelist;
@ -373,6 +376,12 @@ static int GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_TRUE); SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_TRUE);
} }
if (elem->sensors_supported) {
/* FIXME: What's the sensor update rate? */
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 250.0f);
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 250.0f);
}
if (elem->wireless) { if (elem->wireless) {
joystick->epowerlevel = GAMEINPUT_InternalGetPowerLevel(elem->device); joystick->epowerlevel = GAMEINPUT_InternalGetPowerLevel(elem->device);
} else { } else {
@ -415,7 +424,7 @@ static int GAMEINPUT_JoystickSendEffect(SDL_Joystick *joystick, const void *data
static int GAMEINPUT_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled) static int GAMEINPUT_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
{ {
/* I am not sure what is this even supposed to do in case of GameInput... */ joystick->hwdata->report_sensors = enabled;
return 0; return 0;
} }
@ -483,6 +492,14 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick)
#undef CONVERT_TRIGGER #undef CONVERT_TRIGGER
} }
if (hwdata->report_sensors) {
GameInputMotionState motion_state;
if (IGameInputReading_GetMotionState(reading, &motion_state)) {
/* FIXME: How do we interpret the motion data? */
}
}
IGameInputReading_Release(reading); IGameInputReading_Release(reading);
if (joystick->epowerlevel != SDL_JOYSTICK_POWER_WIRED) { if (joystick->epowerlevel != SDL_JOYSTICK_POWER_WIRED) {