cec: and more LG hacks
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 6 Dec 2011 23:16:53 +0000 (00:16 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 6 Dec 2011 23:16:53 +0000 (00:16 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/SLCommandHandler.cpp
src/lib/implementations/SLCommandHandler.h

index d995345c01df94c3f144d21bb4962a4a90404c68..4df840d02f48e261cac71d371cdfcda8c9b123d4 100644 (file)
@@ -268,7 +268,9 @@ void *CCECProcessor::Process(void)
   }
   else
   {
-    m_busDevices[m_logicalAddresses.primary]->TransmitPhysicalAddress();
+    m_busDevices[CECDEVICE_TV]->GetVendorId();
+    m_busDevices[m_logicalAddresses.primary]->TransmitVendorID(CECDEVICE_TV, false);
+
     CLockObject lock(&m_mutex);
     m_bStarted = true;
     m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
@@ -353,11 +355,6 @@ void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout)
   m_iRetryLineTimeout = iTimeout;
 }
 
-bool CCECProcessor::SetActiveSource(cec_logical_address iAddress)
-{
-  return SetStreamPath(m_busDevices[iAddress]->GetPhysicalAddress(false));
-}
-
 bool CCECProcessor::SetActiveView(void)
 {
   return SetActiveSource(m_types.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_types[0]);
@@ -524,7 +521,10 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
   {
     for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
       if (m_logicalAddresses[iPtr])
+      {
         m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
+        m_busDevices[iPtr]->TransmitPhysicalAddress();
+      }
     return SetActiveView();
   }
   return false;
@@ -540,7 +540,7 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable)
     CLockObject lock(&m_mutex);
     m_bMonitor = bEnable;
 
-    if (bEnable)
+    if (!bEnable)
     {
       if (!m_busScan)
       {
@@ -1297,9 +1297,15 @@ const char *CCECProcessor::ToString(const cec_vendor_id vendor)
 void *CCECBusScan::Process(void)
 {
   CCECBusDevice *device(NULL);
+  uint8_t iCounter(0);
 
   while (!IsStopped())
   {
+    if (++iCounter < 30)
+    {
+      Sleep(1000);
+      continue;
+    }
     for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++)
     {
       device = m_processor->m_busDevices[iPtr];
index 24dd5b1d0f7733ad6e355e70d1b16acaf158d26c..6d775f5cf4ecfcb4f9c42eb2f9a76a3f79304da5 100644 (file)
@@ -77,7 +77,6 @@ namespace CEC
 
       virtual bool SetActiveView(void);
       virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
-      virtual bool SetActiveSource(cec_logical_address iAddress);
       virtual bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true);
       virtual bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
       virtual bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce = false);
index 4c25e61907d1cb681aef73c607a63a823551f8c3..1793cc4c5af3431a42b07836908f85eee7b8ec55 100644 (file)
@@ -118,19 +118,20 @@ bool CCECBusDevice::PowerOn(void)
   {
     {
       CLockObject lock(&m_mutex);
-      m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
-    }
-    cec_power_status status = GetPowerStatus();
-    if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
-    {
-      /* sending the normal power on command appears to have failed */
-      CStdString strLog;
-      strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
-      AddLog(CEC_LOG_DEBUG, strLog.c_str());
-
-      TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
-      return TransmitKeyRelease();
+//      m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
+      m_powerStatus = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON;
     }
+//    cec_power_status status = GetPowerStatus();
+//    if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
+//    {
+//      /* sending the normal power on command appears to have failed */
+//      CStdString strLog;
+//      strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+//      AddLog(CEC_LOG_DEBUG, strLog.c_str());
+//
+//      TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
+//      return TransmitKeyRelease();
+//    }
     return true;
   }
 
@@ -749,7 +750,7 @@ bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
   return m_handler->TransmitPowerState(m_iLogicalAddress, dest, state);
 }
 
-bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
+bool CCECBusDevice::TransmitVendorID(cec_logical_address dest, bool bSendAbort /* = true */)
 {
   uint64_t iVendorId;
   {
@@ -759,11 +760,14 @@ bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
 
   if (iVendorId == CEC_VENDOR_UNKNOWN)
   {
-    CStdString strLog;
-    strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
-    AddLog(CEC_LOG_NOTICE, strLog);
+    if (bSendAbort)
+    {
+      CStdString strLog;
+      strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
+      AddLog(CEC_LOG_NOTICE, strLog);
 
-    m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
+      m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
+    }
     return false;
   }
   else
index 6806df07adf35c7756a554379afe674946227eed..80576b4b003b81a8c416653d0ff47e20d5fda89d 100644 (file)
@@ -39,10 +39,12 @@ namespace CEC
 {
   class CCECProcessor;
   class CCECCommandHandler;
+  class CSLCommandHandler;
 
   class CCECBusDevice
   {
     friend class CCECProcessor;
+    friend class CSLCommandHandler;
 
   public:
     CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
@@ -94,7 +96,7 @@ namespace CEC
     virtual bool TransmitPhysicalAddress(void);
     virtual bool TransmitPowerState(cec_logical_address dest);
     virtual bool TransmitPoll(cec_logical_address dest);
-    virtual bool TransmitVendorID(cec_logical_address dest);
+    virtual bool TransmitVendorID(cec_logical_address dest, bool bSendAbort = true);
     virtual bool TransmitKeypress(cec_user_control_code key);
     virtual bool TransmitKeyRelease(void);
 
index 2fe03080c7911fb3acb4bd062fb8b9e6f203a045..c58a606a1f69a8f0349a17091f4a630a0f642aa6 100644 (file)
@@ -319,7 +319,7 @@ bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &comm
 
 bool CCECCommandHandler::HandleImageViewOn(const cec_command &command)
 {
-  m_processor->SetActiveSource(command.initiator);
+  m_processor->SetStreamPath(m_processor->m_busDevices[command.initiator]->GetPhysicalAddress(false));
   return true;
 }
 
@@ -491,7 +491,7 @@ bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command
         uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
         CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress);
         if (newActiveDevice)
-          m_processor->SetActiveSource(newActiveDevice->GetLogicalAddress());
+          m_processor->SetStreamPath(newActiveDevice->GetPhysicalAddress(false));
         return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator);
       }
       else
@@ -545,7 +545,7 @@ bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command)
 
 bool CCECCommandHandler::HandleTextViewOn(const cec_command &command)
 {
-  m_processor->SetActiveSource(command.initiator);
+  m_processor->SetStreamPath(m_processor->m_busDevices[command.initiator]->GetPhysicalAddress(false));
   return true;
 }
 
index f9892d8dab82299ef94fb6e2ccafde81151f666b..b1f16442489399e8875d45e017a49d81bf5df2fb 100644 (file)
@@ -53,6 +53,7 @@ CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) :
     m_bSLEnabled(false),
     m_bVendorIdSent(false)
 {
+  m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary]->m_powerStatus = CEC_POWER_STATUS_STANDBY;
 }
 
 bool CSLCommandHandler::HandleVendorCommand(const cec_command &command)
@@ -103,17 +104,28 @@ bool CSLCommandHandler::HandleGiveDeckStatus(const cec_command &command)
 }
 
 void CSLCommandHandler::HandleVendorCommand01(const cec_command &command)
+{
+  TransmitVendorCommand0205(command.destination, command.initiator);
+}
+
+void CSLCommandHandler::TransmitVendorCommand0205(const cec_logical_address iSource, const cec_logical_address iDestination)
 {
   cec_command response;
-  cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND);
+  cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND);
   response.PushBack(SL_COMMAND_UNKNOWN_02);
   response.PushBack(SL_COMMAND_UNKNOWN_03);
 
   Transmit(response);
+}
 
-  /* transmit power status */
-  if (command.destination != CECDEVICE_BROADCAST)
-    m_processor->m_busDevices[command.destination]->TransmitPowerState(command.initiator);
+void CSLCommandHandler::TransmitVendorCommand04(const cec_logical_address iSource, const cec_logical_address iDestination)
+{
+  m_bSLEnabled = true;
+  cec_command response;
+  cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND);
+  response.PushBack(SL_COMMAND_CONNECT_ACCEPT);
+  response.PushBack((uint8_t)iSource);
+  Transmit(response);
 }
 
 void CSLCommandHandler::HandleVendorCommand03(const cec_command &command)
