From: Lars Op den Kamp Date: Sat, 6 Oct 2012 12:39:07 +0000 (+0200) Subject: added GetAdapterProductId()+GetAdapterVendorId()/cec_get_adapter_product_id()+cec_get... X-Git-Tag: upstream/2.2.0~1^2~17^2^2~27 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8768aecabf8219cdf0ceb28a8b9ca4ef6756b612;p=deb_libcec.git added GetAdapterProductId()+GetAdapterVendorId()/cec_get_adapter_product_id()+cec_get_adapter_vendor_id() --- diff --git a/include/cec.h b/include/cec.h index 8d14164..1b0019b 100644 --- a/include/cec.h +++ b/include/cec.h @@ -397,6 +397,16 @@ namespace CEC */ virtual void InitVideoStandalone(void) = 0; + /*! + * @return The (virtual) USB vendor id + */ + virtual uint16_t GetAdapterVendorId(void) const = 0; + + /*! + * @return The (virtual) USB product id + */ + virtual uint16_t GetAdapterProductId(void) const = 0; + virtual const char *ToString(const cec_menu_state state) = 0; virtual const char *ToString(const cec_version version) = 0; virtual const char *ToString(const cec_power_status status) = 0; diff --git a/include/cecc.h b/include/cecc.h index 5241e73..a4892c4 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -272,6 +272,10 @@ extern DECLSPEC const char * cec_get_lib_info(void); extern DECLSPEC void cec_init_video_standalone(void); +extern DECLSPEC uint16_t cec_get_adapter_vendor_id(void); + +extern DECLSPEC uint16_t cec_get_adapter_product_id(void); + #ifdef __cplusplus }; #endif diff --git a/src/LibCecSharp/LibCecSharp.cpp b/src/LibCecSharp/LibCecSharp.cpp index a008f2e..ff3c619 100644 --- a/src/LibCecSharp/LibCecSharp.cpp +++ b/src/LibCecSharp/LibCecSharp.cpp @@ -731,6 +731,24 @@ namespace CecSharp m_libCec->InitVideoStandalone(); } + /// + /// Get the (virtual) USB vendor id + /// + /// The (virtual) USB vendor id + uint16_t GetAdapterVendorId() + { + return m_libCec->GetAdapterVendorId(); + } + + /// + /// Get the (virtual) USB product id + /// + /// The (virtual) USB product id + uint16_t GetAdapterProductId() + { + return m_libCec->GetAdapterProductId(); + } + private: !LibCecSharp(void) { diff --git a/src/LibCecTray/controller/CECController.cs b/src/LibCecTray/controller/CECController.cs index 13d7520..f7a3a04 100644 --- a/src/LibCecTray/controller/CECController.cs +++ b/src/LibCecTray/controller/CECController.cs @@ -490,20 +490,6 @@ namespace LibCECTray.controller get { return Lib.ToString(Config.ClientVersion); } } - /// - /// Get the usb vid:prod descriptor - /// - public string USBDescriptor - { - get - { - DateTime checkDate = new DateTime(1970, 1, 1, 0, 0, 0, 0); - checkDate = checkDate.AddSeconds(0x5045dbf5); - - return string.Format("2548:100{0}", ((DateTime)Config.FirmwareBuildDate >= checkDate ? "2" : "1")); - } - } - /// /// libCEC /// diff --git a/src/LibCecTray/controller/applications/internal/XBMCController.cs b/src/LibCecTray/controller/applications/internal/XBMCController.cs index 5ffe8f9..9e4fb3a 100644 --- a/src/LibCecTray/controller/applications/internal/XBMCController.cs +++ b/src/LibCecTray/controller/applications/internal/XBMCController.cs @@ -69,17 +69,17 @@ namespace LibCECTray.controller.applications.@internal } public bool LoadXMLConfiguration() - { - var xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data"; - return LoadXMLConfiguration(xbmcDir + @"\usb_2548_1001.xml") || LoadXMLConfiguration(xbmcDir + @"\usb_2548_1002.xml"); - } - - public bool LoadXMLConfiguration(string filename) { bool gotConfig = false; - if (File.Exists(filename)) + string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data"; + string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + string file = defaultDir + @"\usb_2548_1001.xml"; + if (File.Exists(xbmcDir + @"\usb_2548_1001.xml")) + file = xbmcDir + @"\usb_2548_1001.xml"; + + if (File.Exists(file)) { - XmlTextReader reader = new XmlTextReader(filename); + XmlTextReader reader = new XmlTextReader(file); while (reader.Read()) { gotConfig = true; @@ -203,23 +203,14 @@ namespace LibCECTray.controller.applications.@internal { Settings.Persist(); - var xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data"; - if (!Directory.Exists(xbmcDir)) - Directory.CreateDirectory(xbmcDir); - - if (!Directory.Exists(xbmcDir)) - { - // couldn't create directory - MessageBox.Show(string.Format(Resources.could_not_create_directory, xbmcDir), Resources.error, - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data"; + string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); SaveFileDialog dialog = new SaveFileDialog - { + { Title = Resources.store_settings_where, - InitialDirectory = xbmcDir, - FileName = string.Format("usb_{0}.xml", Program.Instance.Controller.USBDescriptor.Replace(':', '_')), + InitialDirectory = Directory.Exists(xbmcDir) ? xbmcDir : defaultDir, + FileName = "usb_2548_1001.xml", Filter = Resources.xml_file_filter, FilterIndex = 1 }; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 409b30b..50bb95f 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -944,6 +944,16 @@ void CCECProcessor::HandleLogicalAddressLost(cec_logical_address oldAddress) } } +uint16_t CCECProcessor::GetAdapterVendorId(void) const +{ + return m_communication ? m_communication->GetAdapterVendorId() : 0; +} + +uint16_t CCECProcessor::GetAdapterProductId(void) const +{ + return m_communication ? m_communication->GetAdapterProductId() : 0; +} + CCECAllocateLogicalAddress::CCECAllocateLogicalAddress(CCECProcessor* processor, CCECClient* client) : m_processor(processor), m_client(client) { } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index e1f6d68..dff892e 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -143,6 +143,9 @@ namespace CEC void SwitchMonitoring(bool bSwitchTo); bool AllocateLogicalAddresses(CCECClient* client); + + uint16_t GetAdapterVendorId(void) const; + uint16_t GetAdapterProductId(void) const; private: bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true); void SetCECInitialised(bool bSetTo = true); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index b74bc33..9ff5e14 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -529,3 +529,12 @@ void CLibCEC::InitVideoStandalone(void) { CAdapterFactory::InitVideoStandalone(); } +uint16_t CLibCEC::GetAdapterVendorId(void) const +{ + return m_cec && m_cec->IsRunning() ? m_cec->GetAdapterVendorId() : 0; +} + +uint16_t CLibCEC::GetAdapterProductId(void) const +{ + return m_cec && m_cec->IsRunning() ? m_cec->GetAdapterProductId() : 0; +} diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index d455861..56a112b 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -48,10 +48,6 @@ namespace CEC CLibCEC(void); virtual ~CLibCEC(void); - /*! - * ICECAdapter implementation - */ - //@{ bool Open(const char *strPort, uint32_t iTimeout = CEC_DEFAULT_CONNECT_TIMEOUT); void Close(void); bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks); @@ -121,7 +117,6 @@ namespace CEC static uint16_t GetMaskForType(cec_device_type type); bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT); - //@} void AddLog(const cec_log_level level, const char *strFormat, ...); void AddCommand(const cec_command &command); @@ -134,6 +129,8 @@ namespace CEC std::vector GetClients(void) { return m_clients; }; const char *GetLibInfo(void); void InitVideoStandalone(void); + uint16_t GetAdapterVendorId(void) const; + uint16_t GetAdapterProductId(void) const; CCECProcessor * m_cec; diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 9f501cc..6d9d8c5 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -378,4 +378,14 @@ void cec_init_video_standalone(void) cec_parser->InitVideoStandalone(); } +uint16_t cec_get_adapter_vendor_id(void) +{ + return cec_parser ? cec_parser->GetAdapterVendorId() : NULL; +} + +uint16_t cec_get_adapter_product_id(void) +{ + return cec_parser ? cec_parser->GetAdapterProductId() : NULL; +} + //@} diff --git a/src/lib/adapter/AdapterCommunication.h b/src/lib/adapter/AdapterCommunication.h index 0702671..7dd56b7 100644 --- a/src/lib/adapter/AdapterCommunication.h +++ b/src/lib/adapter/AdapterCommunication.h @@ -211,6 +211,16 @@ namespace CEC */ virtual cec_adapter_type GetAdapterType(void) = 0; + /*! + * @return The (virtual) USB vendor id + */ + virtual uint16_t GetAdapterVendorId(void) const = 0; + + /*! + * @return The (virtual) USB product id + */ + virtual uint16_t GetAdapterProductId(void) const = 0; + IAdapterCommunicationCallback *m_callback; }; }; diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp index 3d36497..7fa78f7 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp @@ -36,6 +36,7 @@ #include "USBCECAdapterCommands.h" #include "USBCECAdapterMessageQueue.h" #include "USBCECAdapterMessage.h" +#include "USBCECAdapterDetection.h" #include "lib/platform/sockets/serialport.h" #include "lib/platform/util/timeutils.h" #include "lib/platform/util/util.h" @@ -59,6 +60,7 @@ using namespace PLATFORM; #define CEC_LATEST_ADAPTER_FW_DATE 0x501a4b0c #define CEC_FW_DATE_EXTENDED_RESPONSE 0x501a4b0c +#define CEC_FW_DATE_DESCRIPTOR2 0x5045dbf5 #define LIB_CEC m_callback->GetLib() @@ -611,6 +613,20 @@ bool CUSBCECAdapterCommunication::ProvidesExtendedResponse(void) return iBuildDate >= CEC_FW_DATE_EXTENDED_RESPONSE; } +uint16_t CUSBCECAdapterCommunication::GetAdapterVendorId(void) const +{ + return CEC_VID; +} + +uint16_t CUSBCECAdapterCommunication::GetAdapterProductId(void) const +{ + uint32_t iBuildDate(0); + if (m_commands) + iBuildDate = m_commands->GetPersistedBuildDate(); + + return iBuildDate >= CEC_FW_DATE_DESCRIPTOR2 ? CEC_PID2 : CEC_PID; +} + bool CUSBCECAdapterCommunication::IsRunningLatestFirmware(void) { return GetFirmwareBuildDate() >= CEC_LATEST_ADAPTER_FW_DATE && diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h index 2192456..04199e2 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h @@ -88,6 +88,8 @@ namespace CEC cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; } bool SupportsSourceLogicalAddress(const cec_logical_address UNUSED(address)) { return true; } cec_adapter_type GetAdapterType(void); + uint16_t GetAdapterVendorId(void) const; + uint16_t GetAdapterProductId(void) const; ///} bool ProvidesExtendedResponse(void); diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h index dfccd65..37478b9 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h @@ -33,6 +33,10 @@ namespace CEC { + #define CEC_VID 0x2548 + #define CEC_PID 0x1001 + #define CEC_PID2 0x1002 + class CUSBCECAdapterDetection { public: diff --git a/src/lib/adapter/RPi/RPiCECAdapterCommunication.h b/src/lib/adapter/RPi/RPiCECAdapterCommunication.h index 7f81545..7400916 100644 --- a/src/lib/adapter/RPi/RPiCECAdapterCommunication.h +++ b/src/lib/adapter/RPi/RPiCECAdapterCommunication.h @@ -36,6 +36,9 @@ #include "lib/adapter/AdapterCommunication.h" #include "lib/platform/threads/threads.h" +#define RPI_ADAPTER_VID 0x2708 +#define RPI_ADAPTER_PID 0x1001 + extern "C" { #include #include @@ -79,6 +82,8 @@ namespace CEC cec_vendor_id GetVendorId(void) { return CEC_VENDOR_BROADCOM; } bool SupportsSourceLogicalAddress(const cec_logical_address address) { return address > CECDEVICE_TV && address < CECDEVICE_BROADCAST; } cec_adapter_type GetAdapterType(void) { return ADAPTERTYPE_RPI; }; + uint16_t GetAdapterVendorId(void) const { return RPI_ADAPTER_VID; } + uint16_t GetAdapterProductId(void) const { return RPI_ADAPTER_PID; } ///} bool IsInitialised(void); diff --git a/src/lib/platform/windows/os-types.h b/src/lib/platform/windows/os-types.h index 2fc6269..d47eb05 100644 --- a/src/lib/platform/windows/os-types.h +++ b/src/lib/platform/windows/os-types.h @@ -65,6 +65,7 @@ typedef _W64 int ssize_t; #endif #define snprintf _snprintf +#define strdup _strdup #if defined(_MSC_VER) #pragma warning (push)