CLockObject lock(&m_transmitMutex);
m_iLastActive = GetTimeMs();
m_handler->HandleCommand(command);
+ if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
+ m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
m_condition.Signal();
return true;
}
bool CCECBusDevice::PowerOn(void)
{
- cec_power_status current = GetPowerStatus();
- if (current != CEC_POWER_STATUS_ON &&
- current != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)
- {
- CStdString strLog;
- strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
- AddLog(CEC_LOG_DEBUG, strLog.c_str());
+ CStdString strLog;
+ strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+ AddLog(CEC_LOG_DEBUG, strLog.c_str());
- SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
-
- cec_command command;
- cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON);
-
- return m_processor->Transmit(command);
+ cec_command command;
+ cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON);
+ if (m_processor->Transmit(command))
+ {
+ GetPowerStatus();
+ return true;
}
- return true;
+ return false;
}
bool CCECBusDevice::Standby(void)
return m_processor->GetPhysicalAddress();
}
+uint16_t CCECBusDevice::GetPhysicalAddress(bool bRefresh /* = true */)
+{
+ if (GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+ {
+ CLockObject lock(&m_mutex);
+ if (m_iPhysicalAddress == 0xFFFF || bRefresh)
+ {
+ lock.Leave();
+ RequestPhysicalAddress();
+ lock.Lock();
+ }
+ }
+
+ CLockObject lock(&m_mutex);
+ return m_iPhysicalAddress;
+}
+
+bool CCECBusDevice::RequestPhysicalAddress(void)
+{
+ bool bReturn(false);
+ if (!MyLogicalAddressContains(m_iLogicalAddress))
+ {
+ CStdString strLog;
+ strLog.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+ AddLog(CEC_LOG_NOTICE, strLog);
+ cec_command command;
+ cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS);
+ CLockObject lock(&m_transmitMutex);
+ if (m_processor->Transmit(command))
+ bReturn = m_condition.Wait(&m_transmitMutex, 1000);
+ }
+ return bReturn;
+}
+
cec_power_status CCECBusDevice::GetPowerStatus(void)
{
CLockObject lock(&m_mutex);
void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
{
CLockObject lock(&m_mutex);
- if (iNewAddress > 0)
+ if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress)
{
CStdString strLog;
strLog.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
if (iNewAddress > 0)
{
CStdString strLog;
- strLog.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress, iNewAddress);
+ strLog.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress);
AddLog(CEC_LOG_DEBUG, strLog.c_str());
m_iStreamPath = iNewAddress;
cec_command command;
cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_NONE);
- CLockObject lock(&m_transmitMutex);
- bReturn = m_processor->Transmit(command);
+ {
+ CLockObject lock(&m_transmitMutex);
+ bReturn = m_processor->Transmit(command);
+ }
+
AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent");
+
+ if (bReturn)
+ {
+ CLockObject lock(&m_mutex);
+ m_iLastActive = GetTimeMs();
+ }
+
return bReturn;
}
return m_processor->Transmit(command);
}
}
+
+bool CCECBusDevice::SendKeypress(cec_user_control_code key, bool bWait /* = false */)
+{
+ {
+ CLockObject lock(&m_transmitMutex);
+ cec_command command;
+ cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_PRESSED);
+ command.parameters.PushBack(key);
+
+ if (bWait)
+ {
+ if (m_processor->Transmit(command))
+ return m_condition.Wait(&m_transmitMutex, 1000);
+ return false;
+ }
+
+ return m_processor->Transmit(command);
+ }
+}
+
+bool CCECBusDevice::SendKeyRelease(bool bWait /* = false */)
+{
+ {
+ CLockObject lock(&m_transmitMutex);
+ cec_command command;
+ cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_RELEASE);
+
+ if (bWait)
+ {
+ if (m_processor->Transmit(command))
+ return m_condition.Wait(&m_transmitMutex, 1000);
+ return false;
+ }
+ else
+ {
+ return m_processor->Transmit(command);
+ }
+ }
+}
//@}