cec: reset m_bPowerUpEventReceived in CVLCommandHandler when the device lets us know...
[deb_libcec.git] / src / lib / implementations / VLCommandHandler.cpp
CommitLineData
bb5b4874
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
b492c10e 4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
bb5b4874
LOK
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
31 */
32
33#include "VLCommandHandler.h"
34#include "../devices/CECBusDevice.h"
3e61b350 35#include "../CECProcessor.h"
b78b4e33 36#include "../LibCEC.h"
004b8382 37#include "../CECClient.h"
b78b4e33
LOK
38
39#define VL_POWER_CHANGE 0x20
40#define VL_POWERED_UP 0x00
41#define VL_POWERED_DOWN 0x01
bb5b4874
LOK
42
43using namespace CEC;
b78b4e33 44using namespace PLATFORM;
bb5b4874 45
004b8382
LOK
46#define LIB_CEC m_busDevice->GetProcessor()->GetLib()
47#define ToString(p) LIB_CEC->ToString(p)
48
bb5b4874 49CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) :
b78b4e33
LOK
50 CCECCommandHandler(busDevice),
51 m_bActiveSourcePending(false),
52 m_bPowerUpEventReceived(false)
bb5b4874 53{
cf4931be 54 m_vendorId = CEC_VENDOR_PANASONIC;
bb5b4874 55}
3e61b350
LOK
56
57bool CVLCommandHandler::InitHandler(void)
58{
59 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
42d28d15
LOK
60 if (primary && primary->GetLogicalAddress() != CECDEVICE_UNREGISTERED)
61 {
62 /* use the VL commandhandler for the primary device that is handled by libCEC */
63 if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV)
64 {
65 if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
66 {
67 primary->SetVendorId(CEC_VENDOR_PANASONIC);
68 primary->ReplaceHandler(false);
69 }
70 }
71
72 if (primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)
73 return m_processor->GetPrimaryClient()->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
74 }
b78b4e33 75
3e61b350
LOK
76 return CCECCommandHandler::InitHandler();
77}
b78b4e33 78
9a54dc82 79int CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
b78b4e33 80{
344cddb9
LOK
81 if (command.parameters[0] != 0x00 ||
82 command.parameters[1] != 0x80 ||
83 command.parameters[2] != 0x45)
84 return CEC_ABORT_REASON_INVALID_OPERAND;
85
b78b4e33
LOK
86 if (command.initiator == CECDEVICE_TV &&
87 command.destination == CECDEVICE_BROADCAST &&
88 command.parameters.At(3) == VL_POWER_CHANGE)
89 {
90 if (command.parameters.At(4) == VL_POWERED_UP)
91 {
004b8382 92 LIB_CEC->AddLog(CEC_LOG_DEBUG, "TV powered up");
b78b4e33
LOK
93 {
94 CLockObject lock(m_mutex);
95 m_bPowerUpEventReceived = true;
96 }
97 m_processor->TransmitPendingActiveSourceCommands();
98 }
99 else if (command.parameters.At(4) == VL_POWERED_DOWN)
004b8382 100 LIB_CEC->AddLog(CEC_LOG_DEBUG, "TV powered down");
b78b4e33 101 else if (command.parameters.At(4) == VL_POWERED_DOWN)
004b8382 102 LIB_CEC->AddLog(CEC_LOG_DEBUG, "unknown vendor command");
b78b4e33 103
9a54dc82 104 return COMMAND_HANDLED;
b78b4e33
LOK
105 }
106
107 return CCECCommandHandler::HandleDeviceVendorCommandWithId(command);
108}
109
110bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
111{
112 bool bPowerUpEventReceived(false);
113
004b8382
LOK
114 CCECBusDevice *tv = m_processor->GetDevice(CECDEVICE_TV);
115 if (tv && tv->GetCurrentVendorId() == CEC_VENDOR_PANASONIC)
b78b4e33 116 {
b47f66af
LOK
117 CVLCommandHandler *handler = static_cast<CVLCommandHandler *>(tv->GetHandler());
118 bPowerUpEventReceived = handler ? handler->PowerUpEventReceived() : false;
91ef4e2d 119 tv->MarkHandlerReady();
b78b4e33
LOK
120 }
121
122 if (!bPowerUpEventReceived)
123 {
124 CLockObject lock(m_mutex);
125 // wait until we received the event
126 m_bActiveSourcePending = true;
127 return true;
128 }
129 else
130 {
131 // transmit standard active source message
e8a6f887 132 return CCECCommandHandler::TransmitActiveSource(iInitiator, iPhysicalAddress);
b78b4e33
LOK
133 }
134}
135
136bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void)
137{
138 bool bTransmitCommand(false);
139 {
140 CLockObject lock(m_mutex);
141 bTransmitCommand = m_bActiveSourcePending;
142 m_bActiveSourcePending = false;
143 }
144
145 if (bTransmitCommand)
146 {
004b8382 147 LIB_CEC->AddLog(CEC_LOG_DEBUG, "transmitting delayed activate source command");
6d7c0fa8
LOK
148 return CCECCommandHandler::TransmitActiveSource(m_busDevice->GetLogicalAddress(), m_busDevice->GetCurrentPhysicalAddress()) &&
149 TransmitMenuState(m_busDevice->GetLogicalAddress(), CECDEVICE_TV, CEC_MENU_STATE_ACTIVATED);
b78b4e33
LOK
150 }
151 return true;
152}
b47f66af
LOK
153
154bool CVLCommandHandler::PowerUpEventReceived(void)
155{
156 {
157 CLockObject lock(m_mutex);
158 if (m_bPowerUpEventReceived)
159 return true;
160 }
161
b47f66af 162 CLockObject lock(m_mutex);
19b2a82f 163 m_bPowerUpEventReceived = (m_busDevice->GetCurrentPowerStatus() == CEC_POWER_STATUS_ON);
b47f66af
LOK
164 return m_bPowerUpEventReceived;
165}
344cddb9 166
f8a669d0
LOK
167int CVLCommandHandler::HandleStandby(const cec_command &command)
168{
169 {
170 CLockObject lock(m_mutex);
171 m_bPowerUpEventReceived = false;
172 }
173
174 return CCECCommandHandler::HandleStandby(command);
175}
176
344cddb9
LOK
177int CVLCommandHandler::HandleVendorCommand(const cec_command &command)
178{
179 // some vendor command voodoo that will enable more buttons on the remote
180 if (command.parameters.size == 3 &&
181 command.parameters[0] == 0x10 &&
182 command.parameters[1] == 0x01 &&
183 command.parameters[2] == 0x05)
184 {
185 cec_command response;
186 cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND);
187 uint8_t iResponseData[] = {0x10, 0x02, 0xFF, 0xFF, 0x00, 0x05, 0x05, 0x45, 0x55, 0x5c, 0x58, 0x32};
188 response.PushArray(12, iResponseData);
189
190 Transmit(response, true);
191
192 return COMMAND_HANDLED;
193 }
194
195 return CEC_ABORT_REASON_INVALID_OPERAND;
196}
197