67
if (argc<2) goto l_help;
69
for (i=1; i<argc; i++) {
70
if (!strcmp(argv[i],"-d") && i<argc-1) device_name =argv[++i];
71
else if (!strcmp(argv[i],"-u") && i<argc-1) update_rate =atof(argv[++i]);
72
else if (!strcmp(argv[i],"-f") && i<argc-1) motion_frequency=atof(argv[++i]);
73
else if (!strcmp(argv[i],"-a") && i<argc-1) motion_amplitude=atof(argv[++i]);
74
else if (!strcmp(argv[i],"-s") && i<argc-1) spring_strength =atof(argv[++i]);
75
else if (!strcmp(argv[i],"-o")) ;
81
printf("-------- ffcfstress - Force Feedback: Constant Force Stress Test --------\n");
82
printf("Description:\n");
83
printf(" This program is for stress testing constant non-enveloped forces on\n");
84
printf(" a force feedback device via the event interface. It simulates a\n");
85
printf(" moving spring force by a frequently updated constant force effect.\n");
86
printf(" BE CAREFUL IN USAGE, YOUR DEVICE MAY GET DAMAGED BY THE STRESS TEST!\n");
88
printf(" %s <option> [<option>...]\n",argv[0]);
90
printf(" -d <string> device name (default: %s)\n",DEFAULT_DEVICE_NAME);
91
printf(" -u <double> update rate in Hz (default: %.2f)\n",DEFAULT_UPDATE_RATE);
92
printf(" -f <double> spring center motion frequency in Hz (default: %.2f)\n",DEFAULT_MOTION_FREQUENCY);
93
printf(" -a <double> spring center motion amplitude 0.0..1.0 (default: %.2f)\n",DEFAULT_MOTION_AMPLITUDE);
94
printf(" -s <double> spring strength factor (default: %.2f)\n",DEFAULT_SPRING_STRENGTH);
95
printf(" -o dummy option (useful because at least one option is needed)\n");
72
int help = (argc < 2);
74
for (i=1; i<argc && !help; i++) {
75
if (!strcmp(argv[i],"-d")) {
76
if (i<argc-1) device_name = argv[++i]; else help = 1;
77
} else if (!strcmp(argv[i],"-u")) {
78
if (i<argc-1) update_rate = atof(argv[++i]); else help = 1;
79
} else if (!strcmp(argv[i],"-f")) {
80
if (i<argc-1) motion_frequency=atof(argv[++i]); else help = 1;
81
} else if (!strcmp(argv[i],"-a")) {
82
if (i<argc-1) motion_amplitude=atof(argv[++i]); else help = 1;
83
} else if (!strcmp(argv[i],"-s")) {
84
if (i<argc-1) spring_strength =atof(argv[++i]); else help = 1;
85
} else if (!strcmp(argv[i],"-x")) {
87
axis_index = atoi(argv[++i]);
88
if (axis_index < 0 || axis_index >= sizeof(axis_names)/sizeof(char*))
91
axis_code = axis_codes[axis_index];
93
} else if (!strcmp(argv[i],"-o")) {
95
} else if (!strcmp(argv[i],"-A")) {
102
printf("-------- ffcfstress - Force Feedback: Constant Force Stress Test --------\n");
103
printf("Description:\n");
104
printf(" This program is for stress testing constant non-enveloped forces on\n");
105
printf(" a force feedback device via the event interface. It simulates a\n");
106
printf(" moving spring force by a frequently updated constant force effect.\n");
107
printf(" BE CAREFUL IN USAGE, YOUR DEVICE MAY GET DAMAGED BY THE STRESS TEST!\n");
109
printf(" %s <option> [<option>...]\n",argv[0]);
110
printf("Options:\n");
111
printf(" -d <string> device name (default: %s)\n",DEFAULT_DEVICE_NAME);
112
printf(" -u <double> update rate in Hz (default: %.2f)\n",DEFAULT_UPDATE_RATE);
113
printf(" -f <double> spring center motion frequency in Hz (default: %.2f)\n",DEFAULT_MOTION_FREQUENCY);
114
printf(" -a <double> spring center motion amplitude 0.0..1.0 (default: %.2f)\n",DEFAULT_MOTION_AMPLITUDE);
115
printf(" -s <double> spring strength factor (default: %.2f)\n",DEFAULT_SPRING_STRENGTH);
116
printf(" -x <int> absolute axis to test (default: %d=%s)\n",DEFAULT_AXIS_INDEX, axis_names[DEFAULT_AXIS_INDEX]);
117
printf(" (0 = X, 1 = Y, 2 = Z, 3 = RX, 4 = RY, 5 = RZ, 6 = WHEEL)\n");
118
printf(" -A switch off auto-centering\n");
119
printf(" -o dummy option (useful because at least one option is needed)\n");
100
126
/* Initialize device, create constant force effect */
101
127
void init_device()
103
unsigned long key_bits[32],abs_bits[32],ff_bits[32];
129
unsigned char key_bits[1 + KEY_MAX/8/sizeof(unsigned char)];
130
unsigned char abs_bits[1 + ABS_MAX/8/sizeof(unsigned char)];
131
unsigned char ff_bits[1 + FF_MAX/8/sizeof(unsigned char)];
104
133
struct input_event event;
134
struct input_absinfo absinfo;
107
136
/* Open event device with write permission */
108
137
device_handle = open(device_name,O_RDWR|O_NONBLOCK);
115
144
/* Which buttons has the device? */
116
memset(key_bits,0,32*sizeof(unsigned long));
117
if (ioctl(device_handle,EVIOCGBIT(EV_KEY,32*sizeof(unsigned long)),key_bits)<0) {
145
memset(key_bits,0,sizeof(key_bits));
146
if (ioctl(device_handle,EVIOCGBIT(EV_KEY,sizeof(key_bits)),key_bits)<0) {
118
147
fprintf(stderr,"ERROR: can not get key bits (%s) [%s:%d]\n",
119
148
strerror(errno),__FILE__,__LINE__);
123
152
/* Which axes has the device? */
124
memset(abs_bits,0,32*sizeof(unsigned long));
125
if (ioctl(device_handle,EVIOCGBIT(EV_ABS,32*sizeof(unsigned long)),abs_bits)<0) {
153
memset(abs_bits,0,sizeof(abs_bits));
154
if (ioctl(device_handle,EVIOCGBIT(EV_ABS,sizeof(abs_bits)),abs_bits)<0) {
126
155
fprintf(stderr,"ERROR: can not get abs bits (%s) [%s:%d]\n",
127
156
strerror(errno),__FILE__,__LINE__);
131
160
/* Now get some information about force feedback */
132
memset(ff_bits,0,32*sizeof(unsigned long));
133
if (ioctl(device_handle,EVIOCGBIT(EV_FF ,32*sizeof(unsigned long)),ff_bits)<0) {
161
memset(ff_bits,0,sizeof(ff_bits));
162
if (ioctl(device_handle,EVIOCGBIT(EV_FF ,sizeof(ff_bits)),ff_bits)<0) {
134
163
fprintf(stderr,"ERROR: can not get ff bits (%s) [%s:%d]\n",
135
164
strerror(errno),__FILE__,__LINE__);
139
/* Which axis is the x-axis? */
140
if (TEST_BIT(ABS_X ,abs_bits)) axis_code=ABS_X;
141
else if (TEST_BIT(ABS_RX ,abs_bits)) axis_code=ABS_RX;
142
else if (TEST_BIT(ABS_WHEEL,abs_bits)) axis_code=ABS_WHEEL;
144
fprintf(stderr,"ERROR: no suitable x-axis found [%s:%d]\n",
168
/* Check if selected axis is available */
169
if (!testBit(axis_code, abs_bits)) {
170
fprintf(stderr,"ERROR: selected axis %s not available [%s:%d] (see available ones with fftest)\n",
171
axis_names[axis_index], __FILE__,__LINE__);
149
175
/* get axis value range */
150
if (ioctl(device_handle,EVIOCGABS(axis_code),valbuf)<0) {
176
if (ioctl(device_handle,EVIOCGABS(axis_code),&absinfo)<0) {
151
177
fprintf(stderr,"ERROR: can not get axis value range (%s) [%s:%d]\n",
152
178
strerror(errno),__FILE__,__LINE__);
181
axis_min=absinfo.minimum;
182
axis_max=absinfo.maximum;
157
183
if (axis_min>=axis_max) {
158
184
fprintf(stderr,"ERROR: bad axis value range (%d,%d) [%s:%d]\n",
159
185
axis_min,axis_max,__FILE__,__LINE__);
163
189
/* force feedback supported? */
164
if (!TEST_BIT(FF_CONSTANT,ff_bits)) {
165
fprintf(stderr,"ERROR: device (or driver) has no force feedback support [%s:%d]\n",
190
if (!testBit(FF_CONSTANT,ff_bits)) {
191
fprintf(stderr,"ERROR: device (or driver) has no constant force feedback support [%s:%d]\n",
166
192
__FILE__,__LINE__);
170
196
/* Switch off auto centering */
171
memset(&event,0,sizeof(event));
173
event.code=FF_AUTOCENTER;
175
if (write(device_handle,&event,sizeof(event))!=sizeof(event)) {
176
fprintf(stderr,"ERROR: failed to disable auto centering (%s) [%s:%d]\n",
177
strerror(errno),__FILE__,__LINE__);
197
if (autocenter_off) {
198
memset(&event,0,sizeof(event));
200
event.code=FF_AUTOCENTER;
202
if (write(device_handle,&event,sizeof(event))!=sizeof(event)) {
203
fprintf(stderr,"ERROR: failed to disable auto centering (%s) [%s:%d]\n",
204
strerror(errno),__FILE__,__LINE__);
181
209
/* Initialize constant force effect */