2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 #include "SLCommandHandler.h"
34 #include "../devices/CECBusDevice.h"
35 #include "../devices/CECPlaybackDevice.h"
36 #include "../CECProcessor.h"
40 #define SL_COMMAND_UNKNOWN_01 0x01
41 #define SL_COMMAND_UNKNOWN_02 0x02
42 #define SL_COMMAND_UNKNOWN_03 0x05
44 #define SL_COMMAND_REQUEST_POWER_STATUS 0xa0
45 #define SL_COMMAND_POWER_ON 0x03
46 #define SL_COMMAND_CONNECT_REQUEST 0x04
47 #define SL_COMMAND_CONNECT_ACCEPT 0x05
49 CSLCommandHandler::CSLCommandHandler(CCECBusDevice
*busDevice
) :
50 CCECCommandHandler(busDevice
),
51 m_bAwaitingReceiveFailed(false),
53 m_bPowerStateReset(false)
55 m_vendorId
= CEC_VENDOR_LG
;
56 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
58 /* imitate LG devices */
59 if (m_busDevice
->GetLogicalAddress() != primary
->GetLogicalAddress())
60 primary
->SetVendorId(CEC_VENDOR_LG
);
63 /* LG TVs don't always reply to CEC version requests, so just set it to 1.3a */
64 if (m_busDevice
->GetLogicalAddress() == CECDEVICE_TV
)
65 m_busDevice
->SetCecVersion(CEC_VERSION_1_3A
);
67 /* LG devices always return "korean" as language */
68 cec_menu_language lang
;
69 lang
.device
= m_busDevice
->GetLogicalAddress();
70 snprintf(lang
.language
, 4, "eng");
71 m_busDevice
->SetMenuLanguage(lang
);
75 void CSLCommandHandler::HandlePoll(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
77 CCECCommandHandler::HandlePoll(iInitiator
, iDestination
);
78 m_bAwaitingReceiveFailed
= true;
81 bool CSLCommandHandler::HandleReceiveFailed(void)
83 if (m_bAwaitingReceiveFailed
)
85 m_bAwaitingReceiveFailed
= false;
92 bool CSLCommandHandler::InitHandler(void)
96 m_bHandlerInited
= true;
98 /* reply with LGs vendor id */
99 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
100 if (m_busDevice
->GetLogicalAddress() != primary
->GetLogicalAddress())
101 primary
->TransmitVendorID(CECDEVICE_TV
, false);
103 primary
->SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
107 bool CSLCommandHandler::ActivateSource(void)
109 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
110 primary
->SetActiveSource();
111 primary
->TransmitActiveSource();
115 bool CSLCommandHandler::HandleActiveSource(const cec_command
&command
)
117 if (command
.parameters
.size
== 2)
119 uint16_t iAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
120 if (iAddress
!= m_busDevice
->GetPhysicalAddress(false))
121 m_bSLEnabled
= false;
122 return m_processor
->SetActiveSource(iAddress
);
128 bool CSLCommandHandler::HandleFeatureAbort(const cec_command
&command
)
130 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
131 if (primary
->GetPowerStatus(false) == CEC_POWER_STATUS_ON
&& !m_bPowerStateReset
&& !m_bSLEnabled
)
133 m_bPowerStateReset
= true;
134 primary
->SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
137 return CCECCommandHandler::HandleFeatureAbort(command
);
140 bool CSLCommandHandler::HandleGivePhysicalAddress(const cec_command
&command
)
142 if (m_processor
->IsStarted() && m_busDevice
->MyLogicalAddressContains(command
.destination
))
144 CCECBusDevice
*device
= GetDevice(command
.destination
);
146 return device
->TransmitPhysicalAddress();
152 bool CSLCommandHandler::HandleVendorCommand(const cec_command
&command
)
154 if (command
.parameters
.size
== 1 &&
155 command
.parameters
[0] == SL_COMMAND_UNKNOWN_01
)
157 HandleVendorCommand01(command
);
160 else if (command
.parameters
.size
== 2 &&
161 command
.parameters
[0] == SL_COMMAND_POWER_ON
)
163 HandleVendorCommandPowerOn(command
);
166 else if (command
.parameters
.size
== 2 &&
167 command
.parameters
[0] == SL_COMMAND_CONNECT_REQUEST
)
169 HandleVendorCommandSLConnect(command
);
172 else if (command
.parameters
.size
== 1 &&
173 command
.parameters
[0] == SL_COMMAND_REQUEST_POWER_STATUS
)
175 HandleVendorCommandPowerOnStatus(command
);
182 void CSLCommandHandler::HandleVendorCommand01(const cec_command
&command
)
184 TransmitVendorCommand0205(command
.destination
, command
.initiator
);
187 void CSLCommandHandler::TransmitVendorCommand0205(const cec_logical_address iSource
, const cec_logical_address iDestination
)
189 cec_command response
;
190 cec_command::Format(response
, iSource
, iDestination
, CEC_OPCODE_VENDOR_COMMAND
);
191 response
.PushBack(SL_COMMAND_UNKNOWN_02
);
192 response
.PushBack(SL_COMMAND_UNKNOWN_03
);
194 Transmit(response
, false);
197 void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command
&command
)
199 CCECBusDevice
*device
= m_processor
->GetPrimaryDevice();
204 device
->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
); //XXX
205 device
->TransmitPowerState(command
.initiator
);
206 device
->SetPowerStatus(CEC_POWER_STATUS_ON
);
209 device
->SetActiveSource();
210 TransmitImageViewOn(device
->GetLogicalAddress(), command
.initiator
);
213 void CSLCommandHandler::HandleVendorCommandPowerOnStatus(const cec_command
&command
)
215 if (command
.destination
!= CECDEVICE_BROADCAST
)
217 CCECBusDevice
*device
= m_processor
->m_busDevices
[m_processor
->GetLogicalAddresses().primary
];
218 device
->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
);
219 device
->TransmitPowerState(command
.initiator
);
220 device
->SetPowerStatus(CEC_POWER_STATUS_ON
);
224 void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command
&command
)
229 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
231 primary
->SetActiveSource();
232 TransmitImageViewOn(primary
->GetLogicalAddress(), command
.initiator
);
233 TransmitVendorCommand05(primary
->GetLogicalAddress(), command
.initiator
);
236 void CSLCommandHandler::TransmitVendorCommand05(const cec_logical_address iSource
, const cec_logical_address iDestination
)
238 cec_command response
;
239 cec_command::Format(response
, iSource
, iDestination
, CEC_OPCODE_VENDOR_COMMAND
);
240 response
.PushBack(SL_COMMAND_CONNECT_ACCEPT
);
241 response
.PushBack((uint8_t)iSource
);
242 Transmit(response
, false);
245 void CSLCommandHandler::SetLGDeckStatus(void)
247 /* LG TVs only route keypresses when the deck status is set to 0x20 */
248 CCECBusDevice
*device
= m_processor
->GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
250 ((CCECPlaybackDevice
*)device
)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG
);
252 device
= m_processor
->GetDeviceByType(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
254 ((CCECPlaybackDevice
*)device
)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG
);