Some further Modifier cleanup

This commit is contained in:
Ingo Ruhnke 2011-01-16 19:28:47 +01:00
parent aa483bc9ca
commit 541ba1d8f3
17 changed files with 114 additions and 385 deletions

5
NEWS
View file

@ -2,6 +2,11 @@ xboxdrv 0.6.5 - (??/Jan/2011)
============================= =============================
* switched to libusb-1.0 * switched to libusb-1.0
* -D, --daemon replaces xboxdrv-daemon
* --daemon supports hotpluging via libudev, even in applications that
don't support it themselves
* cleaned up axis/button modifier some more
* startup output got cleaned up
xboxdrv 0.6.4 - (13/Jan/2011) xboxdrv 0.6.4 - (13/Jan/2011)

View file

@ -776,7 +776,7 @@ CommandLineParser::print_version() const
void void
CommandLineParser::set_axismap(const std::string& name, const std::string& value) CommandLineParser::set_axismap(const std::string& name, const std::string& value)
{ {
m_options->controller.axis_map.push_back(AxisMapping::from_string(name, value)); m_options->controller.modifier.push_back(ModifierPtr(AxismapModifier::from_string(name, value)));
} }
void void
@ -814,25 +814,25 @@ CommandLineParser::set_evdev_keymap(const std::string& name, const std::string&
void void
CommandLineParser::set_relative_axis(const std::string& name, const std::string& value) CommandLineParser::set_relative_axis(const std::string& name, const std::string& value)
{ {
m_options->controller.relative_axis_map.push_back(RelativeAxisMapping::from_string(name, value)); m_options->controller.modifier.push_back(ModifierPtr(RelativeAxisModifier::from_string(name, value)));
} }
void void
CommandLineParser::set_autofire(const std::string& name, const std::string& value) CommandLineParser::set_autofire(const std::string& name, const std::string& value)
{ {
m_options->controller.autofire_map.push_back(AutofireMapping::from_string(name, value)); m_options->controller.modifier.push_back(ModifierPtr(AutofireModifier::from_string(name, value)));
} }
void void
CommandLineParser::set_calibration(const std::string& name, const std::string& value) CommandLineParser::set_calibration(const std::string& name, const std::string& value)
{ {
m_options->controller.calibration_map.push_back(CalibrationMapping::from_string(name, value)); m_options->controller.modifier.push_back(ModifierPtr(CalibrationModifier::from_string(name, value)));
} }
void void
CommandLineParser::set_axis_sensitivity(const std::string& name, const std::string& value) CommandLineParser::set_axis_sensitivity(const std::string& name, const std::string& value)
{ {
m_options->controller.axis_sensitivity_map.push_back(AxisSensitivityMapping::from_string(name, value)); m_options->controller.modifier.push_back(ModifierPtr(AxisSensitivityModifier::from_string(name, value)));
} }
void void

View file

@ -38,19 +38,21 @@ class Modifier
public: public:
static ModifierPtr create(const std::string& str); static ModifierPtr create(const std::string& str);
/** Priority defines the sort order of modifiers in the modifier
stack, well defined order is important as some modifiers would
otherwise lead to weird results */
enum Priority enum Priority
{ {
kAutofirePriority,
kAxisSensitivityPriority,
kAxismapPriority,
kButtonMapPriority,
kCalibrationPriority, kCalibrationPriority,
kDeadzonePriority, kDeadzonePriority,
kDpadRotationPriority, kSquareAxisPriority,
kFourWayRestrictor, kAxisSensitivityPriority,
kFourWayRestrictorPriority, kFourWayRestrictorPriority,
kDpadRotationPriority,
kAutofirePriority,
kRelativeAxisPriority, kRelativeAxisPriority,
kSquareAxisPriority kAxismapPriority,
kButtonMapPriority
}; };
public: public:

View file

@ -20,18 +20,17 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
AutofireMapping AutofireModifier*
AutofireMapping::from_string(const std::string& lhs, const std::string& rhs) AutofireModifier::from_string(const std::string& lhs, const std::string& rhs)
{ {
/* Format of str: A={ON-DELAY}[:{OFF-DELAY}] /* Format of str: A={ON-DELAY}[:{OFF-DELAY}]
Examples: A=10 or A=10:50 Examples: A=10 or A=10:50
if OFF-DELAY == nil then ON-DELAY = OFF-DELAY if OFF-DELAY == nil then ON-DELAY = OFF-DELAY
*/ */
AutofireMapping mapping(string2btn(lhs), boost::lexical_cast<int>(rhs)); return new AutofireModifier(string2btn(lhs), boost::lexical_cast<int>(rhs));
return mapping;
} }
AutofireMapping::AutofireMapping(XboxButton button, int frequency) : AutofireModifier::AutofireModifier(XboxButton button, int frequency) :
m_button(button), m_button(button),
m_frequency(frequency), m_frequency(frequency),
m_button_timer(0) m_button_timer(0)
@ -39,7 +38,7 @@ AutofireMapping::AutofireMapping(XboxButton button, int frequency) :
} }
void void
AutofireMapping::update(int msec_delta, XboxGenericMsg& msg) AutofireModifier::update(int msec_delta, XboxGenericMsg& msg)
{ {
if (get_button(msg, m_button)) if (get_button(msg, m_button))
{ {
@ -65,44 +64,4 @@ AutofireMapping::update(int msec_delta, XboxGenericMsg& msg)
} }
} }
AutofireModifier::AutofireModifier(const std::vector<AutofireMapping>& autofire_map) :
m_autofire_map(autofire_map),
m_button_timer()
{
for(std::vector<AutofireMapping>::const_iterator i = m_autofire_map.begin(); i != m_autofire_map.end(); ++i)
{
m_button_timer.push_back(0);
}
}
void
AutofireModifier::update(int msec_delta, XboxGenericMsg& msg)
{
for(size_t i = 0; i < m_autofire_map.size(); ++i)
{
if (get_button(msg, m_autofire_map[i].m_button))
{
m_button_timer[i] += msec_delta;
if (m_button_timer[i] > m_autofire_map[i].m_frequency)
{
set_button(msg, m_autofire_map[i].m_button, 1);
m_button_timer[i] = 0; // FIXME: we ignoring the passed time
}
else if (m_button_timer[i] > m_autofire_map[i].m_frequency/2)
{
set_button(msg, m_autofire_map[i].m_button, 0);
}
else
{
set_button(msg, m_autofire_map[i].m_button, 1);
}
}
else
{
m_button_timer[i] = 0;
}
}
}
/* EOF */ /* EOF */

