DECLSPEC_HIDDEN HRESULT linuxinput_get_info_W( int fd, REFGUID rguid, LPDIEFFECTINFOW info) { DWORD type = typeFromGUID(rguid); TRACE("(%d, %s, %p) type=%d\n", fd, _dump_dinput_GUID(rguid), info, type); if (!info) return E_POINTER; if (info->dwSize != sizeof(DIEFFECTINFOW)) return DIERR_INVALIDPARAM; info->guid = *rguid; info->dwEffType = type; /* the event device API does not support querying for all these things * therefore we assume that we have support for them * that's not as dangerous as it sounds, since drivers are allowed to * ignore parameters they claim to support anyway */ info->dwEffType |= DIEFT_DEADBAND | DIEFT_FFATTACK | DIEFT_FFFADE | DIEFT_POSNEGCOEFFICIENTS | DIEFT_POSNEGSATURATION | DIEFT_SATURATION | DIEFT_STARTDELAY; /* again, assume we have support for everything */ info->dwStaticParams = DIEP_ALLPARAMS; info->dwDynamicParams = info->dwStaticParams; /* yes, this is windows behavior (print the GUID_Name for name) */ MultiByteToWideChar(CP_ACP, 0, _dump_dinput_GUID(rguid), -1, info->tszName, MAX_PATH); return DI_OK; }
static HRESULT WINAPI LinuxInputEffectImpl_SetParameters( LPDIRECTINPUTEFFECT iface, LPCDIEFFECT peff, DWORD dwFlags) { LinuxInputEffectImpl *This = impl_from_IDirectInputEffect(iface); DWORD type = typeFromGUID(&This->guid); HRESULT retval = DI_OK; TRACE("(this=%p,%p,%d)\n", This, peff, dwFlags); dump_DIEFFECT(peff, &This->guid, dwFlags); if ((dwFlags & ~DIEP_NORESTART & ~DIEP_NODOWNLOAD & ~DIEP_START) == 0) { /* set everything */ dwFlags = DIEP_AXES | DIEP_DIRECTION | DIEP_DURATION | DIEP_ENVELOPE | DIEP_GAIN | DIEP_SAMPLEPERIOD | DIEP_STARTDELAY | DIEP_TRIGGERBUTTON | DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS; } if (dwFlags & DIEP_AXES) { /* the linux input effect system only supports one or two axes */ if (peff->cAxes > 2) return DIERR_INVALIDPARAM; else if (peff->cAxes < 1) return DIERR_INCOMPLETEEFFECT; This->first_axis_is_x = peff->rgdwAxes[0] == DIJOFS_X; } /* some of this may look funky, but it's 'cause the linux driver and directx have * different opinions about which way direction "0" is. directx has 0 along the x * axis (left), linux has it along the y axis (down). */ if (dwFlags & DIEP_DIRECTION) { if (peff->cAxes == 1) { if (peff->dwFlags & DIEFF_CARTESIAN) { if (dwFlags & DIEP_AXES) { if (peff->rgdwAxes[0] == DIJOFS_X && peff->rglDirection[0] >= 0) This->effect.direction = 0x4000; else if (peff->rgdwAxes[0] == DIJOFS_X && peff->rglDirection[0] < 0) This->effect.direction = 0xC000; else if (peff->rgdwAxes[0] == DIJOFS_Y && peff->rglDirection[0] >= 0) This->effect.direction = 0; else if (peff->rgdwAxes[0] == DIJOFS_Y && peff->rglDirection[0] < 0) This->effect.direction = 0x8000; } } else { /* one-axis effects must use cartesian coords */ return DIERR_INVALIDPARAM; } } else { /* two axes */ if (peff->dwFlags & DIEFF_CARTESIAN) { LONG x, y; if (This->first_axis_is_x) { x = peff->rglDirection[0]; y = peff->rglDirection[1]; } else { x = peff->rglDirection[1]; y = peff->rglDirection[0]; } This->effect.direction = (int)((3 * M_PI / 2 - atan2(y, x)) * -0x7FFF / M_PI); } else { /* Polar and spherical are the same for 2 axes */ /* Precision is important here, so we do double math with exact constants */ This->effect.direction = (int)(((double)peff->rglDirection[0] - 90) / 35999) * 0x7FFF; } } } if (dwFlags & DIEP_DURATION) This->effect.replay.length = peff->dwDuration / 1000; if (dwFlags & DIEP_ENVELOPE) { struct ff_envelope* env; if (This->effect.type == FF_CONSTANT) env = &This->effect.u.constant.envelope; else if (This->effect.type == FF_PERIODIC) env = &This->effect.u.periodic.envelope; else if (This->effect.type == FF_RAMP) env = &This->effect.u.ramp.envelope; else env = NULL; if (peff->lpEnvelope == NULL) { /* if this type had an envelope, reset it */ if (env) { env->attack_length = 0; env->attack_level = 0; env->fade_length = 0; env->fade_level = 0; } } else { /* did we get passed an envelope for a type that doesn't even have one? */ if (!env) return DIERR_INVALIDPARAM; /* copy the envelope */ env->attack_length = peff->lpEnvelope->dwAttackTime / 1000; env->attack_level = (peff->lpEnvelope->dwAttackLevel / 10) * 32; env->fade_length = peff->lpEnvelope->dwFadeTime / 1000; env->fade_level = (peff->lpEnvelope->dwFadeLevel / 10) * 32; } } /* Gain and Sample Period settings are not supported by the linux * event system */ if (dwFlags & DIEP_GAIN) { This->gain = 0xFFFF * peff->dwGain / 10000; TRACE("Effect gain requested but no effect gain functionality present.\n"); } if (dwFlags & DIEP_SAMPLEPERIOD) TRACE("Sample period requested but no sample period functionality present.\n"); if (dwFlags & DIEP_STARTDELAY) This->effect.replay.delay = peff->dwStartDelay / 1000; if (dwFlags & DIEP_TRIGGERBUTTON) { if (peff->dwTriggerButton != -1) { FIXME("Linuxinput button mapping needs redoing, assuming we're using a joystick.\n"); FIXME("Trigger button translation not yet implemented!\n"); } This->effect.trigger.button = 0; } if (dwFlags & DIEP_TRIGGERREPEATINTERVAL) This->effect.trigger.interval = peff->dwTriggerRepeatInterval / 1000; if (dwFlags & DIEP_TYPESPECIFICPARAMS) { if (!(peff->lpvTypeSpecificParams)) return DIERR_INCOMPLETEEFFECT; if (type == DIEFT_PERIODIC) { LPCDIPERIODIC tsp; if (peff->cbTypeSpecificParams != sizeof(DIPERIODIC)) return DIERR_INVALIDPARAM; tsp = peff->lpvTypeSpecificParams; This->effect.u.periodic.magnitude = (tsp->dwMagnitude / 10) * 32; This->effect.u.periodic.offset = (tsp->lOffset / 10) * 32; This->effect.u.periodic.phase = (tsp->dwPhase / 9) * 8; /* == (/ 36 * 32) */ This->effect.u.periodic.period = tsp->dwPeriod / 1000; } else if (type == DIEFT_CONSTANTFORCE) { LPCDICONSTANTFORCE tsp; if (peff->cbTypeSpecificParams != sizeof(DICONSTANTFORCE)) return DIERR_INVALIDPARAM; tsp = peff->lpvTypeSpecificParams; This->effect.u.constant.level = (max(min(tsp->lMagnitude, 10000), -10000) / 10) * 32; } else if (type == DIEFT_RAMPFORCE) { LPCDIRAMPFORCE tsp; if (peff->cbTypeSpecificParams != sizeof(DIRAMPFORCE)) return DIERR_INVALIDPARAM; tsp = peff->lpvTypeSpecificParams; This->effect.u.ramp.start_level = (tsp->lStart / 10) * 32; This->effect.u.ramp.end_level = (tsp->lEnd / 10) * 32; } else if (type == DIEFT_CONDITION) { LPCDICONDITION tsp = peff->lpvTypeSpecificParams; if (peff->cbTypeSpecificParams == sizeof(DICONDITION)) { /* One condition block. This needs to be rotated to direction, * and expanded to separate x and y conditions. */ int i; double factor[2]; factor[0] = asin((This->effect.direction * 3.0 * M_PI) / 0x7FFF); factor[1] = acos((This->effect.direction * 3.0 * M_PI) / 0x7FFF); for (i = 0; i < 2; ++i) { This->effect.u.condition[i].center = (int)(factor[i] * (tsp->lOffset / 10) * 32); This->effect.u.condition[i].right_coeff = (int)(factor[i] * (tsp->lPositiveCoefficient / 10) * 32); This->effect.u.condition[i].left_coeff = (int)(factor[i] * (tsp->lNegativeCoefficient / 10) * 32); This->effect.u.condition[i].right_saturation = (int)(factor[i] * (tsp->dwPositiveSaturation / 10) * 32); This->effect.u.condition[i].left_saturation = (int)(factor[i] * (tsp->dwNegativeSaturation / 10) * 32); This->effect.u.condition[i].deadband = (int)(factor[i] * (tsp->lDeadBand / 10) * 32); } } else if (peff->cbTypeSpecificParams == 2 * sizeof(DICONDITION)) { /* Two condition blocks. Direct parameter copy. */ int i; for (i = 0; i < 2; ++i) { This->effect.u.condition[i].center = (tsp[i].lOffset / 10) * 32; This->effect.u.condition[i].right_coeff = (tsp[i].lPositiveCoefficient / 10) * 32; This->effect.u.condition[i].left_coeff = (tsp[i].lNegativeCoefficient / 10) * 32; This->effect.u.condition[i].right_saturation = (tsp[i].dwPositiveSaturation / 10) * 32; This->effect.u.condition[i].left_saturation = (tsp[i].dwNegativeSaturation / 10) * 32; This->effect.u.condition[i].deadband = (tsp[i].lDeadBand / 10) * 32; } } else { return DIERR_INVALIDPARAM; } } else { FIXME("Custom force types are not supported\n"); return DIERR_INVALIDPARAM; } } if (!(dwFlags & DIEP_NODOWNLOAD)) retval = LinuxInputEffectImpl_Download(iface); if (retval != DI_OK) return DI_DOWNLOADSKIPPED; if (dwFlags & DIEP_NORESTART) TRACE("DIEP_NORESTART: not handled (we have no control of that).\n"); if (dwFlags & DIEP_START) retval = LinuxInputEffectImpl_Start(iface, 1, 0); if (retval != DI_OK) return retval; return DI_OK; }
DECLSPEC_HIDDEN HRESULT linuxinput_create_effect( int* fd, REFGUID rguid, struct list *parent_list_entry, LPDIRECTINPUTEFFECT* peff) { LinuxInputEffectImpl* newEffect = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LinuxInputEffectImpl)); DWORD type = typeFromGUID(rguid); newEffect->IDirectInputEffect_iface.lpVtbl = &LinuxInputEffectVtbl; newEffect->ref = 1; newEffect->guid = *rguid; newEffect->fd = fd; newEffect->gain = 0xFFFF; /* set the type. this cannot be changed over the effect's life. */ switch (type) { case DIEFT_PERIODIC: newEffect->effect.type = FF_PERIODIC; if (IsEqualGUID(rguid, &GUID_Sine)) { newEffect->effect.u.periodic.waveform = FF_SINE; } else if (IsEqualGUID(rguid, &GUID_Triangle)) { newEffect->effect.u.periodic.waveform = FF_TRIANGLE; } else if (IsEqualGUID(rguid, &GUID_Square)) { newEffect->effect.u.periodic.waveform = FF_SQUARE; } else if (IsEqualGUID(rguid, &GUID_SawtoothUp)) { newEffect->effect.u.periodic.waveform = FF_SAW_UP; } else if (IsEqualGUID(rguid, &GUID_SawtoothDown)) { newEffect->effect.u.periodic.waveform = FF_SAW_DOWN; } break; case DIEFT_CONSTANTFORCE: newEffect->effect.type = FF_CONSTANT; break; case DIEFT_RAMPFORCE: newEffect->effect.type = FF_RAMP; break; case DIEFT_CONDITION: if (IsEqualGUID(rguid, &GUID_Spring)) { newEffect->effect.type = FF_SPRING; } else if (IsEqualGUID(rguid, &GUID_Friction)) { newEffect->effect.type = FF_FRICTION; } else if (IsEqualGUID(rguid, &GUID_Inertia)) { newEffect->effect.type = FF_INERTIA; } else if (IsEqualGUID(rguid, &GUID_Damper)) { newEffect->effect.type = FF_DAMPER; } break; case DIEFT_CUSTOMFORCE: FIXME("Custom forces are not supported.\n"); HeapFree(GetProcessHeap(), 0, newEffect); return DIERR_INVALIDPARAM; default: FIXME("Unknown force type 0x%x.\n", type); HeapFree(GetProcessHeap(), 0, newEffect); return DIERR_INVALIDPARAM; } /* mark as non-uploaded */ newEffect->effect.id = -1; newEffect->entry = parent_list_entry; *peff = &newEffect->IDirectInputEffect_iface; TRACE("Creating linux input system effect (%p) with guid %s\n", *peff, _dump_dinput_GUID(rguid)); return DI_OK; }
static HRESULT WINAPI LinuxInputEffectImpl_SetParameters( LPDIRECTINPUTEFFECT iface, LPCDIEFFECT peff, DWORD dwFlags) { LinuxInputEffectImpl *This = impl_from_IDirectInputEffect(iface); DWORD type = typeFromGUID(&This->guid); HRESULT retval = DI_OK; TRACE("(this=%p,%p,%d)\n", This, peff, dwFlags); dump_DIEFFECT(peff, &This->guid, dwFlags); if ((dwFlags & ~DIEP_NORESTART & ~DIEP_NODOWNLOAD & ~DIEP_START) == 0) { /* set everything */ dwFlags = DIEP_AXES | DIEP_DIRECTION | DIEP_DURATION | DIEP_ENVELOPE | DIEP_GAIN | DIEP_SAMPLEPERIOD | DIEP_STARTDELAY | DIEP_TRIGGERBUTTON | DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS; } if (dwFlags & DIEP_AXES) { /* the linux input effect system only supports one or two axes */ if (peff->cAxes > 2) return DIERR_INVALIDPARAM; else if (peff->cAxes < 1) return DIERR_INCOMPLETEEFFECT; This->first_axis_is_x = peff->rgdwAxes[0] == DIJOFS_X; } /* some of this may look funky, but it's 'cause the linux driver and directx have * different opinions about which way direction "0" is. directx has 0 along the x * axis (left), linux has it along the y axis (down). */ if (dwFlags & DIEP_DIRECTION) { if (peff->cAxes == 1) { if (peff->dwFlags & DIEFF_CARTESIAN) { if (dwFlags & DIEP_AXES) { if (peff->rgdwAxes[0] == DIJOFS_X && peff->rglDirection[0] >= 0) This->effect.direction = 0x4000; else if (peff->rgdwAxes[0] == DIJOFS_X && peff->rglDirection[0] < 0) This->effect.direction = 0xC000; else if (peff->rgdwAxes[0] == DIJOFS_Y && peff->rglDirection[0] >= 0) This->effect.direction = 0; else if (peff->rgdwAxes[0] == DIJOFS_Y && peff->rglDirection[0] < 0) This->effect.direction = 0x8000; } } else { /* one-axis effects must use cartesian coords */ return DIERR_INVALIDPARAM; } } /* two axes */ else { if (peff->dwFlags & DIEFF_CARTESIAN) { LONG x, y; if (This->first_axis_is_x) { x = peff->rglDirection[0]; y = peff->rglDirection[1]; } else { x = peff->rglDirection[1]; y = peff->rglDirection[0]; } This->effect.direction = (unsigned int)((M_PI / 2 + atan2(y, x)) * 0x8000 / M_PI); } else { /* Polar and spherical are the same for 2 axes */ /* Precision is important here, so we do double math with exact constants */ This->effect.direction = (unsigned int)(((double)peff->rglDirection[0] / 18000) * 0x8000); } } } if (dwFlags & DIEP_DURATION) { if (peff->dwDuration == INFINITE) This->effect.replay.length = 0; /* infinite for the linux driver */ else if(peff->dwDuration > 1000) This->effect.replay.length = peff->dwDuration / 1000; else This->effect.replay.length = 1; } if (dwFlags & DIEP_ENVELOPE) { struct ff_envelope* env; if (This->effect.type == FF_CONSTANT) env = &This->effect.u.constant.envelope; else if (This->effect.type == FF_PERIODIC) env = &This->effect.u.periodic.envelope; else if (This->effect.type == FF_RAMP) env = &This->effect.u.ramp.envelope; else env = NULL; /* copy the envelope if it is present and the linux effect supports it */ if (peff->lpEnvelope && env) { env->attack_length = peff->lpEnvelope->dwAttackTime / 1000; env->attack_level = (peff->lpEnvelope->dwAttackLevel / 10) * 32; env->fade_length = peff->lpEnvelope->dwFadeTime / 1000; env->fade_level = (peff->lpEnvelope->dwFadeLevel / 10) * 32; } /* if the dinput envelope is NULL we will clear the linux envelope */ else if (env) { env->attack_length = 0; env->attack_level = 0; env->fade_length = 0; env->fade_level = 0; } else if(peff->lpEnvelope) { if(peff->lpEnvelope->dwAttackTime || peff->lpEnvelope->dwAttackLevel || peff->lpEnvelope->dwFadeTime || peff->lpEnvelope->dwFadeLevel) WARN("Ignoring dinput envelope not supported in the linux effect\n"); } } /* Gain and Sample Period settings are not supported by the linux * event system */ if (dwFlags & DIEP_GAIN) { This->gain = 0xFFFF * peff->dwGain / 10000; TRACE("Effect gain requested but no effect gain functionality present.\n"); } if (dwFlags & DIEP_SAMPLEPERIOD) TRACE("Sample period requested but no sample period functionality present.\n"); if (dwFlags & DIEP_STARTDELAY) if ((dwFlags & DIEP_STARTDELAY) && peff->dwSize > sizeof(DIEFFECT_DX5)) This->effect.replay.delay = peff->dwStartDelay / 1000; if (dwFlags & DIEP_TRIGGERBUTTON) { if (peff->dwTriggerButton != -1) { FIXME("Linuxinput button mapping needs redoing, assuming we're using a joystick.\n"); FIXME("Trigger button translation not yet implemented!\n"); } This->effect.trigger.button = 0; } if (dwFlags & DIEP_TRIGGERREPEATINTERVAL) This->effect.trigger.interval = peff->dwTriggerRepeatInterval / 1000; if (dwFlags & DIEP_TYPESPECIFICPARAMS) { if (!(peff->lpvTypeSpecificParams)) return DIERR_INCOMPLETEEFFECT; if (type == DIEFT_PERIODIC) { DIPERIODIC *tsp; if (peff->cbTypeSpecificParams != sizeof(DIPERIODIC)) return DIERR_INVALIDPARAM; tsp = peff->lpvTypeSpecificParams; This->effect.u.periodic.magnitude = (tsp->dwMagnitude / 10) * 32; This->effect.u.periodic.offset = (tsp->lOffset / 10) * 32; /* phase ranges from 0 - 35999 in dinput and 0 - 65535 on linux */ This->effect.u.periodic.phase = (tsp->dwPhase / 36) * 65; /* dinput uses microseconds, linux uses miliseconds */ if (tsp->dwPeriod <= 1000) This->effect.u.periodic.period = 1; else This->effect.u.periodic.period = tsp->dwPeriod / 1000; } else if (type == DIEFT_CONSTANTFORCE) { LPCDICONSTANTFORCE tsp; if (peff->cbTypeSpecificParams != sizeof(DICONSTANTFORCE)) return DIERR_INVALIDPARAM; tsp = peff->lpvTypeSpecificParams; This->effect.u.constant.level = (max(min(tsp->lMagnitude, 10000), -10000) / 10) * 32; } else if (type == DIEFT_RAMPFORCE) { LPCDIRAMPFORCE tsp; if (peff->cbTypeSpecificParams != sizeof(DIRAMPFORCE)) return DIERR_INVALIDPARAM; tsp = peff->lpvTypeSpecificParams; This->effect.u.ramp.start_level = (tsp->lStart / 10) * 32; This->effect.u.ramp.end_level = (tsp->lEnd / 10) * 32; } else if (type == DIEFT_CONDITION) { DICONDITION *tsp = peff->lpvTypeSpecificParams; struct ff_condition_effect *cond = This->effect.u.condition; int i, j, sources; double factor[2]; if (peff->cbTypeSpecificParams == sizeof(DICONDITION)) { /* One condition block. This needs to be rotated to direction, * and expanded to separate x and y conditions. Ensures 0 points right */ double angle = ff_effect_direction_to_rad(This->effect.direction + 0xc000); factor[0] = sin(angle); factor[1] = -cos(angle); sources = 1; } else if (peff->cbTypeSpecificParams == 2 * sizeof(DICONDITION)) { /* Direct parameter copy without changes */ factor[0] = factor[1] = 1; sources = 2; } else return DIERR_INVALIDPARAM; for (i = j = 0; i < 2; ++i) { cond[i].center = (int)(factor[i] * (tsp[j].lOffset / 10) * 32); cond[i].right_coeff = (int)(factor[i] * (tsp[j].lPositiveCoefficient / 10) * 32); cond[i].left_coeff = (int)(factor[i] * (tsp[j].lNegativeCoefficient / 10) * 32); cond[i].right_saturation = (int)(factor[i] * (tsp[j].dwPositiveSaturation / 10) * 65); cond[i].left_saturation = (int)(factor[i] * (tsp[j].dwNegativeSaturation / 10) * 65); cond[i].deadband = (int)(factor[i] * (tsp[j].lDeadBand / 10) * 32); if (sources == 2) j++; } } else { FIXME("Custom force types are not supported\n"); return DIERR_INVALIDPARAM; } } if (!(dwFlags & DIEP_NODOWNLOAD)) retval = LinuxInputEffectImpl_Download(iface); if (retval != DI_OK) return DI_DOWNLOADSKIPPED; if (dwFlags & DIEP_NORESTART) TRACE("DIEP_NORESTART: not handled (we have no control of that).\n"); if (dwFlags & DIEP_START) retval = LinuxInputEffectImpl_Start(iface, 1, 0); if (retval != DI_OK) return retval; return DI_OK; }