1 /* DirectInput Linux Event Device Effect
3 * Copyright 2005 Daniel Remenak
5 * Thanks to Google's Summer of Code Program (2005)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
28 #ifdef HAVE_LINUX_INPUT_H
29 # include <linux/input.h>
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
45 #include "device_private.h"
46 #include "joystick_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
50 static const IDirectInputEffectVtbl LinuxInputEffectVtbl
;
51 typedef struct LinuxInputEffectImpl LinuxInputEffectImpl
;
52 struct LinuxInputEffectImpl
54 IDirectInputEffect IDirectInputEffect_iface
;
58 struct ff_effect effect
; /* Effect data */
59 int gain
; /* Effect gain */
61 int* fd
; /* Parent device */
62 struct list
*entry
; /* Entry into the parent's list of effects */
65 static inline LinuxInputEffectImpl
*impl_from_IDirectInputEffect(IDirectInputEffect
*iface
)
67 return CONTAINING_RECORD(iface
, LinuxInputEffectImpl
, IDirectInputEffect_iface
);
70 /******************************************************************************
71 * LinuxInputEffectImpl
74 static ULONG WINAPI
LinuxInputEffectImpl_AddRef(
75 LPDIRECTINPUTEFFECT iface
)
77 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
78 return InterlockedIncrement(&(This
->ref
));
81 static HRESULT WINAPI
LinuxInputEffectImpl_Download(
82 LPDIRECTINPUTEFFECT iface
)
84 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
86 TRACE("(this=%p)\n", This
);
88 if (ioctl(*(This
->fd
), EVIOCSFF
, &This
->effect
) == -1) {
89 if (errno
== ENOMEM
) {
90 return DIERR_DEVICEFULL
;
92 FIXME("Could not upload effect. Assuming a disconnected device %d \"%s\".\n", *This
->fd
, strerror(errno
));
93 return DIERR_INPUTLOST
;
100 static HRESULT WINAPI
LinuxInputEffectImpl_Escape(
101 LPDIRECTINPUTEFFECT iface
,
104 WARN("(this=%p,%p): invalid: no hardware-specific escape codes in this"
105 " driver!\n", iface
, pesc
);
110 static HRESULT WINAPI
LinuxInputEffectImpl_GetEffectGuid(
111 LPDIRECTINPUTEFFECT iface
,
114 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
116 TRACE("(this=%p,%p)\n", This
, pguid
);
123 static HRESULT WINAPI
LinuxInputEffectImpl_GetEffectStatus(
124 LPDIRECTINPUTEFFECT iface
,
127 TRACE("(this=%p,%p)\n", iface
, pdwFlags
);
129 /* linux sends the effect status through an event.
130 * that event is trapped by our parent joystick driver
131 * and there is no clean way to pass it back to us. */
132 FIXME("Not enough information to provide a status.\n");
139 static HRESULT WINAPI
LinuxInputEffectImpl_GetParameters(
140 LPDIRECTINPUTEFFECT iface
,
144 HRESULT diErr
= DI_OK
;
145 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
146 TRACE("(this=%p,%p,%d)\n", This
, peff
, dwFlags
);
148 /* Major conversion factors are:
149 * times: millisecond (linux) -> microsecond (windows) (x * 1000)
150 * forces: scale 0x7FFF (linux) -> scale 10000 (windows) approx ((x / 33) * 10)
151 * angles: scale 0x7FFF (linux) -> scale 35999 (windows) approx ((x / 33) * 36)
152 * angle bases: 0 -> -y (down) (linux) -> 0 -> +x (right) (windows)
155 if (dwFlags
& DIEP_AXES
) {
156 if (peff
->cAxes
< 2 /* linuxinput effects always use 2 axes, x and y */)
157 diErr
= DIERR_MOREDATA
;
162 peff
->rgdwAxes
[0] = DIJOFS_X
;
163 peff
->rgdwAxes
[1] = DIJOFS_Y
;
167 if (dwFlags
& DIEP_DIRECTION
) {
169 diErr
= DIERR_MOREDATA
;
174 if (peff
->dwFlags
& DIEFF_CARTESIAN
) {
175 peff
->rglDirection
[0] = sin(M_PI
* 3 * This
->effect
.direction
/ 0x7FFF) * 1000;
176 peff
->rglDirection
[1] = cos(M_PI
* 3 * This
->effect
.direction
/ 0x7FFF) * 1000;
178 /* Polar and spherical coordinates are the same for two or less
180 * Note that we also use this case if NO flags are marked.
181 * According to MSDN, we should return the direction in the
182 * format that it was specified in, if no flags are marked.
184 peff
->rglDirection
[0] = (This
->effect
.direction
/ 33) * 36 + 9000;
185 if (peff
->rglDirection
[0] > 35999)
186 peff
->rglDirection
[0] -= 35999;
191 if (dwFlags
& DIEP_DURATION
) {
192 peff
->dwDuration
= (DWORD
)This
->effect
.replay
.length
* 1000;
195 if (dwFlags
& DIEP_ENVELOPE
) {
196 struct ff_envelope
* env
;
197 if (This
->effect
.type
== FF_CONSTANT
) env
= &This
->effect
.u
.constant
.envelope
;
198 else if (This
->effect
.type
== FF_PERIODIC
) env
= &This
->effect
.u
.periodic
.envelope
;
199 else if (This
->effect
.type
== FF_RAMP
) env
= &This
->effect
.u
.ramp
.envelope
;
202 peff
->lpEnvelope
= NULL
;
203 } else if (peff
->lpEnvelope
== NULL
) {
204 return DIERR_INVALIDPARAM
;
206 peff
->lpEnvelope
->dwAttackLevel
= (env
->attack_level
/ 33) * 10;
207 peff
->lpEnvelope
->dwAttackTime
= env
->attack_length
* 1000;
208 peff
->lpEnvelope
->dwFadeLevel
= (env
->fade_level
/ 33) * 10;
209 peff
->lpEnvelope
->dwFadeTime
= env
->fade_length
* 1000;
213 if (dwFlags
& DIEP_GAIN
) {
214 peff
->dwGain
= This
->gain
* 10000 / 0xFFFF;
217 if (dwFlags
& DIEP_SAMPLEPERIOD
) {
218 /* the linux input ff driver has no support for setting
219 * the playback sample period. 0 means default. */
220 peff
->dwSamplePeriod
= 0;
223 if (dwFlags
& DIEP_STARTDELAY
) {
224 peff
->dwStartDelay
= This
->effect
.replay
.delay
* 1000;
227 if (dwFlags
& DIEP_TRIGGERBUTTON
) {
228 FIXME("LinuxInput button mapping needs redoing; for now, assuming we're using an actual joystick.\n");
229 peff
->dwTriggerButton
= DIJOFS_BUTTON(This
->effect
.trigger
.button
- BTN_JOYSTICK
);
232 if (dwFlags
& DIEP_TRIGGERREPEATINTERVAL
) {
233 peff
->dwTriggerRepeatInterval
= This
->effect
.trigger
.interval
* 1000;
236 if (dwFlags
& DIEP_TYPESPECIFICPARAMS
) {
237 DWORD expectedsize
= 0;
238 if (This
->effect
.type
== FF_PERIODIC
) {
239 expectedsize
= sizeof(DIPERIODIC
);
240 } else if (This
->effect
.type
== FF_CONSTANT
) {
241 expectedsize
= sizeof(DICONSTANTFORCE
);
242 } else if (This
->effect
.type
== FF_SPRING
243 || This
->effect
.type
== FF_FRICTION
244 || This
->effect
.type
== FF_INERTIA
245 || This
->effect
.type
== FF_DAMPER
) {
246 expectedsize
= sizeof(DICONDITION
) * 2;
247 } else if (This
->effect
.type
== FF_RAMP
) {
248 expectedsize
= sizeof(DIRAMPFORCE
);
250 if (expectedsize
> peff
->cbTypeSpecificParams
)
251 diErr
= DIERR_MOREDATA
;
252 peff
->cbTypeSpecificParams
= expectedsize
;
256 if (This
->effect
.type
== FF_PERIODIC
) {
257 LPDIPERIODIC tsp
= peff
->lpvTypeSpecificParams
;
258 tsp
->dwMagnitude
= (This
->effect
.u
.periodic
.magnitude
/ 33) * 10;
259 tsp
->lOffset
= (This
->effect
.u
.periodic
.offset
/ 33) * 10;
260 tsp
->dwPhase
= (This
->effect
.u
.periodic
.phase
/ 33) * 36;
261 tsp
->dwPeriod
= (This
->effect
.u
.periodic
.period
* 1000);
262 } else if (This
->effect
.type
== FF_CONSTANT
) {
263 LPDICONSTANTFORCE tsp
= peff
->lpvTypeSpecificParams
;
264 tsp
->lMagnitude
= (This
->effect
.u
.constant
.level
/ 33) * 10;
265 } else if (This
->effect
.type
== FF_SPRING
266 || This
->effect
.type
== FF_FRICTION
267 || This
->effect
.type
== FF_INERTIA
268 || This
->effect
.type
== FF_DAMPER
) {
269 LPDICONDITION tsp
= peff
->lpvTypeSpecificParams
;
271 for (i
= 0; i
< 2; ++i
) {
272 tsp
[i
].lOffset
= (This
->effect
.u
.condition
[i
].center
/ 33) * 10;
273 tsp
[i
].lPositiveCoefficient
= (This
->effect
.u
.condition
[i
].right_coeff
/ 33) * 10;
274 tsp
[i
].lNegativeCoefficient
= (This
->effect
.u
.condition
[i
].left_coeff
/ 33) * 10;
275 tsp
[i
].dwPositiveSaturation
= (This
->effect
.u
.condition
[i
].right_saturation
/ 33) * 10;
276 tsp
[i
].dwNegativeSaturation
= (This
->effect
.u
.condition
[i
].left_saturation
/ 33) * 10;
277 tsp
[i
].lDeadBand
= (This
->effect
.u
.condition
[i
].deadband
/ 33) * 10;
279 } else if (This
->effect
.type
== FF_RAMP
) {
280 LPDIRAMPFORCE tsp
= peff
->lpvTypeSpecificParams
;
281 tsp
->lStart
= (This
->effect
.u
.ramp
.start_level
/ 33) * 10;
282 tsp
->lEnd
= (This
->effect
.u
.ramp
.end_level
/ 33) * 10;
290 static HRESULT WINAPI
LinuxInputEffectImpl_Initialize(
291 LPDIRECTINPUTEFFECT iface
,
296 FIXME("(this=%p,%p,%d,%s): stub!\n",
297 iface
, hinst
, dwVersion
, debugstr_guid(rguid
));
302 static HRESULT WINAPI
LinuxInputEffectImpl_QueryInterface(
303 LPDIRECTINPUTEFFECT iface
,
307 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
309 TRACE("(this=%p,%s,%p)\n", This
, debugstr_guid(riid
), ppvObject
);
311 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
312 IsEqualGUID(&IID_IDirectInputEffect
, riid
)) {
313 LinuxInputEffectImpl_AddRef(iface
);
318 TRACE("Unsupported interface!\n");
322 static HRESULT WINAPI
LinuxInputEffectImpl_Start(
323 LPDIRECTINPUTEFFECT iface
,
327 struct input_event event
;
328 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
330 TRACE("(this=%p,%d,%d)\n", This
, dwIterations
, dwFlags
);
332 if (!(dwFlags
& DIES_NODOWNLOAD
)) {
333 /* Download the effect if necessary */
334 if (This
->effect
.id
== -1) {
335 HRESULT res
= LinuxInputEffectImpl_Download(iface
);
341 if (dwFlags
& DIES_SOLO
) {
342 FIXME("Solo mode requested: should be stopping all effects here!\n");
346 event
.code
= This
->effect
.id
;
347 event
.value
= min( dwIterations
, INT_MAX
);
348 if (write(*(This
->fd
), &event
, sizeof(event
)) == -1) {
349 FIXME("Unable to write event. Assuming device disconnected.\n");
350 return DIERR_INPUTLOST
;
356 static HRESULT WINAPI
LinuxInputEffectImpl_SetParameters(
357 LPDIRECTINPUTEFFECT iface
,
361 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
362 DWORD type
= typeFromGUID(&This
->guid
);
363 HRESULT retval
= DI_OK
;
365 TRACE("(this=%p,%p,%d)\n", This
, peff
, dwFlags
);
367 dump_DIEFFECT(peff
, &This
->guid
, dwFlags
);
369 if ((dwFlags
& ~DIEP_NORESTART
& ~DIEP_NODOWNLOAD
& ~DIEP_START
) == 0) {
371 dwFlags
= DIEP_AXES
| DIEP_DIRECTION
| DIEP_DURATION
| DIEP_ENVELOPE
|
372 DIEP_GAIN
| DIEP_SAMPLEPERIOD
| DIEP_STARTDELAY
| DIEP_TRIGGERBUTTON
|
373 DIEP_TRIGGERREPEATINTERVAL
| DIEP_TYPESPECIFICPARAMS
;
376 if (dwFlags
& DIEP_AXES
) {
377 /* the linux input effect system only supports one or two axes */
379 return DIERR_INVALIDPARAM
;
380 else if (peff
->cAxes
< 1)
381 return DIERR_INCOMPLETEEFFECT
;
382 This
->first_axis_is_x
= peff
->rgdwAxes
[0] == DIJOFS_X
;
385 /* some of this may look funky, but it's 'cause the linux driver and directx have
386 * different opinions about which way direction "0" is. directx has 0 along the x
387 * axis (left), linux has it along the y axis (down). */
388 if (dwFlags
& DIEP_DIRECTION
) {
389 if (peff
->cAxes
== 1) {
390 if (peff
->dwFlags
& DIEFF_CARTESIAN
) {
391 if (dwFlags
& DIEP_AXES
) {
392 if (peff
->rgdwAxes
[0] == DIJOFS_X
&& peff
->rglDirection
[0] >= 0)
393 This
->effect
.direction
= 0x4000;
394 else if (peff
->rgdwAxes
[0] == DIJOFS_X
&& peff
->rglDirection
[0] < 0)
395 This
->effect
.direction
= 0xC000;
396 else if (peff
->rgdwAxes
[0] == DIJOFS_Y
&& peff
->rglDirection
[0] >= 0)
397 This
->effect
.direction
= 0;
398 else if (peff
->rgdwAxes
[0] == DIJOFS_Y
&& peff
->rglDirection
[0] < 0)
399 This
->effect
.direction
= 0x8000;
402 /* one-axis effects must use cartesian coords */
403 return DIERR_INVALIDPARAM
;
405 } else { /* two axes */
406 if (peff
->dwFlags
& DIEFF_CARTESIAN
) {
408 if (This
->first_axis_is_x
) {
409 x
= peff
->rglDirection
[0];
410 y
= peff
->rglDirection
[1];
412 x
= peff
->rglDirection
[1];
413 y
= peff
->rglDirection
[0];
415 This
->effect
.direction
= (int)((3 * M_PI
/ 2 - atan2(y
, x
)) * -0x7FFF / M_PI
);
417 /* Polar and spherical are the same for 2 axes */
418 /* Precision is important here, so we do double math with exact constants */
419 This
->effect
.direction
= (int)(((double)peff
->rglDirection
[0] - 90) / 35999) * 0x7FFF;
424 if (dwFlags
& DIEP_DURATION
)
425 This
->effect
.replay
.length
= peff
->dwDuration
/ 1000;
427 if (dwFlags
& DIEP_ENVELOPE
) {
428 struct ff_envelope
* env
;
429 if (This
->effect
.type
== FF_CONSTANT
) env
= &This
->effect
.u
.constant
.envelope
;
430 else if (This
->effect
.type
== FF_PERIODIC
) env
= &This
->effect
.u
.periodic
.envelope
;
431 else if (This
->effect
.type
== FF_RAMP
) env
= &This
->effect
.u
.ramp
.envelope
;
434 if (peff
->lpEnvelope
== NULL
) {
435 /* if this type had an envelope, reset it */
437 env
->attack_length
= 0;
438 env
->attack_level
= 0;
439 env
->fade_length
= 0;
443 /* did we get passed an envelope for a type that doesn't even have one? */
444 if (!env
) return DIERR_INVALIDPARAM
;
445 /* copy the envelope */
446 env
->attack_length
= peff
->lpEnvelope
->dwAttackTime
/ 1000;
447 env
->attack_level
= (peff
->lpEnvelope
->dwAttackLevel
/ 10) * 32;
448 env
->fade_length
= peff
->lpEnvelope
->dwFadeTime
/ 1000;
449 env
->fade_level
= (peff
->lpEnvelope
->dwFadeLevel
/ 10) * 32;
453 /* Gain and Sample Period settings are not supported by the linux
455 if (dwFlags
& DIEP_GAIN
) {
456 This
->gain
= 0xFFFF * peff
->dwGain
/ 10000;
457 TRACE("Effect gain requested but no effect gain functionality present.\n");
460 if (dwFlags
& DIEP_SAMPLEPERIOD
)
461 TRACE("Sample period requested but no sample period functionality present.\n");
463 if (dwFlags
& DIEP_STARTDELAY
)
464 This
->effect
.replay
.delay
= peff
->dwStartDelay
/ 1000;
466 if (dwFlags
& DIEP_TRIGGERBUTTON
) {
467 if (peff
->dwTriggerButton
!= -1) {
468 FIXME("Linuxinput button mapping needs redoing, assuming we're using a joystick.\n");
469 FIXME("Trigger button translation not yet implemented!\n");
471 This
->effect
.trigger
.button
= 0;
474 if (dwFlags
& DIEP_TRIGGERREPEATINTERVAL
)
475 This
->effect
.trigger
.interval
= peff
->dwTriggerRepeatInterval
/ 1000;
477 if (dwFlags
& DIEP_TYPESPECIFICPARAMS
) {
478 if (!(peff
->lpvTypeSpecificParams
))
479 return DIERR_INCOMPLETEEFFECT
;
480 if (type
== DIEFT_PERIODIC
) {
482 if (peff
->cbTypeSpecificParams
!= sizeof(DIPERIODIC
))
483 return DIERR_INVALIDPARAM
;
484 tsp
= peff
->lpvTypeSpecificParams
;
485 This
->effect
.u
.periodic
.magnitude
= (tsp
->dwMagnitude
/ 10) * 32;
486 This
->effect
.u
.periodic
.offset
= (tsp
->lOffset
/ 10) * 32;
487 This
->effect
.u
.periodic
.phase
= (tsp
->dwPhase
/ 9) * 8; /* == (/ 36 * 32) */
488 This
->effect
.u
.periodic
.period
= tsp
->dwPeriod
/ 1000;
489 } else if (type
== DIEFT_CONSTANTFORCE
) {
490 LPCDICONSTANTFORCE tsp
;
491 if (peff
->cbTypeSpecificParams
!= sizeof(DICONSTANTFORCE
))
492 return DIERR_INVALIDPARAM
;
493 tsp
= peff
->lpvTypeSpecificParams
;
494 This
->effect
.u
.constant
.level
= (max(min(tsp
->lMagnitude
, 10000), -10000) / 10) * 32;
495 } else if (type
== DIEFT_RAMPFORCE
) {
497 if (peff
->cbTypeSpecificParams
!= sizeof(DIRAMPFORCE
))
498 return DIERR_INVALIDPARAM
;
499 tsp
= peff
->lpvTypeSpecificParams
;
500 This
->effect
.u
.ramp
.start_level
= (tsp
->lStart
/ 10) * 32;
501 This
->effect
.u
.ramp
.end_level
= (tsp
->lEnd
/ 10) * 32;
502 } else if (type
== DIEFT_CONDITION
) {
503 LPCDICONDITION tsp
= peff
->lpvTypeSpecificParams
;
504 if (peff
->cbTypeSpecificParams
== sizeof(DICONDITION
)) {
505 /* One condition block. This needs to be rotated to direction,
506 * and expanded to separate x and y conditions. */
509 factor
[0] = asin((This
->effect
.direction
* 3.0 * M_PI
) / 0x7FFF);
510 factor
[1] = acos((This
->effect
.direction
* 3.0 * M_PI
) / 0x7FFF);
511 for (i
= 0; i
< 2; ++i
) {
512 This
->effect
.u
.condition
[i
].center
= (int)(factor
[i
] * (tsp
->lOffset
/ 10) * 32);
513 This
->effect
.u
.condition
[i
].right_coeff
= (int)(factor
[i
] * (tsp
->lPositiveCoefficient
/ 10) * 32);
514 This
->effect
.u
.condition
[i
].left_coeff
= (int)(factor
[i
] * (tsp
->lNegativeCoefficient
/ 10) * 32);
515 This
->effect
.u
.condition
[i
].right_saturation
= (int)(factor
[i
] * (tsp
->dwPositiveSaturation
/ 10) * 32);
516 This
->effect
.u
.condition
[i
].left_saturation
= (int)(factor
[i
] * (tsp
->dwNegativeSaturation
/ 10) * 32);
517 This
->effect
.u
.condition
[i
].deadband
= (int)(factor
[i
] * (tsp
->lDeadBand
/ 10) * 32);
519 } else if (peff
->cbTypeSpecificParams
== 2 * sizeof(DICONDITION
)) {
520 /* Two condition blocks. Direct parameter copy. */
522 for (i
= 0; i
< 2; ++i
) {
523 This
->effect
.u
.condition
[i
].center
= (tsp
[i
].lOffset
/ 10) * 32;
524 This
->effect
.u
.condition
[i
].right_coeff
= (tsp
[i
].lPositiveCoefficient
/ 10) * 32;
525 This
->effect
.u
.condition
[i
].left_coeff
= (tsp
[i
].lNegativeCoefficient
/ 10) * 32;
526 This
->effect
.u
.condition
[i
].right_saturation
= (tsp
[i
].dwPositiveSaturation
/ 10) * 32;
527 This
->effect
.u
.condition
[i
].left_saturation
= (tsp
[i
].dwNegativeSaturation
/ 10) * 32;
528 This
->effect
.u
.condition
[i
].deadband
= (tsp
[i
].lDeadBand
/ 10) * 32;
531 return DIERR_INVALIDPARAM
;
534 FIXME("Custom force types are not supported\n");
535 return DIERR_INVALIDPARAM
;
539 if (!(dwFlags
& DIEP_NODOWNLOAD
))
540 retval
= LinuxInputEffectImpl_Download(iface
);
542 return DI_DOWNLOADSKIPPED
;
544 if (dwFlags
& DIEP_NORESTART
)
545 TRACE("DIEP_NORESTART: not handled (we have no control of that).\n");
547 if (dwFlags
& DIEP_START
)
548 retval
= LinuxInputEffectImpl_Start(iface
, 1, 0);
555 static HRESULT WINAPI
LinuxInputEffectImpl_Stop(
556 LPDIRECTINPUTEFFECT iface
)
558 struct input_event event
;
559 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
561 TRACE("(this=%p)\n", This
);
564 event
.code
= This
->effect
.id
;
566 /* we don't care about the success or failure of this call */
567 write(*(This
->fd
), &event
, sizeof(event
));
572 static HRESULT WINAPI
LinuxInputEffectImpl_Unload(
573 LPDIRECTINPUTEFFECT iface
)
575 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
576 TRACE("(this=%p)\n", This
);
578 /* Erase the downloaded effect */
579 if (ioctl(*(This
->fd
), EVIOCRMFF
, This
->effect
.id
) == -1)
580 return DIERR_INVALIDPARAM
;
582 /* Mark the effect as deallocated */
583 This
->effect
.id
= -1;
588 static ULONG WINAPI
LinuxInputEffectImpl_Release(LPDIRECTINPUTEFFECT iface
)
590 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
591 ULONG ref
= InterlockedDecrement(&(This
->ref
));
595 LinuxInputEffectImpl_Stop(iface
);
596 LinuxInputEffectImpl_Unload(iface
);
597 list_remove(This
->entry
);
598 HeapFree(GetProcessHeap(), 0, LIST_ENTRY(This
->entry
, effect_list_item
, entry
));
599 HeapFree(GetProcessHeap(), 0, This
);
604 /******************************************************************************
608 DECLSPEC_HIDDEN HRESULT
linuxinput_create_effect(
611 struct list
*parent_list_entry
,
612 LPDIRECTINPUTEFFECT
* peff
)
614 LinuxInputEffectImpl
* newEffect
= HeapAlloc(GetProcessHeap(),
615 HEAP_ZERO_MEMORY
, sizeof(LinuxInputEffectImpl
));
616 DWORD type
= typeFromGUID(rguid
);
618 newEffect
->IDirectInputEffect_iface
.lpVtbl
= &LinuxInputEffectVtbl
;
620 newEffect
->guid
= *rguid
;
622 newEffect
->gain
= 0xFFFF;
624 /* set the type. this cannot be changed over the effect's life. */
627 newEffect
->effect
.type
= FF_PERIODIC
;
628 if (IsEqualGUID(rguid
, &GUID_Sine
)) {
629 newEffect
->effect
.u
.periodic
.waveform
= FF_SINE
;
630 } else if (IsEqualGUID(rguid
, &GUID_Triangle
)) {
631 newEffect
->effect
.u
.periodic
.waveform
= FF_TRIANGLE
;
632 } else if (IsEqualGUID(rguid
, &GUID_Square
)) {
633 newEffect
->effect
.u
.periodic
.waveform
= FF_SQUARE
;
634 } else if (IsEqualGUID(rguid
, &GUID_SawtoothUp
)) {
635 newEffect
->effect
.u
.periodic
.waveform
= FF_SAW_UP
;
636 } else if (IsEqualGUID(rguid
, &GUID_SawtoothDown
)) {
637 newEffect
->effect
.u
.periodic
.waveform
= FF_SAW_DOWN
;
640 case DIEFT_CONSTANTFORCE
:
641 newEffect
->effect
.type
= FF_CONSTANT
;
643 case DIEFT_RAMPFORCE
:
644 newEffect
->effect
.type
= FF_RAMP
;
646 case DIEFT_CONDITION
:
647 if (IsEqualGUID(rguid
, &GUID_Spring
)) {
648 newEffect
->effect
.type
= FF_SPRING
;
649 } else if (IsEqualGUID(rguid
, &GUID_Friction
)) {
650 newEffect
->effect
.type
= FF_FRICTION
;
651 } else if (IsEqualGUID(rguid
, &GUID_Inertia
)) {
652 newEffect
->effect
.type
= FF_INERTIA
;
653 } else if (IsEqualGUID(rguid
, &GUID_Damper
)) {
654 newEffect
->effect
.type
= FF_DAMPER
;
657 case DIEFT_CUSTOMFORCE
:
658 FIXME("Custom forces are not supported.\n");
659 HeapFree(GetProcessHeap(), 0, newEffect
);
660 return DIERR_INVALIDPARAM
;
662 FIXME("Unknown force type 0x%x.\n", type
);
663 HeapFree(GetProcessHeap(), 0, newEffect
);
664 return DIERR_INVALIDPARAM
;
667 /* mark as non-uploaded */
668 newEffect
->effect
.id
= -1;
670 newEffect
->entry
= parent_list_entry
;
672 *peff
= &newEffect
->IDirectInputEffect_iface
;
674 TRACE("Creating linux input system effect (%p) with guid %s\n",
675 *peff
, _dump_dinput_GUID(rguid
));
680 DECLSPEC_HIDDEN HRESULT
linuxinput_get_info_A(
683 LPDIEFFECTINFOA info
)
685 DWORD type
= typeFromGUID(rguid
);
687 TRACE("(%d, %s, %p) type=%d\n", fd
, _dump_dinput_GUID(rguid
), info
, type
);
689 if (!info
) return E_POINTER
;
691 if (info
->dwSize
!= sizeof(DIEFFECTINFOA
)) return DIERR_INVALIDPARAM
;
695 info
->dwEffType
= type
;
696 /* the event device API does not support querying for all these things
697 * therefore we assume that we have support for them
698 * that's not as dangerous as it sounds, since drivers are allowed to
699 * ignore parameters they claim to support anyway */
700 info
->dwEffType
|= DIEFT_DEADBAND
| DIEFT_FFATTACK
| DIEFT_FFFADE
701 | DIEFT_POSNEGCOEFFICIENTS
| DIEFT_POSNEGSATURATION
702 | DIEFT_SATURATION
| DIEFT_STARTDELAY
;
704 /* again, assume we have support for everything */
705 info
->dwStaticParams
= DIEP_ALLPARAMS
;
706 info
->dwDynamicParams
= info
->dwStaticParams
;
708 /* yes, this is windows behavior (print the GUID_Name for name) */
709 strcpy(info
->tszName
, _dump_dinput_GUID(rguid
));
714 DECLSPEC_HIDDEN HRESULT
linuxinput_get_info_W(
717 LPDIEFFECTINFOW info
)
719 DWORD type
= typeFromGUID(rguid
);
721 TRACE("(%d, %s, %p) type=%d\n", fd
, _dump_dinput_GUID(rguid
), info
, type
);
723 if (!info
) return E_POINTER
;
725 if (info
->dwSize
!= sizeof(DIEFFECTINFOW
)) return DIERR_INVALIDPARAM
;
729 info
->dwEffType
= type
;
730 /* the event device API does not support querying for all these things
731 * therefore we assume that we have support for them
732 * that's not as dangerous as it sounds, since drivers are allowed to
733 * ignore parameters they claim to support anyway */
734 info
->dwEffType
|= DIEFT_DEADBAND
| DIEFT_FFATTACK
| DIEFT_FFFADE
735 | DIEFT_POSNEGCOEFFICIENTS
| DIEFT_POSNEGSATURATION
736 | DIEFT_SATURATION
| DIEFT_STARTDELAY
;
738 /* again, assume we have support for everything */
739 info
->dwStaticParams
= DIEP_ALLPARAMS
;
740 info
->dwDynamicParams
= info
->dwStaticParams
;
742 /* yes, this is windows behavior (print the GUID_Name for name) */
743 MultiByteToWideChar(CP_ACP
, 0, _dump_dinput_GUID(rguid
), -1,
744 info
->tszName
, MAX_PATH
);
749 static const IDirectInputEffectVtbl LinuxInputEffectVtbl
= {
750 LinuxInputEffectImpl_QueryInterface
,
751 LinuxInputEffectImpl_AddRef
,
752 LinuxInputEffectImpl_Release
,
753 LinuxInputEffectImpl_Initialize
,
754 LinuxInputEffectImpl_GetEffectGuid
,
755 LinuxInputEffectImpl_GetParameters
,
756 LinuxInputEffectImpl_SetParameters
,
757 LinuxInputEffectImpl_Start
,
758 LinuxInputEffectImpl_Stop
,
759 LinuxInputEffectImpl_GetEffectStatus
,
760 LinuxInputEffectImpl_Download
,
761 LinuxInputEffectImpl_Unload
,
762 LinuxInputEffectImpl_Escape
765 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */