cec: fixed - ensure that the ackmask is set
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 16:36:06 +0000 (17:36 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 16:36:06 +0000 (17:36 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h

index c9e9b7fbaefea442cadaa466478caef8fec41f66..4036fbe81b6f37bac88d48f59a89df5960052f08 100644 (file)
@@ -42,11 +42,12 @@ using namespace CEC;
 using namespace std;
 
 CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
-    m_iLogicalAddress(CECDEVICE_UNKNOWN),
+    m_iLogicalAddress(iLogicalAddress),
     m_strDeviceName(strDeviceName),
     m_communication(serComm),
     m_controller(controller),
-    m_bMonitor(false)
+    m_bMonitor(false),
+    m_bLogicalAddressSet(false)
 {
   for (int iPtr = 0; iPtr < 16; iPtr++)
     m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0);
@@ -172,19 +173,21 @@ void CCECProcessor::LogOutput(const cec_command &data)
   m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
 }
 
-bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
+bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress /* = CECDEVICE_UNKNOWN */)
 {
-  if (m_iLogicalAddress != iLogicalAddress)
+  if (iLogicalAddress != CECDEVICE_UNKNOWN)
   {
     CStdString strLog;
     strLog.Format("<< setting logical address to %1x", iLogicalAddress);
     m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
-
     m_iLogicalAddress = iLogicalAddress;
-    return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
+    m_bLogicalAddressSet = false;
   }
 
-  return true;
+  if (!m_bLogicalAddressSet && m_iLogicalAddress != CECDEVICE_UNKNOWN)
+    m_bLogicalAddressSet = m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
+
+  return m_bLogicalAddressSet;
 }
 
 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
@@ -241,6 +244,8 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres
 
 bool CCECProcessor::Transmit(const cec_command &data)
 {
+  SetLogicalAddress();
+
   bool bReturn(false);
   LogOutput(data);
 
index 6b663e352f04de9e7d3a00321493f6fd4bb06f30..c7af22d7fa8b15712977f21d05da38d4d6f1e789 100644 (file)
@@ -58,7 +58,7 @@ namespace CEC
       virtual bool SetActiveView(void);
       virtual bool SetInactiveView(void);
       virtual bool Transmit(const cec_command &data);
-      virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress);
+      virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_UNKNOWN);
       virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress);
       virtual bool SwitchMonitoring(bool bEnable);
       virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress);
@@ -94,5 +94,6 @@ namespace CEC
       CAdapterCommunication           *m_communication;
       CLibCEC                         *m_controller;
       bool                             m_bMonitor;
+      bool                             m_bLogicalAddressSet;
   };
 };