press & hold
[deb_libcec.git] / src / lib / CECClient.cpp
index 9a28916b48bf0a42ff7bd0bd17ac06f651f7f30a..2e0045ced209f8f856406b990458d93840069d1d 100644 (file)
@@ -184,8 +184,18 @@ bool CCECClient::SetHDMIPort(const cec_logical_address iBaseDevice, const uint8_
   // set the default address when something went wrong
   if (!bReturn)
   {
-    LIB_CEC->AddLog(CEC_LOG_WARNING, "failed to set the physical address to %04X, setting it to the default value %04X", iPhysicalAddress, CEC_DEFAULT_PHYSICAL_ADDRESS);
-    iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
+    uint16_t iEepromAddress = m_processor->GetPhysicalAddressFromEeprom();
+    if (CLibCEC::IsValidPhysicalAddress(iEepromAddress))
+    {
+      LIB_CEC->AddLog(CEC_LOG_WARNING, "failed to set the physical address to %04X, setting it to the value that was persisted in the eeprom, %04X", iPhysicalAddress, iEepromAddress);
+      iPhysicalAddress = iEepromAddress;
+      bReturn = true;
+    }
+    else
+    {
+      LIB_CEC->AddLog(CEC_LOG_WARNING, "failed to set the physical address to %04X, setting it to the default value %04X", iPhysicalAddress, CEC_DEFAULT_PHYSICAL_ADDRESS);
+      iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
+    }
   }
 
   // and set the address
@@ -198,7 +208,7 @@ bool CCECClient::SetHDMIPort(const cec_logical_address iBaseDevice, const uint8_
 
 void CCECClient::ResetPhysicalAddress(void)
 {
-  SetPhysicalAddress(m_configuration);
+  SetPhysicalAddress(CEC_DEFAULT_PHYSICAL_ADDRESS);
 }
 
 void CCECClient::SetPhysicalAddress(const libcec_configuration &configuration)
@@ -927,24 +937,25 @@ void CCECClient::AddKey(bool bSendComboKey /* = false */)
 
 void CCECClient::AddKey(const cec_keypress &key)
 {
-  // send back the previous key if there is one
-  AddKey();
+  if (key.keycode > CEC_USER_CONTROL_CODE_MAX &&
+      key.keycode < CEC_USER_CONTROL_CODE_SELECT)
+  {
+    // send back the previous key if there is one
+    AddKey();
+    return;
+  }
 
   cec_keypress transmitKey(key);
 
   {
     CLockObject lock(m_mutex);
-    if (key.duration > 0 || key.keycode > CEC_USER_CONTROL_CODE_MAX)
-    {
-      transmitKey.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
-    }
-    else if (m_iCurrentButton == COMBO_KEY)
+    if (m_iCurrentButton == COMBO_KEY && key.duration == 0)
     {
       // stop + ok -> exit
       if (key.keycode == CEC_USER_CONTROL_CODE_SELECT)
         transmitKey.keycode = CEC_USER_CONTROL_CODE_EXIT;
       // stop + pause -> root menu
-      else if (key.keycode == CEC_USER_CONTROL_CODE_ROOT_MENU)
+      else if (key.keycode == CEC_USER_CONTROL_CODE_PAUSE)
         transmitKey.keycode = CEC_USER_CONTROL_CODE_ROOT_MENU;
       // stop + play -> dot (which is handled as context menu in xbmc)
       else if (key.keycode == CEC_USER_CONTROL_CODE_PLAY)
@@ -954,12 +965,26 @@ void CCECClient::AddKey(const cec_keypress &key)
         AddKey(true);
     }
 
-    m_iCurrentButton = transmitKey.keycode;
-    m_buttontime = m_iCurrentButton == CEC_USER_CONTROL_CODE_UNKNOWN || key.duration > 0 ? 0 : GetTimeMs();
+    if (m_iCurrentButton == key.keycode)
+    {
+      m_buttontime = GetTimeMs();
+    }
+    else
+    {
+      AddKey();
+      if (key.duration == 0)
+      {
+        m_iCurrentButton = transmitKey.keycode;
+        m_buttontime = m_iCurrentButton == CEC_USER_CONTROL_CODE_UNKNOWN || key.duration > 0 ? 0 : GetTimeMs();
+      }
+    }
   }
 
-  LIB_CEC->AddLog(CEC_LOG_DEBUG, "key pressed: %s (%1x)", ToString(transmitKey.keycode), transmitKey.keycode);
-  CallbackAddKey(transmitKey);
+  if (key.keycode != COMBO_KEY || key.duration > 0)
+  {
+    LIB_CEC->AddLog(CEC_LOG_DEBUG, "key pressed: %s (%1x)", ToString(transmitKey.keycode), transmitKey.keycode);
+    CallbackAddKey(transmitKey);
+  }
 }
 
 void CCECClient::SetCurrentButton(const cec_user_control_code iButtonCode)
@@ -1245,7 +1270,7 @@ bool CCECClient::PollDevice(const cec_logical_address iAddress)
   CCECBusDevice *primary = GetPrimaryDevice();
   // poll the destination, with the primary as source
   if (primary)
-    return primary->TransmitPoll(iAddress, false);
+    return primary->TransmitPoll(iAddress, true);
 
   return m_processor ? m_processor->PollDevice(iAddress) : false;
 }