cec: scan the CEC bus for devices when starting libcec
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 28 Nov 2011 00:05:04 +0000 (01:05 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 28 Nov 2011 00:05:58 +0000 (01:05 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/devices/CECBusDevice.cpp

index 021e4317d7812e6d303e5a0737fa104dc498ef44..7f688dd134295872bc710464921f121d669e5a66 100644 (file)
@@ -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;
 }
 
index c1c28740079d7d7e3cb7cc92c5a8acc1c38fab9d..6cd9ba479538cc13c0edc181fe47cabd1a0b7fb8 100644 (file)
@@ -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);
index 5c38f635060be704a9e7cb55121980d235bbbdf1..b4c11f198e703a6e853ae23e2c551264ff1fa502 100644 (file)
@@ -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;