From bfea6e0a8ee4bc9e40c64ea68f22db69ac3cb26f Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Tue, 26 Feb 2013 23:30:33 +0100 Subject: [PATCH] added bQuickScan param to DetectDevices(), so we don't try to open a connection each time we scan --- include/cec.h | 3 ++- include/cecc.h | 4 ++-- src/lib/LibCEC.cpp | 19 +++++++++++-------- src/lib/LibCEC.h | 2 +- src/lib/LibCECC.cpp | 4 ++-- src/lib/adapter/AdapterFactory.cpp | 2 ++ .../Pulse-Eight/USBCECAdapterDetection.cpp | 5 +++++ 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/cec.h b/include/cec.h index b2f232f..ebfaf48 100644 --- a/include/cec.h +++ b/include/cec.h @@ -453,9 +453,10 @@ namespace CEC * @param deviceList The vector to store device descriptors in. * @param iBufSize The size of the deviceList buffer. * @param strDevicePath Optional device path. Only adds device descriptors that match the given device path. + * @param bQuickScan True to do a "quick scan", which will not open a connection to the adapter. Firmware version information and the exact device type will be missing * @return The number of devices that were found, or -1 when an error occured. */ - virtual int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL) = 0; + virtual int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL, bool bQuickScan = false) = 0; }; }; diff --git a/include/cecc.h b/include/cecc.h index ac1c541..0aca0b7 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -285,9 +285,9 @@ extern DECLSPEC uint8_t cec_audio_unmute(void); extern DECLSPEC uint8_t cec_audio_get_status(void); #ifdef __cplusplus -extern DECLSPEC int8_t cec_detect_adapters(CEC::cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath); +extern DECLSPEC int8_t cec_detect_adapters(CEC::cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath, int bQuickScan); #else -extern DECLSPEC int8_t cec_detect_adapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath); +extern DECLSPEC int8_t cec_detect_adapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath, int bQuickScan); #endif #ifdef __cplusplus diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index c04283d..c24b4ed 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -560,17 +560,20 @@ uint8_t CLibCEC::AudioStatus(void) return m_client ? m_client->AudioStatus() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; } -int8_t CLibCEC::DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) +int8_t CLibCEC::DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */, bool bQuickScan /* = false */) { int8_t iAdaptersFound = CAdapterFactory(this).DetectAdapters(deviceList, iBufSize, strDevicePath); - for (int8_t iPtr = 0; iPtr < iAdaptersFound; iPtr++) + if (!bQuickScan) { - libcec_configuration config; - GetDeviceInformation(deviceList[iPtr].strComName, &config); - deviceList[iPtr].iFirmwareVersion = config.iFirmwareVersion; - deviceList[iPtr].iPhysicalAddress = config.iPhysicalAddress; - deviceList[iPtr].iFirmwareBuildDate = config.iFirmwareBuildDate; - deviceList[iPtr].adapterType = config.adapterType; + for (int8_t iPtr = 0; iPtr < iAdaptersFound; iPtr++) + { + libcec_configuration config; + GetDeviceInformation(deviceList[iPtr].strComName, &config); + deviceList[iPtr].iFirmwareVersion = config.iFirmwareVersion; + deviceList[iPtr].iPhysicalAddress = config.iPhysicalAddress; + deviceList[iPtr].iFirmwareBuildDate = config.iFirmwareBuildDate; + deviceList[iPtr].adapterType = config.adapterType; + } } return iAdaptersFound; } diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 385b745..3a312c0 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -52,7 +52,7 @@ namespace CEC void Close(void); bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks); int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); - int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); + int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL, bool bQuickScan = false); bool PingAdapter(void); bool StartBootloader(void); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index b73596e..8309c3c 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -408,10 +408,10 @@ uint8_t cec_audio_get_status(void) return cec_parser ? cec_parser->AudioStatus() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; } -int8_t cec_detect_adapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) +int8_t cec_detect_adapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath, int bQuickScan) { if (cec_parser) - return cec_parser->DetectAdapters(deviceList, iBufSize, strDevicePath); + return cec_parser->DetectAdapters(deviceList, iBufSize, strDevicePath, bQuickScan); return -1; } diff --git a/src/lib/adapter/AdapterFactory.cpp b/src/lib/adapter/AdapterFactory.cpp index ded3b6f..ae90642 100644 --- a/src/lib/adapter/AdapterFactory.cpp +++ b/src/lib/adapter/AdapterFactory.cpp @@ -91,6 +91,7 @@ int8_t CAdapterFactory::DetectAdapters(cec_adapter_descriptor *deviceList, uint8 snprintf(deviceList[iAdaptersFound].strComName, sizeof(deviceList[iAdaptersFound].strComName), CEC_RPI_VIRTUAL_COM); deviceList[iAdaptersFound].iVendorId = RPI_ADAPTER_VID; deviceList[iAdaptersFound].iProductId = RPI_ADAPTER_PID; + deviceList[iAdaptersFound].adapterType = ADAPTERTYPE_RPI; iAdaptersFound++; } #endif @@ -103,6 +104,7 @@ int8_t CAdapterFactory::DetectAdapters(cec_adapter_descriptor *deviceList, uint8 snprintf(deviceList[iAdaptersFound].comm, sizeof(deviceList[iAdaptersFound].strComName), CEC_TDA995x_VIRTUAL_COM); deviceList[iAdaptersFound].iVendorId = TDA995X_ADAPTER_VID; deviceList[iAdaptersFound].iProductId = TDA995X_ADAPTER_PID; + deviceList[iAdaptersFound].adapterType = ADAPTERTYPE_TDA995x; iAdaptersFound++; } #endif diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp index 40b57d1..456350f 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp @@ -268,6 +268,7 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter_descriptor *deviceList snprintf(deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName), "%s", bsdPath); deviceList[iFound].iVendorId = iVendor; deviceList[iFound].iProductId = iProduct; + deviceList[iFound].adapterType = ADAPTERTYPE_P8_EXTERNAL; // will be overridden when not doing a "quick scan" by the actual type iFound++; } } @@ -320,6 +321,7 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter_descriptor *deviceList snprintf(deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName), "%s", strComm.c_str()); deviceList[iFound].iVendorId = iVendor; deviceList[iFound].iProductId = iProduct; + deviceList[iFound].adapterType = ADAPTERTYPE_P8_EXTERNAL; // will be overridden when not doing a "quick scan" by the actual type iFound++; } } @@ -417,6 +419,7 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter_descriptor *deviceList snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", devicedetailData->DevicePath); deviceList[iFound].iVendorId = iVendor; deviceList[iFound].iProductId = iProduct; + deviceList[iFound].adapterType = ADAPTERTYPE_P8_EXTERNAL; // will be overridden when not doing a "quick scan" by the actual type iFound++; } } @@ -425,6 +428,7 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter_descriptor *deviceList snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", devicedetailData->DevicePath); deviceList[iFound].iVendorId = iVendor; deviceList[iFound].iProductId = iProduct; + deviceList[iFound].adapterType = ADAPTERTYPE_P8_EXTERNAL; // will be overridden when not doing a "quick scan" by the actual type iFound++; } } @@ -443,6 +447,7 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter_descriptor *deviceList snprintf(deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName), "%s", devicePath); deviceList[iFound].iVendorId = CEC_VID; deviceList[iFound].iProductId = CEC_VID; + deviceList[iFound].adapterType = ADAPTERTYPE_P8_EXTERNAL; // will be overridden when not doing a "quick scan" by the actual type iFound++; } } -- 2.34.1