cec: set the proper ackmask before doing anything else. set the LG vendor ID after...
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 1daa7b60d2d8d421f879fa9b530ce07039725b1f..94651fcb45d5c00de77b8323efaca191eb1d38c4 100644 (file)
@@ -152,8 +152,10 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */,
     }
 
     lock.Leave();
-    if (SetAckMask(m_logicalAddresses.AckMask()) &&
-        SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true))
+
+    m_busDevices[CECDEVICE_TV]->GetVendorId();
+
+    if (SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true))
     {
       m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
       m_busScan = new CCECBusScan(this);
@@ -260,8 +262,7 @@ void *CCECProcessor::Process(void)
   }
   else
   {
-    m_busDevices[CECDEVICE_TV]->GetVendorId();
-    m_busDevices[m_logicalAddresses.primary]->TransmitVendorID(CECDEVICE_TV, false);
+    SetAckMask(m_logicalAddresses.AckMask());
 
     CLockObject lock(&m_mutex);
     m_bStarted = true;
@@ -395,15 +396,15 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort,
 {
   bool bReturn(false);
 
-  CStdString strLog;
-  strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
-  AddLog(CEC_LOG_DEBUG, strLog);
-
   m_iBaseDevice = iBaseDevice;
   m_iHDMIPort = iPort;
   if (!m_bStarted && !bForce)
     return true;
 
+  CStdString strLog;
+  strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
+  AddLog(CEC_LOG_DEBUG, strLog);
+
   uint16_t iPhysicalAddress(0);
   iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
   uint16_t iPos = 0;
@@ -521,6 +522,7 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
     for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
       if (m_logicalAddresses[iPtr])
       {
+        m_busDevices[iPtr]->SetInactiveDevice();
         m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
         m_busDevices[iPtr]->TransmitPhysicalAddress();
       }
@@ -669,6 +671,13 @@ uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
   return false;
 }
 
+uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress)
+{
+  if (m_busDevices[iAddress])
+    return m_busDevices[iAddress]->GetPhysicalAddress(false);
+  return false;
+}
+
 cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
 {
   if (m_busDevices[iAddress])
@@ -676,6 +685,22 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres
   return CEC_POWER_STATUS_UNKNOWN;
 }
 
+cec_logical_address CCECProcessor::GetActiveSource(void)
+{
+  for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+  {
+    if (m_busDevices[iPtr]->IsActiveSource())
+      return (cec_logical_address)iPtr;
+  }
+
+  return CECDEVICE_UNKNOWN;
+}
+
+bool CCECProcessor::IsActiveSource(cec_logical_address iAddress)
+{
+  return m_busDevices[iAddress]->IsActiveSource();
+}
+
 bool CCECProcessor::Transmit(const cec_command &data)
 {
   bool bReturn(false);