void CCECProcessor::CreateBusDevices(void)
{
- for (int iPtr = 0; iPtr < 16; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
{
switch(iPtr)
{
case CECDEVICE_AUDIOSYSTEM:
- m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+ m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr);
break;
case CECDEVICE_PLAYBACKDEVICE1:
case CECDEVICE_PLAYBACKDEVICE2:
case CECDEVICE_PLAYBACKDEVICE3:
- m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+ m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr);
break;
case CECDEVICE_RECORDINGDEVICE1:
case CECDEVICE_RECORDINGDEVICE2:
case CECDEVICE_RECORDINGDEVICE3:
- m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+ m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr);
break;
case CECDEVICE_TUNER1:
case CECDEVICE_TUNER2:
case CECDEVICE_TUNER3:
case CECDEVICE_TUNER4:
- m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+ m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr);
break;
case CECDEVICE_TV:
- m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, CEC_PHYSICAL_ADDRESS_TV);
+ m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr);
break;
default:
- m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+ m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr);
break;
}
}
{
Close();
- for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
{
delete m_busDevices[iPtr];
m_busDevices[iPtr] = NULL;
m_configuration.iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
CStdString strLog;
strLog.Format("connected to the CEC adapter. libCEC version = %s, client version = %s, firmware version = %d", ToString((cec_server_version)m_configuration.serverVersion), ToString((cec_client_version)m_configuration.clientVersion), m_configuration.iFirmwareVersion);
- if (m_configuration.iFirmwareBuildDate != CEC_DEFAULT_FIRMWARE_BUILD_DATE)
+ if (m_configuration.iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN)
{
time_t buildTime = (time_t)m_configuration.iFirmwareBuildDate;
strLog.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime)));
CLockObject lock(m_mutex);
if (!config.deviceTypes.IsEmpty())
m_configuration.deviceTypes = config.deviceTypes;
- if (config.iPhysicalAddress > 0)
+ if (IsValidPhysicalAddress(config.iPhysicalAddress))
m_configuration.iPhysicalAddress = config.iPhysicalAddress;
snprintf(m_configuration.strDeviceName, 13, "%s", config.strDeviceName);
}
memcpy(language.language, m_configuration.strDeviceLanguage, 3);
language.language[3] = 0;
- for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
{
if (m_configuration.logicalAddresses[iPtr])
{
/* get the vendor id from the TV, so we are using the correct handler */
m_busDevices[CECDEVICE_TV]->GetVendorId();
- if (m_configuration.iPhysicalAddress != 0)
+ if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
{
- CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_configuration.iPhysicalAddress);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %04X", m_configuration.iPhysicalAddress);
m_busDevices[m_configuration.logicalAddresses.primary]->m_iPhysicalAddress = m_configuration.iPhysicalAddress;
if ((bReturn = m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPhysicalAddress()) == false)
- CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_configuration.iPhysicalAddress);
+ CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %04X", m_configuration.iPhysicalAddress);
}
- else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false)
+ else
{
- CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
+ if (!SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true))
+ CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
bReturn = true;
}
CCECBusDevice *previousDevice = GetDeviceByType(from);
m_configuration.logicalAddresses.primary = CECDEVICE_UNKNOWN;
- for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+ for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
{
if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
continue;
return false;
}
- for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+ for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
{
if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
continue;
{
if (!IsInitialised())
return;
- for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
m_busDevices[iPtr]->ReplaceHandler(m_bInitialised);
}
if (type != CEC_DEVICE_TYPE_RESERVED)
{
- for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
{
if (m_configuration.logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
{
}
m_busDevices[addr]->SetActiveSource();
- if (m_busDevices[addr]->GetPhysicalAddress() != CEC_INVALID_PHYSICAL_ADDRESS)
+ if (IsValidPhysicalAddress(m_busDevices[addr]->GetPhysicalAddress()))
bReturn = m_busDevices[addr]->ActivateSource();
return bReturn;
{
CLockObject lock(m_mutex);
m_configuration.baseDevice = iBaseDevice;
- m_configuration.iHDMIPort = iPort;
+ m_configuration.iHDMIPort = iPort;
}
if (!IsRunning() && !bForce)
bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
{
- for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
{
if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
return true;
bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
{
- for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
{
if (m_configuration.logicalAddresses[iPtr])
m_busDevices[iPtr]->SetMenuState(state);
{
CLockObject lock(m_mutex);
m_configuration.iPhysicalAddress = iPhysicalAddress;
- CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%4x'", iPhysicalAddress);
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%04X'", iPhysicalAddress);
if (!m_configuration.logicalAddresses.IsEmpty())
{
bool bWasActiveSource(false);
- for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
if (m_configuration.logicalAddresses[iPtr])
{
bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource();
}
}
- for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
if (sendUpdatesTo[iPtr])
m_busDevices[iPtr]->TransmitPhysicalAddress();
uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
{
- uint8_t status = 0;
+ uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease);
uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
{
- uint8_t status = 0;
+ uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease);
uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */)
{
- uint8_t status = 0;
+ uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease);
{
CCECBusDevice *device(NULL);
- // invalid PA
- if (iPhysicalAddress == CEC_INVALID_PHYSICAL_ADDRESS)
- return device;
-
// check each device until we found a match
- for (unsigned int iPtr = 0; !device && iPtr < 16; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; !device && iPtr < CECDEVICE_BROADCAST; iPtr++)
{
if (m_busDevices[iPtr]->GetPhysicalAddress(bSuppressUpdate) == iPhysicalAddress)
device = m_busDevices[iPtr];
{
CCECBusDevice *device = NULL;
- for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
{
if (m_busDevices[iPtr]->m_type == type && m_configuration.logicalAddresses[iPtr])
{
cec_logical_address CCECProcessor::GetActiveSource(bool bRequestActiveSource /* = true */)
{
- for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
{
if (m_busDevices[iPtr]->IsActiveSource())
return (cec_logical_address)iPtr;
{
cec_logical_addresses addresses;
addresses.Clear();
- for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
{
if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
addresses.Set((cec_logical_address) iPtr);
bool CCECProcessor::IsPresentDeviceType(cec_device_type type)
{
- for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
{
if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
return true;
{
CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
- if (iPhysicalAddress != 0)
+ if (IsValidPhysicalAddress(iPhysicalAddress))
{
m_configuration.bAutodetectAddress = 1;
- m_configuration.iPhysicalAddress = iPhysicalAddress;
- m_configuration.baseDevice = CECDEVICE_UNKNOWN;
- m_configuration.iHDMIPort = 0;
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ m_configuration.iHDMIPort = CEC_HDMI_PORTNUMBER_NONE;
return SetPhysicalAddress(iPhysicalAddress);
}
return false;
if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
{
bool bReturn(true);
- for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
{
if (m_configuration.powerOffDevices[iPtr])
{
if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
{
bool bReturn(true);
- for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
{
if (m_configuration.wakeDevices[iPtr])
{
return "info index search reverse";
case CEC_DECK_INFO_OTHER_STATUS:
return "other";
+ case CEC_DECK_INFO_OTHER_STATUS_LG:
+ return "LG other";
default:
return "unknown";
}
if (IsRunning() && configuration->bAutodetectAddress == 1)
{
uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
- if (iPhysicalAddress != 0)
+ if (IsValidPhysicalAddress(iPhysicalAddress))
{
if (IsRunning())
- CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%4x'", __FUNCTION__, iPhysicalAddress);
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%04X'", __FUNCTION__, iPhysicalAddress);
else
- CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%x'", __FUNCTION__, iPhysicalAddress);
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%04X'", __FUNCTION__, iPhysicalAddress);
bPhysicalAddressChanged = (m_configuration.iPhysicalAddress != iPhysicalAddress);
m_configuration.iPhysicalAddress = iPhysicalAddress;
- m_configuration.iHDMIPort = 0;
- m_configuration.baseDevice = CECDEVICE_UNKNOWN;
- bPhysicalAutodetected = true;
+ m_configuration.iHDMIPort = CEC_HDMI_PORTNUMBER_NONE;
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ bPhysicalAutodetected = true;
}
}
// physical address
if (!bPhysicalAutodetected)
{
- if (configuration->iPhysicalAddress != 0)
- bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress;
+ uint16_t iPhysicalAddress(IsValidPhysicalAddress(configuration->iPhysicalAddress) ? configuration->iPhysicalAddress : CEC_PHYSICAL_ADDRESS_TV);
+ bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != iPhysicalAddress;
if (bPhysicalAddressChanged)
{
- CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%x'", __FUNCTION__, configuration->iPhysicalAddress);
- m_configuration.iPhysicalAddress = configuration->iPhysicalAddress;
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%04X'", __FUNCTION__, iPhysicalAddress);
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
}
}
bool bHdmiPortChanged(false);
- if (!bPhysicalAutodetected && !bPhysicalAddressChanged)
+ if (!IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
{
// base device
bHdmiPortChanged = IsRunning() && m_configuration.baseDevice != configuration->baseDevice;
CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using HDMI port '%d'", __FUNCTION__, configuration->iHDMIPort);
m_configuration.iHDMIPort = configuration->iHDMIPort;
}
- else
+ else if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
{
CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - resetting HDMI port and base device to defaults", __FUNCTION__);
m_configuration.baseDevice = CECDEVICE_UNKNOWN;
- m_configuration.iHDMIPort = 0;
+ m_configuration.iHDMIPort = CEC_HDMI_PORTNUMBER_NONE;
}
bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged;
{
if (bDeviceTypeChanged)
return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
- else if (bPhysicalAddressChanged)
+ else if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
return SetPhysicalAddress(m_configuration.iPhysicalAddress);
- else
+ else if (m_configuration.baseDevice != CECDEVICE_UNKNOWN && m_configuration.iHDMIPort != CEC_HDMI_PORTNUMBER_NONE)
return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort);
}
else if (m_configuration.bActivateSource == 1 && IsRunning() && !IsActiveSource(m_configuration.logicalAddresses.primary))
void CCECProcessor::RescanActiveDevices(void)
{
- for (unsigned int iPtr = 0; iPtr < CECDEVICE_BROADCAST; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
m_busDevices[iPtr]->GetStatus(true);
}
bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
{
bool bReturn(true);
- for (unsigned int iPtr = 0; iPtr < CECDEVICE_BROADCAST; iPtr++)
+ for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
bReturn &= m_busDevices[iPtr]->TransmitPendingActiveSourceCommands();
return bReturn;
}
+
+bool CCECProcessor::IsValidPhysicalAddress(uint16_t iPhysicalAddress)
+{
+ return iPhysicalAddress >= CEC_MIN_PHYSICAL_ADDRESS &&
+ iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS;
+}