View file

@ -23,13 +23,13 @@
#include "modifier.hpp" #include "modifier.hpp"
class AutofireMapping class AutofireModifier : public Modifier
{ {
public: public:
static AutofireMapping from_string(const std::string& lhs, const std::string& rhs); static AutofireModifier* from_string(const std::string& lhs, const std::string& rhs);
public: public:
AutofireMapping(XboxButton button, int frequency); AutofireModifier(XboxButton button, int frequency);
void update(int msec_delta, XboxGenericMsg& msg); void update(int msec_delta, XboxGenericMsg& msg);
@ -42,20 +42,6 @@ public:
int m_button_timer; int m_button_timer;
}; };
class AutofireModifier : public Modifier
{
private:
std::vector<AutofireMapping> m_autofire_map;
std::vector<int> m_button_timer;
public:
AutofireModifier(const std::vector<AutofireMapping>& autofire_map);
void update(int msec_delta, XboxGenericMsg& msg);
Modifier::Priority get_priority() const { return Modifier::kAutofirePriority; };
};
#endif #endif
/* EOF */ /* EOF */

View file

@ -21,26 +21,25 @@
#include "axis_sensitivty_modifier.hpp" #include "axis_sensitivty_modifier.hpp"
AxisSensitivityMapping AxisSensitivityModifier*
AxisSensitivityMapping::from_string(const std::string& lhs, const std::string& rhs) AxisSensitivityModifier::from_string(const std::string& lhs, const std::string& rhs)
{ {
/* /*
Format of str: X1=SENSITIVITY Format of str: X1=SENSITIVITY
Example: X1=2.0 Example: X1=2.0
*/ */
AxisSensitivityMapping mapping(string2axis(lhs), return new AxisSensitivityModifier(string2axis(lhs),
boost::lexical_cast<float>(rhs)); boost::lexical_cast<float>(rhs));
return mapping;
} }
AxisSensitivityMapping::AxisSensitivityMapping(XboxAxis axis, float sensitivity) : AxisSensitivityModifier::AxisSensitivityModifier(XboxAxis axis, float sensitivity) :
m_axis(axis), m_axis(axis),
m_sensitivity(sensitivity) m_sensitivity(sensitivity)
{ {
} }
void void
AxisSensitivityMapping::update(int msec_delta, XboxGenericMsg& msg) AxisSensitivityModifier::update(int msec_delta, XboxGenericMsg& msg)
{ {
float pos = get_axis_float(msg, m_axis); float pos = get_axis_float(msg, m_axis);
float t = powf(2, m_sensitivity); float t = powf(2, m_sensitivity);
@ -57,31 +56,4 @@ AxisSensitivityMapping::update(int msec_delta, XboxGenericMsg& msg)
} }
} }
AxisSensitivityModifier::AxisSensitivityModifier(const std::vector<AxisSensitivityMapping>& axis_sensitivity_map) :
m_axis_sensitivity_map(axis_sensitivity_map)
{
}
void
AxisSensitivityModifier::update(int msec_delta, XboxGenericMsg& msg)
{
for(std::vector<AxisSensitivityMapping>::const_iterator i = m_axis_sensitivity_map.begin();
i != m_axis_sensitivity_map.end(); ++i)
{
float pos = get_axis_float(msg, i->m_axis);
float t = powf(2, i->m_sensitivity);
if (pos > 0)
{
pos = powf(1.0f - powf(1.0f - pos, t), 1 / t);
set_axis_float(msg, i->m_axis, pos);
}
else
{
pos = powf(1.0f - powf(1.0f - -pos, t), 1 / t);
set_axis_float(msg, i->m_axis, -pos);
}
}
}
/* EOF */ /* EOF */

