]> bbs.cooldavid.org Git - net-next-2.6.git/blame - Documentation/input/ff.txt
Merge branch 'intel_idle+snb' into idle-release
[net-next-2.6.git] / Documentation / input / ff.txt
CommitLineData
1da177e4 1Force feedback for Linux.
118e78d1 2By Johann Deneux <johann.deneux@gmail.com> on 2001/04/22.
8b8277a1 3Updated by Anssi Hannula <anssi.hannula@gmail.com> on 2006/04/09.
1da177e4
LT
4You may redistribute this file. Please remember to include shape.fig and
5interactive.fig as well.
6----------------------------------------------------------------------------
7
8b8277a1 81. Introduction
1da177e4
LT
9~~~~~~~~~~~~~~~
10This document describes how to use force feedback devices under Linux. The
11goal is not to support these devices as if they were simple input-only devices
12(as it is already the case), but to really enable the rendering of force
13effects.
8b8277a1
AH
14This document only describes the force feedback part of the Linux input
15interface. Please read joystick.txt and input.txt before reading further this
16document.
1da177e4
LT
17
182. Instructions to the user
19~~~~~~~~~~~~~~~~~~~~~~~~~~~
8b8277a1
AH
20To enable force feedback, you have to:
21
221. have your kernel configured with evdev and a driver that supports your
23 device.
242. make sure evdev module is loaded and /dev/input/event* device files are
25 created.
1da177e4
LT
26
27Before you start, let me WARN you that some devices shake violently during the
28initialisation phase. This happens for example with my "AVB Top Shot Pegasus".
29To stop this annoying behaviour, move you joystick to its limits. Anyway, you
8b8277a1 30should keep a hand on your device, in order to avoid it to break down if
1da177e4
LT
31something goes wrong.
32
8b8277a1
AH
33If you have a serial iforce device, you need to start inputattach. See
34joystick.txt for details.
1da177e4
LT
35
362.1 Does it work ?
37~~~~~~~~~~~~~~~~~~
38There is an utility called fftest that will allow you to test the driver.
39% fftest /dev/input/eventXX
40
fff9289b 413. Instructions to the developer
1da177e4 42~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8b8277a1 43All interactions are done using the event API. That is, you can use ioctl()
1da177e4 44and write() on /dev/input/eventXX.
8b8277a1 45This information is subject to change.
1da177e4
LT
46
473.1 Querying device capabilities
48~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49#include <linux/input.h>
50#include <sys/ioctl.h>
51
52unsigned long features[1 + FF_MAX/sizeof(unsigned long)];
53int ioctl(int file_descriptor, int request, unsigned long *features);
54
55"request" must be EVIOCGBIT(EV_FF, size of features array in bytes )
56
57Returns the features supported by the device. features is a bitfield with the
58following bits:
1da177e4 59- FF_CONSTANT can render constant force effects
8b8277a1
AH
60- FF_PERIODIC can render periodic effects with the following waveforms:
61 - FF_SQUARE square waveform
62 - FF_TRIANGLE triangle waveform
63 - FF_SINE sine waveform
64 - FF_SAW_UP sawtooth up waveform
65 - FF_SAW_DOWN sawtooth down waveform
66 - FF_CUSTOM custom waveform
1da177e4
LT
67- FF_RAMP can render ramp effects
68- FF_SPRING can simulate the presence of a spring
8b8277a1 69- FF_FRICTION can simulate friction
1da177e4 70- FF_DAMPER can simulate damper effects
8b8277a1 71- FF_RUMBLE rumble effects
1da177e4 72- FF_INERTIA can simulate inertia
8b8277a1
AH
73- FF_GAIN gain is adjustable
74- FF_AUTOCENTER autocenter is adjustable
75
76Note: In most cases you should use FF_PERIODIC instead of FF_RUMBLE. All
77 devices that support FF_RUMBLE support FF_PERIODIC (square, triangle,
78 sine) and the other way around.
79
80Note: The exact syntax FF_CUSTOM is undefined for the time being as no driver
81 supports it yet.
1da177e4
LT
82
83
84int ioctl(int fd, EVIOCGEFFECTS, int *n);
85
86Returns the number of effects the device can keep in its memory.
87
883.2 Uploading effects to the device
89~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90#include <linux/input.h>
91#include <sys/ioctl.h>
8b8277a1 92
1da177e4
LT
93int ioctl(int file_descriptor, int request, struct ff_effect *effect);
94
95"request" must be EVIOCSFF.
96
97"effect" points to a structure describing the effect to upload. The effect is
98uploaded, but not played.
99The content of effect may be modified. In particular, its field "id" is set
100to the unique id assigned by the driver. This data is required for performing
101some operations (removing an effect, controlling the playback).
102This if field must be set to -1 by the user in order to tell the driver to
103allocate a new effect.
8b8277a1
AH
104
105Effects are file descriptor specific.
106
32357988 107See <linux/input.h> for a description of the ff_effect struct. You should also
1da177e4
LT
108find help in a few sketches, contained in files shape.fig and interactive.fig.
109You need xfig to visualize these files.
110
1113.3 Removing an effect from the device
112~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113int ioctl(int fd, EVIOCRMFF, effect.id);
114
8b8277a1
AH
115This makes room for new effects in the device's memory. Note that this also
116stops the effect if it was playing.
1da177e4
LT
117
1183.4 Controlling the playback of effects
119~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120Control of playing is done with write(). Below is an example:
121
122#include <linux/input.h>
123#include <unistd.h>
124
125 struct input_event play;
126 struct input_event stop;
127 struct ff_effect effect;
128 int fd;
129...
130 fd = open("/dev/input/eventXX", O_RDWR);
131...
132 /* Play three times */
133 play.type = EV_FF;
134 play.code = effect.id;
135 play.value = 3;
8b8277a1 136
1da177e4
LT
137 write(fd, (const void*) &play, sizeof(play));
138...
139 /* Stop an effect */
140 stop.type = EV_FF;
141 stop.code = effect.id;
142 stop.value = 0;
8b8277a1 143
1da177e4
LT
144 write(fd, (const void*) &play, sizeof(stop));
145
1463.5 Setting the gain
147~~~~~~~~~~~~~~~~~~~~
148Not all devices have the same strength. Therefore, users should set a gain
149factor depending on how strong they want effects to be. This setting is
8b8277a1 150persistent across access to the driver.
1da177e4
LT
151
152/* Set the gain of the device
153int gain; /* between 0 and 100 */
154struct input_event ie; /* structure used to communicate with the driver */
155
156ie.type = EV_FF;
157ie.code = FF_GAIN;
158ie.value = 0xFFFFUL * gain / 100;
159
160if (write(fd, &ie, sizeof(ie)) == -1)
161 perror("set gain");
162
1633.6 Enabling/Disabling autocenter
164~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165The autocenter feature quite disturbs the rendering of effects in my opinion,
166and I think it should be an effect, which computation depends on the game
167type. But you can enable it if you want.
168
169int autocenter; /* between 0 and 100 */
170struct input_event ie;
171
172ie.type = EV_FF;
173ie.code = FF_AUTOCENTER;
174ie.value = 0xFFFFUL * autocenter / 100;
175
176if (write(fd, &ie, sizeof(ie)) == -1)
177 perror("set auto-center");
178
179A value of 0 means "no auto-center".
180
1813.7 Dynamic update of an effect
182~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
183Proceed as if you wanted to upload a new effect, except that instead of
184setting the id field to -1, you set it to the wanted effect id.
185Normally, the effect is not stopped and restarted. However, depending on the
186type of device, not all parameters can be dynamically updated. For example,
187the direction of an effect cannot be updated with iforce devices. In this
188case, the driver stops the effect, up-load it, and restart it.
189
8b8277a1
AH
190Therefore it is recommended to dynamically change direction while the effect
191is playing only when it is ok to restart the effect with a replay count of 1.
1da177e4
LT
192
1933.8 Information about the status of effects
194~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195Every time the status of an effect is changed, an event is sent. The values
196and meanings of the fields of the event are as follows:
8b8277a1 197
1da177e4
LT
198struct input_event {
199/* When the status of the effect changed */
200 struct timeval time;
201
202/* Set to EV_FF_STATUS */
203 unsigned short type;
204
205/* Contains the id of the effect */
206 unsigned short code;
207
208/* Indicates the status */
209 unsigned int value;
210};
211
212FF_STATUS_STOPPED The effect stopped playing
213FF_STATUS_PLAYING The effect started to play
8b8277a1
AH
214
215NOTE: Status feedback is only supported by iforce driver. If you have
216 a really good reason to use this, please contact
217 linux-joystick@atrey.karlin.mff.cuni.cz or anssi.hannula@gmail.com
218 so that support for it can be added to the rest of the drivers.
219