42 #if HAVE_FORCE_FEEDBACK
46 printf(
"Force feedback support disabled when compiled\n" );
54 #if HAVE_FORCE_FEEDBACK
70 printf(
"update force %f degrees %f\n", angle, strength );
75 printf(
"speed effect %f\n", strength );
80 printf(
"shield hit %f degrees %f\n", angle, strength );
87 #if HAVE_FORCE_FEEDBACK
92 eff_last_time[eff_nr] = nowtime;
93 if (activate ==
true && is_played[eff_nr] ==
false) {
94 printf(
"starting ab\n" );
99 is_played[eff_nr] =
true;
100 }
else if (activate ==
false && is_played[eff_nr] ==
true) {
101 if (nowtime > eff_last_time[eff_nr]+min_effect_time) {
102 printf(
"stopped ab\n" );
107 is_played[eff_nr] =
false;
108 eff_last_time[eff_nr] = nowtime;
118 #if HAVE_FORCE_FEEDBACK
122 if (nowtime < eff_last_time[eff_nr]+min_effect_time)
128 eff_last_time[eff_nr] = nowtime;
138 #if HAVE_FORCE_FEEDBACK
139 if (activate ==
true && is_played[eff_nr] ==
false) {
140 playEffect( eff_nr );
141 is_played[eff_nr] =
true;
142 }
else if (activate ==
false && is_played[eff_nr] ==
true) {
143 stopEffect( eff_nr );
144 is_played[eff_nr] =
false;
155 #if HAVE_FORCE_FEEDBACK
157 if (nowtime < eff_last_time[eff_nr]+min_effect_time)
160 playEffect( eff_nr );
162 eff_last_time[eff_nr] = nowtime;
166 #if HAVE_FORCE_FEEDBACK
168 void ForceFeedback::playEffect(
unsigned int eff_nr )
172 play.code = effects[eff_nr].id;
174 if (write( ff_fd, (
const void*) &play,
sizeof (play) ) == -1) {
175 perror(
"ff: Play effect" );
182 printf(
"played effect nr %d\n", eff_nr );
185 void ForceFeedback::stopEffect(
unsigned int eff_nr )
189 stop.code = effects[eff_nr].id;
191 if (write( ff_fd, (
const void*) &stop,
sizeof (stop) ) == -1) {
192 perror(
"ff: stop effect" );
199 printf(
"stopped effect nr %d\n", eff_nr );
202 void ForceFeedback::init()
205 printf(
"force feedback disabled in config file\n" );
209 sprintf( devname,
"/dev/input/event%d", game_options.
ff_device );
211 ff_fd = open( devname, O_RDWR );
213 perror(
"error while opening force feedback device" );
217 printf(
"Device %s opened\n", devname );
219 if (ioctl( ff_fd, EVIOCGBIT( EV_FF,
sizeof (
unsigned long)*4 ), features ) == -1) {
220 perror(
"ff:Ioctl query" );
225 printf(
"Axes query: " );
226 if ( test_bit( ABS_X, features ) ) printf(
"Axis X " );
227 if ( test_bit( ABS_Y, features ) ) printf(
"Axis Y " );
228 if ( test_bit( ABS_WHEEL, features ) ) printf(
"Wheel " );
229 printf(
"\nEffects: " );
230 if ( test_bit( FF_CONSTANT, features ) ) printf(
"Constant " );
231 if ( test_bit( FF_PERIODIC, features ) ) printf(
"Periodic " );
232 if ( test_bit( FF_SPRING, features ) ) printf(
"Spring " );
233 if ( test_bit( FF_FRICTION, features ) ) printf(
"Friction " );
234 if ( test_bit( FF_RUMBLE, features ) ) printf(
"Rumble " );
235 printf(
"\nNumber of simultaneous effects: " );
236 if (ioctl( ff_fd, EVIOCGEFFECTS, &n_effects ) == -1) {
237 perror(
"Ioctl number of effects" );
242 printf(
"nr_effects: %d\n", n_effects );
244 printf(
"not enough effects in device - ff disabled\n" );
250 effects[1].type = FF_CONSTANT;
252 effects[1].u.constant.level = 0x2000;
253 effects[1].direction = 0x6000;
254 effects[1].u.constant.envelope.attack_length = 0x100;
255 effects[1].u.constant.envelope.attack_level = 0;
256 effects[1].u.constant.envelope.fade_length = 0x100;
257 effects[1].u.constant.envelope.fade_level = 0;
258 effects[1].trigger.button = 0;
259 effects[1].trigger.interval = 0;
260 effects[1].replay.length = 2000;
261 effects[1].replay.delay = 0;
264 effects[0].type = FF_PERIODIC;
266 effects[0].u.periodic.waveform = FF_SINE;
267 effects[0].u.periodic.period = 0.4*0x100;
268 effects[0].u.periodic.magnitude = 0x6000;
269 effects[0].u.periodic.offset = 0;
270 effects[0].u.periodic.phase = 0;
271 effects[0].direction = 0x000;
272 effects[0].u.periodic.envelope.attack_length = 0x100;
273 effects[0].u.periodic.envelope.attack_level = 0;
274 effects[0].u.periodic.envelope.fade_length = 0x100;
275 effects[0].u.periodic.envelope.fade_level = 0;
276 effects[0].trigger.button = 0;
277 effects[0].trigger.interval = 0;
278 effects[0].replay.length = 500;
279 effects[0].replay.delay = 0;
282 effects[2].type = FF_SPRING;
284 effects[2].u.condition[0].right_saturation = 0x7fff;
285 effects[2].u.condition[0].left_saturation = 0x7fff;
286 effects[2].u.condition[0].right_coeff = 0x2000;
287 effects[2].u.condition[0].left_coeff = 0x2000;
288 effects[2].u.condition[0].deadband = 0x0;
289 effects[2].u.condition[0].center = 0x0;
290 effects[2].u.condition[1] = effects[2].u.condition[0];
291 effects[2].trigger.button = 0;
292 effects[2].trigger.interval = 0;
293 effects[2].replay.length = 0xFFFF;
294 effects[2].replay.delay = 0;
297 effects[3].type = FF_DAMPER;
299 effects[3].u.condition[0].right_saturation = 0x7fff;
300 effects[3].u.condition[0].left_saturation = 0x7fff;
301 effects[3].u.condition[0].right_coeff = 0x2000;
302 effects[3].u.condition[0].left_coeff = 0x2000;
303 effects[3].u.condition[0].deadband = 0x0;
304 effects[3].u.condition[0].center = 0x0;
305 effects[3].u.condition[1] = effects[3].u.condition[0];
306 effects[3].trigger.button = 0;
307 effects[3].trigger.interval = 0;
308 effects[3].replay.length = 2000;
309 effects[3].replay.delay = 0;
334 effects[
eff_ab_wiggle_x].u.periodic.envelope.attack_length = 2.31*0x100;
351 effects[
eff_ab_wiggle_y].u.periodic.envelope.attack_length = 2.31*0x100;
364 effects[
eff_ab_jerk].u.constant.envelope.attack_length = 0.3*0x100;
365 effects[
eff_ab_jerk].u.constant.envelope.attack_level = 0x7fff;
366 effects[
eff_ab_jerk].u.constant.envelope.fade_length = 0;
367 effects[
eff_ab_jerk].u.constant.envelope.fade_level = 0;
380 effects[
eff_laser_jerk].u.constant.envelope.attack_length = 0x000;
398 effects[
eff_laser_jerk].u.periodic.envelope.attack_length = 0.043*0x100;
399 effects[
eff_laser_jerk].u.periodic.envelope.attack_level = 0x7fff;
435 effects[
eff_force].u.constant.level = 0x0;
437 effects[
eff_force].u.constant.envelope.attack_length = 0x000;
438 effects[
eff_force].u.constant.envelope.attack_level = 0;
439 effects[
eff_force].u.constant.envelope.fade_length = 0x000;
440 effects[
eff_force].u.constant.envelope.fade_level = 0;
443 effects[
eff_force].replay.length = 0xfff;
446 printf(
"uploading effect %d\n", i );
447 if (ioctl( ff_fd, EVIOCSFF, &effects[i] ) == -1) {
448 perror(
"error while uploading effect" );
453 eff_last_time[i] = 0;
454 is_played[i] =
false;
456 min_effect_time = 0.3;
461 void ForceFeedback::init_bogus(
int i )
463 effects[i].type = FF_CONSTANT;
465 effects[i].u.constant.level = 0x2000;
466 effects[i].direction = 0x6000;
467 effects[i].u.constant.envelope.attack_length = 0x100;
468 effects[i].u.constant.envelope.attack_level = 0;
469 effects[i].u.constant.envelope.fade_length = 0x100;
470 effects[i].u.constant.envelope.fade_level = 0;
471 effects[i].trigger.button = 0;
472 effects[i].trigger.interval = 0;
473 effects[i].replay.length = 2000;
474 effects[i].replay.delay = 0;