1
Force feedback for Linux.
2
By Johann Deneux <deneux@ifrance.com> on 2001/04/22.
4
----------------------------------------------------------------------------
8
This document describes how to use force feedback devices under Linux. The
9
goal is not to support these devices as if they were simple input-only devices
10
(as it is already the case), but to really enable the rendering of force
12
At the moment, only I-Force devices are supported, and not officially. That
13
means I had to find out how the protocol works on my own. Of course, the
14
information I managed to grasp is far from being complete, and I can not
15
guarranty that this driver will work for you.
16
This document only describes the force feedback part of the driver for I-Force
17
devices. Please read joystick.txt before reading further this document.
19
2. Instructions to the user
20
~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
Here are instructions on how to compile and use the driver. In fact, this
22
driver is the normal iforce.o, input.o and evdev.o drivers written by Vojtech
23
Pavlik, plus additions to support force feedback.
25
Before you start, let me WARN you that some devices shake violently during the
26
initialisation phase. This happens for example with my "AVB Top Shot Pegasus".
27
To stop this annoying behaviour, move you joystick to its limits. Anyway, you
28
should keep a hand on your device, in order to avoid it to brake down if
31
At the kernel's compilation:
32
- Enable IForce/Serial
33
- Enable Event interface
35
Compile the modules, install them.
37
You also need inputattach.
39
You then need to insert the modules into the following order:
44
% ./inputattach -ifor $2 & # Only for serial
45
For convenience, you may use the shell script named "ff" available from
46
the cvs tree of the Linux Console Project at sourceforge. You can also
47
retrieve it from http://www.esil.univ-mrs.fr/~jdeneux/projects/ff/.
48
If you are using USB, you don't need the inputattach step.
50
Please check that you have all the /dev/input entries needed:
54
mknod input/js0 c 13 0
55
mknod input/js1 c 13 1
56
mknod input/js2 c 13 2
57
mknod input/js3 c 13 3
63
mknod input/event0 c 13 64
64
mknod input/event1 c 13 65
65
mknod input/event2 c 13 66
66
mknod input/event3 c 13 67
70
There is an utility called fftest that will allow you to test the driver.
71
% fftest /dev/input/eventXX
73
3. Instructions to the developper
74
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75
All interactions are done using the event API. That is, you can use ioctl()
76
and write() on /dev/input/eventXX.
77
This information is subject to change.
79
3.1 Querying device capabilities
80
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81
#include <linux/input.h>
82
#include <sys/ioctl.h>
84
int ioctl(int file_descriptor, int request, unsigned long *features);
86
"request" must be EVIOCGBIT(EV_FF, sizeof(unsigned long))
88
Returns the features supported by the device. features is a bitfield with the
90
- FF_X has an X axis (should allways be the case)
91
- FF_Y has an Y axis (usually not the case for wheels)
92
- FF_CONSTANT can render constant force effects
93
- FF_PERIODIC can render periodic effects (sine, ramp, square...)
94
- FF_SPRING can simulate the presence of a spring
95
- FF_FRICTION can simulate friction (aka drag, damper effect...)
96
- FF_RUMBLE rumble effects (normally the only effect supported by rumble
98
- 8 bits from FF_N_EFFECTS_0 containing the number of effects that can be
99
simultaneously played.
101
3.2 Uploading effects to the device
102
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103
#include <linux/input.h>
104
#include <sys/ioctl.h>
106
int ioctl(int file_descriptor, int request, struct ff_effect *effect);
108
"request" must be EVIOCSFF.
110
"effect" points to a structure describing the effect to upload. The effect is
111
uploaded, but not played.
112
The content of effect may be modified. In particular, its field "id" is set
113
to the unique id assigned by the driver. This data is required for performing
114
some operations (removing an effect, controlling the playback).
115
This if field must be set to -1 by the user in order to tell the driver to
116
allocate a new effect.
117
See <linux/input.h> for a description of the ff_effect stuct.
119
3.3 Removing an effect from the device
120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121
int ioctl(int fd, EVIOCRMFF, effect.id);
123
This makes room for new effects in the device's memory. Please note this won't
124
stop the effect if it was playing.
126
3.4 Controlling the playback of effects
127
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128
Control of playing is done with write(). Below is an example:
130
#include <linux/input.h>
133
struct input_event play;
134
struct input_event stop;
135
struct ff_effect effect;
138
fd = open("/dev/input/eventXX", O_RDWR);
140
/* Play three times */
142
play.code = effect.id;
145
write(fd, (const void*) &play, sizeof(play));
149
stop.code = effect.id;
152
write(fd, (const void*) &play, sizeof(stop));
156
Not all devices have the same strength. Therefore, users should set a gain
157
factor depending on how strong they want effects to be. This setting is
158
persistent accross access to the driver, so you should not care about it if
159
you are writing games, as another utility probably already set this for you.
161
/* Set the gain of the device
162
int gain; /* between 0 and 100 */
163
struct input_event ie; /* structure used to communicate with the driver */
167
ie.value = 0xFFFFUL * gain / 100;
169
if (write(fd, &ie, sizeof(ie)) == -1)
172
3.6 Enabling/Disabling autocenter
173
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174
The autocenter feature quite disturbs the rendering of effects in my opinion,
175
and I think it should be an effect, which computation depends on the game
176
type. But you can enable it if you want.
178
int autocenter; /* between 0 and 100 */
179
struct input_event ie;
182
ie.code = FF_AUTOCENTER;
183
ie.value = 0xFFFFUL * autocenter / 100;
185
if (write(fd, &ie, sizeof(ie)) == -1)
186
perror("set auto-center");
188
A value of 0 means "no auto-center".
190
3.7 Dynamic update of an effect
191
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
192
Proceed as if you wanted to upload a new effect, except that instead of
193
setting the id field to -1, you set it to the wanted effect id.
194
If you update very often, some device may stop playing effects. The driver
195
checks that, and re-start the updated effect if necessary. However, this
196
prevents effects from being palyed smoothly.
198
3.8 Information about the status of effects
199
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200
Every time the status of an effect is changed, an event is sent. The values
201
and meanings of the fields of the event are as follows:
203
/* When the status of the effect changed */
206
/* Set to EV_FF_STATUS */
209
/* Contains the id of the effect */
212
/* Indicates the status */
216
FF_STATUS_STOPPED The effect stopped playing
217
FF_STATUS_PLAYING The effect started to play