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