From 2492216a2285656be7a2b548eddd986fd8d6c2b3 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Fri, 14 Oct 2011 11:06:24 +0200 Subject: [PATCH] cec: add SetPhysicalAddress()/cec_set_physical_address() to the interface, so the HDMI port number to use can be changed --- include/cec.h | 7 ++++++- include/cecc.h | 15 +++++++++++---- include/cectypes.h | 2 +- src/lib/CECProcessor.cpp | 34 ++++++++++++++++++++++------------ src/lib/CECProcessor.h | 3 ++- src/lib/LibCEC.cpp | 5 +++++ src/lib/LibCEC.h | 3 ++- src/lib/LibCECC.cpp | 9 ++++++++- 8 files changed, 57 insertions(+), 21 deletions(-) diff --git a/include/cec.h b/include/cec.h index 7afb065..bf7a473 100644 --- a/include/cec.h +++ b/include/cec.h @@ -103,7 +103,12 @@ namespace CEC /*! * @see cec_set_logical_address */ - virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress) = 0; + virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1) = 0; + + /*! + * @see cec_set_physical_address + */ + virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) = 0; /*! * @see cec_power_on_devices diff --git a/include/cecc.h b/include/cecc.h index bfbe0cc..43e79d8 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -185,16 +185,23 @@ extern DECLSPEC int cec_transmit(const cec_command &data, int bWaitForAck = 1); #endif /*! - * @brief Set the logical address of the CEC adapter. - * @param iLogicalAddress The cec adapter's logical address. - * @return True when the logical address was set succesfully, false otherwise. + * @brief Change the logical address of the CEC adapter. + * @param iLogicalAddress The CEC adapter's new logical address. + * @return True when the logical address was set successfully, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC int cec_set_logical_address(CEC::cec_logical_address iLogicalAddress); +extern DECLSPEC int cec_set_logical_address(CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1); #else extern DECLSPEC int cec_set_logical_address(cec_logical_address myAddress, cec_logical_address targetAddress); #endif +/*! + * @brief Change the physical address (HDMI port) of the CEC adapter. + * @param iPhysicalAddress The CEC adapter's new physical address. + * @brief True when the physical address was set successfully, false otherwise. + */ +extern DECLSPEC int cec_set_physical_address(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); + #ifdef __cplusplus }; #endif diff --git a/include/cectypes.h b/include/cectypes.h index e5b7791..f18d928 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -693,7 +693,7 @@ typedef enum cec_vendor_id CEC_VENDOR_UNKNOWN = 0 } vendor_id; -//default physical address 1.0.0.0 +//default physical address 1.0.0.0, HDMI port 1 #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000 #define MSGSTART 0xFF #define MSGEND 0xFE diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index ae7d5fd..7ddf612 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -41,7 +41,7 @@ using namespace CEC; using namespace std; CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) : - m_physicaladdress(iPhysicalAddress), + m_iPhysicalAddress(iPhysicalAddress), m_iLogicalAddress(iLogicalAddress), m_strDeviceName(strDeviceName), m_communication(serComm), @@ -158,8 +158,8 @@ bool CCECProcessor::SetActiveView(void) cec_command command; cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); - command.parameters.push_back((m_physicaladdress >> 8) & 0xFF); - command.parameters.push_back(m_physicaladdress & 0xFF); + command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); + command.parameters.push_back(m_iPhysicalAddress & 0xFF); return Transmit(command); } @@ -173,8 +173,8 @@ bool CCECProcessor::SetInactiveView(void) cec_command command; cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE); - command.parameters.push_back((m_physicaladdress >> 8) & 0xFF); - command.parameters.push_back(m_physicaladdress & 0xFF); + command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF); + command.parameters.push_back(m_iPhysicalAddress & 0xFF); return Transmit(command); } @@ -204,13 +204,23 @@ bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) { CStdString strLog; - strLog.Format("<< setting logical address to %d", iLogicalAddress); + strLog.Format("<< setting logical address to %1x", iLogicalAddress); m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); m_iLogicalAddress = iLogicalAddress; return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); } +bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress) +{ + CStdString strLog; + strLog.Format("<< setting physical address to %2x", iPhysicalAddress); + m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); + + m_iPhysicalAddress = iPhysicalAddress; + return SetActiveView(); +} + bool CCECProcessor::TransmitFormatted(const cec_adapter_message &data, bool bWaitForAck /* = true */) { CLockObject lock(&m_mutex); @@ -316,13 +326,13 @@ void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV void CCECProcessor::ReportPhysicalAddress(void) { CStdString strLog; - strLog.Format("<< reporting physical address as %04x", m_physicaladdress); + strLog.Format("<< reporting physical address as %04x", m_iPhysicalAddress); m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); cec_command command; cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); - command.parameters.push_back((uint8_t) ((m_physicaladdress >> 8) & 0xFF)); - command.parameters.push_back((uint8_t) (m_physicaladdress & 0xFF)); + command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); + command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); command.parameters.push_back((uint8_t) (CEC_DEVICE_TYPE_PLAYBACK_DEVICE)); Transmit(command); @@ -334,8 +344,8 @@ void CCECProcessor::BroadcastActiveSource(void) cec_command command; cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); - command.parameters.push_back((uint8_t) ((m_physicaladdress >> 8) & 0xFF)); - command.parameters.push_back((uint8_t) (m_physicaladdress & 0xFF)); + command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); + command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF)); Transmit(command); } @@ -580,7 +590,7 @@ void CCECProcessor::ParseCommand(cec_command &command) int streamaddr = ((int)command.parameters[0] << 8) | ((int)command.parameters[1]); strLog.Format(">> %i requests stream path from physical address %04x", command.initiator, streamaddr); m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); - if (streamaddr == m_physicaladdress) + if (streamaddr == m_iPhysicalAddress) BroadcastActiveSource(); } } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 8617257..43b7a30 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -58,6 +58,7 @@ namespace CEC virtual bool SetInactiveView(void); virtual bool Transmit(const cec_command &data, bool bWaitForAck = true); virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress); + virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress); static const char *CECVendorIdToString(const uint64_t iVendorId); @@ -80,7 +81,7 @@ namespace CEC void ParseVendorId(cec_logical_address device, const cec_datapacket &data); cec_command m_currentframe; - uint16_t m_physicaladdress; + uint16_t m_iPhysicalAddress; cec_logical_address m_iLogicalAddress; CecBuffer m_frameBuffer; std::string m_strDeviceName; diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 0c4b89d..78fca2d 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -168,6 +168,11 @@ bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress) return m_cec ? m_cec->SetLogicalAddress(iLogicalAddress) : false; } +bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress) +{ + return m_cec ? m_cec->SetPhysicalAddress(iPhysicalAddress) : false; +} + bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */) { return m_cec ? m_cec->PowerOnDevices(address) : false; diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 2ad32da..2f80720 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -64,7 +64,8 @@ namespace CEC virtual bool GetNextCommand(cec_command *command); virtual bool Transmit(const cec_command &data, bool bWaitForAck = true); - virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress); + virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1); + virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV); virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 1c9ef4d..ccdd5b6 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -131,13 +131,20 @@ int cec_transmit(const CEC::cec_command &data, int bWaitForAck /* = true */) return -1; } -int cec_set_logical_address(cec_logical_address iLogicalAddress) +int cec_set_logical_address(cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */) { if (cec_parser) return cec_parser->SetLogicalAddress(iLogicalAddress) ? 1 : 0; return -1; } +int cec_set_physical_address(uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) +{ + if (cec_parser) + return cec_parser->SetPhysicalAddress(iPhysicalAddress) ? 1 : 0; + return -1; +} + int cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */) { if (cec_parser) -- 2.34.1