Commit | Line | Data |
---|---|---|
bb5b4874 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. |
bb5b4874 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 "VLCommandHandler.h" | |
34 | #include "../devices/CECBusDevice.h" | |
aa4c0d34 LOK |
35 | #include "../devices/CECPlaybackDevice.h" |
36 | #include "../devices/CECTV.h" | |
3e61b350 | 37 | #include "../CECProcessor.h" |
b78b4e33 | 38 | #include "../LibCEC.h" |
004b8382 | 39 | #include "../CECClient.h" |
b78b4e33 LOK |
40 | |
41 | #define VL_POWER_CHANGE 0x20 | |
42 | #define VL_POWERED_UP 0x00 | |
43 | #define VL_POWERED_DOWN 0x01 | |
9ee5e8fd | 44 | #define VL_UNKNOWN1 0x06 |
bb5b4874 LOK |
45 | |
46 | using namespace CEC; | |
b78b4e33 | 47 | using namespace PLATFORM; |
bb5b4874 | 48 | |
004b8382 LOK |
49 | #define LIB_CEC m_busDevice->GetProcessor()->GetLib() |
50 | #define ToString(p) LIB_CEC->ToString(p) | |
51 | ||
aa4c0d34 LOK |
52 | // wait this amount of ms before trying to switch sources after receiving the message from the TV that it's powered on |
53 | #define SOURCE_SWITCH_DELAY_MS 1000 | |
54 | ||
bb5b4874 | 55 | CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) : |
b78b4e33 | 56 | CCECCommandHandler(busDevice), |
aa4c0d34 | 57 | m_iPowerUpEventReceived(0) |
bb5b4874 | 58 | { |
cf4931be | 59 | m_vendorId = CEC_VENDOR_PANASONIC; |
bb5b4874 | 60 | } |
3e61b350 LOK |
61 | |
62 | bool CVLCommandHandler::InitHandler(void) | |
63 | { | |
64 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); | |
42d28d15 LOK |
65 | if (primary && primary->GetLogicalAddress() != CECDEVICE_UNREGISTERED) |
66 | { | |
67 | /* use the VL commandhandler for the primary device that is handled by libCEC */ | |
68 | if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV) | |
69 | { | |
70 | if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) | |
71 | { | |
72 | primary->SetVendorId(CEC_VENDOR_PANASONIC); | |
73 | primary->ReplaceHandler(false); | |
74 | } | |
75 | } | |
76 | ||
77 | if (primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) | |
78 | return m_processor->GetPrimaryClient()->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE); | |
aa4c0d34 LOK |
79 | |
80 | m_processor->GetTV()->RequestPowerStatus(primary->GetLogicalAddress(), false); | |
42d28d15 | 81 | } |
b78b4e33 | 82 | |
3e61b350 LOK |
83 | return CCECCommandHandler::InitHandler(); |
84 | } | |
b78b4e33 | 85 | |
9a54dc82 | 86 | int CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) |
b78b4e33 | 87 | { |
344cddb9 LOK |
88 | if (command.parameters[0] != 0x00 || |
89 | command.parameters[1] != 0x80 || | |
90 | command.parameters[2] != 0x45) | |
91 | return CEC_ABORT_REASON_INVALID_OPERAND; | |
92 | ||
b78b4e33 | 93 | if (command.initiator == CECDEVICE_TV && |
9ee5e8fd LOK |
94 | command.parameters.At(3) == VL_UNKNOWN1) |
95 | { | |
96 | // set the power up event time | |
97 | { | |
98 | CLockObject lock(m_mutex); | |
99 | if (m_iPowerUpEventReceived == 0) | |
100 | m_iPowerUpEventReceived = GetTimeMs(); | |
101 | } | |
102 | // mark the TV as powered on | |
103 | m_processor->GetTV()->SetPowerStatus(CEC_POWER_STATUS_ON); | |
104 | } | |
105 | else if (command.initiator == CECDEVICE_TV && | |
b78b4e33 LOK |
106 | command.destination == CECDEVICE_BROADCAST && |
107 | command.parameters.At(3) == VL_POWER_CHANGE) | |
108 | { | |
109 | if (command.parameters.At(4) == VL_POWERED_UP) | |
110 | { | |
aa4c0d34 | 111 | // set the power up event time |
b78b4e33 LOK |
112 | { |
113 | CLockObject lock(m_mutex); | |
aa4c0d34 LOK |
114 | if (m_iPowerUpEventReceived == 0) |
115 | m_iPowerUpEventReceived = GetTimeMs(); | |
b78b4e33 | 116 | } |
aa4c0d34 LOK |
117 | // mark the TV as powered on |
118 | m_processor->GetTV()->SetPowerStatus(CEC_POWER_STATUS_ON); | |
b78b4e33 LOK |
119 | } |
120 | else if (command.parameters.At(4) == VL_POWERED_DOWN) | |
aa4c0d34 LOK |
121 | { |
122 | // reset the power up event time | |
123 | { | |
124 | CLockObject lock(m_mutex); | |
125 | m_iPowerUpEventReceived = 0; | |
126 | } | |
127 | // mark the TV as powered off | |
128 | m_processor->GetTV()->SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
129 | } | |
130 | else | |
131 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "skipping unknown vendor command"); | |
b78b4e33 | 132 | |
9a54dc82 | 133 | return COMMAND_HANDLED; |
b78b4e33 LOK |
134 | } |
135 | ||
136 | return CCECCommandHandler::HandleDeviceVendorCommandWithId(command); | |
137 | } | |
138 | ||
aa4c0d34 | 139 | bool CVLCommandHandler::PowerUpEventReceived(void) |
b78b4e33 | 140 | { |
aa4c0d34 | 141 | bool bPowerUpEventReceived(true); |
b78b4e33 | 142 | |
aa4c0d34 | 143 | if (m_busDevice->GetLogicalAddress() != CECDEVICE_TV) |
b78b4e33 | 144 | { |
aa4c0d34 LOK |
145 | // get the status from the TV |
146 | CCECBusDevice *tv = m_processor->GetTV(); | |
147 | if (tv && tv->GetCurrentVendorId() == CEC_VENDOR_PANASONIC) | |
148 | { | |
149 | CVLCommandHandler *handler = static_cast<CVLCommandHandler *>(tv->GetHandler()); | |
150 | bPowerUpEventReceived = handler ? handler->PowerUpEventReceived() : false; | |
151 | tv->MarkHandlerReady(); | |
152 | } | |
b78b4e33 LOK |
153 | } |
154 | else | |
155 | { | |
aa4c0d34 LOK |
156 | // get the current status |
157 | { | |
158 | CLockObject lock(m_mutex); | |
159 | bPowerUpEventReceived = m_iPowerUpEventReceived > 0 && | |
160 | GetTimeMs() - m_iPowerUpEventReceived > SOURCE_SWITCH_DELAY_MS; | |
161 | } | |
b47f66af | 162 | |
aa4c0d34 LOK |
163 | // if we didn't receive the event, check if the TV is already marked as powered on |
164 | if (!bPowerUpEventReceived && m_busDevice->GetCurrentPowerStatus() == CEC_POWER_STATUS_ON) | |
165 | { | |
166 | CLockObject lock(m_mutex); | |
167 | m_iPowerUpEventReceived = GetTimeMs(); | |
168 | bPowerUpEventReceived = true; | |
169 | } | |
b47f66af LOK |
170 | } |
171 | ||
aa4c0d34 | 172 | return bPowerUpEventReceived; |
b47f66af | 173 | } |
344cddb9 | 174 | |
f8a669d0 LOK |
175 | int CVLCommandHandler::HandleStandby(const cec_command &command) |
176 | { | |
aa4c0d34 | 177 | // reset the power up event time |
f8a669d0 LOK |
178 | { |
179 | CLockObject lock(m_mutex); | |
aa4c0d34 | 180 | m_iPowerUpEventReceived = 0; |
f8a669d0 LOK |
181 | } |
182 | ||
183 | return CCECCommandHandler::HandleStandby(command); | |
184 | } | |
185 | ||
344cddb9 LOK |
186 | int CVLCommandHandler::HandleVendorCommand(const cec_command &command) |
187 | { | |
188 | // some vendor command voodoo that will enable more buttons on the remote | |
189 | if (command.parameters.size == 3 && | |
190 | command.parameters[0] == 0x10 && | |
191 | command.parameters[1] == 0x01 && | |
192 | command.parameters[2] == 0x05) | |
193 | { | |
194 | cec_command response; | |
195 | cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND); | |
196 | uint8_t iResponseData[] = {0x10, 0x02, 0xFF, 0xFF, 0x00, 0x05, 0x05, 0x45, 0x55, 0x5c, 0x58, 0x32}; | |
197 | response.PushArray(12, iResponseData); | |
198 | ||
199 | Transmit(response, true); | |
200 | ||
201 | return COMMAND_HANDLED; | |
202 | } | |
203 | ||
204 | return CEC_ABORT_REASON_INVALID_OPERAND; | |
205 | } | |
206 | ||
aa4c0d34 LOK |
207 | bool CVLCommandHandler::SourceSwitchAllowed(void) |
208 | { | |
209 | return PowerUpEventReceived(); | |
210 | } | |
9ee5e8fd LOK |
211 | |
212 | int CVLCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) | |
213 | { | |
214 | if (command.initiator == CECDEVICE_TV) | |
215 | { | |
216 | // set the power up event time | |
217 | { | |
218 | CLockObject lock(m_mutex); | |
219 | if (m_iPowerUpEventReceived == 0) | |
220 | m_iPowerUpEventReceived = GetTimeMs(); | |
221 | } | |
222 | // mark the TV as powered on | |
223 | m_processor->GetTV()->SetPowerStatus(CEC_POWER_STATUS_ON); | |
224 | } | |
225 | ||
226 | return CCECCommandHandler::HandleSystemAudioModeRequest(command); | |
227 | } |