/*
* This file is part of the libCEC(R) library.
*
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
* libCEC(R) is an original work, containing original code.
*
* libCEC(R) is a trademark of Pulse-Eight Limited.
#include "ANCommandHandler.h"
#include "../devices/CECBusDevice.h"
#include "../CECProcessor.h"
+#include "../LibCEC.h"
+#include "../CECClient.h"
using namespace CEC;
+#define LIB_CEC m_busDevice->GetProcessor()->GetLib()
+#define ToString(p) LIB_CEC->ToString(p)
+
CANCommandHandler::CANCommandHandler(CCECBusDevice *busDevice) :
CCECCommandHandler(busDevice)
{
m_bOPTSendDeckStatusUpdateOnActiveSource = false;
}
-bool CANCommandHandler::HandleVendorRemoteButtonDown(const cec_command &command)
+int CANCommandHandler::HandleVendorRemoteButtonDown(const cec_command &command)
{
- if (m_processor->IsStarted() && command.parameters.size > 0)
- {
- cec_keypress key;
- key.duration = CEC_BUTTON_TIMEOUT;
- key.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
+ if (command.parameters.size == 0)
+ return CEC_ABORT_REASON_INVALID_OPERAND;
+
+ if (!m_processor->CECInitialised())
+ return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND;
- switch (command.parameters[0])
- {
- case CEC_AN_USER_CONTROL_CODE_RETURN:
- key.keycode = CEC_USER_CONTROL_CODE_EXIT;
- break;
- default:
- break;
- }
+ CCECClient *client = m_processor->GetClient(command.destination);
+ if (!client)
+ return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND;
- if (key.keycode != CEC_USER_CONTROL_CODE_UNKNOWN)
- {
- CStdString strLog;
- strLog.Format("key pressed: %1x", key.keycode);
- m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
+ cec_keypress key;
+ key.duration = CEC_BUTTON_TIMEOUT;
+ key.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
- m_busDevice->GetProcessor()->AddKey(key);
- }
+ switch (command.parameters[0])
+ {
+ case CEC_USER_CONTROL_CODE_AN_RETURN:
+ key.keycode = client && client->GetClientVersion() >= CEC_CLIENT_VERSION_1_5_0 ?
+ CEC_USER_CONTROL_CODE_AN_RETURN :
+ CEC_USER_CONTROL_CODE_EXIT;
+ break;
+ case CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST:
+ key.keycode = CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST;
+ break;
+ default:
+ break;
}
- return true;
+ if (key.keycode != CEC_USER_CONTROL_CODE_UNKNOWN && client)
+ client->AddKey(key);
+
+ return COMMAND_HANDLED;
}
-bool CANCommandHandler::HandleCommand(const cec_command &command)
+int CANCommandHandler::HandleVendorRemoteButtonUp(const cec_command &command)
{
- bool bHandled(false);
- if (m_busDevice->MyLogicalAddressContains(command.destination))
+ return HandleUserControlRelease(command);
+}
+
+bool CANCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+{
+ if (iDestination == CECDEVICE_AUDIOSYSTEM)
{
- switch(command.opcode)
- {
- case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
- bHandled = true;
- HandleVendorRemoteButtonDown(command);
- break;
- case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
- bHandled = true;
- HandleUserControlRelease(command);
- break;
- default:
- break;
- }
+ /* Samsung AVR devices need to be woken up with key CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION */
+ return TransmitKeypress(iInitiator, iDestination, CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) &&
+ TransmitKeyRelease(iInitiator, iDestination);
}
- if (!bHandled)
- bHandled = CCECCommandHandler::HandleCommand(command);
-
- return bHandled;
+ return CCECCommandHandler::PowerOn(iInitiator, iDestination);
}