From 921f29fbfed40aa9c33ddce7fda0a9b6c448d83a Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 9 Apr 2018 22:03:49 +0100 Subject: [PATCH] HID-Input disambiguation tweaks --- CMakeLists.txt | 1 + src/Input/FGEventInput.cxx | 7 +++++-- src/Input/FGHIDEventInput.cxx | 16 +++++++++++++--- src/Input/FGMacOSXEventInput.cxx | 6 +----- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f877da9b6..5a2525e46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,6 +266,7 @@ if(EVENT_INPUT) endif() if (ENABLE_HID_INPUT) + message(STATUS "Enabling HID-API input") list(APPEND EVENT_INPUT_LIBRARIES hidapi) endif() diff --git a/src/Input/FGEventInput.cxx b/src/Input/FGEventInput.cxx index 9e46ec2ea..e34f09bf6 100644 --- a/src/Input/FGEventInput.cxx +++ b/src/Input/FGEventInput.cxx @@ -369,17 +369,20 @@ unsigned FGEventInput::AddDevice( FGInputDevice * inputDevice ) const string deviceName = inputDevice->GetName(); SGPropertyNode_ptr configNode; + // if we have a serial number set, tru using that to select a specfic configuration if (!inputDevice->GetSerialNumber().empty()) { const string nameWithSerial = deviceName + "::" + inputDevice->GetSerialNumber(); if (configMap.hasConfiguration(nameWithSerial)) { configNode = configMap.configurationForDeviceName(nameWithSerial); + SG_LOG(SG_INPUT, SG_INFO, "using instance-specific configuration for device " + << nameWithSerial << " : " << configNode->getStringValue("source")); } } + // otherwise try the unmodifed name for the device if (configNode == nullptr) { if (!configMap.hasConfiguration(deviceName)) { - SG_LOG(SG_INPUT, SG_DEBUG, "No configuration found for device " << deviceName << - " (with serial: " << inputDevice->GetSerialNumber() << ")"); + SG_LOG(SG_INPUT, SG_DEBUG, "No configuration found for device " << deviceName); delete inputDevice; return INVALID_DEVICE_INDEX; } diff --git a/src/Input/FGHIDEventInput.cxx b/src/Input/FGHIDEventInput.cxx index 0c0592e4b..3b2c96a1b 100644 --- a/src/Input/FGHIDEventInput.cxx +++ b/src/Input/FGHIDEventInput.cxx @@ -313,11 +313,21 @@ FGHIDDevice::FGHIDDevice(hid_device_info *devInfo, FGHIDEventInput *) productName = std::wstring(devInfo->product_string); const auto serial = devInfo->serial_number; - auto path = devInfo->path; - SetName(simgear::strutils::convertWStringToUtf8(manufactuerName) + " " + simgear::strutils::convertWStringToUtf8(productName)); - SetSerialNumber(simgear::strutils::convertWStringToUtf8(serial)); + + // every device so far encountered returns a blank serial number, so we + // fall back to the device path to disambiguate. + std::string path(devInfo->path); + if ((serial == nullptr) || std::wcslen(serial) == 0) { + // use device path to disambiguate + if (!path.empty()) { + SG_LOG(SG_INPUT, SG_INFO, "Missing serial on device, using path: " << path); + SetSerialNumber(path); + } + } else { + SetSerialNumber(simgear::strutils::convertWStringToUtf8(serial)); + } } FGHIDDevice::~FGHIDDevice() diff --git a/src/Input/FGMacOSXEventInput.cxx b/src/Input/FGMacOSXEventInput.cxx index 226c2664e..9eb7e80a6 100644 --- a/src/Input/FGMacOSXEventInput.cxx +++ b/src/Input/FGMacOSXEventInput.cxx @@ -252,7 +252,7 @@ void FGMacOSXEventInputPrivate::matchedDevice(IOHIDDeviceRef device) std::string manufacturer = getDeviceStringProperty(device, CFSTR(kIOHIDManufacturerKey)); std::string serial = getDeviceStringProperty(device, CFSTR(kIOHIDSerialNumberKey)); - SG_LOG(SG_INPUT, SG_INFO, "matched device:" << productName << " from " << manufacturer); + SG_LOG(SG_INPUT, SG_DEBUG, "MacOSX-EventInput: matched device:" << productName << "( from " << manufacturer << ")"); // allocate a Mac input device, and add to the base class to see if we have // a config @@ -268,10 +268,6 @@ void FGMacOSXEventInputPrivate::removedDevice(IOHIDDeviceRef device) { std::string productName = getDeviceStringProperty(device, CFSTR(kIOHIDProductKey)); std::string manufacturer = getDeviceStringProperty(device, CFSTR(kIOHIDManufacturerKey)); - - SG_LOG(SG_INPUT, SG_INFO, "removed device:" << productName << " from " << manufacturer); - - // see if we have an entry for the device }