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 static double ff_effect_direction_to_rad(unsigned int dir
)
72 return (dir
& 0xffff) * M_PI
/ 0x8000;
75 /******************************************************************************
76 * LinuxInputEffectImpl
79 static ULONG WINAPI
LinuxInputEffectImpl_AddRef(
80 LPDIRECTINPUTEFFECT iface
)
82 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
83 return InterlockedIncrement(&(This
->ref
));
86 static HRESULT WINAPI
LinuxInputEffectImpl_Download(
87 LPDIRECTINPUTEFFECT iface
)
89 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
91 TRACE("(this=%p)\n", This
);
93 if (ioctl(*(This
->fd
), EVIOCSFF
, &This
->effect
) == -1) {
94 if (errno
== ENOMEM
) {
95 return DIERR_DEVICEFULL
;
97 FIXME("Could not upload effect. Assuming a disconnected device %d \"%s\".\n", *This
->fd
, strerror(errno
));
98 return DIERR_INPUTLOST
;
105 static HRESULT WINAPI
LinuxInputEffectImpl_Escape(
106 LPDIRECTINPUTEFFECT iface
,
109 WARN("(this=%p,%p): invalid: no hardware-specific escape codes in this"
110 " driver!\n", iface
, pesc
);
115 static HRESULT WINAPI
LinuxInputEffectImpl_GetEffectGuid(
116 LPDIRECTINPUTEFFECT iface
,
119 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
121 TRACE("(this=%p,%p)\n", This
, pguid
);
128 static HRESULT WINAPI
LinuxInputEffectImpl_GetEffectStatus(
129 LPDIRECTINPUTEFFECT iface
,
132 TRACE("(this=%p,%p)\n", iface
, pdwFlags
);
134 /* linux sends the effect status through an event.
135 * that event is trapped by our parent joystick driver
136 * and there is no clean way to pass it back to us. */
137 FIXME("Not enough information to provide a status.\n");
144 static HRESULT WINAPI
LinuxInputEffectImpl_GetParameters(
145 LPDIRECTINPUTEFFECT iface
,
149 HRESULT diErr
= DI_OK
;
150 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
151 TRACE("(this=%p,%p,%d)\n", This
, peff
, dwFlags
);
153 /* Major conversion factors are:
154 * times: millisecond (linux) -> microsecond (windows) (x * 1000)
155 * forces: scale 0x7FFF (linux) -> scale 10000 (windows) approx ((x / 33) * 10)
156 * angles: scale 0x7FFF (linux) -> scale 35999 (windows) approx ((x / 33) * 36)
157 * angle bases: 0 -> -y (down) (linux) -> 0 -> +x (right) (windows)
160 if (dwFlags
& DIEP_AXES
) {
161 if (peff
->cAxes
< 2 /* linuxinput effects always use 2 axes, x and y */)
162 diErr
= DIERR_MOREDATA
;
167 peff
->rgdwAxes
[0] = DIJOFS_X
;
168 peff
->rgdwAxes
[1] = DIJOFS_Y
;
172 if (dwFlags
& DIEP_DIRECTION
) {
174 diErr
= DIERR_MOREDATA
;
179 if (peff
->dwFlags
& DIEFF_CARTESIAN
) {
180 /* rotate so 0 points right */
181 double angle
= ff_effect_direction_to_rad(This
->effect
.direction
+ 0xc000);
182 peff
->rglDirection
[0] = sin(angle
) * 1000;
183 peff
->rglDirection
[1] = -cos(angle
) * 1000;
185 /* Polar and spherical coordinates are the same for two or less
187 * Note that we also use this case if NO flags are marked.
188 * According to MSDN, we should return the direction in the
189 * format that it was specified in, if no flags are marked.
191 peff
->rglDirection
[0] = (This
->effect
.direction
/ 33) * 36 + 9000;
192 if (peff
->rglDirection
[0] > 35999)
193 peff
->rglDirection
[0] -= 35999;
198 if (dwFlags
& DIEP_DURATION
) {
199 peff
->dwDuration
= (DWORD
)This
->effect
.replay
.length
* 1000;
202 if (dwFlags
& DIEP_ENVELOPE
) {
203 struct ff_envelope
* env
;
204 if (This
->effect
.type
== FF_CONSTANT
) env
= &This
->effect
.u
.constant
.envelope
;
205 else if (This
->effect
.type
== FF_PERIODIC
) env
= &This
->effect
.u
.periodic
.envelope
;
206 else if (This
->effect
.type
== FF_RAMP
) env
= &This
->effect
.u
.ramp
.envelope
;
209 peff
->lpEnvelope
= NULL
;
210 } else if (peff
->lpEnvelope
== NULL
) {
211 return DIERR_INVALIDPARAM
;
213 peff
->lpEnvelope
->dwAttackLevel
= (env
->attack_level
/ 33) * 10;
214 peff
->lpEnvelope
->dwAttackTime
= env
->attack_length
* 1000;
215 peff
->lpEnvelope
->dwFadeLevel
= (env
->fade_level
/ 33) * 10;
216 peff
->lpEnvelope
->dwFadeTime
= env
->fade_length
* 1000;
220 if (dwFlags
& DIEP_GAIN
) {
221 peff
->dwGain
= This
->gain
* 10000 / 0xFFFF;
224 if (dwFlags
& DIEP_SAMPLEPERIOD
) {
225 /* the linux input ff driver has no support for setting
226 * the playback sample period. 0 means default. */
227 peff
->dwSamplePeriod
= 0;
230 if (dwFlags
& DIEP_STARTDELAY
) {
231 peff
->dwStartDelay
= This
->effect
.replay
.delay
* 1000;
234 if (dwFlags
& DIEP_TRIGGERBUTTON
) {
235 FIXME("LinuxInput button mapping needs redoing; for now, assuming we're using an actual joystick.\n");
236 peff
->dwTriggerButton
= DIJOFS_BUTTON(This
->effect
.trigger
.button
- BTN_JOYSTICK
);
239 if (dwFlags
& DIEP_TRIGGERREPEATINTERVAL
) {
240 peff
->dwTriggerRepeatInterval
= This
->effect
.trigger
.interval
* 1000;
243 if (dwFlags
& DIEP_TYPESPECIFICPARAMS
) {
244 DWORD expectedsize
= 0;
245 if (This
->effect
.type
== FF_PERIODIC
) {
246 expectedsize
= sizeof(DIPERIODIC
);
247 } else if (This
->effect
.type
== FF_CONSTANT
) {
248 expectedsize
= sizeof(DICONSTANTFORCE
);
249 } else if (This
->effect
.type
== FF_SPRING
250 || This
->effect
.type
== FF_FRICTION
251 || This
->effect
.type
== FF_INERTIA
252 || This
->effect
.type
== FF_DAMPER
) {
253 expectedsize
= sizeof(DICONDITION
) * 2;
254 } else if (This
->effect
.type
== FF_RAMP
) {
255 expectedsize
= sizeof(DIRAMPFORCE
);
257 if (expectedsize
> peff
->cbTypeSpecificParams
)
258 diErr
= DIERR_MOREDATA
;
259 peff
->cbTypeSpecificParams
= expectedsize
;
263 if (This
->effect
.type
== FF_PERIODIC
) {
264 LPDIPERIODIC tsp
= peff
->lpvTypeSpecificParams
;
265 tsp
->dwMagnitude
= (This
->effect
.u
.periodic
.magnitude
/ 33) * 10;
266 tsp
->lOffset
= (This
->effect
.u
.periodic
.offset
/ 33) * 10;
267 tsp
->dwPhase
= (This
->effect
.u
.periodic
.phase
/ 33) * 36;
268 tsp
->dwPeriod
= (This
->effect
.u
.periodic
.period
* 1000);
269 } else if (This
->effect
.type
== FF_CONSTANT
) {
270 LPDICONSTANTFORCE tsp
= peff
->lpvTypeSpecificParams
;
271 tsp
->lMagnitude
= (This
->effect
.u
.constant
.level
/ 33) * 10;
272 } else if (This
->effect
.type
== FF_SPRING
273 || This
->effect
.type
== FF_FRICTION
274 || This
->effect
.type
== FF_INERTIA
275 || This
->effect
.type
== FF_DAMPER
) {
276 LPDICONDITION tsp
= peff
->lpvTypeSpecificParams
;
278 for (i
= 0; i
< 2; ++i
) {
279 tsp
[i
].lOffset
= (This
->effect
.u
.condition
[i
].center
/ 33) * 10;
280 tsp
[i
].lPositiveCoefficient
= (This
->effect
.u
.condition
[i
].right_coeff
/ 33) * 10;
281 tsp
[i
].lNegativeCoefficient
= (This
->effect
.u
.condition
[i
].left_coeff
/ 33) * 10;
282 tsp
[i
].dwPositiveSaturation
= (This
->effect
.u
.condition
[i
].right_saturation
/ 33) * 10;
283 tsp
[i
].dwNegativeSaturation
= (This
->effect
.u
.condition
[i
].left_saturation
/ 33) * 10;
284 tsp
[i
].lDeadBand
= (This
->effect
.u
.condition
[i
].deadband
/ 33) * 10;
286 } else if (This
->effect
.type
== FF_RAMP
) {
287 LPDIRAMPFORCE tsp
= peff
->lpvTypeSpecificParams
;
288 tsp
->lStart
= (This
->effect
.u
.ramp
.start_level
/ 33) * 10;
289 tsp
->lEnd
= (This
->effect
.u
.ramp
.end_level
/ 33) * 10;
297 static HRESULT WINAPI
LinuxInputEffectImpl_Initialize(
298 LPDIRECTINPUTEFFECT iface
,
303 FIXME("(this=%p,%p,%d,%s): stub!\n",
304 iface
, hinst
, dwVersion
, debugstr_guid(rguid
));
309 static HRESULT WINAPI
LinuxInputEffectImpl_QueryInterface(
310 LPDIRECTINPUTEFFECT iface
,
314 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
316 TRACE("(this=%p,%s,%p)\n", This
, debugstr_guid(riid
), ppvObject
);
318 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
319 IsEqualGUID(&IID_IDirectInputEffect
, riid
)) {
320 LinuxInputEffectImpl_AddRef(iface
);
325 TRACE("Unsupported interface!\n");
329 static HRESULT WINAPI
LinuxInputEffectImpl_Start(
330 LPDIRECTINPUTEFFECT iface
,
334 struct input_event event
;
335 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
337 TRACE("(this=%p,%d,%d)\n", This
, dwIterations
, dwFlags
);
339 if (!(dwFlags
& DIES_NODOWNLOAD
)) {
340 /* Download the effect if necessary */
341 if (This
->effect
.id
== -1) {
342 HRESULT res
= LinuxInputEffectImpl_Download(iface
);
348 if (dwFlags
& DIES_SOLO
) {
349 FIXME("Solo mode requested: should be stopping all effects here!\n");
353 event
.code
= This
->effect
.id
;
354 event
.value
= min( dwIterations
, INT_MAX
);
355 if (write(*(This
->fd
), &event
, sizeof(event
)) == -1) {
356 FIXME("Unable to write event. Assuming device disconnected.\n");
357 return DIERR_INPUTLOST
;
363 static HRESULT WINAPI
LinuxInputEffectImpl_SetParameters(
364 LPDIRECTINPUTEFFECT iface
,
368 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
369 DWORD type
= typeFromGUID(&This
->guid
);
370 HRESULT retval
= DI_OK
;
372 TRACE("(this=%p,%p,%d)\n", This
, peff
, dwFlags
);
374 dump_DIEFFECT(peff
, &This
->guid
, dwFlags
);
376 if ((dwFlags
& ~DIEP_NORESTART
& ~DIEP_NODOWNLOAD
& ~DIEP_START
) == 0) {
378 dwFlags
= DIEP_AXES
| DIEP_DIRECTION
| DIEP_DURATION
| DIEP_ENVELOPE
|
379 DIEP_GAIN
| DIEP_SAMPLEPERIOD
| DIEP_STARTDELAY
| DIEP_TRIGGERBUTTON
|
380 DIEP_TRIGGERREPEATINTERVAL
| DIEP_TYPESPECIFICPARAMS
;
383 if (dwFlags
& DIEP_AXES
) {
384 /* the linux input effect system only supports one or two axes */
386 return DIERR_INVALIDPARAM
;
387 else if (peff
->cAxes
< 1)
388 return DIERR_INCOMPLETEEFFECT
;
389 This
->first_axis_is_x
= peff
->rgdwAxes
[0] == DIJOFS_X
;
392 /* some of this may look funky, but it's 'cause the linux driver and directx have
393 * different opinions about which way direction "0" is. directx has 0 along the x
394 * axis (left), linux has it along the y axis (down). */
395 if (dwFlags
& DIEP_DIRECTION
) {
396 if (peff
->cAxes
== 1) {
397 if (peff
->dwFlags
& DIEFF_CARTESIAN
) {
398 if (dwFlags
& DIEP_AXES
) {
399 if (peff
->rgdwAxes
[0] == DIJOFS_X
&& peff
->rglDirection
[0] >= 0)
400 This
->effect
.direction
= 0x4000;
401 else if (peff
->rgdwAxes
[0] == DIJOFS_X
&& peff
->rglDirection
[0] < 0)
402 This
->effect
.direction
= 0xC000;
403 else if (peff
->rgdwAxes
[0] == DIJOFS_Y
&& peff
->rglDirection
[0] >= 0)
404 This
->effect
.direction
= 0;
405 else if (peff
->rgdwAxes
[0] == DIJOFS_Y
&& peff
->rglDirection
[0] < 0)
406 This
->effect
.direction
= 0x8000;
409 /* one-axis effects must use cartesian coords */
410 return DIERR_INVALIDPARAM
;
412 } else { /* two axes */
413 if (peff
->dwFlags
& DIEFF_CARTESIAN
) {
415 if (This
->first_axis_is_x
) {
416 x
= peff
->rglDirection
[0];
417 y
= peff
->rglDirection
[1];
419 x
= peff
->rglDirection
[1];
420 y
= peff
->rglDirection
[0];
422 This
->effect
.direction
= (int)((3 * M_PI
/ 2 - atan2(y
, x
)) * -0x7FFF / M_PI
);
424 /* Polar and spherical are the same for 2 axes */
425 /* Precision is important here, so we do double math with exact constants */
426 This
->effect
.direction
= (int)(((double)peff
->rglDirection
[0] - 90) / 35999) * 0x7FFF;
431 if (dwFlags
& DIEP_DURATION
)
432 This
->effect
.replay
.length
= peff
->dwDuration
/ 1000;
434 if (dwFlags
& DIEP_ENVELOPE
) {
435 struct ff_envelope
* env
;
436 if (This
->effect
.type
== FF_CONSTANT
) env
= &This
->effect
.u
.constant
.envelope
;
437 else if (This
->effect
.type
== FF_PERIODIC
) env
= &This
->effect
.u
.periodic
.envelope
;
438 else if (This
->effect
.type
== FF_RAMP
) env
= &This
->effect
.u
.ramp
.envelope
;
441 if (peff
->lpEnvelope
== NULL
) {
442 /* if this type had an envelope, reset it */
444 env
->attack_length
= 0;
445 env
->attack_level
= 0;
446 env
->fade_length
= 0;
450 /* did we get passed an envelope for a type that doesn't even have one? */
451 if (!env
) return DIERR_INVALIDPARAM
;
452 /* copy the envelope */
453 env
->attack_length
= peff
->lpEnvelope
->dwAttackTime
/ 1000;
454 env
->attack_level
= (peff
->lpEnvelope
->dwAttackLevel
/ 10) * 32;
455 env
->fade_length
= peff
->lpEnvelope
->dwFadeTime
/ 1000;
456 env
->fade_level
= (peff
->lpEnvelope
->dwFadeLevel
/ 10) * 32;
460 /* Gain and Sample Period settings are not supported by the linux
462 if (dwFlags
& DIEP_GAIN
) {
463 This
->gain
= 0xFFFF * peff
->dwGain
/ 10000;
464 TRACE("Effect gain requested but no effect gain functionality present.\n");
467 if (dwFlags
& DIEP_SAMPLEPERIOD
)
468 TRACE("Sample period requested but no sample period functionality present.\n");
470 if (dwFlags
& DIEP_STARTDELAY
)
471 This
->effect
.replay
.delay
= peff
->dwStartDelay
/ 1000;
473 if (dwFlags
& DIEP_TRIGGERBUTTON
) {
474 if (peff
->dwTriggerButton
!= -1) {
475 FIXME("Linuxinput button mapping needs redoing, assuming we're using a joystick.\n");
476 FIXME("Trigger button translation not yet implemented!\n");
478 This
->effect
.trigger
.button
= 0;
481 if (dwFlags
& DIEP_TRIGGERREPEATINTERVAL
)
482 This
->effect
.trigger
.interval
= peff
->dwTriggerRepeatInterval
/ 1000;
484 if (dwFlags
& DIEP_TYPESPECIFICPARAMS
) {
485 if (!(peff
->lpvTypeSpecificParams
))
486 return DIERR_INCOMPLETEEFFECT
;
487 if (type
== DIEFT_PERIODIC
) {
489 if (peff
->cbTypeSpecificParams
!= sizeof(DIPERIODIC
))
490 return DIERR_INVALIDPARAM
;
491 tsp
= peff
->lpvTypeSpecificParams
;
492 This
->effect
.u
.periodic
.magnitude
= (tsp
->dwMagnitude
/ 10) * 32;
493 This
->effect
.u
.periodic
.offset
= (tsp
->lOffset
/ 10) * 32;
494 This
->effect
.u
.periodic
.phase
= (tsp
->dwPhase
/ 9) * 8; /* == (/ 36 * 32) */
495 This
->effect
.u
.periodic
.period
= tsp
->dwPeriod
/ 1000;
496 } else if (type
== DIEFT_CONSTANTFORCE
) {
497 LPCDICONSTANTFORCE tsp
;
498 if (peff
->cbTypeSpecificParams
!= sizeof(DICONSTANTFORCE
))
499 return DIERR_INVALIDPARAM
;
500 tsp
= peff
->lpvTypeSpecificParams
;
501 This
->effect
.u
.constant
.level
= (max(min(tsp
->lMagnitude
, 10000), -10000) / 10) * 32;
502 } else if (type
== DIEFT_RAMPFORCE
) {
504 if (peff
->cbTypeSpecificParams
!= sizeof(DIRAMPFORCE
))
505 return DIERR_INVALIDPARAM
;
506 tsp
= peff
->lpvTypeSpecificParams
;
507 This
->effect
.u
.ramp
.start_level
= (tsp
->lStart
/ 10) * 32;
508 This
->effect
.u
.ramp
.end_level
= (tsp
->lEnd
/ 10) * 32;
509 } else if (type
== DIEFT_CONDITION
) {
510 LPCDICONDITION tsp
= peff
->lpvTypeSpecificParams
;
511 if (peff
->cbTypeSpecificParams
== sizeof(DICONDITION
)) {
512 /* One condition block. This needs to be rotated to direction,
513 * and expanded to separate x and y conditions. */
515 double factor
[2], angle
;
516 /* rotate so 0 points right */
517 angle
= ff_effect_direction_to_rad(This
->effect
.direction
+ 0xc000);
518 factor
[0] = sin(angle
);
519 factor
[1] = -cos(angle
);
520 for (i
= 0; i
< 2; ++i
) {
521 This
->effect
.u
.condition
[i
].center
= (int)(factor
[i
] * (tsp
->lOffset
/ 10) * 32);
522 This
->effect
.u
.condition
[i
].right_coeff
= (int)(factor
[i
] * (tsp
->lPositiveCoefficient
/ 10) * 32);
523 This
->effect
.u
.condition
[i
].left_coeff
= (int)(factor
[i
] * (tsp
->lNegativeCoefficient
/ 10) * 32);
524 This
->effect
.u
.condition
[i
].right_saturation
= (int)(factor
[i
] * (tsp
->dwPositiveSaturation
/ 10) * 32);
525 This
->effect
.u
.condition
[i
].left_saturation
= (int)(factor
[i
] * (tsp
->dwNegativeSaturation
/ 10) * 32);
526 This
->effect
.u
.condition
[i
].deadband
= (int)(factor
[i
] * (tsp
->lDeadBand
/ 10) * 32);
528 } else if (peff
->cbTypeSpecificParams
== 2 * sizeof(DICONDITION
)) {
529 /* Two condition blocks. Direct parameter copy. */
531 for (i
= 0; i
< 2; ++i
) {
532 This
->effect
.u
.condition
[i
].center
= (tsp
[i
].lOffset
/ 10) * 32;
533 This
->effect
.u
.condition
[i
].right_coeff
= (tsp
[i
].lPositiveCoefficient
/ 10) * 32;
534 This
->effect
.u
.condition
[i
].left_coeff
= (tsp
[i
].lNegativeCoefficient
/ 10) * 32;
535 This
->effect
.u
.condition
[i
].right_saturation
= (tsp
[i
].dwPositiveSaturation
/ 10) * 32;
536 This
->effect
.u
.condition
[i
].left_saturation
= (tsp
[i
].dwNegativeSaturation
/ 10) * 32;
537 This
->effect
.u
.condition
[i
].deadband
= (tsp
[i
].lDeadBand
/ 10) * 32;
540 return DIERR_INVALIDPARAM
;
543 FIXME("Custom force types are not supported\n");
544 return DIERR_INVALIDPARAM
;
548 if (!(dwFlags
& DIEP_NODOWNLOAD
))
549 retval
= LinuxInputEffectImpl_Download(iface
);
551 return DI_DOWNLOADSKIPPED
;
553 if (dwFlags
& DIEP_NORESTART
)
554 TRACE("DIEP_NORESTART: not handled (we have no control of that).\n");
556 if (dwFlags
& DIEP_START
)
557 retval
= LinuxInputEffectImpl_Start(iface
, 1, 0);
564 static HRESULT WINAPI
LinuxInputEffectImpl_Stop(
565 LPDIRECTINPUTEFFECT iface
)
567 struct input_event event
;
568 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
570 TRACE("(this=%p)\n", This
);
573 event
.code
= This
->effect
.id
;
575 /* we don't care about the success or failure of this call */
576 write(*(This
->fd
), &event
, sizeof(event
));
581 static HRESULT WINAPI
LinuxInputEffectImpl_Unload(
582 LPDIRECTINPUTEFFECT iface
)
584 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
585 TRACE("(this=%p)\n", This
);
587 /* Erase the downloaded effect */
588 if (ioctl(*(This
->fd
), EVIOCRMFF
, This
->effect
.id
) == -1)
589 return DIERR_INVALIDPARAM
;
591 /* Mark the effect as deallocated */
592 This
->effect
.id
= -1;
597 static ULONG WINAPI
LinuxInputEffectImpl_Release(LPDIRECTINPUTEFFECT iface
)
599 LinuxInputEffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
600 ULONG ref
= InterlockedDecrement(&(This
->ref
));
604 LinuxInputEffectImpl_Stop(iface
);
605 LinuxInputEffectImpl_Unload(iface
);
606 list_remove(This
->entry
);
607 HeapFree(GetProcessHeap(), 0, LIST_ENTRY(This
->entry
, effect_list_item
, entry
));
608 HeapFree(GetProcessHeap(), 0, This
);
613 /******************************************************************************
617 DECLSPEC_HIDDEN HRESULT
linuxinput_create_effect(
620 struct list
*parent_list_entry
,
621 LPDIRECTINPUTEFFECT
* peff
)
623 LinuxInputEffectImpl
* newEffect
= HeapAlloc(GetProcessHeap(),
624 HEAP_ZERO_MEMORY
, sizeof(LinuxInputEffectImpl
));
625 DWORD type
= typeFromGUID(rguid
);
627 newEffect
->IDirectInputEffect_iface
.lpVtbl
= &LinuxInputEffectVtbl
;
629 newEffect
->guid
= *rguid
;
631 newEffect
->gain
= 0xFFFF;
633 /* set the type. this cannot be changed over the effect's life. */
636 newEffect
->effect
.type
= FF_PERIODIC
;
637 if (IsEqualGUID(rguid
, &GUID_Sine
)) {
638 newEffect
->effect
.u
.periodic
.waveform
= FF_SINE
;
639 } else if (IsEqualGUID(rguid
, &GUID_Triangle
)) {
640 newEffect
->effect
.u
.periodic
.waveform
= FF_TRIANGLE
;
641 } else if (IsEqualGUID(rguid
, &GUID_Square
)) {
642 newEffect
->effect
.u
.periodic
.waveform
= FF_SQUARE
;
643 } else if (IsEqualGUID(rguid
, &GUID_SawtoothUp
)) {
644 newEffect
->effect
.u
.periodic
.waveform
= FF_SAW_UP
;
645 } else if (IsEqualGUID(rguid
, &GUID_SawtoothDown
)) {
646 newEffect
->effect
.u
.periodic
.waveform
= FF_SAW_DOWN
;
649 case DIEFT_CONSTANTFORCE
:
650 newEffect
->effect
.type
= FF_CONSTANT
;
652 case DIEFT_RAMPFORCE
:
653 newEffect
->effect
.type
= FF_RAMP
;
655 case DIEFT_CONDITION
:
656 if (IsEqualGUID(rguid
, &GUID_Spring
)) {
657 newEffect
->effect
.type
= FF_SPRING
;
658 } else if (IsEqualGUID(rguid
, &GUID_Friction
)) {
659 newEffect
->effect
.type
= FF_FRICTION
;
660 } else if (IsEqualGUID(rguid
, &GUID_Inertia
)) {
661 newEffect
->effect
.type
= FF_INERTIA
;
662 } else if (IsEqualGUID(rguid
, &GUID_Damper
)) {
663 newEffect
->effect
.type
= FF_DAMPER
;
666 case DIEFT_CUSTOMFORCE
:
667 FIXME("Custom forces are not supported.\n");
668 HeapFree(GetProcessHeap(), 0, newEffect
);
669 return DIERR_INVALIDPARAM
;
671 FIXME("Unknown force type 0x%x.\n", type
);
672 HeapFree(GetProcessHeap(), 0, newEffect
);
673 return DIERR_INVALIDPARAM
;
676 /* mark as non-uploaded */
677 newEffect
->effect
.id
= -1;
679 newEffect
->entry
= parent_list_entry
;
681 *peff
= &newEffect
->IDirectInputEffect_iface
;
683 TRACE("Creating linux input system effect (%p) with guid %s\n",
684 *peff
, _dump_dinput_GUID(rguid
));
689 DECLSPEC_HIDDEN HRESULT
linuxinput_get_info_A(
692 LPDIEFFECTINFOA info
)
694 DWORD type
= typeFromGUID(rguid
);
696 TRACE("(%d, %s, %p) type=%d\n", fd
, _dump_dinput_GUID(rguid
), info
, type
);
698 if (!info
) return E_POINTER
;
700 if (info
->dwSize
!= sizeof(DIEFFECTINFOA
)) return DIERR_INVALIDPARAM
;
704 info
->dwEffType
= type
;
705 /* the event device API does not support querying for all these things
706 * therefore we assume that we have support for them
707 * that's not as dangerous as it sounds, since drivers are allowed to
708 * ignore parameters they claim to support anyway */
709 info
->dwEffType
|= DIEFT_DEADBAND
| DIEFT_FFATTACK
| DIEFT_FFFADE
710 | DIEFT_POSNEGCOEFFICIENTS
| DIEFT_POSNEGSATURATION
711 | DIEFT_SATURATION
| DIEFT_STARTDELAY
;
713 /* again, assume we have support for everything */
714 info
->dwStaticParams
= DIEP_ALLPARAMS
;
715 info
->dwDynamicParams
= info
->dwStaticParams
;
717 /* yes, this is windows behavior (print the GUID_Name for name) */
718 strcpy(info
->tszName
, _dump_dinput_GUID(rguid
));
723 DECLSPEC_HIDDEN HRESULT
linuxinput_get_info_W(
726 LPDIEFFECTINFOW info
)
728 DWORD type
= typeFromGUID(rguid
);
730 TRACE("(%d, %s, %p) type=%d\n", fd
, _dump_dinput_GUID(rguid
), info
, type
);
732 if (!info
) return E_POINTER
;
734 if (info
->dwSize
!= sizeof(DIEFFECTINFOW
)) return DIERR_INVALIDPARAM
;
738 info
->dwEffType
= type
;
739 /* the event device API does not support querying for all these things
740 * therefore we assume that we have support for them
741 * that's not as dangerous as it sounds, since drivers are allowed to
742 * ignore parameters they claim to support anyway */
743 info
->dwEffType
|= DIEFT_DEADBAND
| DIEFT_FFATTACK
| DIEFT_FFFADE
744 | DIEFT_POSNEGCOEFFICIENTS
| DIEFT_POSNEGSATURATION
745 | DIEFT_SATURATION
| DIEFT_STARTDELAY
;
747 /* again, assume we have support for everything */
748 info
->dwStaticParams
= DIEP_ALLPARAMS
;
749 info
->dwDynamicParams
= info
->dwStaticParams
;
751 /* yes, this is windows behavior (print the GUID_Name for name) */
752 MultiByteToWideChar(CP_ACP
, 0, _dump_dinput_GUID(rguid
), -1,
753 info
->tszName
, MAX_PATH
);
758 static const IDirectInputEffectVtbl LinuxInputEffectVtbl
= {
759 LinuxInputEffectImpl_QueryInterface
,
760 LinuxInputEffectImpl_AddRef
,
761 LinuxInputEffectImpl_Release
,
762 LinuxInputEffectImpl_Initialize
,
763 LinuxInputEffectImpl_GetEffectGuid
,
764 LinuxInputEffectImpl_GetParameters
,
765 LinuxInputEffectImpl_SetParameters
,
766 LinuxInputEffectImpl_Start
,
767 LinuxInputEffectImpl_Stop
,
768 LinuxInputEffectImpl_GetEffectStatus
,
769 LinuxInputEffectImpl_Download
,
770 LinuxInputEffectImpl_Unload
,
771 LinuxInputEffectImpl_Escape
774 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */