- added --dpad-as-button option
- cleaned up --help output a bit - renamed list-led-values and list-devices to --help-*
This commit is contained in:
parent
40aec09bb2
commit
83a1cc3e54
4 changed files with 104 additions and 64 deletions
4
TODO
4
TODO
|
@ -32,9 +32,7 @@ New Command Line Options:
|
|||
Report Dpad motion as regular buttons instead of as axis (conflicts
|
||||
with dpad-first)
|
||||
|
||||
--trigger-as-button
|
||||
|
||||
--trigger-as-axis
|
||||
--trigger-as-zaxis
|
||||
Turn LT,RT into the Z-axis
|
||||
|
||||
--stick2-as-throttle
|
||||
|
|
136
uinput.cpp
136
uinput.cpp
|
@ -35,6 +35,8 @@ uInput::uInput(GamepadType type, uInputCfg config_)
|
|||
else
|
||||
{
|
||||
ioctl(fd, UI_SET_EVBIT, EV_ABS);
|
||||
ioctl(fd, UI_SET_EVBIT, EV_KEY);
|
||||
|
||||
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_X);
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_Y);
|
||||
|
@ -47,11 +49,24 @@ uInput::uInput(GamepadType type, uInputCfg config_)
|
|||
ioctl(fd, UI_SET_ABSBIT, ABS_GAS);
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_BRAKE);
|
||||
}
|
||||
else
|
||||
{
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_TL2);
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_TR2);
|
||||
}
|
||||
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_HAT0X);
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_HAT0Y);
|
||||
|
||||
ioctl(fd, UI_SET_EVBIT, EV_KEY);
|
||||
if (!config.dpad_as_button)
|
||||
{
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_HAT0X);
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_HAT0Y);
|
||||
}
|
||||
else
|
||||
{
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_BASE);
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_BASE2);
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_BASE3);
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_BASE4);
|
||||
}
|
||||
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_START);
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_SELECT);
|
||||
|
@ -67,12 +82,6 @@ uInput::uInput(GamepadType type, uInputCfg config_)
|
|||
ioctl(fd, UI_SET_KEYBIT, BTN_TL);
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_TR);
|
||||
|
||||
if (config.trigger_as_button)
|
||||
{
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_TL2);
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_TR2);
|
||||
}
|
||||
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_THUMBL);
|
||||
ioctl(fd, UI_SET_KEYBIT, BTN_THUMBR);
|
||||
|
||||
|
@ -105,11 +114,14 @@ uInput::uInput(GamepadType type, uInputCfg config_)
|
|||
uinp.absmax[ABS_BRAKE] = 255;
|
||||
}
|
||||
|
||||
uinp.absmin[ABS_HAT0X] = -1;
|
||||
uinp.absmax[ABS_HAT0X] = 1;
|
||||
if (!config.dpad_as_button)
|
||||
{
|
||||
uinp.absmin[ABS_HAT0X] = -1;
|
||||
uinp.absmax[ABS_HAT0X] = 1;
|
||||
|
||||
uinp.absmin[ABS_HAT0Y] = -1;
|
||||
uinp.absmax[ABS_HAT0Y] = 1;
|
||||
uinp.absmin[ABS_HAT0Y] = -1;
|
||||
uinp.absmax[ABS_HAT0Y] = 1;
|
||||
}
|
||||
|
||||
write(fd, &uinp, sizeof(uinp));
|
||||
|
||||
|
@ -189,30 +201,40 @@ uInput::send(XBox360Msg& msg)
|
|||
send_button(BTN_TR2, msg.rt);
|
||||
}
|
||||
|
||||
if (msg.dpad_up)
|
||||
if (config.dpad_as_button)
|
||||
{
|
||||
send_axis(ABS_HAT0Y, -1);
|
||||
}
|
||||
else if (msg.dpad_down)
|
||||
{
|
||||
send_axis(ABS_HAT0Y, 1);
|
||||
send_button(BTN_BASE, msg.dpad_up);
|
||||
send_button(BTN_BASE2, msg.dpad_down);
|
||||
send_button(BTN_BASE3, msg.dpad_left);
|
||||
send_button(BTN_BASE4, msg.dpad_right);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_axis(ABS_HAT0Y, 0);
|
||||
}
|
||||
if (msg.dpad_up)
|
||||
{
|
||||
send_axis(ABS_HAT0Y, -1);
|
||||
}
|
||||
else if (msg.dpad_down)
|
||||
{
|
||||
send_axis(ABS_HAT0Y, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_axis(ABS_HAT0Y, 0);
|
||||
}
|
||||
|
||||
if (msg.dpad_left)
|
||||
{
|
||||
send_axis(ABS_HAT0X, -1);
|
||||
}
|
||||
else if (msg.dpad_right)
|
||||
{
|
||||
send_axis(ABS_HAT0X, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_axis(ABS_HAT0X, 0);
|
||||
if (msg.dpad_left)
|
||||
{
|
||||
send_axis(ABS_HAT0X, -1);
|
||||
}
|
||||
else if (msg.dpad_right)
|
||||
{
|
||||
send_axis(ABS_HAT0X, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_axis(ABS_HAT0X, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,30 +272,40 @@ uInput::send(XBoxMsg& msg)
|
|||
send_button(BTN_TR2, msg.rt);
|
||||
}
|
||||
|
||||
if (msg.dpad_up)
|
||||
if (config.dpad_as_button)
|
||||
{
|
||||
send_axis(ABS_HAT0Y, -1);
|
||||
}
|
||||
else if (msg.dpad_down)
|
||||
{
|
||||
send_axis(ABS_HAT0Y, 1);
|
||||
send_button(BTN_BASE, msg.dpad_up);
|
||||
send_button(BTN_BASE2, msg.dpad_down);
|
||||
send_button(BTN_BASE3, msg.dpad_left);
|
||||
send_button(BTN_BASE4, msg.dpad_right);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_axis(ABS_HAT0Y, 0);
|
||||
}
|
||||
if (msg.dpad_up)
|
||||
{
|
||||
send_axis(ABS_HAT0Y, -1);
|
||||
}
|
||||
else if (msg.dpad_down)
|
||||
{
|
||||
send_axis(ABS_HAT0Y, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_axis(ABS_HAT0Y, 0);
|
||||
}
|
||||
|
||||
if (msg.dpad_left)
|
||||
{
|
||||
send_axis(ABS_HAT0X, -1);
|
||||
}
|
||||
else if (msg.dpad_right)
|
||||
{
|
||||
send_axis(ABS_HAT0X, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_axis(ABS_HAT0X, 0);
|
||||
if (msg.dpad_left)
|
||||
{
|
||||
send_axis(ABS_HAT0X, -1);
|
||||
}
|
||||
else if (msg.dpad_right)
|
||||
{
|
||||
send_axis(ABS_HAT0X, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_axis(ABS_HAT0X, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,11 @@ class uInputCfg
|
|||
{
|
||||
public:
|
||||
bool trigger_as_button;
|
||||
bool dpad_as_button;
|
||||
|
||||
uInputCfg() {
|
||||
trigger_as_button = false;
|
||||
dpad_as_button = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
26
xbox360.cpp
26
xbox360.cpp
|
@ -262,19 +262,23 @@ int main(int argc, char** argv)
|
|||
std::cout << "Usage: " << argv[0] << " [OPTION]..." << std::endl;
|
||||
std::cout << "XBox360 USB Gamepad Userspace Driver" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Options: " << std::endl;
|
||||
std::cout << "General Options: " << std::endl;
|
||||
std::cout << " -h, --help display this help and exit" << std::endl;
|
||||
std::cout << " --help-led list possible values for the led" << std::endl;
|
||||
std::cout << " --help-devices list supported devices" << std::endl;
|
||||
std::cout << " -v, --verbose display controller events" << std::endl;
|
||||
std::cout << " -i, --id N use controller number (default: 0)" << std::endl;
|
||||
std::cout << " --list-controller list available controllers" << std::endl;
|
||||
std::cout << " --test-rumble map rumbling to LT and RT (for testing only)" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Status Options: " << std::endl;
|
||||
std::cout << " -l, --led NUM set LED status, see --list-led-values (default: 0)" << std::endl;
|
||||
std::cout << " -r, --rumble L,R set the speed for both rumble motors [0-255] (default: 0,0)" << std::endl;
|
||||
std::cout << " -i, --id N controller number (default: 0)" << std::endl;
|
||||
std::cout << " -q, --quit only set led and rumble status then quit" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Configuration Options: " << std::endl;
|
||||
std::cout << " --trigger-as-button LT and RT send button instead of axis events" << std::endl;
|
||||
std::cout << " --test-rumble map rumbling to LT and RT (for testing only)" << std::endl;
|
||||
std::cout << " --list-devices list supported devices" << std::endl;
|
||||
std::cout << " --list-controller list available controllers" << std::endl;
|
||||
std::cout << " --list-led-values list possible values for the led" << std::endl;
|
||||
|
||||
std::cout << " --dpad-as-button DPad sends button instead of axis events" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Report bugs to Ingo Ruhnke <grumbel@gmx.de>" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -337,11 +341,15 @@ int main(int argc, char** argv)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if (strcmp("--dpad-as-button", argv[i]) == 0)
|
||||
{
|
||||
uinput_config.dpad_as_button = true;
|
||||
}
|
||||
else if (strcmp("--trigger-as-button", argv[i]) == 0)
|
||||
{
|
||||
uinput_config.trigger_as_button = true;
|
||||
}
|
||||
else if (strcmp("--list-led-values", argv[i]) == 0)
|
||||
else if (strcmp("--help-led", argv[i]) == 0)
|
||||
{
|
||||
std::cout <<
|
||||
"Possible values for '--led VALUE' are:\n\n"
|
||||
|
@ -373,7 +381,7 @@ int main(int argc, char** argv)
|
|||
list_controller();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if (strcmp(argv[i], "--list-devices") == 0)
|
||||
else if (strcmp(argv[i], "--help-devices") == 0)
|
||||
{
|
||||
std::cout << " idVendor | idProduct | Name" << std::endl;
|
||||
std::cout << "----------+-----------+---------------------------------" << std::endl;
|
||||
|
|
Loading…
Reference in a new issue