Split the ports into separate files

This commit is contained in:
Ingo Ruhnke 2010-05-31 01:56:17 +02:00
parent a429856889
commit 35bc301140
13 changed files with 124 additions and 196 deletions

View file

@ -16,9 +16,15 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/bind.hpp>
#include "abs_to_btn.hpp"
#include <boost/bind.hpp>
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
AbsToBtn::AbsToBtn(int threshold)
: threshold(threshold)
{
@ -56,5 +62,5 @@ void
AbsToBtn::update(float delta)
{
}
/* EOF */

View file

@ -16,9 +16,15 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/bind.hpp>
#include "abs_to_rel.hpp"
#include <boost/bind.hpp>
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
AbsToRel::AbsToRel()
{
abs_port_in.push_back(new AbsPortIn("AbsToRel-In", 0, 0,

View file

@ -16,8 +16,12 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/bind.hpp>
#include "autofire_button.hpp"
#include <boost/bind.hpp>
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
AutofireButton::AutofireButton(int rate)
: rate(rate),

View file

@ -16,9 +16,15 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/bind.hpp>
#include "btn_to_abs.hpp"
#include <boost/bind.hpp>
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
BtnToAbs::BtnToAbs()
: target_value(0)
{

View file

@ -17,21 +17,34 @@
*/
#include "control.hpp"
void
BtnPortOut::connect(BtnPortIn* in)
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
Control::Control()
{
if (in)
{
in->out_port = this;
sig_change.connect(in->on_change);
}
}
void
BtnPortOut::connect(boost::function<void(BtnPortOut*)> func)
Control::~Control()
{
sig_change.connect(func);
for(std::vector<BtnPortIn*>::iterator i = btn_port_in.begin(); i != btn_port_in.end(); ++i)
delete *i;
for(std::vector<BtnPortOut*>::iterator i = btn_port_out.begin(); i != btn_port_out.end(); ++i)
delete *i;
for(std::vector<AbsPortIn*>::iterator i = abs_port_in.begin(); i != abs_port_in.end(); ++i)
delete *i;
for(std::vector<AbsPortOut*>::iterator i = abs_port_out.begin(); i != abs_port_out.end(); ++i)
delete *i;
for(std::vector<RelPortIn*>::iterator i = rel_port_in.begin(); i != rel_port_in.end(); ++i)
delete *i;
for(std::vector<RelPortOut*>::iterator i = rel_port_out.begin(); i != rel_port_out.end(); ++i)
delete *i;
}
BtnPortIn*
@ -51,22 +64,6 @@ Control::get_btn_port_out(int idx)
else
return 0;
}
void
AbsPortOut::connect(AbsPortIn* in)
{
if (in)
{
in->out_port = this;
sig_change.connect(in->on_change);
}
}
void
AbsPortOut::connect(boost::function<void(AbsPortOut*)> func)
{
sig_change.connect(func);
}
AbsPortIn*
Control::get_abs_port_in(int idx)
@ -91,22 +88,6 @@ Control::get_abs_port_out(int idx)
return 0;
}
}
void
RelPortOut::connect(RelPortIn* in)
{
if (in)
{
in->out_port = this;
sig_change.connect(in->on_change);
}
}
void
RelPortOut::connect(boost::function<void(RelPortOut*)> func)
{
sig_change.connect(func);
}
RelPortIn*
Control::get_rel_port_in(int idx)
@ -142,7 +123,7 @@ void connect_btn(Control* lhs_ctrl, int lhs_i, Control* rhs_ctrl, int rhs_i)
else
LOG("Couldn't establish connection between " << lhs_ctrl << " and " << rhs_ctrl);
}
void connect_abs(Control* lhs_ctrl, int lhs_i, Control* rhs_ctrl, int rhs_i)
{
AbsPortOut* out = lhs_ctrl->get_abs_port_out(lhs_i);
@ -153,7 +134,7 @@ void connect_abs(Control* lhs_ctrl, int lhs_i, Control* rhs_ctrl, int rhs_i)
else
LOG("Couldn't establish connection between " << lhs_ctrl << " and " << rhs_ctrl);
}
void connect_rel(Control* lhs_ctrl, int lhs_i, Control* rhs_ctrl, int rhs_i)
{
RelPortOut* out = lhs_ctrl->get_rel_port_out(lhs_i);

View file

@ -23,125 +23,13 @@
#include "log.hpp"
class BtnPortIn;
class BtnPortOut;
class BtnPortOut
{
public:
std::string label;
// true if pressed, false otherwise
bool state;
boost::signal<void(BtnPortOut*)> sig_change;
BtnPortOut(const std::string& label)
: label(label),
state(false)
{}
std::string get_label() { return label; }
bool get_state() { return state; }
void set_state(bool s) { if (state != s) { state = s; sig_change(this); } }
void connect(BtnPortIn* in);
void connect(boost::function<void(BtnPortOut*)> func);
};
struct BtnPortIn
{
std::string label;
boost::function<void(BtnPortOut*)> on_change;
BtnPortOut* out_port;
BtnPortIn(const std::string& label, const boost::function<void(BtnPortOut*)>& on_change)
: label(label), on_change(on_change), out_port(0) {}
};
class AbsPortIn;
class AbsPortOut;
class AbsPortOut
{
public:
std::string label;
boost::signal<void(AbsPortOut*)> sig_change;
// true if pressed, false otherwise
int state;
int min_value;
int max_value;
AbsPortOut(const std::string& label, int min_value, int max_value)
: label(label),
state(0),
min_value(min_value),
max_value(max_value)
{}
std::string get_label() { return label; }
int get_state() { return state; }
void set_state(int s) { if (state != s) { state = s; sig_change(this); } }
void connect(AbsPortIn* in);
void connect(boost::function<void(AbsPortOut*)> func);
};
class AbsPortIn
{
public:
std::string label;
int min_value;
int max_value;
boost::function<void(AbsPortOut*)> on_change;
AbsPortOut* out_port;
AbsPortIn(const std::string& label, int min_value, int max_value,
const boost::function<void(AbsPortOut*)>& on_change)
: label(label),
min_value(min_value),
max_value(max_value),
on_change(on_change), out_port(0) {}
};
class RelPortIn;
class RelPortOut
{
public:
std::string label;
boost::signal<void(RelPortOut*)> sig_change;
// true if pressed, false otherwise
int state;
RelPortOut(const std::string& label)
: label(label)
{}
std::string get_label() { return label; }
int get_state() { return state; }
void set_state(int s) { state = s; sig_change(this); }
void connect(RelPortIn* in);
void connect(boost::function<void(RelPortOut*)> func);
};
class RelPortIn
{
public:
std::string label;
boost::function<void(RelPortOut*)> on_change;
RelPortOut* out_port;
RelPortIn(const std::string& label, const boost::function<void(RelPortOut*)>& on_change)
: label(label),
on_change(on_change), out_port(0) {}
};
class RelPortOut;
class Control
{
@ -156,26 +44,8 @@ protected:
std::vector<RelPortOut*> rel_port_out;
public:
Control() {
}
virtual ~Control()
{
for(std::vector<BtnPortIn*>::iterator i = btn_port_in.begin(); i != btn_port_in.end(); ++i)
delete *i;
for(std::vector<BtnPortOut*>::iterator i = btn_port_out.begin(); i != btn_port_out.end(); ++i)
delete *i;
for(std::vector<AbsPortIn*>::iterator i = abs_port_in.begin(); i != abs_port_in.end(); ++i)
delete *i;
for(std::vector<AbsPortOut*>::iterator i = abs_port_out.begin(); i != abs_port_out.end(); ++i)
delete *i;
for(std::vector<RelPortIn*>::iterator i = rel_port_in.begin(); i != rel_port_in.end(); ++i)
delete *i;
for(std::vector<RelPortOut*>::iterator i = rel_port_out.begin(); i != rel_port_out.end(); ++i)
delete *i;
}
Control();
virtual ~Control();
virtual std::string get_name() const =0;

View file

@ -28,6 +28,13 @@
#include "evdev_driver.hpp"
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x) ((x)%BITS_PER_LONG)

View file

@ -22,17 +22,25 @@
#include <sstream>
#include <boost/bind.hpp>
#include <boost/format.hpp>
#include "xbox360_driver.hpp"
#include "uinput_driver.hpp"
#include "abs_to_rel.hpp"
#include "toggle_button.hpp"
#include "autofire_button.hpp"
#include "join_axis.hpp"
#include "btn_to_abs.hpp"
#include "throttle.hpp"
#include "evdev_driver.hpp"
#include "control.hpp"
#include "evdev_driver.hpp"
#include "inputdrv.hpp"
#include "join_axis.hpp"
#include "throttle.hpp"
#include "toggle_button.hpp"
#include "uinput_driver.hpp"
#include "xbox360_driver.hpp"
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
void btn_change(BtnPortOut* port)
{

View file

@ -16,9 +16,17 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/bind.hpp>
#include "join_axis.hpp"
#include <boost/bind.hpp>
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
JoinAxis::JoinAxis()
{
abs_port_in.push_back(new AbsPortIn("JoinAxis-1", 0, 0,

View file

@ -16,9 +16,17 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/bind.hpp>
#include "throttle.hpp"
#include <boost/bind.hpp>
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
Throttle::Throttle()
: value(0)
{

View file

@ -16,9 +16,17 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/bind.hpp>
#include "toggle_button.hpp"
#include <boost/bind.hpp>
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
ToggleButton::ToggleButton()
: state(false)
{

View file

@ -16,13 +16,22 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "uinput_driver.hpp"
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/uinput.h>
#include <boost/bind.hpp>
#include "uinput_driver.hpp"
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
UInputDriver::UInputDriver(const std::string& name)
: abs_bit(false),

View file

@ -29,6 +29,13 @@
#include "xbox360_usb_thread.hpp"
#include "xbox360_driver.hpp"
#include "abs_port_in.hpp"
#include "abs_port_out.hpp"
#include "btn_port_in.hpp"
#include "btn_port_out.hpp"
#include "rel_port_in.hpp"
#include "rel_port_out.hpp"
struct usb_device* find_usb_device_by_path(const std::string& busid, const std::string& devid)
{
struct usb_bus* busses = usb_get_busses();