X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fimplementations%2FANCommandHandler.cpp;h=115fa88709b261fd0f68351532fabe054a9cf33e;hb=41fafb34071badc0ffc57f0efb987058d87c456e;hp=e9674baafb22f84ca8f575d46e407884156cf8a4;hpb=5f3167157997a0d64fd8a44ad04babf43327eec8;p=deb_libcec.git diff --git a/src/lib/implementations/ANCommandHandler.cpp b/src/lib/implementations/ANCommandHandler.cpp index e9674ba..115fa88 100644 --- a/src/lib/implementations/ANCommandHandler.cpp +++ b/src/lib/implementations/ANCommandHandler.cpp @@ -1,7 +1,7 @@ /* * 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-2013 Pulse-Eight Limited. All rights reserved. * libCEC(R) is an original work, containing original code. * * libCEC(R) is a trademark of Pulse-Eight Limited. @@ -30,70 +30,94 @@ * http://www.pulse-eight.net/ */ +#include "env.h" #include "ANCommandHandler.h" -#include "../devices/CECBusDevice.h" -#include "../CECProcessor.h" -#include "../util/StdString.h" + +#include "lib/devices/CECBusDevice.h" +#include "lib/CECProcessor.h" +#include "lib/LibCEC.h" +#include "lib/CECClient.h" using namespace CEC; -CANCommandHandler::CANCommandHandler(CCECBusDevice *busDevice) : - CCECCommandHandler(busDevice) +#define LIB_CEC m_busDevice->GetProcessor()->GetLib() +#define ToString(p) LIB_CEC->ToString(p) + +CANCommandHandler::CANCommandHandler(CCECBusDevice *busDevice, + int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */, + int32_t iTransmitWait /* = CEC_DEFAULT_TRANSMIT_WAIT */, + int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */, + int64_t iActiveSourcePending /* = 0 */) : + CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending) { + m_vendorId = CEC_VENDOR_SAMSUNG; + 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; - switch (command.parameters[0]) - { - case CEC_AN_USER_CONTROL_CODE_RETURN: - key.keycode = CEC_USER_CONTROL_CODE_EXIT; - break; - default: - break; - } + if (!m_processor->CECInitialised()) + 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); + CCECClient *client = m_processor->GetClient(command.destination); + if (!client) + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; - m_busDevice->GetProcessor()->AddKey(key); - } + cec_keypress key; + key.duration = CEC_BUTTON_TIMEOUT; + key.keycode = (cec_user_control_code)command.parameters[0]; + + if (client) + client->AddKey(key); + + return COMMAND_HANDLED; +} + +int CANCommandHandler::HandleVendorRemoteButtonUp(const cec_command &command) +{ + return HandleUserControlRelease(command); +} + +bool CANCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination) +{ + if (iDestination == CECDEVICE_AUDIOSYSTEM) + { + /* 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); } - return true; + return CCECCommandHandler::PowerOn(iInitiator, iDestination); } -bool CANCommandHandler::HandleCommand(const cec_command &command) +int CANCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) { - bool bHandled(false); - if (m_busDevice->MyLogicalAddressContains(command.destination)) + if (!m_processor->IsHandledByLibCEC(command.destination)) + return CEC_ABORT_REASON_INVALID_OPERAND; + + // samsung's vendor id + if (command.parameters[0] == 0x00 && command.parameters[1] == 0x00 && command.parameters[2] == 0xf0) { - switch(command.opcode) + // unknown vendor command sent to devices + if (command.parameters[3] == 0x23) { - 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; - } - } + cec_command response; + cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND_WITH_ID); + + // samsung vendor id + response.parameters.PushBack(0x00); response.parameters.PushBack(0x00); response.parameters.PushBack(0xf0); - if (!bHandled) - bHandled = CCECCommandHandler::HandleCommand(command); + // XXX see bugzid 2164. reply sent back by audio systems, we might have to send something different + response.parameters.PushBack(0x24); + response.parameters.PushBack(0x00); + response.parameters.PushBack(0x80); - return bHandled; + Transmit(response, false, true); + return COMMAND_HANDLED; + } + } + return CEC_ABORT_REASON_INVALID_OPERAND; }