HID: allow raw-descriptor parsing in the XML
Also fix deadband computation (do it after min-max ranging)
This commit is contained in:
parent
005ddf7c98
commit
8bedd52e2b
2 changed files with 35 additions and 16 deletions
|
@ -176,12 +176,12 @@ void FGAxisEvent::fire( FGEventData & eventData )
|
||||||
// We need a copy of the FGEventData struct to set the new value and to avoid side effects
|
// We need a copy of the FGEventData struct to set the new value and to avoid side effects
|
||||||
FGEventData ed = eventData;
|
FGEventData ed = eventData;
|
||||||
|
|
||||||
if( fabs(ed.value) < deadband )
|
|
||||||
ed.value = 0.0;
|
|
||||||
|
|
||||||
if( minRange != maxRange )
|
if( minRange != maxRange )
|
||||||
ed.value = 2.0*(eventData.value-minRange)/(maxRange-minRange)-1.0;
|
ed.value = 2.0*(eventData.value-minRange)/(maxRange-minRange)-1.0;
|
||||||
|
|
||||||
|
if( fabs(ed.value) < deadband )
|
||||||
|
ed.value = 0.0;
|
||||||
|
|
||||||
if (interpolater) {
|
if (interpolater) {
|
||||||
if ((ed.value < 0.0) && mirrorInterpolater) {
|
if ((ed.value < 0.0) && mirrorInterpolater) {
|
||||||
// mirror the positive interpolation for negative values
|
// mirror the positive interpolation for negative values
|
||||||
|
|
|
@ -318,6 +318,9 @@ private:
|
||||||
/// is inaccessible, or devices with broken descriptors
|
/// is inaccessible, or devices with broken descriptors
|
||||||
bool _haveLocalDescriptor = false;
|
bool _haveLocalDescriptor = false;
|
||||||
|
|
||||||
|
/// allow specifying the descriptor as hex bytes in XML
|
||||||
|
std::vector<uint8_t>_rawXMLDescriptor;
|
||||||
|
|
||||||
// all sets which will be send on the next update() call.
|
// all sets which will be send on the next update() call.
|
||||||
std::set<Report*> _dirtyReports;
|
std::set<Report*> _dirtyReports;
|
||||||
};
|
};
|
||||||
|
@ -384,6 +387,13 @@ void FGHIDDevice::Configure(SGPropertyNode_ptr node)
|
||||||
defineReport(report);
|
defineReport(report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node->hasChild("hid-raw-descriptor")) {
|
||||||
|
_rawXMLDescriptor = simgear::strutils::decodeHex(node->getStringValue("hid-raw-descriptor"));
|
||||||
|
if (debugEvents) {
|
||||||
|
SG_LOG(SG_INPUT, SG_INFO, GetUniqueName() << " will configure using XML-defined raw HID descriptor");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FGHIDDevice::Open()
|
bool FGHIDDevice::Open()
|
||||||
|
@ -395,6 +405,19 @@ bool FGHIDDevice::Open()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(SG_WINDOWS)
|
||||||
|
if (_rawXMLDescriptor.empty()) {
|
||||||
|
_rawXMLDescriptor.resize(2048);
|
||||||
|
int descriptorSize = hid_get_descriptor(_device, _rawXMLDescriptor.data(), _rawXMLDescriptor.size());
|
||||||
|
if (descriptorSize <= 0) {
|
||||||
|
SG_LOG(SG_INPUT, SG_WARN, "HID: " << GetUniqueName() << " failed to read HID descriptor");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_rawXMLDescriptor.resize(descriptorSize);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!_haveLocalDescriptor) {
|
if (!_haveLocalDescriptor) {
|
||||||
bool ok = parseUSBHIDDescriptor();
|
bool ok = parseUSBHIDDescriptor();
|
||||||
if (!ok)
|
if (!ok)
|
||||||
|
@ -422,26 +445,22 @@ bool FGHIDDevice::Open()
|
||||||
bool FGHIDDevice::parseUSBHIDDescriptor()
|
bool FGHIDDevice::parseUSBHIDDescriptor()
|
||||||
{
|
{
|
||||||
#if defined(SG_WINDOWS)
|
#if defined(SG_WINDOWS)
|
||||||
SG_LOG(SG_INPUT, SG_ALERT, GetUniqueName() << ": on Windows, there is no way to extract the UDB-HID report descriptor. "
|
if (_rawXMLDescriptor.empty()) {
|
||||||
<< "\nPlease supply the report descriptor in the device XML configuration.");
|
SG_LOG(SG_INPUT, SG_ALERT, GetUniqueName() << ": on Windows, there is no way to extract the UDB-HID report descriptor. "
|
||||||
return false;
|
<< "\nPlease supply the report descriptor in the device XML configuration.");
|
||||||
#endif
|
SG_LOG(SG_INPUT, SG_ALERT, "See this page:<> for information on extracting the report descriptor on Windows");
|
||||||
|
|
||||||
unsigned char reportDescriptor[1024];
|
|
||||||
int descriptorSize = hid_get_descriptor(_device, reportDescriptor, 1024);
|
|
||||||
if (descriptorSize <= 0) {
|
|
||||||
SG_LOG(SG_INPUT, SG_WARN, "HID: " << GetUniqueName() << " failed to read HID descriptor");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (debugEvents) {
|
if (debugEvents) {
|
||||||
SG_LOG(SG_INPUT, SG_INFO, "\nHID: descriptor for:" << GetUniqueName());
|
SG_LOG(SG_INPUT, SG_INFO, "\nHID: descriptor for:" << GetUniqueName());
|
||||||
{
|
{
|
||||||
std::ostringstream byteString;
|
std::ostringstream byteString;
|
||||||
|
|
||||||
for (int i=0; i<descriptorSize; ++i) {
|
for (auto i=0; i<_rawXMLDescriptor.size(); ++i) {
|
||||||
byteString << hexTable[reportDescriptor[i] >> 4];
|
byteString << hexTable[_rawXMLDescriptor[i] >> 4];
|
||||||
byteString << hexTable[reportDescriptor[i] & 0x0f];
|
byteString << hexTable[_rawXMLDescriptor[i] & 0x0f];
|
||||||
byteString << " ";
|
byteString << " ";
|
||||||
}
|
}
|
||||||
SG_LOG(SG_INPUT, SG_INFO, "\tbytes: " << byteString.str());
|
SG_LOG(SG_INPUT, SG_INFO, "\tbytes: " << byteString.str());
|
||||||
|
@ -449,7 +468,7 @@ bool FGHIDDevice::parseUSBHIDDescriptor()
|
||||||
}
|
}
|
||||||
|
|
||||||
hid_item* rootItem = nullptr;
|
hid_item* rootItem = nullptr;
|
||||||
hid_parse_reportdesc(reportDescriptor, descriptorSize, &rootItem);
|
hid_parse_reportdesc(_rawXMLDescriptor.data(), _rawXMLDescriptor.size(), &rootItem);
|
||||||
if (debugEvents) {
|
if (debugEvents) {
|
||||||
SG_LOG(SG_INPUT, SG_INFO, "\nHID: scan for:" << GetUniqueName());
|
SG_LOG(SG_INPUT, SG_INFO, "\nHID: scan for:" << GetUniqueName());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue