Implemented user configurable axis to abs mapping (i.e. --ui-axismap X1=ABS_X)

This commit is contained in:
Ingo Ruhnke 2010-12-10 19:01:43 +01:00
parent c619880ad1
commit aaa39f00c9
6 changed files with 85 additions and 10 deletions

View file

@ -111,9 +111,10 @@ AxisEvent::from_string(const std::string& str)
break;
case EV_KEY:
return key_from_string(str);
ev = key_from_string(str);
case -1:
std::cout << "--------- invalid --------------" << std::endl;
ev = invalid();
break;
@ -121,8 +122,7 @@ AxisEvent::from_string(const std::string& str)
assert(!"AxisEvent::from_string(): should never be reached");
}
if (false)
std::cout << "AxisEvent::from_string():\n in: " << str << "\n out: " << ev.str() << std::endl;
std::cout << "AxisEvent::from_string():\n in: " << str << "\n out: " << ev.str() << std::endl;
return ev;
}
@ -134,14 +134,14 @@ AxisEvent::abs_from_string(const std::string& str)
boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
AxisEvent ev = create_key();
int j = 0;
int code = -1;
for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
{
switch(j)
{
case 0:
code = str2abs(*i);
break;
default:
@ -153,8 +153,15 @@ AxisEvent::abs_from_string(const std::string& str)
{
throw std::runtime_error("AxisEvent::abs_from_string(): at least one argument required: " + str);
}
return ev;
else if (j > 1)
{
throw std::runtime_error("AxisEvent::abs_from_string(): invalid extra arguments in " + str);
}
else
{
AxisEvent ev = create_abs(DEVICEID_AUTO, code, -1, -1, 0, 0);
return ev;
}
}
AxisEvent
@ -352,6 +359,16 @@ AxisEvent::send(uInput& uinput, int old_value, int value) const
}
}
void
AxisEvent::set_axis_range(int min, int max)
{
if (type == EV_ABS)
{
abs.min = min;
abs.max = max;
}
}
std::string
AxisEvent::str() const
{
@ -359,7 +376,9 @@ AxisEvent::str() const
switch(type)
{
case EV_ABS:
out << abs.code.device_id << "-" << abs.code.code << ":" << abs.min << ":" << abs.max << ":" << abs.fuzz << ":" << abs.flat;
out << abs.code.device_id << "-" << abs.code.code << ":"
<< abs.min << ":" << abs.max << ":"
<< abs.fuzz << ":" << abs.flat;
break;
case EV_REL:

View file

@ -38,6 +38,7 @@ public:
static AxisEvent create_rel();
static AxisEvent create_abs();
/** If an AbsAxisEvent gets created the user has to set min/max! */
static AxisEvent from_string(const std::string& str);
private:
@ -55,6 +56,8 @@ public:
std::string str() const;
void set_axis_range(int min, int max);
private:
/** EV_KEY, EV_ABS, EV_REL */
int type;

View file

@ -770,8 +770,14 @@ CommandLineParser::set_ui_axismap(const std::string& name, const std::string& va
{
XboxAxis axis = string2axis(name);
AxisEvent event = AxisEvent::from_string(value);
if (axis != XBOX_AXIS_UNKNOWN)
{
event.set_axis_range(get_axis_min(axis),
get_axis_max(axis));
std::cout << "set_ui_axismap: " << name << " = " << value << std::endl;
m_options->uinput_config.axis_map[axis] = event;
}
else

View file

@ -66,8 +66,8 @@ uInputCfg::uInputCfg() :
btn_map.bind(XBOX_DPAD_RIGHT, ButtonEvent::create_key(BTN_BASE4));
// Axis Mapping
axis_map[XBOX_AXIS_X1] = AxisEvent::create_abs(DEVICEID_AUTO, ABS_X, -32768, 32767, 0, 0);
axis_map[XBOX_AXIS_Y1] = AxisEvent::create_abs(DEVICEID_AUTO, ABS_Y, -32768, 32767, 0, 0);
axis_map[XBOX_AXIS_X1] = AxisEvent::create_abs(DEVICEID_AUTO, ABS_X, -32768, 32767, 0, 0);
axis_map[XBOX_AXIS_Y1] = AxisEvent::create_abs(DEVICEID_AUTO, ABS_Y, -32768, 32767, 0, 0);
axis_map[XBOX_AXIS_X2] = AxisEvent::create_abs(DEVICEID_AUTO, ABS_RX, -32768, 32767, 0, 0);
axis_map[XBOX_AXIS_Y2] = AxisEvent::create_abs(DEVICEID_AUTO, ABS_RY, -32768, 32767, 0, 0);
axis_map[XBOX_AXIS_LT] = AxisEvent::create_abs(DEVICEID_AUTO, ABS_BRAKE, 0, 255, 0, 0);

View file

@ -991,5 +991,49 @@ std::string btn2string(XboxButton btn)
}
return "unknown";
}
int get_axis_min(XboxAxis axis)
{
switch(axis)
{
case XBOX_AXIS_X1: return -32768;
case XBOX_AXIS_Y1: return -32768;
case XBOX_AXIS_X2: return -32768;
case XBOX_AXIS_Y2: return -32768;
case XBOX_AXIS_LT: return 0;
case XBOX_AXIS_RT: return 0;
case XBOX_AXIS_DPAD_X: return -1;
case XBOX_AXIS_DPAD_Y: return -1;
case XBOX_AXIS_TRIGGER: return -255;
default: assert(!"never reached");
}
}
int get_axis_max(XboxAxis axis)
{
switch(axis)
{
case XBOX_AXIS_X1: return 32767;
case XBOX_AXIS_Y1: return 32767;
case XBOX_AXIS_X2: return 32767;
case XBOX_AXIS_Y2: return 32767;
case XBOX_AXIS_LT: return 255;
case XBOX_AXIS_RT: return 255;
case XBOX_AXIS_DPAD_X: return 1;
case XBOX_AXIS_DPAD_Y: return 1;
case XBOX_AXIS_TRIGGER: return 255;
default: assert(!"never reached");
}
}
/* EOF */

View file

@ -256,6 +256,9 @@ XboxAxis string2axis(const std::string& str_);
std::string btn2string(XboxButton btn);
std::string axis2string(XboxAxis axis);
int get_axis_min(XboxAxis axis);
int get_axis_max(XboxAxis axis);
std::string gamepadtype_to_string(const GamepadType& type);
std::string gamepadtype_to_macro_string(const GamepadType& type);