From: Lars Op den Kamp Date: Mon, 28 Nov 2011 00:05:04 +0000 (+0100) Subject: cec: scan the CEC bus for devices when starting libcec X-Git-Tag: upstream/2.2.0~1^2~44^2~89 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=95a73fa78b4524636db470491c1e3434b81df4c0;p=deb_libcec.git cec: scan the CEC bus for devices when starting libcec --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 021e431..7f688dd 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -231,6 +231,8 @@ void *CCECProcessor::Process(void) SetAckMask(m_logicalAddresses.AckMask()); + ScanCECBus(); + { CLockObject lock(&m_mutex); m_bStarted = true; @@ -385,6 +387,22 @@ bool CCECProcessor::SetHDMIPort(uint8_t iPort) return bReturn; } +void CCECProcessor::ScanCECBus(void) +{ + CCECBusDevice *device(NULL); + for (unsigned int iPtr = 0; iPtr < 16; iPtr++) + { + device = m_busDevices[iPtr]; + if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT) + { + device->GetPhysicalAddress(); + device->GetVendorId(); + device->GetCecVersion(); + device->GetPowerStatus(); + } + } +} + bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress) { for (unsigned int iPtr = 0; iPtr < 16; iPtr++) @@ -488,7 +506,11 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable) bool CCECProcessor::PollDevice(cec_logical_address iAddress) { if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress]) - return m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress); + { + return m_logicalAddresses.primary == CECDEVICE_UNKNOWN ? + m_busDevices[iAddress]->TransmitPoll(iAddress) : + m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress); + } return false; } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index c1c2874..6cd9ba4 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -107,6 +107,7 @@ namespace CEC CCECBusDevice *m_busDevices[16]; private: + void ScanCECBus(void); bool CheckPhysicalAddress(uint16_t iPhysicalAddress); bool TryLogicalAddress(cec_logical_address address); bool FindLogicalAddressRecordingDevice(void); diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 5c38f63..b4c11f1 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -322,10 +322,11 @@ cec_bus_device_status CCECBusDevice::GetStatus(void) CLockObject lock(&m_mutex); if (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN) { - if (m_processor->PollDevice(m_iLogicalAddress)) - m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; - else - m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT; + lock.Leave(); + bool bPollAcked = m_processor->PollDevice(m_iLogicalAddress); + + lock.Lock(); + m_deviceStatus = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT; } return m_deviceStatus;