-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.c
292 lines (270 loc) · 11.4 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
* ltwheelconf - configure logitech racing wheels
*
* Copyright (C) 2011 Michael Bauer <michael@m-bauer.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define VERSION "0.2.7"
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "wheels.h"
#include "wheelfunctions.h"
/* Globals */
int verbose_flag = 0;
void help() {
printf ( "%s","\nltwheelconf " VERSION " - Configure Logitech Driving Force Pro, G25, G27 wheels\n\
\n\
ltwheelconf Copyright (C) 2011 Michael Bauer\n\
This program comes with ABSOLUTELY NO WARRANTY.\n\
\n\
General Options: \n\
-h, --help This help text\n\
-v, --verbose Verbose output\n\
Use -vv to get debug messages from libusb\n\
-l, --list List all found/supported devices\n\
\n\
Wheel configuration: \n\
-w, --wheel=shortname Which wheel is connected. Supported values:\n\
-> 'DF' (Driving Force)\n\
-> 'MR' (Momo Racing)\n\
-> 'MF' (Momo Force)\n\
-> 'DFP' (Driving Force Pro)\n\
-> 'DFGT' (Driving Force GT)\n\
-> 'G25' (G25)\n\
-> 'G27' (G27)\n\
-n, --nativemode Set wheel to native mode (separate axes, full wheel range, clutch pedal, H-shifter)\n\
-x, --reset Reset the wheel. This is basically the same like unplugging & replugging it.\n\
Note:\n\
-> Requires wheel to be in native (-n) mode!\n\
-r, --range=degrees Set wheel rotation range (up to 900 degrees).\n\
Note:\n\
-> Requires wheel to be in native (-n) mode!\n\
-a, --autocenter=value Set autocenter bypassing hid driver. Value should be between 0 and 255 (0 -> no autocenter, 255 -> max autocenter force). \n\
Together with the rampspeed setting this allows much finer control of the autocenter behaviour as using the generic input interface.\n\
Note: \n\
-> Requires parameter '--rampspeed'\n\
-s, --rampspeed Use in conjuntion with the --autocenter parameter. Specify how fast the autocenter force should increase when rotating wheel.\n\
Value should be between 0 and 7\n\
Low value means the centering force is increasing only slightly when turning the wheel.\n\
High value means the centering force is increasing very fast when turning the wheel.\n\
-b, --altautocenter=value Set autocenter force using generic input interface. Value should be between 0 and 100 (0 -> no autocenter, 100 -> max autocenter force). \n\
Use this if --autocenter does not work for your device.\n\
Note: \n\
-> Requires parameter '--device' to specify the input device\n\
-> Only works with kernel >= 2.6.39\n\
-> The rampspeed can not be influenced using this method\n\
-g, --gain=value Set forcefeedback gain. Value should be between 0 and 100 (0 -> no gain, 100 -> max gain). \n\
Note: \n\
-> Requires parameter '--device' to specify the input device\n\
-d, --device=inputdevice Specify inputdevice for force-feedback related configuration (--gain and --altautocenter)\n\
\n\
Note: You can freely combine all configuration options.\n\
\n\
Examples:\n\
Put wheel into native mode:\n\
$ sudo ltwheelconf --wheel G25 --nativemode\n\
Set wheel rotation range to 900 degree:\n\
$ sudo ltwheelconf --wheel G27 --range 900 \n\
Set moderate autocenter:\n\
$ sudo ltwheelconf --wheel DFP --autocenter 100 --rampspeed 1\n\
Disable autocenter completely:\n\
$ sudo ltwheelconf --wheel G25 --autocenter 0 --rampspeed 0\n\
Set native mode, disable autocenter and set wheel rotation range of 540 degrees in one call:\n\
$ sudo ltwheelconf --wheel G25 --nativemode --range 540 --autocenter 0 --rampspeed 0\n\
\n\
Contact: michael@m-bauer.org\n\
\n");
}
int main (int argc, char **argv)
{
unsigned short int range = 0;
unsigned short int centerforce = 0;
unsigned short int gain = 0;
int do_validate_wheel = 0;
int do_native = 0;
int do_range = 0;
int do_autocenter = 0;
int do_alt_autocenter = 0;
int do_gain = 0;
int do_list = 0;
int rampspeed = -1;
int do_help = 0;
int do_reset = 0;
char device_file_name[128];
char shortname[255];
memset(device_file_name, 0, sizeof(device_file_name));
verbose_flag = 0;
static struct option long_options[] =
{
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"list", no_argument, 0, 'l'},
{"wheel", required_argument, 0, 'w'},
{"nativemode", no_argument, 0, 'n'},
{"range", required_argument, 0, 'r'},
{"altautocenter", required_argument, 0, 'b'},
{"autocenter", required_argument, 0, 'a'},
{"rampspeed", required_argument, 0, 's'},
{"gain", required_argument, 0, 'g'},
{"device", required_argument, 0, 'd'},
{"reset", no_argument, 0, 'x'},
{0, 0, 0, 0 }
};
while (optind < argc) {
int index = -1;
int result = getopt_long (argc, argv, "vhlw:nr:a:g:d:s:b:x",
long_options, &index);
if (result == -1)
break; /* end of list */
switch (result) {
case 'v':
verbose_flag++;
break;
case 'n':
do_native = 1;
break;
case 'r':
range = atoi(optarg);
do_range = 1;
break;
case 'a':
centerforce = atoi(optarg);
do_autocenter = 1;
do_alt_autocenter = 0;
break;
case 'b':
centerforce = atoi(optarg);
do_autocenter = 0;
do_alt_autocenter = 1;
break;
case 's':
rampspeed = atoi(optarg);
break;
case 'g':
gain = atoi(optarg);
do_gain = 1;
break;
case 'd':
strncpy(device_file_name, optarg, 128);
break;
case 'l':
do_list = 1;
break;
case 'w':
strncpy(shortname, optarg, 255);
do_validate_wheel = 1;
break;
case 'x':
do_reset = 1;
break;
case '?':
default:
do_help = 1;
break;
}
}
if (argc > 1)
{
libusb_init(NULL);
if (verbose_flag > 1)
libusb_set_debug(0, 3);
int wait_for_udev = 0;
wheelstruct* wheel = 0;
if (do_help) {
help();
} else if (do_list) {
// list all devices, ignore other options...
list_devices();
} else {
if (do_validate_wheel) {
int numWheels = sizeof(wheels)/sizeof(wheelstruct);
int i = 0;
for (i=0; i < numWheels; i++) {
if (strncasecmp(wheels[i].shortname, shortname, 255) == 0) {
// found matching wheel
wheel = &(wheels[i]);
break;
}
}
if (!wheel) {
printf("Wheel \"%s\" not supported. Did you spell the shortname correctly?\n", shortname);
}
}
if (do_reset) {
if (!wheel) {
printf("Please provide --wheel parameter!\n");
} else {
reset_wheel(wheel);
wait_for_udev = 1;
}
}
if (do_native) {
if (!wheel) {
printf("Please provide --wheel parameter!\n");
} else {
set_native_mode(wheel);
wait_for_udev = 1;
}
}
if (do_range) {
if (!wheel) {
printf("Please provide --wheel parameter!\n");
} else {
set_range(wheel, clamprange(wheel, range));
wait_for_udev = 1;
}
}
if (do_autocenter) {
if (!wheel) {
printf("Please provide --wheel parameter!\n");
} else {
if (centerforce == 0) {
set_autocenter(wheel, centerforce, 0);
wait_for_udev = 1;
} else if (rampspeed == -1) {
printf("Please provide '--rampspeed' parameter\n");
} else {
set_autocenter(wheel, centerforce, rampspeed);
wait_for_udev = 1;
}
}
}
if (do_alt_autocenter) {
if (strlen(device_file_name)) {
alt_set_autocenter(centerforce, device_file_name, wait_for_udev);
wait_for_udev = 0;
} else {
printf("Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /dev/input/event0')\n");
}
}
if (do_gain) {
if (strlen(device_file_name)) {
set_gain(gain, device_file_name, wait_for_udev);
wait_for_udev = 0;
} else {
printf("Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /dev/input/event0')\n");
}
}
}
libusb_exit(NULL);
} else {
// display usage information if no arguments given
help();
}
exit(0);
}