From 17cc7e2022000e2cce820ac8d898e0e8d1305f26 Mon Sep 17 00:00:00 2001 From: John Rennie Date: Thu, 24 Nov 2011 11:41:01 +0000 Subject: [PATCH] Allow multiple ids per USB device --- system/peripherals.xml | 12 ++----- xbmc/peripherals/PeripheralTypes.h | 9 ++++-- xbmc/peripherals/Peripherals.cpp | 51 +++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/system/peripherals.xml b/system/peripherals.xml index 038543be3caf2..8f916aec99a5b 100644 --- a/system/peripherals.xml +++ b/system/peripherals.xml @@ -1,13 +1,5 @@ - - - - - - - - - + @@ -16,7 +8,7 @@ - + diff --git a/xbmc/peripherals/PeripheralTypes.h b/xbmc/peripherals/PeripheralTypes.h index f3f0bf44d0822..53831fc3f70cd 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 m_PeripheralID; PeripheralBusType m_busType; PeripheralType m_class; CStdString m_strDeviceName; diff --git a/xbmc/peripherals/Peripherals.cpp b/xbmc/peripherals/Peripherals.cpp index 415dfd044c60c..c6105ee7c13d0 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::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, mapAttribute("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