1 /* DirectInput Joystick device
3 * Copyright 1998,2000 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2005 Daniel Remenak
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
37 #include <sys/fcntl.h>
38 #ifdef HAVE_SYS_IOCTL_H
39 # include <sys/ioctl.h>
42 #ifdef HAVE_SYS_ERRNO_H
43 # include <sys/errno.h>
45 #ifdef HAVE_LINUX_INPUT_H
46 # include <linux/input.h>
48 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
49 # define HAVE_CORRECT_LINUXINPUT_H
52 #ifdef HAVE_SYS_POLL_H
53 # include <sys/poll.h>
56 #include "wine/debug.h"
57 #include "wine/unicode.h"
63 #include "dinput_private.h"
64 #include "device_private.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
68 #ifdef HAVE_CORRECT_LINUXINPUT_H
70 #define EVDEVPREFIX "/dev/input/event"
72 /* Wine joystick driver object instances */
73 #define WINE_JOYSTICK_MAX_AXES 8
74 #define WINE_JOYSTICK_MAX_POVS 4
75 #define WINE_JOYSTICK_MAX_BUTTONS 128
77 typedef struct EffectListItem EffectListItem
;
80 LPDIRECTINPUTEFFECT ref
;
81 struct EffectListItem
* next
;
84 /* implemented in effect_linuxinput.c */
85 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, LPDIRECTINPUTEFFECT
* peff
);
86 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
87 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
89 typedef struct JoystickImpl JoystickImpl
;
90 static const IDirectInputDevice8AVtbl JoystickAvt
;
91 static const IDirectInputDevice8WVtbl JoystickWvt
;
101 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
102 BYTE evbits
[(EV_MAX
+7)/8];
103 BYTE absbits
[(ABS_MAX
+7)/8];
104 BYTE keybits
[(KEY_MAX
+7)/8];
105 BYTE ffbits
[(FF_MAX
+7)/8];
108 #define AXIS_ABSMIN 1
109 #define AXIS_ABSMAX 2
110 #define AXIS_ABSFUZZ 3
111 #define AXIS_ABSFLAT 4
113 /* data returned by the EVIOCGABS() ioctl */
114 int axes
[ABS_MAX
][5];
122 /* what range and deadzone the game wants */
130 struct IDirectInputDevice2AImpl base
;
132 struct JoyDev
*joydev
;
134 /* joystick private */
139 struct ObjProps props
[ABS_MAX
];
143 /* LUT for KEY_ to offset in rgbButtons */
144 BYTE buttons
[KEY_MAX
];
150 /* Force feedback variables */
151 EffectListItem
* top_effect
;
155 static void fake_current_js_state(JoystickImpl
*ji
);
156 static DWORD
map_pov(int event_value
, int is_x
);
157 static void find_joydevs(void);
159 /* This GUID is slightly different from the linux joystick one. Take note. */
160 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
164 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
167 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
169 #define MAX_JOYDEV 64
171 static int have_joydevs
= -1;
172 static struct JoyDev
*joydevs
= NULL
;
174 static void find_joydevs(void)
178 if (have_joydevs
!=-1) {
184 for (i
=0;i
<MAX_JOYDEV
;i
++) {
186 struct JoyDev joydev
= {0};
191 snprintf(buf
,MAX_PATH
,EVDEVPREFIX
"%d",i
);
194 if ((fd
=open(buf
, O_RDWR
))==-1) {
195 fd
= open(buf
, O_RDONLY
);
200 if ((-1==ioctl(fd
,EVIOCGBIT(0,sizeof(joydev
.evbits
)),joydev
.evbits
))) {
201 perror("EVIOCGBIT 0");
205 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(joydev
.absbits
)),joydev
.absbits
)) {
206 perror("EVIOCGBIT EV_ABS");
210 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(joydev
.keybits
)),joydev
.keybits
)) {
211 perror("EVIOCGBIT EV_KEY");
215 /* A true joystick has at least axis X and Y, and at least 1
216 * button. copied from linux/drivers/input/joydev.c */
217 if (test_bit(joydev
.absbits
,ABS_X
) && test_bit(joydev
.absbits
,ABS_Y
) &&
218 ( test_bit(joydev
.keybits
,BTN_TRIGGER
) ||
219 test_bit(joydev
.keybits
,BTN_A
) ||
220 test_bit(joydev
.keybits
,BTN_1
)
224 joydev
.device
= strdup(buf
);
226 if (-1!=ioctl(fd
, EVIOCGNAME(MAX_PATH
-1), buf
)) {
228 joydev
.name
= strdup(buf
);
230 joydev
.name
= joydev
.device
;
233 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
234 joydev
.guid
.Data3
+= have_joydevs
;
236 TRACE("Found a joystick on %s: %s (%s)\n",
237 joydev
.device
, joydev
.name
,
238 debugstr_guid(&joydev
.guid
)
241 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
243 test_bit(joydev
.evbits
, EV_FF
) &&
244 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
245 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
246 joydev
.num_effects
> 0)
248 TRACE(" ... with force feedback\n");
253 for (j
=0;j
<ABS_MAX
;j
++) {
254 if (test_bit(joydev
.absbits
,j
)) {
255 if (-1!=ioctl(fd
,EVIOCGABS(j
),&(joydev
.axes
[j
]))) {
256 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
258 joydev
.axes
[j
][AXIS_ABS
],
259 joydev
.axes
[j
][AXIS_ABSMIN
],
260 joydev
.axes
[j
][AXIS_ABSMAX
],
261 joydev
.axes
[j
][AXIS_ABSFUZZ
],
262 joydev
.axes
[j
][AXIS_ABSFLAT
]
268 if (have_joydevs
==0) {
269 joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
271 HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1+have_joydevs
) * sizeof(struct JoyDev
));
273 memcpy(joydevs
+have_joydevs
, &joydev
, sizeof(struct JoyDev
));
282 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
286 if (id
>= have_joydevs
) {
290 if (!((dwDevType
== 0) ||
291 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
292 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
295 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
296 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
300 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
301 lpddi
->guidInstance
= joydevs
[id
].guid
;
302 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
304 lpddi
->guidFFDriver
= GUID_NULL
;
305 if (version
>= 0x0800)
306 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
308 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
310 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
311 strcpy(lpddi
->tszProductName
, joydevs
[id
].device
);
317 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
321 if (id
>= have_joydevs
) {
325 if (!((dwDevType
== 0) ||
326 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
327 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
330 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
331 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
335 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
336 lpddi
->guidInstance
= joydevs
[id
].guid
;
337 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
339 lpddi
->guidFFDriver
= GUID_NULL
;
340 if (version
>= 0x0800)
341 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
343 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
345 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
346 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].device
, -1, lpddi
->tszProductName
, MAX_PATH
);
352 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, struct JoyDev
*joydev
)
354 JoystickImpl
* newDevice
;
355 LPDIDATAFORMAT df
= NULL
;
358 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
359 if (!newDevice
) return NULL
;
361 newDevice
->base
.lpVtbl
= jvt
;
362 newDevice
->base
.ref
= 1;
363 memcpy(&newDevice
->base
.guid
, rguid
, sizeof(*rguid
));
364 InitializeCriticalSection(&newDevice
->base
.crit
);
365 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
366 newDevice
->joyfd
= -1;
367 newDevice
->base
.dinput
= dinput
;
368 newDevice
->joydev
= joydev
;
369 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
370 newDevice
->ff_state
= FF_STATUS_STOPPED
;
373 /* Create copy of default data format */
374 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
375 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
376 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
378 /* Supported Axis & POVs should map 1-to-1 */
379 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
381 if (!test_bit(newDevice
->joydev
->absbits
, i
)) {
382 newDevice
->axes
[i
] = -1;
386 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
], df
->dwObjSize
);
387 newDevice
->axes
[i
] = idx
;
388 newDevice
->props
[idx
].havemin
= newDevice
->joydev
->axes
[i
][AXIS_ABSMIN
];
389 newDevice
->props
[idx
].havemax
= newDevice
->joydev
->axes
[i
][AXIS_ABSMAX
];
390 newDevice
->props
[idx
].wantmin
= 0;
391 newDevice
->props
[idx
].wantmax
= 0xffff;
392 newDevice
->props
[idx
].deadzone
= 0;
393 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numAxes
++) | DIDFT_ABSAXIS
;
396 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
398 if (!test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) ||
399 !test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2)) {
400 newDevice
->axes
[ABS_HAT0X
+ i
* 2] = newDevice
->axes
[ABS_HAT0Y
+ i
* 2] = -1;
404 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
+ WINE_JOYSTICK_MAX_AXES
], df
->dwObjSize
);
405 newDevice
->axes
[ABS_HAT0X
+ i
* 2] = newDevice
->axes
[ABS_HAT0Y
+ i
* 2] = i
;
406 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numPOVs
++) | DIDFT_POV
;
409 /* Buttons can be anywhere, so check all */
410 for (i
= 0; i
< KEY_MAX
&& newDevice
->numButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
412 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
414 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->numButtons
+ WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
], df
->dwObjSize
);
415 newDevice
->buttons
[i
] = 0x80 | newDevice
->numButtons
;
416 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numButtons
++) | DIDFT_PSHBUTTON
;
420 fake_current_js_state(newDevice
);
422 newDevice
->base
.data_format
.wine_df
= df
;
423 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->base
.dinput
);
427 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
428 HeapFree(GetProcessHeap(), 0, df
);
429 HeapFree(GetProcessHeap(), 0, newDevice
);
433 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
439 for (i
=0; i
<have_joydevs
; i
++) {
440 if (IsEqualGUID(&GUID_Joystick
,rguid
) ||
441 IsEqualGUID(&joydevs
[i
].guid
,rguid
)
443 if ((riid
== NULL
) ||
444 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
445 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
446 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
447 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
448 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, &joydevs
[i
]);
449 TRACE("Creating a Joystick device (%p)\n", *pdev
);
451 ERR("out of memory\n");
452 return DIERR_OUTOFMEMORY
;
456 return DIERR_NOINTERFACE
;
461 return DIERR_DEVICENOTREG
;
465 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
471 for (i
=0; i
<have_joydevs
; i
++) {
472 if (IsEqualGUID(&GUID_Joystick
,rguid
) ||
473 IsEqualGUID(&joydevs
[i
].guid
,rguid
)
475 if ((riid
== NULL
) ||
476 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
477 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
478 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
479 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
480 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, &joydevs
[i
]);
481 TRACE("Creating a Joystick device (%p)\n", *pdev
);
483 ERR("out of memory\n");
484 return DIERR_OUTOFMEMORY
;
488 return DIERR_NOINTERFACE
;
493 return DIERR_DEVICENOTREG
;
496 const struct dinput_device joystick_linuxinput_device
= {
497 "Wine Linux-input joystick driver",
500 joydev_create_deviceA
,
501 joydev_create_deviceW
504 /******************************************************************************
507 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
509 JoystickImpl
*This
= (JoystickImpl
*)iface
;
512 ref
= InterlockedDecrement(&This
->base
.ref
);
516 IDirectInputDevice_Unacquire(iface
);
518 /* Reset the FF state, free all effects, etc */
519 IDirectInputDevice8_SendForceFeedbackCommand(iface
, DISFFC_RESET
);
521 /* Free the data queue */
522 HeapFree(GetProcessHeap(), 0, This
->base
.data_queue
);
524 /* release the data transform filter */
525 HeapFree(GetProcessHeap(), 0, This
->base
.data_format
.wine_df
->rgodf
);
526 HeapFree(GetProcessHeap(), 0, This
->base
.data_format
.wine_df
);
527 release_DataFormat(&This
->base
.data_format
);
529 IDirectInput_Release((LPDIRECTINPUTDEVICE8A
)This
->base
.dinput
);
530 This
->base
.crit
.DebugInfo
->Spare
[0] = 0;
531 DeleteCriticalSection(&This
->base
.crit
);
533 HeapFree(GetProcessHeap(),0,This
);
537 /******************************************************************************
538 * Acquire : gets exclusive control of the joystick
540 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
542 JoystickImpl
*This
= (JoystickImpl
*)iface
;
545 TRACE("(this=%p)\n",This
);
547 res
= IDirectInputDevice2AImpl_Acquire(iface
);
549 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDWR
))) {
550 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDONLY
))) {
551 /* Couldn't open the device at all */
552 perror(This
->joydev
->device
);
553 IDirectInputDevice2AImpl_Unacquire(iface
);
554 return DIERR_NOTFOUND
;
556 /* Couldn't open in r/w but opened in read-only. */
557 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
565 /******************************************************************************
566 * Unacquire : frees the joystick
568 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
570 JoystickImpl
*This
= (JoystickImpl
*)iface
;
573 TRACE("(this=%p)\n",This
);
574 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
575 if (res
==DI_OK
&& This
->joyfd
!=-1) {
583 * This maps the read value (from the input event) to a value in the
584 * 'wanted' range. It also autodetects the possible range of the axis and
585 * adapts values accordingly.
588 map_axis(JoystickImpl
* This
, int axis
, int val
) {
589 int hmax
= This
->props
[axis
].havemax
;
590 int hmin
= This
->props
[axis
].havemin
;
591 int wmin
= This
->props
[axis
].wantmin
;
592 int wmax
= This
->props
[axis
].wantmax
;
595 /* map the value from the hmin-hmax range into the wmin-wmax range */
596 ret
= MulDiv( val
- hmin
, wmax
- wmin
, hmax
- hmin
) + wmin
;
598 TRACE("hmin=%d hmax=%d wmin=%d wmax=%d val=%d ret=%d\n", hmin
, hmax
, wmin
, wmax
, val
, ret
);
601 /* deadzone doesn't work comfortably enough right now. needs more testing*/
602 if ((ret
> -deadz
/2 ) && (ret
< deadz
/2)) {
603 FIXME("%d in deadzone, return mid.\n",val
);
604 return (wmax
-wmin
)/2+wmin
;
611 * set the current state of the js device as it would be with the middle
614 static void fake_current_js_state(JoystickImpl
*ji
)
617 /* center the axes */
618 ji
->js
.lX
= ji
->axes
[ABS_X
]!=-1 ? map_axis(ji
, ji
->axes
[ABS_X
], ji
->joydev
->axes
[ABS_X
][AXIS_ABS
]) : 0;
619 ji
->js
.lY
= ji
->axes
[ABS_Y
]!=-1 ? map_axis(ji
, ji
->axes
[ABS_Y
], ji
->joydev
->axes
[ABS_Y
][AXIS_ABS
]) : 0;
620 ji
->js
.lZ
= ji
->axes
[ABS_Z
]!=-1 ? map_axis(ji
, ji
->axes
[ABS_Z
], ji
->joydev
->axes
[ABS_Z
][AXIS_ABS
]) : 0;
621 ji
->js
.lRx
= ji
->axes
[ABS_RX
]!=-1 ? map_axis(ji
, ji
->axes
[ABS_RX
], ji
->joydev
->axes
[ABS_RX
][AXIS_ABS
]) : 0;
622 ji
->js
.lRy
= ji
->axes
[ABS_RY
]!=-1 ? map_axis(ji
, ji
->axes
[ABS_RY
], ji
->joydev
->axes
[ABS_RY
][AXIS_ABS
]) : 0;
623 ji
->js
.lRz
= ji
->axes
[ABS_RZ
]!=-1 ? map_axis(ji
, ji
->axes
[ABS_RZ
], ji
->joydev
->axes
[ABS_RZ
][AXIS_ABS
]) : 0;
624 ji
->js
.rglSlider
[0] = ji
->axes
[ABS_THROTTLE
]!=-1 ? map_axis(ji
, ji
->axes
[ABS_THROTTLE
], ji
->joydev
->axes
[ABS_THROTTLE
][AXIS_ABS
]) : 0;
625 ji
->js
.rglSlider
[1] = ji
->axes
[ABS_RUDDER
]!=-1 ? map_axis(ji
, ji
->axes
[ABS_RUDDER
], ji
->joydev
->axes
[ABS_RUDDER
][AXIS_ABS
]) : 0;
626 /* POV center is -1 */
627 for (i
=0; i
<4; i
++) {
628 ji
->js
.rgdwPOV
[i
] = -1;
633 * Maps an event value to a DX "clock" position:
638 static DWORD
map_pov(int event_value
, int is_x
)
644 } else if (event_value
>0) {
650 } else if (event_value
>0) {
657 /* convert wine format offset to user format object index */
658 static void joy_polldev(JoystickImpl
*This
)
661 struct input_event ie
;
671 plfd
.fd
= This
->joyfd
;
672 plfd
.events
= POLLIN
;
674 if (poll(&plfd
,1,0) != 1)
677 /* we have one event, so we can read */
678 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
681 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
683 case EV_KEY
: /* button */
685 int btn
= This
->buttons
[ie
.code
];
687 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
691 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
692 This
->js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
698 int axis
= This
->axes
[ie
.code
];
702 inst_id
= DIDFT_MAKEINSTANCE(axis
) | (ie
.code
< ABS_HAT0X
? DIDFT_ABSAXIS
: DIDFT_POV
);
703 value
= map_axis(This
, axis
, ie
.value
);
706 case ABS_X
: This
->js
.lX
= value
; break;
707 case ABS_Y
: This
->js
.lY
= value
; break;
708 case ABS_Z
: This
->js
.lZ
= value
; break;
709 case ABS_RX
: This
->js
.lRx
= value
; break;
710 case ABS_RY
: This
->js
.lRy
= value
; break;
711 case ABS_RZ
: This
->js
.lRz
= value
; break;
712 case ABS_THROTTLE
: This
->js
.rglSlider
[0] = value
; break;
713 case ABS_RUDDER
: This
->js
.rglSlider
[1] = value
; break;
716 This
->js
.rgdwPOV
[0] = value
= map_pov(ie
.value
, ie
.code
==ABS_HAT0X
);
720 This
->js
.rgdwPOV
[1] = value
= map_pov(ie
.value
, ie
.code
==ABS_HAT1X
);
724 This
->js
.rgdwPOV
[2] = value
= map_pov(ie
.value
, ie
.code
==ABS_HAT2X
);
728 This
->js
.rgdwPOV
[3] = value
= map_pov(ie
.value
, ie
.code
==ABS_HAT3X
);
731 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
736 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
738 This
->ff_state
= ie
.value
;
743 /* there is nothing to do */
747 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
751 queue_event((LPDIRECTINPUTDEVICE8A
)This
,
752 id_to_offset(&This
->base
.data_format
, inst_id
),
753 value
, ie
.time
.tv_usec
, This
->base
.dinput
->evsequence
++);
757 /******************************************************************************
758 * GetDeviceState : returns the "state" of the joystick.
761 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
762 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
764 JoystickImpl
*This
= (JoystickImpl
*)iface
;
766 TRACE("(this=%p,0x%08x,%p)\n", This
, len
, ptr
);
768 if (This
->joyfd
==-1) {
769 WARN("not acquired\n");
770 return DIERR_NOTACQUIRED
;
775 /* convert and copy data to user supplied buffer */
776 fill_DataFormat(ptr
, &This
->js
, &This
->base
.data_format
);
781 /******************************************************************************
782 * SetProperty : change input device properties
784 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
788 JoystickImpl
*This
= (JoystickImpl
*)iface
;
791 WARN("invalid argument\n");
792 return DIERR_INVALIDPARAM
;
795 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
796 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
797 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
799 if (!HIWORD(rguid
)) {
800 switch (LOWORD(rguid
)) {
801 case (DWORD
)DIPROP_RANGE
: {
802 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
804 if (ph
->dwHow
== DIPH_DEVICE
) {
806 TRACE("proprange(%d,%d) all\n", pr
->lMin
, pr
->lMax
);
807 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
808 This
->props
[i
].wantmin
= pr
->lMin
;
809 This
->props
[i
].wantmax
= pr
->lMax
;
812 int obj
= find_property(&This
->base
.data_format
, ph
);
814 TRACE("proprange(%d,%d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
816 This
->props
[obj
].wantmin
= pr
->lMin
;
817 This
->props
[obj
].wantmax
= pr
->lMax
;
820 fake_current_js_state(This
);
823 case (DWORD
)DIPROP_DEADZONE
: {
824 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
825 if (ph
->dwHow
== DIPH_DEVICE
) {
827 TRACE("deadzone(%d) all\n", pd
->dwData
);
828 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
829 This
->props
[i
].deadzone
= pd
->dwData
;
832 int obj
= find_property(&This
->base
.data_format
, ph
);
834 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
836 This
->props
[obj
].deadzone
= pd
->dwData
;
839 fake_current_js_state(This
);
842 case (DWORD
)DIPROP_CALIBRATIONMODE
: {
843 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
844 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
848 return IDirectInputDevice2AImpl_SetProperty(iface
, rguid
, ph
);
854 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
855 LPDIRECTINPUTDEVICE8A iface
,
856 LPDIDEVCAPS lpDIDevCaps
)
858 JoystickImpl
*This
= (JoystickImpl
*)iface
;
860 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
863 WARN("invalid pointer\n");
867 if (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) {
868 WARN("invalid argument\n");
869 return DIERR_INVALIDPARAM
;
872 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
873 if (This
->base
.dinput
->dwVersion
>= 0x0800)
874 lpDIDevCaps
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
876 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
878 if (This
->joydev
->has_ff
)
879 lpDIDevCaps
->dwFlags
|= DIDC_FORCEFEEDBACK
;
881 lpDIDevCaps
->dwAxes
= This
->numAxes
;
882 lpDIDevCaps
->dwButtons
= This
->numButtons
;
883 lpDIDevCaps
->dwPOVs
= This
->numPOVs
;
888 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
) {
889 JoystickImpl
*This
= (JoystickImpl
*)iface
;
890 TRACE("(%p)\n",This
);
892 if (This
->joyfd
==-1) {
893 return DIERR_NOTACQUIRED
;
900 /******************************************************************************
901 * GetProperty : get input device properties
903 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
905 LPDIPROPHEADER pdiph
)
907 JoystickImpl
*This
= (JoystickImpl
*)iface
;
909 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
910 _dump_DIPROPHEADER(pdiph
);
912 if (HIWORD(rguid
)) return DI_OK
;
914 switch (LOWORD(rguid
)) {
915 case (DWORD
) DIPROP_RANGE
:
917 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
918 int obj
= find_property(&This
->base
.data_format
, pdiph
);
920 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
922 pr
->lMin
= This
->props
[obj
].wantmin
;
923 pr
->lMax
= This
->props
[obj
].wantmax
;
924 TRACE("range(%d, %d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
927 case (DWORD
) DIPROP_DEADZONE
:
929 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
930 int obj
= find_property(&This
->base
.data_format
, pdiph
);
932 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
934 pd
->dwData
= This
->props
[obj
].deadzone
;
935 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
940 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
946 /******************************************************************************
947 * GetObjectInfo : get information about a device object such as a button
950 static HRESULT WINAPI
JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
951 LPDIDEVICEOBJECTINSTANCEW pdidoi
, DWORD dwObj
, DWORD dwHow
)
953 static const WCHAR axisW
[] = {'A','x','i','s',' ','%','d',0};
954 static const WCHAR povW
[] = {'P','O','V',' ','%','d',0};
955 static const WCHAR buttonW
[] = {'B','u','t','t','o','n',' ','%','d',0};
958 res
= IDirectInputDevice2WImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
959 if (res
!= DI_OK
) return res
;
961 if (pdidoi
->dwType
& DIDFT_AXIS
)
962 sprintfW(pdidoi
->tszName
, axisW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
963 else if (pdidoi
->dwType
& DIDFT_POV
)
964 sprintfW(pdidoi
->tszName
, povW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
965 else if (pdidoi
->dwType
& DIDFT_BUTTON
)
966 sprintfW(pdidoi
->tszName
, buttonW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
968 _dump_OBJECTINSTANCEW(pdidoi
);
972 static HRESULT WINAPI
JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface
,
973 LPDIDEVICEOBJECTINSTANCEA pdidoi
, DWORD dwObj
, DWORD dwHow
)
976 DIDEVICEOBJECTINSTANCEW didoiW
;
977 DWORD dwSize
= pdidoi
->dwSize
;
979 didoiW
.dwSize
= sizeof(didoiW
);
980 res
= JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W
)iface
, &didoiW
, dwObj
, dwHow
);
981 if (res
!= DI_OK
) return res
;
983 memset(pdidoi
, 0, pdidoi
->dwSize
);
984 memcpy(pdidoi
, &didoiW
, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW
, tszName
));
985 pdidoi
->dwSize
= dwSize
;
986 WideCharToMultiByte(CP_ACP
, 0, didoiW
.tszName
, -1, pdidoi
->tszName
,
987 sizeof(pdidoi
->tszName
), NULL
, NULL
);
992 /******************************************************************************
993 * CreateEffect - Create a new FF effect with the specified params
995 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
998 LPDIRECTINPUTEFFECT
*ppdef
,
1001 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1002 EffectListItem
* new = NULL
;
1003 HRESULT retval
= DI_OK
;
1006 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1007 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1009 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1010 TRACE("not available (compiled w/o ff support)\n");
1015 new = HeapAlloc(GetProcessHeap(), 0, sizeof(EffectListItem
));
1016 new->next
= This
->top_effect
;
1017 This
->top_effect
= new;
1019 retval
= linuxinput_create_effect(&(This
->joyfd
), rguid
, &(new->ref
));
1020 if (retval
!= DI_OK
)
1024 retval
= IDirectInputEffect_SetParameters(new->ref
, lpeff
, 0);
1025 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1030 if (pUnkOuter
!= NULL
)
1031 FIXME("Interface aggregation not implemented.\n");
1035 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1038 /*******************************************************************************
1039 * EnumEffects - Enumerate available FF effects
1041 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1042 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1046 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1047 DIEFFECTINFOA dei
; /* feif */
1048 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1049 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1051 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1053 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1055 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1056 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1057 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1058 (*lpCallback
)(&dei
, pvRef
);
1061 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1062 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1063 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1064 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1065 (*lpCallback
)(&dei
, pvRef
);
1067 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1068 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1069 (*lpCallback
)(&dei
, pvRef
);
1071 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1072 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1073 (*lpCallback
)(&dei
, pvRef
);
1075 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1076 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1077 (*lpCallback
)(&dei
, pvRef
);
1079 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1080 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1081 (*lpCallback
)(&dei
, pvRef
);
1085 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1086 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1087 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1088 (*lpCallback
)(&dei
, pvRef
);
1091 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1092 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1093 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1094 (*lpCallback
)(&dei
, pvRef
);
1096 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1097 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1098 (*lpCallback
)(&dei
, pvRef
);
1100 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1101 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1102 (*lpCallback
)(&dei
, pvRef
);
1104 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1105 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1106 (*lpCallback
)(&dei
, pvRef
);
1115 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1116 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1120 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1121 /* seems silly to duplicate all this code but all the structures and functions
1122 * are actually different (A/W) */
1123 DIEFFECTINFOW dei
; /* feif */
1124 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1125 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1126 int xfd
= This
->joyfd
;
1128 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1130 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1132 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1133 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1134 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1135 (*lpCallback
)(&dei
, pvRef
);
1138 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1139 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1140 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1141 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1142 (*lpCallback
)(&dei
, pvRef
);
1144 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1145 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1146 (*lpCallback
)(&dei
, pvRef
);
1148 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1149 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1150 (*lpCallback
)(&dei
, pvRef
);
1152 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1153 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1154 (*lpCallback
)(&dei
, pvRef
);
1156 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1157 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1158 (*lpCallback
)(&dei
, pvRef
);
1162 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1163 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1164 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1165 (*lpCallback
)(&dei
, pvRef
);
1168 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1169 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1170 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1171 (*lpCallback
)(&dei
, pvRef
);
1173 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1174 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1175 (*lpCallback
)(&dei
, pvRef
);
1177 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1178 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1179 (*lpCallback
)(&dei
, pvRef
);
1181 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1182 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1183 (*lpCallback
)(&dei
, pvRef
);
1187 /* return to unacquired state if that's where it was */
1189 IDirectInputDevice8_Unacquire(iface
);
1195 /*******************************************************************************
1196 * GetEffectInfo - Get information about a particular effect
1198 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1199 LPDIEFFECTINFOA pdei
,
1202 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1204 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1206 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1207 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1213 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1214 LPDIEFFECTINFOW pdei
,
1217 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1219 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1221 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1222 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1228 /*******************************************************************************
1229 * GetForceFeedbackState - Get information about the device's FF state
1231 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1232 LPDIRECTINPUTDEVICE8A iface
,
1235 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1237 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1241 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1242 /* DIGFFS_STOPPED is the only mandatory flag to report */
1243 if (This
->ff_state
== FF_STATUS_STOPPED
)
1244 (*pdwOut
) |= DIGFFS_STOPPED
;
1250 /*******************************************************************************
1251 * SendForceFeedbackCommand - Send a command to the device's FF system
1253 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1254 LPDIRECTINPUTDEVICE8A iface
,
1257 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1258 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1260 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1261 if (dwFlags
== DISFFC_STOPALL
) {
1262 /* Stop all effects */
1263 EffectListItem
* itr
= This
->top_effect
;
1265 IDirectInputEffect_Stop(itr
->ref
);
1268 } else if (dwFlags
== DISFFC_RESET
) {
1269 /* Stop, unload, release and free all effects */
1270 /* This returns the device to its "bare" state */
1271 while (This
->top_effect
) {
1272 EffectListItem
* temp
= This
->top_effect
;
1273 IDirectInputEffect_Stop(temp
->ref
);
1274 IDirectInputEffect_Unload(temp
->ref
);
1275 IDirectInputEffect_Release(temp
->ref
);
1276 This
->top_effect
= temp
->next
;
1277 HeapFree(GetProcessHeap(), 0, temp
);
1279 } else if (dwFlags
== DISFFC_PAUSE
|| dwFlags
== DISFFC_CONTINUE
) {
1280 FIXME("No support for Pause or Continue in linux\n");
1281 } else if (dwFlags
== DISFFC_SETACTUATORSOFF
1282 || dwFlags
== DISFFC_SETACTUATORSON
) {
1283 FIXME("No direct actuator control in linux\n");
1285 FIXME("Unknown Force Feedback Command!\n");
1286 return DIERR_INVALIDPARAM
;
1290 return DIERR_UNSUPPORTED
;
1294 /*******************************************************************************
1295 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1296 * created for this device.
1298 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1299 LPDIRECTINPUTDEVICE8A iface
,
1300 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1304 /* this function is safe to call on non-ff-enabled builds */
1306 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1307 EffectListItem
* itr
= This
->top_effect
;
1308 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1311 return DIERR_INVALIDPARAM
;
1314 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1317 (*lpCallback
)(itr
->ref
, pvRef
);
1324 static const IDirectInputDevice8AVtbl JoystickAvt
=
1326 IDirectInputDevice2AImpl_QueryInterface
,
1327 IDirectInputDevice2AImpl_AddRef
,
1328 JoystickAImpl_Release
,
1329 JoystickAImpl_GetCapabilities
,
1330 IDirectInputDevice2AImpl_EnumObjects
,
1331 JoystickAImpl_GetProperty
,
1332 JoystickAImpl_SetProperty
,
1333 JoystickAImpl_Acquire
,
1334 JoystickAImpl_Unacquire
,
1335 JoystickAImpl_GetDeviceState
,
1336 IDirectInputDevice2AImpl_GetDeviceData
,
1337 IDirectInputDevice2AImpl_SetDataFormat
,
1338 IDirectInputDevice2AImpl_SetEventNotification
,
1339 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1340 JoystickAImpl_GetObjectInfo
,
1341 IDirectInputDevice2AImpl_GetDeviceInfo
,
1342 IDirectInputDevice2AImpl_RunControlPanel
,
1343 IDirectInputDevice2AImpl_Initialize
,
1344 JoystickAImpl_CreateEffect
,
1345 JoystickAImpl_EnumEffects
,
1346 JoystickAImpl_GetEffectInfo
,
1347 JoystickAImpl_GetForceFeedbackState
,
1348 JoystickAImpl_SendForceFeedbackCommand
,
1349 JoystickAImpl_EnumCreatedEffectObjects
,
1350 IDirectInputDevice2AImpl_Escape
,
1352 IDirectInputDevice2AImpl_SendDeviceData
,
1353 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1354 IDirectInputDevice7AImpl_WriteEffectToFile
,
1355 IDirectInputDevice8AImpl_BuildActionMap
,
1356 IDirectInputDevice8AImpl_SetActionMap
,
1357 IDirectInputDevice8AImpl_GetImageInfo
1360 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1361 # define XCAST(fun) (typeof(JoystickWvt.fun))
1363 # define XCAST(fun) (void*)
1366 static const IDirectInputDevice8WVtbl JoystickWvt
=
1368 IDirectInputDevice2WImpl_QueryInterface
,
1369 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1370 XCAST(Release
)JoystickAImpl_Release
,
1371 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1372 IDirectInputDevice2WImpl_EnumObjects
,
1373 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1374 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1375 XCAST(Acquire
)JoystickAImpl_Acquire
,
1376 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1377 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1378 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1379 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
1380 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1381 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1382 JoystickWImpl_GetObjectInfo
,
1383 IDirectInputDevice2WImpl_GetDeviceInfo
,
1384 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1385 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1386 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1387 JoystickWImpl_EnumEffects
,
1388 JoystickWImpl_GetEffectInfo
,
1389 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1390 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1391 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1392 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1393 XCAST(Poll
)JoystickAImpl_Poll
,
1394 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1395 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1396 IDirectInputDevice7WImpl_WriteEffectToFile
,
1397 IDirectInputDevice8WImpl_BuildActionMap
,
1398 IDirectInputDevice8WImpl_SetActionMap
,
1399 IDirectInputDevice8WImpl_GetImageInfo
1403 #else /* HAVE_CORRECT_LINUXINPUT_H */
1405 const struct dinput_device joystick_linuxinput_device
= {
1406 "Wine Linux-input joystick driver",
1413 #endif /* HAVE_CORRECT_LINUXINPUT_H */