HID-Input disambiguation tweaks
This commit is contained in:
parent
361225f919
commit
921f29fbfe
4 changed files with 20 additions and 10 deletions
|
@ -266,6 +266,7 @@ if(EVENT_INPUT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_HID_INPUT)
|
if (ENABLE_HID_INPUT)
|
||||||
|
message(STATUS "Enabling HID-API input")
|
||||||
list(APPEND EVENT_INPUT_LIBRARIES hidapi)
|
list(APPEND EVENT_INPUT_LIBRARIES hidapi)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -369,17 +369,20 @@ unsigned FGEventInput::AddDevice( FGInputDevice * inputDevice )
|
||||||
const string deviceName = inputDevice->GetName();
|
const string deviceName = inputDevice->GetName();
|
||||||
SGPropertyNode_ptr configNode;
|
SGPropertyNode_ptr configNode;
|
||||||
|
|
||||||
|
// if we have a serial number set, tru using that to select a specfic configuration
|
||||||
if (!inputDevice->GetSerialNumber().empty()) {
|
if (!inputDevice->GetSerialNumber().empty()) {
|
||||||
const string nameWithSerial = deviceName + "::" + inputDevice->GetSerialNumber();
|
const string nameWithSerial = deviceName + "::" + inputDevice->GetSerialNumber();
|
||||||
if (configMap.hasConfiguration(nameWithSerial)) {
|
if (configMap.hasConfiguration(nameWithSerial)) {
|
||||||
configNode = configMap.configurationForDeviceName(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 (configNode == nullptr) {
|
||||||
if (!configMap.hasConfiguration(deviceName)) {
|
if (!configMap.hasConfiguration(deviceName)) {
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "No configuration found for device " << deviceName <<
|
SG_LOG(SG_INPUT, SG_DEBUG, "No configuration found for device " << deviceName);
|
||||||
" (with serial: " << inputDevice->GetSerialNumber() << ")");
|
|
||||||
delete inputDevice;
|
delete inputDevice;
|
||||||
return INVALID_DEVICE_INDEX;
|
return INVALID_DEVICE_INDEX;
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,11 +313,21 @@ FGHIDDevice::FGHIDDevice(hid_device_info *devInfo, FGHIDEventInput *)
|
||||||
productName = std::wstring(devInfo->product_string);
|
productName = std::wstring(devInfo->product_string);
|
||||||
const auto serial = devInfo->serial_number;
|
const auto serial = devInfo->serial_number;
|
||||||
|
|
||||||
auto path = devInfo->path;
|
|
||||||
|
|
||||||
SetName(simgear::strutils::convertWStringToUtf8(manufactuerName) + " " +
|
SetName(simgear::strutils::convertWStringToUtf8(manufactuerName) + " " +
|
||||||
simgear::strutils::convertWStringToUtf8(productName));
|
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()
|
FGHIDDevice::~FGHIDDevice()
|
||||||
|
|
|
@ -252,7 +252,7 @@ void FGMacOSXEventInputPrivate::matchedDevice(IOHIDDeviceRef device)
|
||||||
std::string manufacturer = getDeviceStringProperty(device, CFSTR(kIOHIDManufacturerKey));
|
std::string manufacturer = getDeviceStringProperty(device, CFSTR(kIOHIDManufacturerKey));
|
||||||
std::string serial = getDeviceStringProperty(device, CFSTR(kIOHIDSerialNumberKey));
|
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
|
// allocate a Mac input device, and add to the base class to see if we have
|
||||||
// a config
|
// a config
|
||||||
|
@ -268,10 +268,6 @@ void FGMacOSXEventInputPrivate::removedDevice(IOHIDDeviceRef device)
|
||||||
{
|
{
|
||||||
std::string productName = getDeviceStringProperty(device, CFSTR(kIOHIDProductKey));
|
std::string productName = getDeviceStringProperty(device, CFSTR(kIOHIDProductKey));
|
||||||
std::string manufacturer = getDeviceStringProperty(device, CFSTR(kIOHIDManufacturerKey));
|
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
|
// see if we have an entry for the device
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue