Commit | Line | Data |
---|---|---|
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" |
e9de9629 LOK |
38 | |
39 | using namespace CEC; | |
40 | ||
11d13a02 LOK |
41 | #define SL_COMMAND_UNKNOWN_01 0x01 |
42 | #define SL_COMMAND_UNKNOWN_02 0x02 | |
43 | #define SL_COMMAND_UNKNOWN_03 0x05 | |
44 | ||
45 | #define SL_COMMAND_REQUEST_VENDOR_ID 0xa0 | |
46 | #define SL_COMMAND_CONNECT_REQUEST 0x04 | |
47 | #define SL_COMMAND_CONNECT_ACCEPT 0x05 | |
48 | ||
e9de9629 | 49 | CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) : |
855a3a98 | 50 | CCECCommandHandler(busDevice), |
b4c4ef7d LOK |
51 | m_bAwaitingReceiveFailed(false), |
52 | m_bSLEnabled(false), | |
53 | m_bSkipNextVendorId(false) | |
e9de9629 LOK |
54 | { |
55 | } | |
e54fd7d2 LOK |
56 | |
57 | bool CSLCommandHandler::HandleVendorCommand(const cec_command &command) | |
58 | { | |
59 | if (command.parameters.size == 1 && | |
11d13a02 | 60 | command.parameters[0] == SL_COMMAND_UNKNOWN_01) |
e54fd7d2 LOK |
61 | { |
62 | /* enable SL */ | |
63 | cec_command response; | |
caaf64d7 | 64 | cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND, m_busDevice->GetTransmitTimeout()); |
11d13a02 LOK |
65 | response.PushBack(SL_COMMAND_UNKNOWN_02); |
66 | response.PushBack(SL_COMMAND_UNKNOWN_03); | |
e54fd7d2 | 67 | |
8d915412 | 68 | m_busDevice->GetProcessor()->Transmit(response); |
8d915412 | 69 | return true; |
e54fd7d2 | 70 | } |
797dd7c4 | 71 | else if (command.parameters.size == 2 && |
11d13a02 | 72 | command.parameters[0] == SL_COMMAND_CONNECT_REQUEST) |
9902f4e8 | 73 | { |
797dd7c4 LOK |
74 | /* enable SL */ |
75 | cec_command response; | |
76 | cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND, m_busDevice->GetTransmitTimeout()); | |
11d13a02 | 77 | response.PushBack(SL_COMMAND_CONNECT_ACCEPT); |
b4c4ef7d | 78 | response.PushBack(m_busDevice->GetProcessor()->GetLogicalAddresses().primary); |
797dd7c4 LOK |
79 | m_busDevice->GetProcessor()->Transmit(response); |
80 | ||
11d13a02 | 81 | /* set deck status for the playback device */ |
b4c4ef7d | 82 | TransmitDeckStatus(command.initiator); |
8d915412 | 83 | return true; |
9902f4e8 LOK |
84 | } |
85 | else if (command.parameters.size == 1 && | |
11d13a02 | 86 | command.parameters[0] == SL_COMMAND_REQUEST_VENDOR_ID) |
9902f4e8 | 87 | { |
b4c4ef7d | 88 | TransmitLGVendorId(m_busDevice->GetProcessor()->GetLogicalAddresses().primary, CECDEVICE_BROADCAST); |
8d915412 | 89 | return true; |
9902f4e8 | 90 | } |
e54fd7d2 LOK |
91 | |
92 | return false; | |
93 | } | |
94 | ||
b4c4ef7d LOK |
95 | void CSLCommandHandler::TransmitDeckStatus(const cec_logical_address iDestination) |
96 | { | |
97 | /* set deck status for the playback device */ | |
98 | CCECBusDevice *primary = m_busDevice->GetProcessor()->m_busDevices[m_busDevice->GetProcessor()->GetLogicalAddresses().primary]; | |
99 | if (primary->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) | |
100 | { | |
101 | ((CCECPlaybackDevice *)primary)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); | |
102 | ((CCECPlaybackDevice *)primary)->TransmitDeckStatus(iDestination); | |
103 | } | |
104 | } | |
105 | ||
8d915412 LOK |
106 | bool CSLCommandHandler::TransmitLGVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination) |
107 | { | |
108 | cec_command response; | |
b4c4ef7d | 109 | cec_command::Format(response, iInitiator, iDestination, CEC_OPCODE_DEVICE_VENDOR_ID, m_busDevice->GetTransmitTimeout()); |
8d915412 LOK |
110 | response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 16) & 0xFF)); |
111 | response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 8) & 0xFF)); | |
112 | response.parameters.PushBack((uint8_t) ((uint64_t)CEC_VENDOR_LG & 0xFF)); | |
113 | ||
b4c4ef7d LOK |
114 | m_busDevice->GetProcessor()->Transmit(response); |
115 | return true; | |
8d915412 LOK |
116 | } |
117 | ||
e54fd7d2 LOK |
118 | bool CSLCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) |
119 | { | |
120 | /* imitate LG devices */ | |
121 | CCECBusDevice *device = GetDevice(command.destination); | |
122 | if (device) | |
123 | device->SetVendorId(CEC_VENDOR_LG); | |
124 | ||
125 | return CCECCommandHandler::HandleGiveDeviceVendorId(command); | |
126 | } | |
127 | ||
128 | bool CSLCommandHandler::HandleCommand(const cec_command &command) | |
129 | { | |
130 | bool bHandled(false); | |
b4c4ef7d LOK |
131 | if (m_busDevice->MyLogicalAddressContains(command.destination) || |
132 | command.destination == CECDEVICE_BROADCAST) | |
e54fd7d2 LOK |
133 | { |
134 | switch(command.opcode) | |
135 | { | |
136 | case CEC_OPCODE_VENDOR_COMMAND: | |
137 | bHandled = HandleVendorCommand(command); | |
138 | break; | |
b4c4ef7d | 139 | case CEC_OPCODE_GIVE_DECK_STATUS: |
8d915412 | 140 | { |
b4c4ef7d | 141 | if (command.parameters.size == 1) |
8d915412 | 142 | { |
b4c4ef7d LOK |
143 | if (command.parameters[0] == CEC_STATUS_REQUEST_ONCE || |
144 | command.parameters[0] == CEC_STATUS_REQUEST_ON) | |
145 | TransmitDeckStatus(command.initiator); | |
146 | else | |
147 | CCECCommandHandler::HandleCommand(command); | |
8d915412 | 148 | } |
b4c4ef7d | 149 | bHandled = true; |
8d915412 LOK |
150 | } |
151 | break; | |
b4c4ef7d LOK |
152 | case CEC_OPCODE_FEATURE_ABORT: |
153 | { | |
154 | if (!m_bSkipNextVendorId) | |
155 | { | |
156 | m_bSkipNextVendorId = true; | |
157 | TransmitLGVendorId(m_busDevice->GetProcessor()->GetLogicalAddresses().primary, CECDEVICE_BROADCAST); | |
158 | } | |
159 | m_bSLEnabled = false; | |
160 | } | |
161 | bHandled = true; | |
e54fd7d2 LOK |
162 | default: |
163 | break; | |
164 | } | |
165 | } | |
166 | ||
167 | if (!bHandled) | |
168 | bHandled = CCECCommandHandler::HandleCommand(command); | |
169 | ||
170 | return bHandled; | |
171 | } | |
855a3a98 | 172 | |
855a3a98 LOK |
173 | void CSLCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) |
174 | { | |
175 | CCECCommandHandler::HandlePoll(iInitiator, iDestination); | |
176 | m_bAwaitingReceiveFailed = true; | |
177 | } | |
178 | ||
179 | bool CSLCommandHandler::HandleReceiveFailed(void) | |
180 | { | |
181 | if (m_bAwaitingReceiveFailed) | |
182 | { | |
183 | m_bAwaitingReceiveFailed = false; | |
184 | return false; | |
185 | } | |
186 | ||
187 | return true; | |
188 | } | |
8d915412 LOK |
189 | |
190 | bool CSLCommandHandler::InitHandler(void) | |
191 | { | |
192 | if (m_busDevice->GetLogicalAddress() != CECDEVICE_TV) | |
193 | return true; | |
194 | ||
b4c4ef7d LOK |
195 | if (m_bSLEnabled) |
196 | return true; | |
197 | m_bSLEnabled = true; | |
198 | ||
199 | CCECBusDevice *primary = m_busDevice->GetProcessor()->m_busDevices[m_busDevice->GetProcessor()->GetLogicalAddresses().primary]; | |
200 | primary->SetVendorId(CEC_VENDOR_LG); | |
201 | primary->TransmitVendorID(CECDEVICE_TV); | |
202 | primary->TransmitPhysicalAddress(); | |
203 | ||
204 | cec_command command; | |
205 | cec_command::Format(command, m_busDevice->GetProcessor()->GetLogicalAddresses().primary, CECDEVICE_TV, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); | |
206 | m_busDevice->GetProcessor()->Transmit(command); | |
207 | ||
caaf64d7 LOK |
208 | /* LG TVs don't always reply to CEC version requests, so just set it to 1.3a */ |
209 | m_busDevice->GetProcessor()->m_busDevices[CECDEVICE_TV]->SetCecVersion(CEC_VERSION_1_3A); | |
210 | ||
8d915412 LOK |
211 | /* LG TVs only route keypresses when the deck status is set to 0x20 */ |
212 | cec_logical_addresses addr = m_busDevice->GetProcessor()->GetLogicalAddresses(); | |
213 | for (uint8_t iPtr = 0; iPtr < 15; iPtr++) | |
214 | { | |
caaf64d7 LOK |
215 | CCECBusDevice *device = m_busDevice->GetProcessor()->m_busDevices[iPtr]; |
216 | ||
217 | /* increase the transmit timeout because the tv is keeping the bus busy at times */ | |
218 | device->SetTransmitTimeout(3000); | |
8d915412 LOK |
219 | if (addr[iPtr]) |
220 | { | |
8d915412 LOK |
221 | if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || |
222 | device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) | |
223 | { | |
224 | ((CCECPlaybackDevice *)device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); | |
b4c4ef7d | 225 | TransmitDeckStatus(CECDEVICE_TV); |
8d915412 LOK |
226 | } |
227 | } | |
228 | } | |
229 | return true; | |
230 | } |