Vitaliy Margolen : dinput: Fix handling of dead-zone in evdev
joystick.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Aug 6 08:03:54 CDT 2007
Module: wine
Branch: master
Commit: 1fdc0230f0f7a33b10ec7ac481fc98780d190c03
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1fdc0230f0f7a33b10ec7ac481fc98780d190c03
Author: Vitaliy Margolen <wine-patches at kievinfo.com>
Date: Sun Aug 5 12:20:26 2007 -0600
dinput: Fix handling of dead-zone in evdev joystick.
USB joysticks can and do provide dead-zone area. Use it to initialize
the initial dead-zone.
---
dlls/dinput/joystick_linuxinput.c | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 8e8dd4b..f4c8018 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -389,7 +389,9 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
newDevice->props[idx].havemax = newDevice->joydev->axes[i][AXIS_ABSMAX];
newDevice->props[idx].wantmin = 0;
newDevice->props[idx].wantmax = 0xffff;
- newDevice->props[idx].deadzone = 0;
+ newDevice->props[idx].deadzone = MulDiv(newDevice->joydev->axes[i][AXIS_ABSFLAT], 0xffff,
+ newDevice->props[idx].havemax - newDevice->props[idx].havemin);
+
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->numAxes++) | DIDFT_ABSAXIS;
}
@@ -551,26 +553,24 @@ static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
* 'wanted' range. It also autodetects the possible range of the axis and
* adapts values accordingly.
*/
-static int
-map_axis(JoystickImpl* This, int axis, int val) {
+static int map_axis(JoystickImpl* This, int axis, int val)
+{
int hmax = This->props[axis].havemax;
int hmin = This->props[axis].havemin;
int wmin = This->props[axis].wantmin;
int wmax = This->props[axis].wantmax;
+ int deadz= This->props[axis].deadzone;
int ret;
/* map the value from the hmin-hmax range into the wmin-wmax range */
ret = MulDiv( val - hmin, wmax - wmin, hmax - hmin ) + wmin;
- TRACE("hmin=%d hmax=%d wmin=%d wmax=%d val=%d ret=%d\n", hmin, hmax, wmin, wmax, val, ret);
+ if ((ret >= -deadz / 2 ) && (ret <= deadz / 2))
+ ret = (wmax - wmin) / 2 + wmin;
+
+ TRACE("[%d] hmin=%d hmax=%d wmin=%d wmax=%d deadz=%d val=%d ret=%d\n",
+ axis, hmin, hmax, wmin, wmax, deadz, val, ret);
-#if 0
- /* deadzone doesn't work comfortably enough right now. needs more testing*/
- if ((ret > -deadz/2 ) && (ret < deadz/2)) {
- FIXME("%d in deadzone, return mid.\n",val);
- return (wmax-wmin)/2+wmin;
- }
-#endif
return ret;
}
@@ -772,6 +772,9 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
int i;
TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++) {
+ /* Scale dead-zone */
+ This->props[i].deadzone = MulDiv(This->props[i].deadzone, pr->lMax - pr->lMin,
+ This->props[i].wantmax - This->props[i].wantmin);
This->props[i].wantmin = pr->lMin;
This->props[i].wantmax = pr->lMax;
}
@@ -780,6 +783,9 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
if (obj >= 0) {
+ /* Scale dead-zone */
+ This->props[obj].deadzone = MulDiv(This->props[obj].deadzone, pr->lMax - pr->lMin,
+ This->props[obj].wantmax - This->props[obj].wantmin);
This->props[obj].wantmin = pr->lMin;
This->props[obj].wantmax = pr->lMax;
}
More information about the wine-cvs
mailing list