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)
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);
* @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;
};
};
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();