Split AxisEvent and ButtonEvent into their own files
This commit is contained in:
parent
e9699e6161
commit
5784f09921
8 changed files with 339 additions and 229 deletions
|
@ -49,6 +49,8 @@ env = conf.Finish()
|
|||
env.Program('xboxdrv', ['src/xboxdrv.cpp',
|
||||
'src/xboxmsg.cpp',
|
||||
'src/uinput.cpp',
|
||||
'src/button_event.cpp',
|
||||
'src/axis_event.cpp',
|
||||
'src/arg_parser.cpp',
|
||||
'src/pretty_printer.cpp',
|
||||
'src/helper.cpp',
|
||||
|
|
120
src/axis_event.cpp
Normal file
120
src/axis_event.cpp
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2010 Ingo Ruhnke <grumbel@gmx.de>
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/input.h>
|
||||
#include <assert.h>
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "axis_event.hpp"
|
||||
#include "evdev_helper.hpp"
|
||||
|
||||
AxisEvent
|
||||
AxisEvent::create(int type, int code, int fuzz, int flat)
|
||||
{
|
||||
AxisEvent ev;
|
||||
ev.type = type;
|
||||
ev.code = code;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EV_REL:
|
||||
ev.rel.repeat = 10;
|
||||
ev.rel.value = 5;
|
||||
break;
|
||||
|
||||
case EV_ABS:
|
||||
ev.abs.fuzz = fuzz;
|
||||
ev.abs.flat = flat;
|
||||
break;
|
||||
|
||||
case EV_KEY:
|
||||
ev.key.secondary_code = code;
|
||||
ev.key.threshold = 8000;
|
||||
break;
|
||||
|
||||
case -1:
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(!"This should never be reached");
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
AxisEvent
|
||||
AxisEvent::from_string(const std::string& str)
|
||||
{
|
||||
AxisEvent ev;
|
||||
|
||||
boost::char_separator<char> sep(":", "", boost::keep_empty_tokens);
|
||||
boost::tokenizer<boost::char_separator<char> > tokenizer(str, sep);
|
||||
|
||||
std::vector<std::string> tokens;
|
||||
std::copy(tokenizer.begin(), tokenizer.end(), std::back_inserter(tokens));
|
||||
|
||||
int j = 0;
|
||||
for(std::vector<std::string>::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
int type, code;
|
||||
if (!str2event(*i, type, code))
|
||||
{
|
||||
throw std::runtime_error("Couldn't convert '" + str + "' to AxisEvent");
|
||||
}
|
||||
else
|
||||
{
|
||||
ev = AxisEvent::create(type, code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (ev.type)
|
||||
{
|
||||
case EV_ABS:
|
||||
break;
|
||||
|
||||
case EV_REL:
|
||||
switch(j) {
|
||||
case 1: ev.rel.value = boost::lexical_cast<int>(*i); break;
|
||||
case 2: ev.rel.repeat = boost::lexical_cast<int>(*i); break;
|
||||
}
|
||||
break;
|
||||
|
||||
case EV_KEY:
|
||||
switch(j) {
|
||||
case 1:
|
||||
{
|
||||
int type;
|
||||
str2event(*i, type, ev.key.secondary_code);
|
||||
assert(type == EV_KEY);
|
||||
}
|
||||
break;
|
||||
case 2: ev.key.threshold = boost::lexical_cast<int>(*i); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
/* EOF */
|
56
src/axis_event.hpp
Normal file
56
src/axis_event.hpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2010 Ingo Ruhnke <grumbel@gmx.de>
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_XBOXDRV_AXIS_EVENT_HPP
|
||||
#define HEADER_XBOXDRV_AXIS_EVENT_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
struct AxisEvent
|
||||
{
|
||||
static AxisEvent invalid() { return create(-1, -1); }
|
||||
static AxisEvent create(int type, int code, int fuzz = 0, int flat = 0);
|
||||
static AxisEvent from_string(const std::string& str);
|
||||
|
||||
/** EV_KEY, EV_ABS, EV_REL */
|
||||
int type;
|
||||
|
||||
/** BTN_A, REL_X, ABS_X, ... */
|
||||
int code;
|
||||
|
||||
union {
|
||||
struct {
|
||||
int repeat;
|
||||
float value;
|
||||
} rel;
|
||||
|
||||
struct {
|
||||
int fuzz;
|
||||
int flat;
|
||||
} abs;
|
||||
|
||||
struct {
|
||||
int secondary_code;
|
||||
int threshold;
|
||||
} key;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
100
src/button_event.cpp
Normal file
100
src/button_event.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2010 Ingo Ruhnke <grumbel@gmx.de>
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <linux/input.h>
|
||||
#include <stdexcept>
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "button_event.hpp"
|
||||
#include "evdev_helper.hpp"
|
||||
|
||||
ButtonEvent
|
||||
ButtonEvent::create(int type, int code)
|
||||
{
|
||||
ButtonEvent ev;
|
||||
ev.type = type;
|
||||
ev.code = code;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EV_REL:
|
||||
ev.rel.repeat = 100;
|
||||
ev.rel.value = 3;
|
||||
break;
|
||||
|
||||
case EV_ABS:
|
||||
throw std::runtime_error("Using EV_ABS for ButtonEvent is currently not supported");
|
||||
ev.abs.value = 1;
|
||||
break;
|
||||
|
||||
case EV_KEY:
|
||||
break;
|
||||
|
||||
case -1:
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(!"This should never be reached");
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
ButtonEvent
|
||||
ButtonEvent::from_string(const std::string& str)
|
||||
{
|
||||
ButtonEvent ev;
|
||||
boost::char_separator<char> sep(":", "", boost::keep_empty_tokens);
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
|
||||
int j = 0;
|
||||
tokenizer tokens(str, sep);
|
||||
for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
int type, code;
|
||||
if (!str2event(*i, type, code))
|
||||
{
|
||||
throw std::runtime_error("Couldn't convert '" + str + "' to ButtonEvent");
|
||||
}
|
||||
else
|
||||
{
|
||||
ev = ButtonEvent::create(type, code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (ev.type)
|
||||
{
|
||||
case EV_REL:
|
||||
switch(j) {
|
||||
case 1: ev.rel.value = boost::lexical_cast<int>(*i); break;
|
||||
case 2: ev.rel.repeat = boost::lexical_cast<int>(*i); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
/* EOF */
|
53
src/button_event.hpp
Normal file
53
src/button_event.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2010 Ingo Ruhnke <grumbel@gmx.de>
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_XBOXDRV_BUTTON_EVENT_HPP
|
||||
#define HEADER_XBOXDRV_BUTTON_EVENT_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
struct ButtonEvent
|
||||
{
|
||||
static ButtonEvent invalid() { return create(-1, -1); }
|
||||
static ButtonEvent create(int type, int code);
|
||||
static ButtonEvent from_string(const std::string& str);
|
||||
|
||||
/** EV_KEY, EV_ABS, EV_REL */
|
||||
int type;
|
||||
|
||||
/** BTN_A, REL_X, ABS_X, ... */
|
||||
int code;
|
||||
|
||||
union {
|
||||
struct {
|
||||
int repeat;
|
||||
int value;
|
||||
} rel;
|
||||
|
||||
struct {
|
||||
int value;
|
||||
} abs;
|
||||
|
||||
struct {
|
||||
} key;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
165
src/uinput.cpp
165
src/uinput.cpp
|
@ -31,172 +31,7 @@
|
|||
|
||||
#include "xboxmsg.hpp"
|
||||
#include "uinput.hpp"
|
||||
|
||||
ButtonEvent
|
||||
ButtonEvent::create(int type, int code)
|
||||
{
|
||||
ButtonEvent ev;
|
||||
ev.type = type;
|
||||
ev.code = code;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EV_REL:
|
||||
ev.rel.repeat = 100;
|
||||
ev.rel.value = 3;
|
||||
break;
|
||||
|
||||
case EV_ABS:
|
||||
throw std::runtime_error("Using EV_ABS for ButtonEvent is currently not supported");
|
||||
ev.abs.value = 1;
|
||||
break;
|
||||
|
||||
case EV_KEY:
|
||||
break;
|
||||
|
||||
case -1:
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(!"This should never be reached");
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
ButtonEvent
|
||||
ButtonEvent::from_string(const std::string& str)
|
||||
{
|
||||
ButtonEvent ev;
|
||||
boost::char_separator<char> sep(":", "", boost::keep_empty_tokens);
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
|
||||
int j = 0;
|
||||
tokenizer tokens(str, sep);
|
||||
for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
int type, code;
|
||||
if (!str2event(*i, type, code))
|
||||
{
|
||||
throw std::runtime_error("Couldn't convert '" + str + "' to ButtonEvent");
|
||||
}
|
||||
else
|
||||
{
|
||||
ev = ButtonEvent::create(type, code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (ev.type)
|
||||
{
|
||||
case EV_REL:
|
||||
switch(j) {
|
||||
case 1: ev.rel.value = boost::lexical_cast<int>(*i); break;
|
||||
case 2: ev.rel.repeat = boost::lexical_cast<int>(*i); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
AxisEvent
|
||||
AxisEvent::create(int type, int code, int fuzz, int flat)
|
||||
{
|
||||
AxisEvent ev;
|
||||
ev.type = type;
|
||||
ev.code = code;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EV_REL:
|
||||
ev.rel.repeat = 10;
|
||||
ev.rel.value = 5;
|
||||
break;
|
||||
|
||||
case EV_ABS:
|
||||
ev.abs.fuzz = fuzz;
|
||||
ev.abs.flat = flat;
|
||||
break;
|
||||
|
||||
case EV_KEY:
|
||||
ev.key.secondary_code = code;
|
||||
ev.key.threshold = 8000;
|
||||
break;
|
||||
|
||||
case -1:
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(!"This should never be reached");
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
AxisEvent
|
||||
AxisEvent::from_string(const std::string& str)
|
||||
{
|
||||
AxisEvent ev;
|
||||
|
||||
boost::char_separator<char> sep(":", "", boost::keep_empty_tokens);
|
||||
boost::tokenizer<boost::char_separator<char> > tokenizer(str, sep);
|
||||
|
||||
std::vector<std::string> tokens;
|
||||
std::copy(tokenizer.begin(), tokenizer.end(), std::back_inserter(tokens));
|
||||
|
||||
int j = 0;
|
||||
for(std::vector<std::string>::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
int type, code;
|
||||
if (!str2event(*i, type, code))
|
||||
{
|
||||
throw std::runtime_error("Couldn't convert '" + str + "' to AxisEvent");
|
||||
}
|
||||
else
|
||||
{
|
||||
ev = AxisEvent::create(type, code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (ev.type)
|
||||
{
|
||||
case EV_ABS:
|
||||
break;
|
||||
|
||||
case EV_REL:
|
||||
switch(j) {
|
||||
case 1: ev.rel.value = boost::lexical_cast<int>(*i); break;
|
||||
case 2: ev.rel.repeat = boost::lexical_cast<int>(*i); break;
|
||||
}
|
||||
break;
|
||||
|
||||
case EV_KEY:
|
||||
switch(j) {
|
||||
case 1:
|
||||
{
|
||||
int type;
|
||||
str2event(*i, type, ev.key.secondary_code);
|
||||
assert(type == EV_KEY);
|
||||
}
|
||||
break;
|
||||
case 2: ev.key.threshold = boost::lexical_cast<int>(*i); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
uInputCfg::uInputCfg() :
|
||||
device_name("Xbox Gamepad (userspace driver)"),
|
||||
trigger_as_button(false),
|
||||
|
|
|
@ -19,77 +19,20 @@
|
|||
#ifndef HEADER_UINPUT_HPP
|
||||
#define HEADER_UINPUT_HPP
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "xpad_device.hpp"
|
||||
#include "xboxdrv.hpp"
|
||||
#include "linux_uinput.hpp"
|
||||
#include "axis_event.hpp"
|
||||
#include "button_event.hpp"
|
||||
#include "evdev_helper.hpp"
|
||||
#include "linux_uinput.hpp"
|
||||
#include "xboxdrv.hpp"
|
||||
#include "xpad_device.hpp"
|
||||
|
||||
class Xbox360Msg;
|
||||
class Xbox360GuitarMsg;
|
||||
class XboxMsg;
|
||||
|
||||
struct ButtonEvent
|
||||
{
|
||||
static ButtonEvent invalid() { return create(-1, -1); }
|
||||
static ButtonEvent create(int type, int code);
|
||||
static ButtonEvent from_string(const std::string& str);
|
||||
|
||||
/** EV_KEY, EV_ABS, EV_REL */
|
||||
int type;
|
||||
|
||||
/** BTN_A, REL_X, ABS_X, ... */
|
||||
int code;
|
||||
|
||||
union {
|
||||
struct {
|
||||
int repeat;
|
||||
int value;
|
||||
} rel;
|
||||
|
||||
struct {
|
||||
int value;
|
||||
} abs;
|
||||
|
||||
struct {
|
||||
} key;
|
||||
};
|
||||
};
|
||||
|
||||
struct AxisEvent
|
||||
{
|
||||
static AxisEvent invalid() { return create(-1, -1); }
|
||||
static AxisEvent create(int type, int code, int fuzz = 0, int flat = 0);
|
||||
static AxisEvent from_string(const std::string& str);
|
||||
|
||||
/** EV_KEY, EV_ABS, EV_REL */
|
||||
int type;
|
||||
|
||||
/** BTN_A, REL_X, ABS_X, ... */
|
||||
int code;
|
||||
|
||||
union {
|
||||
struct {
|
||||
int repeat;
|
||||
float value;
|
||||
} rel;
|
||||
|
||||
struct {
|
||||
int fuzz;
|
||||
int flat;
|
||||
} abs;
|
||||
|
||||
struct {
|
||||
int secondary_code;
|
||||
int threshold;
|
||||
} key;
|
||||
};
|
||||
};
|
||||
|
||||
class uInputCfg
|
||||
{
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_XBOX360_HPP
|
||||
#define HEADER_XBOX360_HPP
|
||||
#ifndef HEADER_XBOXDRV_XBOXDRV_HPP
|
||||
#define HEADER_XBOXDRV_XBOXDRV_HPP
|
||||
|
||||
#include "xboxmsg.hpp"
|
||||
|
||||
struct XPadDevice;
|
||||
class CommandLineOptions;
|
||||
class uInput;
|
||||
class XboxGenericController;
|
||||
|
|
Loading…
Add table
Reference in a new issue