Split axisfilter and buttonfilter into their own separate files
This commit is contained in:
parent
283cbf48f3
commit
445fa1aa97
30 changed files with 1272 additions and 708 deletions
SConstruct
src
axis_filter.cppaxis_filter.hpp
axisfilter
calibration_axis_filter.cppcalibration_axis_filter.hppdeadzone_axis_filter.cppdeadzone_axis_filter.hppinvert_axis_filter.cppinvert_axis_filter.hpplog_axis_filter.cpplog_axis_filter.hpprelative_axis_filter.cpprelative_axis_filter.hppresponse_curve_axis_filter.cppresponse_curve_axis_filter.hppsensitivity_axis_filter.cppsensitivity_axis_filter.hpp
button_filter.cppbutton_filter.hppbuttonfilter
autofire_button_filter.cppautofire_button_filter.hppinvert_button_filter.cppinvert_button_filter.hpplog_button_filter.cpplog_button_filter.hpptoggle_button_filter.cpptoggle_button_filter.hpp
command_line_options.cppcontroller_slot_config.cpphelper.hpp
|
@ -76,6 +76,8 @@ env = conf.Finish()
|
|||
|
||||
env.Program('xboxdrv',
|
||||
Glob('src/*.cpp') +
|
||||
Glob('src/axisfilter/*.cpp') +
|
||||
Glob('src/buttonfilter/*.cpp') +
|
||||
Glob('src/modifier/*.cpp'))
|
||||
|
||||
# EOF #
|
||||
|
|
|
@ -24,22 +24,14 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
/** converts the arbitary range to [-1,1] */
|
||||
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;
|
||||
}
|
||||
|
||||
/** converts the range [-1,1] to [min,max] */
|
||||
inline int from_float(float value, int min, int max)
|
||||
{
|
||||
return (value + 1.0f) / 2.0f * static_cast<float>(max - min) + min;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#include "axisfilter/calibration_axis_filter.hpp"
|
||||
#include "axisfilter/deadzone_axis_filter.hpp"
|
||||
#include "axisfilter/invert_axis_filter.hpp"
|
||||
#include "axisfilter/log_axis_filter.hpp"
|
||||
#include "axisfilter/relative_axis_filter.hpp"
|
||||
#include "axisfilter/response_curve_axis_filter.hpp"
|
||||
#include "axisfilter/sensitivity_axis_filter.hpp"
|
||||
|
||||
AxisFilterPtr
|
||||
AxisFilter::from_string(const std::string& str)
|
||||
|
@ -87,367 +79,4 @@ AxisFilter::from_string(const std::string& str)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
InvertAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
int center = (max + min + 1)/2; // FIXME: '+1' is kind of a hack to
|
||||
// get the center at 0 for the
|
||||
// [-32768, 32767] case
|
||||
if (value < center)
|
||||
{
|
||||
return (max - center) * (value - center) / (min - center) + center;
|
||||
}
|
||||
else if (value > center)
|
||||
{
|
||||
return (min - center) * (value - center) / (max - center) + center;
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
InvertAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "invert";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
SensitivityAxisFilter*
|
||||
SensitivityAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
|
||||
float sensitivity = 0.0f;
|
||||
|
||||
int j = 0;
|
||||
for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
|
||||
{
|
||||
switch(j)
|
||||
{
|
||||
case 0: sensitivity = boost::lexical_cast<float>(*i); break;
|
||||
default: throw std::runtime_error("to many arguments");
|
||||
};
|
||||
}
|
||||
|
||||
return new SensitivityAxisFilter(sensitivity);
|
||||
}
|
||||
|
||||
SensitivityAxisFilter::SensitivityAxisFilter(float sensitivity) :
|
||||
m_sensitivity(sensitivity)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
SensitivityAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
float pos = to_float(value, min, max);
|
||||
|
||||
float t = powf(2, m_sensitivity);
|
||||
|
||||
// FIXME: there might be better/more standard ways to accomplish this
|
||||
if (pos > 0)
|
||||
{
|
||||
pos = powf(1.0f - powf(1.0f - pos, t), 1 / t);
|
||||
return from_float(pos, min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = powf(1.0f - powf(1.0f - -pos, t), 1 / t);
|
||||
return from_float(-pos, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
SensitivityAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "sensitivity:" << m_sensitivity;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
CalibrationAxisFilter*
|
||||
CalibrationAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
|
||||
int min = 0;
|
||||
int center = 0;
|
||||
int max = 0;
|
||||
|
||||
int j = 0;
|
||||
for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
|
||||
{
|
||||
switch(j)
|
||||
{
|
||||
case 0: min = boost::lexical_cast<int>(*i); break;
|
||||
case 1: center = boost::lexical_cast<int>(*i); break;
|
||||
case 2: max = boost::lexical_cast<int>(*i); break;
|
||||
default: throw std::runtime_error("to many arguments");
|
||||
};
|
||||
}
|
||||
|
||||
return new CalibrationAxisFilter(min, center, max);
|
||||
}
|
||||
|
||||
CalibrationAxisFilter::CalibrationAxisFilter(int min, int center, int max) :
|
||||
m_min(min),
|
||||
m_center(center),
|
||||
m_max(max)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
CalibrationAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
if (value < m_center)
|
||||
value = -min * (value - m_center) / (m_center - m_min);
|
||||
else if (value > m_center)
|
||||
value = max * (value - m_center) / (m_max - m_center);
|
||||
else
|
||||
value = 0;
|
||||
|
||||
return Math::clamp(min, value, max);
|
||||
}
|
||||
|
||||
std::string
|
||||
CalibrationAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "calibration:" << m_min << ":" << m_center << ":" << m_max;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
DeadzoneAxisFilter*
|
||||
DeadzoneAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
int min_deadzone = 0;
|
||||
int max_deadzone = 0;
|
||||
bool smooth = true;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
switch(idx)
|
||||
{
|
||||
case 0:
|
||||
min_deadzone = -boost::lexical_cast<int>(*t);
|
||||
max_deadzone = -min_deadzone;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
max_deadzone = boost::lexical_cast<int>(*t);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
smooth = boost::lexical_cast<bool>(*t);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::runtime_error("to many arguments");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new DeadzoneAxisFilter(min_deadzone, max_deadzone, smooth);
|
||||
}
|
||||
|
||||
DeadzoneAxisFilter::DeadzoneAxisFilter(int min_deadzone, int max_deadzone, bool smooth) :
|
||||
m_min_deadzone(min_deadzone),
|
||||
m_max_deadzone(max_deadzone),
|
||||
m_smooth(smooth)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
DeadzoneAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
if (!m_smooth)
|
||||
{
|
||||
if (value < m_min_deadzone || m_max_deadzone < value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else // (m_smooth)
|
||||
{
|
||||
if (value < m_min_deadzone)
|
||||
{
|
||||
return min * (value - m_min_deadzone) / (min - m_min_deadzone);
|
||||
}
|
||||
else if (value > m_max_deadzone)
|
||||
{
|
||||
return max * (value - m_max_deadzone) / (max - m_max_deadzone);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
DeadzoneAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "deadzone:" << m_min_deadzone << ":" << m_max_deadzone << ":" << m_smooth;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
RelativeAxisFilter*
|
||||
RelativeAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
int speed = 20000;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
switch(idx)
|
||||
{
|
||||
case 0: speed = boost::lexical_cast<int>(*t); break;
|
||||
default: throw std::runtime_error("to many arguments"); break;
|
||||
}
|
||||
}
|
||||
|
||||
return new RelativeAxisFilter(speed);
|
||||
}
|
||||
|
||||
RelativeAxisFilter::RelativeAxisFilter(int speed) :
|
||||
m_speed(speed),
|
||||
m_float_speed(0.0f),
|
||||
m_value(0),
|
||||
m_state(0)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RelativeAxisFilter::update(int msec_delta)
|
||||
{
|
||||
m_state += m_float_speed * m_value * msec_delta / 1000.0f;
|
||||
m_state = Math::clamp(-1.0f, m_state, 1.0f);
|
||||
}
|
||||
|
||||
int
|
||||
RelativeAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
m_value = to_float(value, min, max);
|
||||
|
||||
m_float_speed = to_float(m_speed, min, max);
|
||||
|
||||
return from_float(m_state, min, max);
|
||||
}
|
||||
|
||||
std::string
|
||||
RelativeAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "relativeaxis:" << m_speed;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
ResponseCurveAxisFilter*
|
||||
ResponseCurveAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
std::vector<int> samples;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
samples.push_back(boost::lexical_cast<int>(*t));
|
||||
}
|
||||
|
||||
return new ResponseCurveAxisFilter(samples);
|
||||
}
|
||||
|
||||
ResponseCurveAxisFilter::ResponseCurveAxisFilter(const std::vector<int>& samples) :
|
||||
m_samples(samples)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
ResponseCurveAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
if (m_samples.empty())
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else if (m_samples.size() == 1)
|
||||
{
|
||||
return m_samples[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: should rewrite this to use integer only and make sure
|
||||
// that the edge conditions are meet
|
||||
int bucket_count = m_samples.size() - 1;
|
||||
float bucket_size = (max - min) / static_cast<float>(bucket_count);
|
||||
|
||||
int bucket_index = int((value - min) / bucket_size);
|
||||
|
||||
float t = ((value - min) - (static_cast<float>(bucket_index) * bucket_size)) / bucket_size;
|
||||
|
||||
return ((1.0f - t) * m_samples[bucket_index]) + (t * m_samples[bucket_index + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
ResponseCurveAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "responsecurve";
|
||||
for(std::vector<int>::const_iterator i = m_samples.begin(); i != m_samples.end(); ++i)
|
||||
{
|
||||
out << ":" << *i;
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
||||
LogAxisFilter*
|
||||
LogAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
return new LogAxisFilter(str);
|
||||
}
|
||||
|
||||
LogAxisFilter::LogAxisFilter(const std::string& name) :
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
LogAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
if (m_name.empty())
|
||||
{
|
||||
std::cout << value << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << m_name << ": " << value << std::endl;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string
|
||||
LogAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "log:" << m_name;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -41,115 +41,6 @@ public:
|
|||
virtual std::string str() const = 0;
|
||||
};
|
||||
|
||||
class InvertAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
InvertAxisFilter() {}
|
||||
~InvertAxisFilter() {}
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
class SensitivityAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static SensitivityAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
SensitivityAxisFilter(float sensitivity);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
float m_sensitivity;
|
||||
};
|
||||
|
||||
class CalibrationAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static CalibrationAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
CalibrationAxisFilter(int min, int center, int max);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
int m_min;
|
||||
int m_center;
|
||||
int m_max;
|
||||
};
|
||||
|
||||
class DeadzoneAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static DeadzoneAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
DeadzoneAxisFilter(int min_deadzone, int max_deathzone, bool smooth);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
int m_min_deadzone;
|
||||
int m_max_deadzone;
|
||||
bool m_smooth;
|
||||
};
|
||||
|
||||
class RelativeAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static RelativeAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
RelativeAxisFilter(int speed);
|
||||
|
||||
void update(int msec_delta);
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
int m_speed;
|
||||
|
||||
float m_float_speed;
|
||||
float m_value;
|
||||
float m_state;
|
||||
};
|
||||
|
||||
class ResponseCurveAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static ResponseCurveAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
ResponseCurveAxisFilter(const std::vector<int>& samples);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
std::vector<int> m_samples;
|
||||
};
|
||||
|
||||
class LogAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static LogAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
LogAxisFilter(const std::string& name);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
||||
|
|
79
src/axisfilter/calibration_axis_filter.cpp
Normal file
79
src/axisfilter/calibration_axis_filter.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "axisfilter/calibration_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
CalibrationAxisFilter*
|
||||
CalibrationAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
|
||||
int min = 0;
|
||||
int center = 0;
|
||||
int max = 0;
|
||||
|
||||
int j = 0;
|
||||
for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
|
||||
{
|
||||
switch(j)
|
||||
{
|
||||
case 0: min = boost::lexical_cast<int>(*i); break;
|
||||
case 1: center = boost::lexical_cast<int>(*i); break;
|
||||
case 2: max = boost::lexical_cast<int>(*i); break;
|
||||
default: throw std::runtime_error("to many arguments");
|
||||
};
|
||||
}
|
||||
|
||||
return new CalibrationAxisFilter(min, center, max);
|
||||
}
|
||||
|
||||
CalibrationAxisFilter::CalibrationAxisFilter(int min, int center, int max) :
|
||||
m_min(min),
|
||||
m_center(center),
|
||||
m_max(max)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
CalibrationAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
if (value < m_center)
|
||||
value = -min * (value - m_center) / (m_center - m_min);
|
||||
else if (value > m_center)
|
||||
value = max * (value - m_center) / (m_max - m_center);
|
||||
else
|
||||
value = 0;
|
||||
|
||||
return Math::clamp(min, value, max);
|
||||
}
|
||||
|
||||
std::string
|
||||
CalibrationAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "calibration:" << m_min << ":" << m_center << ":" << m_max;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
43
src/axisfilter/calibration_axis_filter.hpp
Normal file
43
src/axisfilter/calibration_axis_filter.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_AXISFILTER_CALIBRATION_AXIS_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_AXISFILTER_CALIBRATION_AXIS_FILTER_HPP
|
||||
|
||||
#include "axis_filter.hpp"
|
||||
|
||||
class CalibrationAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static CalibrationAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
CalibrationAxisFilter(int min, int center, int max);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
int m_min;
|
||||
int m_center;
|
||||
int m_max;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
106
src/axisfilter/deadzone_axis_filter.cpp
Normal file
106
src/axisfilter/deadzone_axis_filter.cpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "axisfilter/deadzone_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
DeadzoneAxisFilter*
|
||||
DeadzoneAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
int min_deadzone = 0;
|
||||
int max_deadzone = 0;
|
||||
bool smooth = true;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
switch(idx)
|
||||
{
|
||||
case 0:
|
||||
min_deadzone = -boost::lexical_cast<int>(*t);
|
||||
max_deadzone = -min_deadzone;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
max_deadzone = boost::lexical_cast<int>(*t);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
smooth = boost::lexical_cast<bool>(*t);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::runtime_error("to many arguments");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new DeadzoneAxisFilter(min_deadzone, max_deadzone, smooth);
|
||||
}
|
||||
|
||||
DeadzoneAxisFilter::DeadzoneAxisFilter(int min_deadzone, int max_deadzone, bool smooth) :
|
||||
m_min_deadzone(min_deadzone),
|
||||
m_max_deadzone(max_deadzone),
|
||||
m_smooth(smooth)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
DeadzoneAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
if (!m_smooth)
|
||||
{
|
||||
if (value < m_min_deadzone || m_max_deadzone < value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else // (m_smooth)
|
||||
{
|
||||
if (value < m_min_deadzone)
|
||||
{
|
||||
return min * (value - m_min_deadzone) / (min - m_min_deadzone);
|
||||
}
|
||||
else if (value > m_max_deadzone)
|
||||
{
|
||||
return max * (value - m_max_deadzone) / (max - m_max_deadzone);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
DeadzoneAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "deadzone:" << m_min_deadzone << ":" << m_max_deadzone << ":" << m_smooth;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
43
src/axisfilter/deadzone_axis_filter.hpp
Normal file
43
src/axisfilter/deadzone_axis_filter.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_AXISFILTER_DEADZONE_AXIS_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_AXISFILTER_DEADZONE_AXIS_FILTER_HPP
|
||||
|
||||
#include "axis_filter.hpp"
|
||||
|
||||
class DeadzoneAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static DeadzoneAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
DeadzoneAxisFilter(int min_deadzone, int max_deathzone, bool smooth);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
int m_min_deadzone;
|
||||
int m_max_deadzone;
|
||||
bool m_smooth;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
47
src/axisfilter/invert_axis_filter.cpp
Normal file
47
src/axisfilter/invert_axis_filter.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "invert_axis_filter.hpp"
|
||||
|
||||
int
|
||||
InvertAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
int center = (max + min + 1)/2; // FIXME: '+1' is kind of a hack to
|
||||
// get the center at 0 for the
|
||||
// [-32768, 32767] case
|
||||
if (value < center)
|
||||
{
|
||||
return (max - center) * (value - center) / (min - center) + center;
|
||||
}
|
||||
else if (value > center)
|
||||
{
|
||||
return (min - center) * (value - center) / (max - center) + center;
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
InvertAxisFilter::str() const
|
||||
{
|
||||
return "invert";
|
||||
}
|
||||
|
||||
/* EOF */
|
36
src/axisfilter/invert_axis_filter.hpp
Normal file
36
src/axisfilter/invert_axis_filter.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_AXISFILTER_INVERT_AXIS_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_AXISFILTER_INVERT_AXIS_FILTER_HPP
|
||||
|
||||
#include "axis_filter.hpp"
|
||||
|
||||
class InvertAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
InvertAxisFilter() {}
|
||||
~InvertAxisFilter() {}
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
58
src/axisfilter/log_axis_filter.cpp
Normal file
58
src/axisfilter/log_axis_filter.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "axisfilter/log_axis_filter.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
LogAxisFilter*
|
||||
LogAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
return new LogAxisFilter(str);
|
||||
}
|
||||
|
||||
LogAxisFilter::LogAxisFilter(const std::string& name) :
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
LogAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
if (m_name.empty())
|
||||
{
|
||||
std::cout << value << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << m_name << ": " << value << std::endl;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string
|
||||
LogAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "log:" << m_name;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
41
src/axisfilter/log_axis_filter.hpp
Normal file
41
src/axisfilter/log_axis_filter.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_AXISFILTER_LOG_AXIS_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_AXISFILTER_LOG_AXIS_FILTER_HPP
|
||||
|
||||
#include "axis_filter.hpp"
|
||||
|
||||
class LogAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static LogAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
LogAxisFilter(const std::string& name);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
79
src/axisfilter/relative_axis_filter.cpp
Normal file
79
src/axisfilter/relative_axis_filter.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "axisfilter/relative_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
RelativeAxisFilter*
|
||||
RelativeAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
int speed = 20000;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
switch(idx)
|
||||
{
|
||||
case 0: speed = boost::lexical_cast<int>(*t); break;
|
||||
default: throw std::runtime_error("to many arguments"); break;
|
||||
}
|
||||
}
|
||||
|
||||
return new RelativeAxisFilter(speed);
|
||||
}
|
||||
|
||||
RelativeAxisFilter::RelativeAxisFilter(int speed) :
|
||||
m_speed(speed),
|
||||
m_float_speed(0.0f),
|
||||
m_value(0),
|
||||
m_state(0)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RelativeAxisFilter::update(int msec_delta)
|
||||
{
|
||||
m_state += m_float_speed * m_value * msec_delta / 1000.0f;
|
||||
m_state = Math::clamp(-1.0f, m_state, 1.0f);
|
||||
}
|
||||
|
||||
int
|
||||
RelativeAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
m_value = to_float(value, min, max);
|
||||
|
||||
m_float_speed = to_float(m_speed, min, max);
|
||||
|
||||
return from_float(m_state, min, max);
|
||||
}
|
||||
|
||||
std::string
|
||||
RelativeAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "relativeaxis:" << m_speed;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
46
src/axisfilter/relative_axis_filter.hpp
Normal file
46
src/axisfilter/relative_axis_filter.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_AXISFILTER_RELATIVE_AXIS_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_AXISFILTER_RELATIVE_AXIS_FILTER_HPP
|
||||
|
||||
#include "axis_filter.hpp"
|
||||
|
||||
class RelativeAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static RelativeAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
RelativeAxisFilter(int speed);
|
||||
|
||||
void update(int msec_delta);
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
int m_speed;
|
||||
|
||||
float m_float_speed;
|
||||
float m_value;
|
||||
float m_state;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
83
src/axisfilter/response_curve_axis_filter.cpp
Normal file
83
src/axisfilter/response_curve_axis_filter.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "response_curve_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
ResponseCurveAxisFilter*
|
||||
ResponseCurveAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
std::vector<int> samples;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
samples.push_back(boost::lexical_cast<int>(*t));
|
||||
}
|
||||
|
||||
return new ResponseCurveAxisFilter(samples);
|
||||
}
|
||||
|
||||
ResponseCurveAxisFilter::ResponseCurveAxisFilter(const std::vector<int>& samples) :
|
||||
m_samples(samples)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
ResponseCurveAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
if (m_samples.empty())
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else if (m_samples.size() == 1)
|
||||
{
|
||||
return m_samples[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: should rewrite this to use integer only and make sure
|
||||
// that the edge conditions are meet
|
||||
int bucket_count = m_samples.size() - 1;
|
||||
float bucket_size = (max - min) / static_cast<float>(bucket_count);
|
||||
|
||||
int bucket_index = int((value - min) / bucket_size);
|
||||
|
||||
float t = ((value - min) - (static_cast<float>(bucket_index) * bucket_size)) / bucket_size;
|
||||
|
||||
return ((1.0f - t) * m_samples[bucket_index]) + (t * m_samples[bucket_index + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
ResponseCurveAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "responsecurve";
|
||||
for(std::vector<int>::const_iterator i = m_samples.begin(); i != m_samples.end(); ++i)
|
||||
{
|
||||
out << ":" << *i;
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
41
src/axisfilter/response_curve_axis_filter.hpp
Normal file
41
src/axisfilter/response_curve_axis_filter.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_AXISFILTER_RESPONSE_CURVE_AXIS_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_AXISFILTER_RESPONSE_CURVE_AXIS_FILTER_HPP
|
||||
|
||||
#include "axis_filter.hpp"
|
||||
|
||||
class ResponseCurveAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static ResponseCurveAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
ResponseCurveAxisFilter(const std::vector<int>& samples);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
std::vector<int> m_samples;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
81
src/axisfilter/sensitivity_axis_filter.cpp
Normal file
81
src/axisfilter/sensitivity_axis_filter.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "sensitivity_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <math.h>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
SensitivityAxisFilter*
|
||||
SensitivityAxisFilter::from_string(const std::string& str)
|
||||
{
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
|
||||
float sensitivity = 0.0f;
|
||||
|
||||
int j = 0;
|
||||
for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
|
||||
{
|
||||
switch(j)
|
||||
{
|
||||
case 0: sensitivity = boost::lexical_cast<float>(*i); break;
|
||||
default: throw std::runtime_error("to many arguments");
|
||||
};
|
||||
}
|
||||
|
||||
return new SensitivityAxisFilter(sensitivity);
|
||||
}
|
||||
|
||||
SensitivityAxisFilter::SensitivityAxisFilter(float sensitivity) :
|
||||
m_sensitivity(sensitivity)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
SensitivityAxisFilter::filter(int value, int min, int max)
|
||||
{
|
||||
float pos = to_float(value, min, max);
|
||||
|
||||
float t = powf(2, m_sensitivity);
|
||||
|
||||
// FIXME: there might be better/more standard ways to accomplish this
|
||||
if (pos > 0)
|
||||
{
|
||||
pos = powf(1.0f - powf(1.0f - pos, t), 1 / t);
|
||||
return from_float(pos, min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = powf(1.0f - powf(1.0f - -pos, t), 1 / t);
|
||||
return from_float(-pos, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
SensitivityAxisFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "sensitivity:" << m_sensitivity;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
41
src/axisfilter/sensitivity_axis_filter.hpp
Normal file
41
src/axisfilter/sensitivity_axis_filter.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_AXISFILTER_SENSITIVITY_AXIS_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_AXISFILTER_SENSITIVITY_AXIS_FILTER_HPP
|
||||
|
||||
#include "axis_filter.hpp"
|
||||
|
||||
class SensitivityAxisFilter : public AxisFilter
|
||||
{
|
||||
public:
|
||||
static SensitivityAxisFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
SensitivityAxisFilter(float sensitivity);
|
||||
|
||||
int filter(int value, int min, int max);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
float m_sensitivity;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
|
@ -21,7 +21,12 @@
|
|||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include "buttonfilter/autofire_button_filter.hpp"
|
||||
#include "buttonfilter/invert_button_filter.hpp"
|
||||
#include "buttonfilter/log_button_filter.hpp"
|
||||
#include "buttonfilter/toggle_button_filter.hpp"
|
||||
|
||||
ButtonFilterPtr
|
||||
ButtonFilter::from_string(const std::string& str)
|
||||
{
|
||||
|
@ -55,163 +60,5 @@ ButtonFilter::from_string(const std::string& str)
|
|||
throw std::runtime_error(out.str());
|
||||
}
|
||||
}
|
||||
|
||||
ToggleButtonFilter::ToggleButtonFilter() :
|
||||
m_state(false),
|
||||
m_last_value(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ToggleButtonFilter::filter(bool value)
|
||||
{
|
||||
if (value != m_last_value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
m_state = !m_state;
|
||||
}
|
||||
|
||||
m_last_value = value;
|
||||
}
|
||||
return m_state;
|
||||
}
|
||||
|
||||
std::string
|
||||
ToggleButtonFilter::str() const
|
||||
{
|
||||
return "toggle";
|
||||
}
|
||||
|
||||
bool
|
||||
InvertButtonFilter::filter(bool value)
|
||||
{
|
||||
return !value;
|
||||
}
|
||||
|
||||
std::string
|
||||
InvertButtonFilter::str() const
|
||||
{
|
||||
return "invert";
|
||||
}
|
||||
|
||||
AutofireButtonFilter*
|
||||
AutofireButtonFilter::from_string(const std::string& str)
|
||||
{
|
||||
int rate = 50;
|
||||
int delay = 0;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
switch(idx)
|
||||
{
|
||||
case 0: rate = boost::lexical_cast<int>(*t); break;
|
||||
case 1: delay = boost::lexical_cast<int>(*t); break;
|
||||
default: throw std::runtime_error("to many arguments"); break;
|
||||
}
|
||||
}
|
||||
|
||||
return new AutofireButtonFilter(rate, delay);
|
||||
}
|
||||
|
||||
AutofireButtonFilter::AutofireButtonFilter(int rate, int delay) :
|
||||
m_state(false),
|
||||
m_autofire(false),
|
||||
m_rate(rate),
|
||||
m_delay(delay),
|
||||
m_counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
AutofireButtonFilter::update(int msec_delta)
|
||||
{
|
||||
if (m_state)
|
||||
{
|
||||
m_counter += msec_delta;
|
||||
|
||||
if (m_counter > m_delay)
|
||||
{
|
||||
m_autofire = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
AutofireButtonFilter::filter(bool value)
|
||||
{
|
||||
m_state = value;
|
||||
|
||||
if (!value)
|
||||
{
|
||||
m_counter = 0;
|
||||
m_autofire = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ // auto fire
|
||||
if (m_autofire)
|
||||
{
|
||||
if (m_counter > m_rate)
|
||||
{
|
||||
m_counter = 0;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
AutofireButtonFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "auto:" << m_rate << ":" << m_delay;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
LogButtonFilter*
|
||||
LogButtonFilter::from_string(const std::string& str)
|
||||
{
|
||||
return new LogButtonFilter(str);
|
||||
}
|
||||
|
||||
LogButtonFilter::LogButtonFilter(const std::string& name) :
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
LogButtonFilter::filter(bool value)
|
||||
{
|
||||
if (m_name.empty())
|
||||
{
|
||||
std::cout << value << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << m_name << ": " << value << std::endl;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string
|
||||
LogButtonFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "log:" << m_name;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
class ButtonFilter;
|
||||
|
||||
typedef boost::shared_ptr<ButtonFilter> ButtonFilterPtr;
|
||||
|
||||
|
||||
class ButtonFilter
|
||||
{
|
||||
public:
|
||||
|
@ -39,68 +39,7 @@ public:
|
|||
virtual void update(int msec_delta) {}
|
||||
virtual std::string str() const = 0;
|
||||
};
|
||||
|
||||
class ToggleButtonFilter : public ButtonFilter
|
||||
{
|
||||
public:
|
||||
ToggleButtonFilter();
|
||||
|
||||
bool filter(bool value);
|
||||
void update(int msec_delta) {}
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
bool m_state;
|
||||
bool m_last_value;
|
||||
};
|
||||
|
||||
class InvertButtonFilter : public ButtonFilter
|
||||
{
|
||||
public:
|
||||
InvertButtonFilter() {}
|
||||
|
||||
void update(int msec_delta) {}
|
||||
bool filter(bool value);
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
class AutofireButtonFilter : public ButtonFilter
|
||||
{
|
||||
public:
|
||||
static AutofireButtonFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
AutofireButtonFilter(int rate, int delay);
|
||||
|
||||
void update(int msec_delta);
|
||||
bool filter(bool value);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
bool m_state;
|
||||
bool m_autofire;
|
||||
|
||||
/** msec between shots */
|
||||
int m_rate;
|
||||
int m_delay;
|
||||
int m_counter;
|
||||
};
|
||||
|
||||
class LogButtonFilter : public ButtonFilter
|
||||
{
|
||||
public:
|
||||
static LogButtonFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
LogButtonFilter(const std::string& name);
|
||||
|
||||
bool filter(bool value);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
||||
|
|
109
src/buttonfilter/autofire_button_filter.cpp
Normal file
109
src/buttonfilter/autofire_button_filter.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "buttonfilter/autofire_button_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
AutofireButtonFilter*
|
||||
AutofireButtonFilter::from_string(const std::string& str)
|
||||
{
|
||||
int rate = 50;
|
||||
int delay = 0;
|
||||
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
|
||||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
switch(idx)
|
||||
{
|
||||
case 0: rate = boost::lexical_cast<int>(*t); break;
|
||||
case 1: delay = boost::lexical_cast<int>(*t); break;
|
||||
default: throw std::runtime_error("to many arguments"); break;
|
||||
}
|
||||
}
|
||||
|
||||
return new AutofireButtonFilter(rate, delay);
|
||||
}
|
||||
|
||||
AutofireButtonFilter::AutofireButtonFilter(int rate, int delay) :
|
||||
m_state(false),
|
||||
m_autofire(false),
|
||||
m_rate(rate),
|
||||
m_delay(delay),
|
||||
m_counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
AutofireButtonFilter::update(int msec_delta)
|
||||
{
|
||||
if (m_state)
|
||||
{
|
||||
m_counter += msec_delta;
|
||||
|
||||
if (m_counter > m_delay)
|
||||
{
|
||||
m_autofire = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
AutofireButtonFilter::filter(bool value)
|
||||
{
|
||||
m_state = value;
|
||||
|
||||
if (!value)
|
||||
{
|
||||
m_counter = 0;
|
||||
m_autofire = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ // auto fire
|
||||
if (m_autofire)
|
||||
{
|
||||
if (m_counter > m_rate)
|
||||
{
|
||||
m_counter = 0;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
AutofireButtonFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "auto:" << m_rate << ":" << m_delay;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
48
src/buttonfilter/autofire_button_filter.hpp
Normal file
48
src/buttonfilter/autofire_button_filter.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_BUTTONFILTER_AUTOFIRE_BUTTON_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_BUTTONFILTER_AUTOFIRE_BUTTON_FILTER_HPP
|
||||
|
||||
#include "button_filter.hpp"
|
||||
|
||||
class AutofireButtonFilter : public ButtonFilter
|
||||
{
|
||||
public:
|
||||
static AutofireButtonFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
AutofireButtonFilter(int rate, int delay);
|
||||
|
||||
void update(int msec_delta);
|
||||
bool filter(bool value);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
bool m_state;
|
||||
bool m_autofire;
|
||||
|
||||
/** msec between shots */
|
||||
int m_rate;
|
||||
int m_delay;
|
||||
int m_counter;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
33
src/buttonfilter/invert_button_filter.cpp
Normal file
33
src/buttonfilter/invert_button_filter.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "invert_button_filter.hpp"
|
||||
|
||||
bool
|
||||
InvertButtonFilter::filter(bool value)
|
||||
{
|
||||
return !value;
|
||||
}
|
||||
|
||||
std::string
|
||||
InvertButtonFilter::str() const
|
||||
{
|
||||
return "invert";
|
||||
}
|
||||
|
||||
/* EOF */
|
36
src/buttonfilter/invert_button_filter.hpp
Normal file
36
src/buttonfilter/invert_button_filter.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_BUTTONFILTER_INVERT_BUTTON_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_BUTTONFILTER_INVERT_BUTTON_FILTER_HPP
|
||||
|
||||
#include "button_filter.hpp"
|
||||
|
||||
class InvertButtonFilter : public ButtonFilter
|
||||
{
|
||||
public:
|
||||
InvertButtonFilter() {}
|
||||
|
||||
void update(int msec_delta) {}
|
||||
bool filter(bool value);
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
58
src/buttonfilter/log_button_filter.cpp
Normal file
58
src/buttonfilter/log_button_filter.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "buttonfilter/log_button_filter.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
LogButtonFilter*
|
||||
LogButtonFilter::from_string(const std::string& str)
|
||||
{
|
||||
return new LogButtonFilter(str);
|
||||
}
|
||||
|
||||
LogButtonFilter::LogButtonFilter(const std::string& name) :
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
LogButtonFilter::filter(bool value)
|
||||
{
|
||||
if (m_name.empty())
|
||||
{
|
||||
std::cout << value << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << m_name << ": " << value << std::endl;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string
|
||||
LogButtonFilter::str() const
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "log:" << m_name;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
/* EOF */
|
41
src/buttonfilter/log_button_filter.hpp
Normal file
41
src/buttonfilter/log_button_filter.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_BUTTONFILTER_LOG_BUTTON_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_BUTTONFILTER_LOG_BUTTON_FILTER_HPP
|
||||
|
||||
#include "button_filter.hpp"
|
||||
|
||||
class LogButtonFilter : public ButtonFilter
|
||||
{
|
||||
public:
|
||||
static LogButtonFilter* from_string(const std::string& str);
|
||||
|
||||
public:
|
||||
LogButtonFilter(const std::string& name);
|
||||
|
||||
bool filter(bool value);
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
48
src/buttonfilter/toggle_button_filter.cpp
Normal file
48
src/buttonfilter/toggle_button_filter.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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 "buttonfilter/toggle_button_filter.hpp"
|
||||
|
||||
ToggleButtonFilter::ToggleButtonFilter() :
|
||||
m_state(false),
|
||||
m_last_value(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ToggleButtonFilter::filter(bool value)
|
||||
{
|
||||
if (value != m_last_value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
m_state = !m_state;
|
||||
}
|
||||
|
||||
m_last_value = value;
|
||||
}
|
||||
return m_state;
|
||||
}
|
||||
|
||||
std::string
|
||||
ToggleButtonFilter::str() const
|
||||
{
|
||||
return "toggle";
|
||||
}
|
||||
|
||||
/* EOF */
|
40
src/buttonfilter/toggle_button_filter.hpp
Normal file
40
src/buttonfilter/toggle_button_filter.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
** Xbox360 USB Gamepad Userspace Driver
|
||||
** Copyright (C) 2011 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_BUTTONFILTER_TOGGLE_BUTTON_FILTER_HPP
|
||||
#define HEADER_XBOXDRV_BUTTONFILTER_TOGGLE_BUTTON_FILTER_HPP
|
||||
|
||||
#include "button_filter.hpp"
|
||||
|
||||
class ToggleButtonFilter : public ButtonFilter
|
||||
{
|
||||
public:
|
||||
ToggleButtonFilter();
|
||||
|
||||
bool filter(bool value);
|
||||
void update(int msec_delta) {}
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
bool m_state;
|
||||
bool m_last_value;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* EOF */
|
|
@ -29,6 +29,11 @@
|
|||
#include "log.hpp"
|
||||
#include "options.hpp"
|
||||
|
||||
#include "axisfilter/relative_axis_filter.hpp"
|
||||
#include "axisfilter/calibration_axis_filter.hpp"
|
||||
#include "axisfilter/sensitivity_axis_filter.hpp"
|
||||
#include "buttonfilter/autofire_button_filter.hpp"
|
||||
|
||||
#define RAISE_EXCEPTION(x) do { \
|
||||
std::ostringstream kiJk8f08d4oMX; \
|
||||
kiJk8f08d4oMX << x; \
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "modifier/four_way_restrictor_modifier.hpp"
|
||||
#include "modifier/square_axis_modifier.hpp"
|
||||
|
||||
#include "axisfilter/deadzone_axis_filter.hpp"
|
||||
|
||||
ControllerSlotConfigPtr
|
||||
ControllerSlotConfig::create(UInput& uinput, int slot, bool extra_devices, const ControllerSlotOptions& opts)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,18 @@
|
|||
|
||||
#include <boost/function.hpp>
|
||||
|
||||
/** converts the arbitary range to [-1,1] */
|
||||
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;
|
||||
}
|
||||
|
||||
/** converts the range [-1,1] to [min,max] */
|
||||
inline int from_float(float value, int min, int max)
|
||||
{
|
||||
return (value + 1.0f) / 2.0f * static_cast<float>(max - min) + min;
|
||||
}
|
||||
|
||||
int hexstr2int(const std::string& str);
|
||||
|
||||
std::string raw2str(uint8_t* buffer, int len);
|
||||
|
|
Loading…
Add table
Reference in a new issue