/*
* This file is part of the libCEC(R) library.
*
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
* libCEC(R) is an original work, containing original code.
*
* libCEC(R) is a trademark of Pulse-Eight Limited.
#include "devices/CECTV.h"
#include "implementations/CECCommandHandler.h"
#include "LibCEC.h"
+#include "platform/util/timeutils.h"
using namespace CEC;
using namespace std;
return bReturn;
}
+ 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);
+
/* open a new connection */
- if ((bReturn = m_communication->Open(strPort, iBaudRate, iTimeoutMs)) == false)
- CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection");
+ while (iNow < iTarget && (bConnected = m_communication->Open(strPort, iBaudRate, iTimeoutMs)) == false)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
+ Sleep(500);
+ iNow = GetTimeMs();
+ }
/* try to ping the adapter */
- if ((bReturn = m_communication->PingAdapter()) == false)
- CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter does not respond correctly");
+ while (bConnected && iNow < iTarget && (bPinged = m_communication->PingAdapter()) == false)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond correctly to a ping (try %d)", ++iPingTry);
+ Sleep(500);
+ iNow = GetTimeMs();
+ }
- uint16_t iFirmwareVersion = m_communication->GetFirmwareVersion();
- if ((bReturn = (iFirmwareVersion != CEC_FW_VERSION_UNKNOWN)) == false)
- m_controller->AddLog(CEC_LOG_ERROR, "the adapter is running an unknown firmware version");
+ /* try to read the firmware version */
+ uint16_t iFirmwareVersion(CEC_FW_VERSION_UNKNOWN);
+ while (bPinged && iNow < iTarget && (iFirmwareVersion = m_communication->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();
+ }
- CLibCEC::AddLog(CEC_LOG_NOTICE, "CEC Adapter firmware version: %d", iFirmwareVersion);
+ if ((bReturn = iFirmwareVersion != CEC_FW_VERSION_UNKNOWN) == true)
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d", iFirmwareVersion);
return bReturn;
}
if (previousDevice && newDevice)
{
newDevice->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
- previousDevice->SetDeviceStatus(CEC_DEVICE_STATUS_UNKNOWN);
+ previousDevice->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
newDevice->SetCecVersion(previousDevice->GetCecVersion(false));
previousDevice->SetCecVersion(CEC_VERSION_UNKNOWN);
{
bReturn = m_busDevices[addr]->TransmitActiveSource();
+ if (bReturn)
+ {
+ m_busDevices[addr]->SetMenuState(CEC_MENU_STATE_ACTIVATED);
+ m_busDevices[addr]->TransmitMenuState(CECDEVICE_TV);
+ }
+
if (bReturn && (m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE ||
m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) &&
m_busDevices[addr]->GetHandler()->SendDeckStatusUpdateOnActiveSource())
if (output->tries > 0)
m_communication->SetLineTimeout(m_iRetryLineTimeout);
bReturn = m_communication->Write(output);
+ if (!bReturn)
+ Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT);
}while (!bReturn && output->transmit_timeout > 0 && output->NeedsRetry() && ++output->tries < output->maxTries);
}
return false;
}
-void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
-{
- m_controller->SetCurrentButton(iButtonCode);
-}
-
-void CCECProcessor::AddCommand(const cec_command &command)
-{
- m_controller->AddCommand(command);
-}
-
-void CCECProcessor::AddKey(cec_keypress &key)
-{
- m_controller->AddKey(key);
-}
-
-void CCECProcessor::AddKey(void)
-{
- m_controller->AddKey();
-}
-
bool CCECProcessor::SetAckMask(uint16_t iMask)
{
return m_communication->SetAckMask(iMask);