- fixed some smaller issues, uinput devices are now working
This commit is contained in:
parent
ec73a8feb9
commit
74f8aa534f
6 changed files with 82 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
||||||
# -*- python -*-
|
# -*- python -*-
|
||||||
|
|
||||||
env = Environment(CPPFLAGS=["-g", "-O2", "-Wall"], LIBS=["usb"])
|
env = Environment(CPPFLAGS=["-g", "-O0", "-Wall"], LIBS=["usb"])
|
||||||
env.Program("xboxdrv", ["xboxdrv.cpp", "uinput.cpp"])
|
env.Program("xboxdrv", ["xboxdrv.cpp", "uinput.cpp"])
|
||||||
env.Program("inputdrv",
|
env.Program("inputdrv",
|
||||||
["inputdrv.cpp",
|
["inputdrv.cpp",
|
||||||
|
|
51
inputdrv.cpp
51
inputdrv.cpp
|
@ -27,6 +27,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include "xbox360_driver.hpp"
|
#include "xbox360_driver.hpp"
|
||||||
|
#include "uinput_driver.hpp"
|
||||||
#include "toggle_button.hpp"
|
#include "toggle_button.hpp"
|
||||||
#include "control.hpp"
|
#include "control.hpp"
|
||||||
#include "inputdrv.hpp"
|
#include "inputdrv.hpp"
|
||||||
|
@ -43,6 +44,23 @@ void abs_change(AbsPortOut* port)
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
UInputDriver uinput1;
|
||||||
|
uinput1.add_abs(ABS_X, -32768, 32767);
|
||||||
|
uinput1.add_abs(ABS_Y, -32768, 32767);
|
||||||
|
uinput1.add_btn(BTN_A);
|
||||||
|
uinput1.add_btn(BTN_B);
|
||||||
|
uinput1.add_btn(BTN_C);
|
||||||
|
uinput1.finish();
|
||||||
|
|
||||||
|
UInputDriver uinput2;
|
||||||
|
uinput2.add_abs(ABS_X, -32768, 32767);
|
||||||
|
uinput2.add_abs(ABS_Y, -32768, 32767);
|
||||||
|
uinput2.add_btn(BTN_A);
|
||||||
|
uinput2.add_btn(BTN_B);
|
||||||
|
uinput2.add_btn(BTN_C);
|
||||||
|
uinput2.finish();
|
||||||
|
|
||||||
|
|
||||||
// Init USB
|
// Init USB
|
||||||
usb_init();
|
usb_init();
|
||||||
usb_find_busses();
|
usb_find_busses();
|
||||||
|
@ -61,13 +79,44 @@ int main()
|
||||||
|
|
||||||
toggle_out->connect(xbox360.get_btn_port_in(0));
|
toggle_out->connect(xbox360.get_btn_port_in(0));
|
||||||
|
|
||||||
|
// ----------------------------
|
||||||
|
|
||||||
|
xbox360.get_abs_port_out(Xbox360Driver::XBOX360_AXIS_X1)
|
||||||
|
->connect(uinput1.get_abs_port_in(0));
|
||||||
|
xbox360.get_abs_port_out(Xbox360Driver::XBOX360_AXIS_Y1)
|
||||||
|
->connect(uinput1.get_abs_port_in(1));
|
||||||
|
|
||||||
|
xbox360.get_btn_port_out(Xbox360Driver::XBOX360_BTN_A)
|
||||||
|
->connect(uinput1.get_btn_port_in(0));
|
||||||
|
xbox360.get_btn_port_out(Xbox360Driver::XBOX360_BTN_B)
|
||||||
|
->connect(uinput1.get_btn_port_in(1));
|
||||||
|
xbox360.get_btn_port_out(Xbox360Driver::XBOX360_BTN_X)
|
||||||
|
->connect(uinput1.get_btn_port_in(2));
|
||||||
|
|
||||||
|
// ----------------------------
|
||||||
|
// ----------------------------
|
||||||
|
|
||||||
|
xbox360.get_abs_port_out(Xbox360Driver::XBOX360_AXIS_X2)
|
||||||
|
->connect(uinput2.get_abs_port_in(0));
|
||||||
|
xbox360.get_abs_port_out(Xbox360Driver::XBOX360_AXIS_Y2)
|
||||||
|
->connect(uinput2.get_abs_port_in(1));
|
||||||
|
|
||||||
|
xbox360.get_btn_port_out(Xbox360Driver::XBOX360_DPAD_DOWN)
|
||||||
|
->connect(uinput2.get_btn_port_in(0));
|
||||||
|
xbox360.get_btn_port_out(Xbox360Driver::XBOX360_DPAD_LEFT)
|
||||||
|
->connect(uinput2.get_btn_port_in(1));
|
||||||
|
xbox360.get_btn_port_out(Xbox360Driver::XBOX360_DPAD_RIGHT)
|
||||||
|
->connect(uinput2.get_btn_port_in(2));
|
||||||
|
|
||||||
|
// ----------------------------
|
||||||
|
|
||||||
xbox360.get_abs_port_out(Xbox360Driver::XBOX360_AXIS_LT)
|
xbox360.get_abs_port_out(Xbox360Driver::XBOX360_AXIS_LT)
|
||||||
->connect(xbox360.get_abs_port_in(Xbox360Driver::ABS_PORT_IN_RUMBLE_L));
|
->connect(xbox360.get_abs_port_in(Xbox360Driver::ABS_PORT_IN_RUMBLE_L));
|
||||||
|
|
||||||
xbox360.get_abs_port_out(Xbox360Driver::XBOX360_AXIS_RT)
|
xbox360.get_abs_port_out(Xbox360Driver::XBOX360_AXIS_RT)
|
||||||
->connect(xbox360.get_abs_port_in(Xbox360Driver::ABS_PORT_IN_RUMBLE_R));
|
->connect(xbox360.get_abs_port_in(Xbox360Driver::ABS_PORT_IN_RUMBLE_R));
|
||||||
|
|
||||||
xbox360.get_btn_port_out(Xbox360Driver::XBOX360_BTN_B)->connect(btn_change);
|
xbox360.get_btn_port_out(Xbox360Driver::XBOX360_BTN_Y)->connect(btn_change);
|
||||||
|
|
||||||
xbox360.run();
|
xbox360.run();
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,16 @@ UInputDriver::UInputDriver()
|
||||||
key_bit(false),
|
key_bit(false),
|
||||||
fd(-1)
|
fd(-1)
|
||||||
{
|
{
|
||||||
|
std::cout << "UInputDriver" << std::endl;
|
||||||
memset(&user_dev, 0, sizeof(user_dev));
|
memset(&user_dev, 0, sizeof(user_dev));
|
||||||
|
strncpy(user_dev.name, "Custom UInput Driver", UINPUT_MAX_NAME_SIZE);
|
||||||
|
user_dev.id.version = 0;
|
||||||
|
user_dev.id.bustype = BUS_USB; // And neither that
|
||||||
|
user_dev.id.vendor = 0x045e; // FIXME: Don't hardcode this
|
||||||
|
user_dev.id.product = 0x028e;
|
||||||
|
|
||||||
// Open the input device
|
// Open the input device
|
||||||
char* uinput_filename[] = { "/dev/input/uinput", "/dev/uinput", "/dev/misc/uinput" };
|
const char* uinput_filename[] = { "/dev/input/uinput", "/dev/uinput", "/dev/misc/uinput" };
|
||||||
const int uinput_filename_count = (sizeof(uinput_filename)/sizeof(char*));
|
const int uinput_filename_count = (sizeof(uinput_filename)/sizeof(char*));
|
||||||
|
|
||||||
for (int i = 0; i < uinput_filename_count; ++i)
|
for (int i = 0; i < uinput_filename_count; ++i)
|
||||||
|
@ -68,6 +74,12 @@ UInputDriver::UInputDriver()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UInputDriver::~UInputDriver()
|
||||||
|
{
|
||||||
|
ioctl(fd, UI_DEV_DESTROY);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UInputDriver::add_abs(uint16_t code, int min, int max)
|
UInputDriver::add_abs(uint16_t code, int min, int max)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +94,6 @@ UInputDriver::add_abs(uint16_t code, int min, int max)
|
||||||
user_dev.absmin[code] = min;
|
user_dev.absmin[code] = min;
|
||||||
user_dev.absmax[code] = max;
|
user_dev.absmax[code] = max;
|
||||||
|
|
||||||
|
|
||||||
abs_port_in.push_back(new AbsPortIn("UInput", min, max,
|
abs_port_in.push_back(new AbsPortIn("UInput", min, max,
|
||||||
boost::bind(&UInputDriver::on_abs, this, _1, code)));
|
boost::bind(&UInputDriver::on_abs, this, _1, code)));
|
||||||
}
|
}
|
||||||
|
@ -125,12 +136,20 @@ UInputDriver::add_btn(uint16_t code)
|
||||||
}
|
}
|
||||||
|
|
||||||
ioctl(fd, UI_SET_KEYBIT, code);
|
ioctl(fd, UI_SET_KEYBIT, code);
|
||||||
|
|
||||||
|
btn_port_in.push_back(new BtnPortIn("UInput",
|
||||||
|
boost::bind(&UInputDriver::on_btn, this, _1, code)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UInputDriver::finish()
|
UInputDriver::finish()
|
||||||
{
|
{
|
||||||
|
std::cout << "Finalizing UInput" << std::endl;
|
||||||
write(fd, &user_dev, sizeof(user_dev));
|
write(fd, &user_dev, sizeof(user_dev));
|
||||||
|
if (ioctl(fd, UI_DEV_CREATE))
|
||||||
|
{
|
||||||
|
std::cout << "Unable to create UINPUT device." << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UInputDriver();
|
UInputDriver();
|
||||||
|
~UInputDriver();
|
||||||
|
|
||||||
void add_abs(uint16_t code, int min, int max);
|
void add_abs(uint16_t code, int min, int max);
|
||||||
void add_btn(uint16_t code);
|
void add_btn(uint16_t code);
|
||||||
|
@ -47,6 +48,7 @@ public:
|
||||||
|
|
||||||
void on_abs(AbsPortOut* port, uint16_t code);
|
void on_abs(AbsPortOut* port, uint16_t code);
|
||||||
void on_btn(BtnPortOut* port, uint16_t code);
|
void on_btn(BtnPortOut* port, uint16_t code);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UInputDriver (const UInputDriver&);
|
UInputDriver (const UInputDriver&);
|
||||||
UInputDriver& operator= (const UInputDriver&);
|
UInputDriver& operator= (const UInputDriver&);
|
||||||
|
|
|
@ -76,8 +76,8 @@ struct usb_device* find_usb_device_by_ids(int id, uint16_t idVendor, uint16_t id
|
||||||
}
|
}
|
||||||
|
|
||||||
XPadDevice xbox360_devices[] = {
|
XPadDevice xbox360_devices[] = {
|
||||||
{ GAMEPAD_XBOX360, 0x045e, 0x028e, "Microsoft Xbox 360 Controller" },
|
{ GAMEPAD_XBOX360, 0x045e, 0x028e, "Microsoft Xbox 360 Controller" },
|
||||||
{ GAMEPAD_XBOX360, 0x0738, 0x4716, "Mad Catz Xbox 360 Controller" },
|
{ GAMEPAD_XBOX360, 0x0738, 0x4716, "Mad Catz Xbox 360 Controller" },
|
||||||
{ GAMEPAD_XBOX360_GUITAR, 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer" },
|
{ GAMEPAD_XBOX360_GUITAR, 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -154,6 +154,8 @@ Xbox360Driver::open_dev()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
handle = usb_open(dev);
|
handle = usb_open(dev);
|
||||||
|
if (usb_claim_interface(handle, 0) != 0) // FIXME: bInterfaceNumber shouldn't be hardcoded
|
||||||
|
std::cout << "Error claiming the interface: " << usb_strerror() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +267,7 @@ Xbox360Driver::set_led(uint8_t led_status)
|
||||||
void
|
void
|
||||||
Xbox360Driver::set_rumble(uint8_t big, uint8_t small)
|
Xbox360Driver::set_rumble(uint8_t big, uint8_t small)
|
||||||
{
|
{
|
||||||
std::cout << int(big) << " " << int(small) << std::endl;
|
//std::cout << int(big) << " " << int(small) << std::endl;
|
||||||
char rumblecmd[] = { 0x00, 0x08, 0x00, big, small, 0x00, 0x00, 0x00 };
|
char rumblecmd[] = { 0x00, 0x08, 0x00, big, small, 0x00, 0x00, 0x00 };
|
||||||
usb_interrupt_write(handle, 2, rumblecmd, 8, 0);
|
usb_interrupt_write(handle, 2, rumblecmd, 8, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ struct XPadDevice {
|
||||||
GamepadType type;
|
GamepadType type;
|
||||||
uint16_t idVendor;
|
uint16_t idVendor;
|
||||||
uint16_t idProduct;
|
uint16_t idProduct;
|
||||||
char* name;
|
const char* name;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue