cec: don't send a deck status update when sending an active source message for panaso...
[deb_libcec.git] / src / lib / implementations / SLCommandHandler.cpp
CommitLineData
e9de9629
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
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 "SLCommandHandler.h"
e54fd7d2 34#include "../devices/CECBusDevice.h"
8d915412 35#include "../devices/CECPlaybackDevice.h"
e54fd7d2 36#include "../CECProcessor.h"
b4c4ef7d 37#include "../platform/timeutils.h"
468a1414 38#include "../platform/threads.h"
e9de9629
LOK
39
40using namespace CEC;
41
0d4c3a7b
LOK
42#define SL_COMMAND_UNKNOWN_01 0x01
43#define SL_COMMAND_UNKNOWN_02 0x02
44#define SL_COMMAND_UNKNOWN_03 0x05
11d13a02 45
0d4c3a7b 46#define SL_COMMAND_REQUEST_POWER_STATUS 0xa0
9a0d7b9f 47#define SL_COMMAND_POWER_ON 0x03
0d4c3a7b
LOK
48#define SL_COMMAND_CONNECT_REQUEST 0x04
49#define SL_COMMAND_CONNECT_ACCEPT 0x05
11d13a02 50
e9de9629 51CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) :
855a3a98 52 CCECCommandHandler(busDevice),
b4c4ef7d
LOK
53 m_bAwaitingReceiveFailed(false),
54 m_bSLEnabled(false),
468a1414 55 m_bPowerStateReset(false)
e9de9629 56{
79f01d26
LOK
57 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
58
59 /* imitate LG devices */
60 if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
3e61b350 61 primary->SetVendorId(CEC_VENDOR_LG);
468a1414 62 SetLGDeckStatus();
79f01d26
LOK
63
64 /* LG TVs don't always reply to CEC version requests, so just set it to 1.3a */
65 if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV)
66 m_busDevice->SetCecVersion(CEC_VERSION_1_3A);
67
68 /* LG devices always return "korean" as language */
69 cec_menu_language lang;
70 lang.device = m_busDevice->GetLogicalAddress();
71 snprintf(lang.language, 4, "eng");
72 m_busDevice->SetMenuLanguage(lang);
9f65e017
LOK
73}
74
468a1414
LOK
75
76void CSLCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination)
9f65e017 77{
468a1414
LOK
78 CCECCommandHandler::HandlePoll(iInitiator, iDestination);
79 m_bAwaitingReceiveFailed = true;
80}
9f65e017 81
468a1414
LOK
82bool CSLCommandHandler::HandleReceiveFailed(void)
83{
84 if (m_bAwaitingReceiveFailed)
85 {
86 m_bAwaitingReceiveFailed = false;
87 return false;
88 }
89
90 return true;
91}
92
93bool CSLCommandHandler::InitHandler(void)
94{
95 if (m_bHandlerInited)
96 return true;
97 m_bHandlerInited = true;
98
99 /* reply with LGs vendor id */
100 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
101 if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
102 primary->TransmitVendorID(CECDEVICE_TV, false);
103
104 primary->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
105 return true;
106}
107
3e61b350
LOK
108bool CSLCommandHandler::ActivateSource(void)
109{
110 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
111 primary->SetActiveSource();
112 primary->TransmitActiveSource();
113 return true;
114}
115
468a1414
LOK
116bool CSLCommandHandler::HandleActiveSource(const cec_command &command)
117{
118 if (command.parameters.size == 2)
119 {
120 uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
121 if (iAddress != m_busDevice->GetPhysicalAddress(false))
122 m_bSLEnabled = false;
123 return m_processor->SetActiveSource(iAddress);
124 }
125
126 return true;
127}
128
129bool CSLCommandHandler::HandleFeatureAbort(const cec_command &command)
130{
131 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
132 if (primary->GetPowerStatus(false) == CEC_POWER_STATUS_ON && !m_bPowerStateReset && !m_bSLEnabled)
133 {
134 m_bPowerStateReset = true;
135 primary->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
136 }
137
138 return CCECCommandHandler::HandleFeatureAbort(command);
139}
140
141bool CSLCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
142{
143 if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
144 {
145 CCECBusDevice *device = GetDevice(command.destination);
146 if (device)
147 return device->TransmitPhysicalAddress();
148 }
149
150 return false;
e9de9629 151}
e54fd7d2
LOK
152
153bool CSLCommandHandler::HandleVendorCommand(const cec_command &command)
154{
155 if (command.parameters.size == 1 &&
11d13a02 156 command.parameters[0] == SL_COMMAND_UNKNOWN_01)
e54fd7d2 157 {
5f316715 158 HandleVendorCommand01(command);
8d915412 159 return true;
e54fd7d2 160 }
9a0d7b9f
LOK
161 else if (command.parameters.size == 2 &&
162 command.parameters[0] == SL_COMMAND_POWER_ON)
163 {
0ecbcd4d 164 HandleVendorCommandPowerOn(command);
9a0d7b9f
LOK
165 return true;
166 }
797dd7c4 167 else if (command.parameters.size == 2 &&
11d13a02 168 command.parameters[0] == SL_COMMAND_CONNECT_REQUEST)
9902f4e8 169 {
0ecbcd4d 170 HandleVendorCommandSLConnect(command);
8d915412 171 return true;
9902f4e8
LOK
172 }
173 else if (command.parameters.size == 1 &&
0d4c3a7b 174 command.parameters[0] == SL_COMMAND_REQUEST_POWER_STATUS)
9902f4e8 175 {
0ecbcd4d 176 HandleVendorCommandPowerOnStatus(command);
8d915412 177 return true;
9902f4e8 178 }
e54fd7d2
LOK
179
180 return false;
181}
182
5f316715 183void CSLCommandHandler::HandleVendorCommand01(const cec_command &command)
fe6f8e37
LOK
184{
185 TransmitVendorCommand0205(command.destination, command.initiator);
186}
187
188void CSLCommandHandler::TransmitVendorCommand0205(const cec_logical_address iSource, const cec_logical_address iDestination)
5f316715
LOK
189{
190 cec_command response;
fe6f8e37 191 cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND);
5f316715
LOK
192 response.PushBack(SL_COMMAND_UNKNOWN_02);
193 response.PushBack(SL_COMMAND_UNKNOWN_03);
194
19cbfa8f 195 Transmit(response, false);
fe6f8e37 196}
5f316715 197
0ecbcd4d 198void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command)
9a0d7b9f 199{
842262d8 200 CCECBusDevice *device = m_processor->GetPrimaryDevice();
9a0d7b9f
LOK
201 if (device)
202 {
fe6f8e37 203 m_bSLEnabled = true;
468a1414
LOK
204
205 device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); //XXX
9a0d7b9f 206 device->TransmitPowerState(command.initiator);
468a1414 207 device->SetPowerStatus(CEC_POWER_STATUS_ON);
9a0d7b9f 208
468a1414
LOK
209 SetLGDeckStatus();
210 device->SetActiveSource();
211 TransmitImageViewOn(device->GetLogicalAddress(), command.initiator);
212 }
5f316715 213}
0ecbcd4d 214void CSLCommandHandler::HandleVendorCommandPowerOnStatus(const cec_command &command)
5f316715
LOK
215{
216 if (command.destination != CECDEVICE_BROADCAST)
217 {
218 CCECBusDevice *device = m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary];
219 device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
220 device->TransmitPowerState(command.initiator);
221 device->SetPowerStatus(CEC_POWER_STATUS_ON);
222 }
223}
224
468a1414 225void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command &command)
8d915412 226{
468a1414
LOK
227 m_bSLEnabled = true;
228 SetLGDeckStatus();
89a726fa 229
79f01d26 230 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
37acf382 231
468a1414
LOK
232 primary->SetActiveSource();
233 TransmitImageViewOn(primary->GetLogicalAddress(), command.initiator);
234 TransmitVendorCommand05(primary->GetLogicalAddress(), command.initiator);
8d915412 235}
0d4c3a7b 236
468a1414 237void CSLCommandHandler::TransmitVendorCommand05(const cec_logical_address iSource, const cec_logical_address iDestination)
0d4c3a7b 238{
468a1414
LOK
239 cec_command response;
240 cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND);
241 response.PushBack(SL_COMMAND_CONNECT_ACCEPT);
242 response.PushBack((uint8_t)iSource);
243 Transmit(response, false);
0d4c3a7b 244}
fe6f8e37 245
468a1414 246void CSLCommandHandler::SetLGDeckStatus(void)
9f65e017 247{
468a1414
LOK
248 /* LG TVs only route keypresses when the deck status is set to 0x20 */
249 CCECBusDevice *device = m_processor->GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
250 if (device)
251 ((CCECPlaybackDevice *)device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
9f65e017 252
468a1414
LOK
253 device = m_processor->GetDeviceByType(CEC_DEVICE_TYPE_RECORDING_DEVICE);
254 if (device)
255 ((CCECPlaybackDevice *)device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG);
9f65e017 256}