87
84
printf("Device %s opened\n", device_file_name);
90
if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features) < 0) {
91
perror("Ioctl query");
95
printf("Axes query: ");
97
if (test_bit(ABS_X, features)) printf("Axis X ");
98
if (test_bit(ABS_Y, features)) printf("Axis Y ");
99
if (test_bit(ABS_WHEEL, features)) printf("Wheel ");
101
printf("\nEffects: ");
103
if (test_bit(FF_CONSTANT, features)) printf("Constant ");
104
if (test_bit(FF_PERIODIC, features)) printf("Periodic ");
105
if (test_bit(FF_SPRING, features)) printf("Spring ");
106
if (test_bit(FF_FRICTION, features)) printf("Friction ");
107
if (test_bit(FF_RUMBLE, features)) printf("Rumble ");
109
printf("\nNumber of simultaneous effects: ");
111
if (ioctl(fd, EVIOCGEFFECTS, &n_effects) < 0) {
87
printf("Features:\n");
90
memset(absFeatures, 0, sizeof(absFeatures)*sizeof(unsigned char));
91
if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absFeatures)*sizeof(unsigned char)), absFeatures) == -1) {
92
perror("Ioctl absolute axes features query");
96
printf(" * Absolute axes: ");
98
if (testBit(ABS_X, absFeatures)) printf("X, ");
99
if (testBit(ABS_Y, absFeatures)) printf("Y, ");
100
if (testBit(ABS_Z, absFeatures)) printf("Z, ");
101
if (testBit(ABS_RX, absFeatures)) printf("RX, ");
102
if (testBit(ABS_RY, absFeatures)) printf("RY, ");
103
if (testBit(ABS_RZ, absFeatures)) printf("RZ, ");
104
if (testBit(ABS_THROTTLE, absFeatures)) printf("Throttle, ");
105
if (testBit(ABS_RUDDER, absFeatures)) printf("Rudder, ");
106
if (testBit(ABS_WHEEL, absFeatures)) printf("Wheel, ");
107
if (testBit(ABS_GAS, absFeatures)) printf("Gas, ");
108
if (testBit(ABS_BRAKE, absFeatures)) printf("Brake, ");
109
if (testBit(ABS_HAT0X, absFeatures)) printf("Hat 0 X, ");
110
if (testBit(ABS_HAT0Y, absFeatures)) printf("Hat 0 Y, ");
111
if (testBit(ABS_HAT1X, absFeatures)) printf("Hat 1 X, ");
112
if (testBit(ABS_HAT1Y, absFeatures)) printf("Hat 1 Y, ");
113
if (testBit(ABS_HAT2X, absFeatures)) printf("Hat 2 X, ");
114
if (testBit(ABS_HAT2Y, absFeatures)) printf("Hat 2 Y, ");
115
if (testBit(ABS_HAT3X, absFeatures)) printf("Hat 3 X, ");
116
if (testBit(ABS_HAT3Y, absFeatures)) printf("Hat 3 Y, ");
117
if (testBit(ABS_PRESSURE, absFeatures)) printf("Pressure, ");
118
if (testBit(ABS_DISTANCE, absFeatures)) printf("Distance, ");
119
if (testBit(ABS_TILT_X, absFeatures)) printf("Tilt X, ");
120
if (testBit(ABS_TILT_Y, absFeatures)) printf("Tilt Y, ");
121
if (testBit(ABS_TOOL_WIDTH, absFeatures)) printf("Tool width, ");
122
if (testBit(ABS_VOLUME, absFeatures)) printf("Volume, ");
123
if (testBit(ABS_MISC, absFeatures)) printf("Misc ,");
126
for (i=0; i<sizeof(absFeatures)/sizeof(unsigned char);i++)
127
printf("%02X ", absFeatures[i]);
131
memset(relFeatures, 0, sizeof(relFeatures)*sizeof(unsigned char));
132
if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relFeatures)*sizeof(unsigned char)), relFeatures) == -1) {
133
perror("Ioctl relative axes features query");
137
printf(" * Relative axes: ");
139
if (testBit(REL_X, relFeatures)) printf("X, ");
140
if (testBit(REL_Y, relFeatures)) printf("Y, ");
141
if (testBit(REL_Z, relFeatures)) printf("Z, ");
142
if (testBit(REL_RX, relFeatures)) printf("RX, ");
143
if (testBit(REL_RY, relFeatures)) printf("RY, ");
144
if (testBit(REL_RZ, relFeatures)) printf("RZ, ");
145
if (testBit(REL_HWHEEL, relFeatures)) printf("HWheel, ");
146
if (testBit(REL_DIAL, relFeatures)) printf("Dial, ");
147
if (testBit(REL_WHEEL, relFeatures)) printf("Wheel, ");
148
if (testBit(REL_MISC, relFeatures)) printf("Misc, ");
151
for (i=0; i<sizeof(relFeatures)/sizeof(unsigned char);i++)
152
printf("%02X ", relFeatures[i]);
155
/* Force feedback effects */
156
memset(ffFeatures, 0, sizeof(ffFeatures)*sizeof(unsigned char));
157
if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(ffFeatures)*sizeof(unsigned char)), ffFeatures) == -1) {
158
perror("Ioctl force feedback features query");
162
printf(" * Force feedback effects types: ");
164
if (testBit(FF_CONSTANT, ffFeatures)) printf("Constant, ");
165
if (testBit(FF_PERIODIC, ffFeatures)) printf("Periodic, ");
166
if (testBit(FF_RAMP, ffFeatures)) printf("Ramp, ");
167
if (testBit(FF_SPRING, ffFeatures)) printf("Spring, ");
168
if (testBit(FF_FRICTION, ffFeatures)) printf("Friction, ");
169
if (testBit(FF_DAMPER, ffFeatures)) printf("Damper, ");
170
if (testBit(FF_RUMBLE, ffFeatures)) printf("Rumble, ");
171
if (testBit(FF_INERTIA, ffFeatures)) printf("Inertia, ");
172
if (testBit(FF_GAIN, ffFeatures)) printf("Gain, ");
173
if (testBit(FF_AUTOCENTER, ffFeatures)) printf("Autocenter, ");
175
printf("\n Force feedback periodic effects: ");
177
if (testBit(FF_SQUARE, ffFeatures)) printf("Square, ");
178
if (testBit(FF_TRIANGLE, ffFeatures)) printf("Triangle, ");
179
if (testBit(FF_SINE, ffFeatures)) printf("Sine, ");
180
if (testBit(FF_SAW_UP, ffFeatures)) printf("Saw up, ");
181
if (testBit(FF_SAW_DOWN, ffFeatures)) printf("Saw down, ");
182
if (testBit(FF_CUSTOM, ffFeatures)) printf("Custom, ");
185
for (i=0; i<sizeof(ffFeatures)/sizeof(unsigned char);i++)
186
printf("%02X ", ffFeatures[i]);
189
printf(" * Number of simultaneous effects: ");
191
if (ioctl(fd, EVIOCGEFFECTS, &n_effects) == -1) {
112
192
perror("Ioctl number of effects");
115
printf("%d\n", n_effects);
195
printf("%d\n\n", n_effects);
197
/* Set master gain to 75% if supported */
198
if (testBit(FF_GAIN, ffFeatures)) {
199
memset(&gain, 0, sizeof(gain));
202
gain.value = 0xC000; /* [0, 0xFFFF]) */
204
printf("Setting master gain to 75%% ... ");
206
if (write(fd, &gain, sizeof(gain)) != sizeof(gain)) {
117
213
/* download a periodic sinusoidal effect */
214
memset(&effects[0],0,sizeof(effects[0]));
118
215
effects[0].type = FF_PERIODIC;
119
216
effects[0].id = -1;
120
217
effects[0].u.periodic.waveform = FF_SINE;
121
effects[0].u.periodic.period = 0.1*0x100; /* 0.1 second */
122
effects[0].u.periodic.magnitude = 0x4000; /* 0.5 * Maximum magnitude */
218
effects[0].u.periodic.period = 10; /* 0.1 second */
219
effects[0].u.periodic.magnitude = 0x7fff; /* 0.5 * Maximum magnitude */
123
220
effects[0].u.periodic.offset = 0;
124
221
effects[0].u.periodic.phase = 0;
125
222
effects[0].direction = 0x4000; /* Along X axis */
126
effects[0].u.periodic.envelope.attack_length = 0x100;
127
effects[0].u.periodic.envelope.attack_level = 0;
128
effects[0].u.periodic.envelope.fade_length = 0x100;
129
effects[0].u.periodic.envelope.fade_level = 0;
223
effects[0].u.periodic.envelope.attack_length = 1000;
224
effects[0].u.periodic.envelope.attack_level = 0x7fff;
225
effects[0].u.periodic.envelope.fade_length = 1000;
226
effects[0].u.periodic.envelope.fade_level = 0x7fff;
130
227
effects[0].trigger.button = 0;
131
228
effects[0].trigger.interval = 0;
132
229
effects[0].replay.length = 20000; /* 20 seconds */
133
effects[0].replay.delay = 0;
230
effects[0].replay.delay = 1000;
135
if (ioctl(fd, EVIOCSFF, &effects[0]) < 0) {
136
perror("Upload effects[0]");
232
printf("Uploading effect #0 (Periodic sinusoidal) ... ");
234
if (ioctl(fd, EVIOCSFF, &effects[0]) == -1) {
237
printf("OK (id %d)\n", effects[0].id);
139
240
/* download a constant effect */