/Documentation/input/ff.txt

https://bitbucket.org/evzijst/gittest · Plain Text · 227 lines · 182 code · 45 blank · 0 comment · 0 complexity · f551d3e0802e3061d5088e506d597abf MD5 · raw file

  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. ----------------------------------------------------------------------------
  6. 0. Introduction
  7. ~~~~~~~~~~~~~~~
  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
  11. effects.
  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.
  18. 2. Instructions to the user
  19. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. Here are instructions on how to compile and use the driver. In fact, this
  21. driver is the normal iforce, input and evdev drivers written by Vojtech
  22. Pavlik, plus additions to support force feedback.
  23. Before you start, let me WARN you that some devices shake violently during the
  24. initialisation phase. This happens for example with my "AVB Top Shot Pegasus".
  25. To stop this annoying behaviour, move you joystick to its limits. Anyway, you
  26. should keep a hand on your device, in order to avoid it to brake down if
  27. something goes wrong.
  28. At the kernel's compilation:
  29. - Enable IForce/Serial
  30. - Enable Event interface
  31. Compile the modules, install them.
  32. You also need inputattach.
  33. You then need to insert the modules into the following order:
  34. % modprobe joydev
  35. % modprobe serport # Only for serial
  36. % modprobe iforce
  37. % modprobe evdev
  38. % ./inputattach -ifor $2 & # Only for serial
  39. If you are using USB, you don't need the inputattach step.
  40. Please check that you have all the /dev/input entries needed:
  41. cd /dev
  42. rm js*
  43. mkdir input
  44. mknod input/js0 c 13 0
  45. mknod input/js1 c 13 1
  46. mknod input/js2 c 13 2
  47. mknod input/js3 c 13 3
  48. ln -s input/js0 js0
  49. ln -s input/js1 js1
  50. ln -s input/js2 js2
  51. ln -s input/js3 js3
  52. mknod input/event0 c 13 64
  53. mknod input/event1 c 13 65
  54. mknod input/event2 c 13 66
  55. mknod input/event3 c 13 67
  56. 2.1 Does it work ?
  57. ~~~~~~~~~~~~~~~~~~
  58. There is an utility called fftest that will allow you to test the driver.
  59. % fftest /dev/input/eventXX
  60. 3. Instructions to the developper
  61. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62. All interactions are done using the event API. That is, you can use ioctl()
  63. and write() on /dev/input/eventXX.
  64. This information is subject to change.
  65. 3.1 Querying device capabilities
  66. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. #include <linux/input.h>
  68. #include <sys/ioctl.h>
  69. unsigned long features[1 + FF_MAX/sizeof(unsigned long)];
  70. int ioctl(int file_descriptor, int request, unsigned long *features);
  71. "request" must be EVIOCGBIT(EV_FF, size of features array in bytes )
  72. Returns the features supported by the device. features is a bitfield with the
  73. following bits:
  74. - FF_X has an X axis (usually joysticks)
  75. - FF_Y has an Y axis (usually joysticks)
  76. - FF_WHEEL has a wheel (usually sterring wheels)
  77. - FF_CONSTANT can render constant force effects
  78. - FF_PERIODIC can render periodic effects (sine, triangle, square...)
  79. - FF_RAMP can render ramp effects
  80. - FF_SPRING can simulate the presence of a spring
  81. - FF_FRICTION can simulate friction
  82. - FF_DAMPER can simulate damper effects
  83. - FF_RUMBLE rumble effects (normally the only effect supported by rumble
  84. pads)
  85. - FF_INERTIA can simulate inertia
  86. int ioctl(int fd, EVIOCGEFFECTS, int *n);
  87. Returns the number of effects the device can keep in its memory.
  88. 3.2 Uploading effects to the device
  89. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. #include <linux/input.h>
  91. #include <sys/ioctl.h>
  92. int ioctl(int file_descriptor, int request, struct ff_effect *effect);
  93. "request" must be EVIOCSFF.
  94. "effect" points to a structure describing the effect to upload. The effect is
  95. uploaded, but not played.
  96. The content of effect may be modified. In particular, its field "id" is set
  97. to the unique id assigned by the driver. This data is required for performing
  98. some operations (removing an effect, controlling the playback).
  99. This if field must be set to -1 by the user in order to tell the driver to
  100. allocate a new effect.
  101. See <linux/input.h> for a description of the ff_effect stuct. You should also
  102. find help in a few sketches, contained in files shape.fig and interactive.fig.
  103. You need xfig to visualize these files.
  104. 3.3 Removing an effect from the device
  105. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  106. int ioctl(int fd, EVIOCRMFF, effect.id);
  107. This makes room for new effects in the device's memory. Please note this won't
  108. stop the effect if it was playing.
  109. 3.4 Controlling the playback of effects
  110. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. Control of playing is done with write(). Below is an example:
  112. #include <linux/input.h>
  113. #include <unistd.h>
  114. struct input_event play;
  115. struct input_event stop;
  116. struct ff_effect effect;
  117. int fd;
  118. ...
  119. fd = open("/dev/input/eventXX", O_RDWR);
  120. ...
  121. /* Play three times */
  122. play.type = EV_FF;
  123. play.code = effect.id;
  124. play.value = 3;
  125. write(fd, (const void*) &play, sizeof(play));
  126. ...
  127. /* Stop an effect */
  128. stop.type = EV_FF;
  129. stop.code = effect.id;
  130. stop.value = 0;
  131. write(fd, (const void*) &play, sizeof(stop));
  132. 3.5 Setting the gain
  133. ~~~~~~~~~~~~~~~~~~~~
  134. Not all devices have the same strength. Therefore, users should set a gain
  135. factor depending on how strong they want effects to be. This setting is
  136. persistent across access to the driver, so you should not care about it if
  137. you are writing games, as another utility probably already set this for you.
  138. /* Set the gain of the device
  139. int gain; /* between 0 and 100 */
  140. struct input_event ie; /* structure used to communicate with the driver */
  141. ie.type = EV_FF;
  142. ie.code = FF_GAIN;
  143. ie.value = 0xFFFFUL * gain / 100;
  144. if (write(fd, &ie, sizeof(ie)) == -1)
  145. perror("set gain");
  146. 3.6 Enabling/Disabling autocenter
  147. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148. The autocenter feature quite disturbs the rendering of effects in my opinion,
  149. and I think it should be an effect, which computation depends on the game
  150. type. But you can enable it if you want.
  151. int autocenter; /* between 0 and 100 */
  152. struct input_event ie;
  153. ie.type = EV_FF;
  154. ie.code = FF_AUTOCENTER;
  155. ie.value = 0xFFFFUL * autocenter / 100;
  156. if (write(fd, &ie, sizeof(ie)) == -1)
  157. perror("set auto-center");
  158. A value of 0 means "no auto-center".
  159. 3.7 Dynamic update of an effect
  160. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161. Proceed as if you wanted to upload a new effect, except that instead of
  162. setting the id field to -1, you set it to the wanted effect id.
  163. Normally, the effect is not stopped and restarted. However, depending on the
  164. type of device, not all parameters can be dynamically updated. For example,
  165. the direction of an effect cannot be updated with iforce devices. In this
  166. case, the driver stops the effect, up-load it, and restart it.
  167. 3.8 Information about the status of effects
  168. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  169. Every time the status of an effect is changed, an event is sent. The values
  170. and meanings of the fields of the event are as follows:
  171. struct input_event {
  172. /* When the status of the effect changed */
  173. struct timeval time;
  174. /* Set to EV_FF_STATUS */
  175. unsigned short type;
  176. /* Contains the id of the effect */
  177. unsigned short code;
  178. /* Indicates the status */
  179. unsigned int value;
  180. };
  181. FF_STATUS_STOPPED The effect stopped playing
  182. FF_STATUS_PLAYING The effect started to play