2000-02-26 14:14:04 +01:00
|
|
|
/*
|
|
|
|
* joystick functions
|
|
|
|
*
|
|
|
|
* Copyright 1997 Andreas Mohr
|
2002-09-04 20:43:05 +02:00
|
|
|
* Copyright 2000 Wolfgang Schwotzer
|
|
|
|
* Copyright 2002 David Hagood
|
2000-02-26 14:14:04 +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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
*
|
2004-12-06 21:55:25 +01:00
|
|
|
* - nearly all joystick functions can be regarded as obsolete,
|
|
|
|
* as Linux (2.1.x) now supports extended joysticks with a completely
|
|
|
|
* new joystick driver interface
|
2008-01-09 18:59:19 +01:00
|
|
|
* New driver's documentation says:
|
2004-12-06 21:55:25 +01:00
|
|
|
* "For backward compatibility the old interface is still included,
|
|
|
|
* but will be dropped in the future."
|
|
|
|
* Thus we should implement the new interface and at most keep the old
|
|
|
|
* routines for backward compatibility.
|
|
|
|
* - better support of enhanced joysticks (Linux 2.2 interface is available)
|
|
|
|
* - support more joystick drivers (like the XInput extension)
|
|
|
|
* - should load joystick DLL as any other driver (instead of hardcoding)
|
|
|
|
* the driver's name, and load it as any low lever driver.
|
2000-02-26 14:14:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2005-08-03 23:25:10 +02:00
|
|
|
#include "wine/port.h"
|
2000-02-26 14:14:04 +01:00
|
|
|
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-02-26 14:14:04 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
2002-06-01 01:06:46 +02:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
2000-02-26 14:14:04 +01:00
|
|
|
#include <sys/ioctl.h>
|
2002-05-20 00:25:02 +02:00
|
|
|
#endif
|
2004-03-01 22:32:02 +01:00
|
|
|
#ifdef HAVE_LINUX_IOCTL_H
|
|
|
|
#include <linux/ioctl.h>
|
|
|
|
#endif
|
2000-02-26 14:14:04 +01:00
|
|
|
#ifdef HAVE_LINUX_JOYSTICK_H
|
|
|
|
#include <linux/joystick.h>
|
2006-06-13 09:58:38 +02:00
|
|
|
#ifdef SW_MAX
|
|
|
|
#undef SW_MAX
|
|
|
|
#endif
|
2006-04-19 00:58:44 +02:00
|
|
|
#define JOYDEV_NEW "/dev/input/js%d"
|
|
|
|
#define JOYDEV_OLD "/dev/js%d"
|
2000-02-26 14:14:04 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_ERRNO_H
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#endif
|
2000-12-19 05:53:20 +01:00
|
|
|
|
2000-02-26 14:14:04 +01:00
|
|
|
#include "windef.h"
|
2000-12-19 05:53:20 +01:00
|
|
|
#include "winbase.h"
|
2000-02-26 14:14:04 +01:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2004-12-06 21:55:25 +01:00
|
|
|
#include "winnls.h"
|
2000-02-26 14:14:04 +01:00
|
|
|
#include "mmddk.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-02-26 14:14:04 +01:00
|
|
|
|
2005-11-14 12:23:34 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(joystick);
|
2000-02-26 14:14:04 +01:00
|
|
|
|
2008-10-26 19:01:28 +01:00
|
|
|
#define MAXJOYSTICK (JOYSTICKID2 + 30)
|
2000-02-26 14:14:04 +01:00
|
|
|
|
2000-03-19 13:41:41 +01:00
|
|
|
typedef struct tagWINE_JSTCK {
|
|
|
|
int joyIntf;
|
|
|
|
int in_use;
|
2008-01-09 18:59:19 +01:00
|
|
|
/* Some extra info we need to make this actually work under the
|
2002-09-04 20:43:05 +02:00
|
|
|
Linux 2.2 event api.
|
|
|
|
First of all, we cannot keep closing and reopening the device file -
|
|
|
|
that blows away the state of the stick device, and we lose events. So, we
|
|
|
|
need to open the low-level device once, and close it when we are done.
|
|
|
|
|
|
|
|
Secondly, the event API only gives us what's changed. However, Windows apps
|
|
|
|
want the whole state every time, so we have to cache the data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int dev; /* Linux level device file descriptor */
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int z;
|
|
|
|
int r;
|
|
|
|
int u;
|
|
|
|
int v;
|
2009-01-17 12:54:07 +01:00
|
|
|
int pov_x;
|
|
|
|
int pov_y;
|
2002-09-04 20:43:05 +02:00
|
|
|
int buttons;
|
2009-01-17 12:35:05 +01:00
|
|
|
char axesMap[ABS_MAX + 1];
|
2000-03-19 13:41:41 +01:00
|
|
|
} WINE_JSTCK;
|
|
|
|
|
|
|
|
static WINE_JSTCK JSTCK_Data[MAXJOYSTICK];
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* JSTCK_drvGet [internal]
|
2000-03-19 13:41:41 +01:00
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
static WINE_JSTCK *JSTCK_drvGet(DWORD_PTR dwDevID)
|
2000-03-19 13:41:41 +01:00
|
|
|
{
|
|
|
|
int p;
|
|
|
|
|
2005-11-28 20:53:22 +01:00
|
|
|
if ((dwDevID - (DWORD_PTR)JSTCK_Data) % sizeof(JSTCK_Data[0]) != 0)
|
2000-03-19 13:41:41 +01:00
|
|
|
return NULL;
|
2005-11-28 20:53:22 +01:00
|
|
|
p = (dwDevID - (DWORD_PTR)JSTCK_Data) / sizeof(JSTCK_Data[0]);
|
2000-03-19 13:41:41 +01:00
|
|
|
if (p < 0 || p >= MAXJOYSTICK || !((WINE_JSTCK*)dwDevID)->in_use)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (WINE_JSTCK*)dwDevID;
|
|
|
|
}
|
2000-02-26 14:14:04 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* JSTCK_drvOpen [internal]
|
2000-02-26 14:14:04 +01:00
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
static LRESULT JSTCK_drvOpen(LPSTR str, DWORD dwIntf)
|
2000-02-26 14:14:04 +01:00
|
|
|
{
|
2000-03-19 13:41:41 +01:00
|
|
|
if (dwIntf >= MAXJOYSTICK || JSTCK_Data[dwIntf].in_use)
|
2000-02-26 14:14:04 +01:00
|
|
|
return 0;
|
2000-03-19 13:41:41 +01:00
|
|
|
|
|
|
|
JSTCK_Data[dwIntf].joyIntf = dwIntf;
|
|
|
|
JSTCK_Data[dwIntf].in_use = 1;
|
2005-11-28 20:53:22 +01:00
|
|
|
return (LRESULT)&JSTCK_Data[dwIntf];
|
2000-02-26 14:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* JSTCK_drvClose [internal]
|
2000-02-26 14:14:04 +01:00
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
static LRESULT JSTCK_drvClose(DWORD_PTR dwDevID)
|
2000-02-26 14:14:04 +01:00
|
|
|
{
|
2000-03-19 13:41:41 +01:00
|
|
|
WINE_JSTCK* jstck = JSTCK_drvGet(dwDevID);
|
|
|
|
|
|
|
|
if (jstck == NULL)
|
|
|
|
return 0;
|
|
|
|
jstck->in_use = 0;
|
2002-09-04 20:43:05 +02:00
|
|
|
if (jstck->dev > 0)
|
|
|
|
{
|
|
|
|
close(jstck->dev);
|
|
|
|
jstck->dev = 0;
|
|
|
|
}
|
2000-03-19 13:41:41 +01:00
|
|
|
return 1;
|
2000-02-26 14:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct js_status
|
|
|
|
{
|
|
|
|
int buttons;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* JSTCK_OpenDevice [internal]
|
|
|
|
*/
|
2000-03-19 13:41:41 +01:00
|
|
|
static int JSTCK_OpenDevice(WINE_JSTCK* jstick)
|
2000-02-26 14:14:04 +01:00
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
int flags;
|
|
|
|
|
2002-09-04 20:43:05 +02:00
|
|
|
if (jstick->dev > 0)
|
|
|
|
return jstick->dev;
|
|
|
|
|
2006-04-19 00:58:44 +02:00
|
|
|
sprintf(buf, JOYDEV_NEW, jstick->joyIntf);
|
2000-02-26 14:14:04 +01:00
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
|
|
|
flags = O_RDONLY | O_NONBLOCK;
|
|
|
|
#else
|
|
|
|
flags = O_RDONLY;
|
|
|
|
#endif
|
2006-04-19 00:58:44 +02:00
|
|
|
if ((jstick->dev = open(buf, flags)) < 0) {
|
|
|
|
sprintf(buf, JOYDEV_OLD, jstick->joyIntf);
|
2009-01-17 12:35:05 +01:00
|
|
|
if ((jstick->dev = open(buf, flags)) < 0)
|
|
|
|
return jstick->dev;
|
2006-04-19 00:58:44 +02:00
|
|
|
}
|
2009-01-17 12:35:05 +01:00
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
|
|
|
ioctl(jstick->dev, JSIOCGAXMAP, jstick->axesMap);
|
|
|
|
#endif
|
2009-01-17 12:31:39 +01:00
|
|
|
return jstick->dev;
|
2000-02-26 14:14:04 +01:00
|
|
|
}
|
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
|
2000-02-26 14:14:04 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* JoyGetDevCaps [MMSYSTEM.102]
|
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
static LRESULT JSTCK_GetDevCaps(DWORD_PTR dwDevID, LPJOYCAPSW lpCaps, DWORD dwSize)
|
2000-02-26 14:14:04 +01:00
|
|
|
{
|
2000-03-19 13:41:41 +01:00
|
|
|
WINE_JSTCK* jstck;
|
2000-02-26 14:14:04 +01:00
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
|
|
|
int dev;
|
|
|
|
char nrOfAxes;
|
|
|
|
char nrOfButtons;
|
|
|
|
char identString[MAXPNAMELEN];
|
2009-01-17 12:35:05 +01:00
|
|
|
int i;
|
2000-02-26 14:14:04 +01:00
|
|
|
int driverVersion;
|
2004-12-06 21:55:25 +01:00
|
|
|
#else
|
|
|
|
static const WCHAR ini[] = {'W','i','n','e',' ','J','o','y','s','t','i','c','k',' ','D','r','i','v','e','r',0};
|
2000-02-26 14:14:04 +01:00
|
|
|
#endif
|
|
|
|
|
2000-03-19 13:41:41 +01:00
|
|
|
if ((jstck = JSTCK_drvGet(dwDevID)) == NULL)
|
|
|
|
return MMSYSERR_NODRIVER;
|
2000-02-26 14:14:04 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
2000-03-19 13:41:41 +01:00
|
|
|
if ((dev = JSTCK_OpenDevice(jstck)) < 0) return JOYERR_PARMS;
|
2000-02-26 14:14:04 +01:00
|
|
|
ioctl(dev, JSIOCGAXES, &nrOfAxes);
|
|
|
|
ioctl(dev, JSIOCGBUTTONS, &nrOfButtons);
|
|
|
|
ioctl(dev, JSIOCGVERSION, &driverVersion);
|
2008-07-12 21:37:24 +02:00
|
|
|
ioctl(dev, JSIOCGNAME(sizeof(identString)), identString);
|
2000-02-26 14:14:04 +01:00
|
|
|
TRACE("Driver: 0x%06x, Name: %s, #Axes: %d, #Buttons: %d\n",
|
|
|
|
driverVersion, identString, nrOfAxes, nrOfButtons);
|
|
|
|
lpCaps->wMid = MM_MICROSOFT;
|
|
|
|
lpCaps->wPid = MM_PC_JOYSTICK;
|
2009-02-18 21:32:27 +01:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, identString, -1, lpCaps->szPname, MAXPNAMELEN);
|
2000-02-26 14:14:04 +01:00
|
|
|
lpCaps->szPname[MAXPNAMELEN-1] = '\0';
|
|
|
|
lpCaps->wXmin = 0;
|
|
|
|
lpCaps->wXmax = 0xFFFF;
|
|
|
|
lpCaps->wYmin = 0;
|
|
|
|
lpCaps->wYmax = 0xFFFF;
|
|
|
|
lpCaps->wZmin = 0;
|
|
|
|
lpCaps->wZmax = (nrOfAxes >= 3) ? 0xFFFF : 0;
|
2002-09-04 20:43:05 +02:00
|
|
|
#ifdef BODGE_THE_HAT
|
2010-06-24 10:18:34 +02:00
|
|
|
/* Half-Life won't allow you to map an axis event to things like
|
2002-09-04 20:43:05 +02:00
|
|
|
"next weapon" and "use". Linux reports the hat on my stick as
|
|
|
|
axis U and V. So, IFF BODGE_THE_HAT is defined, lie through our
|
2010-06-24 10:18:34 +02:00
|
|
|
teeth and say we have 32 buttons, and we will map the axes to
|
2002-09-04 20:43:05 +02:00
|
|
|
the high buttons. Really, perhaps this should be a registry entry,
|
|
|
|
or even a parameter to the Linux joystick driver (which would completely
|
|
|
|
remove the need for this.)
|
|
|
|
*/
|
|
|
|
lpCaps->wNumButtons = 32;
|
|
|
|
#else
|
2000-02-26 14:14:04 +01:00
|
|
|
lpCaps->wNumButtons = nrOfButtons;
|
2002-09-04 20:43:05 +02:00
|
|
|
#endif
|
2004-12-06 21:55:25 +01:00
|
|
|
if (dwSize == sizeof(JOYCAPSW)) {
|
2000-02-26 14:14:04 +01:00
|
|
|
/* complete 95 structure */
|
|
|
|
lpCaps->wRmin = 0;
|
2009-01-17 12:35:05 +01:00
|
|
|
lpCaps->wRmax = 0xFFFF;
|
2000-02-26 14:14:04 +01:00
|
|
|
lpCaps->wUmin = 0;
|
2009-01-17 12:35:05 +01:00
|
|
|
lpCaps->wUmax = 0xFFFF;
|
2000-02-26 14:14:04 +01:00
|
|
|
lpCaps->wVmin = 0;
|
2009-01-17 12:35:05 +01:00
|
|
|
lpCaps->wVmax = 0xFFFF;
|
2000-02-26 14:14:04 +01:00
|
|
|
lpCaps->wMaxAxes = 6; /* same as MS Joystick Driver */
|
2009-01-17 12:35:05 +01:00
|
|
|
lpCaps->wNumAxes = 0; /* nr of axes in use */
|
2000-02-26 14:14:04 +01:00
|
|
|
lpCaps->wMaxButtons = 32; /* same as MS Joystick Driver */
|
2004-12-06 21:55:25 +01:00
|
|
|
lpCaps->szRegKey[0] = 0;
|
|
|
|
lpCaps->szOEMVxD[0] = 0;
|
2000-02-26 14:14:04 +01:00
|
|
|
lpCaps->wCaps = 0;
|
2009-01-17 12:35:05 +01:00
|
|
|
for (i = 0; i < nrOfAxes; i++) {
|
|
|
|
switch (jstck->axesMap[i]) {
|
|
|
|
case 0: /* X */
|
|
|
|
case 1: /* Y */
|
|
|
|
lpCaps->wNumAxes++;
|
|
|
|
break;
|
|
|
|
case 2: /* Z */
|
|
|
|
case 6: /* Throttle */
|
|
|
|
lpCaps->wNumAxes++;
|
|
|
|
lpCaps->wCaps |= JOYCAPS_HASZ;
|
|
|
|
break;
|
|
|
|
case 5: /* Rz */
|
|
|
|
case 7: /* Rudder */
|
|
|
|
lpCaps->wNumAxes++;
|
|
|
|
lpCaps->wCaps |= JOYCAPS_HASR;
|
|
|
|
break;
|
|
|
|
case 3: /* Rx */
|
|
|
|
lpCaps->wNumAxes++;
|
|
|
|
lpCaps->wCaps |= JOYCAPS_HASU;
|
|
|
|
break;
|
|
|
|
case 4: /* Ry */
|
|
|
|
lpCaps->wNumAxes++;
|
|
|
|
lpCaps->wCaps |= JOYCAPS_HASV;
|
|
|
|
break;
|
2009-01-17 12:54:07 +01:00
|
|
|
case 16: /* Hat 0 X */
|
|
|
|
case 17: /* Hat 0 Y */
|
|
|
|
lpCaps->wCaps |= JOYCAPS_HASPOV | JOYCAPS_POV4DIR;
|
|
|
|
/* TODO: JOYCAPS_POVCTS handling */
|
|
|
|
break;
|
2009-01-17 12:35:05 +01:00
|
|
|
default:
|
2010-09-20 10:54:33 +02:00
|
|
|
WARN("Unknown axis %hhu(%u). Skipped.\n", jstck->axesMap[i], i);
|
2009-01-17 12:35:05 +01:00
|
|
|
}
|
2000-02-26 14:14:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
lpCaps->wMid = MM_MICROSOFT;
|
|
|
|
lpCaps->wPid = MM_PC_JOYSTICK;
|
2004-12-06 21:55:25 +01:00
|
|
|
strcpyW(lpCaps->szPname, ini); /* joystick product name */
|
2000-02-26 14:14:04 +01:00
|
|
|
lpCaps->wXmin = 0;
|
|
|
|
lpCaps->wXmax = 0xFFFF;
|
|
|
|
lpCaps->wYmin = 0;
|
|
|
|
lpCaps->wYmax = 0xFFFF;
|
|
|
|
lpCaps->wZmin = 0;
|
|
|
|
lpCaps->wZmax = 0;
|
|
|
|
lpCaps->wNumButtons = 2;
|
2004-12-06 21:55:25 +01:00
|
|
|
if (dwSize == sizeof(JOYCAPSW)) {
|
2000-02-26 14:14:04 +01:00
|
|
|
/* complete 95 structure */
|
|
|
|
lpCaps->wRmin = 0;
|
|
|
|
lpCaps->wRmax = 0;
|
|
|
|
lpCaps->wUmin = 0;
|
|
|
|
lpCaps->wUmax = 0;
|
|
|
|
lpCaps->wVmin = 0;
|
|
|
|
lpCaps->wVmax = 0;
|
|
|
|
lpCaps->wCaps = 0;
|
|
|
|
lpCaps->wMaxAxes = 2;
|
|
|
|
lpCaps->wNumAxes = 2;
|
|
|
|
lpCaps->wMaxButtons = 4;
|
2004-12-06 21:55:25 +01:00
|
|
|
lpCaps->szRegKey[0] = 0;
|
|
|
|
lpCaps->szOEMVxD[0] = 0;
|
2000-02-26 14:14:04 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return JOYERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* JSTCK_GetPos [internal]
|
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
static LRESULT JSTCK_GetPosEx(DWORD_PTR dwDevID, LPJOYINFOEX lpInfo)
|
2000-02-26 14:14:04 +01:00
|
|
|
{
|
2000-03-19 13:41:41 +01:00
|
|
|
WINE_JSTCK* jstck;
|
2000-02-26 14:14:04 +01:00
|
|
|
int dev;
|
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
|
|
|
struct js_event ev;
|
|
|
|
#else
|
|
|
|
struct js_status js;
|
|
|
|
int dev_stat;
|
|
|
|
#endif
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-03-19 13:41:41 +01:00
|
|
|
if ((jstck = JSTCK_drvGet(dwDevID)) == NULL)
|
|
|
|
return MMSYSERR_NODRIVER;
|
|
|
|
|
|
|
|
if ((dev = JSTCK_OpenDevice(jstck)) < 0) return JOYERR_PARMS;
|
2000-02-26 14:14:04 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
|
|
|
while ((read(dev, &ev, sizeof(struct js_event))) > 0) {
|
2002-09-04 20:43:05 +02:00
|
|
|
if (ev.type == (JS_EVENT_AXIS)) {
|
2009-01-17 12:35:05 +01:00
|
|
|
switch (jstck->axesMap[ev.number]) {
|
|
|
|
case 0: /* X */
|
2002-09-04 20:43:05 +02:00
|
|
|
jstck->x = ev.value;
|
2000-02-26 14:14:04 +01:00
|
|
|
break;
|
2009-01-17 12:35:05 +01:00
|
|
|
case 1: /* Y */
|
2002-09-04 20:43:05 +02:00
|
|
|
jstck->y = ev.value;
|
2000-02-26 14:14:04 +01:00
|
|
|
break;
|
2009-01-17 12:35:05 +01:00
|
|
|
case 2: /* Z */
|
|
|
|
case 6: /* Throttle */
|
2002-09-04 20:43:05 +02:00
|
|
|
jstck->z = ev.value;
|
2000-02-26 14:14:04 +01:00
|
|
|
break;
|
2009-01-17 12:35:05 +01:00
|
|
|
case 5: /* Rz */
|
|
|
|
case 7: /* Rudder */
|
2002-09-04 20:43:05 +02:00
|
|
|
jstck->r = ev.value;
|
|
|
|
break;
|
2009-01-17 12:35:05 +01:00
|
|
|
case 3: /* Rx */
|
2002-09-04 20:43:05 +02:00
|
|
|
jstck->u = ev.value;
|
|
|
|
break;
|
2009-01-17 12:35:05 +01:00
|
|
|
case 4: /* Ry */
|
2002-09-04 20:43:05 +02:00
|
|
|
jstck->v = ev.value;
|
2000-02-26 14:14:04 +01:00
|
|
|
break;
|
2009-01-17 12:54:07 +01:00
|
|
|
case 16: /* Hat 0 X */
|
|
|
|
jstck->pov_x = ev.value;
|
|
|
|
break;
|
|
|
|
case 17: /* Hat 0 Y */
|
|
|
|
jstck->pov_y = ev.value;
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
default:
|
2000-02-26 14:14:04 +01:00
|
|
|
FIXME("Unknown joystick event '%d'\n", ev.number);
|
|
|
|
}
|
2002-09-04 20:43:05 +02:00
|
|
|
} else if (ev.type == (JS_EVENT_BUTTON)) {
|
|
|
|
if (ev.value) {
|
|
|
|
jstck->buttons |= (1 << ev.number);
|
2002-06-01 01:06:46 +02:00
|
|
|
/* FIXME: what to do for this field when
|
2000-02-26 14:14:04 +01:00
|
|
|
* multiple buttons are depressed ?
|
|
|
|
*/
|
2002-09-04 20:43:05 +02:00
|
|
|
if (lpInfo->dwFlags & JOY_RETURNBUTTONS)
|
|
|
|
lpInfo->dwButtonNumber = ev.number + 1;
|
2000-02-26 14:14:04 +01:00
|
|
|
}
|
2002-09-04 20:43:05 +02:00
|
|
|
else
|
|
|
|
jstck->buttons &= ~(1 << ev.number);
|
2000-02-26 14:14:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* EAGAIN is returned when the queue is empty */
|
|
|
|
if (errno != EAGAIN) {
|
|
|
|
/* FIXME: error should not be ignored */
|
2000-08-26 22:31:48 +02:00
|
|
|
ERR("Error while reading joystick state (%s)\n", strerror(errno));
|
2000-02-26 14:14:04 +01:00
|
|
|
}
|
2002-09-04 20:43:05 +02:00
|
|
|
/* Now, copy the cached values into Window's structure... */
|
|
|
|
if (lpInfo->dwFlags & JOY_RETURNBUTTONS)
|
|
|
|
lpInfo->dwButtons = jstck->buttons;
|
|
|
|
if (lpInfo->dwFlags & JOY_RETURNX)
|
|
|
|
lpInfo->dwXpos = jstck->x + 32767;
|
|
|
|
if (lpInfo->dwFlags & JOY_RETURNY)
|
|
|
|
lpInfo->dwYpos = jstck->y + 32767;
|
|
|
|
if (lpInfo->dwFlags & JOY_RETURNZ)
|
|
|
|
lpInfo->dwZpos = jstck->z + 32767;
|
|
|
|
if (lpInfo->dwFlags & JOY_RETURNR)
|
|
|
|
lpInfo->dwRpos = jstck->r + 32767;
|
2005-03-02 13:23:20 +01:00
|
|
|
# ifdef BODGE_THE_HAT
|
2002-09-04 20:43:05 +02:00
|
|
|
else if (lpInfo->dwFlags & JOY_RETURNBUTTONS)
|
|
|
|
{
|
|
|
|
if (jstck->r > 0)
|
|
|
|
lpInfo->dwButtons |= 1<<7;
|
|
|
|
else if (jstck->r < 0)
|
|
|
|
lpInfo->dwButtons |= 1<<8;
|
|
|
|
}
|
2005-03-02 13:23:20 +01:00
|
|
|
# endif
|
2002-09-04 20:43:05 +02:00
|
|
|
if (lpInfo->dwFlags & JOY_RETURNU)
|
|
|
|
lpInfo->dwUpos = jstck->u + 32767;
|
2005-03-02 13:23:20 +01:00
|
|
|
# ifdef BODGE_THE_HAT
|
2002-09-04 20:43:05 +02:00
|
|
|
else if (lpInfo->dwFlags & JOY_RETURNBUTTONS)
|
|
|
|
{
|
|
|
|
if (jstck->u > 0)
|
|
|
|
lpInfo->dwButtons |= 1<<9;
|
|
|
|
else if (jstck->u < 0)
|
|
|
|
lpInfo->dwButtons |= 1<<10;
|
|
|
|
}
|
2005-03-02 13:23:20 +01:00
|
|
|
# endif
|
2002-09-04 20:43:05 +02:00
|
|
|
if (lpInfo->dwFlags & JOY_RETURNV)
|
|
|
|
lpInfo->dwVpos = jstck->v + 32767;
|
2009-01-17 12:54:07 +01:00
|
|
|
if (lpInfo->dwFlags & JOY_RETURNPOV) {
|
|
|
|
if (jstck->pov_y > 0) {
|
|
|
|
if (jstck->pov_x < 0)
|
|
|
|
lpInfo->dwPOV = 22500; /* SW */
|
|
|
|
else if (jstck->pov_x > 0)
|
|
|
|
lpInfo->dwPOV = 13500; /* SE */
|
|
|
|
else
|
|
|
|
lpInfo->dwPOV = 18000; /* S, JOY_POVBACKWARD */
|
|
|
|
} else if (jstck->pov_y < 0) {
|
|
|
|
if (jstck->pov_x < 0)
|
|
|
|
lpInfo->dwPOV = 31500; /* NW */
|
|
|
|
else if (jstck->pov_x > 0)
|
|
|
|
lpInfo->dwPOV = 4500; /* NE */
|
|
|
|
else
|
|
|
|
lpInfo->dwPOV = 0; /* N, JOY_POVFORWARD */
|
|
|
|
} else if (jstck->pov_x < 0)
|
|
|
|
lpInfo->dwPOV = 27000; /* W, JOY_POVLEFT */
|
|
|
|
else if (jstck->pov_x > 0)
|
|
|
|
lpInfo->dwPOV = 9000; /* E, JOY_POVRIGHT */
|
|
|
|
else
|
|
|
|
lpInfo->dwPOV = JOY_POVCENTERED; /* Center */
|
|
|
|
}
|
2002-09-04 20:43:05 +02:00
|
|
|
|
2000-02-26 14:14:04 +01:00
|
|
|
#else
|
|
|
|
dev_stat = read(dev, &js, sizeof(js));
|
|
|
|
if (dev_stat != sizeof(js)) {
|
|
|
|
return JOYERR_UNPLUGGED; /* FIXME: perhaps wrong, but what should I return else ? */
|
|
|
|
}
|
|
|
|
js.x = js.x<<8;
|
|
|
|
js.y = js.y<<8;
|
|
|
|
if (lpInfo->dwFlags & JOY_RETURNX)
|
|
|
|
lpInfo->dwXpos = js.x; /* FIXME: perhaps multiply it somehow ? */
|
|
|
|
if (lpInfo->dwFlags & JOY_RETURNY)
|
|
|
|
lpInfo->dwYpos = js.y;
|
|
|
|
if (lpInfo->dwFlags & JOY_RETURNBUTTONS)
|
|
|
|
lpInfo->dwButtons = js.buttons;
|
|
|
|
#endif
|
|
|
|
|
2006-09-29 01:19:00 +02:00
|
|
|
TRACE("x: %d, y: %d, z: %d, r: %d, u: %d, v: %d, buttons: 0x%04x, flags: 0x%04x (fd %d)\n",
|
2000-02-26 14:14:04 +01:00
|
|
|
lpInfo->dwXpos, lpInfo->dwYpos, lpInfo->dwZpos,
|
|
|
|
lpInfo->dwRpos, lpInfo->dwUpos, lpInfo->dwVpos,
|
2008-02-08 22:58:40 +01:00
|
|
|
lpInfo->dwButtons, lpInfo->dwFlags, dev
|
2002-09-04 20:43:05 +02:00
|
|
|
);
|
2000-02-26 14:14:04 +01:00
|
|
|
|
|
|
|
return JOYERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* JSTCK_GetPos [internal]
|
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
static LRESULT JSTCK_GetPos(DWORD_PTR dwDevID, LPJOYINFO lpInfo)
|
2000-02-26 14:14:04 +01:00
|
|
|
{
|
|
|
|
JOYINFOEX ji;
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
memset(&ji, 0, sizeof(ji));
|
|
|
|
|
|
|
|
ji.dwSize = sizeof(ji);
|
|
|
|
ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNBUTTONS;
|
|
|
|
ret = JSTCK_GetPosEx(dwDevID, &ji);
|
|
|
|
if (ret == JOYERR_NOERROR) {
|
|
|
|
lpInfo->wXpos = ji.dwXpos;
|
|
|
|
lpInfo->wYpos = ji.dwYpos;
|
|
|
|
lpInfo->wZpos = ji.dwZpos;
|
|
|
|
lpInfo->wButtons = ji.dwButtons;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* DriverProc (JOYSTICK.@)
|
2000-02-26 14:14:04 +01:00
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
LRESULT CALLBACK JSTCK_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
|
|
|
|
LPARAM dwParam1, LPARAM dwParam2)
|
2000-02-26 14:14:04 +01:00
|
|
|
{
|
|
|
|
/* EPP TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n", */
|
|
|
|
/* EPP dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-02-26 14:14:04 +01:00
|
|
|
switch(wMsg) {
|
|
|
|
case DRV_LOAD: return 1;
|
|
|
|
case DRV_FREE: return 1;
|
2000-03-19 13:41:41 +01:00
|
|
|
case DRV_OPEN: return JSTCK_drvOpen((LPSTR)dwParam1, dwParam2);
|
2000-02-26 14:14:04 +01:00
|
|
|
case DRV_CLOSE: return JSTCK_drvClose(dwDevID);
|
|
|
|
case DRV_ENABLE: return 1;
|
|
|
|
case DRV_DISABLE: return 1;
|
|
|
|
case DRV_QUERYCONFIGURE: return 1;
|
|
|
|
case DRV_CONFIGURE: MessageBoxA(0, "JoyStick MultiMedia Driver !", "JoyStick Driver", MB_OK); return 1;
|
|
|
|
case DRV_INSTALL: return DRVCNF_RESTART;
|
|
|
|
case DRV_REMOVE: return DRVCNF_RESTART;
|
|
|
|
|
2000-03-19 13:41:41 +01:00
|
|
|
case JDD_GETNUMDEVS: return 1;
|
2004-12-06 21:55:25 +01:00
|
|
|
case JDD_GETDEVCAPS: return JSTCK_GetDevCaps(dwDevID, (LPJOYCAPSW)dwParam1, dwParam2);
|
2000-02-26 14:14:04 +01:00
|
|
|
case JDD_GETPOS: return JSTCK_GetPos(dwDevID, (LPJOYINFO)dwParam1);
|
2002-06-01 01:06:46 +02:00
|
|
|
case JDD_SETCALIBRATION:
|
2000-02-26 14:14:04 +01:00
|
|
|
case JDD_CONFIGCHANGED: return JOYERR_NOCANDO;
|
|
|
|
case JDD_GETPOSEX: return JSTCK_GetPosEx(dwDevID, (LPJOYINFOEX)dwParam1);
|
|
|
|
default:
|
|
|
|
return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
|
|
|
|
}
|
|
|
|
}
|