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" |
e9de9629 LOK |
37 | |
38 | using namespace CEC; | |
39 | ||
0d4c3a7b LOK |
40 | #define SL_COMMAND_UNKNOWN_01 0x01 |
41 | #define SL_COMMAND_UNKNOWN_02 0x02 | |
42 | #define SL_COMMAND_UNKNOWN_03 0x05 | |
11d13a02 | 43 | |
0d4c3a7b | 44 | #define SL_COMMAND_REQUEST_POWER_STATUS 0xa0 |
9a0d7b9f | 45 | #define SL_COMMAND_POWER_ON 0x03 |
0d4c3a7b LOK |
46 | #define SL_COMMAND_CONNECT_REQUEST 0x04 |
47 | #define SL_COMMAND_CONNECT_ACCEPT 0x05 | |
11d13a02 | 48 | |
e9de9629 | 49 | CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) : |
855a3a98 | 50 | CCECCommandHandler(busDevice), |
b4c4ef7d | 51 | m_bSLEnabled(false), |
468a1414 | 52 | m_bPowerStateReset(false) |
e9de9629 | 53 | { |
cf4931be | 54 | m_vendorId = CEC_VENDOR_LG; |
79f01d26 LOK |
55 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); |
56 | ||
57 | /* imitate LG devices */ | |
ef583662 | 58 | if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) |
3e61b350 | 59 | primary->SetVendorId(CEC_VENDOR_LG); |
50e27928 | 60 | SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); |
79f01d26 LOK |
61 | |
62 | /* LG TVs don't always reply to CEC version requests, so just set it to 1.3a */ | |
63 | if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV) | |
64 | m_busDevice->SetCecVersion(CEC_VERSION_1_3A); | |
65 | ||
66 | /* LG devices always return "korean" as language */ | |
67 | cec_menu_language lang; | |
68 | lang.device = m_busDevice->GetLogicalAddress(); | |
69 | snprintf(lang.language, 4, "eng"); | |
70 | m_busDevice->SetMenuLanguage(lang); | |
9f65e017 LOK |
71 | } |
72 | ||
468a1414 LOK |
73 | bool CSLCommandHandler::InitHandler(void) |
74 | { | |
75 | if (m_bHandlerInited) | |
76 | return true; | |
77 | m_bHandlerInited = true; | |
78 | ||
79 | /* reply with LGs vendor id */ | |
80 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); | |
81 | if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) | |
82 | primary->TransmitVendorID(CECDEVICE_TV, false); | |
83 | ||
a463f954 | 84 | primary->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); |
468a1414 LOK |
85 | return true; |
86 | } | |
87 | ||
3e61b350 LOK |
88 | bool CSLCommandHandler::ActivateSource(void) |
89 | { | |
90 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); | |
91 | primary->SetActiveSource(); | |
49c8f2e4 | 92 | primary->TransmitImageViewOn(); |
3e61b350 LOK |
93 | primary->TransmitActiveSource(); |
94 | return true; | |
95 | } | |
96 | ||
468a1414 LOK |
97 | bool CSLCommandHandler::HandleActiveSource(const cec_command &command) |
98 | { | |
99 | if (command.parameters.size == 2) | |
100 | { | |
101 | uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
102 | if (iAddress != m_busDevice->GetPhysicalAddress(false)) | |
103 | m_bSLEnabled = false; | |
104 | return m_processor->SetActiveSource(iAddress); | |
105 | } | |
106 | ||
107 | return true; | |
108 | } | |
109 | ||
a463f954 LOK |
110 | bool CSLCommandHandler::HandleDeviceVendorId(const cec_command &command) |
111 | { | |
112 | SetVendorId(command); | |
113 | ||
114 | cec_command response; | |
115 | cec_command::Format(response, m_processor->GetLogicalAddress(), command.initiator, CEC_OPCODE_FEATURE_ABORT); | |
116 | return Transmit(response); | |
117 | } | |
118 | ||
468a1414 LOK |
119 | bool CSLCommandHandler::HandleFeatureAbort(const cec_command &command) |
120 | { | |
121 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); | |
122 | if (primary->GetPowerStatus(false) == CEC_POWER_STATUS_ON && !m_bPowerStateReset && !m_bSLEnabled) | |
123 | { | |
124 | m_bPowerStateReset = true; | |
a463f954 | 125 | primary->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); |
468a1414 LOK |
126 | } |
127 | ||
128 | return CCECCommandHandler::HandleFeatureAbort(command); | |
129 | } | |
130 | ||
131 | bool CSLCommandHandler::HandleGivePhysicalAddress(const cec_command &command) | |
132 | { | |
8e57f83c | 133 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
468a1414 LOK |
134 | { |
135 | CCECBusDevice *device = GetDevice(command.destination); | |
136 | if (device) | |
137 | return device->TransmitPhysicalAddress(); | |
138 | } | |
139 | ||
140 | return false; | |
e9de9629 | 141 | } |
e54fd7d2 LOK |
142 | |
143 | bool CSLCommandHandler::HandleVendorCommand(const cec_command &command) | |
144 | { | |
145 | if (command.parameters.size == 1 && | |
11d13a02 | 146 | command.parameters[0] == SL_COMMAND_UNKNOWN_01) |
e54fd7d2 | 147 | { |
5f316715 | 148 | HandleVendorCommand01(command); |
8d915412 | 149 | return true; |
e54fd7d2 | 150 | } |
9a0d7b9f LOK |
151 | else if (command.parameters.size == 2 && |
152 | command.parameters[0] == SL_COMMAND_POWER_ON) | |
153 | { | |
0ecbcd4d | 154 | HandleVendorCommandPowerOn(command); |
9a0d7b9f LOK |
155 | return true; |
156 | } | |
797dd7c4 | 157 | else if (command.parameters.size == 2 && |
11d13a02 | 158 | command.parameters[0] == SL_COMMAND_CONNECT_REQUEST) |
9902f4e8 | 159 | { |
0ecbcd4d | 160 | HandleVendorCommandSLConnect(command); |
8d915412 | 161 | return true; |
9902f4e8 LOK |
162 | } |
163 | else if (command.parameters.size == 1 && | |
0d4c3a7b | 164 | command.parameters[0] == SL_COMMAND_REQUEST_POWER_STATUS) |
9902f4e8 | 165 | { |
0ecbcd4d | 166 | HandleVendorCommandPowerOnStatus(command); |
8d915412 | 167 | return true; |
9902f4e8 | 168 | } |
e54fd7d2 LOK |
169 | |
170 | return false; | |
171 | } | |
172 | ||
5f316715 | 173 | void CSLCommandHandler::HandleVendorCommand01(const cec_command &command) |
fe6f8e37 LOK |
174 | { |
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 | |
50e27928 | 199 | SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); |
468a1414 LOK |
200 | device->SetActiveSource(); |
201 | TransmitImageViewOn(device->GetLogicalAddress(), command.initiator); | |
202 | } | |
5f316715 | 203 | } |
0ecbcd4d | 204 | void CSLCommandHandler::HandleVendorCommandPowerOnStatus(const cec_command &command) |
5f316715 LOK |
205 | { |
206 | if (command.destination != CECDEVICE_BROADCAST) | |
207 | { | |
208 | CCECBusDevice *device = m_processor->m_busDevices[m_processor->GetLogicalAddresses().primary]; | |
209 | device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); | |
210 | device->TransmitPowerState(command.initiator); | |
211 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
212 | } | |
213 | } | |
214 | ||
468a1414 | 215 | void CSLCommandHandler::HandleVendorCommandSLConnect(const cec_command &command) |
8d915412 | 216 | { |
468a1414 | 217 | m_bSLEnabled = true; |
79f01d26 | 218 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); |
37acf382 | 219 | |
468a1414 | 220 | TransmitVendorCommand05(primary->GetLogicalAddress(), command.initiator); |
50e27928 LOK |
221 | |
222 | CCECPlaybackDevice *playback = (primary->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) ? | |
223 | (CCECPlaybackDevice *)primary : NULL; | |
224 | if (playback) | |
225 | { | |
226 | SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS); | |
227 | playback->TransmitDeckStatus(CECDEVICE_TV); | |
228 | PLATFORM::CEvent::Sleep(2000); | |
229 | } | |
230 | ||
231 | primary->SetActiveSource(); | |
232 | primary->TransmitImageViewOn(); | |
233 | ||
234 | SetDeckStatus(CEC_DECK_INFO_OTHER_STATUS_LG); | |
235 | if (playback) | |
236 | playback->TransmitDeckStatus(CECDEVICE_TV); | |
8d915412 | 237 | } |
0d4c3a7b | 238 | |
468a1414 | 239 | void CSLCommandHandler::TransmitVendorCommand05(const cec_logical_address iSource, const cec_logical_address iDestination) |
0d4c3a7b | 240 | { |
468a1414 LOK |
241 | cec_command response; |
242 | cec_command::Format(response, iSource, iDestination, CEC_OPCODE_VENDOR_COMMAND); | |
243 | response.PushBack(SL_COMMAND_CONNECT_ACCEPT); | |
199034ab | 244 | response.PushBack((uint8_t)m_processor->m_busDevices[iSource]->GetType()); |
468a1414 | 245 | Transmit(response, false); |
0d4c3a7b | 246 | } |
fe6f8e37 | 247 | |
50e27928 | 248 | void CSLCommandHandler::SetDeckStatus(cec_deck_info deckStatus) |
9f65e017 | 249 | { |
468a1414 LOK |
250 | CCECBusDevice *device = m_processor->GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); |
251 | if (device) | |
50e27928 | 252 | ((CCECPlaybackDevice *)device)->SetDeckStatus(deckStatus); |
9f65e017 | 253 | |
468a1414 LOK |
254 | device = m_processor->GetDeviceByType(CEC_DEVICE_TYPE_RECORDING_DEVICE); |
255 | if (device) | |
50e27928 | 256 | ((CCECPlaybackDevice *)device)->SetDeckStatus(deckStatus); |
9f65e017 | 257 | } |