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 | { | |
b818fb5a LOK |
91 | if (m_bActiveSourceSent) |
92 | return false; | |
93 | m_bActiveSourceSent = true; | |
94 | ||
3e61b350 LOK |
95 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); |
96 | primary->SetActiveSource(); | |
97 | primary->TransmitActiveSource(); | |
98 | return true; | |
99 | } | |
100 | ||
468a1414 LOK |
101 | bool CSLCommandHandler::HandleActiveSource(const cec_command &command) |
102 | { | |
103 | if (command.parameters.size == 2) | |
104 | { | |
105 | uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
106 | if (iAddress != m_busDevice->GetPhysicalAddress(false)) | |
107 | m_bSLEnabled = false; | |
108 | return m_processor->SetActiveSource(iAddress); | |
109 | } | |
110 | ||
111 | return true; | |
112 | } | |
113 | ||
a463f954 LOK |
114 | bool CSLCommandHandler::HandleDeviceVendorId(const cec_command &command) |
115 | { | |
116 | SetVendorId(command); | |
117 | ||
2abe628c | 118 | if (!m_bSLEnabled) |
468a1414 | 119 | { |
2abe628c LOK |
120 | cec_command response; |
121 | cec_command::Format(response, m_processor->GetLogicalAddress(), command.initiator, CEC_OPCODE_FEATURE_ABORT); | |
122 | return Transmit(response); | |
468a1414 | 123 | } |
2abe628c | 124 | return true; |
468a1414 LOK |
125 | } |
126 | ||
127 | bool CSLCommandHandler::HandleGivePhysicalAddress(const cec_command &command) | |
128 | { | |
8e57f83c | 129 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
468a1414 LOK |
130 | { |
131 | CCECBusDevice *device = GetDevice(command.destination); | |
132 | if (device) | |
b818fb5a | 133 | return device->TransmitPhysicalAddress(); // only the physical address, don't send image view on |
468a1414 LOK |
134 | } |
135 | ||
136 | return false; | |
e9de9629 | 137 | } |
e54fd7d2 LOK |
138 | |
139 | bool CSLCommandHandler::HandleVendorCommand(const cec_command &command) | |
140 | { | |
141 | if (command.parameters.size == 1 && | |
11d13a02 | 142 | command.parameters[0] == SL_COMMAND_UNKNOWN_01) |
e54fd7d2 | 143 | { |
5f316715 | 144 | HandleVendorCommand01(command); |
8d915412 | 145 | return true; |
e54fd7d2 | 146 | } |
9a0d7b9f LOK |
147 | else if (command.parameters.size == 2 && |
148 | command.parameters[0] == SL_COMMAND_POWER_ON) | |
149 | { | |
0ecbcd4d | 150 | HandleVendorCommandPowerOn(command); |
9a0d7b9f LOK |
151 | return true; |
152 | } | |
797dd7c4 | 153 | else if (command.parameters.size == 2 && |
11d13a02 | 154 | command.parameters[0] == SL_COMMAND_CONNECT_REQUEST) |
9902f4e8 | 155 | { |
0ecbcd4d | 156 | HandleVendorCommandSLConnect(command); |
8d915412 | 157 | return true; |
9902f4e8 LOK |
158 | } |
159 | else if (command.parameters.size == 1 && | |
0d4c3a7b | 160 | command.parameters[0] == SL_COMMAND_REQUEST_POWER_STATUS) |
9902f4e8 | 161 | { |
0ecbcd4d | 162 | HandleVendorCommandPowerOnStatus(command); |
8d915412 | 163 | return true; |
9902f4e8 | 164 | } |
e54fd7d2 LOK |
165 | |
166 | return false; | |
167 | } | |
168 | ||
5f316715 | 169 | void CSLCommandHandler::HandleVendorCommand01(const cec_command &command) |
fe6f8e37 | 170 | { |
b818fb5a | 171 | m_processor->GetPrimaryDevice()->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); |
fe6f8e37 LOK |
172 | TransmitVendorCommand0205(command.destination, command.initiator); |
173 | } | |
174 | ||
175 | void CSLCommandHandler::TransmitVendorCommand0205(const cec_logical_address iSource, const cec_logical_address iDestination) | |
5f316715 LOK |
176 | { |
177 | cec_command response; | |
fe6f8e37 | 178 | cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND); |
5f316715 LOK |
179 | response.PushBack(SL_COMMAND_UNKNOWN_02); |
180 | response.PushBack(SL_COMMAND_UNKNOWN_03); | |
181 | ||
19cbfa8f | 182 | Transmit(response, false); |
fe6f8e37 | 183 | } |
5f316715 | 184 | |
0ecbcd4d | 185 | void CSLCommandHandler::HandleVendorCommandPowerOn(const cec_command &command) |
9a0d7b9f | 186 | { |
842262d8 | 187 | CCECBusDevice *device = m_processor->GetPrimaryDevice(); |
9a0d7b9f LOK |
188 | if (device) |
189 | { | |
fe6f8e37 | 190 | m_bSLEnabled = true; |
468a1414 LOK |
191 | |
192 | device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); //XXX | |
9a0d7b9f | 193 | device->TransmitPowerState(command.initiator); |
468a1414 | 194 | device->SetPowerStatus(CEC_POWER_STATUS_ON); |
9a0d7b9f | 195 | |
468a1414 LOK |
196 | device->SetActiveSource(); |
197 | TransmitImageViewOn(device->GetLogicalAddress(), command.initiator); | |
198 | } | |
5f316715 | 199 | } |
0ecbcd4d | 200 | void CSLCommandHandler::HandleVendorCommandPowerOnStatus(const cec_command &command) |
5f316715 LOK |
201 | { |
202 | if (command.destination != CECDEVICE_BROADCAST) | |
203 | { | |
204 | CCECBusDevice *device = m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary]; | |
205 | device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); | |
206 | device->TransmitPowerState(command.initiator); | |
207 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
208 | } | |
209 | } | |
210 | ||
468a1414 | 211 | void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command &command) |
8d915412 | 212 | { |
468a1414 | 213 | m_bSLEnabled = true; |
5abb18f3 | 214 | TransmitVendorCommandSetDeviceMode(m_processor->GetLogicalAddress(), command.initiator, CEC_DEVICE_TYPE_RECORDING_DEVICE); |
37acf382 | 215 | |
2abe628c | 216 | ActivateSource(); |
8d915412 | 217 | } |
0d4c3a7b | 218 | |
5abb18f3 | 219 | void CSLCommandHandler::TransmitVendorCommandSetDeviceMode(const cec_logical_address iSource, const cec_logical_address iDestination, const cec_device_type type) |
0d4c3a7b | 220 | { |
468a1414 LOK |
221 | cec_command response; |
222 | cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND); | |
5abb18f3 LOK |
223 | response.PushBack(SL_COMMAND_SET_DEVICE_MODE); |
224 | response.PushBack((uint8_t)type); | |
468a1414 | 225 | Transmit(response, false); |
0d4c3a7b | 226 | } |
fe6f8e37 | 227 | |
b818fb5a | 228 | bool CSLCommandHandler::HandleGiveDeckStatus(const cec_command &command) |
9f65e017 | 229 | { |
b818fb5a LOK |
230 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
231 | { | |
232 | CCECBusDevice *device = GetDevice(command.destination); | |
233 | if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) | |
234 | { | |
235 | if (command.parameters.size > 0) | |
236 | { | |
b818fb5a LOK |
237 | if (command.parameters[0] == CEC_STATUS_REQUEST_ON) |
238 | { | |
2abe628c | 239 | ((CCECPlaybackDevice *) device)->SetDeckStatus(CEC_DECK_INFO_STOP); |
b818fb5a LOK |
240 | return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator) && |
241 | device->TransmitImageViewOn() && | |
242 | device->TransmitPhysicalAddress(); | |
243 | } | |
244 | else if (command.parameters[0] == CEC_STATUS_REQUEST_ONCE) | |
245 | { | |
2abe628c | 246 | ((CCECPlaybackDevice *) device)->SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); |
b818fb5a LOK |
247 | return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator); |
248 | } | |
249 | } | |
250 | } | |
251 | return CCECCommandHandler::HandleGiveDeckStatus(command); | |
252 | } | |
9f65e017 | 253 | |
b818fb5a | 254 | return false; |
9f65e017 | 255 | } |
718b3632 | 256 | |
718b3632 LOK |
257 | bool CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) |
258 | { | |
2abe628c | 259 | bool bReturn(false); |
718b3632 LOK |
260 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
261 | { | |
262 | CCECBusDevice *device = GetDevice(command.destination); | |
263 | if (device && device->GetPowerStatus(false) != CEC_POWER_STATUS_ON) | |
2abe628c LOK |
264 | { |
265 | bReturn = device->TransmitPowerState(command.initiator); | |
266 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
267 | } | |
b818fb5a LOK |
268 | else if (!ActivateSource()) |
269 | { | |
2abe628c LOK |
270 | /* assume that we've bugged out */ |
271 | CLibCEC::AddLog(CEC_LOG_NOTICE, "LG seems to have bugged out. resetting to 'in transition standby to on'"); | |
272 | m_bActiveSourceSent = false; | |
b818fb5a | 273 | device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); |
2abe628c LOK |
274 | bReturn = device->TransmitPowerState(command.initiator); |
275 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
276 | } | |
277 | else | |
278 | { | |
279 | bReturn = true; | |
b818fb5a | 280 | } |
718b3632 LOK |
281 | } |
282 | ||
2abe628c LOK |
283 | return bReturn; |
284 | } | |
285 | ||
286 | bool CSLCommandHandler::HandleRequestActiveSource(const cec_command &command) | |
287 | { | |
288 | if (m_processor->IsRunning()) | |
289 | { | |
290 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i requests active source, ignored", (uint8_t) command.initiator); | |
291 | return true; | |
292 | } | |
718b3632 LOK |
293 | return false; |
294 | } | |
5c3b1f92 LOK |
295 | |
296 | bool CSLCommandHandler::HandleFeatureAbort(const cec_command &command) | |
297 | { | |
298 | if (command.parameters.size == 0 && m_processor->GetPrimaryDevice()->GetPowerStatus() == CEC_POWER_STATUS_ON && !m_bSLEnabled) | |
299 | { | |
300 | m_processor->GetPrimaryDevice()->TransmitPowerState(command.initiator); | |
301 | m_processor->GetPrimaryDevice()->TransmitVendorID(CECDEVICE_BROADCAST, false); | |
302 | } | |
303 | ||
304 | return CCECCommandHandler::HandleFeatureAbort(command); | |
305 | } | |
306 | ||
307 | bool CSLCommandHandler::HandleStandby(const cec_command &command) | |
308 | { | |
309 | if (command.initiator == CECDEVICE_TV) | |
310 | { | |
311 | m_bSLEnabled = false; | |
312 | m_bPowerStateReset = false; | |
313 | m_bActiveSourceSent = false; | |
314 | } | |
315 | ||
316 | CCECBusDevice *device = GetDevice(command.initiator); | |
317 | if (device) | |
318 | device->SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
319 | ||
320 | return true; | |
321 | } |