cec: get the cached power status of a device in CVLCommandHandler::PowerUpEventReceiv...
[deb_libcec.git] / src / lib / implementations / VLCommandHandler.cpp
index 3d96004a7f401bdbf5874ac1a0cf69484b74b857..642b3839a456d6cef69d75bca0092d02a92a71e7 100644 (file)
@@ -76,8 +76,13 @@ bool CVLCommandHandler::InitHandler(void)
   return CCECCommandHandler::InitHandler();
 }
 
-bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
+int CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
 {
+  if (command.parameters[0] != 0x00 ||
+      command.parameters[1] != 0x80 ||
+      command.parameters[2] != 0x45)
+    return CEC_ABORT_REASON_INVALID_OPERAND;
+
   if (command.initiator == CECDEVICE_TV &&
       command.destination == CECDEVICE_BROADCAST &&
       command.parameters.At(3) == VL_POWER_CHANGE)
@@ -96,7 +101,7 @@ bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &comma
     else if (command.parameters.At(4) == VL_POWERED_DOWN)
       LIB_CEC->AddLog(CEC_LOG_DEBUG, "unknown vendor command");
 
-    return true;
+    return COMMAND_HANDLED;
   }
 
   return CCECCommandHandler::HandleDeviceVendorCommandWithId(command);
@@ -111,6 +116,7 @@ bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiato
   {
     CVLCommandHandler *handler = static_cast<CVLCommandHandler *>(tv->GetHandler());
     bPowerUpEventReceived = handler ? handler->PowerUpEventReceived() : false;
+    tv->MarkHandlerReady();
   }
 
   if (!bPowerUpEventReceived)
@@ -123,8 +129,7 @@ bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiato
   else
   {
     // transmit standard active source message
-    return CCECCommandHandler::TransmitActiveSource(iInitiator, iPhysicalAddress) &&
-        TransmitMenuState(iInitiator, CECDEVICE_TV, CEC_MENU_STATE_ACTIVATED);
+    return CCECCommandHandler::TransmitActiveSource(iInitiator, iPhysicalAddress);
   }
 }
 
@@ -154,9 +159,29 @@ bool CVLCommandHandler::PowerUpEventReceived(void)
       return true;
   }
 
-  cec_power_status powerStatus = m_busDevice->GetCurrentPowerStatus();
-
   CLockObject lock(m_mutex);
-  m_bPowerUpEventReceived = (powerStatus == CEC_POWER_STATUS_ON);
+  m_bPowerUpEventReceived = (m_busDevice->GetCurrentPowerStatus() == CEC_POWER_STATUS_ON);
   return m_bPowerUpEventReceived;
 }
+
+int CVLCommandHandler::HandleVendorCommand(const cec_command &command)
+{
+  // some vendor command voodoo that will enable more buttons on the remote
+  if (command.parameters.size == 3 &&
+      command.parameters[0] == 0x10 &&
+      command.parameters[1] == 0x01 &&
+      command.parameters[2] == 0x05)
+  {
+    cec_command response;
+    cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND);
+    uint8_t iResponseData[] = {0x10, 0x02, 0xFF, 0xFF, 0x00, 0x05, 0x05, 0x45, 0x55, 0x5c, 0x58, 0x32};
+    response.PushArray(12, iResponseData);
+
+    Transmit(response, true);
+
+    return COMMAND_HANDLED;
+  }
+
+  return CEC_ABORT_REASON_INVALID_OPERAND;
+}
+