@@ -121,26 +133,18 @@ void CSLCommandHandler::HandleVendorCommand03(const cec_command &command)
   CCECBusDevice *device = m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary];
   if (device)
   {
-    device->SetPowerStatus(CEC_POWER_STATUS_ON);
+    m_bSLEnabled = true;
+    device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
     device->TransmitPowerState(command.initiator);
-    device->TransmitPhysicalAddress();
+    device->TransmitVendorID(command.initiator);
     TransmitPowerOn(device->GetLogicalAddress(), command.initiator);
-    if (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE ||
-        device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)
-    {
-      ((CCECPlaybackDevice *)device)->TransmitDeckStatus(command.initiator);
-    }
   }
 }
 
 void CSLCommandHandler::HandleVendorCommand04(const cec_command &command)
 {
-  cec_command response;
-  cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND);
-  response.PushBack(SL_COMMAND_CONNECT_ACCEPT);
-  response.PushBack((uint8_t)m_processor->GetLogicalAddresses().primary);
-  Transmit(response);
-
+  m_bSLEnabled = true;
+  TransmitVendorCommand04(command.destination, command.initiator);
   TransmitDeckStatus(command.initiator);
 }
 
@@ -192,8 +196,8 @@ bool CSLCommandHandler::HandleCommand(const cec_command &command)
 {
   bool bHandled(false);
 
-  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination) ||
-      command.destination == CECDEVICE_BROADCAST)
+  if (m_processor->IsStarted() && (m_busDevice->MyLogicalAddressContains(command.destination) ||
+      command.destination == CECDEVICE_BROADCAST))
   {
     switch(command.opcode)
     {
@@ -207,8 +211,6 @@ bool CSLCommandHandler::HandleCommand(const cec_command &command)
           m_bVendorIdSent = true;
           TransmitLGVendorId(m_processor->GetLogicalAddresses().primary, CECDEVICE_BROADCAST);
         }
-        m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary]->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
-        m_bSLEnabled = false;
       }
       bHandled = true;
     default:
@@ -241,10 +243,6 @@ bool CSLCommandHandler::HandleReceiveFailed(void)
 
 bool CSLCommandHandler::InitHandler(void)
 {
-  if (m_bSLEnabled)
-    return true;
-  m_bSLEnabled = true;
-
   m_processor->SetStandardLineTimeout(3);
   m_processor->SetRetryLineTimeout(3);
 
@@ -271,7 +269,8 @@ bool CSLCommandHandler::InitHandler(void)
 
   if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV)
   {
-    m_processor->SetActiveSource(m_processor->GetLogicalAddresses().primary);
+    m_processor->SetActiveSource();
+
     /* LG TVs only route keypresses when the deck status is set to 0x20 */
     cec_logical_addresses addr = m_processor->GetLogicalAddresses();
     for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
@@ -307,3 +306,4 @@ bool CSLCommandHandler::TransmitPowerOn(const cec_logical_address iInitiator, co
 
   return CCECCommandHandler::TransmitPowerOn(iInitiator, iDestination);
 }
+
index 6a91df4c1e7a6d1d62c4e8dd2ef20543141e342a..d00f2cd8f34bebcbcddeaa4e40aa5efb7c656c19 100644 (file)
@@ -55,6 +55,8 @@ namespace CEC
     virtual void HandleVendorCommand04(const cec_command &command);
     virtual void HandleVendorCommandA0(const cec_command &command);
 
+    virtual void TransmitVendorCommand0205(const cec_logical_address iSource, const cec_logical_address iDestination);
+    virtual void TransmitVendorCommand04(const cec_logical_address iSource, const cec_logical_address iDestination);
     virtual void TransmitDeckStatus(const cec_logical_address iDestination);
     virtual bool HandleGiveDeviceVendorId(const cec_command &command);
     virtual bool HandleVendorCommand(const cec_command &command);