2017-04-05 08:40:14 +08:00
|
|
|
========================
|
|
|
|
Force feedback for Linux
|
|
|
|
========================
|
|
|
|
|
|
|
|
:Author: Johann Deneux <johann.deneux@gmail.com> on 2001/04/22.
|
|
|
|
:Updated: Anssi Hannula <anssi.hannula@gmail.com> on 2006/04/09.
|
|
|
|
|
2017-04-05 12:42:54 +08:00
|
|
|
You may redistribute this file. Please remember to include shape.svg and
|
|
|
|
interactive.svg as well.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Introduction
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
This document describes how to use force feedback devices under Linux. The
|
|
|
|
goal is not to support these devices as if they were simple input-only devices
|
|
|
|
(as it is already the case), but to really enable the rendering of force
|
|
|
|
effects.
|
2006-07-19 13:44:22 +08:00
|
|
|
This document only describes the force feedback part of the Linux input
|
|
|
|
interface. Please read joystick.txt and input.txt before reading further this
|
|
|
|
document.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Instructions to the user
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2006-07-19 13:44:22 +08:00
|
|
|
To enable force feedback, you have to:
|
|
|
|
|
|
|
|
1. have your kernel configured with evdev and a driver that supports your
|
|
|
|
device.
|
|
|
|
2. make sure evdev module is loaded and /dev/input/event* device files are
|
|
|
|
created.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Before you start, let me WARN you that some devices shake violently during the
|
|
|
|
initialisation phase. This happens for example with my "AVB Top Shot Pegasus".
|
2018-01-19 07:58:18 +08:00
|
|
|
To stop this annoying behaviour, move your joystick to its limits. Anyway, you
|
2006-07-19 13:44:22 +08:00
|
|
|
should keep a hand on your device, in order to avoid it to break down if
|
2005-04-17 06:20:36 +08:00
|
|
|
something goes wrong.
|
|
|
|
|
2006-07-19 13:44:22 +08:00
|
|
|
If you have a serial iforce device, you need to start inputattach. See
|
|
|
|
joystick.txt for details.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Does it work ?
|
|
|
|
--------------
|
|
|
|
|
|
|
|
There is an utility called fftest that will allow you to test the driver::
|
|
|
|
|
|
|
|
% fftest /dev/input/eventXX
|
|
|
|
|
|
|
|
Instructions to the developer
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-19 13:44:22 +08:00
|
|
|
All interactions are done using the event API. That is, you can use ioctl()
|
2005-04-17 06:20:36 +08:00
|
|
|
and write() on /dev/input/eventXX.
|
2006-07-19 13:44:22 +08:00
|
|
|
This information is subject to change.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Querying device capabilities
|
|
|
|
----------------------------
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
::
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
#include <linux/input.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#define BITS_TO_LONGS(x) \
|
|
|
|
(((x) + 8 * sizeof (unsigned long) - 1) / (8 * sizeof (unsigned long)))
|
|
|
|
unsigned long features[BITS_TO_LONGS(FF_CNT)];
|
|
|
|
int ioctl(int file_descriptor, int request, unsigned long *features);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
"request" must be EVIOCGBIT(EV_FF, size of features array in bytes )
|
|
|
|
|
|
|
|
Returns the features supported by the device. features is a bitfield with the
|
|
|
|
following bits:
|
2017-04-05 08:40:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
- FF_CONSTANT can render constant force effects
|
2006-07-19 13:44:22 +08:00
|
|
|
- FF_PERIODIC can render periodic effects with the following waveforms:
|
2017-04-05 08:40:14 +08:00
|
|
|
|
2006-07-19 13:44:22 +08:00
|
|
|
- FF_SQUARE square waveform
|
|
|
|
- FF_TRIANGLE triangle waveform
|
|
|
|
- FF_SINE sine waveform
|
|
|
|
- FF_SAW_UP sawtooth up waveform
|
|
|
|
- FF_SAW_DOWN sawtooth down waveform
|
|
|
|
- FF_CUSTOM custom waveform
|
2017-04-05 08:40:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
- FF_RAMP can render ramp effects
|
|
|
|
- FF_SPRING can simulate the presence of a spring
|
2006-07-19 13:44:22 +08:00
|
|
|
- FF_FRICTION can simulate friction
|
2005-04-17 06:20:36 +08:00
|
|
|
- FF_DAMPER can simulate damper effects
|
2006-07-19 13:44:22 +08:00
|
|
|
- FF_RUMBLE rumble effects
|
2005-04-17 06:20:36 +08:00
|
|
|
- FF_INERTIA can simulate inertia
|
2006-07-19 13:44:22 +08:00
|
|
|
- FF_GAIN gain is adjustable
|
|
|
|
- FF_AUTOCENTER autocenter is adjustable
|
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
- In most cases you should use FF_PERIODIC instead of FF_RUMBLE. All
|
2006-07-19 13:44:22 +08:00
|
|
|
devices that support FF_RUMBLE support FF_PERIODIC (square, triangle,
|
|
|
|
sine) and the other way around.
|
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
- The exact syntax FF_CUSTOM is undefined for the time being as no driver
|
2006-07-19 13:44:22 +08:00
|
|
|
supports it yet.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
::
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
int ioctl(int fd, EVIOCGEFFECTS, int *n);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Returns the number of effects the device can keep in its memory.
|
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Uploading effects to the device
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
::
|
2006-07-19 13:44:22 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
#include <linux/input.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
int ioctl(int file_descriptor, int request, struct ff_effect *effect);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
"request" must be EVIOCSFF.
|
|
|
|
|
|
|
|
"effect" points to a structure describing the effect to upload. The effect is
|
|
|
|
uploaded, but not played.
|
|
|
|
The content of effect may be modified. In particular, its field "id" is set
|
|
|
|
to the unique id assigned by the driver. This data is required for performing
|
|
|
|
some operations (removing an effect, controlling the playback).
|
2018-01-19 07:58:18 +08:00
|
|
|
The "id" field must be set to -1 by the user in order to tell the driver to
|
2005-04-17 06:20:36 +08:00
|
|
|
allocate a new effect.
|
2006-07-19 13:44:22 +08:00
|
|
|
|
|
|
|
Effects are file descriptor specific.
|
|
|
|
|
2017-05-04 03:38:20 +08:00
|
|
|
See <uapi/linux/input.h> for a description of the ff_effect struct. You
|
|
|
|
should also find help in a few sketches, contained in files shape.svg
|
|
|
|
and interactive.svg:
|
2017-04-05 12:42:54 +08:00
|
|
|
|
2017-04-11 18:01:19 +08:00
|
|
|
.. kernel-figure:: shape.svg
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 12:42:54 +08:00
|
|
|
Shape
|
|
|
|
|
2017-04-11 18:01:19 +08:00
|
|
|
.. kernel-figure:: interactive.svg
|
2017-04-05 12:42:54 +08:00
|
|
|
|
|
|
|
Interactive
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
|
|
|
|
Removing an effect from the device
|
|
|
|
----------------------------------
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
int ioctl(int fd, EVIOCRMFF, effect.id);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-19 13:44:22 +08:00
|
|
|
This makes room for new effects in the device's memory. Note that this also
|
|
|
|
stops the effect if it was playing.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Controlling the playback of effects
|
|
|
|
-----------------------------------
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Control of playing is done with write(). Below is an example:
|
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
::
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <unistd.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct input_event play;
|
|
|
|
struct input_event stop;
|
|
|
|
struct ff_effect effect;
|
|
|
|
int fd;
|
2017-04-05 08:40:14 +08:00
|
|
|
...
|
2005-04-17 06:20:36 +08:00
|
|
|
fd = open("/dev/input/eventXX", O_RDWR);
|
2017-04-05 08:40:14 +08:00
|
|
|
...
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Play three times */
|
|
|
|
play.type = EV_FF;
|
|
|
|
play.code = effect.id;
|
|
|
|
play.value = 3;
|
2006-07-19 13:44:22 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
write(fd, (const void*) &play, sizeof(play));
|
2017-04-05 08:40:14 +08:00
|
|
|
...
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Stop an effect */
|
|
|
|
stop.type = EV_FF;
|
|
|
|
stop.code = effect.id;
|
|
|
|
stop.value = 0;
|
2006-07-19 13:44:22 +08:00
|
|
|
|
2018-01-19 07:58:18 +08:00
|
|
|
write(fd, (const void*) &stop, sizeof(stop));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Setting the gain
|
|
|
|
----------------
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Not all devices have the same strength. Therefore, users should set a gain
|
|
|
|
factor depending on how strong they want effects to be. This setting is
|
2006-07-19 13:44:22 +08:00
|
|
|
persistent across access to the driver.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
::
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
/* Set the gain of the device
|
|
|
|
int gain; /* between 0 and 100 */
|
|
|
|
struct input_event ie; /* structure used to communicate with the driver */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
ie.type = EV_FF;
|
|
|
|
ie.code = FF_GAIN;
|
|
|
|
ie.value = 0xFFFFUL * gain / 100;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
if (write(fd, &ie, sizeof(ie)) == -1)
|
2005-04-17 06:20:36 +08:00
|
|
|
perror("set gain");
|
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Enabling/Disabling autocenter
|
|
|
|
-----------------------------
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
The autocenter feature quite disturbs the rendering of effects in my opinion,
|
|
|
|
and I think it should be an effect, which computation depends on the game
|
|
|
|
type. But you can enable it if you want.
|
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
::
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
int autocenter; /* between 0 and 100 */
|
|
|
|
struct input_event ie;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
ie.type = EV_FF;
|
|
|
|
ie.code = FF_AUTOCENTER;
|
|
|
|
ie.value = 0xFFFFUL * autocenter / 100;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
if (write(fd, &ie, sizeof(ie)) == -1)
|
2005-04-17 06:20:36 +08:00
|
|
|
perror("set auto-center");
|
|
|
|
|
|
|
|
A value of 0 means "no auto-center".
|
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Dynamic update of an effect
|
|
|
|
---------------------------
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Proceed as if you wanted to upload a new effect, except that instead of
|
|
|
|
setting the id field to -1, you set it to the wanted effect id.
|
|
|
|
Normally, the effect is not stopped and restarted. However, depending on the
|
|
|
|
type of device, not all parameters can be dynamically updated. For example,
|
|
|
|
the direction of an effect cannot be updated with iforce devices. In this
|
|
|
|
case, the driver stops the effect, up-load it, and restart it.
|
|
|
|
|
2006-07-19 13:44:22 +08:00
|
|
|
Therefore it is recommended to dynamically change direction while the effect
|
|
|
|
is playing only when it is ok to restart the effect with a replay count of 1.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
Information about the status of effects
|
|
|
|
---------------------------------------
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Every time the status of an effect is changed, an event is sent. The values
|
2017-04-05 08:40:14 +08:00
|
|
|
and meanings of the fields of the event are as follows::
|
2006-07-19 13:44:22 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
struct input_event {
|
|
|
|
/* When the status of the effect changed */
|
|
|
|
struct timeval time;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
/* Set to EV_FF_STATUS */
|
|
|
|
unsigned short type;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
/* Contains the id of the effect */
|
|
|
|
unsigned short code;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
/* Indicates the status */
|
|
|
|
unsigned int value;
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
FF_STATUS_STOPPED The effect stopped playing
|
|
|
|
FF_STATUS_PLAYING The effect started to play
|
2006-07-19 13:44:22 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
.. note::
|
2006-07-19 13:44:22 +08:00
|
|
|
|
2017-04-05 08:40:14 +08:00
|
|
|
- Status feedback is only supported by iforce driver. If you have
|
2006-07-19 13:44:22 +08:00
|
|
|
a really good reason to use this, please contact
|
|
|
|
linux-joystick@atrey.karlin.mff.cuni.cz or anssi.hannula@gmail.com
|
|
|
|
so that support for it can be added to the rest of the drivers.
|