From e33e0d75ff34b5d4aa2b7c7922662ca666022f57 Mon Sep 17 00:00:00 2001 From: Mark Kendall Date: Wed, 21 Mar 2012 11:36:41 +0000 Subject: [PATCH] cec: Correct handling CEC_USER_CONTROL_CODE_POWER This ensures that the power code always operates as a toggle, depending on the current state, and that SetCurrentButton is always called for a valid user control code. Bugzid: 570 --- src/lib/implementations/CECCommandHandler.cpp | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index d0aa2b3..6e1aaac 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -591,37 +591,49 @@ bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) { - if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0) + if (m_processor->IsRunning() && + m_busDevice->MyLogicalAddressContains(command.destination) && + command.parameters.size > 0) { CLibCEC::AddKey(); - if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) + CLibCEC::SetCurrentButton((cec_user_control_code) command.parameters[0]); + + if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || + command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) { - if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || - command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) + bool bPowerOn(true); + CCECBusDevice *device = GetDevice(command.destination); + if (!device) + return true; + + // CEC_USER_CONTROL_CODE_POWER operates as a toggle + // assume CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION does not + if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER) { - CCECBusDevice *device = GetDevice(command.destination); - if (device) - { - device->SetPowerStatus(CEC_POWER_STATUS_ON); - if (device->MyLogicalAddressContains(device->GetLogicalAddress())) - { - device->SetActiveSource(); - device->TransmitImageViewOn(); - device->TransmitActiveSource(); - - if (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || - device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) - ((CCECPlaybackDevice *)device)->TransmitDeckStatus(command.initiator); - } - } + cec_power_status status = device->GetPowerStatus(); + bPowerOn = !(status == CEC_POWER_STATUS_ON || status == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); + } + + if (bPowerOn) + { + device->SetActiveSource(); + device->TransmitImageViewOn(); + device->TransmitActiveSource(); + + if (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || + device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) + ((CCECPlaybackDevice *)device)->TransmitDeckStatus(command.initiator); } else { - CLibCEC::SetCurrentButton((cec_user_control_code) command.parameters[0]); + device->SetInactiveSource(); + device->TransmitInactiveSource(); + device->SetMenuState(CEC_MENU_STATE_DEACTIVATED); } - return true; } + + return true; } return false; } -- 2.34.1