2000-11-05 21:25:02 +01:00
|
|
|
/* DirectInput Joystick device
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998,1999 Lionel Ulmer
|
2002-06-14 02:39:44 +02:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2000-11-05 21:25:02 +01:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-11-05 21:25:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2002-07-22 23:53:32 +02:00
|
|
|
#include "wine/port.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
2000-11-05 21:25:02 +01:00
|
|
|
#include <sys/fcntl.h>
|
2002-05-22 03:55:18 +02:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
2000-11-05 21:25:02 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_SYS_ERRNO_H
|
|
|
|
# include <sys/errno.h>
|
|
|
|
#endif
|
2000-11-25 04:09:30 +01:00
|
|
|
#ifdef HAVE_LINUX_JOYSTICK_H
|
|
|
|
# include <linux/joystick.h>
|
|
|
|
#endif
|
2000-11-05 21:25:02 +01:00
|
|
|
#define JOYDEV "/dev/js0"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-11-05 21:25:02 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "dinput.h"
|
|
|
|
|
|
|
|
#include "dinput_private.h"
|
|
|
|
#include "device_private.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
|
2000-11-05 21:25:02 +01:00
|
|
|
|
|
|
|
/* Wine joystick driver object instances */
|
|
|
|
#define WINE_JOYSTICK_AXIS_BASE 0
|
|
|
|
#define WINE_JOYSTICK_BUTTON_BASE 8
|
|
|
|
|
|
|
|
typedef struct JoystickAImpl JoystickAImpl;
|
2002-06-14 02:39:44 +02:00
|
|
|
static ICOM_VTABLE(IDirectInputDevice8A) JoystickAvt;
|
2000-11-05 21:25:02 +01:00
|
|
|
struct JoystickAImpl
|
|
|
|
{
|
2002-06-14 02:39:44 +02:00
|
|
|
LPVOID lpVtbl;
|
2000-11-05 21:25:02 +01:00
|
|
|
DWORD ref;
|
|
|
|
GUID guid;
|
|
|
|
|
|
|
|
/* The 'parent' DInput */
|
|
|
|
IDirectInputAImpl *dinput;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/* joystick private */
|
|
|
|
int joyfd;
|
|
|
|
LPDIDATAFORMAT df;
|
|
|
|
HANDLE hEvent;
|
|
|
|
LONG lMin,lMax,deadzone;
|
|
|
|
LPDIDEVICEOBJECTDATA data_queue;
|
2001-01-29 00:14:25 +01:00
|
|
|
int queue_head, queue_tail, queue_len;
|
2000-11-05 21:25:02 +01:00
|
|
|
DIJOYSTATE js;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
|
|
|
|
0x9e573ed9,
|
|
|
|
0x7734,
|
|
|
|
0x11d2,
|
|
|
|
{0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
|
|
|
|
};
|
|
|
|
|
2002-06-02 23:18:48 +02:00
|
|
|
static BOOL joydev_enum_device(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
2002-06-14 02:39:44 +02:00
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
if (dwFlags & DIEDFL_FORCEFEEDBACK)
|
|
|
|
return FALSE;
|
|
|
|
|
2000-12-12 01:38:58 +01:00
|
|
|
if ((dwDevType==0) || (GET_DIDEVICE_TYPE(dwDevType)==DIDEVTYPE_JOYSTICK)) {
|
2000-11-05 21:25:02 +01:00
|
|
|
/* check whether we have a joystick */
|
2002-06-14 02:39:44 +02:00
|
|
|
if ((fd = open(JOYDEV,O_RDONLY) != -1) || (errno!=ENODEV && errno!=ENOENT)) {
|
|
|
|
TRACE("Enumerating the linux Joystick device\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/* Return joystick */
|
|
|
|
lpddi->guidInstance = GUID_Joystick;
|
|
|
|
lpddi->guidProduct = DInput_Wine_Joystick_GUID;
|
|
|
|
/* we only support traditional joysticks for now */
|
2000-12-12 01:38:58 +01:00
|
|
|
lpddi->dwDevType = DIDEVTYPE_JOYSTICK |
|
|
|
|
(DIDEVTYPEJOYSTICK_TRADITIONAL<<8);
|
2000-11-05 21:25:02 +01:00
|
|
|
strcpy(lpddi->tszInstanceName, "Joystick");
|
|
|
|
/* ioctl JSIOCGNAME(len) */
|
|
|
|
strcpy(lpddi->tszProductName, "Wine Joystick");
|
|
|
|
|
2002-06-14 02:39:44 +02:00
|
|
|
lpddi->guidFFDriver = GUID_NULL;
|
|
|
|
if (fd != -1)
|
|
|
|
close(fd);
|
2000-11-05 21:25:02 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-06-14 02:39:44 +02:00
|
|
|
static JoystickAImpl *alloc_device(REFGUID rguid, LPVOID jvt, IDirectInputAImpl *dinput)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
|
|
|
JoystickAImpl* newDevice;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickAImpl));
|
2002-06-14 02:39:44 +02:00
|
|
|
newDevice->lpVtbl = jvt;
|
|
|
|
newDevice->ref = 1;
|
|
|
|
newDevice->joyfd = -1;
|
2000-11-05 21:25:02 +01:00
|
|
|
newDevice->lMin = -32768;
|
|
|
|
newDevice->lMax = +32767;
|
|
|
|
newDevice->dinput = dinput;
|
|
|
|
memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
|
|
|
|
|
|
|
|
return newDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT joydev_create_device(IDirectInputAImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
|
|
|
|
{
|
|
|
|
if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
|
|
|
|
(IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
|
2002-06-14 02:39:44 +02:00
|
|
|
if ((riid == NULL) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
|
2000-11-05 21:25:02 +01:00
|
|
|
*pdev=(IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
TRACE("Creating a Joystick device (%p)\n", *pdev);
|
|
|
|
return DI_OK;
|
|
|
|
} else
|
|
|
|
return DIERR_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DIERR_DEVICENOTREG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dinput_device joydev = {
|
2000-12-12 01:38:58 +01:00
|
|
|
10,
|
2000-11-05 21:25:02 +01:00
|
|
|
joydev_enum_device,
|
|
|
|
joydev_create_device
|
|
|
|
};
|
|
|
|
|
|
|
|
DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Joystick
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
|
|
|
|
This->ref--;
|
|
|
|
if (This->ref)
|
|
|
|
return This->ref;
|
|
|
|
|
|
|
|
/* Free the data queue */
|
|
|
|
if (This->data_queue != NULL)
|
|
|
|
HeapFree(GetProcessHeap(),0,This->data_queue);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/* Free the DataFormat */
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->df);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SetDataFormat : the application can choose the format of the data
|
|
|
|
* the device driver sends back with GetDeviceState.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickAImpl_SetDataFormat(
|
2002-06-14 02:39:44 +02:00
|
|
|
LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
|
2000-11-05 21:25:02 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
int i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
TRACE("(this=%p,%p)\n",This,df);
|
|
|
|
|
|
|
|
TRACE("(df.dwSize=%ld)\n",df->dwSize);
|
|
|
|
TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
|
|
|
|
TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
|
|
|
|
TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
|
|
|
|
TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
|
|
|
|
|
|
|
|
for (i=0;i<df->dwNumObjs;i++) {
|
|
|
|
TRACE("df.rgodf[%d].guid %s (%p)\n",i,debugstr_guid(df->rgodf[i].pguid), df->rgodf[i].pguid);
|
|
|
|
TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
|
|
|
|
TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
|
|
|
|
TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/* Store the new data format */
|
|
|
|
This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
|
|
|
|
memcpy(This->df, df, df->dwSize);
|
|
|
|
This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
|
|
|
|
memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Acquire : gets exclusive control of the joystick
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
TRACE("(this=%p)\n",This);
|
|
|
|
if (This->joyfd!=-1)
|
|
|
|
return 0;
|
|
|
|
This->joyfd=open(JOYDEV,O_RDONLY);
|
|
|
|
if (This->joyfd==-1)
|
|
|
|
return DIERR_NOTFOUND;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Unacquire : frees the joystick
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
|
|
|
|
TRACE("(this=%p)\n",This);
|
|
|
|
if (This->joyfd!=-1) {
|
|
|
|
close(This->joyfd);
|
|
|
|
This->joyfd = -1;
|
|
|
|
}
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define map_axis(val) ((val+32768)*(This->lMax-This->lMin)/65536+This->lMin)
|
|
|
|
|
|
|
|
static void joy_polldev(JoystickAImpl *This) {
|
|
|
|
struct timeval tv;
|
|
|
|
fd_set readfds;
|
|
|
|
struct js_event jse;
|
|
|
|
|
|
|
|
if (This->joyfd==-1)
|
|
|
|
return;
|
|
|
|
while (1) {
|
|
|
|
memset(&tv,0,sizeof(tv));
|
|
|
|
FD_ZERO(&readfds);FD_SET(This->joyfd,&readfds);
|
|
|
|
if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
|
|
|
|
return;
|
|
|
|
/* we have one event, so we can read */
|
|
|
|
if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TRACE("js_event: type 0x%x, number %d, value %d\n",jse.type,jse.number,jse.value);
|
|
|
|
if (jse.type & JS_EVENT_BUTTON) {
|
|
|
|
GEN_EVENT(DIJOFS_BUTTON(jse.number),jse.value?0x80:0x00,jse.time,(This->dinput->evsequence)++);
|
|
|
|
This->js.rgbButtons[jse.number] = jse.value?0x80:0x00;
|
|
|
|
}
|
|
|
|
if (jse.type & JS_EVENT_AXIS) {
|
|
|
|
switch (jse.number) {
|
|
|
|
case 0:
|
|
|
|
GEN_EVENT(jse.number*4,jse.value,jse.time,(This->dinput->evsequence)++);
|
|
|
|
This->js.lX = map_axis(jse.value);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
GEN_EVENT(jse.number*4,jse.value,jse.time,(This->dinput->evsequence)++);
|
|
|
|
This->js.lY = map_axis(jse.value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
GEN_EVENT(jse.number*4,jse.value,jse.time,(This->dinput->evsequence)++);
|
|
|
|
This->js.lZ = map_axis(jse.value);
|
|
|
|
break;
|
|
|
|
default:
|
2001-11-19 03:09:49 +01:00
|
|
|
FIXME("more than 3 axes (%d) not handled!\n",jse.number);
|
2000-11-05 21:25:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetDeviceState : returns the "state" of the joystick.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickAImpl_GetDeviceState(
|
2002-06-14 02:39:44 +02:00
|
|
|
LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
|
2000-11-05 21:25:02 +01:00
|
|
|
) {
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
joy_polldev(This);
|
|
|
|
TRACE("(this=%p,0x%08lx,%p)\n",This,len,ptr);
|
|
|
|
if (len != sizeof(DIJOYSTATE)) {
|
|
|
|
FIXME("len %ld is not sizeof(DIJOYSTATE), unsupported format.\n",len);
|
|
|
|
}
|
|
|
|
memcpy(ptr,&(This->js),len);
|
2001-01-29 00:14:25 +01:00
|
|
|
This->queue_head = 0;
|
|
|
|
This->queue_tail = 0;
|
2000-11-05 21:25:02 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetDeviceData : gets buffered input data.
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
|
2000-11-05 21:25:02 +01:00
|
|
|
DWORD dodsize,
|
|
|
|
LPDIDEVICEOBJECTDATA dod,
|
|
|
|
LPDWORD entries,
|
|
|
|
DWORD flags
|
|
|
|
) {
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This,dodsize,*entries,flags);
|
|
|
|
|
|
|
|
joy_polldev(This);
|
|
|
|
if (flags & DIGDD_PEEK)
|
|
|
|
FIXME("DIGDD_PEEK\n");
|
|
|
|
|
|
|
|
if (dod == NULL) {
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SetProperty : change input device properties
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
|
2000-11-05 21:25:02 +01:00
|
|
|
REFGUID rguid,
|
|
|
|
LPCDIPROPHEADER ph)
|
|
|
|
{
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
|
|
|
|
FIXME("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
|
|
|
|
FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph->dwSize, ph->dwHeaderSize,ph->dwObj,ph->dwHow);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
if (!HIWORD(rguid)) {
|
|
|
|
switch ((DWORD)rguid) {
|
|
|
|
case (DWORD) DIPROP_BUFFERSIZE: {
|
|
|
|
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
|
|
|
|
|
|
|
FIXME("buffersize = %ld\n",pd->dwData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DWORD)DIPROP_RANGE: {
|
|
|
|
LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
|
|
|
|
|
|
|
|
FIXME("proprange(%ld,%ld)\n",pr->lMin,pr->lMax);
|
|
|
|
This->lMin = pr->lMin;
|
|
|
|
This->lMax = pr->lMax;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DWORD)DIPROP_DEADZONE: {
|
|
|
|
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
|
|
|
|
|
|
|
FIXME("deadzone(%ld)\n",pd->dwData);
|
|
|
|
This->deadzone = pd->dwData;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SetEventNotification : specifies event to be sent on state change
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickAImpl_SetEventNotification(
|
2002-06-14 02:39:44 +02:00
|
|
|
LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
|
2000-11-05 21:25:02 +01:00
|
|
|
) {
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
|
|
|
|
TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
|
|
|
|
This->hEvent = hnd;
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI JoystickAImpl_GetCapabilities(
|
2002-06-14 02:39:44 +02:00
|
|
|
LPDIRECTINPUTDEVICE8A iface,
|
2000-11-05 21:25:02 +01:00
|
|
|
LPDIDEVCAPS lpDIDevCaps)
|
|
|
|
{
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
BYTE axes,buttons;
|
|
|
|
int xfd = This->joyfd;
|
|
|
|
|
|
|
|
TRACE("%p->(%p)\n",iface,lpDIDevCaps);
|
|
|
|
if (xfd==-1)
|
|
|
|
xfd = open(JOYDEV,O_RDONLY);
|
|
|
|
lpDIDevCaps->dwFlags = DIDC_ATTACHED;
|
|
|
|
lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK;
|
|
|
|
#ifdef JSIOCGAXES
|
|
|
|
if (-1==ioctl(xfd,JSIOCGAXES,&axes))
|
|
|
|
axes = 2;
|
|
|
|
lpDIDevCaps->dwAxes = axes;
|
|
|
|
#endif
|
|
|
|
#ifdef JSIOCGBUTTONS
|
|
|
|
if (-1==ioctl(xfd,JSIOCGAXES,&buttons))
|
|
|
|
buttons = 2;
|
|
|
|
lpDIDevCaps->dwButtons = buttons;
|
|
|
|
#endif
|
|
|
|
if (xfd!=This->joyfd)
|
|
|
|
close(xfd);
|
|
|
|
return DI_OK;
|
|
|
|
}
|
2002-06-14 02:39:44 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
|
2000-11-05 21:25:02 +01:00
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
TRACE("(),stub!\n");
|
|
|
|
|
|
|
|
joy_polldev(This);
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* EnumObjects : enumerate the different buttons and axis...
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI JoystickAImpl_EnumObjects(
|
2002-06-14 02:39:44 +02:00
|
|
|
LPDIRECTINPUTDEVICE8A iface,
|
2000-11-05 21:25:02 +01:00
|
|
|
LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
|
|
|
|
LPVOID lpvRef,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
DIDEVICEOBJECTINSTANCEA ddoi;
|
|
|
|
int xfd = This->joyfd;
|
|
|
|
|
|
|
|
TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
|
|
|
|
if (TRACE_ON(dinput)) {
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE(" - flags = ");
|
2000-11-05 21:25:02 +01:00
|
|
|
_dump_EnumObjects_flags(dwFlags);
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("\n");
|
2000-11-05 21:25:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Only the fields till dwFFMaxForce are relevant */
|
|
|
|
ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/* For the joystick, do as is done in the GetCapabilities function */
|
|
|
|
if ((dwFlags == DIDFT_ALL) ||
|
|
|
|
(dwFlags & DIDFT_AXIS)) {
|
|
|
|
BYTE axes, i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
#ifdef JSIOCGAXES
|
|
|
|
if (-1==ioctl(xfd,JSIOCGAXES,&axes))
|
|
|
|
axes = 2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < axes; i++) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
ddoi.guidType = GUID_XAxis;
|
|
|
|
ddoi.dwOfs = DIJOFS_X;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ddoi.guidType = GUID_YAxis;
|
|
|
|
ddoi.dwOfs = DIJOFS_Y;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ddoi.guidType = GUID_ZAxis;
|
|
|
|
ddoi.dwOfs = DIJOFS_Z;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ddoi.guidType = GUID_Unknown;
|
|
|
|
ddoi.dwOfs = DIJOFS_Z + (i - 2) * sizeof(LONG);
|
|
|
|
}
|
|
|
|
ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << i) << WINE_JOYSTICK_AXIS_BASE) | DIDFT_ABSAXIS;
|
|
|
|
sprintf(ddoi.tszName, "%d-Axis", i);
|
|
|
|
_dump_OBJECTINSTANCEA(&ddoi);
|
|
|
|
if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dwFlags == DIDFT_ALL) ||
|
|
|
|
(dwFlags & DIDFT_BUTTON)) {
|
|
|
|
BYTE buttons, i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
#ifdef JSIOCGBUTTONS
|
|
|
|
if (-1==ioctl(xfd,JSIOCGAXES,&buttons))
|
|
|
|
buttons = 2;
|
|
|
|
#endif
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
/* The DInput SDK says that GUID_Button is only for mouse buttons but well... */
|
|
|
|
ddoi.guidType = GUID_Button;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
for (i = 0; i < buttons; i++) {
|
|
|
|
ddoi.dwOfs = DIJOFS_BUTTON(i);
|
|
|
|
ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << i) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
|
|
|
|
sprintf(ddoi.tszName, "%d-Button", i);
|
|
|
|
_dump_OBJECTINSTANCEA(&ddoi);
|
|
|
|
if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfd!=This->joyfd)
|
|
|
|
close(xfd);
|
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetProperty : get input device properties
|
|
|
|
*/
|
2002-06-14 02:39:44 +02:00
|
|
|
static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
|
2000-11-05 21:25:02 +01:00
|
|
|
REFGUID rguid,
|
|
|
|
LPDIPROPHEADER pdiph)
|
|
|
|
{
|
|
|
|
ICOM_THIS(JoystickAImpl,iface);
|
|
|
|
|
|
|
|
TRACE("(this=%p,%s,%p): stub!\n",
|
|
|
|
iface, debugstr_guid(rguid), pdiph);
|
|
|
|
|
|
|
|
if (TRACE_ON(dinput))
|
|
|
|
_dump_DIPROPHEADER(pdiph);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
if (!HIWORD(rguid)) {
|
|
|
|
switch ((DWORD)rguid) {
|
|
|
|
case (DWORD) DIPROP_BUFFERSIZE: {
|
|
|
|
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
TRACE(" return buffersize = %d\n",This->queue_len);
|
|
|
|
pd->dwData = This->queue_len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case (DWORD) DIPROP_RANGE: {
|
|
|
|
LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
|
|
|
|
|
|
|
|
if ((pdiph->dwHow == DIPH_BYID) &&
|
|
|
|
(pdiph->dwObj & DIDFT_ABSAXIS)) {
|
|
|
|
/* The app is querying the current range of the axis : return the lMin and lMax values */
|
|
|
|
pr->lMin = This->lMin;
|
|
|
|
pr->lMax = This->lMax;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
|
2000-11-05 21:25:02 +01:00
|
|
|
return DI_OK;
|
|
|
|
}
|
|
|
|
|
2002-06-14 02:39:44 +02:00
|
|
|
static ICOM_VTABLE(IDirectInputDevice8A) JoystickAvt =
|
2000-11-05 21:25:02 +01:00
|
|
|
{
|
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|
|
|
IDirectInputDevice2AImpl_QueryInterface,
|
|
|
|
IDirectInputDevice2AImpl_AddRef,
|
|
|
|
JoystickAImpl_Release,
|
|
|
|
JoystickAImpl_GetCapabilities,
|
|
|
|
JoystickAImpl_EnumObjects,
|
|
|
|
JoystickAImpl_GetProperty,
|
|
|
|
JoystickAImpl_SetProperty,
|
|
|
|
JoystickAImpl_Acquire,
|
|
|
|
JoystickAImpl_Unacquire,
|
|
|
|
JoystickAImpl_GetDeviceState,
|
|
|
|
JoystickAImpl_GetDeviceData,
|
|
|
|
JoystickAImpl_SetDataFormat,
|
|
|
|
JoystickAImpl_SetEventNotification,
|
|
|
|
IDirectInputDevice2AImpl_SetCooperativeLevel,
|
|
|
|
IDirectInputDevice2AImpl_GetObjectInfo,
|
|
|
|
IDirectInputDevice2AImpl_GetDeviceInfo,
|
|
|
|
IDirectInputDevice2AImpl_RunControlPanel,
|
|
|
|
IDirectInputDevice2AImpl_Initialize,
|
|
|
|
IDirectInputDevice2AImpl_CreateEffect,
|
|
|
|
IDirectInputDevice2AImpl_EnumEffects,
|
|
|
|
IDirectInputDevice2AImpl_GetEffectInfo,
|
|
|
|
IDirectInputDevice2AImpl_GetForceFeedbackState,
|
|
|
|
IDirectInputDevice2AImpl_SendForceFeedbackCommand,
|
|
|
|
IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
|
|
|
|
IDirectInputDevice2AImpl_Escape,
|
|
|
|
JoystickAImpl_Poll,
|
|
|
|
IDirectInputDevice2AImpl_SendDeviceData,
|
|
|
|
IDirectInputDevice7AImpl_EnumEffectsInFile,
|
2002-06-14 02:39:44 +02:00
|
|
|
IDirectInputDevice7AImpl_WriteEffectToFile,
|
|
|
|
IDirectInputDevice8AImpl_BuildActionMap,
|
|
|
|
IDirectInputDevice8AImpl_SetActionMap,
|
|
|
|
IDirectInputDevice8AImpl_GetImageInfo
|
2000-11-05 21:25:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* HAVE_LINUX_22_JOYSTICK_API */
|