diff options
author | John Rennie <john.rennie@ratsauce.co.uk> | 2011-11-24 11:41:01 +0000 |
---|---|---|
committer | John Rennie <john.rennie@ratsauce.co.uk> | 2011-11-24 11:41:01 +0000 |
commit | 17cc7e2022000e2cce820ac8d898e0e8d1305f26 (patch) | |
tree | 47699dcd5ffac635f1d4627d4b49ac1bf7ac7467 | |
parent | e86e4f44dfb61aea1dbdbfc1535fc2f6b3d46f98 (diff) |
Allow multiple ids per USB device
-rw-r--r-- | system/peripherals.xml | 12 | ||||
-rw-r--r-- | xbmc/peripherals/PeripheralTypes.h | 9 | ||||
-rw-r--r-- | xbmc/peripherals/Peripherals.cpp | 51 |
3 files changed, 48 insertions, 24 deletions
diff --git a/system/peripherals.xml b/system/peripherals.xml index 038543be3c..8f916aec99 100644 --- a/system/peripherals.xml +++ b/system/peripherals.xml @@ -1,13 +1,5 @@ <peripherals> - <peripheral vendor="1915" product="003B" bus="usb" name="Motorola Nyxboard Hybrid" mapTo="nyxboard"> - <setting key="keymap_enabled" type="bool" value="1" label="35008" /> - <setting key="keymap" value="nyxboard" label="35007" configurable="0" /> - <setting key="enable_flip_commands" type="bool" value="1" label="36005" /> - <setting key="flip_keyboard" value="XBMC.VideoLibrary.Search" label="36002" /> - <setting key="flip_remote" value="Dialog.Close(virtualkeyboard)" label="36003" /> - <setting key="key_user" value="" label="36004" /> - </peripheral> - <peripheral vendor="22B8" product="003B" bus="usb" name="Motorola Nyxboard Hybrid" mapTo="nyxboard"> + <peripheral vendor_product="1915:003B,22B8:003B" bus="usb" name="Motorola Nyxboard Hybrid" mapTo="nyxboard"> <setting key="keymap_enabled" type="bool" value="1" label="35008" /> <setting key="keymap" value="nyxboard" label="35007" configurable="0" /> <setting key="enable_flip_commands" type="bool" value="1" label="36005" /> @@ -16,7 +8,7 @@ <setting key="key_user" value="" label="36004" /> </peripheral> - <peripheral vendor="2548" product="1001" bus="usb" name="Pulse-Eight CEC Adaptor" mapTo="cec"> + <peripheral vendor_product="2548:1001" bus="usb" name="Pulse-Eight CEC Adaptor" mapTo="cec"> <setting key="enabled" type="bool" value="1" label="305" /> <setting key="port" type="string" value="" label="792" /> <setting key="cec_hdmi_port" type="int" value="1" min="1" max="16" label="36015" /> diff --git a/xbmc/peripherals/PeripheralTypes.h b/xbmc/peripherals/PeripheralTypes.h index f3f0bf44d0..53831fc3f7 100644 --- a/xbmc/peripherals/PeripheralTypes.h +++ b/xbmc/peripherals/PeripheralTypes.h @@ -62,10 +62,15 @@ namespace PERIPHERALS PERIPHERAL_TUNER }; + struct PeripheralID + { + int m_iVendorId; + int m_iProductId; + }; + struct PeripheralDeviceMapping { - int m_iVendorId; - int m_iProductId; + std::vector<PeripheralID> m_PeripheralID; PeripheralBusType m_busType; PeripheralType m_class; CStdString m_strDeviceName; diff --git a/xbmc/peripherals/Peripherals.cpp b/xbmc/peripherals/Peripherals.cpp index 415dfd044c..c6105ee7c1 100644 --- a/xbmc/peripherals/Peripherals.cpp +++ b/xbmc/peripherals/Peripherals.cpp @@ -324,12 +324,16 @@ int CPeripherals::GetMappingForDevice(const CPeripheralBus &bus, const Periphera for (unsigned int iMappingPtr = 0; iMappingPtr < m_mappings.size(); iMappingPtr++) { PeripheralDeviceMapping mapping = m_mappings.at(iMappingPtr); + + bool bProductMatch = false; + for (unsigned int i = 0; i < mapping.m_PeripheralID.size(); i++) + if (mapping.m_PeripheralID[i].m_iVendorId == iVendorId && mapping.m_PeripheralID[i].m_iProductId == iProductId) + bProductMatch = true; + bool bBusMatch = (mapping.m_busType == PERIPHERAL_BUS_UNKNOWN || mapping.m_busType == bus.Type()); - bool bVendorMatch = (mapping.m_iVendorId == 0 || mapping.m_iVendorId == iVendorId); - bool bProductMatch = (mapping.m_iProductId == 0 || mapping.m_iProductId == iProductId); bool bClassMatch = (mapping.m_class == PERIPHERAL_UNKNOWN || mapping.m_class == classType); - if (bBusMatch && bVendorMatch && bProductMatch && bClassMatch) + if (bProductMatch && bBusMatch && bClassMatch) { CStdString strVendorId, strProductId; PeripheralTypeTranslator::FormatHexString(iVendorId, strVendorId); @@ -348,12 +352,16 @@ void CPeripherals::GetSettingsFromMapping(CPeripheral &peripheral) const for (unsigned int iMappingPtr = 0; iMappingPtr < m_mappings.size(); iMappingPtr++) { const PeripheralDeviceMapping *mapping = &m_mappings.at(iMappingPtr); + + bool bProductMatch = false; + for (unsigned int i = 0; i < mapping->m_PeripheralID.size(); i++) + if (mapping->m_PeripheralID[i].m_iVendorId == peripheral.VendorId() && mapping->m_PeripheralID[i].m_iProductId == peripheral.ProductId()) + bProductMatch = true; + bool bBusMatch = (mapping->m_busType == PERIPHERAL_BUS_UNKNOWN || mapping->m_busType == peripheral.GetBusType()); - bool bVendorMatch = (mapping->m_iVendorId == 0 || mapping->m_iVendorId == peripheral.VendorId()); - bool bProductMatch = (mapping->m_iProductId == 0 || mapping->m_iProductId == peripheral.ProductId()); bool bClassMatch = (mapping->m_class == PERIPHERAL_UNKNOWN || mapping->m_class == peripheral.Type()); - if (bBusMatch && bVendorMatch && bProductMatch && bClassMatch) + if (bBusMatch && bProductMatch && bClassMatch) { for (map<CStdString, CSetting *>::const_iterator itr = mapping->m_settings.begin(); itr != mapping->m_settings.end(); itr++) peripheral.AddSetting((*itr).first, (*itr).second); @@ -380,10 +388,29 @@ bool CPeripherals::LoadMappings(void) TiXmlElement *currentNode = pRootElement->FirstChildElement("peripheral"); while (currentNode) { + CStdStringArray vpArray, idArray; + PeripheralID id; PeripheralDeviceMapping mapping; - mapping.m_iVendorId = currentNode->Attribute("vendor") ? PeripheralTypeTranslator::HexStringToInt(currentNode->Attribute("vendor")) : 0; - mapping.m_iProductId = currentNode->Attribute("product") ? PeripheralTypeTranslator::HexStringToInt(currentNode->Attribute("product")) : 0; + // If there is no vendor_product attribute ignore this entry + if (!currentNode->Attribute("vendor_product")) + continue; + + // The vendor_product attribute is a list of comma separated vendor:product pairs + StringUtils::SplitString(currentNode->Attribute("vendor_product"), ",", vpArray); + for (unsigned int i = 0; i < vpArray.size(); i++) + { + StringUtils::SplitString(vpArray[i], ":", idArray); + if (idArray.size() != 2) + continue; + + id.m_iVendorId = PeripheralTypeTranslator::HexStringToInt(idArray[0]); + id.m_iProductId = PeripheralTypeTranslator::HexStringToInt(idArray[1]); + mapping.m_PeripheralID.push_back(id); + } + if (mapping.m_PeripheralID.size() == 0) + continue; + mapping.m_busType = PeripheralTypeTranslator::GetBusTypeFromString(currentNode->Attribute("bus")); mapping.m_class = PeripheralTypeTranslator::GetTypeFromString(currentNode->Attribute("class")); mapping.m_strDeviceName = currentNode->Attribute("name") ? CStdString(currentNode->Attribute("name")) : StringUtils::EmptyString; @@ -432,10 +459,10 @@ void CPeripherals::GetSettingsFromMappingsFile(TiXmlElement *xmlNode, map<CStdSt } else if (strSettingsType.Equals("float")) { - float fValue = currentNode->Attribute("value") ? atof(currentNode->Attribute("value")) : 0; - float fMin = currentNode->Attribute("min") ? atof(currentNode->Attribute("min")) : 0; - float fStep = currentNode->Attribute("step") ? atof(currentNode->Attribute("step")) : 0; - float fMax = currentNode->Attribute("max") ? atof(currentNode->Attribute("max")) : 0; + float fValue = currentNode->Attribute("value") ? (float) atof(currentNode->Attribute("value")) : 0; + float fMin = currentNode->Attribute("min") ? (float) atof(currentNode->Attribute("min")) : 0; + float fStep = currentNode->Attribute("step") ? (float) atof(currentNode->Attribute("step")) : 0; + float fMax = currentNode->Attribute("max") ? (float) atof(currentNode->Attribute("max")) : 0; setting = new CSettingFloat(0, strKey, iLabelId, fValue, fMin, fStep, fMax, SPIN_CONTROL_FLOAT); } else |