⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ff.txt

📁 嵌入式系统设计与实验教材二源码linux内核移植与编译
💻 TXT
字号:
Force feedback for Linux.By Johann Deneux <deneux@ifrance.com> on 2001/04/22.----------------------------------------------------------------------------0. Introduction~~~~~~~~~~~~~~~This document describes how to use force feedback devices under Linux. Thegoal is not to support these devices as if they were simple input-only devices(as it is already the case), but to really enable the rendering of forceeffects.At the moment, only I-Force devices are supported, and not officially. Thatmeans I had to find out how the protocol works on my own. Of course, theinformation I managed to grasp is far from being complete, and I can notguarranty that this driver will work for you.This document only describes the force feedback part of the driver for I-Forcedevices. Please read joystick.txt before reading further this document.2. Instructions to the user~~~~~~~~~~~~~~~~~~~~~~~~~~~Here are instructions on how to compile and use the driver. In fact, thisdriver is the normal iforce.o, input.o and evdev.o drivers written by VojtechPavlik, plus additions to support force feedback.Before you start, let me WARN you that some devices shake violently during theinitialisation phase. This happens for example with my "AVB Top Shot Pegasus".To stop this annoying behaviour, move you joystick to its limits. Anyway, youshould keep a hand on your device, in order to avoid it to brake down ifsomething goes wrong.At the kernel's compilation:	- Enable IForce/Serial	- Enable Event interfaceCompile the modules, install them.You also need inputattach.You then need to insert the modules into the following order:% modprobe joydev% modprobe serport% modprobe iforce% modprobe evdev% ./inputattach -ifor $2 &	# Only for serialFor convenience, you may use the shell script named "ff" available fromthe cvs tree of the Linux Console Project at sourceforge. You can alsoretrieve it from http://www.esil.univ-mrs.fr/~jdeneux/projects/ff/.If you are using USB, you don't need the inputattach step.Please check that you have all the /dev/input entries needed:cd /devrm js*mkdir inputmknod input/js0 c 13 0mknod input/js1 c 13 1mknod input/js2 c 13 2mknod input/js3 c 13 3ln -s input/js0 js0ln -s input/js1 js1ln -s input/js2 js2ln -s input/js3 js3mknod input/event0 c 13 64mknod input/event1 c 13 65mknod input/event2 c 13 66mknod input/event3 c 13 672.1 Does it work ?~~~~~~~~~~~~~~~~~~There is an utility called fftest that will allow you to test the driver.% fftest /dev/eventXX3. Instructions to the developper~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  All interactions are done using the event API. That is, you can use ioctl()and write() on /dev/input/eventXX.  This information is subject to change.3.1 Querying device capabilities~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#include <linux/input.h>#include <sys/ioctl.h>int ioctl(int file_descriptor, int request, unsigned long *features);"request" must be EVIOCGBIT(EV_FF, sizeof(unsigned long))Returns the features supported by the device. features is a bitfield with thefollowing bits:- FF_X		has an X axis (should allways be the case)- FF_Y		has an Y axis (usually not the case for wheels)- FF_CONSTANT	can render constant force effects- FF_PERIODIC	can render periodic effects (sine, ramp, square...)- FF_SPRING	can simulate the presence of a spring- FF_FRICTION	can simulate friction (aka drag, damper effect...)- FF_RUMBLE	rumble effects (normally the only effect supported by rumble		pads)- 8 bits from FF_N_EFFECTS_0 containing the number of effects that can be		simultaneously played.3.2 Uploading effects to the device~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#include <linux/input.h>#include <sys/ioctl.h> int ioctl(int file_descriptor, int request, struct ff_effect *effect);"request" must be EVIOCSFF."effect" points to a structure describing the effect to upload. The effect isuploaded, but not played.The content of effect may be modified. In particular, its field "id" is setto the unique id assigned by the driver. This data is required for performingsome operations (removing an effect, controlling the playback).See <linux/input.h> for a description of the ff_effect stuct.3.3 Removing an effect from the device~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~int ioctl(int fd, EVIOCRMFF, effect.id);This makes room for new effects in the device's memory. Please note this won'tstop the effect if it was playing.3.4 Controlling the playback of effects~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Control of playing is done with write(). Below is an example:#include <linux/input.h>#include <unistd.h>	struct input_event play;	struct input_event stop;	struct ff_effect effect;	int fd;...	fd = open("/dev/input/eventXX", O_RDWR);...	/* Play three times */	play.type = EV_FF;	play.code = effect.id;	play.value = 3;		write(fd, (const void*) &play, sizeof(play));...	/* Stop an effect */	stop.type = EV_FF;	stop.code = effect.id;	stop.value = 0;		write(fd, (const void*) &play, sizeof(stop));3.5 Setting the gain~~~~~~~~~~~~~~~~~~~~Not all devices have the same strength. Therefore, users should set a gainfactor depending on how strong they want effects to be. This setting ispersistent accross access to the driver, so you should not care about it ifyou are writing games, as another utility probably already set this for you./* Set the gain of the deviceint gain;		/* between 0 and 100 */struct input_event ie;	/* structure used to communicate with the driver */ie.type = EV_FF;ie.code = FF_GAIN;ie.value = 0xFFFFUL * gain / 100;if (write(fd, &ie, sizeof(ie)) == -1)	perror("set gain");3.6 Enabling/Disabling autocenter~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The autocenter feature quite disturbs the rendering of effects in my opinion,and I think it should be an effect, which computation depends on the gametype. But you can enable it if you want.int autocenter;		/* between 0 and 100 */struct input_event ie;ie.type = EV_FF;ie.code = FF_AUTOCENTER;ie.value = 0xFFFFUL * autocenter / 100;if (write(fd, &ie, sizeof(ie)) == -1)	perror("set auto-center");A value of 0 means "no auto-center".3.7 Dynamic update of an effect~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~This consists in changing some parameters of an effect while it's playing. Thedriver currently does not support that. You still have the brute-force method,which consists in erasing the effect and uploading the updated version. Itactually works pretty well. You don't need to stop-and-start the effect.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -