Commit | Line | Data |
---|---|---|
e9de9629 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. |
e9de9629 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 "SLCommandHandler.h" | |
e54fd7d2 | 34 | #include "../devices/CECBusDevice.h" |
8d915412 | 35 | #include "../devices/CECPlaybackDevice.h" |
e54fd7d2 | 36 | #include "../CECProcessor.h" |
2abe628c | 37 | #include "../LibCEC.h" |
e9de9629 LOK |
38 | |
39 | using namespace CEC; | |
40 | ||
0d4c3a7b LOK |
41 | #define SL_COMMAND_UNKNOWN_01 0x01 |
42 | #define SL_COMMAND_UNKNOWN_02 0x02 | |
43 | #define SL_COMMAND_UNKNOWN_03 0x05 | |
11d13a02 | 44 | |
0d4c3a7b | 45 | #define SL_COMMAND_REQUEST_POWER_STATUS 0xa0 |
9a0d7b9f | 46 | #define SL_COMMAND_POWER_ON 0x03 |
0d4c3a7b | 47 | #define SL_COMMAND_CONNECT_REQUEST 0x04 |
5abb18f3 | 48 | #define SL_COMMAND_SET_DEVICE_MODE 0x05 |
11d13a02 | 49 | |
e9de9629 | 50 | CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) : |
855a3a98 | 51 | CCECCommandHandler(busDevice), |
b4c4ef7d | 52 | m_bSLEnabled(false), |
b818fb5a LOK |
53 | m_bPowerStateReset(false), |
54 | m_bActiveSourceSent(false) | |
e9de9629 | 55 | { |
cf4931be | 56 | m_vendorId = CEC_VENDOR_LG; |
79f01d26 LOK |
57 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); |
58 | ||
59 | /* imitate LG devices */ | |
ef583662 | 60 | if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) |
3e61b350 | 61 | primary->SetVendorId(CEC_VENDOR_LG); |
79f01d26 LOK |
62 | |
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); | |
66 | ||
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); | |
9f65e017 LOK |
72 | } |
73 | ||
468a1414 LOK |
74 | bool CSLCommandHandler::InitHandler(void) |
75 | { | |
76 | if (m_bHandlerInited) | |
77 | return true; | |
78 | m_bHandlerInited = true; | |
79 | ||
80 | /* reply with LGs vendor id */ | |
81 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); | |
82 | if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) | |
7e5a449a | 83 | primary->TransmitVendorID(CECDEVICE_BROADCAST, false); |
468a1414 | 84 | |
a463f954 | 85 | primary->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); |
468a1414 LOK |
86 | return true; |
87 | } | |
88 | ||
3e61b350 LOK |
89 | bool CSLCommandHandler::ActivateSource(void) |
90 | { | |
3faa971c LOK |
91 | if (!m_bSLEnabled) |
92 | return true; | |
93 | ||
b818fb5a | 94 | if (m_bActiveSourceSent) |
3faa971c | 95 | return true; |
b818fb5a LOK |
96 | m_bActiveSourceSent = true; |
97 | ||
3e61b350 LOK |
98 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); |
99 | primary->SetActiveSource(); | |
100 | primary->TransmitActiveSource(); | |
101 | return true; | |
102 | } | |
103 | ||
468a1414 LOK |
104 | bool CSLCommandHandler::HandleActiveSource(const cec_command &command) |
105 | { | |
106 | if (command.parameters.size == 2) | |
107 | { | |
108 | uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
109 | if (iAddress != m_busDevice->GetPhysicalAddress(false)) | |
110 | m_bSLEnabled = false; | |
111 | return m_processor->SetActiveSource(iAddress); | |
112 | } | |
113 | ||
114 | return true; | |
115 | } | |
116 | ||
a463f954 LOK |
117 | bool CSLCommandHandler::HandleDeviceVendorId(const cec_command &command) |
118 | { | |
119 | SetVendorId(command); | |
120 | ||
2abe628c | 121 | if (!m_bSLEnabled) |
468a1414 | 122 | { |
2abe628c LOK |
123 | cec_command response; |
124 | cec_command::Format(response, m_processor->GetLogicalAddress(), command.initiator, CEC_OPCODE_FEATURE_ABORT); | |
125 | return Transmit(response); | |
468a1414 | 126 | } |
2abe628c | 127 | return true; |
468a1414 LOK |
128 | } |
129 | ||
130 | bool CSLCommandHandler::HandleGivePhysicalAddress(const cec_command &command) | |
131 | { | |
8e57f83c | 132 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
468a1414 LOK |
133 | { |
134 | CCECBusDevice *device = GetDevice(command.destination); | |
135 | if (device) | |
b818fb5a | 136 | return device->TransmitPhysicalAddress(); // only the physical address, don't send image view on |
468a1414 LOK |
137 | } |
138 | ||
139 | return false; | |
e9de9629 | 140 | } |
e54fd7d2 LOK |
141 | |
142 | bool CSLCommandHandler::HandleVendorCommand(const cec_command &command) | |
143 | { | |
144 | if (command.parameters.size == 1 && | |
11d13a02 | 145 | command.parameters[0] == SL_COMMAND_UNKNOWN_01) |
e54fd7d2 | 146 | { |
5f316715 | 147 | HandleVendorCommand01(command); |
8d915412 | 148 | return true; |
e54fd7d2 | 149 | } |
9a0d7b9f LOK |
150 | else if (command.parameters.size == 2 && |
151 | command.parameters[0] == SL_COMMAND_POWER_ON) | |
152 | { | |
0ecbcd4d | 153 | HandleVendorCommandPowerOn(command); |
9a0d7b9f LOK |
154 | return true; |
155 | } | |
797dd7c4 | 156 | else if (command.parameters.size == 2 && |
11d13a02 | 157 | command.parameters[0] == SL_COMMAND_CONNECT_REQUEST) |
9902f4e8 | 158 | { |
0ecbcd4d | 159 | HandleVendorCommandSLConnect(command); |
8d915412 | 160 | return true; |
9902f4e8 LOK |
161 | } |
162 | else if (command.parameters.size == 1 && | |
0d4c3a7b | 163 | command.parameters[0] == SL_COMMAND_REQUEST_POWER_STATUS) |
9902f4e8 | 164 | { |
0ecbcd4d | 165 | HandleVendorCommandPowerOnStatus(command); |
8d915412 | 166 | return true; |
9902f4e8 | 167 | } |
e54fd7d2 LOK |
168 | |
169 | return false; | |
170 | } | |
171 | ||
5f316715 | 172 | void CSLCommandHandler::HandleVendorCommand01(const cec_command &command) |
fe6f8e37 | 173 | { |
b818fb5a | 174 | m_processor->GetPrimaryDevice()->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); |
fe6f8e37 LOK |
175 | TransmitVendorCommand0205(command.destination, command.initiator); |
176 | } | |
177 | ||
178 | void CSLCommandHandler::TransmitVendorCommand0205(const cec_logical_address iSource, const cec_logical_address iDestination) | |
5f316715 LOK |
179 | { |
180 | cec_command response; | |
fe6f8e37 | 181 | cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND); |
5f316715 LOK |
182 | response.PushBack(SL_COMMAND_UNKNOWN_02); |
183 | response.PushBack(SL_COMMAND_UNKNOWN_03); | |
184 | ||
19cbfa8f | 185 | Transmit(response, false); |
fe6f8e37 | 186 | } |
5f316715 | 187 | |
0ecbcd4d | 188 | void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command) |
9a0d7b9f | 189 | { |
842262d8 | 190 | CCECBusDevice *device = m_processor->GetPrimaryDevice(); |
9a0d7b9f LOK |
191 | if (device) |
192 | { | |
fe6f8e37 | 193 | m_bSLEnabled = true; |
468a1414 LOK |
194 | |
195 | device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); //XXX | |
9a0d7b9f | 196 | device->TransmitPowerState(command.initiator); |
468a1414 | 197 | device->SetPowerStatus(CEC_POWER_STATUS_ON); |
9a0d7b9f | 198 | |
468a1414 LOK |
199 | device->SetActiveSource(); |
200 | TransmitImageViewOn(device->GetLogicalAddress(), command.initiator); | |
201 | } | |
5f316715 | 202 | } |
0ecbcd4d | 203 | void CSLCommandHandler::HandleVendorCommandPowerOnStatus(const cec_command &command) |
5f316715 LOK |
204 | { |
205 | if (command.destination != CECDEVICE_BROADCAST) | |
206 | { | |
207 | CCECBusDevice *device = m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary]; | |
208 | device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); | |
209 | device->TransmitPowerState(command.initiator); | |
210 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
211 | } | |
212 | } | |
213 | ||
468a1414 | 214 | void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command &command) |
8d915412 | 215 | { |
468a1414 | 216 | m_bSLEnabled = true; |
5abb18f3 | 217 | TransmitVendorCommandSetDeviceMode(m_processor->GetLogicalAddress(), command.initiator, CEC_DEVICE_TYPE_RECORDING_DEVICE); |
37acf382 | 218 | |
2abe628c | 219 | ActivateSource(); |
8d915412 | 220 | } |
0d4c3a7b | 221 | |
5abb18f3 | 222 | void CSLCommandHandler::TransmitVendorCommandSetDeviceMode(const cec_logical_address iSource, const cec_logical_address iDestination, const cec_device_type type) |
0d4c3a7b | 223 | { |
468a1414 LOK |
224 | cec_command response; |
225 | cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND); | |
5abb18f3 LOK |
226 | response.PushBack(SL_COMMAND_SET_DEVICE_MODE); |
227 | response.PushBack((uint8_t)type); | |
468a1414 | 228 | Transmit(response, false); |
0d4c3a7b | 229 | } |
fe6f8e37 | 230 | |
b818fb5a | 231 | bool CSLCommandHandler::HandleGiveDeckStatus(const cec_command &command) |
9f65e017 | 232 | { |
b818fb5a LOK |
233 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
234 | { | |
235 | CCECBusDevice *device = GetDevice(command.destination); | |
236 | if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) | |
237 | { | |
238 | if (command.parameters.size > 0) | |
239 | { | |
b818fb5a LOK |
240 | if (command.parameters[0] == CEC_STATUS_REQUEST_ON) |
241 | { | |
2abe628c | 242 | ((CCECPlaybackDevice *) device)->SetDeckStatus(CEC_DECK_INFO_STOP); |
b818fb5a LOK |
243 | return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator) && |
244 | device->TransmitImageViewOn() && | |
245 | device->TransmitPhysicalAddress(); | |
246 | } | |
247 | else if (command.parameters[0] == CEC_STATUS_REQUEST_ONCE) | |
248 | { | |
2abe628c | 249 | ((CCECPlaybackDevice *) device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); |
b818fb5a LOK |
250 | return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator); |
251 | } | |
252 | } | |
253 | } | |
254 | return CCECCommandHandler::HandleGiveDeckStatus(command); | |
255 | } | |
9f65e017 | 256 | |
b818fb5a | 257 | return false; |
9f65e017 | 258 | } |
718b3632 | 259 | |
718b3632 LOK |
260 | bool CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) |
261 | { | |
2abe628c | 262 | bool bReturn(false); |
718b3632 LOK |
263 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
264 | { | |
265 | CCECBusDevice *device = GetDevice(command.destination); | |
266 | if (device && device->GetPowerStatus(false) != CEC_POWER_STATUS_ON) | |
2abe628c LOK |
267 | { |
268 | bReturn = device->TransmitPowerState(command.initiator); | |
269 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
270 | } | |
2abe628c LOK |
271 | else |
272 | { | |
3faa971c LOK |
273 | if (!m_bActiveSourceSent) |
274 | { | |
275 | device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); | |
276 | bReturn = device->TransmitPowerState(command.initiator); | |
277 | ActivateSource(); | |
278 | } | |
279 | else if (m_resetPowerState.IsSet() && m_resetPowerState.TimeLeft() > 0) | |
280 | { | |
281 | /* assume that we've bugged out */ | |
282 | CLibCEC::AddLog(CEC_LOG_NOTICE, "LG seems to have bugged out. resetting to 'in transition standby to on'"); | |
283 | m_bActiveSourceSent = false; | |
284 | device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); | |
285 | bReturn = device->TransmitPowerState(command.initiator); | |
286 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
287 | m_resetPowerState.Init(5000); | |
288 | } | |
289 | else | |
290 | { | |
291 | bReturn = device->TransmitPowerState(command.initiator); | |
292 | m_resetPowerState.Init(5000); | |
293 | } | |
b818fb5a | 294 | } |
718b3632 LOK |
295 | } |
296 | ||
2abe628c LOK |
297 | return bReturn; |
298 | } | |
299 | ||
300 | bool CSLCommandHandler::HandleRequestActiveSource(const cec_command &command) | |
301 | { | |
302 | if (m_processor->IsRunning()) | |
303 | { | |
304 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i requests active source, ignored", (uint8_t) command.initiator); | |
305 | return true; | |
306 | } | |
718b3632 LOK |
307 | return false; |
308 | } | |
5c3b1f92 LOK |
309 | |
310 | bool CSLCommandHandler::HandleFeatureAbort(const cec_command &command) | |
311 | { | |
312 | if (command.parameters.size == 0 && m_processor->GetPrimaryDevice()->GetPowerStatus() == CEC_POWER_STATUS_ON && !m_bSLEnabled) | |
313 | { | |
314 | m_processor->GetPrimaryDevice()->TransmitPowerState(command.initiator); | |
315 | m_processor->GetPrimaryDevice()->TransmitVendorID(CECDEVICE_BROADCAST, false); | |
316 | } | |
317 | ||
318 | return CCECCommandHandler::HandleFeatureAbort(command); | |
319 | } | |
320 | ||
321 | bool CSLCommandHandler::HandleStandby(const cec_command &command) | |
322 | { | |
323 | if (command.initiator == CECDEVICE_TV) | |
324 | { | |
325 | m_bSLEnabled = false; | |
326 | m_bPowerStateReset = false; | |
327 | m_bActiveSourceSent = false; | |
328 | } | |
329 | ||
330 | CCECBusDevice *device = GetDevice(command.initiator); | |
331 | if (device) | |
332 | device->SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
333 | ||
334 | return true; | |
335 | } |