- added --trigger-as-button option
This commit is contained in:
parent
c1b50860d6
commit
40aec09bb2
4 changed files with 62 additions and 15 deletions
1
README
1
README
|
@ -70,4 +70,5 @@ game. For most games the driver should work as-is.
|
|||
|
||||
See ftp://ptah.lnf.kth.se/pub/misc/sdl-env-vars for more information.
|
||||
|
||||
|
||||
# EOF #
|
||||
|
|
53
uinput.cpp
53
uinput.cpp
|
@ -23,7 +23,8 @@
|
|||
#include <linux/uinput.h>
|
||||
#include "uinput.hpp"
|
||||
|
||||
uInput::uInput(GamepadType type)
|
||||
uInput::uInput(GamepadType type, uInputCfg config_)
|
||||
: config(config_)
|
||||
{
|
||||
// Open the input device
|
||||
fd = open("/dev/input/uinput", O_WRONLY | O_NDELAY);
|
||||
|
@ -41,8 +42,11 @@ uInput::uInput(GamepadType type)
|
|||
ioctl(fd, UI_SET_ABSBIT, ABS_RX);
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_RY);
|
||||
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_GAS);
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_BRAKE);
|
||||
if (!config.trigger_as_button)
|
||||
{
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_GAS);
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_BRAKE);
|
||||
}
|
||||
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_HAT0X);
|
||||
ioctl(fd, UI_SET_ABSBIT, ABS_HAT0Y);
|
||||
|
@ -63,6 +67,12 @@ uInput::uInput(GamepadType type)
|
|||
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);
|
||||
|
||||
|
@ -86,11 +96,14 @@ uInput::uInput(GamepadType type)
|
|||
uinp.absmin[ABS_RY] = -32768;
|
||||
uinp.absmax[ABS_RY] = 32767;
|
||||
|
||||
uinp.absmin[ABS_GAS] = 0;
|
||||
uinp.absmax[ABS_GAS] = 255;
|
||||
|
||||
uinp.absmin[ABS_BRAKE] = 0;
|
||||
uinp.absmax[ABS_BRAKE] = 255;
|
||||
if (!config.trigger_as_button)
|
||||
{
|
||||
uinp.absmin[ABS_GAS] = 0;
|
||||
uinp.absmax[ABS_GAS] = 255;
|
||||
|
||||
uinp.absmin[ABS_BRAKE] = 0;
|
||||
uinp.absmax[ABS_BRAKE] = 255;
|
||||
}
|
||||
|
||||
uinp.absmin[ABS_HAT0X] = -1;
|
||||
uinp.absmax[ABS_HAT0X] = 1;
|
||||
|
@ -165,8 +178,16 @@ uInput::send(XBox360Msg& msg)
|
|||
send_axis(ABS_RX, msg.x2);
|
||||
send_axis(ABS_RY, -msg.y2);
|
||||
|
||||
send_axis(ABS_BRAKE, msg.lt);
|
||||
send_axis(ABS_GAS, msg.rt);
|
||||
if (!config.trigger_as_button)
|
||||
{
|
||||
send_axis(ABS_BRAKE, msg.lt);
|
||||
send_axis(ABS_GAS, msg.rt);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_button(BTN_TL2, msg.lt);
|
||||
send_button(BTN_TR2, msg.rt);
|
||||
}
|
||||
|
||||
if (msg.dpad_up)
|
||||
{
|
||||
|
@ -218,8 +239,16 @@ uInput::send(XBoxMsg& msg)
|
|||
send_axis(ABS_RX, msg.x2);
|
||||
send_axis(ABS_RY, msg.y2);
|
||||
|
||||
send_axis(ABS_BRAKE, msg.lt);
|
||||
send_axis(ABS_GAS, msg.rt);
|
||||
if (!config.trigger_as_button)
|
||||
{
|
||||
send_axis(ABS_BRAKE, msg.lt);
|
||||
send_axis(ABS_GAS, msg.rt);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_button(BTN_TL2, msg.lt);
|
||||
send_button(BTN_TR2, msg.rt);
|
||||
}
|
||||
|
||||
if (msg.dpad_up)
|
||||
{
|
||||
|
|
13
uinput.hpp
13
uinput.hpp
|
@ -21,13 +21,24 @@
|
|||
|
||||
#include "xbox360.hpp"
|
||||
|
||||
class uInputCfg
|
||||
{
|
||||
public:
|
||||
bool trigger_as_button;
|
||||
|
||||
uInputCfg() {
|
||||
trigger_as_button = false;
|
||||
}
|
||||
};
|
||||
|
||||
class uInput
|
||||
{
|
||||
private:
|
||||
int fd;
|
||||
uInputCfg config;
|
||||
|
||||
public:
|
||||
uInput(GamepadType type);
|
||||
uInput(GamepadType type, uInputCfg cfg = uInputCfg());
|
||||
~uInput();
|
||||
|
||||
void send(XBox360Msg& msg);
|
||||
|
|
10
xbox360.cpp
10
xbox360.cpp
|
@ -252,6 +252,7 @@ int main(int argc, char** argv)
|
|||
int rumble_r = 0;
|
||||
int controller_id = 0;
|
||||
bool instant_exit = false;
|
||||
uInputCfg uinput_config;
|
||||
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
|
@ -268,11 +269,12 @@ int main(int argc, char** argv)
|
|||
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 << " --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 << " --merge-trigger merge both trigger to form a Z axis" << std::endl;
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Report bugs to Ingo Ruhnke <grumbel@gmx.de>" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -335,6 +337,10 @@ int main(int argc, char** argv)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if (strcmp("--trigger-as-button", argv[i]) == 0)
|
||||
{
|
||||
uinput_config.trigger_as_button = true;
|
||||
}
|
||||
else if (strcmp("--list-led-values", argv[i]) == 0)
|
||||
{
|
||||
std::cout <<
|
||||
|
@ -446,7 +452,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
uInput* uinput = new uInput(dev_type->type);
|
||||
uInput* uinput = new uInput(dev_type->type, uinput_config);
|
||||
std::cout << "\nYour XBox360 controller should now be available as /dev/input/jsX" << std::endl;
|
||||
std::cout << "Press Ctrl-c to quit" << std::endl;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue