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 "CECCommandHandler.h" | |
eafa9d46 | 34 | #include "../devices/CECBusDevice.h" |
a1f8fb1b | 35 | #include "../devices/CECAudioSystem.h" |
28089abc | 36 | #include "../devices/CECPlaybackDevice.h" |
387b6f6f | 37 | #include "../CECProcessor.h" |
5477a250 | 38 | #include "../LibCEC.h" |
e9de9629 LOK |
39 | |
40 | using namespace CEC; | |
8747dd4f | 41 | using namespace std; |
f00ff009 | 42 | using namespace PLATFORM; |
e9de9629 | 43 | |
8fa35473 LOK |
44 | CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) : |
45 | m_busDevice(busDevice), | |
46 | m_processor(m_busDevice->GetProcessor()), | |
ae693aaa LOK |
47 | m_iTransmitTimeout(CEC_DEFAULT_TRANSMIT_TIMEOUT), |
48 | m_iTransmitWait(CEC_DEFAULT_TRANSMIT_WAIT), | |
89a726fa | 49 | m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES), |
b64db02e | 50 | m_bHandlerInited(false), |
7b74fdfb | 51 | m_expectedResponse(CEC_OPCODE_NONE), |
d79b67d8 | 52 | m_bOPTSendDeckStatusUpdateOnActiveSource(false), |
960f33c6 LOK |
53 | m_vendorId(CEC_VENDOR_UNKNOWN), |
54 | m_bRcvSignal(false) | |
e9de9629 | 55 | { |
8fa35473 LOK |
56 | } |
57 | ||
58 | CCECCommandHandler::~CCECCommandHandler(void) | |
59 | { | |
60 | m_condition.Broadcast(); | |
e9de9629 LOK |
61 | } |
62 | ||
63 | bool CCECCommandHandler::HandleCommand(const cec_command &command) | |
64 | { | |
3e61b350 | 65 | bool bHandled(true); |
e9de9629 | 66 | |
02e7043e | 67 | CLibCEC::AddCommand(command); |
855a3a98 | 68 | |
6b72afcd | 69 | switch(command.opcode) |
e9de9629 | 70 | { |
6b72afcd LOK |
71 | case CEC_OPCODE_REPORT_POWER_STATUS: |
72 | HandleReportPowerStatus(command); | |
73 | break; | |
74 | case CEC_OPCODE_CEC_VERSION: | |
75 | HandleDeviceCecVersion(command); | |
76 | break; | |
77 | case CEC_OPCODE_SET_MENU_LANGUAGE: | |
78 | HandleSetMenuLanguage(command); | |
79 | break; | |
80 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
3e61b350 LOK |
81 | if (m_processor->IsInitialised()) |
82 | HandleGivePhysicalAddress(command); | |
6b72afcd LOK |
83 | break; |
84 | case CEC_OPCODE_GIVE_OSD_NAME: | |
3e61b350 LOK |
85 | if (m_processor->IsInitialised()) |
86 | HandleGiveOSDName(command); | |
6b72afcd LOK |
87 | break; |
88 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
3e61b350 LOK |
89 | if (m_processor->IsInitialised()) |
90 | HandleGiveDeviceVendorId(command); | |
6b72afcd LOK |
91 | break; |
92 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
3e61b350 | 93 | HandleDeviceVendorId(command); |
6b72afcd LOK |
94 | break; |
95 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
96 | HandleDeviceVendorCommandWithId(command); | |
97 | break; | |
98 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
3e61b350 LOK |
99 | if (m_processor->IsInitialised()) |
100 | HandleGiveDeckStatus(command); | |
6b72afcd LOK |
101 | break; |
102 | case CEC_OPCODE_DECK_CONTROL: | |
103 | HandleDeckControl(command); | |
104 | break; | |
105 | case CEC_OPCODE_MENU_REQUEST: | |
3e61b350 LOK |
106 | if (m_processor->IsInitialised()) |
107 | HandleMenuRequest(command); | |
6b72afcd LOK |
108 | break; |
109 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
3e61b350 LOK |
110 | if (m_processor->IsInitialised()) |
111 | HandleGiveDevicePowerStatus(command); | |
6b72afcd LOK |
112 | break; |
113 | case CEC_OPCODE_GET_CEC_VERSION: | |
3e61b350 LOK |
114 | if (m_processor->IsInitialised()) |
115 | HandleGetCecVersion(command); | |
6b72afcd LOK |
116 | break; |
117 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
3e61b350 LOK |
118 | if (m_processor->IsInitialised()) |
119 | HandleUserControlPressed(command); | |
6b72afcd LOK |
120 | break; |
121 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
3e61b350 LOK |
122 | if (m_processor->IsInitialised()) |
123 | HandleUserControlRelease(command); | |
6b72afcd LOK |
124 | break; |
125 | case CEC_OPCODE_GIVE_AUDIO_STATUS: | |
3e61b350 LOK |
126 | if (m_processor->IsInitialised()) |
127 | HandleGiveAudioStatus(command); | |
6b72afcd LOK |
128 | break; |
129 | case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: | |
3e61b350 LOK |
130 | if (m_processor->IsInitialised()) |
131 | HandleGiveSystemAudioModeStatus(command); | |
6b72afcd LOK |
132 | break; |
133 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: | |
3e61b350 LOK |
134 | if (m_processor->IsInitialised()) |
135 | HandleSystemAudioModeRequest(command); | |
aa517a0d LOK |
136 | break; |
137 | case CEC_OPCODE_REPORT_AUDIO_STATUS: | |
855a3a98 | 138 | HandleReportAudioStatus(command); |
aa517a0d LOK |
139 | break; |
140 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: | |
855a3a98 | 141 | HandleSystemAudioModeStatus(command); |
aa517a0d LOK |
142 | break; |
143 | case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: | |
855a3a98 | 144 | HandleSetSystemAudioMode(command); |
6b72afcd LOK |
145 | break; |
146 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
3e61b350 LOK |
147 | if (m_processor->IsInitialised()) |
148 | HandleRequestActiveSource(command); | |
6b72afcd LOK |
149 | break; |
150 | case CEC_OPCODE_SET_STREAM_PATH: | |
151 | HandleSetStreamPath(command); | |
152 | break; | |
153 | case CEC_OPCODE_ROUTING_CHANGE: | |
154 | HandleRoutingChange(command); | |
155 | break; | |
907bd60f LOK |
156 | case CEC_OPCODE_ROUTING_INFORMATION: |
157 | HandleRoutingInformation(command); | |
158 | break; | |
6b72afcd | 159 | case CEC_OPCODE_STANDBY: |
3e61b350 LOK |
160 | if (m_processor->IsInitialised()) |
161 | HandleStandby(command); | |
6b72afcd LOK |
162 | break; |
163 | case CEC_OPCODE_ACTIVE_SOURCE: | |
164 | HandleActiveSource(command); | |
165 | break; | |
907bd60f LOK |
166 | case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: |
167 | HandleReportPhysicalAddress(command); | |
168 | break; | |
15d1a84c LOK |
169 | case CEC_OPCODE_SET_OSD_NAME: |
170 | HandleSetOSDName(command); | |
171 | break; | |
1a6669b8 LOK |
172 | case CEC_OPCODE_IMAGE_VIEW_ON: |
173 | HandleImageViewOn(command); | |
174 | break; | |
175 | case CEC_OPCODE_TEXT_VIEW_ON: | |
176 | HandleTextViewOn(command); | |
177 | break; | |
4d738fe3 LOK |
178 | case CEC_OPCODE_FEATURE_ABORT: |
179 | HandleFeatureAbort(command); | |
180 | break; | |
468a1414 LOK |
181 | case CEC_OPCODE_VENDOR_COMMAND: |
182 | HandleVendorCommand(command); | |
183 | break; | |
6b72afcd LOK |
184 | default: |
185 | UnhandledCommand(command); | |
e9de9629 | 186 | bHandled = false; |
6b72afcd | 187 | break; |
e9de9629 LOK |
188 | } |
189 | ||
3e61b350 | 190 | if (bHandled) |
8fa35473 | 191 | { |
f00ff009 | 192 | CLockObject lock(m_receiveMutex); |
446c0cfc LOK |
193 | if (m_expectedResponse == CEC_OPCODE_NONE || |
194 | m_expectedResponse == command.opcode) | |
960f33c6 LOK |
195 | { |
196 | m_bRcvSignal = true; | |
446c0cfc | 197 | m_condition.Signal(); |
960f33c6 | 198 | } |
8fa35473 LOK |
199 | } |
200 | ||
e9de9629 LOK |
201 | return bHandled; |
202 | } | |
203 | ||
be5b0e24 LOK |
204 | bool CCECCommandHandler::HandleActiveSource(const cec_command &command) |
205 | { | |
206 | if (command.parameters.size == 2) | |
207 | { | |
208 | uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
37b0c572 | 209 | return m_processor->SetActiveSource(iAddress); |
be5b0e24 LOK |
210 | } |
211 | ||
212 | return true; | |
213 | } | |
214 | ||
a9232a79 LOK |
215 | bool CCECCommandHandler::HandleDeckControl(const cec_command &command) |
216 | { | |
217 | CCECBusDevice *device = GetDevice(command.destination); | |
88e5de6f | 218 | if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0) |
a9232a79 LOK |
219 | { |
220 | ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]); | |
221 | return true; | |
222 | } | |
223 | ||
224 | return false; | |
225 | } | |
226 | ||
6a1c0009 LOK |
227 | bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) |
228 | { | |
229 | if (command.parameters.size == 1) | |
230 | { | |
231 | CCECBusDevice *device = GetDevice(command.initiator); | |
232 | if (device) | |
233 | device->SetCecVersion((cec_version) command.parameters[0]); | |
234 | } | |
235 | ||
236 | return true; | |
237 | } | |
238 | ||
e9de9629 LOK |
239 | bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) |
240 | { | |
8e57f83c | 241 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
fcf10e27 | 242 | m_processor->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); |
6b72afcd | 243 | |
6a1c0009 | 244 | return true; |
e9de9629 LOK |
245 | } |
246 | ||
247 | bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) | |
248 | { | |
8fa35473 | 249 | return SetVendorId(command); |
e9de9629 LOK |
250 | } |
251 | ||
4d738fe3 LOK |
252 | bool CCECCommandHandler::HandleFeatureAbort(const cec_command &command) |
253 | { | |
254 | if (command.parameters.size == 2) | |
255 | { | |
256 | m_processor->m_busDevices[command.initiator]->SetUnsupportedFeature((cec_opcode)command.parameters[0]); | |
257 | } | |
7de6ad36 | 258 | return true; |
4d738fe3 LOK |
259 | } |
260 | ||
e9de9629 LOK |
261 | bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) |
262 | { | |
8e57f83c | 263 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
6b72afcd LOK |
264 | { |
265 | CCECBusDevice *device = GetDevice(command.destination); | |
266 | if (device) | |
267 | return device->TransmitCECVersion(command.initiator); | |
268 | } | |
0f23c85c LOK |
269 | |
270 | return false; | |
e9de9629 LOK |
271 | } |
272 | ||
a1f8fb1b LOK |
273 | bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) |
274 | { | |
8e57f83c | 275 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
6b72afcd LOK |
276 | { |
277 | CCECBusDevice *device = GetDevice(command.destination); | |
278 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
279 | return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator); | |
280 | } | |
a1f8fb1b LOK |
281 | |
282 | return false; | |
283 | } | |
284 | ||
e9de9629 LOK |
285 | bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) |
286 | { | |
8e57f83c | 287 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
6b72afcd LOK |
288 | { |
289 | CCECBusDevice *device = GetDevice(command.destination); | |
290 | if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) | |
291 | return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator); | |
292 | } | |
0f23c85c LOK |
293 | |
294 | return false; | |
e9de9629 LOK |
295 | } |
296 | ||
297 | bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) | |
298 | { | |
8e57f83c | 299 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
6b72afcd LOK |
300 | { |
301 | CCECBusDevice *device = GetDevice(command.destination); | |
302 | if (device) | |
303 | return device->TransmitPowerState(command.initiator); | |
304 | } | |
0f23c85c LOK |
305 | |
306 | return false; | |
e9de9629 LOK |
307 | } |
308 | ||
309 | bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) | |
310 | { | |
8e57f83c | 311 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
6b72afcd LOK |
312 | { |
313 | CCECBusDevice *device = GetDevice(command.destination); | |
314 | if (device) | |
315 | return device->TransmitVendorID(command.initiator); | |
316 | } | |
0f23c85c LOK |
317 | |
318 | return false; | |
e9de9629 LOK |
319 | } |
320 | ||
321 | bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) | |
322 | { | |
8e57f83c | 323 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
6b72afcd LOK |
324 | { |
325 | CCECBusDevice *device = GetDevice(command.destination); | |
326 | if (device) | |
327 | return device->TransmitOSDName(command.initiator); | |
328 | } | |
0f23c85c LOK |
329 | |
330 | return false; | |
e9de9629 LOK |
331 | } |
332 | ||
333 | bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) | |
334 | { | |
8e57f83c | 335 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
6b72afcd LOK |
336 | { |
337 | CCECBusDevice *device = GetDevice(command.destination); | |
338 | if (device) | |
3c20db73 LOK |
339 | { |
340 | device->SetActiveSource(); | |
341 | return device->TransmitPhysicalAddress() && | |
49c8f2e4 | 342 | device->TransmitImageViewOn() && |
3c20db73 LOK |
343 | device->TransmitActiveSource(); |
344 | } | |
6b72afcd | 345 | } |
09c10b66 LOK |
346 | |
347 | return false; | |
e9de9629 LOK |
348 | } |
349 | ||
1a6669b8 LOK |
350 | bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) |
351 | { | |
8e57f83c | 352 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
1a6669b8 LOK |
353 | { |
354 | CCECBusDevice *device = GetDevice(command.destination); | |
355 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
356 | return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator); | |
357 | } | |
358 | ||
359 | return false; | |
360 | } | |
361 | ||
362 | bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) | |
363 | { | |
37b0c572 | 364 | m_processor->m_busDevices[command.initiator]->SetActiveSource(); |
1a6669b8 LOK |
365 | return true; |
366 | } | |
367 | ||
e9de9629 LOK |
368 | bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) |
369 | { | |
8e57f83c | 370 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
0f23c85c | 371 | { |
6b72afcd LOK |
372 | if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY) |
373 | { | |
374 | CCECBusDevice *device = GetDevice(command.destination); | |
375 | if (device) | |
376 | return device->TransmitMenuState(command.initiator); | |
377 | } | |
15d1a84c LOK |
378 | } |
379 | ||
380 | return false; | |
381 | } | |
382 | ||
383 | bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command) | |
384 | { | |
385 | if (command.parameters.size == 1) | |
386 | { | |
387 | CCECBusDevice *device = GetDevice(command.initiator); | |
388 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
6b72afcd | 389 | { |
15d1a84c LOK |
390 | ((CCECAudioSystem *)device)->SetAudioStatus(command.parameters[0]); |
391 | return true; | |
6b72afcd | 392 | } |
0f23c85c LOK |
393 | } |
394 | return false; | |
e9de9629 LOK |
395 | } |
396 | ||
907bd60f LOK |
397 | bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command) |
398 | { | |
0bfce006 | 399 | if (command.parameters.size == 3) |
907bd60f LOK |
400 | { |
401 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
16b1e052 | 402 | SetPhysicalAddress(command.initiator, iNewAddress); |
907bd60f LOK |
403 | } |
404 | return true; | |
405 | } | |
406 | ||
e55f3f70 LOK |
407 | bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) |
408 | { | |
409 | if (command.parameters.size == 1) | |
410 | { | |
411 | CCECBusDevice *device = GetDevice(command.initiator); | |
412 | if (device) | |
413 | device->SetPowerStatus((cec_power_status) command.parameters[0]); | |
414 | } | |
415 | return true; | |
416 | } | |
417 | ||
e9de9629 LOK |
418 | bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) |
419 | { | |
8e57f83c | 420 | if (m_processor->IsRunning()) |
5f316715 | 421 | { |
5477a250 | 422 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator); |
8747dd4f | 423 | |
5f316715 | 424 | vector<CCECBusDevice *> devices; |
f00ff009 | 425 | for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++) |
5f316715 | 426 | devices[iDevicePtr]->TransmitActiveSource(); |
c4098482 | 427 | |
5f316715 LOK |
428 | return true; |
429 | } | |
430 | return false; | |
e9de9629 LOK |
431 | } |
432 | ||
433 | bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) | |
434 | { | |
435 | if (command.parameters.size == 4) | |
436 | { | |
437 | uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
438 | uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); | |
e9de9629 | 439 | |
0f23c85c LOK |
440 | CCECBusDevice *device = GetDevice(command.initiator); |
441 | if (device) | |
9dc04b07 | 442 | device->SetStreamPath(iNewAddress, iOldAddress); |
e9de9629 LOK |
443 | } |
444 | return true; | |
445 | } | |
446 | ||
907bd60f LOK |
447 | bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command) |
448 | { | |
449 | if (command.parameters.size == 2) | |
450 | { | |
451 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
37b0c572 | 452 | m_processor->SetActiveSource(iNewAddress); |
907bd60f | 453 | } |
15d1a84c LOK |
454 | |
455 | return false; | |
907bd60f LOK |
456 | } |
457 | ||
a3269a0a LOK |
458 | bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command) |
459 | { | |
460 | if (command.parameters.size == 3) | |
461 | { | |
462 | CCECBusDevice *device = GetDevice(command.initiator); | |
463 | if (device) | |
464 | { | |
465 | cec_menu_language language; | |
466 | language.device = command.initiator; | |
56701628 | 467 | for (uint8_t iPtr = 0; iPtr < 4; iPtr++) |
a3269a0a LOK |
468 | language.language[iPtr] = command.parameters[iPtr]; |
469 | language.language[3] = 0; | |
470 | device->SetMenuLanguage(language); | |
15d1a84c LOK |
471 | return true; |
472 | } | |
473 | } | |
474 | return false; | |
475 | } | |
476 | ||
477 | bool CCECCommandHandler::HandleSetOSDName(const cec_command &command) | |
478 | { | |
479 | if (command.parameters.size > 0) | |
480 | { | |
481 | CCECBusDevice *device = GetDevice(command.initiator); | |
482 | if (device) | |
483 | { | |
484 | char buf[1024]; | |
485 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) | |
486 | buf[iPtr] = (char)command.parameters[iPtr]; | |
487 | buf[command.parameters.size] = 0; | |
488 | ||
489 | CStdString strName(buf); | |
490 | device->SetOSDName(strName); | |
6b72afcd | 491 | |
15d1a84c | 492 | return true; |
a3269a0a LOK |
493 | } |
494 | } | |
15d1a84c | 495 | return false; |
a3269a0a LOK |
496 | } |
497 | ||
e9de9629 LOK |
498 | bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) |
499 | { | |
8e57f83c | 500 | if (m_processor->IsRunning() && command.parameters.size >= 2) |
e9de9629 | 501 | { |
b6c7bc94 | 502 | uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); |
5477a250 | 503 | CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); |
72689600 LOK |
504 | |
505 | /* one of the device handled by libCEC has been made active */ | |
506 | CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); | |
507 | if (device && m_busDevice->MyLogicalAddressContains(device->GetLogicalAddress())) | |
508 | { | |
509 | device->SetActiveSource(); | |
49c8f2e4 | 510 | device->TransmitImageViewOn(); |
72689600 | 511 | device->TransmitActiveSource(); |
538d8471 LOK |
512 | |
513 | device->SetMenuState(CEC_MENU_STATE_ACTIVATED); | |
514 | device->TransmitMenuState(command.initiator); | |
72689600 | 515 | } |
e9de9629 | 516 | } |
15d1a84c | 517 | return false; |
e9de9629 LOK |
518 | } |
519 | ||
aa517a0d | 520 | bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) |
e5e86c76 | 521 | { |
8e57f83c | 522 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
e5e86c76 LOK |
523 | { |
524 | CCECBusDevice *device = GetDevice(command.destination); | |
aa517a0d LOK |
525 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) |
526 | { | |
527 | if (command.parameters.size >= 2) | |
528 | { | |
529 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
530 | ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON); | |
531 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
532 | CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress); | |
533 | if (newActiveDevice) | |
37b0c572 | 534 | newActiveDevice->SetActiveSource(); |
aa517a0d LOK |
535 | return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); |
536 | } | |
537 | else | |
538 | { | |
539 | ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); | |
540 | return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); | |
541 | } | |
542 | } | |
e5e86c76 | 543 | } |
6b72afcd | 544 | return false; |
e5e86c76 LOK |
545 | } |
546 | ||
4d6b4433 LOK |
547 | bool CCECCommandHandler::HandleStandby(const cec_command &command) |
548 | { | |
549 | CCECBusDevice *device = GetDevice(command.initiator); | |
550 | if (device) | |
551 | device->SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
6b72afcd | 552 | |
4d6b4433 LOK |
553 | return true; |
554 | } | |
555 | ||
aa517a0d | 556 | bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) |
868dc71f | 557 | { |
aa517a0d | 558 | if (command.parameters.size == 1) |
868dc71f | 559 | { |
aa517a0d LOK |
560 | CCECBusDevice *device = GetDevice(command.initiator); |
561 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
562 | { | |
563 | ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); | |
564 | return true; | |
565 | } | |
566 | } | |
567 | ||
568 | return false; | |
569 | } | |
570 | ||
571 | bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) | |
572 | { | |
573 | if (command.parameters.size == 1) | |
574 | { | |
575 | CCECBusDevice *device = GetDevice(command.initiator); | |
576 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
577 | { | |
578 | ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); | |
579 | return true; | |
580 | } | |
868dc71f LOK |
581 | } |
582 | ||
583 | return false; | |
584 | } | |
585 | ||
1a6669b8 | 586 | bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) |
cf0ecd85 | 587 | { |
37b0c572 | 588 | m_processor->m_busDevices[command.initiator]->SetActiveSource(); |
1a6669b8 | 589 | return true; |
cf0ecd85 LOK |
590 | } |
591 | ||
e9de9629 LOK |
592 | bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) |
593 | { | |
8e57f83c | 594 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0) |
e9de9629 | 595 | { |
02e7043e | 596 | CLibCEC::AddKey(); |
e9de9629 LOK |
597 | |
598 | if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) | |
599 | { | |
68391d4f LOK |
600 | if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || |
601 | command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) | |
602 | { | |
603 | CCECBusDevice *device = GetDevice(command.destination); | |
604 | if (device) | |
3fd2a2b8 | 605 | { |
68391d4f | 606 | device->SetPowerStatus(CEC_POWER_STATUS_ON); |
3fd2a2b8 LOK |
607 | if (device->MyLogicalAddressContains(device->GetLogicalAddress())) |
608 | { | |
609 | device->SetActiveSource(); | |
49c8f2e4 | 610 | device->TransmitImageViewOn(); |
3fd2a2b8 LOK |
611 | device->TransmitActiveSource(); |
612 | ||
613 | if (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || | |
614 | device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) | |
615 | ((CCECPlaybackDevice *)device)->TransmitDeckStatus(command.initiator); | |
616 | } | |
617 | } | |
68391d4f | 618 | } |
d1ab114f LOK |
619 | else |
620 | { | |
02e7043e | 621 | CLibCEC::SetCurrentButton((cec_user_control_code) command.parameters[0]); |
d1ab114f | 622 | } |
15d1a84c | 623 | return true; |
e9de9629 LOK |
624 | } |
625 | } | |
15d1a84c | 626 | return false; |
e9de9629 LOK |
627 | } |
628 | ||
629 | bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) | |
630 | { | |
8e57f83c | 631 | if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination)) |
02e7043e | 632 | CLibCEC::AddKey(); |
6b72afcd | 633 | |
e9de9629 LOK |
634 | return true; |
635 | } | |
636 | ||
1de6617c LOK |
637 | bool CCECCommandHandler::HandleVendorCommand(const cec_command & UNUSED(command)) |
638 | { | |
639 | return true; | |
640 | } | |
641 | ||
e9de9629 LOK |
642 | void CCECCommandHandler::UnhandledCommand(const cec_command &command) |
643 | { | |
5477a250 | 644 | CLibCEC::AddLog(CEC_LOG_DEBUG, "unhandled command with opcode %02x from address %d", command.opcode, command.initiator); |
0f23c85c LOK |
645 | } |
646 | ||
6f14b512 | 647 | size_t CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const |
8747dd4f | 648 | { |
6f14b512 | 649 | size_t iReturn(0); |
8747dd4f | 650 | |
fcf10e27 | 651 | cec_logical_addresses addresses = m_processor->GetLogicalAddresses(); |
f2198ab5 | 652 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) |
8747dd4f LOK |
653 | { |
654 | if (addresses[iPtr]) | |
655 | { | |
656 | devices.push_back(GetDevice((cec_logical_address) iPtr)); | |
657 | ++iReturn; | |
658 | } | |
659 | } | |
660 | ||
661 | return iReturn; | |
662 | } | |
663 | ||
0f23c85c LOK |
664 | CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const |
665 | { | |
666 | CCECBusDevice *device = NULL; | |
667 | ||
668 | if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST) | |
fcf10e27 | 669 | device = m_processor->m_busDevices[iLogicalAddress]; |
0f23c85c LOK |
670 | |
671 | return device; | |
e9de9629 | 672 | } |
6685ae07 LOK |
673 | |
674 | CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const | |
675 | { | |
fcf10e27 | 676 | return m_processor->GetDeviceByPhysicalAddress(iPhysicalAddress); |
6685ae07 | 677 | } |
181b3475 | 678 | |
c4098482 LOK |
679 | CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const |
680 | { | |
fcf10e27 | 681 | return m_processor->GetDeviceByType(type); |
c4098482 LOK |
682 | } |
683 | ||
8fa35473 | 684 | bool CCECCommandHandler::SetVendorId(const cec_command &command) |
181b3475 | 685 | { |
8fa35473 | 686 | bool bChanged(false); |
181b3475 LOK |
687 | if (command.parameters.size < 3) |
688 | { | |
5477a250 | 689 | CLibCEC::AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); |
8fa35473 | 690 | return bChanged; |
181b3475 LOK |
691 | } |
692 | ||
bae71306 LOK |
693 | uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) + |
694 | ((uint64_t)command.parameters[1] << 8) + | |
181b3475 LOK |
695 | (uint64_t)command.parameters[2]; |
696 | ||
697 | CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator); | |
698 | if (device) | |
8fa35473 LOK |
699 | bChanged = device->SetVendorId(iVendorId); |
700 | return bChanged; | |
181b3475 | 701 | } |
5e822b09 | 702 | |
16b1e052 LOK |
703 | void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16_t iNewAddress) |
704 | { | |
705 | if (!m_busDevice->MyLogicalAddressContains(iAddress)) | |
706 | { | |
fcf10e27 | 707 | bool bOurAddress(m_processor->GetPhysicalAddress() == iNewAddress); |
16b1e052 LOK |
708 | GetDevice(iAddress)->SetPhysicalAddress(iNewAddress); |
709 | if (bOurAddress) | |
710 | { | |
711 | /* another device reported the same physical address as ours | |
712 | * since we don't have physical address detection yet, we'll just use the | |
713 | * given address, increased by 0x100 for now */ | |
fcf10e27 | 714 | m_processor->SetPhysicalAddress(iNewAddress + 0x100); |
16b1e052 LOK |
715 | } |
716 | } | |
717 | } | |
855a3a98 | 718 | |
b64db02e | 719 | bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination) |
8fa35473 LOK |
720 | { |
721 | cec_command command; | |
ae693aaa | 722 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_IMAGE_VIEW_ON); |
8fa35473 | 723 | |
19cbfa8f | 724 | return Transmit(command, false); |
8fa35473 LOK |
725 | } |
726 | ||
727 | bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
728 | { | |
729 | cec_command command; | |
ae693aaa | 730 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_STANDBY); |
8fa35473 | 731 | |
19cbfa8f | 732 | return Transmit(command, false); |
8fa35473 LOK |
733 | } |
734 | ||
735 | bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
736 | { | |
737 | cec_command command; | |
ae693aaa | 738 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_CEC_VERSION); |
8fa35473 | 739 | |
5e526919 | 740 | return Transmit(command, true, CEC_OPCODE_CEC_VERSION); |
8fa35473 LOK |
741 | } |
742 | ||
743 | bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
744 | { | |
745 | cec_command command; | |
ae693aaa | 746 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_MENU_LANGUAGE); |
8fa35473 | 747 | |
5e526919 | 748 | return Transmit(command, true, CEC_OPCODE_SET_MENU_LANGUAGE); |
8fa35473 LOK |
749 | } |
750 | ||
751 | bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
752 | { | |
753 | cec_command command; | |
ae693aaa | 754 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_OSD_NAME); |
8fa35473 | 755 | |
5e526919 | 756 | return Transmit(command, true, CEC_OPCODE_SET_OSD_NAME); |
8fa35473 LOK |
757 | } |
758 | ||
759 | bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
760 | { | |
761 | cec_command command; | |
ae693aaa | 762 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS); |
8fa35473 | 763 | |
5e526919 | 764 | return Transmit(command, true, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); |
8fa35473 LOK |
765 | } |
766 | ||
767 | bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
768 | { | |
769 | cec_command command; | |
ae693aaa | 770 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS); |
8fa35473 | 771 | |
5e526919 | 772 | return Transmit(command, true, CEC_OPCODE_REPORT_POWER_STATUS); |
8fa35473 LOK |
773 | } |
774 | ||
775 | bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
776 | { | |
777 | cec_command command; | |
ae693aaa | 778 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
8fa35473 | 779 | |
5e526919 | 780 | return Transmit(command, true, CEC_OPCODE_DEVICE_VENDOR_ID); |
8fa35473 LOK |
781 | } |
782 | ||
783 | bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress) | |
784 | { | |
785 | cec_command command; | |
ae693aaa | 786 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); |
8fa35473 LOK |
787 | command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF)); |
788 | command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF)); | |
789 | ||
19cbfa8f | 790 | return Transmit(command, false); |
8fa35473 LOK |
791 | } |
792 | ||
793 | bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_version cecVersion) | |
794 | { | |
795 | cec_command command; | |
ae693aaa | 796 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_CEC_VERSION); |
8fa35473 LOK |
797 | command.parameters.PushBack((uint8_t)cecVersion); |
798 | ||
19cbfa8f | 799 | return Transmit(command, false); |
8fa35473 LOK |
800 | } |
801 | ||
802 | bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress) | |
803 | { | |
804 | cec_command command; | |
ae693aaa | 805 | cec_command::Format(command, iInitiator, CECDEVICE_TV, CEC_OPCODE_INACTIVE_SOURCE); |
8fa35473 LOK |
806 | command.parameters.PushBack((iPhysicalAddress >> 8) & 0xFF); |
807 | command.parameters.PushBack(iPhysicalAddress & 0xFF); | |
808 | ||
19cbfa8f | 809 | return Transmit(command, false); |
8fa35473 LOK |
810 | } |
811 | ||
812 | bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_menu_state menuState) | |
813 | { | |
814 | cec_command command; | |
ae693aaa | 815 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_MENU_STATUS); |
8fa35473 LOK |
816 | command.parameters.PushBack((uint8_t)menuState); |
817 | ||
19cbfa8f | 818 | return Transmit(command, false); |
8fa35473 LOK |
819 | } |
820 | ||
821 | bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, CStdString strDeviceName) | |
822 | { | |
823 | cec_command command; | |
ae693aaa | 824 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_NAME); |
6f14b512 | 825 | for (size_t iPtr = 0; iPtr < strDeviceName.length(); iPtr++) |
8fa35473 LOK |
826 | command.parameters.PushBack(strDeviceName.at(iPtr)); |
827 | ||
19cbfa8f | 828 | return Transmit(command, false); |
8fa35473 LOK |
829 | } |
830 | ||
831 | bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_display_control duration, const char *strMessage) | |
832 | { | |
833 | cec_command command; | |
ae693aaa | 834 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_STRING); |
8fa35473 LOK |
835 | command.parameters.PushBack((uint8_t)duration); |
836 | ||
6f14b512 | 837 | size_t iLen = strlen(strMessage); |
8fa35473 LOK |
838 | if (iLen > 13) iLen = 13; |
839 | ||
6f14b512 | 840 | for (size_t iPtr = 0; iPtr < iLen; iPtr++) |
8fa35473 LOK |
841 | command.parameters.PushBack(strMessage[iPtr]); |
842 | ||
19cbfa8f | 843 | return Transmit(command, false); |
8fa35473 LOK |
844 | } |
845 | ||
846 | bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator, uint16_t iPhysicalAddress, cec_device_type type) | |
847 | { | |
848 | cec_command command; | |
ae693aaa | 849 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); |
8fa35473 LOK |
850 | command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF)); |
851 | command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF)); | |
852 | command.parameters.PushBack((uint8_t) (type)); | |
853 | ||
19cbfa8f | 854 | return Transmit(command, false); |
8fa35473 LOK |
855 | } |
856 | ||
857 | bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
858 | { | |
859 | cec_command command; | |
ae693aaa | 860 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_NONE); |
8fa35473 | 861 | |
ae693aaa | 862 | return Transmit(command, false); |
8fa35473 LOK |
863 | } |
864 | ||
865 | bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_power_status state) | |
866 | { | |
867 | cec_command command; | |
ae693aaa | 868 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_POWER_STATUS); |
8fa35473 LOK |
869 | command.parameters.PushBack((uint8_t) state); |
870 | ||
19cbfa8f | 871 | return Transmit(command, false); |
8fa35473 LOK |
872 | } |
873 | ||
874 | bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator, uint64_t iVendorId) | |
875 | { | |
876 | cec_command command; | |
ae693aaa | 877 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID); |
8fa35473 LOK |
878 | |
879 | command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 16) & 0xFF)); | |
880 | command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 8) & 0xFF)); | |
881 | command.parameters.PushBack((uint8_t) ((uint64_t)iVendorId & 0xFF)); | |
882 | ||
19cbfa8f | 883 | return Transmit(command, false); |
8fa35473 LOK |
884 | } |
885 | ||
886 | bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, uint8_t state) | |
887 | { | |
888 | cec_command command; | |
ae693aaa | 889 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_AUDIO_STATUS); |
8fa35473 LOK |
890 | command.parameters.PushBack(state); |
891 | ||
19cbfa8f | 892 | return Transmit(command, false); |
8fa35473 LOK |
893 | } |
894 | ||
895 | bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state) | |
896 | { | |
897 | cec_command command; | |
ae693aaa | 898 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE); |
8fa35473 LOK |
899 | command.parameters.PushBack((uint8_t)state); |
900 | ||
19cbfa8f | 901 | return Transmit(command, false); |
8fa35473 LOK |
902 | } |
903 | ||
f42d3e0f LOK |
904 | bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath) |
905 | { | |
906 | cec_command command; | |
907 | cec_command::Format(command, m_busDevice->GetLogicalAddress(), CECDEVICE_BROADCAST, CEC_OPCODE_SET_STREAM_PATH); | |
908 | command.parameters.PushBack((uint8_t) ((iStreamPath >> 8) & 0xFF)); | |
909 | command.parameters.PushBack((uint8_t) (iStreamPath & 0xFF)); | |
910 | ||
911 | return Transmit(command, false); | |
912 | } | |
913 | ||
8fa35473 LOK |
914 | bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state) |
915 | { | |
916 | cec_command command; | |
ae693aaa | 917 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS); |
8fa35473 LOK |
918 | command.parameters.PushBack((uint8_t)state); |
919 | ||
19cbfa8f | 920 | return Transmit(command, false); |
8fa35473 LOK |
921 | } |
922 | ||
923 | bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_deck_info state) | |
924 | { | |
925 | cec_command command; | |
ae693aaa | 926 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_DECK_STATUS); |
8fa35473 LOK |
927 | command.PushBack((uint8_t)state); |
928 | ||
19cbfa8f | 929 | return Transmit(command, false); |
8fa35473 LOK |
930 | } |
931 | ||
4bec9d79 | 932 | bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */) |
8fa35473 LOK |
933 | { |
934 | cec_command command; | |
ae693aaa | 935 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_PRESSED); |
8fa35473 LOK |
936 | command.parameters.PushBack((uint8_t)key); |
937 | ||
4bec9d79 | 938 | return Transmit(command, bWait); |
8fa35473 LOK |
939 | } |
940 | ||
4bec9d79 | 941 | bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWait /* = true */) |
8fa35473 LOK |
942 | { |
943 | cec_command command; | |
ae693aaa | 944 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_RELEASE); |
8fa35473 | 945 | |
4bec9d79 | 946 | return Transmit(command, bWait); |
8fa35473 LOK |
947 | } |
948 | ||
446c0cfc | 949 | bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /* = true */, cec_opcode expectedResponse /* = CEC_OPCODE_NONE */) |
8fa35473 | 950 | { |
b64db02e | 951 | bool bReturn(false); |
ae693aaa | 952 | command.transmit_timeout = m_iTransmitTimeout; |
ae693aaa | 953 | |
ae693aaa | 954 | { |
861832f6 | 955 | uint8_t iTries(0), iMaxTries(command.opcode == CEC_OPCODE_NONE ? 1 : m_iTransmitRetries + 1); |
f00ff009 LOK |
956 | CLockObject writeLock(m_processor->m_transmitMutex); |
957 | CLockObject receiveLock(m_receiveMutex); | |
19cbfa8f | 958 | while (!bReturn && ++iTries <= iMaxTries) |
b64db02e | 959 | { |
446c0cfc | 960 | m_expectedResponse = expectedResponse; |
99666519 | 961 | if ((bReturn = m_processor->Transmit(command)) == true) |
19cbfa8f | 962 | { |
5477a250 | 963 | CLibCEC::AddLog(CEC_LOG_DEBUG, "command transmitted"); |
4478bc79 | 964 | if (bExpectResponse) |
960f33c6 | 965 | bReturn = m_condition.Wait(m_receiveMutex, m_bRcvSignal, m_iTransmitWait); |
94e9a2af LOK |
966 | m_bRcvSignal = false; |
967 | CLibCEC::AddLog(CEC_LOG_DEBUG, bReturn ? "expected response received" : "expected response not received"); | |
19cbfa8f | 968 | } |
b64db02e | 969 | } |
ae693aaa | 970 | } |
8fa35473 | 971 | |
b64db02e | 972 | return bReturn; |
8fa35473 | 973 | } |
83be0701 | 974 | |
3e61b350 | 975 | bool CCECCommandHandler::ActivateSource(void) |
83be0701 LOK |
976 | { |
977 | if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV) | |
978 | { | |
842262d8 | 979 | CCECBusDevice *primary = m_processor->GetPrimaryDevice(); |
6b1eea98 LOK |
980 | primary->SetPowerStatus(CEC_POWER_STATUS_ON); |
981 | primary->SetMenuState(CEC_MENU_STATE_ACTIVATED); | |
982 | ||
89a726fa LOK |
983 | if (m_processor->GetPrimaryDevice()->GetPhysicalAddress(false) != 0xffff) |
984 | { | |
985 | m_processor->SetActiveSource(); | |
986 | primary->TransmitMenuState(m_busDevice->GetLogicalAddress()); | |
987 | m_bHandlerInited = true; | |
988 | } | |
83be0701 | 989 | } |
7dc58c9f | 990 | return true; |
83be0701 | 991 | } |