cec: keep trying to connect while iTimeout isn't reached (default 10 seconds). fixes...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 14 Oct 2011 00:23:11 +0000 (02:23 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 14 Oct 2011 00:23:11 +0000 (02:23 +0200)
include/cectypes.h
src/lib/AdapterCommunication.cpp
src/lib/LibCEC.cpp

index 854fdebb906c76daa5870385427cb6e284b687e3..196eed97da0a5010b17bcf8fa9226b4d6a483309 100644 (file)
@@ -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
index 2ee72707773d9db64ad1fd0d53634ff16a26921d..f880d982e80175a7ab54590116528b2eca81bfce 100644 (file)
@@ -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");
index afbf2260f5c16dbeaee4e55a764bf2eb49875e16..0c4b89de220d0a7ebff81bc0f4e5189d20a84718 100644 (file)
@@ -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;