| 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 | |
| 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 | |
| 43 | using namespace CEC; |
| 44 | using namespace PLATFORM; |
| 45 | |
| 46 | #define LIB_CEC m_comm->m_callback->GetLib() |
| 47 | #define ToString(p) CCECTypeUtils::ToString(p) |
| 48 | |
| 49 | CUSBCECAdapterCommands::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 | { |
| 58 | m_persistedConfiguration.Clear(); |
| 59 | } |
| 60 | |
| 61 | cec_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 | } |
| 74 | |
| 75 | delete message; |
| 76 | return retVal; |
| 77 | } |
| 78 | |
| 79 | uint16_t CUSBCECAdapterCommands::RequestFirmwareVersion(void) |
| 80 | { |
| 81 | m_persistedConfiguration.iFirmwareVersion = CEC_FW_VERSION_UNKNOWN; |
| 82 | unsigned int iFwVersionTry(0); |
| 83 | |
| 84 | while (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN && iFwVersionTry++ < 3) |
| 85 | { |
| 86 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); |
| 87 | cec_datapacket response = RequestSetting(MSGCODE_FIRMWARE_VERSION); |
| 88 | if (response.size == 2) |
| 89 | m_persistedConfiguration.iFirmwareVersion = (response[0] << 8 | response[1]); |
| 90 | else |
| 91 | { |
| 92 | LIB_CEC->AddLog(CEC_LOG_WARNING, "the adapter did not respond with a correct firmware version (try %d)", iFwVersionTry); |
| 93 | CEvent::Sleep(500); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN) |
| 98 | { |
| 99 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "defaulting to firmware version 1"); |
| 100 | m_persistedConfiguration.iFirmwareVersion = 1; |
| 101 | } |
| 102 | |
| 103 | return m_persistedConfiguration.iFirmwareVersion; |
| 104 | } |
| 105 | |
| 106 | bool CUSBCECAdapterCommands::RequestSettingAutoEnabled(void) |
| 107 | { |
| 108 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting autonomous mode setting"); |
| 109 | |
| 110 | cec_datapacket response = RequestSetting(MSGCODE_GET_AUTO_ENABLED); |
| 111 | if (response.size == 1) |
| 112 | { |
| 113 | m_bSettingAutoEnabled = response[0] == 1; |
| 114 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted autonomous mode setting: '%s'", m_bSettingAutoEnabled ? "enabled" : "disabled"); |
| 115 | return true; |
| 116 | } |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | bool CUSBCECAdapterCommands::RequestSettingCECVersion(void) |
| 121 | { |
| 122 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting CEC version setting"); |
| 123 | |
| 124 | cec_datapacket response = RequestSetting(MSGCODE_GET_HDMI_VERSION); |
| 125 | if (response.size == 1) |
| 126 | { |
| 127 | m_settingCecVersion = (cec_version)response[0]; |
| 128 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted CEC version setting: '%s'", ToString(m_settingCecVersion)); |
| 129 | return true; |
| 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | uint32_t CUSBCECAdapterCommands::RequestBuildDate(void) |
| 135 | { |
| 136 | if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN) |
| 137 | { |
| 138 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting firmware build date"); |
| 139 | |
| 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; |
| 145 | } |
| 146 | |
| 147 | bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void) |
| 148 | { |
| 149 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting default logical address setting"); |
| 150 | |
| 151 | cec_datapacket response = RequestSetting(MSGCODE_GET_DEFAULT_LOGICAL_ADDRESS); |
| 152 | if (response.size == 1) |
| 153 | { |
| 154 | m_persistedConfiguration.logicalAddresses.primary = (cec_logical_address)response[0]; |
| 155 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address setting: '%s'", ToString(m_persistedConfiguration.logicalAddresses.primary)); |
| 156 | return true; |
| 157 | } |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | bool CUSBCECAdapterCommands::RequestSettingDeviceType(void) |
| 162 | { |
| 163 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting device type setting"); |
| 164 | m_persistedConfiguration.deviceTypes.Clear(); |
| 165 | |
| 166 | cec_datapacket response = RequestSetting(MSGCODE_GET_DEVICE_TYPE); |
| 167 | if (response.size == 1) |
| 168 | { |
| 169 | m_persistedConfiguration.deviceTypes.Add((cec_device_type)response[0]); |
| 170 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device type setting: '%s'", ToString((cec_device_type)response[0])); |
| 171 | return true; |
| 172 | } |
| 173 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device type setting"); |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | bool CUSBCECAdapterCommands::RequestSettingLogicalAddressMask(void) |
| 178 | { |
| 179 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting logical address mask setting"); |
| 180 | |
| 181 | cec_datapacket response = RequestSetting(MSGCODE_GET_LOGICAL_ADDRESS_MASK); |
| 182 | if (response.size == 2) |
| 183 | { |
| 184 | m_iSettingLAMask = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]); |
| 185 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address mask setting: '%x'", m_iSettingLAMask); |
| 186 | return true; |
| 187 | } |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | bool CUSBCECAdapterCommands::RequestSettingOSDName(void) |
| 192 | { |
| 193 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting OSD name setting"); |
| 194 | |
| 195 | memset(m_persistedConfiguration.strDeviceName, 0, 13); |
| 196 | cec_datapacket response = RequestSetting(MSGCODE_GET_OSD_NAME); |
| 197 | if (response.size == 0) |
| 198 | { |
| 199 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device name setting"); |
| 200 | return false; |
| 201 | } |
| 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 | |
| 208 | snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", buf); |
| 209 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device name setting: '%s'", buf); |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | bool CUSBCECAdapterCommands::RequestSettingPhysicalAddress(void) |
| 214 | { |
| 215 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting physical address setting"); |
| 216 | |
| 217 | cec_datapacket response = RequestSetting(MSGCODE_GET_PHYSICAL_ADDRESS); |
| 218 | if (response.size == 2) |
| 219 | { |
| 220 | m_persistedConfiguration.iPhysicalAddress = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]); |
| 221 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted physical address setting: '%4x'", m_persistedConfiguration.iPhysicalAddress); |
| 222 | return true; |
| 223 | } |
| 224 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted physical address setting"); |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | bool CUSBCECAdapterCommands::SetSettingAutoEnabled(bool enabled) |
| 229 | { |
| 230 | bool bReturn(false); |
| 231 | |
| 232 | /* check whether this value was changed */ |
| 233 | if (m_bSettingAutoEnabled == enabled) |
| 234 | return bReturn; |
| 235 | |
| 236 | m_bNeedsWrite = true; |
| 237 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning autonomous mode %s", enabled ? "on" : "off"); |
| 238 | |
| 239 | CCECAdapterMessage params; |
| 240 | params.PushEscaped(enabled ? 1 : 0); |
| 241 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_AUTO_ENABLED, params); |
| 242 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
| 243 | delete message; |
| 244 | |
| 245 | if (bReturn) |
| 246 | m_bSettingAutoEnabled = enabled; |
| 247 | |
| 248 | return bReturn; |
| 249 | } |
| 250 | |
| 251 | bool CUSBCECAdapterCommands::SetSettingDeviceType(cec_device_type type) |
| 252 | { |
| 253 | bool bReturn(false); |
| 254 | |
| 255 | /* check whether this value was changed */ |
| 256 | if (m_persistedConfiguration.deviceTypes.types[0] == type) |
| 257 | return bReturn; |
| 258 | |
| 259 | m_bNeedsWrite = true; |
| 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]); |
| 261 | |
| 262 | CCECAdapterMessage params; |
| 263 | params.PushEscaped((uint8_t)type); |
| 264 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_DEVICE_TYPE, params); |
| 265 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
| 266 | delete message; |
| 267 | |
| 268 | return bReturn; |
| 269 | } |
| 270 | |
| 271 | bool CUSBCECAdapterCommands::SetSettingDefaultLogicalAddress(cec_logical_address address) |
| 272 | { |
| 273 | bool bReturn(false); |
| 274 | |
| 275 | /* check whether this value was changed */ |
| 276 | if (m_persistedConfiguration.logicalAddresses.primary == address) |
| 277 | return bReturn; |
| 278 | |
| 279 | m_bNeedsWrite = true; |
| 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); |
| 281 | |
| 282 | CCECAdapterMessage params; |
| 283 | params.PushEscaped((uint8_t)address); |
| 284 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_DEFAULT_LOGICAL_ADDRESS, params); |
| 285 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
| 286 | delete message; |
| 287 | |
| 288 | if (bReturn) |
| 289 | m_persistedConfiguration.logicalAddresses.primary = address; |
| 290 | |
| 291 | return bReturn; |
| 292 | } |
| 293 | |
| 294 | bool CUSBCECAdapterCommands::SetSettingLogicalAddressMask(uint16_t iMask) |
| 295 | { |
| 296 | bool bReturn(false); |
| 297 | |
| 298 | /* check whether this value was changed */ |
| 299 | if (m_iSettingLAMask == iMask) |
| 300 | return bReturn; |
| 301 | |
| 302 | m_bNeedsWrite = true; |
| 303 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask); |
| 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); |
| 309 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
| 310 | delete message; |
| 311 | |
| 312 | if (bReturn) |
| 313 | m_iSettingLAMask = iMask; |
| 314 | |
| 315 | return bReturn; |
| 316 | } |
| 317 | |
| 318 | bool CUSBCECAdapterCommands::SetSettingPhysicalAddress(uint16_t iPhysicalAddress) |
| 319 | { |
| 320 | bool bReturn(false); |
| 321 | |
| 322 | /* check whether this value was changed */ |
| 323 | if (m_persistedConfiguration.iPhysicalAddress == iPhysicalAddress) |
| 324 | return bReturn; |
| 325 | |
| 326 | m_bNeedsWrite = true; |
| 327 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X (previous: %04X)", iPhysicalAddress, m_persistedConfiguration.iPhysicalAddress); |
| 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); |
| 333 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
| 334 | delete message; |
| 335 | |
| 336 | if (bReturn) |
| 337 | m_persistedConfiguration.iPhysicalAddress = iPhysicalAddress; |
| 338 | |
| 339 | return bReturn; |
| 340 | } |
| 341 | |
| 342 | bool CUSBCECAdapterCommands::SetSettingCECVersion(cec_version version) |
| 343 | { |
| 344 | bool bReturn(false); |
| 345 | |
| 346 | /* check whether this value was changed */ |
| 347 | if (m_settingCecVersion == version) |
| 348 | return bReturn; |
| 349 | |
| 350 | m_bNeedsWrite = true; |
| 351 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s (previous: %s)", ToString(version), ToString(m_settingCecVersion)); |
| 352 | |
| 353 | CCECAdapterMessage params; |
| 354 | params.PushEscaped((uint8_t)version); |
| 355 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_HDMI_VERSION, params); |
| 356 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
| 357 | delete message; |
| 358 | |
| 359 | if (bReturn) |
| 360 | m_settingCecVersion = version; |
| 361 | |
| 362 | return bReturn; |
| 363 | } |
| 364 | |
| 365 | bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName) |
| 366 | { |
| 367 | bool bReturn(false); |
| 368 | |
| 369 | /* check whether this value was changed */ |
| 370 | if (!strcmp(m_persistedConfiguration.strDeviceName, strOSDName)) |
| 371 | return bReturn; |
| 372 | |
| 373 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s (previous: %s)", strOSDName, m_persistedConfiguration.strDeviceName); |
| 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); |
| 379 | bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; |
| 380 | delete message; |
| 381 | |
| 382 | if (bReturn) |
| 383 | snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", strOSDName); |
| 384 | |
| 385 | return bReturn; |
| 386 | } |
| 387 | |
| 388 | bool CUSBCECAdapterCommands::WriteEEPROM(void) |
| 389 | { |
| 390 | if (!m_bNeedsWrite) |
| 391 | return true; |
| 392 | |
| 393 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "writing settings in the EEPROM"); |
| 394 | |
| 395 | CCECAdapterMessage params; |
| 396 | CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_WRITE_EEPROM, params); |
| 397 | m_bNeedsWrite = !(message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED); |
| 398 | delete message; |
| 399 | return m_bNeedsWrite; |
| 400 | } |
| 401 | |
| 402 | bool CUSBCECAdapterCommands::PersistConfiguration(const libcec_configuration &configuration) |
| 403 | { |
| 404 | bool bReturn(false); |
| 405 | if (m_persistedConfiguration.iFirmwareVersion < 2) |
| 406 | return bReturn; |
| 407 | |
| 408 | if (!RequestSettings()) |
| 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); |
| 418 | |
| 419 | return bReturn; |
| 420 | } |
| 421 | |
| 422 | bool CUSBCECAdapterCommands::RequestSettings(void) |
| 423 | { |
| 424 | if (m_persistedConfiguration.iFirmwareVersion < 2) |
| 425 | { |
| 426 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - firmware version %d does not have any eeprom settings", __FUNCTION__, m_persistedConfiguration.iFirmwareVersion); |
| 427 | // settings can only be persisted with firmware v2+ |
| 428 | return false; |
| 429 | } |
| 430 | |
| 431 | if (m_bSettingsRetrieved) |
| 432 | return true; |
| 433 | |
| 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(); |
| 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) |
| 460 | |
| 461 | m_bSettingsRetrieved = true; |
| 462 | |
| 463 | return bReturn; |
| 464 | } |
| 465 | |
| 466 | bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration &configuration) |
| 467 | { |
| 468 | // get the settings from the eeprom if needed |
| 469 | if (!RequestSettings()) |
| 470 | return false; |
| 471 | |
| 472 | // copy the settings |
| 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); |
| 477 | |
| 478 | return true; |
| 479 | } |
| 480 | |
| 481 | bool CUSBCECAdapterCommands::PingAdapter(void) |
| 482 | { |
| 483 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending ping"); |
| 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 | |
| 492 | bool CUSBCECAdapterCommands::SetAckMask(uint16_t iMask) |
| 493 | { |
| 494 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask); |
| 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 | |
| 505 | bool CUSBCECAdapterCommands::StartBootloader(void) |
| 506 | { |
| 507 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "starting the bootloader"); |
| 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 | |
| 516 | bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout) |
| 517 | { |
| 518 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the line timeout to %d", iTimeout); |
| 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 | |
| 527 | bool CUSBCECAdapterCommands::SetControlledMode(bool controlled) |
| 528 | { |
| 529 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off"); |
| 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 | } |