-bool CUSBCECAdapterCommunication::CheckAdapter(uint32_t iTimeoutMs /* = 10000 */)
-{
- bool bReturn(false);
- uint64_t iNow = GetTimeMs();
- uint64_t iTarget = iTimeoutMs > 0 ? iNow + iTimeoutMs : iNow + CEC_DEFAULT_TRANSMIT_WAIT;
-
- /* try to ping the adapter */
- bool bPinged(false);
- unsigned iPingTry(0);
- while (iNow < iTarget && (bPinged = PingAdapter()) == false)
- {
- CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond correctly to a ping (try %d)", ++iPingTry);
- Sleep(500);
- iNow = GetTimeMs();
- }
-
- /* try to read the firmware version */
- m_iFirmwareVersion = CEC_FW_VERSION_UNKNOWN;
- unsigned iFwVersionTry(0);
- while (bPinged && iNow < iTarget && (m_iFirmwareVersion = GetFirmwareVersion()) == CEC_FW_VERSION_UNKNOWN)
- {
- CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond with a correct firmware version (try %d)", ++iFwVersionTry);
- Sleep(500);
- iNow = GetTimeMs();
- }
-
- if (m_iFirmwareVersion >= 2)
- {
- /* try to set controlled mode */
- unsigned iControlledTry(0);
- bool bControlled(false);
- while (iNow < iTarget && (bControlled = 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();
- }
- bReturn = bControlled;
- }
- else
- bReturn = true;
-
- return bReturn;
-}
-
-bool CUSBCECAdapterCommunication::Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs /* = 10000 */)