cec: always refresh the power state of a device when it hasn't been updated for 30...
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 11 Jan 2012 00:42:55 +0000 (01:42 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 11 Jan 2012 00:42:55 +0000 (01:42 +0100)
include/cectypes.h
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h

index ab4dcd862de8faeb5ed264fe81bb1b55405851a0..1ad7d407fc24362c14862c1568d8f4f5f5fb62d5 100644 (file)
@@ -64,6 +64,7 @@ namespace CEC {
 #define MSGESC                       0xFD
 #define ESCOFFSET                    3
 #define CEC_BUTTON_TIMEOUT           500
+#define CEC_POWER_STATE_REFRESH_TIME 30000
 
 #define CEC_DEFAULT_TRANSMIT_TIMEOUT 1000
 #define CEC_DEFAULT_TRANSMIT_WAIT    2000
index 9e9145c0e76af2f4b2abcd70c60182f189166722..d6e447f96303f44cf91735807601704451a01df0 100644 (file)
@@ -54,6 +54,7 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi
   m_menuState(CEC_MENU_STATE_ACTIVATED),
   m_bActiveSource(false),
   m_iLastActive(0),
+  m_iLastPowerStateUpdate(0),
   m_cecVersion(CEC_VERSION_UNKNOWN),
   m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN),
   m_handlerMutex(false)
@@ -314,7 +315,9 @@ cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */)
     CLockObject lock(&m_mutex);
     bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
         (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN ||
-            m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON));
+            m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON ||
+            m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY ||
+            GetTimeMs() - m_iLastPowerStateUpdate >= CEC_POWER_STATE_REFRESH_TIME));
   }
 
   if (bRequestUpdate)
@@ -619,6 +622,7 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
   CLockObject lock(&m_mutex);
   if (m_powerStatus != powerStatus)
   {
+    m_iLastPowerStateUpdate = GetTimeMs();
     CStdString strLog;
     strLog.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus));
     m_processor->AddLog(CEC_LOG_DEBUG, strLog);
index 6157e0a7448adf81a235d9631fc28b37f5e8718d..2bef3a7657d5f61afb81c55f76d02e1950edfc9d 100644 (file)
@@ -132,6 +132,7 @@ namespace CEC
     cec_menu_state        m_menuState;
     bool                  m_bActiveSource;
     uint64_t              m_iLastActive;
+    uint64_t              m_iLastPowerStateUpdate;
     cec_version           m_cecVersion;
     cec_bus_device_status m_deviceStatus;
     std::set<cec_opcode>  m_unsupportedFeatures;