1 #include <sigc++/bind.h>
2 #include <msp/core/except.h>
13 unsigned Hub::attach(Device &dev)
15 unsigned index=devices.size();
16 devices.push_back(&dev);
17 dev.signal_button_press.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index));
18 dev.signal_button_release.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index));
19 dev.signal_axis_motion.connect(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index));
23 std::string Hub::get_button_name(unsigned btn) const
25 unsigned dev_index=btn>>12;
26 if(dev_index>=devices.size())
27 throw InvalidParameterValue("Button does not exist");
29 const Device &dev=*devices[dev_index];
30 return dev.get_name()+": "+dev.get_button_name(btn&0xFFF);
33 std::string Hub::get_axis_name(unsigned axis) const
35 unsigned dev_index=axis>>12;
36 if(dev_index>=devices.size())
37 throw InvalidParameterValue("Axis does not exist");
39 const Device &dev=*devices[dev_index];
40 return dev.get_name()+": "+dev.get_axis_name(axis&0xFFF);
43 void Hub::button_press(unsigned btn, unsigned index)
45 set_button_state((index<<12) | (btn&0xFFF), true, true);
48 void Hub::button_release(unsigned btn, unsigned index)
50 set_button_state((index<<12) | (btn&0xFFF), false, true);
53 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
55 set_axis_value((index<<12) | (axis&0xFFF), value, true);