From 8d915412796290269f7efd48dc5e6802d82f5f15 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Sun, 4 Dec 2011 02:55:21 +0100 Subject: [PATCH] cec: send deck status 0x20 when an LG tv is found, so keypresses will be routed to libcec --- include/cectypes.h | 3 +- src/lib/AdapterCommunication.cpp | 2 +- src/lib/CECProcessor.cpp | 13 +++- src/lib/devices/CECBusDevice.cpp | 10 +++ src/lib/implementations/CECCommandHandler.h | 2 + src/lib/implementations/SLCommandHandler.cpp | 73 +++++++++++++++----- src/lib/implementations/SLCommandHandler.h | 2 + 7 files changed, 84 insertions(+), 21 deletions(-) diff --git a/include/cectypes.h b/include/cectypes.h index 467f150..c13f349 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -154,7 +154,8 @@ typedef enum cec_deck_info CEC_DECK_INFO_SKIP_REVERSE_REWIND = 0x1C, CEC_DECK_INFO_INDEX_SEARCH_FORWARD = 0x1D, CEC_DECK_INFO_INDEX_SEARCH_REVERSE = 0x1E, - CEC_DECK_INFO_OTHER_STATUS = 0x1F + CEC_DECK_INFO_OTHER_STATUS = 0x1F, + CEC_DECK_INFO_OTHER_STATUS_LG = 0x20 } cec_deck_info; typedef enum cec_device_type diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 7f801b6..caa8442 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -290,7 +290,7 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38 //clear any input bytes uint8_t buff[1024]; - while (m_port->Read(buff, sizeof(buff), 500) > 0) {} + while (m_port->Read(buff, sizeof(buff), 1000) > 0) {} if (CreateThread()) { diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index d1d7c6d..6791d51 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -315,8 +315,17 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE } } - return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false)) && - m_busDevices[addr]->TransmitActiveSource(); + bReturn = m_busDevices[CECDEVICE_TV]->PowerOn() && + m_busDevices[addr]->TransmitActiveSource() && + SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false)); + + if (bReturn && (m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || + m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) + { + bReturn = ((CCECPlaybackDevice *)m_busDevices[addr])->TransmitDeckStatus(CECDEVICE_TV); + } + + return bReturn; } bool CCECProcessor::SetActiveSource(cec_logical_address iAddress) diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index c06a8b8..5cfca59 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -84,7 +84,15 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) m_iLastActive = GetTimeMs(); m_handler->HandleCommand(command); if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) + { + if (m_deviceStatus != CEC_DEVICE_STATUS_PRESENT) + { + CStdString strLog; + strLog.Format("device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command.opcode)); + AddLog(CEC_LOG_DEBUG, strLog); + } m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; + } m_condition.Signal(); return true; } @@ -595,6 +603,8 @@ void CCECBusDevice::SetVendorId(uint64_t iVendorId) } } + m_handler->InitHandler(); + CStdString strLog; strLog.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor); m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str()); diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 8c6d0c1..383a386 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -50,6 +50,8 @@ namespace CEC virtual void HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination); virtual bool HandleReceiveFailed(void); + virtual bool InitHandler(void) { return true; } + protected: virtual bool HandleActiveSource(const cec_command &command); virtual bool HandleDeckControl(const cec_command &command); diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index c6affec..d442eaf 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -32,6 +32,7 @@ #include "SLCommandHandler.h" #include "../devices/CECBusDevice.h" +#include "../devices/CECPlaybackDevice.h" #include "../CECProcessor.h" using namespace CEC; @@ -53,35 +54,42 @@ bool CSLCommandHandler::HandleVendorCommand(const cec_command &command) response.PushBack(0x02); response.PushBack(0x05); - return m_busDevice->GetProcessor()->Transmit(response); + m_busDevice->GetProcessor()->Transmit(response); + TransmitLGVendorId(command.destination, command.initiator); + return true; } else if (command.parameters.size >= 1 && command.parameters[0] == 0x04) { - /* enable SL */ - cec_command response; - cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND); - response.PushBack(0x05); - response.PushBack(0x04); - - return m_busDevice->GetProcessor()->Transmit(response); + CCECBusDevice *primary = m_busDevice->GetProcessor()->m_busDevices[m_busDevice->GetProcessor()->GetLogicalAddresses().primary]; + if (primary->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) + { + ((CCECPlaybackDevice *)primary)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); + ((CCECPlaybackDevice *)primary)->TransmitDeckStatus(command.initiator); + } + return true; } else if (command.parameters.size == 1 && command.parameters[0] == 0xa0) { - /* enable SL */ - cec_command response; - cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND); - response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 16) & 0xFF)); - response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 8) & 0xFF)); - response.parameters.PushBack((uint8_t) ((uint64_t)CEC_VENDOR_LG & 0xFF)); - - return m_busDevice->GetProcessor()->Transmit(response); + TransmitLGVendorId(command.destination, command.initiator); + return true; } return false; } +bool CSLCommandHandler::TransmitLGVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination) +{ + cec_command response; + cec_command::Format(response, iInitiator, iDestination, CEC_OPCODE_VENDOR_COMMAND); + response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 16) & 0xFF)); + response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 8) & 0xFF)); + response.parameters.PushBack((uint8_t) ((uint64_t)CEC_VENDOR_LG & 0xFF)); + + return m_busDevice->GetProcessor()->Transmit(response); +} + bool CSLCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) { /* imitate LG devices */ @@ -102,6 +110,15 @@ bool CSLCommandHandler::HandleCommand(const cec_command &command) case CEC_OPCODE_VENDOR_COMMAND: bHandled = HandleVendorCommand(command); break; + case CEC_OPCODE_DEVICE_VENDOR_ID: + { + if (command.initiator == m_busDevice->GetLogicalAddress()) + { + TransmitLGVendorId(m_busDevice->GetProcessor()->GetLogicalAddresses().primary, command.initiator); + bHandled = true; + } + } + break; default: break; } @@ -113,7 +130,6 @@ bool CSLCommandHandler::HandleCommand(const cec_command &command) return bHandled; } - void CSLCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) { CCECCommandHandler::HandlePoll(iInitiator, iDestination); @@ -130,3 +146,26 @@ bool CSLCommandHandler::HandleReceiveFailed(void) return true; } + +bool CSLCommandHandler::InitHandler(void) +{ + if (m_busDevice->GetLogicalAddress() != CECDEVICE_TV) + return true; + + /* LG TVs only route keypresses when the deck status is set to 0x20 */ + cec_logical_addresses addr = m_busDevice->GetProcessor()->GetLogicalAddresses(); + for (uint8_t iPtr = 0; iPtr < 15; iPtr++) + { + if (addr[iPtr]) + { + CCECBusDevice *device = m_busDevice->GetProcessor()->m_busDevices[iPtr]; + if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || + device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) + { + ((CCECPlaybackDevice *)device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); + ((CCECPlaybackDevice *)device)->TransmitDeckStatus(CECDEVICE_TV); + } + } + } + return true; +} diff --git a/src/lib/implementations/SLCommandHandler.h b/src/lib/implementations/SLCommandHandler.h index 7566fb7..9d3ba01 100644 --- a/src/lib/implementations/SLCommandHandler.h +++ b/src/lib/implementations/SLCommandHandler.h @@ -45,6 +45,8 @@ namespace CEC virtual bool HandleCommand(const cec_command &command); virtual void HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination); virtual bool HandleReceiveFailed(void); + virtual bool InitHandler(void); + virtual bool TransmitLGVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination); protected: virtual bool HandleGiveDeviceVendorId(const cec_command &command); -- 2.34.1