cec: fix loop when initialising LG
[deb_libcec.git] / src / lib / implementations / SLCommandHandler.cpp
index 125a23ee01f7bfa1c30c01db990d39bd7e841807..fef6a4a0e05a5973eff9b7dbf869faca8c76386c 100644 (file)
@@ -57,7 +57,7 @@ CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) :
   /* imitate LG devices */
   if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
     primary->SetVendorId(CEC_VENDOR_LG);
-  SetLGDeckStatus();
+  SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
 
   /* LG TVs don't always reply to CEC version requests, so just set it to 1.3a */
   if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV)
@@ -89,6 +89,7 @@ bool CSLCommandHandler::ActivateSource(void)
 {
   CCECBusDevice *primary = m_processor->GetPrimaryDevice();
   primary->SetActiveSource();
+  primary->TransmitImageViewOn();
   primary->TransmitActiveSource();
   return true;
 }
@@ -195,7 +196,7 @@ void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command)
     device->TransmitPowerState(command.initiator);
     device->SetPowerStatus(CEC_POWER_STATUS_ON);
 
-    SetLGDeckStatus();
+    SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
     device->SetActiveSource();
     TransmitImageViewOn(device->GetLogicalAddress(), command.initiator);
   }
@@ -214,13 +215,25 @@ void CSLCommandHandler::HandleVendorCommandPowerOnStatus(const cec_command &comm
 void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command &command)
 {
   m_bSLEnabled = true;
-  SetLGDeckStatus();
-
   CCECBusDevice *primary = m_processor->GetPrimaryDevice();
 
-  primary->SetActiveSource();
-  TransmitImageViewOn(primary->GetLogicalAddress(), command.initiator);
   TransmitVendorCommand05(primary->GetLogicalAddress(), command.initiator);
+
+  CCECPlaybackDevice *playback = (primary->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) ?
+      (CCECPlaybackDevice *)primary : NULL;
+  if (playback)
+  {
+    SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS);
+    playback->TransmitDeckStatus(CECDEVICE_TV);
+    PLATFORM::CEvent::Sleep(2000);
+  }
+
+  primary->SetActiveSource();
+  primary->TransmitImageViewOn();
+
+  SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
+  if (playback)
+    playback->TransmitDeckStatus(CECDEVICE_TV);
 }
 
 void CSLCommandHandler::TransmitVendorCommand05(const cec_logical_address iSource, const cec_logical_address iDestination)
@@ -228,18 +241,17 @@ void CSLCommandHandler::TransmitVendorCommand05(const cec_logical_address iSourc
   cec_command response;
   cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND);
   response.PushBack(SL_COMMAND_CONNECT_ACCEPT);
-  response.PushBack((uint8_t)iSource);
+  response.PushBack((uint8_t)m_processor->m_busDevices[iSource]->GetType());
   Transmit(response, false);
 }
 
-void CSLCommandHandler::SetLGDeckStatus(void)
+void CSLCommandHandler::SetDeckStatus(cec_deck_info deckStatus)
 {
-  /* LG TVs only route keypresses when the deck status is set to 0x20 */
   CCECBusDevice *device = m_processor->GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
   if (device)
-    ((CCECPlaybackDevice *)device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
+    ((CCECPlaybackDevice *)device)->SetDeckStatus(deckStatus);
 
   device = m_processor->GetDeviceByType(CEC_DEVICE_TYPE_RECORDING_DEVICE);
   if (device)
-    ((CCECPlaybackDevice *)device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
+    ((CCECPlaybackDevice *)device)->SetDeckStatus(deckStatus);
 }