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