cec: added SetMenuState()
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 07592587d6a4134e216bac82540d70bc0bfb3822..f2eafaac5022bf095a7a6b678c61fd16151105ba 100644 (file)
@@ -156,12 +156,13 @@ bool CCECProcessor::TryLogicalAddress(cec_logical_address address, unsigned int
       m_busDevices[address]->m_strDeviceName = m_strDeviceName;
       m_busDevices[address]->m_bActiveSource = true;
     }
-    m_busDevices[address]->m_powerStatus = (m_types[0] == m_busDevices[address]->m_type) ? CEC_POWER_STATUS_ON : CEC_POWER_STATUS_STANDBY;
-    m_busDevices[address]->m_cecVersion = CEC_VERSION_1_3A;
+    m_busDevices[address]->m_powerStatus = CEC_POWER_STATUS_STANDBY;
+    m_busDevices[address]->m_cecVersion =  CEC_VERSION_1_3A;
+
     m_logicalAddresses.set(address);
 
     // TODO
-    m_busDevices[address]->SetPhysicalAddress(CEC_DEFAULT_PHYSICAL_ADDRESS + (iIndex * 0x100));
+    m_busDevices[address]->SetPhysicalAddress((uint16_t)CEC_DEFAULT_PHYSICAL_ADDRESS + ((uint16_t)iIndex * 0x100));
 
     return true;
   }
@@ -268,7 +269,7 @@ void *CCECProcessor::Process(void)
       else if (m_communication->IsOpen() && m_communication->Read(msg, 50))
       {
         m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
-        if ((bParseFrame = (ParseMessage(msg) && !IsStopped())))
+        if ((bParseFrame = (ParseMessage(msg) && !IsStopped())) == true)
           command = m_currentframe;
       }
     }
@@ -301,7 +302,7 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
 
   if (type != CEC_DEVICE_TYPE_RESERVED)
   {
-    for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+    for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
     {
       if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
       {
@@ -319,6 +320,38 @@ bool CCECProcessor::SetActiveView(void)
   return SetActiveSource();
 }
 
+bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
+{
+  bool bReturn(false);
+
+  CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
+  if (device)
+  {
+    ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
+    if (bSendUpdate)
+      ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
+    bReturn = true;
+  }
+
+  return bReturn;
+}
+
+bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
+{
+  bool bReturn(false);
+
+  CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
+  if (device)
+  {
+    ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
+    if (bSendUpdate)
+      ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
+    bReturn = true;
+  }
+
+  return bReturn;
+}
+
 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
 {
   bool bReturn(false);
@@ -330,6 +363,7 @@ bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
       m_busDevices[iPtr]->m_bActiveSource = false;
 
     device->m_bActiveSource = true;
+    device->m_powerStatus   = CEC_POWER_STATUS_ON;
 
     if (m_logicalAddresses.isset(device->m_iLogicalAddress))
       bReturn = device->TransmitActiveSource();
@@ -377,6 +411,20 @@ bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
   return true;
 }
 
+bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
+{
+  for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+  {
+    if (m_logicalAddresses[iPtr])
+      m_busDevices[iPtr]->SetMenuState(state);
+  }
+
+  if (bSendUpdate)
+    m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
+
+  return true;
+}
+
 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
 {
   if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
@@ -407,7 +455,6 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress)
   return false;
 }
 
-
 CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
 {
   CCECBusDevice *device = NULL;
@@ -424,6 +471,22 @@ CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddre
   return device;
 }
 
+CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
+{
+  CCECBusDevice *device = NULL;
+
+  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  {
+    if (m_busDevices[iPtr]->m_type == type)
+    {
+      device = m_busDevices[iPtr];
+      break;
+    }
+  }
+
+  return device;
+}
+
 cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
 {
   return m_busDevices[iAddress]->GetCecVersion();
@@ -495,7 +558,7 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output)
   return bReturn;
 }
 
-void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
+void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
 {
   m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");