Revert "cec: fixed typo which prevented LG TVs from connecting sometimes". This broke...
[deb_libcec.git] / src / lib / implementations / SLCommandHandler.cpp
index b1f16442489399e8875d45e017a49d81bf5df2fb..f86a644f2db452804a19baa3c32f4e37fa83d7ba 100644 (file)
@@ -53,7 +53,8 @@ CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) :
     m_bSLEnabled(false),
     m_bVendorIdSent(false)
 {
-  m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary]->m_powerStatus = CEC_POWER_STATUS_STANDBY;
+  /* TODO set to powered off until we fixed the connect on start loop issue */
+  m_processor->GetPrimaryDevice()->m_powerStatus = CEC_POWER_STATUS_STANDBY;
 }
 
 bool CSLCommandHandler::HandleVendorCommand(const cec_command &command)
@@ -67,19 +68,19 @@ bool CSLCommandHandler::HandleVendorCommand(const cec_command &command)
   else if (command.parameters.size == 2 &&
       command.parameters[0] == SL_COMMAND_POWER_ON)
   {
-    HandleVendorCommand03(command);
+    HandleVendorCommandPowerOn(command);
     return true;
   }
   else if (command.parameters.size == 2 &&
       command.parameters[0] == SL_COMMAND_CONNECT_REQUEST)
   {
-    HandleVendorCommand04(command);
+    HandleVendorCommandSLConnect(command);
     return true;
   }
   else if (command.parameters.size == 1 &&
       command.parameters[0] == SL_COMMAND_REQUEST_POWER_STATUS)
   {
-    HandleVendorCommandA0(command);
+    HandleVendorCommandPowerOnStatus(command);
     return true;
   }
 
@@ -118,7 +119,7 @@ void CSLCommandHandler::TransmitVendorCommand0205(const cec_logical_address iSou
   Transmit(response);
 }
 
-void CSLCommandHandler::TransmitVendorCommand04(const cec_logical_address iSource, const cec_logical_address iDestination)
+void CSLCommandHandler::TransmitVendorCommand05(const cec_logical_address iSource, const cec_logical_address iDestination)
 {
   m_bSLEnabled = true;
   cec_command response;
@@ -128,9 +129,9 @@ void CSLCommandHandler::TransmitVendorCommand04(const cec_logical_address iSourc
   Transmit(response);
 }
 
-void CSLCommandHandler::HandleVendorCommand03(const cec_command &command)
+void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command)
 {
-  CCECBusDevice *device = m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary];
+  CCECBusDevice *device = m_processor->GetPrimaryDevice();
   if (device)
   {
     m_bSLEnabled = true;
@@ -141,14 +142,16 @@ void CSLCommandHandler::HandleVendorCommand03(const cec_command &command)
   }
 }
 
-void CSLCommandHandler::HandleVendorCommand04(const cec_command &command)
+void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command &command)
 {
   m_bSLEnabled = true;
-  TransmitVendorCommand04(command.destination, command.initiator);
+  m_processor->m_busDevices[command.initiator]->SetActiveSource();
+  m_processor->m_busDevices[command.destination]->TransmitActiveSource();
+  TransmitVendorCommand05(command.destination, command.initiator);
   TransmitDeckStatus(command.initiator);
 }
 
-void CSLCommandHandler::HandleVendorCommandA0(const cec_command &command)
+void CSLCommandHandler::HandleVendorCommandPowerOnStatus(const cec_command &command)
 {
   if (command.destination != CECDEVICE_BROADCAST)
   {
@@ -162,7 +165,7 @@ void CSLCommandHandler::HandleVendorCommandA0(const cec_command &command)
 void CSLCommandHandler::TransmitDeckStatus(const cec_logical_address iDestination)
 {
   /* set deck status for the playback device */
-  CCECBusDevice *primary = m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary];
+  CCECBusDevice *primary = m_processor->GetPrimaryDevice();
   if (primary->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)
   {
     ((CCECPlaybackDevice *)primary)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
@@ -243,6 +246,10 @@ bool CSLCommandHandler::HandleReceiveFailed(void)
 
 bool CSLCommandHandler::InitHandler(void)
 {
+  if (m_bHandlerInited)
+    return true;
+  m_bHandlerInited = true;
+
   m_processor->SetStandardLineTimeout(3);
   m_processor->SetRetryLineTimeout(3);
 
@@ -251,9 +258,12 @@ bool CSLCommandHandler::InitHandler(void)
   m_iTransmitRetries = 4;
   m_iTransmitTimeout = 500;
 
-  CCECBusDevice *primary = m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary];
+  CCECBusDevice *primary = m_processor->GetPrimaryDevice();
   if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
+  {
     primary->SetVendorId(CEC_VENDOR_LG, false);
+    primary->TransmitVendorID(CECDEVICE_TV, false);
+  }
 
   if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV)
   {
@@ -283,6 +293,7 @@ bool CSLCommandHandler::InitHandler(void)
                        device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
         {
           ((CCECPlaybackDevice *)device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
+          ((CCECPlaybackDevice *)device)->TransmitDeckStatus(CECDEVICE_TV);
         }
       }
     }