Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 093876689778e06f853f977eac67c8e366464f4d Mon Sep 17 00:00:00 2001
- From: Christoph Frick <frick@sc-networks.com>
- Date: Sat, 26 Apr 2008 02:50:01 +0200
- Subject: Initial support for BSD's usbhid joysticks
- Please consider this a tracer bullet. I had only time to test it with a
- 4-axis/4-button wheel in LFS in FreeBSD 7.0. I will take further tests using a
- flight stick and other games soon. But for now i just want to see, what others
- have to say about it.
- ---
- configure | 49 ++++
- configure.ac | 7 +
- dlls/dinput/Makefile.in | 3 +-
- dlls/dinput/dinput_main.c | 1 +
- dlls/dinput/dinput_private.h | 1 +
- dlls/dinput/joystick_bsduhid.c | 562 +++++++++++++++++++++++++++++++++++++++++
- include/config.h.in | 3 +
- 7 files changed, 625 insertions(+), 1 deletion(-)
- create mode 100644 dlls/dinput/joystick_bsduhid.c
- diff --git a/configure b/configure
- index d3247bd..0a0171e 100755
- --- a/configure
- +++ b/configure
- @@ -627,6 +627,7 @@ LIBOBJS
- PORCFLAGS
- LINGUAS
- ALL_TEST_RESOURCES
- +LIBUSBHID
- LDAPLIBS
- LIBPOLL
- LIBDL
- @@ -5943,6 +5944,7 @@ for ac_header in \
- termios.h \
- tiffio.h \
- unistd.h \
- + usbhid.h \
- utime.h \
- valgrind/memcheck.h \
- valgrind/valgrind.h \
- @@ -13852,6 +13854,53 @@ $as_echo "#define HAVE_LINUX_22_JOYSTICK_API 1" >>confdefs.h
- fi
- fi
- +LIBUSBHID=""
- +
- +if test "$ac_cv_header_usbhid_h" = "yes"
- +then
- + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for hid_get_report_desc in -lusbhid" >&5
- +$as_echo_n "checking for hid_get_report_desc in -lusbhid... " >&6; }
- +if ${ac_cv_lib_usbhid_hid_get_report_desc+:} false; then :
- + $as_echo_n "(cached) " >&6
- +else
- + ac_check_lib_save_LIBS=$LIBS
- +LIBS="-lusbhid $LIBS"
- +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
- +/* end confdefs.h. */
- +
- +/* Override any GCC internal prototype to avoid an error.
- + Use char because int might match the return type of a GCC
- + builtin and then its argument prototype would still apply. */
- +#ifdef __cplusplus
- +extern "C"
- +#endif
- +char hid_get_report_desc ();
- +int
- +main ()
- +{
- +return hid_get_report_desc ();
- + ;
- + return 0;
- +}
- +_ACEOF
- +if ac_fn_c_try_link "$LINENO"; then :
- + ac_cv_lib_usbhid_hid_get_report_desc=yes
- +else
- + ac_cv_lib_usbhid_hid_get_report_desc=no
- +fi
- +rm -f core conftest.err conftest.$ac_objext \
- + conftest$ac_exeext conftest.$ac_ext
- +LIBS=$ac_check_lib_save_LIBS
- +fi
- +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_usbhid_hid_get_report_desc" >&5
- +$as_echo "$ac_cv_lib_usbhid_hid_get_report_desc" >&6; }
- +if test "x$ac_cv_lib_usbhid_hid_get_report_desc" = xyes; then :
- + LIBUSBHID="-lusbhid"
- +
- +fi
- +
- +fi
- +
- ac_fn_c_check_member "$LINENO" "struct statfs" "f_bfree" "ac_cv_member_struct_statfs_f_bfree" "#include <sys/types.h>
- #ifdef HAVE_SYS_PARAM_H
- diff --git a/configure.ac b/configure.ac
- index 2a0a1b6..7eb3409 100644
- --- a/configure.ac
- +++ b/configure.ac
- @@ -530,6 +530,7 @@ AC_CHECK_HEADERS(\
- termios.h \
- tiffio.h \
- unistd.h \
- + usbhid.h \
- utime.h \
- valgrind/memcheck.h \
- valgrind/valgrind.h \
- @@ -2223,6 +2224,12 @@ then
- fi
- fi
- +AC_SUBST(LIBUSBHID,"")
- +if test "$ac_cv_header_usbhid_h" = "yes"
- +then
- + AC_CHECK_LIB(usbhid,hid_get_report_desc,[AC_SUBST(LIBUSBHID,"-lusbhid")])
- +fi
- +
- dnl **** FIXME: what about mixed cases, where we need two of them? ***
- dnl Check for statfs members
- diff --git a/dlls/dinput/Makefile.in b/dlls/dinput/Makefile.in
- index 1be48c4..9adf4af 100644
- --- a/dlls/dinput/Makefile.in
- +++ b/dlls/dinput/Makefile.in
- @@ -1,7 +1,7 @@
- MODULE = dinput.dll
- IMPORTLIB = dinput
- IMPORTS = dxguid uuid comctl32 ole32 user32 advapi32
- -EXTRALIBS = @IOKITLIB@
- +EXTRALIBS = @IOKITLIB@ @LIBUSBHID@
- C_SRCS = \
- config.c \
- @@ -12,6 +12,7 @@ C_SRCS = \
- joystick.c \
- joystick_linux.c \
- joystick_linuxinput.c \
- + joystick_bsduhid.c \
- joystick_osx.c \
- keyboard.c \
- mouse.c
- diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
- index c07b333..6658c46 100644
- --- a/dlls/dinput/dinput_main.c
- +++ b/dlls/dinput/dinput_main.c
- @@ -94,6 +94,7 @@ static const struct dinput_device *dinput_devices[] =
- &keyboard_device,
- &joystick_linuxinput_device,
- &joystick_linux_device,
- + &joystick_bsduhid_device,
- &joystick_osx_device
- };
- #define NB_DINPUT_DEVICES (sizeof(dinput_devices)/sizeof(dinput_devices[0]))
- diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h
- index e593b40..0fd49b3 100644
- --- a/dlls/dinput/dinput_private.h
- +++ b/dlls/dinput/dinput_private.h
- @@ -60,6 +60,7 @@ extern const struct dinput_device mouse_device DECLSPEC_HIDDEN;
- extern const struct dinput_device keyboard_device DECLSPEC_HIDDEN;
- extern const struct dinput_device joystick_linux_device DECLSPEC_HIDDEN;
- extern const struct dinput_device joystick_linuxinput_device DECLSPEC_HIDDEN;
- +extern const struct dinput_device joystick_bsduhid_device DECLSPEC_HIDDEN;
- extern const struct dinput_device joystick_osx_device DECLSPEC_HIDDEN;
- extern void check_dinput_hooks(LPDIRECTINPUTDEVICE8W) DECLSPEC_HIDDEN;
- diff --git a/dlls/dinput/joystick_bsduhid.c b/dlls/dinput/joystick_bsduhid.c
- new file mode 100644
- index 0000000..db6ec7e
- --- /dev/null
- +++ b/dlls/dinput/joystick_bsduhid.c
- @@ -0,0 +1,562 @@
- +/*
- + * DirectInput Joystick device For BSD's uhid(4) interface
- + *
- + * This library is free software; you can redistribute it and/or modify it under
- + * the terms of the GNU Lesser General Public License as published by the
- + * Free Software Foundation; either version 2.1 of the License, or (at your
- + * option) any later version.
- + *
- + * This library is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- + * License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public License
- + * along with this library; if not, write to the Free Software Foundation,
- + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- + */
- +
- +#include "config.h"
- +#include "wine/port.h"
- +#include <errno.h>
- +#include <stdio.h>
- +#include <time.h>
- +#ifdef HAVE_SYS_TIME_H
- +# include <sys/time.h>
- +#endif
- +#ifdef HAVE_SYS_ERRNO_H
- +#include <sys/errno.h>
- +#endif
- +#ifdef HAVE_SYS_IOCTL_H
- +# include <sys/ioctl.h>
- +#endif
- +#ifdef HAVE_SYS_POLL_H
- +# include <sys/poll.h>
- +#endif
- +
- +#include "wine/debug.h"
- +#include "wine/unicode.h"
- +#include "windef.h"
- +#include "winbase.h"
- +#include "winerror.h"
- +#include "winreg.h"
- +#include "dinput.h"
- +
- +#include "dinput_private.h"
- +#include "device_private.h"
- +#include "joystick_private.h"
- +
- +WINE_DEFAULT_DEBUG_CHANNEL(dinput);
- +
- +#ifdef HAVE_USBHID_H
- +
- +#include <usbhid.h>
- +#include <dev/usb/usb.h>
- +#include <dev/usb/usbhid.h>
- +#include <dev/usb/usb_ioctl.h>
- +
- +#define FMT_UHIDDEVS "/dev/uhid%d"
- +#define MAX_UHIDDEVS 64
- +
- +/* FIXME: these are offsets in c_dfDIJoystick2 */
- +#define WINE_JOYSTICK_MAX_AXES 8
- +#define WINE_JOYSTICK_MAX_POVS 4
- +#define WINE_JOYSTICK_MAX_BUTTONS 128
- +
- +typedef struct JoystickImpl JoystickImpl;
- +static const IDirectInputDevice8AVtbl JoystickAvt;
- +static const IDirectInputDevice8WVtbl JoystickWvt;
- +
- +struct JoyDev {
- + char *device;
- + char *name;
- + GUID guid;
- +
- + int num_axes;
- + int num_buttons;
- +
- + struct hid_item axes[WINE_JOYSTICK_MAX_AXES];
- + struct hid_item buttons[WINE_JOYSTICK_MAX_BUTTONS];
- +
- + int axis_values[WINE_JOYSTICK_MAX_AXES];
- + int button_values[WINE_JOYSTICK_MAX_BUTTONS];
- +
- + size_t len_data;
- + char *data;
- +};
- +
- +struct JoystickImpl {
- + struct IDirectInputDeviceImpl base;
- + struct JoyDev *joydev;
- + DIJOYSTATE2 js;
- + ObjProps props [WINE_JOYSTICK_MAX_AXES];
- + int joyfd;
- +};
- +
- +static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573edb-7734-11d2-8d4
- + * a-23903fb6bdf7 */
- + 0x9e573edb,
- + 0x7734,
- + 0x11d2,
- + {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
- +};
- +
- +static int have_joy_devs = -1;
- +static struct JoyDev *joy_devs = NULL;
- +
- +static void
- +find_joy_devs(void)
- +{
- + int i;
- +
- + if (have_joy_devs >= 0) {
- + return;
- + }
- + have_joy_devs = 0;
- +
- + for (i = 0; i < MAX_UHIDDEVS; i++) {
- + int usb_report_id, is_joystick = 0;
- + char buf [MAX_PATH];
- + int fd;
- + struct JoyDev joydev = {0};
- + report_desc_t rdesc;
- +
- + snprintf(buf, MAX_PATH, FMT_UHIDDEVS, i);
- + buf[MAX_PATH - 1] = 0;
- +
- + if ((fd = open(buf, O_RDWR | O_NDELAY, 0)) == -1) {
- + TRACE("Unable to open %s read/write: %s\n", buf, strerror(errno));
- + continue;
- + }
- + if ((rdesc = hid_get_report_desc(fd)) == 0) {
- + TRACE("%s: unable to get report descriptor: %s\n", buf, strerror(errno));
- + close(fd);
- + continue;
- + }
- + if (ioctl(fd, USB_GET_REPORT_ID, &usb_report_id) < 0) {
- + TRACE("%s: unable to get USB report id: %s\n", buf, strerror(errno));
- + hid_dispose_report_desc(rdesc);
- + close(fd);
- + continue;
- + }
- + joydev.len_data = hid_report_size(rdesc, hid_input, usb_report_id);
- + joydev.data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(char) * joydev.len_data);
- +
- + {
- + struct hid_data *hdata;
- + struct hid_item hitem;
- + hdata = hid_start_parse(rdesc, 1 << hid_input, usb_report_id);
- + do {
- + int page = HID_PAGE(hitem.usage);
- + int usage = HID_USAGE(hitem.usage);
- +
- + is_joystick |= hitem.kind == hid_collection && page == HUP_GENERIC_DESKTOP && (usage == HUG_JOYSTICK || usage == HUG_GAME_PAD);
- + if (hitem.kind != hid_input) {
- + continue;
- + }
- + if (!is_joystick) {
- + continue;
- + }
- + if (page == HUP_GENERIC_DESKTOP) {
- + if (usage != HUG_HAT_SWITCH) {
- + if (joydev.num_axes < WINE_JOYSTICK_MAX_AXES) {
- + joydev.axes[joydev.num_axes++] = hitem;
- + }
- + }
- + } else if (page == HUP_BUTTON) {
- + if (joydev.num_buttons < WINE_JOYSTICK_MAX_BUTTONS) {
- + joydev.buttons[joydev.num_buttons++] = hitem;
- + }
- + }
- + } while (hid_get_item(hdata, &hitem));
- + hid_end_parse(hdata);
- + }
- +
- + if (!is_joystick) {
- + TRACE("%s: looks not like a joystick\n", buf);
- + HeapFree(GetProcessHeap(), 0, joydev.data);
- + hid_dispose_report_desc(rdesc);
- + close(fd);
- + continue;
- + }
- + joydev.device = strdup(buf);
- + joydev.name = strdup(buf); /* TODO */
- + joydev.guid = DInput_Wine_Joystick_Base_GUID;
- + joydev.guid.Data3 += have_joy_devs;
- +
- + TRACE("Found a joystick on %s: %s (%s)\n", joydev.device, joydev.name, debugstr_guid(&joydev.guid));
- +
- + if (have_joy_devs == 0) {
- + joy_devs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct JoyDev));
- + } else {
- + HeapReAlloc(GetProcessHeap(), 0, joy_devs, (1 + have_joy_devs) * sizeof(struct JoyDev));
- + }
- + joy_devs[have_joy_devs++] = joydev;
- +
- + hid_dispose_report_desc(rdesc);
- + close(fd);
- + }
- +}
- +
- +#define CENTER_AXIS(a) (a < ji->joydev->num_axes ? joystick_map_axis( &ji->props[a], ji->joydev->axis_values[a]) : 0)
- +static void fake_current_js_state(JoystickImpl *ji)
- +{
- + ji->js.lX = CENTER_AXIS(0);
- + ji->js.lY = CENTER_AXIS(1);
- + ji->js.lZ = CENTER_AXIS(2);
- + ji->js.lRx = CENTER_AXIS(3);
- + ji->js.lRy = CENTER_AXIS(4);
- + ji->js.lRz = CENTER_AXIS(5);
- + ji->js.rglSlider[0] = CENTER_AXIS(6);
- + ji->js.rglSlider[1] = CENTER_AXIS(7);
- +}
- +#undef CENTER_AXIS
- +
- +/* FIXME: duplication */
- +static void
- +fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
- +{
- + DWORD dwSize = lpddi->dwSize;
- +
- + TRACE("%d %p\n", dwSize, lpddi);
- + memset(lpddi, 0, dwSize);
- +
- + lpddi->dwSize = dwSize;
- + lpddi->guidInstance = joy_devs[id].guid;
- + lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
- + lpddi->guidFFDriver = GUID_NULL;
- +
- + if (version >= 0x0800)
- + lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
- + else
- + lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
- +
- + strcpy(lpddi->tszInstanceName, joy_devs[id].name);
- + strcpy(lpddi->tszProductName, joy_devs[id].device);
- +}
- +
- +/* FIXME: duplication */
- +static void
- +fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
- +{
- + DWORD dwSize = lpddi->dwSize;
- +
- + TRACE("%d %p\n", dwSize, lpddi);
- + memset(lpddi, 0, dwSize);
- +
- + lpddi->dwSize = dwSize;
- + lpddi->guidInstance = joy_devs[id].guid;
- + lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
- + lpddi->guidFFDriver = GUID_NULL;
- +
- + if (version >= 0x0800)
- + lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
- + else
- + lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
- +
- + MultiByteToWideChar(CP_ACP, 0, joy_devs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
- + MultiByteToWideChar(CP_ACP, 0, joy_devs[id].device, -1, lpddi->tszProductName, MAX_PATH);
- +}
- +
- +/* FIXME: duplication */
- +static BOOL
- +joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
- +{
- + find_joy_devs();
- +
- + if (id >= have_joy_devs) {
- + return FALSE;
- + }
- + if (!((dwDevType == 0) ||
- + ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
- + (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
- + return FALSE;
- +
- + fill_joystick_dideviceinstanceA(lpddi, version, id);
- + return TRUE;
- +}
- +
- +/* FIXME: duplication */
- +static BOOL
- +joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
- +{
- + find_joy_devs();
- +
- + if (id >= have_joy_devs) {
- + return FALSE;
- + }
- + if (!((dwDevType == 0) ||
- + ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
- + (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
- + return FALSE;
- +
- + fill_joystick_dideviceinstanceW(lpddi, version, id);
- + return TRUE;
- +}
- +
- +/* FIXME: duplication */
- +static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, unsigned short index)
- +{
- + JoystickImpl* newDevice;
- + LPDIDATAFORMAT df = NULL;
- + int i, idx=0;
- + char buffer[MAX_PATH+16];
- + HKEY hkey, appkey;
- + LONG def_deadzone = 0;
- +
- + newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
- + if (!newDevice) return NULL;
- +
- + newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
- + newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
- + newDevice->base.ref = 1;
- + newDevice->base.guid = *rguid;
- + newDevice->base.dinput = dinput;
- + newDevice->joyfd = -1;
- + newDevice->joydev = &joy_devs[index];
- + InitializeCriticalSection(&newDevice->base.crit);
- + newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
- +
- + /* get options */
- + get_app_key(&hkey, &appkey);
- +
- + if (!get_config_key(hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH))
- + {
- + def_deadzone = atoi(buffer);
- + TRACE("setting default deadzone to: %d\n", def_deadzone);
- + }
- + if (appkey) RegCloseKey(appkey);
- + if (hkey) RegCloseKey(hkey);
- +
- + /* Create copy of default data format */
- + if (!(df = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, c_dfDIJoystick2.dwSize))) goto failed;
- + memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
- + if (!(df->rgodf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, df->dwNumObjs * df->dwObjSize))) goto failed;
- +
- + /* Supported Axis & POVs should map 1-to-1 */
- + for (i = 0; i < newDevice->joydev->num_axes; i++) {
- + memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i], df->dwObjSize);
- + newDevice->props[idx].lDevMin = newDevice->joydev->axes[i].logical_minimum;
- + newDevice->props[idx].lDevMax = newDevice->joydev->axes[i].logical_maximum;
- + newDevice->props[idx].lMin = 0;
- + newDevice->props[idx].lMax = 0xffff;
- + newDevice->props[idx].lSaturation = 0;
- + newDevice->props[idx].lDeadZone = def_deadzone;
- + df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_ABSAXIS;
- + idx ++;
- + }
- +
- + for (i = 0; i < newDevice->joydev->num_buttons; i++) {
- + memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS + i], df->dwObjSize);
- + df->rgodf[idx ].pguid = &GUID_Button;
- + df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
- + idx ++;
- + }
- + df->dwNumObjs = idx;
- +
- + fake_current_js_state(newDevice);
- +
- + newDevice->base.data_format.wine_df = df;
- + IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->base.dinput);
- + return newDevice;
- +
- +failed:
- + if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
- + HeapFree(GetProcessHeap(), 0, df);
- + HeapFree(GetProcessHeap(), 0, newDevice);
- + return NULL;
- +}
- +
- +/* FIXME: duplication */
- +/******************************************************************************
- + * get_joystick_index : Get the joystick index from a given GUID
- + */
- +static unsigned short get_joystick_index(REFGUID guid)
- +{
- + GUID wine_joystick = DInput_Wine_Joystick_Base_GUID;
- + GUID dev_guid = *guid;
- +
- + wine_joystick.Data3 = 0;
- + dev_guid.Data3 = 0;
- +
- + /* for the standard joystick GUID use index 0 */
- + if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
- +
- + /* for the wine joystick GUIDs use the index stored in Data3 */
- + if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3 - DInput_Wine_Joystick_Base_GUID.Data3;
- +
- + return MAX_UHIDDEVS;
- +}
- +
- +/* FIXME: duplication */
- +static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
- +{
- + unsigned short index;
- +
- + TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
- + find_joy_devs();
- +
- + if ((index = get_joystick_index(rguid)) < MAX_UHIDDEVS && have_joy_devs && index < have_joy_devs)
- + {
- + if (riid == NULL)
- + ;/* nothing */
- + else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
- + IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
- + IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
- + IsEqualGUID(&IID_IDirectInputDevice8A, riid))
- + {
- + unicode = 0;
- + }
- + else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
- + IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
- + IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
- + IsEqualGUID(&IID_IDirectInputDevice8W, riid))
- + {
- + unicode = 1;
- + }
- + else
- + {
- + WARN("no interface\n");
- + return DIERR_NOINTERFACE;
- + }
- +
- + *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index);
- + return DIERR_NOINTERFACE;
- + }
- +
- + return DIERR_DEVICENOTREG;
- +}
- +
- +const struct dinput_device joystick_bsduhid_device = {
- + "Wine BSD uhid joystick driver",
- + joydev_enum_deviceA,
- + joydev_enum_deviceW,
- + joydev_create_device
- +};
- +
- +/******************************************************************************
- + * Acquire : gets exclusive control of the joystick
- + */
- +static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
- +{
- + JoystickImpl *This = (JoystickImpl *)iface;
- + HRESULT res;
- +
- + TRACE("(this=%p)\n",This);
- +
- + res = IDirectInputDevice2AImpl_Acquire(iface);
- + if (res==DI_OK) {
- + if ((This->joyfd=open(This->joydev->device,O_RDWR|O_NDELAY,0))==-1) {
- + /* Couldn't open in r/w but opened in read-only. */
- + WARN("Could not open %s in read-write mode: %s\n", This->joydev->device, strerror(errno));
- + }
- + }
- + return res;
- +}
- +
- +/******************************************************************************
- + * Unacquire : frees the joystick
- + */
- +static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
- +{
- + JoystickImpl *This = (JoystickImpl *)iface;
- + HRESULT res;
- +
- + TRACE("(this=%p)\n",This);
- + res = IDirectInputDevice2AImpl_Unacquire(iface);
- + if (res==DI_OK && This->joyfd!=-1) {
- + close(This->joyfd);
- + This->joyfd = -1;
- + }
- + return res;
- +}
- +
- +static const IDirectInputDevice8AVtbl JoystickAvt =
- +{
- + IDirectInputDevice2AImpl_QueryInterface,
- + IDirectInputDevice2AImpl_AddRef,
- + IDirectInputDevice2AImpl_Release,
- + JoystickAGenericImpl_GetCapabilities,
- + IDirectInputDevice2AImpl_EnumObjects,
- + JoystickAGenericImpl_GetProperty,
- + JoystickAGenericImpl_SetProperty,
- + JoystickAImpl_Acquire,
- + JoystickAImpl_Unacquire,
- + JoystickAGenericImpl_GetDeviceState,
- + IDirectInputDevice2AImpl_GetDeviceData,
- + IDirectInputDevice2AImpl_SetDataFormat,
- + IDirectInputDevice2AImpl_SetEventNotification,
- + IDirectInputDevice2AImpl_SetCooperativeLevel,
- + JoystickAGenericImpl_GetObjectInfo,
- + JoystickAGenericImpl_GetDeviceInfo,
- + IDirectInputDevice2AImpl_RunControlPanel,
- + IDirectInputDevice2AImpl_Initialize,
- + IDirectInputDevice2AImpl_CreateEffect,
- + IDirectInputDevice2AImpl_EnumEffects,
- + IDirectInputDevice2AImpl_GetEffectInfo,
- + IDirectInputDevice2AImpl_GetForceFeedbackState,
- + IDirectInputDevice2AImpl_SendForceFeedbackCommand,
- + IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
- + IDirectInputDevice2AImpl_Escape,
- + JoystickAGenericImpl_Poll,
- + IDirectInputDevice2AImpl_SendDeviceData,
- + IDirectInputDevice7AImpl_EnumEffectsInFile,
- + IDirectInputDevice7AImpl_WriteEffectToFile,
- + JoystickAGenericImpl_BuildActionMap,
- + JoystickAGenericImpl_SetActionMap,
- + IDirectInputDevice8AImpl_GetImageInfo
- +};
- +
- +#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
- +# define XCAST(fun) (typeof(JoystickWvt.fun))
- +#else
- +# define XCAST(fun) (void*)
- +#endif
- +
- +static const IDirectInputDevice8WVtbl JoystickWvt =
- +{
- + IDirectInputDevice2WImpl_QueryInterface,
- + XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
- + XCAST(Release)IDirectInputDevice2AImpl_Release,
- + JoystickWGenericImpl_GetCapabilities,
- + IDirectInputDevice2WImpl_EnumObjects,
- + JoystickWGenericImpl_GetProperty,
- + JoystickWGenericImpl_SetProperty,
- + XCAST(Acquire)JoystickAImpl_Acquire,
- + XCAST(Unacquire)JoystickAImpl_Unacquire,
- + JoystickWGenericImpl_GetDeviceState,
- + XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
- + XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
- + XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
- + XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
- + JoystickWGenericImpl_GetObjectInfo,
- + JoystickWGenericImpl_GetDeviceInfo,
- + XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
- + XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
- + XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
- + XCAST(EnumEffects)IDirectInputDevice2AImpl_EnumEffects,
- + XCAST(GetEffectInfo)IDirectInputDevice2AImpl_GetEffectInfo,
- + XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
- + XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
- + XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
- + XCAST(Escape)IDirectInputDevice2AImpl_Escape,
- + JoystickWGenericImpl_Poll,
- + XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
- + IDirectInputDevice7WImpl_EnumEffectsInFile,
- + IDirectInputDevice7WImpl_WriteEffectToFile,
- + JoystickWGenericImpl_BuildActionMap,
- + JoystickWGenericImpl_SetActionMap,
- + IDirectInputDevice8WImpl_GetImageInfo
- +};
- +#undef XCAST
- +
- +#else /* HAVE_USBHID_H */
- +
- +const struct dinput_device joystick_bsduhid_device = {
- + "Wine BSD uhid joystick driver",
- + NULL,
- + NULL,
- + NULL
- +};
- +
- +#endif /* HAVE_USBHID_H */
- diff --git a/include/config.h.in b/include/config.h.in
- index 9dc3e14..864748f 100644
- --- a/include/config.h.in
- +++ b/include/config.h.in
- @@ -1082,6 +1082,9 @@
- /* Define to 1 if you have the <unistd.h> header file. */
- #undef HAVE_UNISTD_H
- +/* Define to 1 if you have the <usbhid.h> header file. */
- +#undef HAVE_USBHID_H
- +
- /* Define to 1 if you have the `usleep' function. */
- #undef HAVE_USLEEP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement