Added --evdev-debug, prints events required from evdev

This commit is contained in:
Ingo Ruhnke 2010-12-30 22:59:57 +01:00
parent 0659035066
commit 4e0d0173f3
6 changed files with 49 additions and 5 deletions

View file

@ -95,6 +95,7 @@ enum {
OPTION_LIST_CONTROLLER,
OPTION_MOUSE,
OPTION_EVDEV,
OPTION_EVDEV_DEBUG,
OPTION_EVDEV_ABSMAP,
OPTION_EVDEV_KEYMAP,
OPTION_DETACH_KERNEL_DRIVER,
@ -146,6 +147,7 @@ CommandLineParser::init_argp()
.add_option(OPTION_DEVICE_BY_ID, 0, "device-by-id", "VENDOR:PRODUCT", "Use device that matches VENDOR:PRODUCT (as returned by lsusb)")
.add_option(OPTION_TYPE, 0, "type", "TYPE", "Ignore autodetection and enforce controller type (xbox, xbox-mat, xbox360, xbox360-wireless, xbox360-guitar)")
.add_option(OPTION_EVDEV, 0, "evdev", "DEVICE", "Read events from a evdev device, instead of USB")
.add_option(OPTION_EVDEV_DEBUG, 0, "evdev-debug", "", "Print out all events received from evdev")
.add_option(OPTION_EVDEV_ABSMAP, 0, "evdev-absmap", "MAP", "Map evdev key events to Xbox360 button events")
.add_option(OPTION_EVDEV_KEYMAP, 0, "evdev-keymap", "MAP", "Map evdev abs events to Xbox360 axis events")
.add_newline()
@ -218,6 +220,7 @@ CommandLineParser::init_ini(Options* opts)
("four-way-restrictor", &opts->four_way_restrictor)
("dpad-rotation", &opts->dpad_rotation)
("evdev", &opts->evdev_device)
("evdev-debug", &opts->evdev_debug)
("config", boost::bind(&CommandLineParser::read_config_file, this, opts, _1))
("alt-config", boost::bind(&CommandLineParser::read_alt_config_file, this, opts, _1))
@ -483,6 +486,10 @@ CommandLineParser::parse_args(int argc, char** argv, Options* options)
case OPTION_EVDEV:
opts.evdev_device = opt.argument;
break;
case OPTION_EVDEV_DEBUG:
opts.evdev_debug = true;
break;
case OPTION_EVDEV_ABSMAP:
process_name_value_string(opt.argument, boost::bind(&CommandLineParser::set_evdev_absmap, this, _1, _2));

View file

@ -39,9 +39,11 @@
EvdevController::EvdevController(const std::string& filename,
const EvdevAbsMap& absmap,
const std::map<int, XboxButton>& keymap) :
const std::map<int, XboxButton>& keymap,
bool debug) :
m_fd(-1),
m_name(),
m_debug(debug),
m_absmap(absmap),
m_keymap(keymap),
m_absinfo(ABS_MAX),
@ -142,7 +144,37 @@ EvdevController::set_led(uint8_t status)
bool
EvdevController::apply(XboxGenericMsg& msg, const struct input_event& ev)
{
//std::cout << ev.type << " " << ev.code << " " << ev.value << std::endl;
if (m_debug)
{
switch(ev.type)
{
case EV_KEY:
std::cout << "[evdev] EV_KEY " << key2str(ev.code) << " " << ev.value << std::endl;
break;
case EV_REL:
std::cout << "[evdev] EV_REL " << rel2str(ev.code) << " " << ev.value << std::endl;
break;
case EV_ABS:
std::cout << "[evdev] EV_ABS " << abs2str(ev.code) << " " << ev.value << std::endl;
break;
case EV_SYN:
std::cout << "------------------- sync -------------------" << std::endl;
break;
case EV_MSC:
// FIXME: no idea what those are good for, but they pop up
// after key presses (something with scancodes maybe?!)
break;
default:
std::cout << "[evdev] unknown: " << ev.type << " " << ev.code << " " << ev.value << std::endl;
break;
}
}
switch(ev.type)
{
case EV_KEY:

View file

@ -35,6 +35,7 @@ class EvdevController : public XboxGenericController
private:
int m_fd;
std::string m_name;
bool m_debug;
EvdevAbsMap m_absmap;
@ -50,7 +51,8 @@ private:
public:
EvdevController(const std::string& filename,
const EvdevAbsMap& absmap,
const std::map<int, XboxButton>& keyMap);
const std::map<int, XboxButton>& keyMap,
bool debug);
void set_rumble(uint8_t left, uint8_t right);
void set_led(uint8_t status);

View file

@ -50,7 +50,8 @@ Options::Options() :
square_axis(false),
four_way_restrictor(false),
dpad_rotation(0),
evdev_device()
evdev_device(),
evdev_debug(false)
{
}

View file

@ -79,6 +79,7 @@ public:
std::string evdev_device;
EvdevAbsMap evdev_absmap;
std::map<int, XboxButton> evdev_keymap;
bool evdev_debug;
std::vector<std::string> exec;

View file

@ -522,7 +522,8 @@ Xboxdrv::run_main(const Options& opts)
{ // normal PC joystick via evdev
controller = std::auto_ptr<XboxGenericController>(new EvdevController(opts.evdev_device,
opts.evdev_absmap,
opts.evdev_keymap));
opts.evdev_keymap,
opts.evdev_debug));
// FIXME: ugly, should be part of XboxGenericController
dev_type.type = GAMEPAD_XBOX360;