From d9de2aae6b2f47b8e1faacc69adba7406b9d85f0 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Thu, 5 Sep 2013 19:14:24 +0200 Subject: [PATCH 1/1] sharp: check whether the 'auto power on' option is disabled and tell the user how to enable it --- src/lib/CECProcessor.cpp | 2 +- src/lib/Makefile.am | 3 +- src/lib/devices/CECBusDevice.cpp | 10 ++- src/lib/devices/CECBusDevice.h | 2 +- src/lib/implementations/AQCommandHandler.cpp | 89 +++++++++++++++++++ src/lib/implementations/AQCommandHandler.h | 74 +++++++++++++++ src/lib/implementations/CECCommandHandler.cpp | 6 +- src/lib/implementations/CECCommandHandler.h | 4 +- src/lib/implementations/VLCommandHandler.cpp | 2 +- 9 files changed, 180 insertions(+), 12 deletions(-) create mode 100644 src/lib/implementations/AQCommandHandler.cpp create mode 100644 src/lib/implementations/AQCommandHandler.h diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 6749170..b1761a3 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -859,7 +859,7 @@ bool CCECProcessor::RegisterClient(CCECClient *client) client->GetPrimaryDevice()->TransmitOSDName(CECDEVICE_TV, false); // request the power status of the TV - tv->RequestPowerStatus(sourceAddress, true); + tv->RequestPowerStatus(sourceAddress, true, true); return bReturn; } diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index cdc1cbd..9117d8e 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -27,7 +27,8 @@ libcec_la_SOURCES = CECProcessor.cpp \ implementations/VLCommandHandler.cpp \ implementations/RLCommandHandler.cpp \ implementations/PHCommandHandler.cpp \ - implementations/RHCommandHandler.cpp + implementations/RHCommandHandler.cpp \ + implementations/AQCommandHandler.cpp ## server sockets, currently unused ##libcec_la_SOURCES += platform/posix/serversocket.cpp diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 25332b3..f2bd59f 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -42,6 +42,7 @@ #include "lib/implementations/PHCommandHandler.h" #include "lib/implementations/RLCommandHandler.h" #include "lib/implementations/RHCommandHandler.h" +#include "lib/implementations/AQCommandHandler.h" #include "lib/LibCEC.h" #include "lib/CECTypeUtils.h" #include "lib/platform/util/timeutils.h" @@ -145,6 +146,9 @@ bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) case CEC_VENDOR_ONKYO: m_handler = new CRHCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); break; + case CEC_VENDOR_SHARP: + m_handler = new CAQCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); + break; default: m_handler = new CCECCommandHandler(this, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending); break; @@ -609,7 +613,7 @@ cec_power_status CCECBusDevice::GetPowerStatus(const cec_logical_address initiat if (bRequestUpdate) { CheckVendorIdRequested(initiator); - RequestPowerStatus(initiator); + RequestPowerStatus(initiator, bUpdate); } CLockObject lock(m_mutex); @@ -646,7 +650,7 @@ bool CCECBusDevice::ImageViewOnSent(void) return m_bImageViewOnSent; } -bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator, bool bWaitForResponse /* = true */) +bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator, bool bUpdate, bool bWaitForResponse /* = true */) { bool bReturn(false); @@ -654,7 +658,7 @@ bool CCECBusDevice::RequestPowerStatus(const cec_logical_address initiator, bool !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS)) { MarkBusy(); - bReturn = m_handler->TransmitRequestPowerStatus(initiator, m_iLogicalAddress, bWaitForResponse); + bReturn = m_handler->TransmitRequestPowerStatus(initiator, m_iLogicalAddress, bUpdate, bWaitForResponse); if (!bReturn) SetPowerStatus(CEC_POWER_STATUS_UNKNOWN); MarkReady(); diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index e159aea..8a80f48 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -194,7 +194,7 @@ namespace CEC virtual void SetPowerStatus(const cec_power_status powerStatus); virtual void OnImageViewOnSent(bool bSentByLibCEC); virtual bool ImageViewOnSent(void); - virtual bool RequestPowerStatus(const cec_logical_address initiator, bool bWaitForResponse = true); + virtual bool RequestPowerStatus(const cec_logical_address initiator, bool bUpdate, bool bWaitForResponse = true); virtual bool TransmitPowerState(const cec_logical_address destination, bool bIsReply); virtual cec_vendor_id GetCurrentVendorId(void); diff --git a/src/lib/implementations/AQCommandHandler.cpp b/src/lib/implementations/AQCommandHandler.cpp new file mode 100644 index 0000000..93bba24 --- /dev/null +++ b/src/lib/implementations/AQCommandHandler.cpp @@ -0,0 +1,89 @@ +/* + * This file is part of the libCEC(R) library. + * + * 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. + * + * This program is dual-licensed; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * Alternatively, you can license this library under a commercial license, + * please contact Pulse-Eight Licensing for more information. + * + * For more information contact: + * Pulse-Eight Licensing + * http://www.pulse-eight.com/ + * http://www.pulse-eight.net/ + */ + +#include "env.h" +#include "AQCommandHandler.h" + +#include "lib/devices/CECBusDevice.h" +#include "lib/CECProcessor.h" +#include "lib/LibCEC.h" +#include "lib/CECClient.h" + +using namespace CEC; +using namespace PLATFORM; + +#define LIB_CEC m_busDevice->GetProcessor()->GetLib() +#define ToString(p) LIB_CEC->ToString(p) + +CAQCommandHandler::CAQCommandHandler(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_powerOnCheck(NULL) +{ + m_vendorId = CEC_VENDOR_SHARP; +} + +CAQCommandHandler::~CAQCommandHandler(void) +{ + delete m_powerOnCheck; +} + +bool CAQCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination) +{ + bool bCheck(false); + bool bRetval(false); + if (m_busDevice->GetCurrentPowerStatus() != CEC_POWER_STATUS_ON && (!m_powerOnCheck || !m_powerOnCheck->IsRunning())) + bCheck = true; + bRetval = CCECCommandHandler::PowerOn(iInitiator, iDestination); + + if (bRetval && bCheck) + { + if (!m_powerOnCheck) + m_powerOnCheck = new CAQPowerStatusCheck(this, iInitiator, iDestination); + if (m_powerOnCheck) + m_powerOnCheck->CreateThread(); + } + + return bRetval; +} + +void* CAQPowerStatusCheck::Process(void) +{ + // sleep for 2 seconds and query the power status + Sleep(2000); + if (m_handler->m_busDevice->GetProcessor()->GetDevice(m_iDestination)->GetPowerStatus(m_iInitiator, true) == CEC_POWER_STATUS_STANDBY) + m_handler->m_busDevice->GetProcessor()->GetLib()->AddLog(CEC_LOG_WARNING, "AQUOS LINK 'auto power on' is disabled, which prevents the TV from being powered on. To correct this, press the menu button on your remote, go to 'link operation' -> 'AQUOS LINK setup' -> 'Auto power on' and set it to 'On'"); + return NULL; +} diff --git a/src/lib/implementations/AQCommandHandler.h b/src/lib/implementations/AQCommandHandler.h new file mode 100644 index 0000000..9193b3a --- /dev/null +++ b/src/lib/implementations/AQCommandHandler.h @@ -0,0 +1,74 @@ +#pragma once +/* + * This file is part of the libCEC(R) library. + * + * 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. + * + * This program is dual-licensed; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * Alternatively, you can license this library under a commercial license, + * please contact Pulse-Eight Licensing for more information. + * + * For more information contact: + * Pulse-Eight Licensing + * http://www.pulse-eight.com/ + * http://www.pulse-eight.net/ + */ + +#include "CECCommandHandler.h" +#include "platform/threads/threads.h" + +namespace CEC +{ + class CAQPowerStatusCheck; + + class CAQCommandHandler : public CCECCommandHandler + { + friend class CAQPowerStatusCheck; + public: + CAQCommandHandler(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); + virtual ~CAQCommandHandler(void); + + protected: + virtual bool PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination); + + private: + CAQPowerStatusCheck* m_powerOnCheck; + }; + + class CAQPowerStatusCheck : public PLATFORM::CThread + { + public: + CAQPowerStatusCheck(CAQCommandHandler* handler, cec_logical_address iInitiator, cec_logical_address iDestination) : + m_handler(handler), + m_iInitiator(iInitiator), + m_iDestination(iDestination) {} + virtual ~CAQPowerStatusCheck(void) {} + + private: + void* Process(void); + CAQCommandHandler* m_handler; + cec_logical_address m_iInitiator; + cec_logical_address m_iDestination; + }; +}; diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index b742f49..12e74e3 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -910,12 +910,12 @@ bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_addres return Transmit(command, !bWaitForResponse, false); } -bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) +bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bUpdate, bool bWaitForResponse /* = true */) { if (iDestination == CECDEVICE_TV) { int64_t now(GetTimeMs()); - if (now - m_iPowerStatusRequested < REQUEST_POWER_STATUS_TIMEOUT) + if (!bUpdate && now - m_iPowerStatusRequested < REQUEST_POWER_STATUS_TIMEOUT) return true; m_iPowerStatusRequested = now; } @@ -1207,7 +1207,7 @@ bool CCECCommandHandler::ActivateSource(bool bTransmitDelayedCommandsOnly /* = f bool bTvPresent = (tv && tv->GetStatus() == CEC_DEVICE_STATUS_PRESENT); bool bActiveSourceFailed(false); if (bTvPresent) - bActiveSourceFailed = !m_busDevice->TransmitImageViewOn(); + bActiveSourceFailed = !tv->PowerOn(m_busDevice->GetLogicalAddress()); else LIB_CEC->AddLog(CEC_LOG_DEBUG, "TV not present, not sending 'image view on'"); diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 5ad5ab0..aeace02 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -58,7 +58,7 @@ namespace CEC virtual bool HandleCommand(const cec_command &command); virtual cec_vendor_id GetVendorId(void) { return m_vendorId; }; virtual void SetVendorId(cec_vendor_id vendorId) { m_vendorId = vendorId; } - static bool HasSpecificHandler(cec_vendor_id vendorId) { return vendorId == CEC_VENDOR_LG || vendorId == CEC_VENDOR_SAMSUNG || vendorId == CEC_VENDOR_PANASONIC || vendorId == CEC_VENDOR_PHILIPS;} + static bool HasSpecificHandler(cec_vendor_id vendorId) { return vendorId == CEC_VENDOR_LG || vendorId == CEC_VENDOR_SAMSUNG || vendorId == CEC_VENDOR_PANASONIC || vendorId == CEC_VENDOR_PHILIPS || vendorId == CEC_VENDOR_SHARP;} virtual bool InitHandler(void) { return true; } virtual bool ActivateSource(bool bTransmitDelayedCommandsOnly = false); @@ -73,7 +73,7 @@ namespace CEC virtual bool TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true); virtual bool TransmitRequestAudioStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true); virtual bool TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true); - virtual bool TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true); + virtual bool TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bUpdate, bool bWaitForResponse = true); virtual bool TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse = true); virtual bool TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress, bool bIsReply); virtual bool TransmitCECVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_version cecVersion, bool bIsReply); diff --git a/src/lib/implementations/VLCommandHandler.cpp b/src/lib/implementations/VLCommandHandler.cpp index 907de02..5f014f0 100644 --- a/src/lib/implementations/VLCommandHandler.cpp +++ b/src/lib/implementations/VLCommandHandler.cpp @@ -262,7 +262,7 @@ int CVLCommandHandler::HandleVendorCommand(const cec_command &command) bool CVLCommandHandler::SourceSwitchAllowed(void) { if (!PowerUpEventReceived()) - TransmitRequestPowerStatus(m_processor->GetPrimaryDevice()->GetLogicalAddress(), CECDEVICE_TV, false); + TransmitRequestPowerStatus(m_processor->GetPrimaryDevice()->GetLogicalAddress(), CECDEVICE_TV, false, false); return PowerUpEventReceived(); } -- 2.34.1