From: Lars Op den Kamp Date: Tue, 6 Dec 2011 00:25:28 +0000 (+0100) Subject: cec: fix device polling X-Git-Tag: upstream/2.2.0~1^2~44^2~34 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b750a5c3fb139dade6974a1f99a9d090ae706d5b;p=deb_libcec.git cec: fix device polling --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 6aad7e9..618cd9a 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -158,7 +158,7 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, if (SetAckMask(m_logicalAddresses.AckMask()) && SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true)) { - m_controller->AddLog(CEC_LOG_ERROR, "processor thread started"); + m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); m_busScan = new CCECBusScan(this); m_busScan->CreateThread(true); return true; @@ -1287,12 +1287,12 @@ const char *CCECProcessor::ToString(const cec_vendor_id vendor) void *CCECBusScan::Process(void) { CCECBusDevice *device(NULL); - int iCount(0); + int iCount(50); while (!IsStopped()) { if (iCount == 0) { - for (unsigned int iPtr = 0; iPtr < 15 && !IsStopped(); iPtr++) + for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++) { device = m_processor->m_busDevices[iPtr]; if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT) diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 5deeddf..4c25e61 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -366,7 +366,8 @@ bool CCECBusDevice::NeedsPoll(void) cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */) { CLockObject lock(&m_writeMutex); - if (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll) + if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && + (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll)) { lock.Leave(); bool bPollAcked(false); @@ -712,17 +713,24 @@ bool CCECBusDevice::TransmitPoll(cec_logical_address dest) if (dest == CECDEVICE_UNKNOWN) dest = m_iLogicalAddress; + CCECBusDevice *destDevice = m_processor->m_busDevices[dest]; + if (destDevice->m_deviceStatus == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) + return bReturn; + CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); AddLog(CEC_LOG_NOTICE, strLog.c_str()); bReturn = m_handler->TransmitPoll(m_iLogicalAddress, dest); AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); + CLockObject lock(&m_writeMutex); if (bReturn) { - CLockObject lock(&m_writeMutex); m_iLastActive = GetTimeMs(); + destDevice->m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; } + else + destDevice->m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT; return bReturn; } diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index 4a9d19e..dd9aec1 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -231,6 +231,7 @@ bool CSLCommandHandler::InitHandler(void) if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV) { + m_busDevice->GetProcessor()->SetActiveSource(m_busDevice->GetProcessor()->GetLogicalAddresses().primary); /* LG TVs only route keypresses when the deck status is set to 0x20 */ cec_logical_addresses addr = m_busDevice->GetProcessor()->GetLogicalAddresses(); for (uint8_t iPtr = 0; iPtr < 15; iPtr++)