Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/joystick_hid.c | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index e2c1a125903..fc991f5f093 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -138,6 +138,13 @@ struct pid_set_condition struct hid_value_caps *dead_band_caps; };
+struct pid_set_constant_force +{ + BYTE id; + ULONG collection; + struct hid_value_caps *magnitude_caps; +}; + #define DEVICE_STATE_MAX_SIZE 1024
struct hid_joystick @@ -173,6 +180,7 @@ struct hid_joystick struct pid_set_periodic pid_set_periodic; struct pid_set_envelope pid_set_envelope; struct pid_set_condition pid_set_condition; + struct pid_set_constant_force pid_set_constant_force; };
static inline struct hid_joystick *impl_from_IDirectInputDevice8W( IDirectInputDevice8W *iface ) @@ -193,6 +201,7 @@ struct hid_joystick_effect
DWORD axes[6]; LONG directions[6]; + DICONSTANTFORCE constant_force; DICONDITION condition[2]; DIENVELOPE envelope; DIPERIODIC periodic; @@ -1912,6 +1921,7 @@ static BOOL init_data_format( struct hid_joystick *impl, struct hid_value_caps * static BOOL init_pid_reports( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { + struct pid_set_constant_force *set_constant_force = &impl->pid_set_constant_force; struct pid_control_report *device_control = &impl->pid_device_control; struct pid_control_report *effect_control = &impl->pid_effect_control; struct pid_effect_update *effect_update = &impl->pid_effect_update; @@ -1946,6 +1956,7 @@ static BOOL init_pid_reports( struct hid_joystick *impl, struct hid_value_caps * case PID_USAGE_SET_PERIODIC_REPORT: SET_COLLECTION( set_periodic ); break; case PID_USAGE_SET_ENVELOPE_REPORT: SET_COLLECTION( set_envelope ); break; case PID_USAGE_SET_CONDITION_REPORT: SET_COLLECTION( set_condition ); break; + case PID_USAGE_SET_CONSTANT_FORCE_REPORT: SET_COLLECTION( set_constant_force ); break;
case PID_USAGE_DEVICE_CONTROL: SET_SUB_COLLECTION( device_control, control_coll ); break; case PID_USAGE_EFFECT_OPERATION: SET_SUB_COLLECTION( effect_control, control_coll ); break; @@ -1967,6 +1978,7 @@ static BOOL init_pid_reports( struct hid_joystick *impl, struct hid_value_caps * static BOOL init_pid_caps( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { + struct pid_set_constant_force *set_constant_force = &impl->pid_set_constant_force; struct pid_control_report *device_control = &impl->pid_device_control; struct pid_control_report *effect_control = &impl->pid_effect_control; struct pid_effect_update *effect_update = &impl->pid_effect_update; @@ -2113,6 +2125,16 @@ static BOOL init_pid_caps( struct hid_joystick *impl, struct hid_value_caps *cap set_condition->dead_band_caps = caps; } } + if (instance->wCollectionNumber == set_constant_force->collection) + { + SET_REPORT_ID( set_constant_force ); + if (instance->wUsage == PID_USAGE_MAGNITUDE) + { + caps->physical_min = -10000; + caps->physical_max = 10000; + set_constant_force->magnitude_caps = caps; + } + }
#undef SET_REPORT_ID
@@ -2222,6 +2244,8 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID TRACE( "set periodic id %u, coll %u\n", impl->pid_set_periodic.id, impl->pid_set_periodic.collection ); TRACE( "set envelope id %u, coll %u\n", impl->pid_set_envelope.id, impl->pid_set_envelope.collection ); TRACE( "set condition id %u, coll %u\n", impl->pid_set_condition.id, impl->pid_set_condition.collection ); + TRACE( "set constant force id %u, coll %u\n", impl->pid_set_constant_force.id, + impl->pid_set_constant_force.collection );
if (impl->pid_device_control.id) { @@ -2379,6 +2403,13 @@ static HRESULT WINAPI hid_joystick_effect_Initialize( IDirectInputEffect *iface, if (status != HIDP_STATUS_SUCCESS) return DIERR_DEVICENOTREG; break; case PID_USAGE_ET_CONSTANT_FORCE: + status = HidP_InitializeReportForID( HidP_Output, joystick->pid_set_constant_force.id, joystick->preparsed, + impl->type_specific_buf[0], report_len ); + if (status != HIDP_STATUS_SUCCESS) return DIERR_DEVICENOTREG; + status = HidP_InitializeReportForID( HidP_Output, joystick->pid_set_envelope.id, joystick->preparsed, + impl->type_specific_buf[1], report_len ); + if (status != HIDP_STATUS_SUCCESS) return DIERR_DEVICENOTREG; + break; case PID_USAGE_ET_RAMP: case PID_USAGE_ET_CUSTOM_FORCE_DATA: FIXME( "effect type %#x not implemented!\n", type ); @@ -2528,6 +2559,10 @@ static HRESULT WINAPI hid_joystick_effect_GetParameters( IDirectInputEffect *ifa memcpy( params->lpvTypeSpecificParams, impl->condition, params->cbTypeSpecificParams ); break; case PID_USAGE_ET_CONSTANT_FORCE: + if (!params->lpvTypeSpecificParams) return E_POINTER; + if (params->cbTypeSpecificParams != sizeof(DICONSTANTFORCE)) return DIERR_INVALIDPARAM; + memcpy( params->lpvTypeSpecificParams, &impl->constant_force, sizeof(DICONSTANTFORCE) ); + break; case PID_USAGE_ET_RAMP: case PID_USAGE_ET_CUSTOM_FORCE_DATA: FIXME( "DIEP_TYPESPECIFICPARAMS not implemented!\n" ); @@ -2686,6 +2721,13 @@ static HRESULT WINAPI hid_joystick_effect_SetParameters( IDirectInputEffect *ifa } break; case PID_USAGE_ET_CONSTANT_FORCE: + if (!params->lpvTypeSpecificParams) return E_POINTER; + if (params->cbTypeSpecificParams != sizeof(DICONSTANTFORCE)) return DIERR_INVALIDPARAM; + if (memcmp( &impl->constant_force, params->lpvTypeSpecificParams, sizeof(DICONSTANTFORCE) )) + impl->modified = TRUE; + memcpy( &impl->constant_force, params->lpvTypeSpecificParams, sizeof(DICONSTANTFORCE) ); + impl->params.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); + break; case PID_USAGE_ET_RAMP: case PID_USAGE_ET_CUSTOM_FORCE_DATA: FIXME( "DIEP_TYPESPECIFICPARAMS not implemented!\n" ); @@ -2892,6 +2934,7 @@ static HRESULT WINAPI hid_joystick_effect_Download( IDirectInputEffect *iface ) { static const DWORD complete_mask = DIEP_AXES | DIEP_DIRECTION | DIEP_TYPESPECIFICPARAMS; struct hid_joystick_effect *impl = impl_from_IDirectInputEffect( iface ); + struct pid_set_constant_force *set_constant_force = &impl->joystick->pid_set_constant_force; struct pid_effect_update *effect_update = &impl->joystick->pid_effect_update; struct pid_set_condition *set_condition = &impl->joystick->pid_set_condition; struct pid_set_periodic *set_periodic = &impl->joystick->pid_set_periodic; @@ -2983,6 +3026,25 @@ static HRESULT WINAPI hid_joystick_effect_Download( IDirectInputEffect *iface ) else hr = DIERR_INPUTLOST; } break; + case PID_USAGE_ET_CONSTANT_FORCE: + set_parameter_value( impl, impl->type_specific_buf[0], set_constant_force->magnitude_caps, + impl->constant_force.lMagnitude ); + + if (WriteFile( device, impl->type_specific_buf[0], report_len, NULL, NULL )) hr = DI_OK; + else hr = DIERR_INPUTLOST; + + set_parameter_value( impl, impl->type_specific_buf[1], set_envelope->attack_level_caps, + impl->envelope.dwAttackLevel ); + set_parameter_value_us( impl, impl->type_specific_buf[1], set_envelope->attack_time_caps, + impl->envelope.dwAttackTime ); + set_parameter_value( impl, impl->type_specific_buf[1], set_envelope->fade_level_caps, + impl->envelope.dwFadeLevel ); + set_parameter_value_us( impl, impl->type_specific_buf[1], set_envelope->fade_time_caps, + impl->envelope.dwFadeTime ); + + if (WriteFile( device, impl->type_specific_buf[1], report_len, NULL, NULL )) hr = DI_OK; + else hr = DIERR_INPUTLOST; + break; }
set_parameter_value_us( impl, impl->effect_update_buf, effect_update->duration_caps,