View file

@ -21,13 +21,13 @@
#include "modifier.hpp" #include "modifier.hpp"
class AxisSensitivityMapping class AxisSensitivityModifier : public Modifier
{ {
public: public:
static AxisSensitivityMapping from_string(const std::string& lhs, const std::string& rhs); static AxisSensitivityModifier* from_string(const std::string& lhs, const std::string& rhs);
public: public:
AxisSensitivityMapping(XboxAxis axis, float sensitivity); AxisSensitivityModifier(XboxAxis axis, float sensitivity);
void update(int msec_delta, XboxGenericMsg& msg); void update(int msec_delta, XboxGenericMsg& msg);
@ -38,23 +38,6 @@ public:
float m_sensitivity; float m_sensitivity;
}; };
class AxisSensitivityModifier : public Modifier
{
private:
std::vector<AxisSensitivityMapping> m_axis_sensitivity_map;
public:
AxisSensitivityModifier(const std::vector<AxisSensitivityMapping>& axis_sensitivity_map);
void update(int msec_delta, XboxGenericMsg& msg);
Modifier::Priority get_priority() const { return Modifier::kAxisSensitivityPriority; };
private:
AxisSensitivityModifier(const AxisSensitivityModifier&);
AxisSensitivityModifier& operator=(const AxisSensitivityModifier&);
};
#endif #endif
/* EOF */ /* EOF */

View file

