Merge branch 'master' of github.com:Pulse-Eight/libcec
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 7 Dec 2011 22:57:53 +0000 (23:57 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 7 Dec 2011 22:57:53 +0000 (23:57 +0100)
1  2 
src/lib/CECProcessor.cpp

diff --combined src/lib/CECProcessor.cpp
index 210f44b38dca04217b290dfce29ed528d7025a6d,7a1dcad90a422eaa725500b5c4528c414703223d..e1e03b868d1ee6925bf319fd26c6f2b29fb801a8
@@@ -152,10 -152,8 +152,10 @@@ bool CCECProcessor::Start(const char *s
      }
  
      lock.Leave();
 -    if (SetAckMask(m_logicalAddresses.AckMask()) &&
 -        SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true))
 +
 +    m_busDevices[CECDEVICE_TV]->GetVendorId();
 +
 +    if (SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true))
      {
        m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
        m_busScan = new CCECBusScan(this);
@@@ -262,7 -260,8 +262,7 @@@ void *CCECProcessor::Process(void
    }
    else
    {
 -    m_busDevices[CECDEVICE_TV]->GetVendorId();
 -    m_busDevices[m_logicalAddresses.primary]->TransmitVendorID(CECDEVICE_TV, false);
 +    SetAckMask(m_logicalAddresses.AckMask());
  
      CLockObject lock(&m_mutex);
      m_bStarted = true;
@@@ -396,54 -395,44 +396,54 @@@ bool CCECProcessor::SetHDMIPort(cec_log
  {
    bool bReturn(false);
  
 -  CStdString strLog;
 -  strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
 -  AddLog(CEC_LOG_DEBUG, strLog);
 -
    m_iBaseDevice = iBaseDevice;
    m_iHDMIPort = iPort;
    if (!m_bStarted && !bForce)
      return true;
  
 +  CStdString strLog;
 +  strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
 +  AddLog(CEC_LOG_DEBUG, strLog);
 +
    uint16_t iPhysicalAddress(0);
 -  iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
 -  uint16_t iPos = 0;
 -  if (iPhysicalAddress == 0)
 -    iPos = 0x1000;
 -  else if (iPhysicalAddress % 0x1000 == 0)
 -    iPos = 0x100;
 -  else if (iPhysicalAddress % 0x100 == 0)
 -    iPos = 0x10;
 -  else if (iPhysicalAddress % 0x10 == 0)
 -    iPos = 0x1;
 -
 -  while(!bReturn && iPos > 0)
 +  if (iBaseDevice > CECDEVICE_TV)
 +    iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
 +
 +  if (iPhysicalAddress == 0xffff)
    {
 -    iPhysicalAddress += (uint16_t)(iPort * iPos);
 -    strLog.Format("checking physical address %4x", iPhysicalAddress);
 -    AddLog(CEC_LOG_DEBUG, strLog);
 -    if (PhysicalAddressInUse(iPhysicalAddress))
 -    {
 -      strLog.Format("physical address %4x is in use", iPhysicalAddress);
 -      AddLog(CEC_LOG_DEBUG, strLog);
 -      iPos = (iPos == 1) ? 0 : iPos / 0x10;
 -    }
 -    else
 +    SetPhysicalAddress((uint16_t)iPort * 0x1000);
 +    bReturn = false;
 +  }
 +  else
 +  {
 +    uint16_t iPos = 0;
 +    if (iPhysicalAddress == 0)
 +      iPos = 0x1000;
 +    else if (iPhysicalAddress % 0x1000 == 0)
 +      iPos = 0x100;
 +    else if (iPhysicalAddress % 0x100 == 0)
 +      iPos = 0x10;
 +    else if (iPhysicalAddress % 0x10 == 0)
 +      iPos = 0x1;
 +
 +    while(!bReturn && iPos > 0)
      {
 -      strLog.Format("physical address %4x is free", iPhysicalAddress);
 +      iPhysicalAddress += (uint16_t)(iPort * iPos);
 +      strLog.Format("checking physical address %4x", iPhysicalAddress);
        AddLog(CEC_LOG_DEBUG, strLog);
 -      SetPhysicalAddress(iPhysicalAddress);
 -      bReturn = true;
 +      if (PhysicalAddressInUse(iPhysicalAddress))
 +      {
 +        strLog.Format("physical address %4x is in use", iPhysicalAddress);
 +        AddLog(CEC_LOG_DEBUG, strLog);
 +        iPos = (iPos == 1) ? 0 : iPos / 0x10;
 +      }
 +      else
 +      {
 +        strLog.Format("physical address %4x is free", iPhysicalAddress);
 +        AddLog(CEC_LOG_DEBUG, strLog);
 +        SetPhysicalAddress(iPhysicalAddress);
 +        bReturn = true;
 +      }
      }
    }
  
@@@ -532,7 -521,6 +532,7 @@@ bool CCECProcessor::SetPhysicalAddress(
      for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
        if (m_logicalAddresses[iPtr])
        {
 +        m_busDevices[iPtr]->SetInactiveDevice();
          m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
          m_busDevices[iPtr]->TransmitPhysicalAddress();
        }
@@@ -681,13 -669,6 +681,13 @@@ uint64_t CCECProcessor::GetDeviceVendor
    return false;
  }
  
 +uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress)
 +{
 +  if (m_busDevices[iAddress])
 +    return m_busDevices[iAddress]->GetPhysicalAddress(false);
 +  return false;
 +}
 +
  cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
  {
    if (m_busDevices[iAddress])
    return CEC_POWER_STATUS_UNKNOWN;
  }
  
 +cec_logical_address CCECProcessor::GetActiveSource(void)
 +{
 +  for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
 +  {
 +    if (m_busDevices[iPtr]->IsActiveSource())
 +      return (cec_logical_address)iPtr;
 +  }
 +
 +  return CECDEVICE_UNKNOWN;
 +}
 +
 +bool CCECProcessor::IsActiveSource(cec_logical_address iAddress)
 +{
 +  return m_busDevices[iAddress]->IsActiveSource();
 +}
 +
  bool CCECProcessor::Transmit(const cec_command &data)
  {
    bool bReturn(false);
@@@ -1335,7 -1300,7 +1335,7 @@@ void *CCECBusScan::Process(void
  
    while (!IsStopped())
    {
 -    if (++iCounter < 30)
 +    if (++iCounter < 10)
      {
        Sleep(1000);
        continue;
@@@ -1365,11 -1330,11 +1365,11 @@@ void CCECBusScan::WaitUntilIdle(void
    if (IsStopped())
      return;
  
-   int64_t iWaitTime = 3000 - (GetTimeMs() - m_processor->GetLastTransmission());
+   int32_t iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
    while (iWaitTime > 0)
    {
      Sleep(iWaitTime);
-     iWaitTime = 3000 - (GetTimeMs() - m_processor->GetLastTransmission());
+     iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
    }
  }