updated .gitignore
[deb_libcec.git] / src / lib / CECClient.cpp
index 9dc9bff85d107816abc55de7461feae9d8bb6137..ed3f47eecc23e04976bd3ed560184f3ea8155908 100644 (file)
@@ -56,8 +56,11 @@ CCECClient::CCECClient(CCECProcessor *processor, const libcec_configuration &con
     m_bRegistered(false),
     m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
     m_buttontime(0),
-    m_iPreventForwardingPowerOffCommand(0)
+    m_iPreventForwardingPowerOffCommand(0),
+    m_iLastKeypressTime(0)
 {
+  m_lastKeypress.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
+  m_lastKeypress.duration = 0;
   m_configuration.Clear();
   // set the initial configuration
   SetConfiguration(configuration);
@@ -457,7 +460,7 @@ bool CCECClient::SetLogicalAddress(const cec_logical_address iLogicalAddress)
 
   if (GetPrimaryLogicalAdddress() != iLogicalAddress)
   {
-    LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress);
+    LIB_CEC->AddLog(CEC_LOG_NOTICE, "setting primary logical address to %1x", iLogicalAddress);
     {
       CLockObject lock(m_mutex);
       m_configuration.logicalAddresses.primary = iLogicalAddress;
@@ -938,14 +941,14 @@ void CCECClient::AddCommand(const cec_command &command)
 
   if (command.destination == CECDEVICE_BROADCAST || GetLogicalAddresses().IsSet(command.destination))
   {
-    LIB_CEC->AddLog(CEC_LOG_NOTICE, ">> %s (%X) -> %s (%X): %s (%2X)", ToString(command.initiator), command.initiator, ToString(command.destination), command.destination, ToString(command.opcode), command.opcode);
+    LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s (%X) -> %s (%X): %s (%2X)", ToString(command.initiator), command.initiator, ToString(command.destination), command.destination, ToString(command.opcode), command.opcode);
     CallbackAddCommand(command);
   }
 }
 
 int CCECClient::MenuStateChanged(const cec_menu_state newState)
 {
-  LIB_CEC->AddLog(CEC_LOG_NOTICE, ">> %s: %s", ToString(CEC_OPCODE_MENU_REQUEST), ToString(newState));
+  LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %s: %s", ToString(CEC_OPCODE_MENU_REQUEST), ToString(newState));
   return CallbackMenuStateChanged(newState);
 }
 
@@ -1073,7 +1076,7 @@ std::string CCECClient::GetConnectionInfo(void)
   {
     time_t buildTime = (time_t)m_configuration.iFirmwareBuildDate;
     strLog.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime)));
-    strLog = strLog.Left((int)strLog.length() - 1); // strip \n added by asctime
+    strLog = strLog.substr(0, strLog.length() > 0 ? (size_t)(strLog.length() - 1) : 0); // strip \n added by asctime
     strLog.append(" +0000");
   }
 
@@ -1424,7 +1427,20 @@ void CCECClient::CallbackAddKey(const cec_keypress &key)
 {
   CLockObject lock(m_cbMutex);
   if (m_configuration.callbacks && m_configuration.callbacks->CBCecKeyPress)
-    m_configuration.callbacks->CBCecKeyPress(m_configuration.callbackParam, key);
+  {
+    // prevent double taps
+    int64_t now = GetTimeMs();
+    if (m_lastKeypress.keycode != key.keycode ||
+        key.duration > 0 ||
+        now - m_iLastKeypressTime >= CEC_DOUBLE_TAP_TIMEOUT_MS)
+    {
+      // no double tap
+      if (key.duration == 0)
+        m_iLastKeypressTime = now;
+      m_lastKeypress = key;
+      m_configuration.callbacks->CBCecKeyPress(m_configuration.callbackParam, key);
+    }
+  }
 }
 
 void CCECClient::CallbackAddLog(const cec_log_message &message)