From: Lars Op den Kamp Date: Fri, 14 Oct 2011 00:23:11 +0000 (+0200) Subject: cec: keep trying to connect while iTimeout isn't reached (default 10 seconds). fixes... X-Git-Tag: upstream/2.2.0~1^2~235 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a11148b7b6b9fb9b1aed569c4445958d4e91b860;p=deb_libcec.git cec: keep trying to connect while iTimeout isn't reached (default 10 seconds). fixes exit with a 'permission denied' error when the device isn't ready yet. remove CEC_SETTLE_DOWN_TIME --- diff --git a/include/cectypes.h b/include/cectypes.h index 854fdeb..196eed9 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -696,7 +696,6 @@ typedef enum cec_vendor_id #define ESCOFFSET 3 #define CEC_MIN_VERSION 6 #define CEC_LIB_VERSION 7 -#define CEC_SETTLE_DOWN_TIME 1500 #define CEC_BUTTON_TIMEOUT 500 #ifdef __cplusplus diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 2ee7270..f880d98 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -91,8 +91,6 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38 uint8_t buff[1024]; m_port->Read(buff, sizeof(buff), 50); - Sleep(CEC_SETTLE_DOWN_TIME); - if (CreateThread()) { m_controller->AddLog(CEC_LOG_DEBUG, "communication thread created"); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index afbf226..0c4b89d 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -78,7 +78,17 @@ bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */) return false; } - if (!m_comm->Open(strPort, 38400, iTimeoutMs)) + int64_t iNow = GetTimeMs(); + int64_t iTarget = iNow + iTimeoutMs; + + bool bOpened(false); + while (!bOpened && iNow < iTarget) + { + bOpened = m_comm->Open(strPort, 38400, iTimeoutMs); + iNow = GetTimeMs(); + } + + if (!bOpened) { AddLog(CEC_LOG_ERROR, "could not open a connection"); return false;