@ -19,6 +19,7 @@
#include "axismap_modifier.hpp" #include "axismap_modifier.hpp"
#include <boost/tokenizer.hpp> #include <boost/tokenizer.hpp>
#include <memory>
/** converts the arbitary range to [-1,1] */ /** converts the arbitary range to [-1,1] */
inline float to_float(int value, int min, int max) inline float to_float(int value, int min, int max)
@ -26,19 +27,19 @@ inline float to_float(int value, int min, int max)
return static_cast<float>(value - min) / static_cast<float>(max - min) * 2.0f - 1.0f; return static_cast<float>(value - min) / static_cast<float>(max - min) * 2.0f - 1.0f;
} }
AxisMapping AxismapModifier*
AxisMapping::from_string(const std::string& lhs_, const std::string& rhs) AxismapModifier::from_string(const std::string& lhs_, const std::string& rhs)
{ {
std::string lhs = lhs_; std::string lhs = lhs_;
AxisMapping mapping; std::auto_ptr<AxismapModifier> mapping(new AxismapModifier);
mapping.m_invert = false; mapping->m_invert = false;
mapping.m_lhs = XBOX_AXIS_UNKNOWN; mapping->m_lhs = XBOX_AXIS_UNKNOWN;
mapping.m_rhs = XBOX_AXIS_UNKNOWN; mapping->m_rhs = XBOX_AXIS_UNKNOWN;
if (lhs[0] == '-') if (lhs[0] == '-')
{ {
mapping.m_invert = true; mapping->m_invert = true;
lhs = lhs.substr(1); lhs = lhs.substr(1);
} }
@ -49,31 +50,34 @@ AxisMapping::from_string(const std::string& lhs_, const std::string& rhs)
{ {
switch(idx) switch(idx)
{ {
case 0: mapping.m_lhs = string2axis(*t); break; case 0: mapping->m_lhs = string2axis(*t); break;
default: mapping.m_filters.push_back(AxisFilter::from_string(*t)); default: mapping->m_filters.push_back(AxisFilter::from_string(*t));
} }
} }
if (rhs.empty()) if (rhs.empty())
{ {
mapping.m_rhs = mapping.m_lhs; mapping->m_rhs = mapping->m_lhs;
} }
else else
{ {
mapping.m_rhs = string2axis(rhs); mapping->m_rhs = string2axis(rhs);
} }
if (mapping.m_lhs == XBOX_AXIS_UNKNOWN || if (mapping->m_lhs == XBOX_AXIS_UNKNOWN ||
mapping.m_rhs == XBOX_AXIS_UNKNOWN) mapping->m_rhs == XBOX_AXIS_UNKNOWN)
{ {
throw std::runtime_error("Couldn't convert string \"" + lhs + "=" + rhs + "\" to axis mapping"); throw std::runtime_error("Couldn't convert string \"" + lhs + "=" + rhs + "\" to axis mapping");
} }
return mapping; return mapping.release();
} }
AxismapModifier::AxismapModifier(const std::vector<AxisMapping>& axismap) : AxismapModifier::AxismapModifier() :
m_axismap(axismap) m_lhs(XBOX_AXIS_UNKNOWN),
m_rhs(XBOX_AXIS_UNKNOWN),
m_invert(false),
m_filters()
{ {
} }
@ -83,42 +87,34 @@ AxismapModifier::update(int msec_delta, XboxGenericMsg& msg)
XboxGenericMsg newmsg = msg; XboxGenericMsg newmsg = msg;
// update all filters in all mappings // update all filters in all mappings
for(std::vector<AxisMapping>::iterator i = m_axismap.begin(); i != m_axismap.end(); ++i) for(std::vector<AxisFilterPtr>::iterator j = m_filters.begin(); j != m_filters.end(); ++j)
{ {
for(std::vector<AxisFilterPtr>::iterator j = i->m_filters.begin(); j != i->m_filters.end(); ++j) (*j)->update(msec_delta);
{
(*j)->update(msec_delta);
}
} }
// clear all values in the new msg // clear all values in the new msg
for(std::vector<AxisMapping>::iterator i = m_axismap.begin(); i != m_axismap.end(); ++i) set_axis_float(newmsg, m_lhs, 0);
int min = get_axis_min(m_lhs);
int max = get_axis_max(m_lhs);
int value = get_axis(msg, m_lhs);
for(std::vector<AxisFilterPtr>::iterator j = m_filters.begin(); j != m_filters.end(); ++j)
{ {
set_axis_float(newmsg, i->m_lhs, 0); value = (*j)->filter(value, min, max);
} }
for(std::vector<AxisMapping>::iterator i = m_axismap.begin(); i != m_axismap.end(); ++i) float lhs = to_float(value, min, max);
float nrhs = get_axis_float(newmsg, m_rhs);
if (m_invert)
{ {
int min = get_axis_min(i->m_lhs); lhs = -lhs;
int max = get_axis_max(i->m_lhs);
int value = get_axis(msg, i->m_lhs);
for(std::vector<AxisFilterPtr>::iterator j = i->m_filters.begin(); j != i->m_filters.end(); ++j)
{
value = (*j)->filter(value, min, max);
}
float lhs = to_float(value, min, max);
float nrhs = get_axis_float(newmsg, i->m_rhs);
if (i->m_invert)
{
lhs = -lhs;
}
set_axis_float(newmsg, i->m_rhs, std::max(std::min(nrhs + lhs, 1.0f), -1.0f));
} }
msg = newmsg;
set_axis_float(newmsg, m_rhs, std::max(std::min(nrhs + lhs, 1.0f), -1.0f));
msg = newmsg;
} }
/* EOF */ /* EOF */

