X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=38c9b76f8e52e3592802ea4d158a31eea5ea8601;hb=b74fd339e942f438e288f9e26cca404a5a430925;hp=57704bdba531e571f8db1babbede3680ef167834;hpb=7bb4ed43f15a0fa2be17d2c3f580b181ac7430a7;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 57704bd..38c9b76 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -134,8 +134,9 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint CLockObject lock(m_mutex); if (m_communication) { - CLibCEC::AddLog(CEC_LOG_ERROR, "existing connection handler found"); - return bReturn; + CLibCEC::AddLog(CEC_LOG_WARNING, "existing connection handler found, deleting it"); + m_communication->Close(); + delete m_communication; } m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate); @@ -149,8 +150,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 +178,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); @@ -438,7 +450,11 @@ void *CCECProcessor::Process(void) } if (m_communication) + { m_communication->Close(); + delete m_communication; + m_communication = NULL; + } return NULL; }