Set proper vendor/product for uinput device, fixed rumble test for firestorm pad

This commit is contained in:
Ingo Ruhnke 2009-01-16 06:33:55 +01:00
parent 01a59ef68c
commit 34047bc0a8
7 changed files with 35 additions and 24 deletions

2
TODO
View file

@ -29,8 +29,6 @@ Stuff to do before 0.5 release:
don't differ between default bindings and user created ones, also
which bindings get used depends on other configuration options
* set proper idVendor/idProduct in uinput
* figure out what jscal does and if it can break stuff
1) jscal uses the joystick interface, not the event interface

View file

@ -29,8 +29,10 @@
#include "evdev_helper.hpp"
#include "linux_uinput.hpp"
LinuxUinput::LinuxUinput(const std::string& name)
LinuxUinput::LinuxUinput(const std::string& name, uint16_t vendor, uint16_t product)
: name(name),
vendor(vendor),
product(product),
fd(-1),
key_bit(false),
rel_bit(false),
@ -146,8 +148,8 @@ LinuxUinput::finish()
strncpy(user_dev.name, name.c_str(), UINPUT_MAX_NAME_SIZE);
user_dev.id.version = 0;
user_dev.id.bustype = BUS_USB;
user_dev.id.vendor = 0x045e; // FIXME: this shouldn't be hardcoded
user_dev.id.product = 0x028e;
user_dev.id.vendor = vendor;
user_dev.id.product = product;
//std::cout << "Finalizing uinput: '" << user_dev.name << "'" << std::endl;

View file

@ -28,6 +28,9 @@ class LinuxUinput
{
private:
std::string name;
uint16_t vendor;
uint16_t product;
int fd;
uinput_user_dev user_dev;
bool key_bit;
@ -41,7 +44,7 @@ private:
bool key_lst[KEY_CNT];
public:
LinuxUinput(const std::string& name);
LinuxUinput(const std::string& name, uint16_t vendor, uint16_t product);
~LinuxUinput();
/*@{*/

View file

@ -331,31 +331,31 @@ uInput::is_keyboard_button(int ev_code)
return (ev_code < 256);
}
uInput::uInput(GamepadType type, uInputCfg config_)
uInput::uInput(XPadDevice dev, uInputCfg config_)
: cfg(config_)
{
std::fill_n(axis_state, (int)XBOX_AXIS_MAX, 0);
std::fill_n(button_state, (int)XBOX_BTN_MAX, false);
joystick_uinput_dev = std::auto_ptr<LinuxUinput>(new LinuxUinput(cfg.device_name));
joystick_uinput_dev = std::auto_ptr<LinuxUinput>(new LinuxUinput(cfg.device_name, dev.idVendor, dev.idProduct));
if (cfg.extra_devices && need_mouse_device())
{
mouse_uinput_dev = std::auto_ptr<LinuxUinput>(new LinuxUinput(cfg.device_name + " - Mouse Emulation"));
mouse_uinput_dev = std::auto_ptr<LinuxUinput>(new LinuxUinput(cfg.device_name + " - Mouse Emulation", dev.idVendor, dev.idProduct));
}
if (cfg.extra_devices && need_keyboard_device())
{
keyboard_uinput_dev = std::auto_ptr<LinuxUinput>(new LinuxUinput(cfg.device_name + " - Keyboard Emulation"));
keyboard_uinput_dev = std::auto_ptr<LinuxUinput>(new LinuxUinput(cfg.device_name + " - Keyboard Emulation", dev.idVendor, dev.idProduct));
}
switch(type)
switch(dev.type)
{
case GAMEPAD_XBOX360:
case GAMEPAD_XBOX:
case GAMEPAD_XBOX360_WIRELESS:
case GAMEPAD_FIRESTORM:
setup_xbox360_gamepad(type);
setup_xbox360_gamepad(dev.type);
break;
case GAMEPAD_XBOX360_GUITAR:
@ -363,7 +363,7 @@ uInput::uInput(GamepadType type, uInputCfg config_)
break;
default:
std::cout << "Unhandled type: " << type << std::endl;
std::cout << "Unhandled type: " << dev.type << std::endl;
exit(EXIT_FAILURE);
break;
}

View file

@ -132,7 +132,7 @@ private:
std::vector<RelButtonState> rel_button;
public:
uInput(GamepadType type, uInputCfg cfg = uInputCfg());
uInput(XPadDevice dev, uInputCfg cfg = uInputCfg());
~uInput();
void setup_xbox360_gamepad(GamepadType type);

View file

@ -1052,7 +1052,7 @@ void apply_deadzone(XboxGenericMsg& msg, int deadzone)
return tv.tv_sec * 1000 + tv.tv_usec/1000;
}
void controller_loop(uInput* uinput, XboxGenericController* controller, CommandLineOptions& opts)
void controller_loop(GamepadType type, uInput* uinput, XboxGenericController* controller, CommandLineOptions& opts)
{
int timeout = 0; // 0 == no timeout
XboxGenericMsg oldmsg; // last data send to uinput
@ -1126,17 +1126,22 @@ void controller_loop(uInput* uinput, XboxGenericController* controller, CommandL
if (uinput)
uinput->send(msg);
if (opts.rumble)
{
if (opts.gamepad_type == GAMEPAD_XBOX)
if (type == GAMEPAD_XBOX)
{
controller->set_rumble(msg.xbox.lt, msg.xbox.rt);
}
else if (opts.gamepad_type == GAMEPAD_XBOX360 ||
opts.gamepad_type == GAMEPAD_XBOX360_WIRELESS)
else if (type == GAMEPAD_XBOX360 ||
type == GAMEPAD_XBOX360_WIRELESS)
{
controller->set_rumble(msg.xbox360.lt, msg.xbox360.rt);
controller->set_rumble(msg.xbox360.lt, msg.xbox360.rt);
}
else if (type == GAMEPAD_FIRESTORM)
{
controller->set_rumble(std::min(255, abs((msg.xbox360.y1>>8)*2)),
std::min(255, abs((msg.xbox360.y2>>8)*2)));
}
}
}
@ -1165,10 +1170,10 @@ void find_controller(struct usb_device*& dev,
}
else
{
dev_type.type = opts.gamepad_type;
dev_type.type = opts.gamepad_type;
dev_type.idVendor = dev->descriptor.idVendor;
dev_type.idProduct = dev->descriptor.idProduct;
dev_type.name = "unknown";
dev_type.name = "unknown";
}
}
}
@ -1303,7 +1308,7 @@ void run_main(CommandLineOptions& opts)
if (!opts.no_uinput)
{
std::cout << "\nStarting with uinput... " << std::flush;
uinput = new uInput(dev_type.type, opts.uinput_config);
uinput = new uInput(dev_type, opts.uinput_config);
std::cout << "done" << std::endl;
}
else
@ -1317,7 +1322,7 @@ void run_main(CommandLineOptions& opts)
std::cout << "\nPress Ctrl-c to quit\n" << std::endl;
global_exit_xboxdrv = false;
controller_loop(uinput, controller, opts);
controller_loop(dev_type.type, uinput, controller, opts);
delete controller;
delete uinput;

View file

@ -41,6 +41,9 @@ std::ostream& operator<<(std::ostream& out, const GamepadType& type)
case GAMEPAD_XBOX360_GUITAR:
return out << "Xbox360 Guitar";
case GAMEPAD_FIRESTORM:
return out << "Firestorm Dual Power";
default:
return out << "unknown" << std::endl;
}