View file

@ -23,10 +23,17 @@
#include "modifier.hpp" #include "modifier.hpp"
class AxisMapping class AxismapModifier : public Modifier
{ {
public: public:
static AxisMapping from_string(const std::string& lhs, const std::string& rhs); static AxismapModifier* from_string(const std::string& lhs, const std::string& rhs);
public:
AxismapModifier();
void update(int msec_delta, XboxGenericMsg& msg);
Modifier::Priority get_priority() const { return Modifier::kAxismapPriority; };
public: public:
XboxAxis m_lhs; XboxAxis m_lhs;
@ -35,23 +42,6 @@ public:
std::vector<AxisFilterPtr> m_filters; std::vector<AxisFilterPtr> m_filters;
}; };
class AxismapModifier : public Modifier
{
private:
std::vector<AxisMapping> m_axismap;
public:
AxismapModifier(const std::vector<AxisMapping>& axismap);
void update(int msec_delta, XboxGenericMsg& msg);
Modifier::Priority get_priority() const { return Modifier::kAxismapPriority; };
private:
AxismapModifier(const AxismapModifier&);
AxismapModifier& operator=(const AxismapModifier&);
};
#endif #endif
/* EOF */ /* EOF */

View file

@ -30,13 +30,15 @@ int clamp(int lhs, int rhs, int v)
} // namespace } // namespace
CalibrationMapping CalibrationMapping::from_string(const std::string& lhs, const std::string& rhs) CalibrationModifier*
CalibrationModifier::from_string(const std::string& lhs, const std::string& rhs)
{ {
CalibrationMapping mapping; std::auto_ptr<CalibrationModifier> mapping(new CalibrationModifier);
mapping.m_axis = string2axis(lhs);
mapping.m_min = -32768; mapping->m_axis = string2axis(lhs);
mapping.m_center = 0; mapping->m_min = -32768;
mapping.m_max = 32767; mapping->m_center = 0;
mapping->m_max = 32767;
boost::char_separator<char> sep(":", "", boost::keep_empty_tokens); boost::char_separator<char> sep(":", "", boost::keep_empty_tokens);
typedef boost::tokenizer<boost::char_separator<char> > tokenizer; typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
@ -52,11 +54,11 @@ CalibrationMapping CalibrationMapping::from_string(const std::string& lhs, const
try try
{ {
if (j == 0) if (j == 0)
mapping.m_min = boost::lexical_cast<int>(*i); mapping->m_min = boost::lexical_cast<int>(*i);
else if (j == 1) else if (j == 1)
mapping.m_center = boost::lexical_cast<int>(*i); mapping->m_center = boost::lexical_cast<int>(*i);
else if (j == 2) else if (j == 2)
mapping.m_max = boost::lexical_cast<int>(*i); mapping->m_max = boost::lexical_cast<int>(*i);
else else
throw std::runtime_error("--calibration: to many arguments given, syntax is 'AXIS=MIN:CENTER:MAX'"); throw std::runtime_error("--calibration: to many arguments given, syntax is 'AXIS=MIN:CENTER:MAX'");
} }
@ -67,13 +69,13 @@ CalibrationMapping CalibrationMapping::from_string(const std::string& lhs, const
} }
} }
if (!(mapping.m_min <= mapping.m_center && mapping.m_center <= mapping.m_max)) if (!(mapping->m_min <= mapping->m_center && mapping->m_center <= mapping->m_max))
throw std::runtime_error("Order wrong 'AXIS=MIN:CENTER:MAX'"); throw std::runtime_error("Order wrong 'AXIS=MIN:CENTER:MAX'");
return mapping; return mapping.release();
} }
CalibrationMapping::CalibrationMapping() : CalibrationModifier::CalibrationModifier() :
m_axis(XBOX_AXIS_UNKNOWN), m_axis(XBOX_AXIS_UNKNOWN),
m_min(0), m_min(0),
m_center(0), m_center(0),
@ -82,7 +84,7 @@ CalibrationMapping::CalibrationMapping() :
} }
void void
CalibrationMapping::update(int msec_delta, XboxGenericMsg& msg) CalibrationModifier::update(int msec_delta, XboxGenericMsg& msg)
{ {
int value = get_axis(msg, m_axis); int value = get_axis(msg, m_axis);
@ -96,27 +98,4 @@ CalibrationMapping::update(int msec_delta, XboxGenericMsg& msg)
set_axis(msg, m_axis, clamp(-32768, 32767, value)); set_axis(msg, m_axis, clamp(-32768, 32767, value));
} }
CalibrationModifier::CalibrationModifier(const std::vector<CalibrationMapping>& calibration_map) :
m_calibration_map(calibration_map)
{
}
void
CalibrationModifier::update(int msec_delta, XboxGenericMsg& msg)
{
for(std::vector<CalibrationMapping>::const_iterator i = m_calibration_map.begin(); i != m_calibration_map.end(); ++i)
{
int value = get_axis(msg, i->m_axis);
if (value < i->m_center)
value = 32768 * (value - i->m_center) / (i->m_center - i->m_min);
else if (value > i->m_center)
value = 32767 * (value - i->m_center) / (i->m_max - i->m_center);
else
value = 0;
set_axis(msg, i->m_axis, clamp(-32768, 32767, value));
}
}
/* EOF */ /* EOF */

