1 Force feedback for Linux.
2 By Johann Deneux <deneux@ifrance.com> on 2001/04/22.
3 You may redistribute this file. Please remember to include shape.fig and
4 interactive.fig as well.
5 ----------------------------------------------------------------------------
9 This document describes how to use force feedback devices under Linux. The
10 goal is not to support these devices as if they were simple input-only devices
11 (as it is already the case), but to really enable the rendering of force
13 At the moment, only I-Force devices are supported, and not officially. That
14 means I had to find out how the protocol works on my own. Of course, the
15 information I managed to grasp is far from being complete, and I can not
16 guarranty that this driver will work for you.
17 This document only describes the force feedback part of the driver for I-Force
18 devices. Please read joystick.txt before reading further this document.
20 2. Instructions to the user
21 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 Here are instructions on how to compile and use the driver. In fact, this
23 driver is the normal iforce, input and evdev drivers written by Vojtech
24 Pavlik, plus additions to support force feedback.
26 Before you start, let me WARN you that some devices shake violently during the
27 initialisation phase. This happens for example with my "AVB Top Shot Pegasus".
28 To stop this annoying behaviour, move you joystick to its limits. Anyway, you
29 should keep a hand on your device, in order to avoid it to brake down if
32 At the kernel's compilation:
33 - Enable IForce/Serial
34 - Enable Event interface
36 Compile the modules, install them.
38 You also need inputattach.
40 You then need to insert the modules into the following order:
42 % modprobe serport # Only for serial
45 % ./inputattach -ifor $2 & # Only for serial
46 If you are using USB, you don't need the inputattach step.
48 Please check that you have all the /dev/input entries needed:
52 mknod input/js0 c 13 0
53 mknod input/js1 c 13 1
54 mknod input/js2 c 13 2
55 mknod input/js3 c 13 3
61 mknod input/event0 c 13 64
62 mknod input/event1 c 13 65
63 mknod input/event2 c 13 66
64 mknod input/event3 c 13 67
68 There is an utility called fftest that will allow you to test the driver.
69 % fftest /dev/input/eventXX
71 3. Instructions to the developper
72 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73 All interactions are done using the event API. That is, you can use ioctl()
74 and write() on /dev/input/eventXX.
75 This information is subject to change.
77 3.1 Querying device capabilities
78 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79 #include <linux/input.h>
80 #include <sys/ioctl.h>
82 unsigned long features[1 + FF_MAX/sizeof(unsigned long)];
83 int ioctl(int file_descriptor, int request, unsigned long *features);
85 "request" must be EVIOCGBIT(EV_FF, size of features array in bytes )
87 Returns the features supported by the device. features is a bitfield with the
89 - FF_X has an X axis (usually joysticks)
90 - FF_Y has an Y axis (usually joysticks)
91 - FF_WHEEL has a wheel (usually sterring wheels)
92 - FF_CONSTANT can render constant force effects
93 - FF_PERIODIC can render periodic effects (sine, triangle, square...)
94 - FF_RAMP can render ramp effects
95 - FF_SPRING can simulate the presence of a spring
96 - FF_FRICTION can simulate friction
97 - FF_DAMPER can simulate damper effects
98 - FF_RUMBLE rumble effects (normally the only effect supported by rumble
100 - FF_INERTIA can simulate inertia
103 int ioctl(int fd, EVIOCGEFFECTS, int *n);
105 Returns the number of effects the device can keep in its memory.
107 3.2 Uploading effects to the device
108 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109 #include <linux/input.h>
110 #include <sys/ioctl.h>
112 int ioctl(int file_descriptor, int request, struct ff_effect *effect);
114 "request" must be EVIOCSFF.
116 "effect" points to a structure describing the effect to upload. The effect is
117 uploaded, but not played.
118 The content of effect may be modified. In particular, its field "id" is set
119 to the unique id assigned by the driver. This data is required for performing
120 some operations (removing an effect, controlling the playback).
121 This if field must be set to -1 by the user in order to tell the driver to
122 allocate a new effect.
123 See <linux/input.h> for a description of the ff_effect struct. You should also
124 find help in a few sketches, contained in files shape.fig and interactive.fig.
125 You need xfig to visualize these files.
127 3.3 Removing an effect from the device
128 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129 int ioctl(int fd, EVIOCRMFF, effect.id);
131 This makes room for new effects in the device's memory. Please note this won't
132 stop the effect if it was playing.
134 3.4 Controlling the playback of effects
135 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136 Control of playing is done with write(). Below is an example:
138 #include <linux/input.h>
141 struct input_event play;
142 struct input_event stop;
143 struct ff_effect effect;
146 fd = open("/dev/input/eventXX", O_RDWR);
148 /* Play three times */
150 play.code = effect.id;
153 write(fd, (const void*) &play, sizeof(play));
157 stop.code = effect.id;
160 write(fd, (const void*) &play, sizeof(stop));
164 Not all devices have the same strength. Therefore, users should set a gain
165 factor depending on how strong they want effects to be. This setting is
166 persistent across access to the driver, so you should not care about it if
167 you are writing games, as another utility probably already set this for you.
169 /* Set the gain of the device
170 int gain; /* between 0 and 100 */
171 struct input_event ie; /* structure used to communicate with the driver */
175 ie.value = 0xFFFFUL * gain / 100;
177 if (write(fd, &ie, sizeof(ie)) == -1)
180 3.6 Enabling/Disabling autocenter
181 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182 The autocenter feature quite disturbs the rendering of effects in my opinion,
183 and I think it should be an effect, which computation depends on the game
184 type. But you can enable it if you want.
186 int autocenter; /* between 0 and 100 */
187 struct input_event ie;
190 ie.code = FF_AUTOCENTER;
191 ie.value = 0xFFFFUL * autocenter / 100;
193 if (write(fd, &ie, sizeof(ie)) == -1)
194 perror("set auto-center");
196 A value of 0 means "no auto-center".
198 3.7 Dynamic update of an effect
199 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200 Proceed as if you wanted to upload a new effect, except that instead of
201 setting the id field to -1, you set it to the wanted effect id.
202 Normally, the effect is not stopped and restarted. However, depending on the
203 type of device, not all parameters can be dynamically updated. For example,
204 the direction of an effect cannot be updated with iforce devices. In this
205 case, the driver stops the effect, up-load it, and restart it.
208 3.8 Information about the status of effects
209 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210 Every time the status of an effect is changed, an event is sent. The values
211 and meanings of the fields of the event are as follows:
213 /* When the status of the effect changed */
216 /* Set to EV_FF_STATUS */
219 /* Contains the id of the effect */
222 /* Indicates the status */
226 FF_STATUS_STOPPED The effect stopped playing
227 FF_STATUS_PLAYING The effect started to play