cec: send the physical address before sending the vendor id in the SL handler
[deb_libcec.git] / src / lib / implementations / SLCommandHandler.cpp
index 7b3b427af2f4154f8a449851f50c15d2aa0e49cf..dbf9d0957921b21f6cfd5e77a5be2ecca1230a6a 100644 (file)
@@ -51,7 +51,8 @@ CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) :
     CCECCommandHandler(busDevice),
     m_bSLEnabled(false),
     m_bPowerStateReset(false),
-    m_bActiveSourceSent(false)
+    m_bActiveSourceSent(false),
+    m_bVendorIdSent(false)
 {
   m_vendorId = CEC_VENDOR_LG;
   CCECBusDevice *primary = m_processor->GetPrimaryDevice();
@@ -77,19 +78,31 @@ bool CSLCommandHandler::InitHandler(void)
     return true;
   m_bHandlerInited = true;
 
-  /* reply with LGs vendor id */
   CCECBusDevice *primary = m_processor->GetPrimaryDevice();
   if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
-    primary->TransmitVendorID(CECDEVICE_TV, false);
+  {
+    /* start as 'in transition standby->on' */
+    primary->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
+    primary->TransmitPowerState(CECDEVICE_TV);
+  }
 
-  primary->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
   return true;
 }
 
 bool CSLCommandHandler::ActivateSource(void)
 {
+  /* reply with LGs vendor id */
+  if (!m_bVendorIdSent)
+  {
+    m_bVendorIdSent = true;
+    m_processor->GetPrimaryDevice()->TransmitVendorID(CECDEVICE_BROADCAST, false);
+  }
+
+  if (!m_bSLEnabled)
+    return true;
+
   if (m_bActiveSourceSent)
-    return false;
+    return true;
   m_bActiveSourceSent = true;
 
   CCECBusDevice *primary = m_processor->GetPrimaryDevice();
@@ -265,18 +278,29 @@ bool CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
       bReturn = device->TransmitPowerState(command.initiator);
       device->SetPowerStatus(CEC_POWER_STATUS_ON);
     }
-    else if (!ActivateSource())
-    {
-      /* assume that we've bugged out */
-      CLibCEC::AddLog(CEC_LOG_NOTICE, "LG seems to have bugged out. resetting to 'in transition standby to on'");
-      m_bActiveSourceSent = false;
-      device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
-      bReturn = device->TransmitPowerState(command.initiator);
-      device->SetPowerStatus(CEC_POWER_STATUS_ON);
-    }
     else
     {
-      bReturn = true;
+      if (!m_bActiveSourceSent)
+      {
+        device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
+        bReturn = device->TransmitPowerState(command.initiator);
+        ActivateSource();
+      }
+      else if (m_resetPowerState.IsSet() && m_resetPowerState.TimeLeft() > 0)
+      {
+        /* assume that we've bugged out */
+        CLibCEC::AddLog(CEC_LOG_NOTICE, "LG seems to have bugged out. resetting to 'in transition standby to on'");
+        m_bActiveSourceSent = false;
+        device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
+        bReturn = device->TransmitPowerState(command.initiator);
+        device->SetPowerStatus(CEC_POWER_STATUS_ON);
+        m_resetPowerState.Init(5000);
+      }
+      else
+      {
+        bReturn = device->TransmitPowerState(command.initiator);
+        m_resetPowerState.Init(5000);
+      }
     }
   }