3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <sigc++/bind.h>
9 #include <msp/core/except.h>
20 unsigned Hub::attach(Device &dev)
22 unsigned index=devices.size();
23 devices.push_back(&dev);
24 dev.signal_button_press.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index));
25 dev.signal_button_release.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index));
26 dev.signal_axis_motion.connect(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index));
30 std::string Hub::get_button_name(unsigned btn) const
32 unsigned dev_index=btn>>12;
33 if(dev_index>=devices.size())
34 throw InvalidParameterValue("Button does not exist");
36 const Device &dev=*devices[dev_index];
37 return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
40 std::string Hub::get_axis_name(unsigned axis) const
42 unsigned dev_index=axis>>12;
43 if(dev_index>=devices.size())
44 throw InvalidParameterValue("Axis does not exist");
46 const Device &dev=*devices[dev_index];
47 return dev.get_name()+": "+dev.get_axis_name(axis&0xFFF);
50 void Hub::button_press(unsigned btn, unsigned index)
52 set_button_state((index<<12) | (btn&0xFFF), true, true);
55 void Hub::button_release(unsigned btn, unsigned index)
57 set_button_state((index<<12) | (btn&0xFFF), false, true);
60 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
62 set_axis_value((index<<12) | (axis&0xFFF), value, true);