From: Bob van Loosen Date: Wed, 1 Feb 2012 23:55:40 +0000 (+0100) Subject: added: set controlled mode on after opening a connection to the adapter X-Git-Tag: upstream/2.2.0~1^2~36^2~25 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b057edadea84636e4e48fff043631b4bf98a9a34;p=deb_libcec.git added: set controlled mode on after opening a connection to the adapter --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 57704bd..7041b78 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -149,8 +149,8 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint uint64_t iNow = GetTimeMs(); uint64_t iTarget = iTimeoutMs > 0 ? iNow + iTimeoutMs : iNow + CEC_DEFAULT_TRANSMIT_WAIT; - unsigned iConnectTry(0), iPingTry(0), iFwVersionTry(0); - bool bConnected(false), bPinged(false); + unsigned iConnectTry(0), iPingTry(0), iFwVersionTry(0), iControlledTry(0); + bool bConnected(false), bPinged(false), bControlled(false); /* open a new connection */ while (iNow < iTarget && (bConnected = m_communication->Open(iTimeoutMs)) == false) @@ -177,6 +177,17 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint iNow = GetTimeMs(); } + if (iFirmwareVersion >= 2) + { + /* try to set controlled mode */ + while (bConnected && iNow < iTarget && (bControlled = m_communication->SetControlledMode(true)) == false) + { + CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond correctly to setting controlled mode (try %d)", ++iControlledTry); + Sleep(500); + iNow = GetTimeMs(); + } + } + if ((bReturn = iFirmwareVersion != CEC_FW_VERSION_UNKNOWN) == true) CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d", iFirmwareVersion); diff --git a/src/lib/adapter/AdapterCommunication.h b/src/lib/adapter/AdapterCommunication.h index cec8501..36a9bb1 100644 --- a/src/lib/adapter/AdapterCommunication.h +++ b/src/lib/adapter/AdapterCommunication.h @@ -119,5 +119,10 @@ namespace CEC * @return The firmware version of this CEC adapter. */ virtual uint16_t GetFirmwareVersion(void) = 0; + + /*! + * @return True when the control mode has been set, false otherwise. + */ + virtual bool SetControlledMode(bool controlled) = 0; }; }; diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index 0134751..e2b0386 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -432,6 +432,29 @@ bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask) return bReturn; } + +bool CUSBCECAdapterCommunication::SetControlledMode(bool controlled) +{ + bool bReturn(false); + CStdString strLog; + strLog.Format("turning controlled mode %s", controlled ? "on" : "off"); + CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str()); + + CCECAdapterMessage *output = new CCECAdapterMessage; + + output->PushBack(MSGSTART); + output->PushEscaped(MSGCODE_SET_CONTROLLED); + output->PushEscaped(controlled); + output->PushBack(MSGEND); + output->isTransmission = false; + + if ((bReturn = Write(output)) == false) + CLibCEC::AddLog(CEC_LOG_ERROR, "could not set controlled mode"); + delete output; + + return bReturn; +} + bool CUSBCECAdapterCommunication::IsOpen(void) { return !IsStopped() && m_port->IsOpen() && IsRunning(); diff --git a/src/lib/adapter/USBCECAdapterCommunication.h b/src/lib/adapter/USBCECAdapterCommunication.h index 7aa0350..8cada4d 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.h +++ b/src/lib/adapter/USBCECAdapterCommunication.h @@ -65,6 +65,7 @@ namespace CEC virtual bool SetAckMask(uint16_t iMask); virtual bool PingAdapter(void); virtual uint16_t GetFirmwareVersion(void); + virtual bool SetControlledMode(bool controlled); void *Process(void); private: