Moved addition of extra events on devices to LinuxUinput, added extra events for joystick devices
This commit is contained in:
parent
936396e30f
commit
e4781149be
3 changed files with 43 additions and 27 deletions
|
@ -32,7 +32,8 @@
|
|||
#include "force_feedback_handler.hpp"
|
||||
#include "linux_uinput.hpp"
|
||||
|
||||
LinuxUinput::LinuxUinput(const std::string& name_, uint16_t vendor_, uint16_t product_) :
|
||||
LinuxUinput::LinuxUinput(DeviceType device_type, const std::string& name_, uint16_t vendor_, uint16_t product_) :
|
||||
m_device_type(device_type),
|
||||
name(name_),
|
||||
vendor(vendor_),
|
||||
product(product_),
|
||||
|
@ -183,6 +184,37 @@ LinuxUinput::set_ff_callback(const boost::function<void (uint8_t, uint8_t)>& cal
|
|||
void
|
||||
LinuxUinput::finish()
|
||||
{
|
||||
// Create some mandatory events that are needed for the kernel/Xorg
|
||||
// to register the device as its proper type
|
||||
switch(m_device_type)
|
||||
{
|
||||
case kGenericDevice:
|
||||
// nothing to be done
|
||||
break;
|
||||
|
||||
case kMouseDevice:
|
||||
add_rel(REL_X);
|
||||
add_rel(REL_Y);
|
||||
add_key(BTN_LEFT);
|
||||
break;
|
||||
|
||||
case kJoystickDevice:
|
||||
if (!key_lst[BTN_JOYSTICK] &&
|
||||
!key_lst[BTN_GAMEPAD] &&
|
||||
!key_lst[BTN_TRIGGER_HAPPY] &&
|
||||
|
||||
!abs_lst[ABS_THROTTLE] &&
|
||||
!abs_lst[ABS_WHEEL] &&
|
||||
!abs_lst[ABS_X])
|
||||
{
|
||||
// using BTN_TRIGGER_HAPPY instead of more common BTN_JOYSTICK
|
||||
// as it should end up as last joystick button instead of
|
||||
// first
|
||||
add_key(BTN_TRIGGER_HAPPY);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
strncpy(user_dev.name, name.c_str(), UINPUT_MAX_NAME_SIZE);
|
||||
user_dev.id.version = 0x114; // FIXME: whats this for?
|
||||
user_dev.id.bustype = BUS_USB;
|
||||
|
|
|
@ -28,7 +28,11 @@ class ForceFeedbackHandler;
|
|||
|
||||
class LinuxUinput
|
||||
{
|
||||
public:
|
||||
enum DeviceType { kGenericDevice, kMouseDevice, kJoystickDevice };
|
||||
|
||||
private:
|
||||
DeviceType m_device_type;
|
||||
std::string name;
|
||||
uint16_t vendor;
|
||||
uint16_t product;
|
||||
|
@ -52,7 +56,7 @@ private:
|
|||
bool needs_sync;
|
||||
|
||||
public:
|
||||
LinuxUinput(const std::string& name, uint16_t vendor, uint16_t product);
|
||||
LinuxUinput(DeviceType device_type, const std::string& name, uint16_t vendor, uint16_t product);
|
||||
~LinuxUinput();
|
||||
|
||||
/*@{*/
|
||||
|
|
|
@ -99,20 +99,23 @@ uInput::create_uinput_device(int device_id)
|
|||
}
|
||||
else
|
||||
{
|
||||
LinuxUinput::DeviceType device_type = LinuxUinput::kGenericDevice;
|
||||
std::ostringstream dev_name;
|
||||
dev_name << cfg.device_name;
|
||||
|
||||
switch (device_id)
|
||||
{
|
||||
case DEVICEID_JOYSTICK:
|
||||
dev_name << " - Mouse Emulation";
|
||||
device_type = LinuxUinput::kJoystickDevice;
|
||||
break;
|
||||
|
||||
case DEVICEID_MOUSE:
|
||||
device_type = LinuxUinput::kMouseDevice;
|
||||
dev_name << " - Mouse Emulation";
|
||||
break;
|
||||
|
||||
case DEVICEID_KEYBOARD:
|
||||
device_type = LinuxUinput::kGenericDevice;
|
||||
dev_name << " - Keyboard Emulation";
|
||||
break;
|
||||
|
||||
|
@ -121,32 +124,9 @@ uInput::create_uinput_device(int device_id)
|
|||
break;
|
||||
}
|
||||
|
||||
boost::shared_ptr<LinuxUinput> dev(new LinuxUinput(dev_name.str(), m_vendor_id, m_product_id));
|
||||
boost::shared_ptr<LinuxUinput> dev(new LinuxUinput(device_type, dev_name.str(), m_vendor_id, m_product_id));
|
||||
uinput_devs.insert(std::pair<int, boost::shared_ptr<LinuxUinput> >(device_id, dev));
|
||||
|
||||
// Create some mandatory events that are needed for the kernel/Xorg
|
||||
// to register the device as its proper type
|
||||
switch(device_id)
|
||||
{
|
||||
case DEVICEID_KEYBOARD:
|
||||
// do nothing, detection seems to be fine without
|
||||
break;
|
||||
|
||||
case DEVICEID_MOUSE:
|
||||
dev->add_rel(REL_X);
|
||||
dev->add_rel(REL_Y);
|
||||
dev->add_key(BTN_LEFT);
|
||||
break;
|
||||
|
||||
case DEVICEID_JOYSTICK:
|
||||
// FIXME: do nothing, as we don't know yet the range of abs,
|
||||
// unmapped buttons might also confuse some games
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "Creating uinput device: device_id: " << device_id << ", dev_name: " << dev_name.str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue