using namespace CEC;
using namespace PLATFORM;
+#define LIB_CEC m_comm->m_callback->GetLib()
+#define ToString(p) LIB_CEC->ToString(p)
+
CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm) :
m_comm(comm),
m_bSettingsRetrieved(false),
m_bSettingAutoEnabled(false),
m_settingCecVersion(CEC_VERSION_UNKNOWN),
m_iSettingLAMask(0),
- m_bNeedsWrite(false)
+ m_bNeedsWrite(false),
+ m_iBuildDate(CEC_FW_BUILD_UNKNOWN)
{
m_persistedConfiguration.Clear();
}
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;
}
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;
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted autonomous mode setting: '%s'", m_bSettingAutoEnabled ? "enabled" : "disabled");
return true;
}
return false;
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];
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted CEC version setting: '%s'", ToString(m_settingCecVersion));
return true;
}
return false;
}
+uint32_t CUSBCECAdapterCommands::RequestBuildDate(void)
+{
+ if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting firmware build date");
+
+ cec_datapacket response = RequestSetting(MSGCODE_GET_BUILDDATE);
+ if (response.size == 4)
+ m_iBuildDate = (uint32_t)response[0] << 24 | (uint32_t)response[1] << 16 | (uint32_t)response[2] << 8 | (uint32_t)response[3];
+ }
+ return m_iBuildDate;
+}
+
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];
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address setting: '%s'", ToString(m_persistedConfiguration.logicalAddresses.primary));
return true;
}
return false;
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]);
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address mask setting: '%x'", m_iSettingLAMask);
return true;
}
return false;
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;
}
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;
}
/* 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);
/* 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", (uint8_t)type);
+ 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);
/* 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", (uint8_t)address);
+ 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);
/* 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", iMask);
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask);
CCECAdapterMessage params;
params.PushEscaped(iMask >> 8);
/* check whether this value was changed */
if (m_persistedConfiguration.iPhysicalAddress == iPhysicalAddress)
{
- CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address mask 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", 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);
/* 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", CLibCEC::GetInstance()->ToString(version));
+ 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);
/* 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", strOSDName);
+ 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++)
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);
return m_bNeedsWrite;
}
-bool CUSBCECAdapterCommands::PersistConfiguration(libcec_configuration *configuration)
+bool CUSBCECAdapterCommands::PersistConfiguration(const libcec_configuration &configuration)
{
if (m_persistedConfiguration.iFirmwareVersion < 2)
return false;
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;
}
{
if (m_persistedConfiguration.iFirmwareVersion < 2)
{
+ 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;
}
- if (!m_bSettingsRetrieved)
+ if (m_bSettingsRetrieved)
return true;
bool bReturn(true);
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);
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);
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);
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);
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);