View file

@ -23,13 +23,13 @@
#include "modifier.hpp" #include "modifier.hpp"
class CalibrationMapping : public Modifier class CalibrationModifier : public Modifier
{ {
public: public:
static CalibrationMapping from_string(const std::string& lhs, const std::string& rhs); static CalibrationModifier* from_string(const std::string& lhs, const std::string& rhs);
public: public:
CalibrationMapping(); CalibrationModifier();
void update(int msec_delta, XboxGenericMsg& msg); void update(int msec_delta, XboxGenericMsg& msg);
@ -42,23 +42,6 @@ public:
int m_max; int m_max;
}; };
class CalibrationModifier : public Modifier
{
private:
std::vector<CalibrationMapping> m_calibration_map;
public:
CalibrationModifier(const std::vector<CalibrationMapping>& calibration_map);
void update(int msec_delta, XboxGenericMsg& msg);
Modifier::Priority get_priority() const { return Modifier::kCalibrationPriority; };
private:
CalibrationModifier(const CalibrationModifier&);
CalibrationModifier& operator=(const CalibrationModifier&);
};
#endif #endif
/* EOF */ /* EOF */

View file

@ -21,18 +21,18 @@
#include <boost/tokenizer.hpp> #include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
RelativeAxisMapping RelativeAxisModifier*
RelativeAxisMapping::from_string(const std::string& lhs, const std::string& rhs) RelativeAxisModifier::from_string(const std::string& lhs, const std::string& rhs)
{ {
/* Format of str: A={SPEED} */ /* Format of str: A={SPEED} */
RelativeAxisMapping mapping; std::auto_ptr<RelativeAxisModifier> mapping(new RelativeAxisModifier);
mapping.m_axis = string2axis(lhs); mapping->m_axis = string2axis(lhs);
mapping.m_speed = boost::lexical_cast<int>(rhs); mapping->m_speed = boost::lexical_cast<int>(rhs);
// FIXME: insert some error checking here // FIXME: insert some error checking here
return mapping; return mapping.release();
} }
RelativeAxisMapping::RelativeAxisMapping() : RelativeAxisModifier::RelativeAxisModifier() :
m_axis(XBOX_AXIS_UNKNOWN), m_axis(XBOX_AXIS_UNKNOWN),
m_speed(0), m_speed(0),
m_axis_state(0) m_axis_state(0)
@ -40,7 +40,7 @@ RelativeAxisMapping::RelativeAxisMapping() :
} }
void void
RelativeAxisMapping::update(int msec_delta, XboxGenericMsg& msg) RelativeAxisModifier::update(int msec_delta, XboxGenericMsg& msg)
{ {
int value = get_axis(msg, m_axis); int value = get_axis(msg, m_axis);
if (abs(value) > 4000 ) // FIXME: add proper deadzone handling if (abs(value) > 4000 ) // FIXME: add proper deadzone handling
@ -59,37 +59,4 @@ RelativeAxisMapping::update(int msec_delta, XboxGenericMsg& msg)
} }
} }
RelativeAxisModifier::RelativeAxisModifier(const std::vector<RelativeAxisMapping>& relative_axis_map) :
m_relative_axis_map(relative_axis_map),
m_axis_state()
{
for(size_t i = 0; i < m_relative_axis_map.size(); ++i)
{
m_axis_state.push_back(0);
}
}
void
RelativeAxisModifier::update(int msec_delta, XboxGenericMsg& msg)
{
for(size_t i = 0; i < m_relative_axis_map.size(); ++i)
{
int value = get_axis(msg, m_relative_axis_map[i].m_axis);
if (abs(value) > 4000 ) // FIXME: add proper deadzone handling
{
m_axis_state[i] += ((m_relative_axis_map[i].m_speed * value) / 32768) * msec_delta / 1000;
if (m_axis_state[i] < -32768)
m_axis_state[i] = -32768;
else if (m_axis_state[i] > 32767)
m_axis_state[i] = 32767;
set_axis(msg, m_relative_axis_map[i].m_axis, m_axis_state[i]);
}
else
{
set_axis(msg, m_relative_axis_map[i].m_axis, m_axis_state[i]);
}
}
}
/* EOF */ /* EOF */

