~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/input/ff.rst

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/input/ff.rst (Version linux-6.11.5) and /Documentation/input/ff.rst (Version linux-4.10.17)


  1 ========================                          
  2 Force feedback for Linux                          
  3 ========================                          
  4                                                   
  5 :Author: Johann Deneux <johann.deneux@gmail.com    
  6 :Updated: Anssi Hannula <anssi.hannula@gmail.co    
  7                                                   
  8 You may redistribute this file. Please remembe    
  9 interactive.svg as well.                          
 10                                                   
 11 Introduction                                      
 12 ~~~~~~~~~~~~                                      
 13                                                   
 14 This document describes how to use force feedb    
 15 goal is not to support these devices as if the    
 16 (as it is already the case), but to really ena    
 17 effects.                                          
 18 This document only describes the force feedbac    
 19 interface. Please read joydev/joystick.rst and    
 20 this document.                                    
 21                                                   
 22 Instructions to the user                          
 23 ~~~~~~~~~~~~~~~~~~~~~~~~                          
 24                                                   
 25 To enable force feedback, you have to:            
 26                                                   
 27 1. have your kernel configured with evdev and     
 28    device.                                        
 29 2. make sure evdev module is loaded and /dev/i    
 30    created.                                       
 31                                                   
 32 Before you start, let me WARN you that some de    
 33 initialisation phase. This happens for example    
 34 To stop this annoying behaviour, move your joy    
 35 should keep a hand on your device, in order to    
 36 something goes wrong.                             
 37                                                   
 38 If you have a serial iforce device, you need t    
 39 joydev/joystick.rst for details.                  
 40                                                   
 41 Does it work ?                                    
 42 --------------                                    
 43                                                   
 44 There is an utility called fftest that will al    
 45                                                   
 46     % fftest /dev/input/eventXX                   
 47                                                   
 48 Instructions to the developer                     
 49 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                     
 50                                                   
 51 All interactions are done using the event API.    
 52 and write() on /dev/input/eventXX.                
 53 This information is subject to change.            
 54                                                   
 55 Querying device capabilities                      
 56 ----------------------------                      
 57                                                   
 58 ::                                                
 59                                                   
 60     #include <linux/input.h>                      
 61     #include <sys/ioctl.h>                        
 62                                                   
 63     #define BITS_TO_LONGS(x) \                    
 64             (((x) + 8 * sizeof (unsigned long)    
 65     unsigned long features[BITS_TO_LONGS(FF_CN    
 66     int ioctl(int file_descriptor, int request    
 67                                                   
 68 "request" must be EVIOCGBIT(EV_FF, size of fea    
 69                                                   
 70 Returns the features supported by the device.     
 71 following bits:                                   
 72                                                   
 73 - FF_CONSTANT   can render constant force effe    
 74 - FF_PERIODIC   can render periodic effects wi    
 75                                                   
 76   - FF_SQUARE     square waveform                 
 77   - FF_TRIANGLE   triangle waveform               
 78   - FF_SINE       sine waveform                   
 79   - FF_SAW_UP     sawtooth up waveform            
 80   - FF_SAW_DOWN   sawtooth down waveform          
 81   - FF_CUSTOM     custom waveform                 
 82                                                   
 83 - FF_RAMP       can render ramp effects           
 84 - FF_SPRING     can simulate the presence of a    
 85 - FF_FRICTION   can simulate friction             
 86 - FF_DAMPER     can simulate damper effects       
 87 - FF_RUMBLE     rumble effects                    
 88 - FF_INERTIA    can simulate inertia              
 89 - FF_GAIN       gain is adjustable                
 90 - FF_AUTOCENTER autocenter is adjustable          
 91                                                   
 92 .. note::                                         
 93                                                   
 94     - In most cases you should use FF_PERIODIC    
 95       devices that support FF_RUMBLE support F    
 96       sine) and the other way around.             
 97                                                   
 98     - The exact syntax FF_CUSTOM is undefined     
 99       supports it yet.                            
100                                                   
101 ::                                                
102                                                   
103     int ioctl(int fd, EVIOCGEFFECTS, int *n);     
104                                                   
105 Returns the number of effects the device can k    
106                                                   
107 Uploading effects to the device                   
108 -------------------------------                   
109                                                   
110 ::                                                
111                                                   
112     #include <linux/input.h>                      
113     #include <sys/ioctl.h>                        
114                                                   
115     int ioctl(int file_descriptor, int request    
116                                                   
117 "request" must be EVIOCSFF.                       
118                                                   
119 "effect" points to a structure describing the     
120 uploaded, but not played.                         
121 The content of effect may be modified. In part    
122 to the unique id assigned by the driver. This     
123 some operations (removing an effect, controlli    
124 The "id" field must be set to -1 by the user i    
125 allocate a new effect.                            
126                                                   
127 Effects are file descriptor specific.             
128                                                   
129 See <uapi/linux/input.h> for a description of     
130 should also find help in a few sketches, conta    
131 and interactive.svg:                              
132                                                   
133 .. kernel-figure:: shape.svg                      
134                                                   
135     Shape                                         
136                                                   
137 .. kernel-figure:: interactive.svg                
138                                                   
139     Interactive                                   
140                                                   
141                                                   
142 Removing an effect from the device                
143 ----------------------------------                
144                                                   
145 ::                                                
146                                                   
147     int ioctl(int fd, EVIOCRMFF, effect.id);      
148                                                   
149 This makes room for new effects in the device'    
150 stops the effect if it was playing.               
151                                                   
152 Controlling the playback of effects               
153 -----------------------------------               
154                                                   
155 Control of playing is done with write(). Below    
156                                                   
157 ::                                                
158                                                   
159     #include <linux/input.h>                      
160     #include <unistd.h>                           
161                                                   
162         struct input_event play;                  
163         struct input_event stop;                  
164         struct ff_effect effect;                  
165         int fd;                                   
166    ...                                            
167         fd = open("/dev/input/eventXX", O_RDWR    
168    ...                                            
169         /* Play three times */                    
170         play.type = EV_FF;                        
171         play.code = effect.id;                    
172         play.value = 3;                           
173                                                   
174         write(fd, (const void*) &play, sizeof(    
175    ...                                            
176         /* Stop an effect */                      
177         stop.type = EV_FF;                        
178         stop.code = effect.id;                    
179         stop.value = 0;                           
180                                                   
181         write(fd, (const void*) &stop, sizeof(    
182                                                   
183 Setting the gain                                  
184 ----------------                                  
185                                                   
186 Not all devices have the same strength. Theref    
187 factor depending on how strong they want effec    
188 persistent across access to the driver.           
189                                                   
190 ::                                                
191                                                   
192     /* Set the gain of the device                 
193     int gain;           /* between 0 and 100 *    
194     struct input_event ie;      /* structure u    
195                                                   
196     ie.type = EV_FF;                              
197     ie.code = FF_GAIN;                            
198     ie.value = 0xFFFFUL * gain / 100;             
199                                                   
200     if (write(fd, &ie, sizeof(ie)) == -1)         
201         perror("set gain");                       
202                                                   
203 Enabling/Disabling autocenter                     
204 -----------------------------                     
205                                                   
206 The autocenter feature quite disturbs the rend    
207 and I think it should be an effect, which comp    
208 type. But you can enable it if you want.          
209                                                   
210 ::                                                
211                                                   
212     int autocenter;             /* between 0 a    
213     struct input_event ie;                        
214                                                   
215     ie.type = EV_FF;                              
216     ie.code = FF_AUTOCENTER;                      
217     ie.value = 0xFFFFUL * autocenter / 100;       
218                                                   
219     if (write(fd, &ie, sizeof(ie)) == -1)         
220         perror("set auto-center");                
221                                                   
222 A value of 0 means "no auto-center".              
223                                                   
224 Dynamic update of an effect                       
225 ---------------------------                       
226                                                   
227 Proceed as if you wanted to upload a new effec    
228 setting the id field to -1, you set it to the     
229 Normally, the effect is not stopped and restar    
230 type of device, not all parameters can be dyna    
231 the direction of an effect cannot be updated w    
232 case, the driver stops the effect, up-load it,    
233                                                   
234 Therefore it is recommended to dynamically cha    
235 is playing only when it is ok to restart the e    
236                                                   
237 Information about the status of effects           
238 ---------------------------------------           
239                                                   
240 Every time the status of an effect is changed,    
241 and meanings of the fields of the event are as    
242                                                   
243     struct input_event {                          
244     /* When the status of the effect changed *    
245             struct timeval time;                  
246                                                   
247     /* Set to EV_FF_STATUS */                     
248             unsigned short type;                  
249                                                   
250     /* Contains the id of the effect */           
251             unsigned short code;                  
252                                                   
253     /* Indicates the status */                    
254             unsigned int value;                   
255     };                                            
256                                                   
257     FF_STATUS_STOPPED   The effect stopped pla    
258     FF_STATUS_PLAYING   The effect started to     
259                                                   
260 .. note::                                         
261                                                   
262     - Status feedback is only supported by ifo    
263       a really good reason to use this, please    
264       linux-joystick@atrey.karlin.mff.cuni.cz     
265       so that support for it can be added to t    
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php