do not wake the system when exiting away mode
[deb_libcec.git] / src / lib / adapter / Pulse-Eight / USBCECAdapterCommands.cpp
... / ...
CommitLineData
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
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 "env.h"
34#include "USBCECAdapterCommands.h"
35
36#include "USBCECAdapterMessage.h"
37#include "USBCECAdapterCommunication.h"
38#include "lib/LibCEC.h"
39#include "lib/CECProcessor.h"
40#include "lib/CECTypeUtils.h"
41#include <stdio.h>
42
43using namespace CEC;
44using namespace PLATFORM;
45
46#define LIB_CEC m_comm->m_callback->GetLib()
47#define ToString(p) CCECTypeUtils::ToString(p)
48
49CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm) :
50 m_comm(comm),
51 m_bSettingsRetrieved(false),
52 m_bSettingAutoEnabled(false),
53 m_settingCecVersion(CEC_VERSION_UNKNOWN),
54 m_iSettingLAMask(0),
55 m_bNeedsWrite(false),
56 m_iBuildDate(CEC_FW_BUILD_UNKNOWN),
57 m_bControlledMode(false),
58 m_adapterType(P8_ADAPTERTYPE_UNKNOWN)
59{
60 m_persistedConfiguration.Clear();
61}
62
63cec_datapacket CUSBCECAdapterCommands::RequestSetting(cec_adapter_messagecode msgCode)
64{
65 cec_datapacket retVal;
66 retVal.Clear();
67
68 CCECAdapterMessage params;
69 CCECAdapterMessage *message = m_comm->SendCommand(msgCode, params);
70 if (message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED)
71 {
72 retVal = message->response;
73 retVal.Shift(2); // shift out start and msgcode
74 retVal.size -= 1; // remove end
75 }
76
77 delete message;
78 return retVal;
79}
80
81uint16_t CUSBCECAdapterCommands::RequestFirmwareVersion(void)
82{
83 m_persistedConfiguration.iFirmwareVersion = CEC_FW_VERSION_UNKNOWN;
84 unsigned int iFwVersionTry(0);
85
86 while (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN && iFwVersionTry++ < 3)
87 {
88#ifdef CEC_DEBUGGING
89 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting the firmware version");
90#endif
91 cec_datapacket response = RequestSetting(MSGCODE_FIRMWARE_VERSION);
92 if (response.size == 2)
93 m_persistedConfiguration.iFirmwareVersion = (response[0] << 8 | response[1]);
94 else
95 {
96 LIB_CEC->AddLog(CEC_LOG_WARNING, "the adapter did not respond with a correct firmware version (try %d, size = %d)", iFwVersionTry, response.size);
97 CEvent::Sleep(500);
98 }
99 }
100
101 if (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN)
102 {
103 LIB_CEC->AddLog(CEC_LOG_DEBUG, "defaulting to firmware version 1");
104 m_persistedConfiguration.iFirmwareVersion = 1;
105 }
106
107 // firmware versions < 2 don't have an autonomous mode
108 if (m_persistedConfiguration.iFirmwareVersion < 2)
109 m_bControlledMode = true;
110
111 return m_persistedConfiguration.iFirmwareVersion;
112}
113
114bool CUSBCECAdapterCommands::RequestSettingAutoEnabled(void)
115{
116#ifdef CEC_DEBUGGING
117 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting autonomous mode setting");
118#endif
119
120 cec_datapacket response = RequestSetting(MSGCODE_GET_AUTO_ENABLED);
121 if (response.size == 1)
122 {
123 m_bSettingAutoEnabled = response[0] == 1;
124 LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted autonomous mode setting: '%s'", m_bSettingAutoEnabled ? "enabled" : "disabled");
125 return true;
126 }
127 return false;
128}
129
130bool CUSBCECAdapterCommands::RequestSettingCECVersion(void)
131{
132#ifdef CEC_DEBUGGING
133 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting CEC version setting");
134#endif
135
136 cec_datapacket response = RequestSetting(MSGCODE_GET_HDMI_VERSION);
137 if (response.size == 1)
138 {
139 m_settingCecVersion = (cec_version)response[0];
140 LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted CEC version setting: '%s'", ToString(m_settingCecVersion));
141 return true;
142 }
143 return false;
144}
145
146p8_cec_adapter_type CUSBCECAdapterCommands::RequestAdapterType(void)
147{
148 if (m_adapterType == P8_ADAPTERTYPE_UNKNOWN)
149 {
150#ifdef CEC_DEBUGGING
151 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting adapter type");
152#endif
153
154 cec_datapacket response = RequestSetting(MSGCODE_GET_ADAPTER_TYPE);
155 if (response.size == 1)
156 m_adapterType = (p8_cec_adapter_type)response[0];
157 }
158 return m_adapterType;
159}
160
161uint32_t CUSBCECAdapterCommands::RequestBuildDate(void)
162{
163 if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN)
164 {
165#ifdef CEC_DEBUGGING
166 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting firmware build date");
167#endif
168
169 cec_datapacket response = RequestSetting(MSGCODE_GET_BUILDDATE);
170 if (response.size == 4)
171 m_iBuildDate = (uint32_t)response[0] << 24 | (uint32_t)response[1] << 16 | (uint32_t)response[2] << 8 | (uint32_t)response[3];
172 }
173 return m_iBuildDate;
174}
175
176bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void)
177{
178#ifdef CEC_DEBUGGING
179 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting default logical address setting");
180#endif
181
182 cec_datapacket response = RequestSetting(MSGCODE_GET_DEFAULT_LOGICAL_ADDRESS);
183 if (response.size == 1)
184 {
185 m_persistedConfiguration.logicalAddresses.primary = (cec_logical_address)response[0];
186 LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address setting: '%s'", ToString(m_persistedConfiguration.logicalAddresses.primary));
187 return true;
188 }
189 return false;
190}
191
192bool CUSBCECAdapterCommands::RequestSettingDeviceType(void)
193{
194#ifdef CEC_DEBUGGING
195 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting device type setting");
196#endif
197 m_persistedConfiguration.deviceTypes.Clear();
198
199 cec_datapacket response = RequestSetting(MSGCODE_GET_DEVICE_TYPE);
200 if (response.size == 1)
201 {
202 m_persistedConfiguration.deviceTypes.Add((cec_device_type)response[0]);
203 LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device type setting: '%s'", ToString((cec_device_type)response[0]));
204 return true;
205 }
206 LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device type setting");
207 return false;
208}
209
210bool CUSBCECAdapterCommands::RequestSettingLogicalAddressMask(void)
211{
212#ifdef CEC_DEBUGGING
213 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting logical address mask setting");
214#endif
215
216 cec_datapacket response = RequestSetting(MSGCODE_GET_LOGICAL_ADDRESS_MASK);
217 if (response.size == 2)
218 {
219 m_iSettingLAMask = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]);
220 LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address mask setting: '%x'", m_iSettingLAMask);
221 return true;
222 }
223 return false;
224}
225
226bool CUSBCECAdapterCommands::RequestSettingOSDName(void)
227{
228#ifdef CEC_DEBUGGING
229 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting OSD name setting");
230#endif
231
232 memset(m_persistedConfiguration.strDeviceName, 0, 13);
233 cec_datapacket response = RequestSetting(MSGCODE_GET_OSD_NAME);
234 if (response.size == 0)
235 {
236 LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device name setting");
237 return false;
238 }
239
240 char buf[14];
241 for (uint8_t iPtr = 0; iPtr < response.size && iPtr < 13; iPtr++)
242 buf[iPtr] = (char)response[iPtr];
243 buf[response.size] = 0;
244
245 snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", buf);
246 LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device name setting: '%s'", buf);
247 return true;
248}
249
250bool CUSBCECAdapterCommands::RequestSettingPhysicalAddress(void)
251{
252#ifdef CEC_DEBUGGING
253 LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting physical address setting");
254#endif
255
256 cec_datapacket response = RequestSetting(MSGCODE_GET_PHYSICAL_ADDRESS);
257 if (response.size == 2)
258 {
259 m_persistedConfiguration.iPhysicalAddress = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]);
260 LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted physical address setting: '%4x'", m_persistedConfiguration.iPhysicalAddress);
261 return true;
262 }
263 LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted physical address setting");
264 return false;
265}
266
267bool CUSBCECAdapterCommands::SetSettingAutoEnabled(bool enabled)
268{
269 bool bReturn(false);
270
271 /* check whether this value was changed */
272 {
273 CLockObject lock(m_mutex);
274 if (m_bSettingAutoEnabled == enabled)
275 return bReturn;
276 m_bNeedsWrite = true;
277 }
278
279 LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning autonomous mode %s", enabled ? "on" : "off");
280
281 CCECAdapterMessage params;
282 params.PushEscaped(enabled ? 1 : 0);
283 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_AUTO_ENABLED, params);
284 bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
285 delete message;
286
287 if (bReturn)
288 {
289 CLockObject lock(m_mutex);
290 m_bSettingAutoEnabled = enabled;
291 }
292
293 return bReturn;
294}
295
296bool CUSBCECAdapterCommands::SetSettingDeviceType(cec_device_type type)
297{
298 bool bReturn(false);
299
300 /* check whether this value was changed */
301 {
302 CLockObject lock(m_mutex);
303 if (m_persistedConfiguration.deviceTypes.types[0] == type)
304 return bReturn;
305 m_bNeedsWrite = true;
306 }
307
308 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the device type to %X (previous: %X)", (uint8_t)type, (uint8_t)m_persistedConfiguration.deviceTypes.types[0]);
309
310 CCECAdapterMessage params;
311 params.PushEscaped((uint8_t)type);
312 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_DEVICE_TYPE, params);
313 bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
314 delete message;
315
316 if (bReturn)
317 {
318 CLockObject lock(m_mutex);
319 m_persistedConfiguration.deviceTypes.types[0] = type;
320 }
321
322 return bReturn;
323}
324
325bool CUSBCECAdapterCommands::SetSettingDefaultLogicalAddress(cec_logical_address address)
326{
327 bool bReturn(false);
328
329 /* check whether this value was changed */
330 {
331 CLockObject lock(m_mutex);
332 if (m_persistedConfiguration.logicalAddresses.primary == address)
333 return bReturn;
334 m_bNeedsWrite = true;
335 }
336
337 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X (previous: %X)", (uint8_t)address, (uint8_t)m_persistedConfiguration.logicalAddresses.primary);
338
339 CCECAdapterMessage params;
340 params.PushEscaped((uint8_t)address);
341 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_DEFAULT_LOGICAL_ADDRESS, params);
342 bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
343 delete message;
344
345 if (bReturn)
346 {
347 CLockObject lock(m_mutex);
348 m_persistedConfiguration.logicalAddresses.primary = address;
349 }
350
351 return bReturn;
352}
353
354bool CUSBCECAdapterCommands::SetSettingLogicalAddressMask(uint16_t iMask)
355{
356 bool bReturn(false);
357
358 /* check whether this value was changed */
359 {
360 CLockObject lock(m_mutex);
361 if (m_iSettingLAMask == iMask)
362 return bReturn;
363 m_bNeedsWrite = true;
364 }
365
366 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask);
367
368 CCECAdapterMessage params;
369 params.PushEscaped(iMask >> 8);
370 params.PushEscaped((uint8_t)iMask);
371 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_LOGICAL_ADDRESS_MASK, params);
372 bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
373 delete message;
374
375 if (bReturn)
376 {
377 CLockObject lock(m_mutex);
378 m_iSettingLAMask = iMask;
379 }
380
381 return bReturn;
382}
383
384bool CUSBCECAdapterCommands::SetSettingPhysicalAddress(uint16_t iPhysicalAddress)
385{
386 bool bReturn(false);
387
388 /* check whether this value was changed */
389 {
390 CLockObject lock(m_mutex);
391 if (m_persistedConfiguration.iPhysicalAddress == iPhysicalAddress)
392 return bReturn;
393 m_bNeedsWrite = true;
394 }
395
396 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X (previous: %04X)", iPhysicalAddress, m_persistedConfiguration.iPhysicalAddress);
397
398 CCECAdapterMessage params;
399 params.PushEscaped(iPhysicalAddress >> 8);
400 params.PushEscaped((uint8_t)iPhysicalAddress);
401 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_PHYSICAL_ADDRESS, params);
402 bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
403 delete message;
404
405 if (bReturn)
406 {
407 CLockObject lock(m_mutex);
408 m_persistedConfiguration.iPhysicalAddress = iPhysicalAddress;
409 }
410
411 return bReturn;
412}
413
414bool CUSBCECAdapterCommands::SetSettingCECVersion(cec_version version)
415{
416 bool bReturn(false);
417
418 /* check whether this value was changed */
419 {
420 CLockObject lock(m_mutex);
421 if (m_settingCecVersion == version)
422 return bReturn;
423 m_bNeedsWrite = true;
424 }
425
426 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s (previous: %s)", ToString(version), ToString(m_settingCecVersion));
427
428 CCECAdapterMessage params;
429 params.PushEscaped((uint8_t)version);
430 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_HDMI_VERSION, params);
431 bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
432 delete message;
433
434 if (bReturn)
435 {
436 CLockObject lock(m_mutex);
437 m_settingCecVersion = version;
438 }
439
440 return bReturn;
441}
442
443bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName)
444{
445 bool bReturn(false);
446
447 /* check whether this value was changed */
448 if (!strcmp(m_persistedConfiguration.strDeviceName, strOSDName))
449 return bReturn;
450
451 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s (previous: %s)", strOSDName, m_persistedConfiguration.strDeviceName);
452
453 CCECAdapterMessage params;
454 for (size_t iPtr = 0; iPtr < strlen(strOSDName); iPtr++)
455 params.PushEscaped(strOSDName[iPtr]);
456 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_OSD_NAME, params);
457 bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
458 delete message;
459
460 if (bReturn)
461 snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", strOSDName);
462
463 return bReturn;
464}
465
466bool CUSBCECAdapterCommands::WriteEEPROM(void)
467{
468 {
469 CLockObject lock(m_mutex);
470 if (!m_bNeedsWrite)
471 return true;
472 }
473
474 LIB_CEC->AddLog(CEC_LOG_DEBUG, "writing settings in the EEPROM");
475
476 CCECAdapterMessage params;
477 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_WRITE_EEPROM, params);
478 bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
479 delete message;
480
481 if (bReturn)
482 {
483 CLockObject lock(m_mutex);
484 m_bNeedsWrite = false;
485 }
486
487 return bReturn;
488}
489
490bool CUSBCECAdapterCommands::PersistConfiguration(const libcec_configuration &configuration)
491{
492 bool bReturn(false);
493 if (m_persistedConfiguration.iFirmwareVersion < 2)
494 return bReturn;
495
496 if (!RequestSettings())
497 return bReturn;
498
499 bReturn |= SetSettingAutoEnabled(true);
500 bReturn |= SetSettingDeviceType(CLibCEC::GetType(configuration.logicalAddresses.primary));
501 bReturn |= SetSettingDefaultLogicalAddress(configuration.logicalAddresses.primary);
502 bReturn |= SetSettingLogicalAddressMask(CLibCEC::GetMaskForType(configuration.logicalAddresses.primary));
503 bReturn |= SetSettingPhysicalAddress(configuration.iPhysicalAddress);
504 bReturn |= SetSettingCECVersion(configuration.clientVersion >= CEC_CLIENT_VERSION_1_8_0 ? configuration.cecVersion : CEC_VERSION_1_4);
505 bReturn |= SetSettingOSDName(configuration.strDeviceName);
506
507 return bReturn;
508}
509
510bool CUSBCECAdapterCommands::RequestSettings(void)
511{
512 if (m_persistedConfiguration.iFirmwareVersion < 2)
513 {
514 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - firmware version %d does not have any eeprom settings", __FUNCTION__, m_persistedConfiguration.iFirmwareVersion);
515 // settings can only be persisted with firmware v2+
516 return false;
517 }
518
519 if (m_bSettingsRetrieved)
520 return true;
521
522 bool bReturn(true);
523 bReturn &= RequestSettingAutoEnabled();
524 bReturn &= RequestSettingCECVersion();
525 bReturn &= RequestSettingDefaultLogicalAddress();
526 bReturn &= RequestSettingDeviceType();
527 bReturn &= RequestSettingLogicalAddressMask();
528 bReturn &= RequestSettingOSDName();
529 bReturn &= RequestSettingPhysicalAddress();
530
531 // don't read the following settings:
532 // - auto enabled (always enabled)
533 // - default logical address (autodetected)
534 // - logical address mask (autodetected)
535 // - CEC version (1.3a)
536
537 // TODO to be added to the firmware:
538 // - base device (4 bits)
539 // - HDMI port number (4 bits)
540 // - TV vendor id (12 bits)
541 // - wake devices (8 bits)
542 // - standby devices (8 bits)
543 // - use TV menu language (1 bit)
544 // - activate source (1 bit)
545 // - power off screensaver (1 bit)
546 // - power off on standby (1 bit)
547 // - send inactive source (1 bit)
548
549 m_bSettingsRetrieved = true;
550
551 return bReturn;
552}
553
554bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration &configuration)
555{
556 // get the settings from the eeprom if needed
557 if (!RequestSettings())
558 return false;
559
560 // copy the settings
561 configuration.iFirmwareVersion = m_persistedConfiguration.iFirmwareVersion;
562 configuration.deviceTypes = m_persistedConfiguration.deviceTypes;
563 configuration.iPhysicalAddress = m_persistedConfiguration.iPhysicalAddress;
564 snprintf(configuration.strDeviceName, 13, "%s", m_persistedConfiguration.strDeviceName);
565
566 return true;
567}
568
569bool CUSBCECAdapterCommands::PingAdapter(void)
570{
571#ifdef CEC_DEBUGGING
572 LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending ping");
573#endif
574
575 CCECAdapterMessage params;
576 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_PING, params);
577 bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
578 delete message;
579 return bReturn;
580}
581
582bool CUSBCECAdapterCommands::SetAckMask(uint16_t iMask)
583{
584 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask);
585
586 CCECAdapterMessage params;
587 params.PushEscaped(iMask >> 8);
588 params.PushEscaped((uint8_t)iMask);
589 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_ACK_MASK, params);
590 bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
591 delete message;
592 return bReturn;
593}
594
595void CUSBCECAdapterCommands::SetActiveSource(bool bSetTo, bool bClientUnregistered)
596{
597 if (bClientUnregistered) return;
598 if (m_persistedConfiguration.iFirmwareVersion >= 3)
599 {
600 LIB_CEC->AddLog(CEC_LOG_DEBUG, "marking the adapter as %s source", bSetTo ? "active" : "inactive");
601 CCECAdapterMessage params;
602 params.PushEscaped(bSetTo ? 1 : 0);
603 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_ACTIVE_SOURCE, params);
604 delete message;
605 }
606}
607
608bool CUSBCECAdapterCommands::StartBootloader(void)
609{
610 LIB_CEC->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
611
612 CCECAdapterMessage params;
613 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_START_BOOTLOADER, params);
614 bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
615 delete message;
616 return bReturn;
617}
618
619bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout)
620{
621 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the line timeout to %d", iTimeout);
622 CCECAdapterMessage params;
623 params.PushEscaped(iTimeout);
624 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_TRANSMIT_IDLETIME, params);
625 bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
626 delete message;
627 return bReturn;
628}
629
630bool CUSBCECAdapterCommands::SetControlledMode(bool controlled)
631{
632 {
633 CLockObject lock(m_mutex);
634 if (m_bControlledMode == controlled)
635 return true;
636 }
637
638 LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off");
639
640 CCECAdapterMessage params;
641 params.PushEscaped(controlled ? 1 : 0);
642 CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_CONTROLLED, params);
643 bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
644 delete message;
645
646 if (bReturn)
647 {
648 CLockObject lock(m_mutex);
649 m_bControlledMode = controlled;
650 }
651
652 return bReturn;
653}