View file

@ -21,13 +21,13 @@
#include "modifier.hpp" #include "modifier.hpp"
class RelativeAxisMapping : public Modifier class RelativeAxisModifier : public Modifier
{ {
public: public:
static RelativeAxisMapping from_string(const std::string& lhs, const std::string& rhs); static RelativeAxisModifier* from_string(const std::string& lhs, const std::string& rhs);
public: public:
RelativeAxisMapping(); RelativeAxisModifier();
void update(int msec_delta, XboxGenericMsg& msg); void update(int msec_delta, XboxGenericMsg& msg);
@ -40,24 +40,6 @@ public:
int m_axis_state; int m_axis_state;
}; };
class RelativeAxisModifier : public Modifier
{
private:
std::vector<RelativeAxisMapping> m_relative_axis_map;
std::vector<int> m_axis_state;
public:
RelativeAxisModifier(const std::vector<RelativeAxisMapping>& relative_axis_map);
void update(int msec_delta, XboxGenericMsg& msg);
Modifier::Priority get_priority() const { return Modifier::kRelativeAxisPriority; };
private:
RelativeAxisModifier(const RelativeAxisModifier&);
RelativeAxisModifier& operator=(const RelativeAxisModifier&);
};
#endif #endif
/* EOF */ /* EOF */

View file

@ -25,11 +25,6 @@ ControllerOptions::ControllerOptions() :
modifier(), modifier(),
deadzone(0), deadzone(0),
deadzone_trigger(0), deadzone_trigger(0),
axis_map(),
autofire_map(),
relative_axis_map(),
calibration_map(),
axis_sensitivity_map(),
square_axis(false), square_axis(false),
four_way_restrictor(false), four_way_restrictor(false),
dpad_rotation(0) dpad_rotation(0)

View file

@ -44,11 +44,6 @@ public:
std::vector<ModifierPtr> modifier; std::vector<ModifierPtr> modifier;
int deadzone; int deadzone;
int deadzone_trigger; int deadzone_trigger;
std::vector<AxisMapping> axis_map;
std::vector<AutofireMapping> autofire_map;
std::vector<RelativeAxisMapping> relative_axis_map;
std::vector<CalibrationMapping> calibration_map;
std::vector<AxisSensitivityMapping> axis_sensitivity_map;
bool square_axis; bool square_axis;
bool four_way_restrictor; bool four_way_restrictor;
int dpad_rotation; int dpad_rotation;

View file

