Made guitar buttons remapable, create a seperate device for keyboard events

This commit is contained in:
Ingo Ruhnke 2009-01-03 07:02:49 +01:00
parent 746b8c04bf
commit 2268c7e3d0
10 changed files with 208 additions and 127 deletions

View file

@ -150,10 +150,10 @@ struct Xbox360Msg
unsigned int guide :1;
unsigned int dummy1 :1; // always 0
unsigned int a :1;
unsigned int b :1;
unsigned int x :1;
unsigned int y :1;
unsigned int a :1; // green
unsigned int b :1; // red
unsigned int x :1; // blue
unsigned int y :1; // yellow
// data[4] ------------------
unsigned int lt :8;

5
README
View file

@ -183,6 +183,9 @@ lb, rb | shoulder buttons (Xbox360 only, mapped to black, white on Xbox1
lt, rt | analog trigger (needs --trigger-as-button option)
tl, tr | pressing the left or right analog stick
du, dd, dl, dr | dpad directions (needs --dpad-as-button option)
green, red, | guitar buttons
yellow, blue, |
orange |
[[ Axis Remapping ]]
--------------------
@ -297,7 +300,7 @@ Note: The exact string will differ depending on the type of controller you use.
[[ Mouse Emulation ]]
---------------------
xboxdrv does not support mouse emulation, however due to Xorg
xboxdrv does not support real mouse emulation, however due to Xorg
brokeness and ugly hackery, the following gives you mouse emulation:
% ./xboxdrv --ui-buttonmap A=BTN_LEFT,B=BTN_RIGHT -s --relative-axis X1=64000,Y1=64000 --deadzone 4192

6
TODO
View file

@ -1,3 +1,9 @@
* figure out which devices xorg handles as keyboard
* catch duplicates in uinput
* could optimize to only send buttons when things changed
* create two seperate uinput devices for keyboard and mouse events
* output driver/device name on startup

View file

@ -110,17 +110,17 @@ LinuxUinput::add_key(uint16_t code)
}
void
LinuxUinput::finish()
LinuxUinput::finish(const char* name)
{
std::cout << "Finalizing UInput" << std::endl;
strncpy(user_dev.name, "Xbox Gamepad (userspace driver)", UINPUT_MAX_NAME_SIZE);
strncpy(user_dev.name, name, 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;
if (write(fd, &user_dev, sizeof(user_dev)) < 0)
throw std::runtime_error(strerror(errno));
throw std::runtime_error(std::string("uinput:finish: ") + strerror(errno));
if (ioctl(fd, UI_DEV_CREATE))
{
@ -140,7 +140,7 @@ LinuxUinput::send_button(uint16_t code, int32_t value)
ev.value = (value>0) ? 1 : 0;
if (write(fd, &ev, sizeof(ev)) < 0)
throw std::runtime_error(strerror(errno));
throw std::runtime_error(std::string("uinput:send_button: ") + strerror(errno));
}
void
@ -155,7 +155,7 @@ LinuxUinput::send_axis(uint16_t code, int32_t value)
ev.value = value;
if (write(fd, &ev, sizeof(ev)) < 0)
throw std::runtime_error(strerror(errno));
throw std::runtime_error(std::string("uinput:send_axis: ") + strerror(errno));
}
/* EOF */

View file

@ -49,7 +49,7 @@ public:
void add_rel(uint16_t code);
/** Finish*/
void finish();
void finish(const char* name);
/*@}*/
void send_button(uint16_t code, int32_t value);

View file

@ -49,6 +49,12 @@ uInputCfg::uInputCfg()
btn_map[XBOX_BTN_X] = BTN_X;
btn_map[XBOX_BTN_Y] = BTN_Y;
btn_map[XBOX_BTN_GREEN] = BTN_0;
btn_map[XBOX_BTN_RED] = BTN_1;
btn_map[XBOX_BTN_YELLOW] = BTN_2;
btn_map[XBOX_BTN_BLUE] = BTN_3;
btn_map[XBOX_BTN_ORANGE] = BTN_4;
btn_map[XBOX_BTN_WHITE] = BTN_TL;
btn_map[XBOX_BTN_BLACK] = BTN_TR;
@ -81,7 +87,8 @@ uInputCfg::uInputCfg()
uInput::uInput(GamepadType type, uInputCfg config_)
:cfg(config_)
{
uinput = std::auto_ptr<LinuxUinput>(new LinuxUinput());
joy_uinput = std::auto_ptr<LinuxUinput>(new LinuxUinput());
key_uinput = std::auto_ptr<LinuxUinput>(new LinuxUinput());
if (type == GAMEPAD_XBOX360 || type == GAMEPAD_XBOX || type == GAMEPAD_XBOX360_WIRELESS)
{
@ -97,7 +104,8 @@ uInput::uInput(GamepadType type, uInputCfg config_)
exit(EXIT_FAILURE);
}
uinput->finish();
joy_uinput->finish("Xbox Gamepad (userspace driver)");
key_uinput->finish("Xbox Gamepad - Keyboard Emulation (userspace driver)");
}
void
@ -122,62 +130,62 @@ uInput::setup_xbox360_gamepad(GamepadType type)
// ioctl(fd, UI_SET_FFBIT, FF_RAMP);
}
uinput->add_abs(cfg.axis_map[XBOX_AXIS_X1], -32768, 32767);
uinput->add_abs(cfg.axis_map[XBOX_AXIS_Y1], -32768, 32767);
add_abs(cfg.axis_map[XBOX_AXIS_X1], -32768, 32767);
add_abs(cfg.axis_map[XBOX_AXIS_Y1], -32768, 32767);
if (!cfg.dpad_only)
{
uinput->add_abs(cfg.axis_map[XBOX_AXIS_X2], -32768, 32767);
uinput->add_abs(cfg.axis_map[XBOX_AXIS_Y2], -32768, 32767);
add_abs(cfg.axis_map[XBOX_AXIS_X2], -32768, 32767);
add_abs(cfg.axis_map[XBOX_AXIS_Y2], -32768, 32767);
}
if (cfg.trigger_as_button)
{
uinput->add_key(cfg.btn_map[XBOX_BTN_LT]);
uinput->add_key(cfg.btn_map[XBOX_BTN_RT]);
add_key(cfg.btn_map[XBOX_BTN_LT]);
add_key(cfg.btn_map[XBOX_BTN_RT]);
}
else if (cfg.trigger_as_zaxis)
{
uinput->add_abs(cfg.axis_map[XBOX_AXIS_TRIGGER], -255, 255);
add_abs(cfg.axis_map[XBOX_AXIS_TRIGGER], -255, 255);
}
else
{
uinput->add_abs(cfg.axis_map[XBOX_AXIS_LT], 0, 255);
uinput->add_abs(cfg.axis_map[XBOX_AXIS_RT], 0, 255);
add_abs(cfg.axis_map[XBOX_AXIS_LT], 0, 255);
add_abs(cfg.axis_map[XBOX_AXIS_RT], 0, 255);
}
if (!cfg.dpad_only)
{
if (!cfg.dpad_as_button)
{
uinput->add_abs(cfg.axis_map[XBOX_AXIS_DPAD_X], -1, 1);
uinput->add_abs(cfg.axis_map[XBOX_AXIS_DPAD_Y], -1, 1);
add_abs(cfg.axis_map[XBOX_AXIS_DPAD_X], -1, 1);
add_abs(cfg.axis_map[XBOX_AXIS_DPAD_Y], -1, 1);
}
else
{
uinput->add_key(cfg.btn_map[XBOX_DPAD_UP]);
uinput->add_key(cfg.btn_map[XBOX_DPAD_DOWN]);
uinput->add_key(cfg.btn_map[XBOX_DPAD_LEFT]);
uinput->add_key(cfg.btn_map[XBOX_DPAD_RIGHT]);
add_key(cfg.btn_map[XBOX_DPAD_UP]);
add_key(cfg.btn_map[XBOX_DPAD_DOWN]);
add_key(cfg.btn_map[XBOX_DPAD_LEFT]);
add_key(cfg.btn_map[XBOX_DPAD_RIGHT]);
}
}
uinput->add_key(cfg.btn_map[XBOX_BTN_START]);
uinput->add_key(cfg.btn_map[XBOX_BTN_BACK]);
add_key(cfg.btn_map[XBOX_BTN_START]);
add_key(cfg.btn_map[XBOX_BTN_BACK]);
if (type == GAMEPAD_XBOX360 || type == GAMEPAD_XBOX360_WIRELESS)
uinput->add_key(cfg.btn_map[XBOX_BTN_GUIDE]);
add_key(cfg.btn_map[XBOX_BTN_GUIDE]);
uinput->add_key(cfg.btn_map[XBOX_BTN_A]);
uinput->add_key(cfg.btn_map[XBOX_BTN_B]);
uinput->add_key(cfg.btn_map[XBOX_BTN_X]);
uinput->add_key(cfg.btn_map[XBOX_BTN_Y]);
add_key(cfg.btn_map[XBOX_BTN_A]);
add_key(cfg.btn_map[XBOX_BTN_B]);
add_key(cfg.btn_map[XBOX_BTN_X]);
add_key(cfg.btn_map[XBOX_BTN_Y]);
uinput->add_key(cfg.btn_map[XBOX_BTN_LB]);
uinput->add_key(cfg.btn_map[XBOX_BTN_RB]);
add_key(cfg.btn_map[XBOX_BTN_LB]);
add_key(cfg.btn_map[XBOX_BTN_RB]);
uinput->add_key(cfg.btn_map[XBOX_BTN_THUMB_L]);
uinput->add_key(cfg.btn_map[XBOX_BTN_THUMB_R]);
add_key(cfg.btn_map[XBOX_BTN_THUMB_L]);
add_key(cfg.btn_map[XBOX_BTN_THUMB_R]);
struct uinput_user_dev uinp;
memset(&uinp,0,sizeof(uinp));
@ -192,26 +200,26 @@ void
uInput::setup_xbox360_guitar()
{
// Whammy and Tilt
uinput->add_abs(cfg.axis_map[XBOX_AXIS_X1], -32768, 32767);
uinput->add_abs(cfg.axis_map[XBOX_AXIS_Y1], -32768, 32767);
add_abs(cfg.axis_map[XBOX_AXIS_X1], -32768, 32767);
add_abs(cfg.axis_map[XBOX_AXIS_Y1], -32768, 32767);
// Dpad
uinput->add_key(cfg.btn_map[XBOX_DPAD_UP]);
uinput->add_key(cfg.btn_map[XBOX_DPAD_DOWN]);
uinput->add_key(cfg.btn_map[XBOX_DPAD_LEFT]);
uinput->add_key(cfg.btn_map[XBOX_DPAD_RIGHT]);
add_key(cfg.btn_map[XBOX_DPAD_UP]);
add_key(cfg.btn_map[XBOX_DPAD_DOWN]);
add_key(cfg.btn_map[XBOX_DPAD_LEFT]);
add_key(cfg.btn_map[XBOX_DPAD_RIGHT]);
// Base
uinput->add_key(cfg.btn_map[XBOX_BTN_START]);
uinput->add_key(cfg.btn_map[XBOX_BTN_BACK]);
uinput->add_key(cfg.btn_map[XBOX_BTN_GUIDE]);
add_key(cfg.btn_map[XBOX_BTN_START]);
add_key(cfg.btn_map[XBOX_BTN_BACK]);
add_key(cfg.btn_map[XBOX_BTN_GUIDE]);
// Fret button
uinput->add_key(BTN_1);
uinput->add_key(BTN_2);
uinput->add_key(BTN_3);
uinput->add_key(BTN_4);
uinput->add_key(BTN_5);
add_key(BTN_1);
add_key(BTN_2);
add_key(BTN_3);
add_key(BTN_4);
add_key(BTN_5);
}
uInput::~uInput()
@ -246,48 +254,48 @@ uInput::send(XboxGenericMsg& msg)
void
uInput::send(Xbox360Msg& msg)
{
uinput->send_button(BTN_THUMBL, msg.thumb_l);
uinput->send_button(BTN_THUMBR, msg.thumb_r);
send_button(cfg.btn_map[XBOX_BTN_THUMB_L], msg.thumb_l);
send_button(cfg.btn_map[XBOX_BTN_THUMB_R], msg.thumb_r);
uinput->send_button(BTN_TL, msg.lb);
uinput->send_button(BTN_TR, msg.rb);
send_button(cfg.btn_map[XBOX_BTN_LB], msg.lb);
send_button(cfg.btn_map[XBOX_BTN_RB], msg.rb);
uinput->send_button(cfg.btn_map[XBOX_BTN_START], msg.start);
uinput->send_button(cfg.btn_map[XBOX_BTN_GUIDE], msg.guide);
uinput->send_button(cfg.btn_map[XBOX_BTN_BACK], msg.back);
send_button(cfg.btn_map[XBOX_BTN_START], msg.start);
send_button(cfg.btn_map[XBOX_BTN_GUIDE], msg.guide);
send_button(cfg.btn_map[XBOX_BTN_BACK], msg.back);
uinput->send_button(cfg.btn_map[XBOX_BTN_A], msg.a);
uinput->send_button(cfg.btn_map[XBOX_BTN_B], msg.b);
uinput->send_button(cfg.btn_map[XBOX_BTN_X], msg.x);
uinput->send_button(cfg.btn_map[XBOX_BTN_Y], msg.y);
send_button(cfg.btn_map[XBOX_BTN_A], msg.a);
send_button(cfg.btn_map[XBOX_BTN_B], msg.b);
send_button(cfg.btn_map[XBOX_BTN_X], msg.x);
send_button(cfg.btn_map[XBOX_BTN_Y], msg.y);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_X1], msg.x1);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_Y1], -msg.y1);
send_axis(cfg.axis_map[XBOX_AXIS_X1], msg.x1);
send_axis(cfg.axis_map[XBOX_AXIS_Y1], -msg.y1);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_X2], msg.x2);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_Y2], -msg.y2);
send_axis(cfg.axis_map[XBOX_AXIS_X2], msg.x2);
send_axis(cfg.axis_map[XBOX_AXIS_Y2], -msg.y2);
if (cfg.trigger_as_zaxis)
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_TRIGGER], (int(msg.rt) - int(msg.lt)));
send_axis(cfg.axis_map[XBOX_AXIS_TRIGGER], (int(msg.rt) - int(msg.lt)));
}
else if (cfg.trigger_as_button)
{
uinput->send_button(cfg.btn_map[XBOX_BTN_LT], msg.lt);
uinput->send_button(cfg.btn_map[XBOX_BTN_RT], msg.rt);
send_button(cfg.btn_map[XBOX_BTN_LT], msg.lt);
send_button(cfg.btn_map[XBOX_BTN_RT], msg.rt);
}
else
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_LT], msg.lt);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_RT], msg.rt);
send_axis(cfg.axis_map[XBOX_AXIS_LT], msg.lt);
send_axis(cfg.axis_map[XBOX_AXIS_RT], msg.rt);
}
if (cfg.dpad_as_button && !cfg.dpad_only)
{
uinput->send_button(BTN_BASE, msg.dpad_up);
uinput->send_button(BTN_BASE2, msg.dpad_down);
uinput->send_button(BTN_BASE3, msg.dpad_left);
uinput->send_button(BTN_BASE4, msg.dpad_right);
send_button(cfg.btn_map[XBOX_DPAD_UP], msg.dpad_up);
send_button(cfg.btn_map[XBOX_DPAD_DOWN], msg.dpad_down);
send_button(cfg.btn_map[XBOX_DPAD_LEFT], msg.dpad_left);
send_button(cfg.btn_map[XBOX_DPAD_RIGHT], msg.dpad_right);
}
else
{
@ -302,28 +310,28 @@ uInput::send(Xbox360Msg& msg)
if (msg.dpad_up)
{
uinput->send_axis(dpad_y, -1);
send_axis(dpad_y, -1);
}
else if (msg.dpad_down)
{
uinput->send_axis(dpad_y, 1);
send_axis(dpad_y, 1);
}
else
{
uinput->send_axis(dpad_y, 0);
send_axis(dpad_y, 0);
}
if (msg.dpad_left)
{
uinput->send_axis(dpad_x, -1);
send_axis(dpad_x, -1);
}
else if (msg.dpad_right)
{
uinput->send_axis(dpad_x, 1);
send_axis(dpad_x, 1);
}
else
{
uinput->send_axis(dpad_x, 0);
send_axis(dpad_x, 0);
}
}
}
@ -331,74 +339,74 @@ uInput::send(Xbox360Msg& msg)
void
uInput::send(XboxMsg& msg)
{
uinput->send_button(BTN_THUMBL, msg.thumb_l);
uinput->send_button(BTN_THUMBR, msg.thumb_r);
send_button(cfg.btn_map[XBOX_BTN_THUMB_L], msg.thumb_l);
send_button(cfg.btn_map[XBOX_BTN_THUMB_R], msg.thumb_r);
uinput->send_button(BTN_TL, msg.white);
uinput->send_button(BTN_TR, msg.black);
send_button(cfg.btn_map[XBOX_BTN_WHITE], msg.white);
send_button(cfg.btn_map[XBOX_BTN_BLACK], msg.black);
uinput->send_button(BTN_START, msg.start);
uinput->send_button(BTN_SELECT, msg.back);
send_button(cfg.btn_map[XBOX_BTN_START], msg.start);
send_button(cfg.btn_map[XBOX_BTN_BACK], msg.back);
uinput->send_button(cfg.btn_map[XBOX_BTN_A], msg.a);
uinput->send_button(cfg.btn_map[XBOX_BTN_B], msg.b);
uinput->send_button(cfg.btn_map[XBOX_BTN_X], msg.x);
uinput->send_button(cfg.btn_map[XBOX_BTN_Y], msg.y);
send_button(cfg.btn_map[XBOX_BTN_A], msg.a);
send_button(cfg.btn_map[XBOX_BTN_B], msg.b);
send_button(cfg.btn_map[XBOX_BTN_X], msg.x);
send_button(cfg.btn_map[XBOX_BTN_Y], msg.y);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_X1], msg.x1);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_Y1], msg.y1);
send_axis(cfg.axis_map[XBOX_AXIS_X1], msg.x1);
send_axis(cfg.axis_map[XBOX_AXIS_Y1], msg.y1);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_X2], msg.x2);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_Y2], msg.y2);
send_axis(cfg.axis_map[XBOX_AXIS_X2], msg.x2);
send_axis(cfg.axis_map[XBOX_AXIS_Y2], msg.y2);
if (cfg.trigger_as_zaxis)
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_TRIGGER], (int(msg.rt) - int(msg.lt)));
send_axis(cfg.axis_map[XBOX_AXIS_TRIGGER], (int(msg.rt) - int(msg.lt)));
}
else if (cfg.trigger_as_button)
{
uinput->send_button(cfg.btn_map[XBOX_BTN_LT], msg.lt);
uinput->send_button(cfg.btn_map[XBOX_BTN_RT], msg.rt);
send_button(cfg.btn_map[XBOX_BTN_LT], msg.lt);
send_button(cfg.btn_map[XBOX_BTN_RT], msg.rt);
}
else
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_LT], msg.lt);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_RT], msg.rt);
send_axis(cfg.axis_map[XBOX_AXIS_LT], msg.lt);
send_axis(cfg.axis_map[XBOX_AXIS_RT], msg.rt);
}
if (cfg.dpad_as_button)
{
uinput->send_button(cfg.btn_map[XBOX_DPAD_UP], msg.dpad_up);
uinput->send_button(cfg.btn_map[XBOX_DPAD_DOWN], msg.dpad_down);
uinput->send_button(cfg.btn_map[XBOX_DPAD_LEFT], msg.dpad_left);
uinput->send_button(cfg.btn_map[XBOX_DPAD_RIGHT], msg.dpad_right);
send_button(cfg.btn_map[XBOX_DPAD_UP], msg.dpad_up);
send_button(cfg.btn_map[XBOX_DPAD_DOWN], msg.dpad_down);
send_button(cfg.btn_map[XBOX_DPAD_LEFT], msg.dpad_left);
send_button(cfg.btn_map[XBOX_DPAD_RIGHT], msg.dpad_right);
}
else
{
if (msg.dpad_up)
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_DPAD_Y], -1);
send_axis(cfg.axis_map[XBOX_AXIS_DPAD_Y], -1);
}
else if (msg.dpad_down)
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_DPAD_Y], 1);
send_axis(cfg.axis_map[XBOX_AXIS_DPAD_Y], 1);
}
else
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_DPAD_Y], 0);
send_axis(cfg.axis_map[XBOX_AXIS_DPAD_Y], 0);
}
if (msg.dpad_left)
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_DPAD_X], -1);
send_axis(cfg.axis_map[XBOX_AXIS_DPAD_X], -1);
}
else if (msg.dpad_right)
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_DPAD_X], 1);
send_axis(cfg.axis_map[XBOX_AXIS_DPAD_X], 1);
}
else
{
uinput->send_axis(cfg.axis_map[XBOX_AXIS_DPAD_X], 0);
send_axis(cfg.axis_map[XBOX_AXIS_DPAD_X], 0);
}
}
}
@ -406,23 +414,23 @@ uInput::send(XboxMsg& msg)
void
uInput::send(Xbox360GuitarMsg& msg)
{
uinput->send_button(cfg.btn_map[XBOX_DPAD_UP], msg.dpad_up);
uinput->send_button(cfg.btn_map[XBOX_DPAD_DOWN], msg.dpad_down);
uinput->send_button(cfg.btn_map[XBOX_DPAD_LEFT], msg.dpad_left);
uinput->send_button(cfg.btn_map[XBOX_DPAD_RIGHT], msg.dpad_right);
send_button(cfg.btn_map[XBOX_DPAD_UP], msg.dpad_up);
send_button(cfg.btn_map[XBOX_DPAD_DOWN], msg.dpad_down);
send_button(cfg.btn_map[XBOX_DPAD_LEFT], msg.dpad_left);
send_button(cfg.btn_map[XBOX_DPAD_RIGHT], msg.dpad_right);
uinput->send_button(cfg.btn_map[XBOX_BTN_START], msg.start);
uinput->send_button(cfg.btn_map[XBOX_BTN_GUIDE], msg.guide);
uinput->send_button(cfg.btn_map[XBOX_BTN_BACK], msg.back);
send_button(cfg.btn_map[XBOX_BTN_START], msg.start);
send_button(cfg.btn_map[XBOX_BTN_GUIDE], msg.guide);
send_button(cfg.btn_map[XBOX_BTN_BACK], msg.back);
uinput->send_button(BTN_1, msg.green);
uinput->send_button(BTN_2, msg.red);
uinput->send_button(BTN_3, msg.yellow);
uinput->send_button(BTN_4, msg.blue);
uinput->send_button(BTN_5, msg.orange);
send_button(cfg.btn_map[XBOX_BTN_GREEN], msg.green);
send_button(cfg.btn_map[XBOX_BTN_RED], msg.red);
send_button(cfg.btn_map[XBOX_BTN_YELLOW], msg.yellow);
send_button(cfg.btn_map[XBOX_BTN_BLUE], msg.blue);
send_button(cfg.btn_map[XBOX_BTN_ORANGE], msg.orange);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_X1], msg.whammy);
uinput->send_axis(cfg.axis_map[XBOX_AXIS_Y1], msg.tilt);
send_axis(cfg.axis_map[XBOX_AXIS_X1], msg.whammy);
send_axis(cfg.axis_map[XBOX_AXIS_Y1], msg.tilt);
}
std::ostream& operator<<(std::ostream& out, const struct ff_envelope& envelope)
@ -610,4 +618,36 @@ uInput::update()
#endif
}
void
uInput::send_button(uint16_t code, int32_t value)
{
//std::cout << "send_button: " << code << " " << value << std::endl;
if (code < 256)
key_uinput->send_button(code, value);
else
joy_uinput->send_button(code, value);
}
void
uInput::send_axis(uint16_t code, int32_t value)
{
joy_uinput->send_axis(code, value);
}
void
uInput::add_abs(uint16_t code, int min, int max)
{
joy_uinput->add_abs(code, min, max);
}
void
uInput::add_key(uint16_t code)
{
if (code < 256)
key_uinput->add_key(code);
else
joy_uinput->add_key(code);
}
/* EOF */

