diff options
author | Sascha Hlusiak <saschahlusiak@arcor.de> | 2007-03-30 14:25:13 -0400 |
---|---|---|
committer | Sascha Hlusiak <saschahlusiak@arcor.de> | 2007-03-30 14:25:13 -0400 |
commit | 7c709f6a8a8e234b7b7122238bd2227caeaf17c8 (patch) | |
tree | c657490d76f36bfc4d1fe1eacf58d84cf0b556bd | |
parent | 70b1bba65880c27da13b77accc6f971c5cabca95 (diff) |
Added range for absolute axis configuration
Completed man page
-rw-r--r-- | man/joystick.man | 96 | ||||
-rw-r--r-- | src/jstk.c | 38 | ||||
-rw-r--r-- | src/jstk.h | 8 | ||||
-rw-r--r-- | src/jstk_axis.c | 40 | ||||
-rw-r--r-- | src/jstk_axis.h | 1 | ||||
-rw-r--r-- | src/jstk_options.c | 8 | ||||
-rw-r--r-- | src/linux_jstk.c | 10 | ||||
-rw-r--r-- | src/linux_jstk.h | 8 |
8 files changed, 152 insertions, 57 deletions
diff --git a/man/joystick.man b/man/joystick.man index 1bdf7fe..50f3ba0 100644 --- a/man/joystick.man +++ b/man/joystick.man @@ -18,7 +18,10 @@ is an __xservername__ input driver for Linux\'s joystick devices. .SH SUPPORTED HARDWARE In general, every by the kernel supported joystick should be supported through the .B joystick -driver. See the Linux kernel documentation for a complete list. +driver. The driver assumes that the joystick is calibrated and will report axis values +between +.IR "-32768 " and " 32768" . +See the Linux kernel documentation for a complete list of supported devices. .SH CONFIGURATION DETAILS Please refer to __xconfigfile__(__filemansuffix__) for general configuration @@ -70,7 +73,7 @@ factors can be combined. .BI "\*qkey="<keycode>[,<keycode>[,<keycode>[,<keycode>]]] When button is pressed, a series of keydown events with the specified keycode is generated. When the button is released, there are keyup events in the opposite -order generated. +order generated. You can specify up to 4 keycodes per button. See special section about key events below. .TP 7 @@ -116,25 +119,94 @@ Sets the unresponsive range of the axis to .IR <number> . This can be between .IR "0" " and " "30000" . -Default: 10 - +Default: 1000 .RE + +.PP +The default configuration looks as follows: + +.nf +.BI " Option \*qMapButton1\*q \*q" button=1 \*q +.BI " Option \*qMapButton2\*q \*q" button=2 \*q +.BI " Option \*qMapButton3\*q \*q" button=3 \*q +.BI " Option \*qMapButton4\*q \*q" none \*q +\ \ ... +.BI " Option \*qMapAxis1\*q \*q" "mode=relative axis=+1x deadzone=1000" \*q +.BI " Option \*qMapAxis2\*q \*q" "mode=relative axis=+1y deadzone=1000" \*q +.BI " Option \*qMapAxis3\*q \*q" "mode=none" \*q +\ \ ... +.fi + +.SH "ACCELERATED AXIS CONFIGURATION" +.B Accelerated +mode should be selected, if the axis is a +.IR pad , +which reports only three states: negative, center, positive. It will produce a smooth acceleration of the movement +when the axis is deflected. The speed will be affected by the factor of the axis, but not the acceleration speed. + +This example will set up the axis as scrolling vertically inverted, which half of the speed: +.nf +.BI " Option \*qMapAxis1\*q \*q" "mode=accelerated axis=-0.5zy" \*q +.fi + +THis example maps four buttons to the four half axes, so you can use them like a pad. The movement will get half +the normal speed: +.nf +.BI " Option \*qMapButton1\*q \*q" "axis=+0.5x" \*q +.BI " Option \*qMapButton2\*q \*q" "axis=-0.5x" \*q +.BI " Option \*qMapButton3\*q \*q" "axis=+0.5y" \*q +.BI " Option \*qMapButton4\*q \*q" "axis=-0.5y" \*q +.fi + +.SH "ABSOLUTE AXIS CONFIGURATION" +With the +.B absolute +axis mode, the position of the cursor will be fixed to the position, according to the deflection of the axis. +This fixed position is calculated around the previous position of the cursor. You can specify the range in pixels, +the cursor can move. The default range is the +.I width +of the screen, when mapped to the x-axis and the +.I height +of the screen, when mapped to the y-axis. This mode can be combines with the other modes without problems. + +In this example the first axis gets a range from left to the right of the screen. The second axis gets a +total range of 200 pixels, 100 to the top and 100 to the bottom: +.nf +.BI " Option \*qMapAxis1\*q \*q" "mode=absolute axis=x" \*q +.BI " Option \*qMapAxis2\*q \*q" "mode=absolute axis=200y" \*q +.fi + .SH "GENERATING KEY EVENTS" -Proving a \*qkey=<keycode>[,<keycode>[...]]\*q option will generate X Events with the specified keycode. +Proving a \*qkey=<keycode>[,<keycode>[...]]\*q option will generate X Events with the specified keycodes in order, +when the joystick button is pressed. When the button is released, the keys are released in the reverse order. To lookup keycodes for KeySyms, you can use .BR "xmodmap -pk" . -You can use unused keycodes and map to a KEYSYMNAME of your choice using xmodmap(1). +You can use unused keycodes and map them to a KeySym of your choice using xmodmap(1). You can specify up to 4 +keycodes per joystick button. -Example: -To make the button perform +Examples: +.nf +.BI " Option \*qMapButton1\*q \*q" "key=64,23" \*q +.fi +will generate .I "Alt_L+Tab" -, use \*qkey=64,23\*q. For a lowercase -.I d -, use \*qkey=40\*q. +when the button is pressed. + +.nf +.BI " Option \*qMapButton1\*q \*q" "key=40" \*q +.fi +will generate a lowercase +.IR d . + +.nf +.BI " Option \*qMapButton1\*q \*q" "key=65" \*q +.fi +is for the +.IR "space " key. .SH "SEE ALSO" __xservername__(__appmansuffix__), __xconfigfile__(__filemansuffix__), xorgconfig(__appmansuffix__), Xserver(__appmansuffix__), X(__miscmansuffix__), xmodmap(1) .SH AUTHORS -Sascha Hlusiak +Sascha Hlusiak .fi Frederic Lepied (1995-1999) @@ -48,11 +48,6 @@ -/**************************************************************************** - * Forward declarations - ****************************************************************************/ - -static Bool xf86JstkProc(DeviceIntPtr pJstk, int what); int debug_level = 0; @@ -104,7 +99,7 @@ xf86JstkRead(LocalDevicePtr local) JoystickDevPtr priv = local->private; - if (xf86ReadJoystickData(priv, &event, &number)==0) { + if (jstkReadData(priv, &event, &number)==0) { xf86Msg(X_WARNING, "JOYSTICK: Read failed. Deactivating device.\n"); if (local->fd >= 0) @@ -115,7 +110,7 @@ xf86JstkRead(LocalDevicePtr local) /* A button's status changed */ if (event == EVENT_BUTTON) { DBG(4, ErrorF("Button %d %s. Mapping: %d\n", number, - (priv->button[number].value == 1)?"pressed":"released", + (priv->button[number].pressed == 0)?"released":"pressed", priv->button[number].mapping)); switch (priv->button[number].mapping) { case MAPPING_BUTTON: @@ -156,15 +151,19 @@ xf86JstkRead(LocalDevicePtr local) (priv->button[i].mapping == MAPPING_SPEED_MULTIPLY)) priv->amplify *= ((float)(priv->button[i].value)) / 1000.0; } + DBG(2, ErrorF("Global amplify is now %.3f\n", priv->amplify)); + break; case MAPPING_DISABLE: if (priv->button[number].pressed == 1) { if ((priv->mouse_enabled == TRUE) || (priv->keys_enabled == TRUE)) { priv->mouse_enabled = FALSE; priv->keys_enabled = FALSE; + DBG(2, ErrorF("All events disabled\n")); } else { priv->mouse_enabled = TRUE; priv->keys_enabled = TRUE; + DBG(2, ErrorF("All events enabled\n")); } } break; @@ -172,12 +171,14 @@ xf86JstkRead(LocalDevicePtr local) if (priv->button[number].pressed == 1) { if (priv->mouse_enabled == TRUE) priv->mouse_enabled = FALSE; else priv->mouse_enabled = TRUE; + DBG(2, ErrorF("Mouse events %s\n", priv->mouse_enabled?"enabled":"disabled")); } break; case MAPPING_DISABLE_KEYS: if (priv->button[number].pressed == 1) { if (priv->keys_enabled == TRUE) priv->keys_enabled = FALSE; else priv->keys_enabled = TRUE; + DBG(2, ErrorF("Keyboard events %s\n", priv->mouse_enabled?"enabled":"disabled")); } break; @@ -190,8 +191,9 @@ xf86JstkRead(LocalDevicePtr local) if ((event == EVENT_AXIS) && (priv->axis[number].mapping != MAPPING_NONE) && (priv->axis[number].type != TYPE_NONE)) { - DBG(5, ErrorF("Axis %d moved to %d. Mapping: %d\n", number, - priv->axis[number].value, priv->axis[number].mapping)); + DBG(5, ErrorF("Axis %d moved to %d. Type: %d, Mapping: %d\n", number, + priv->axis[number].value, priv->axis[number].type, + priv->axis[number].mapping)); switch (priv->axis[number].type) { case TYPE_BYVALUE: case TYPE_ACCELERATED: @@ -283,7 +285,7 @@ xf86JstkProc(DeviceIntPtr pJstk, break; case DEVICE_ON: - i = xf86JoystickOn(priv, FALSE); + i = jstkOpenDevice(priv, FALSE); DBG(1, ErrorF("xf86JstkProc what=ON name=%s\n", priv->device)); @@ -310,7 +312,7 @@ xf86JstkProc(DeviceIntPtr pJstk, if (local->fd >= 0) RemoveEnabledDevice(local->fd); local->fd = -1; - xf86JoystickOff(priv); + jstkCloseDevice(priv); pJstk->public.on = FALSE; break; @@ -408,10 +410,10 @@ xf86JstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags) /* Initialize default mappings */ for (i=0; i<MAXAXES; i++) { priv->axis[i].value = 0; - priv->axis[i].deadzone = 10; + priv->axis[i].deadzone = 1000; priv->axis[i].type = TYPE_BYVALUE; priv->axis[i].mapping = MAPPING_NONE; - priv->axis[i].temp = 1.0; + priv->axis[i].temp = 0.0; priv->axis[i].amplify = 1.0; } for (i=0; i<MAXBUTTONS; i++) { @@ -456,10 +458,11 @@ xf86JstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags) } xf86Msg(X_CONFIG, "%s: device is %s\n", local->name, priv->device); - if (xf86JoystickOn(priv, TRUE) == -1) { + /* Open the device once, see if it works and get information */ + if (jstkOpenDevice(priv, TRUE) == -1) { goto SetupProc_fail; } - xf86JoystickOff(priv); + jstkCloseDevice(priv); xf86ProcessCommonOptions(local, local->options); @@ -502,8 +505,8 @@ xf86JstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags) local->name, i+1, s); jstkParseAxisOption(s, &priv->axis[i], local->name); } - DBG(1, ErrorF("Axis %d type is %d, mapped to %d\n", i+1, - priv->axis[i].type, priv->axis[i].mapping)); + DBG(1, ErrorF("Axis %d type is %d, mapped to %d, amplify=%.3f\n", i+1, + priv->axis[i].type, priv->axis[i].mapping,priv->axis[i].amplify)); } /* return the LocalDevice */ @@ -580,4 +583,5 @@ _X_EXPORT XF86ModuleData joystickModuleData = { xf86JstkPlug, xf86JstkUnplug }; + #endif /* XFree86LOADER */ @@ -39,6 +39,10 @@ #define DEBUG 1 +/** + * DEBUG Makros + **/ + #if DEBUG extern int debug_level; #define DBG(lvl, f) {if ((lvl) <= debug_level) f;} @@ -48,10 +52,8 @@ extern int debug_level; - - #define MAXBUTTONS 32 -#define MAXAXES MAXBUTTONS +#define MAXAXES 32 #define MAXKEYSPERBUTTON 4 enum JOYSTICKTYPE { diff --git a/src/jstk_axis.c b/src/jstk_axis.c index 5c72427..e718e03 100644 --- a/src/jstk_axis.c +++ b/src/jstk_axis.c @@ -246,29 +246,43 @@ jstkStartButtonAxisTimer(LocalDevicePtr device, int number) { device->dev); } - void jstkHandleAbsoluteAxis(LocalDevicePtr device, int number) { JoystickDevPtr priv = device->private; - int x,y,i; - x = screenInfo.screens[0]->width / 2; - y = screenInfo.screens[0]->height / 2; + int i,x,y; + + x=0; + y=0; for (i=0; i<MAXAXES; i++) - if ((priv->axis[i].type == TYPE_ABSOLUTE)&&(priv->axis[i].value != 0)) + if ((priv->axis[i].type == TYPE_ABSOLUTE)) { float rel; + int dif; rel = (priv->axis[i].value>0)? (priv->axis[i].value - priv->axis[i].deadzone): (priv->axis[i].value + priv->axis[i].deadzone); - rel = (rel)/(2.0*(float)(32768 - priv->axis[i].deadzone)) + 0.5; - - if (priv->axis[i].mapping == MAPPING_X) - x = rel * screenInfo.screens[0]->width; - if (priv->axis[i].mapping == MAPPING_Y) - y = rel * screenInfo.screens[0]->height; + rel = (rel)/(2.0*(float)(32768 - priv->axis[i].deadzone)); + + rel *= priv->axis[i].amplify; + + DBG(5, ErrorF("Relative Position of axis %d: %.2f\n",i, rel)); + + dif = (int)(rel - priv->axis[i].temp + 0.5); + if ((dif >= 1)||(dif <= -1)) { + if (priv->axis[i].mapping == MAPPING_X) { + x += (dif); + priv->axis[i].temp += (float)dif; + } + if (priv->axis[i].mapping == MAPPING_Y) { + y += (int)(dif); + priv->axis[i].temp += (float)dif; + } + } + } + if ((x != 0) || (y != 0)) { + DBG(4, ErrorF("Moving mouse by %dx%d\n",x,y)); + xf86PostMotionEvent(device->dev, 0, 0, 2, x, y); } - DBG(3, ErrorF("Setting mouse to %dx%d\n",x,y)); - xf86PostMotionEvent(device->dev, 1, 0, 2, x, y); } diff --git a/src/jstk_axis.h b/src/jstk_axis.h index dc642e2..cb2b502 100644 --- a/src/jstk_axis.h +++ b/src/jstk_axis.h @@ -28,5 +28,4 @@ void jstkStartAxisTimer(LocalDevicePtr device, int number); void jstkStartButtonAxisTimer(LocalDevicePtr device, int number); void jstkHandleAbsoluteAxis(LocalDevicePtr device, int number); - #endif diff --git a/src/jstk_options.c b/src/jstk_options.c index 9d50894..f9dbbbb 100644 --- a/src/jstk_options.c +++ b/src/jstk_options.c @@ -36,9 +36,8 @@ static enum JOYSTICKMAPPING jstkGetAxisMapping(float *value, const char* param, const char* name) { if (sscanf(param, "%f", value)==0) { - *value = 1.0; if (param[0]=='-') - *value = -1.0; + *value *= -1.0; } if (strstr(param, "zx") != NULL) return MAPPING_ZX; @@ -155,7 +154,12 @@ jstkParseAxisOption(const char* org, struct AXIS *axis, const char *name) { if ((tmp=strstr(param, "axis=")) != NULL) { if (sscanf(tmp, "axis=%15s", p) == 1) { p[15]='\0'; + fvalue = 1.0; axis->mapping = jstkGetAxisMapping(&fvalue, p, name); + if ((axis->type == TYPE_ABSOLUTE) && ((fvalue <= 1.1)&&(fvalue >= -1.1))) { + if (axis->mapping == MAPPING_X) fvalue *= (int)screenInfo.screens[0]->width; + if (axis->mapping == MAPPING_Y) fvalue *= (int)screenInfo.screens[0]->height; + } axis->amplify = fvalue; if (axis->mapping == MAPPING_NONE) xf86Msg(X_WARNING, "%s: error parsing axis: %s.\n", diff --git a/src/linux_jstk.c b/src/linux_jstk.c index 14b253d..0de8558 100644 --- a/src/linux_jstk.c +++ b/src/linux_jstk.c @@ -49,7 +49,7 @@ */ int -xf86JoystickOn(JoystickDevPtr joystick,int init) +jstkOpenDevice(JoystickDevPtr joystick,int init) { char joy_name[128]; @@ -94,7 +94,7 @@ xf86JoystickOn(JoystickDevPtr joystick,int init) */ void -xf86JoystickOff(JoystickDevPtr joystick) +jstkCloseDevice(JoystickDevPtr joystick) { if ((joystick->fd >= 0)) { close(joystick->fd); @@ -115,9 +115,9 @@ xf86JoystickOff(JoystickDevPtr joystick) */ int -xf86ReadJoystickData(JoystickDevPtr joystick, - enum JOYSTICKEVENT *event, - int *number) +jstkReadData(JoystickDevPtr joystick, + enum JOYSTICKEVENT *event, + int *number) { struct js_event js; if (event != NULL) *event = EVENT_NONE; diff --git a/src/linux_jstk.h b/src/linux_jstk.h index f1e6eb6..191541d 100644 --- a/src/linux_jstk.h +++ b/src/linux_jstk.h @@ -25,9 +25,9 @@ #define _LINUX_JSTK_H_INCLUDED_ -int xf86JoystickOn(JoystickDevPtr joystick, int init); -void xf86JoystickOff(JoystickDevPtr joystick); -int xf86ReadJoystickData(JoystickDevPtr joystick, - enum JOYSTICKEVENT *event, int *number); +int jstkOpenDevice(JoystickDevPtr joystick, int init); +void jstkCloseDevice(JoystickDevPtr joystick); +int jstkReadData(JoystickDevPtr joystick, + enum JOYSTICKEVENT *event, int *number); #endif |