X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fadapter%2FUSBCECAdapterCommands.cpp;h=6642ac838567a35dd0b0fc86cd0e3aa27028c968;hb=0a61dc2416f3eacb839ff67ac5abf0024c1d2f40;hp=5989bc9f49667db231ad704be123114b9b3272e3;hpb=c37545cf1873b9e4f735b227206ba57ad3b20a93;p=deb_libcec.git diff --git a/src/lib/adapter/USBCECAdapterCommands.cpp b/src/lib/adapter/USBCECAdapterCommands.cpp index 5989bc9..6642ac8 100644 --- a/src/lib/adapter/USBCECAdapterCommands.cpp +++ b/src/lib/adapter/USBCECAdapterCommands.cpp @@ -33,10 +33,14 @@ #include "USBCECAdapterCommands.h" #include "../LibCEC.h" #include "../CECProcessor.h" +#include "../CECTypeUtils.h" using namespace CEC; using namespace PLATFORM; +#define LIB_CEC m_comm->m_callback->GetLib() +#define ToString(p) CCECTypeUtils::ToString(p) + CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm) : m_comm(comm), m_bSettingsRetrieved(false), @@ -44,7 +48,7 @@ CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm m_settingCecVersion(CEC_VERSION_UNKNOWN), m_iSettingLAMask(0), m_bNeedsWrite(false), - m_iBuildDate(0) + m_iBuildDate(CEC_FW_BUILD_UNKNOWN) { m_persistedConfiguration.Clear(); } @@ -62,6 +66,7 @@ cec_datapacket CUSBCECAdapterCommands::RequestSetting(cec_adapter_messagecode ms retVal.Shift(2); // shift out start and msgcode retVal.size -= 1; // remove end } + delete message; return retVal; } @@ -73,20 +78,20 @@ uint16_t CUSBCECAdapterCommands::RequestFirmwareVersion(void) while (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN && iFwVersionTry++ < 3) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); cec_datapacket response = RequestSetting(MSGCODE_FIRMWARE_VERSION); if (response.size == 2) m_persistedConfiguration.iFirmwareVersion = (response[0] << 8 | response[1]); else { - CLibCEC::AddLog(CEC_LOG_WARNING, "the adapter did not respond with a correct firmware version (try %d)", iFwVersionTry); + LIB_CEC->AddLog(CEC_LOG_WARNING, "the adapter did not respond with a correct firmware version (try %d)", iFwVersionTry); CEvent::Sleep(500); } } if (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "defaulting to firmware version 1"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "defaulting to firmware version 1"); m_persistedConfiguration.iFirmwareVersion = 1; } @@ -95,13 +100,13 @@ uint16_t CUSBCECAdapterCommands::RequestFirmwareVersion(void) bool CUSBCECAdapterCommands::RequestSettingAutoEnabled(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting autonomous mode setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting autonomous mode setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_AUTO_ENABLED); if (response.size == 1) { m_bSettingAutoEnabled = response[0] == 1; - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted autonomous mode setting: '%s'", m_bSettingAutoEnabled ? "enabled" : "disabled"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted autonomous mode setting: '%s'", m_bSettingAutoEnabled ? "enabled" : "disabled"); return true; } return false; @@ -109,13 +114,13 @@ bool CUSBCECAdapterCommands::RequestSettingAutoEnabled(void) bool CUSBCECAdapterCommands::RequestSettingCECVersion(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting CEC version setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting CEC version setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_HDMI_VERSION); if (response.size == 1) { m_settingCecVersion = (cec_version)response[0]; - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted CEC version setting: '%s'", CLibCEC::GetInstance()->ToString(m_settingCecVersion)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted CEC version setting: '%s'", ToString(m_settingCecVersion)); return true; } return false; @@ -123,9 +128,9 @@ bool CUSBCECAdapterCommands::RequestSettingCECVersion(void) uint32_t CUSBCECAdapterCommands::RequestBuildDate(void) { - if (m_iBuildDate == 0) + if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting firmware build date"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting firmware build date"); cec_datapacket response = RequestSetting(MSGCODE_GET_BUILDDATE); if (response.size == 4) @@ -136,13 +141,13 @@ uint32_t CUSBCECAdapterCommands::RequestBuildDate(void) bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting default logical address setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting default logical address setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_DEFAULT_LOGICAL_ADDRESS); if (response.size == 1) { m_persistedConfiguration.logicalAddresses.primary = (cec_logical_address)response[0]; - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted logical address setting: '%s'", CLibCEC::GetInstance()->ToString(m_persistedConfiguration.logicalAddresses.primary)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address setting: '%s'", ToString(m_persistedConfiguration.logicalAddresses.primary)); return true; } return false; @@ -150,29 +155,29 @@ bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void) bool CUSBCECAdapterCommands::RequestSettingDeviceType(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting device type setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting device type setting"); m_persistedConfiguration.deviceTypes.Clear(); cec_datapacket response = RequestSetting(MSGCODE_GET_DEVICE_TYPE); if (response.size == 1) { m_persistedConfiguration.deviceTypes.Add((cec_device_type)response[0]); - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted device type setting: '%s'", CLibCEC::GetInstance()->ToString((cec_device_type)response[0])); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device type setting: '%s'", ToString((cec_device_type)response[0])); return true; } - CLibCEC::AddLog(CEC_LOG_DEBUG, "no persisted device type setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device type setting"); return false; } bool CUSBCECAdapterCommands::RequestSettingLogicalAddressMask(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting logical address mask setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting logical address mask setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_LOGICAL_ADDRESS_MASK); if (response.size == 2) { m_iSettingLAMask = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]); - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted logical address mask setting: '%x'", m_iSettingLAMask); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address mask setting: '%x'", m_iSettingLAMask); return true; } return false; @@ -180,13 +185,13 @@ bool CUSBCECAdapterCommands::RequestSettingLogicalAddressMask(void) bool CUSBCECAdapterCommands::RequestSettingOSDName(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting OSD name setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting OSD name setting"); memset(m_persistedConfiguration.strDeviceName, 0, 13); cec_datapacket response = RequestSetting(MSGCODE_GET_OSD_NAME); if (response.size == 0) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "no persisted device name setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device name setting"); return false; } @@ -196,22 +201,22 @@ bool CUSBCECAdapterCommands::RequestSettingOSDName(void) buf[response.size] = 0; snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", buf); - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted device name setting: '%s'", buf); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device name setting: '%s'", buf); return true; } bool CUSBCECAdapterCommands::RequestSettingPhysicalAddress(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting physical address setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting physical address setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_PHYSICAL_ADDRESS); if (response.size == 2) { m_persistedConfiguration.iPhysicalAddress = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]); - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted physical address setting: '%4x'", m_persistedConfiguration.iPhysicalAddress); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted physical address setting: '%4x'", m_persistedConfiguration.iPhysicalAddress); return true; } - CLibCEC::AddLog(CEC_LOG_DEBUG, "no persisted physical address setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted physical address setting"); return false; } @@ -222,12 +227,12 @@ bool CUSBCECAdapterCommands::SetSettingAutoEnabled(bool enabled) /* check whether this value was changed */ if (m_bSettingAutoEnabled == enabled) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "autonomous mode setting unchanged (%s)", enabled ? "on" : "off"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "autonomous mode setting unchanged (%s)", enabled ? "on" : "off"); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "turning autonomous mode %s", enabled ? "on" : "off"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning autonomous mode %s", enabled ? "on" : "off"); CCECAdapterMessage params; params.PushEscaped(enabled ? 1 : 0); @@ -248,12 +253,12 @@ bool CUSBCECAdapterCommands::SetSettingDeviceType(cec_device_type type) /* check whether this value was changed */ if (m_persistedConfiguration.deviceTypes.types[0] == type) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "device type setting unchanged (%X)", (uint8_t)type); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "device type setting unchanged (%X)", (uint8_t)type); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the device type to %X (previous: %X)", (uint8_t)type, (uint8_t)m_persistedConfiguration.deviceTypes.types[0]); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the device type to %X (previous: %X)", (uint8_t)type, (uint8_t)m_persistedConfiguration.deviceTypes.types[0]); CCECAdapterMessage params; params.PushEscaped((uint8_t)type); @@ -271,12 +276,12 @@ bool CUSBCECAdapterCommands::SetSettingDefaultLogicalAddress(cec_logical_address /* check whether this value was changed */ if (m_persistedConfiguration.logicalAddresses.primary == address) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address setting unchanged (%X)", (uint8_t)address); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "logical address setting unchanged (%X)", (uint8_t)address); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X (previous: %X)", (uint8_t)address, (uint8_t)m_persistedConfiguration.logicalAddresses.primary); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X (previous: %X)", (uint8_t)address, (uint8_t)m_persistedConfiguration.logicalAddresses.primary); CCECAdapterMessage params; params.PushEscaped((uint8_t)address); @@ -297,12 +302,12 @@ bool CUSBCECAdapterCommands::SetSettingLogicalAddressMask(uint16_t iMask) /* check whether this value was changed */ if (m_iSettingLAMask == iMask) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address mask setting unchanged (%2X)", iMask); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "logical address mask setting unchanged (%2X)", iMask); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask); CCECAdapterMessage params; params.PushEscaped(iMask >> 8); @@ -324,12 +329,12 @@ bool CUSBCECAdapterCommands::SetSettingPhysicalAddress(uint16_t iPhysicalAddress /* check whether this value was changed */ if (m_persistedConfiguration.iPhysicalAddress == iPhysicalAddress) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "physical address setting unchanged (%04X)", iPhysicalAddress); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "physical address setting unchanged (%04X)", iPhysicalAddress); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X (previous: %04X)", iPhysicalAddress, m_persistedConfiguration.iPhysicalAddress); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X (previous: %04X)", iPhysicalAddress, m_persistedConfiguration.iPhysicalAddress); CCECAdapterMessage params; params.PushEscaped(iPhysicalAddress >> 8); @@ -351,12 +356,12 @@ bool CUSBCECAdapterCommands::SetSettingCECVersion(cec_version version) /* check whether this value was changed */ if (m_settingCecVersion == version) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "CEC version setting unchanged (%s)", CLibCEC::GetInstance()->ToString(version)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "CEC version setting unchanged (%s)", ToString(version)); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s (previous: %s)", CLibCEC::GetInstance()->ToString(version), CLibCEC::GetInstance()->ToString(m_settingCecVersion)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s (previous: %s)", ToString(version), ToString(m_settingCecVersion)); CCECAdapterMessage params; params.PushEscaped((uint8_t)version); @@ -377,11 +382,11 @@ bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName) /* check whether this value was changed */ if (!strcmp(m_persistedConfiguration.strDeviceName, strOSDName)) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "OSD name setting unchanged (%s)", strOSDName); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "OSD name setting unchanged (%s)", strOSDName); return bReturn; } - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s (previous: %s)", strOSDName, m_persistedConfiguration.strDeviceName); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s (previous: %s)", strOSDName, m_persistedConfiguration.strDeviceName); CCECAdapterMessage params; for (size_t iPtr = 0; iPtr < strlen(strOSDName); iPtr++) @@ -401,7 +406,7 @@ bool CUSBCECAdapterCommands::WriteEEPROM(void) if (!m_bNeedsWrite) return true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "writing settings in the EEPROM"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "writing settings in the EEPROM"); CCECAdapterMessage params; CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_WRITE_EEPROM, params); @@ -410,7 +415,7 @@ bool CUSBCECAdapterCommands::WriteEEPROM(void) return m_bNeedsWrite; } -bool CUSBCECAdapterCommands::PersistConfiguration(libcec_configuration *configuration) +bool CUSBCECAdapterCommands::PersistConfiguration(const libcec_configuration &configuration) { if (m_persistedConfiguration.iFirmwareVersion < 2) return false; @@ -420,12 +425,12 @@ bool CUSBCECAdapterCommands::PersistConfiguration(libcec_configuration *configur bool bReturn(true); bReturn &= SetSettingAutoEnabled(true); - bReturn &= SetSettingDeviceType(CLibCEC::GetType(configuration->logicalAddresses.primary)); - bReturn &= SetSettingDefaultLogicalAddress(configuration->logicalAddresses.primary); - bReturn &= SetSettingLogicalAddressMask(CLibCEC::GetMaskForType(configuration->logicalAddresses.primary)); - bReturn &= SetSettingPhysicalAddress(configuration->iPhysicalAddress); + bReturn &= SetSettingDeviceType(CLibCEC::GetType(configuration.logicalAddresses.primary)); + bReturn &= SetSettingDefaultLogicalAddress(configuration.logicalAddresses.primary); + bReturn &= SetSettingLogicalAddressMask(CLibCEC::GetMaskForType(configuration.logicalAddresses.primary)); + bReturn &= SetSettingPhysicalAddress(configuration.iPhysicalAddress); bReturn &= SetSettingCECVersion(CEC_VERSION_1_3A); - bReturn &= SetSettingOSDName(configuration->strDeviceName); + bReturn &= SetSettingOSDName(configuration.strDeviceName); bReturn &= WriteEEPROM(); return bReturn; } @@ -434,7 +439,7 @@ bool CUSBCECAdapterCommands::RequestSettings(void) { if (m_persistedConfiguration.iFirmwareVersion < 2) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - firmware version %d does not have any eeprom settings", __FUNCTION__, m_persistedConfiguration.iFirmwareVersion); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - firmware version %d does not have any eeprom settings", __FUNCTION__, m_persistedConfiguration.iFirmwareVersion); // settings can only be persisted with firmware v2+ return false; } @@ -474,24 +479,24 @@ bool CUSBCECAdapterCommands::RequestSettings(void) return bReturn; } -bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration *configuration) +bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration &configuration) { // get the settings from the eeprom if needed if (!RequestSettings()) return false; // copy the settings - configuration->iFirmwareVersion = m_persistedConfiguration.iFirmwareVersion; - configuration->deviceTypes = m_persistedConfiguration.deviceTypes; - configuration->iPhysicalAddress = m_persistedConfiguration.iPhysicalAddress; - snprintf(configuration->strDeviceName, 13, "%s", m_persistedConfiguration.strDeviceName); + configuration.iFirmwareVersion = m_persistedConfiguration.iFirmwareVersion; + configuration.deviceTypes = m_persistedConfiguration.deviceTypes; + configuration.iPhysicalAddress = m_persistedConfiguration.iPhysicalAddress; + snprintf(configuration.strDeviceName, 13, "%s", m_persistedConfiguration.strDeviceName); return true; } bool CUSBCECAdapterCommands::PingAdapter(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "sending ping"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending ping"); CCECAdapterMessage params; CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_PING, params); @@ -502,7 +507,7 @@ bool CUSBCECAdapterCommands::PingAdapter(void) bool CUSBCECAdapterCommands::SetAckMask(uint16_t iMask) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask); CCECAdapterMessage params; params.PushEscaped(iMask >> 8); @@ -515,7 +520,7 @@ bool CUSBCECAdapterCommands::SetAckMask(uint16_t iMask) bool CUSBCECAdapterCommands::StartBootloader(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "starting the bootloader"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "starting the bootloader"); CCECAdapterMessage params; CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_START_BOOTLOADER, params); @@ -526,7 +531,7 @@ bool CUSBCECAdapterCommands::StartBootloader(void) bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the line timeout to %d", iTimeout); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the line timeout to %d", iTimeout); CCECAdapterMessage params; params.PushEscaped(iTimeout); CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_TRANSMIT_IDLETIME, params); @@ -537,7 +542,7 @@ bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout) bool CUSBCECAdapterCommands::SetControlledMode(bool controlled) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off"); CCECAdapterMessage params; params.PushEscaped(controlled ? 1 : 0);