View file

@ -45,7 +45,8 @@ public:
class uInput
{
private:
std::auto_ptr<LinuxUinput> uinput;
std::auto_ptr<LinuxUinput> joy_uinput;
std::auto_ptr<LinuxUinput> key_uinput;
uInputCfg cfg;
public:
@ -60,6 +61,12 @@ public:
void send(Xbox360GuitarMsg& msg);
void send(XboxMsg& msg);
void add_abs(uint16_t code, int min, int max);
void add_key(uint16_t code);
void send_button(uint16_t code, int32_t value);
void send_axis(uint16_t code, int32_t value);
void update();
};

View file

@ -156,6 +156,8 @@ void set_ui_button_map(int* ui_button_map, const std::string& str)
}
else
{
std::cout << string2btn(str.substr(0, i)) << " -> " << str.substr(i+1, str.size()-i) << std::endl;
XboxButton btn = string2btn(str.substr(0, i));
std::string rhs = str.substr(i+1, str.size()-i);
int code = is_number(rhs) ? boost::lexical_cast<int>(rhs) : str2evbtn(rhs);

View file

@ -546,6 +546,17 @@ XboxButton string2btn(const std::string& str_)
else if (str == "y")
return XBOX_BTN_Y;
else if (str == "green")
return XBOX_BTN_GREEN;
else if (str == "red")
return XBOX_BTN_RED;
else if (str == "blue")
return XBOX_BTN_BLUE;
else if (str == "yellow")
return XBOX_BTN_YELLOW;
else if (str == "orange")
return XBOX_BTN_ORANGE;
else if (str == "black")
return XBOX_BTN_BLACK;
else if (str == "white")
@ -648,6 +659,12 @@ std::string btn2string(XboxButton btn)
case XBOX_BTN_X: return "X";
case XBOX_BTN_Y: return "Y";
case XBOX_BTN_GREEN: return "green";
case XBOX_BTN_RED: return "red";
case XBOX_BTN_BLUE: return "blue";
case XBOX_BTN_YELLOW: return "yellow";
case XBOX_BTN_ORANGE: return "orange";
case XBOX_BTN_WHITE: return "White";
case XBOX_BTN_BLACK: return "Black";

View file

@ -188,6 +188,12 @@ enum XboxButton {
XBOX_BTN_X,
XBOX_BTN_Y,
XBOX_BTN_GREEN,
XBOX_BTN_RED,
XBOX_BTN_BLUE,
XBOX_BTN_YELLOW,
XBOX_BTN_ORANGE,
XBOX_BTN_WHITE,
XBOX_BTN_BLACK,