@ -525,56 +525,6 @@ Xboxdrv::print_info(libusb_device* dev,
std::cout << "4-Way Restrictor: " << ((opts.controller.four_way_restrictor) ? "yes" : "no") << std::endl; std::cout << "4-Way Restrictor: " << ((opts.controller.four_way_restrictor) ? "yes" : "no") << std::endl;
std::cout << "Dpad Rotation: " << opts.controller.dpad_rotation * 45 << " degree" << std::endl; std::cout << "Dpad Rotation: " << opts.controller.dpad_rotation * 45 << " degree" << std::endl;
std::cout << "AxisMap: ";
if (opts.controller.axis_map.empty())
{
std::cout << "none" << std::endl;
}
else
{
for(std::vector<AxisMapping>::const_iterator i = opts.controller.axis_map.begin();
i != opts.controller.axis_map.end(); ++i)
{
if (i->m_invert)
std::cout << "-" << axis2string(i->m_lhs) << "->" << axis2string(i->m_rhs) << " ";
else
std::cout << axis2string(i->m_lhs) << "->" << axis2string(i->m_rhs) << " ";
}
std::cout << std::endl;
}
std::cout << "RelativeAxisMap: ";
if (opts.controller.relative_axis_map.empty())
{
std::cout << "none" << std::endl;
}
else
{
for(std::vector<RelativeAxisMapping>::const_iterator i = opts.controller.relative_axis_map.begin();
i != opts.controller.relative_axis_map.end();
++i)
{
std::cout << axis2string(i->m_axis) << "=" << i->m_speed << " ";
}
std::cout << std::endl;
}
std::cout << "AutofireMap: ";
if (opts.controller.autofire_map.empty())
{
std::cout << "none" << std::endl;
}
else
{
for(std::vector<AutofireMapping>::const_iterator i = opts.controller.autofire_map.begin();
i != opts.controller.autofire_map.end();
++i)
{
std::cout << btn2string(i->m_button) << "=" << i->m_frequency << " ";
}
std::cout << std::endl;
}
std::cout << "RumbleGain: " << opts.rumble_gain << std::endl; std::cout << "RumbleGain: " << opts.rumble_gain << std::endl;
std::cout << "ForceFeedback: " << ((opts.controller.uinput.force_feedback) ? "enabled" : "disabled") << std::endl; std::cout << "ForceFeedback: " << ((opts.controller.uinput.force_feedback) ? "enabled" : "disabled") << std::endl;
} }

View file

@ -99,33 +99,18 @@ XboxdrvThread::controller_loop(GamepadType type, uInput* uinput, const Options&
std::vector<ModifierPtr> modifier; std::vector<ModifierPtr> modifier;
// Create filter // Create filter
if (!opts.controller.calibration_map.empty())
modifier.push_back(ModifierPtr(new CalibrationModifier(opts.controller.calibration_map)));
if (opts.controller.deadzone != 0 || opts.controller.deadzone_trigger != 0) if (opts.controller.deadzone != 0 || opts.controller.deadzone_trigger != 0)
modifier.push_back(ModifierPtr(new DeadzoneModifier(opts.controller.deadzone, opts.controller.deadzone_trigger))); modifier.push_back(ModifierPtr(new DeadzoneModifier(opts.controller.deadzone, opts.controller.deadzone_trigger)));
if (opts.controller.square_axis) if (opts.controller.square_axis)
modifier.push_back(ModifierPtr(new SquareAxisModifier())); modifier.push_back(ModifierPtr(new SquareAxisModifier()));
if (!opts.controller.axis_sensitivity_map.empty())
modifier.push_back(ModifierPtr(new AxisSensitivityModifier(opts.controller.axis_sensitivity_map)));
if (opts.controller.four_way_restrictor) if (opts.controller.four_way_restrictor)
modifier.push_back(ModifierPtr(new FourWayRestrictorModifier())); modifier.push_back(ModifierPtr(new FourWayRestrictorModifier()));
if (opts.controller.dpad_rotation) if (opts.controller.dpad_rotation)
modifier.push_back(ModifierPtr(new DpadRotationModifier(opts.controller.dpad_rotation))); modifier.push_back(ModifierPtr(new DpadRotationModifier(opts.controller.dpad_rotation)));
if (!opts.controller.autofire_map.empty())
modifier.push_back(ModifierPtr(new AutofireModifier(opts.controller.autofire_map)));
if (!opts.controller.relative_axis_map.empty())
modifier.push_back(ModifierPtr(new RelativeAxisModifier(opts.controller.relative_axis_map)));
if (!opts.controller.axis_map.empty())
modifier.push_back(ModifierPtr(new AxismapModifier(opts.controller.axis_map)));
modifier.insert(modifier.end(), opts.controller.modifier.begin(), opts.controller.modifier.end()); modifier.insert(modifier.end(), opts.controller.modifier.begin(), opts.controller.modifier.end());
std::stable_sort(modifier.begin(), modifier.end(), SortModifierByPriority()); std::stable_sort(modifier.begin(), modifier.end(), SortModifierByPriority());