added combo key handling, based on the implementation from @ashwinkp, but with suppor...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 21 Sep 2012 11:21:35 +0000 (13:21 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 21 Sep 2012 11:49:26 +0000 (13:49 +0200)
src/lib/CECClient.cpp
src/lib/CECClient.h

index 0bbc081191652ba7b65a80bb88bd2070d5358e40..fea8ed73a114bd93ad09db978f019c24fcd08dec 100644 (file)
@@ -47,6 +47,9 @@ using namespace PLATFORM;
 #define LIB_CEC     m_processor->GetLib()
 #define ToString(x) CCECTypeUtils::ToString(x)
 
+#define COMBO_KEY        CEC_USER_CONTROL_CODE_STOP
+#define COMBO_TIMEOUT_MS 1000
+
 CCECClient::CCECClient(CCECProcessor *processor, const libcec_configuration &configuration) :
     m_processor(processor),
     m_bInitialised(false),
@@ -946,7 +949,7 @@ int CCECClient::MenuStateChanged(const cec_menu_state newState)
   return CallbackMenuStateChanged(newState);
 }
 
-void CCECClient::AddKey(void)
+void CCECClient::AddKey(bool bSendComboKey /* = false */)
 {
   cec_keypress key;
   key.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
@@ -956,10 +959,14 @@ void CCECClient::AddKey(void)
     if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN)
     {
       key.duration = (unsigned int) (GetTimeMs() - m_buttontime);
-      key.keycode = m_iCurrentButton;
 
-      m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
-      m_buttontime = 0;
+      if (key.duration > COMBO_TIMEOUT_MS || m_iCurrentButton != COMBO_KEY || bSendComboKey)
+      {
+        key.keycode = m_iCurrentButton;
+
+        m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
+        m_buttontime = 0;
+      }
     }
   }
 
@@ -975,16 +982,36 @@ void CCECClient::AddKey(const cec_keypress &key)
   // send back the previous key if there is one
   AddKey();
 
+  cec_keypress transmitKey(key);
+
   {
     CLockObject lock(m_mutex);
-    m_iCurrentButton = key.duration > 0 || key.keycode > CEC_USER_CONTROL_CODE_MAX ?
-        CEC_USER_CONTROL_CODE_UNKNOWN :
-        key.keycode;
-    m_buttontime = key.duration > 0 ? 0 : GetTimeMs();
+    if (key.duration > 0 || key.keycode > CEC_USER_CONTROL_CODE_MAX)
+    {
+      transmitKey.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
+    }
+    else if (m_iCurrentButton == COMBO_KEY)
+    {
+      // 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)
+        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)
+        transmitKey.keycode = CEC_USER_CONTROL_CODE_DOT;
+      // default, send back the previous key
+      else
+        AddKey(true);
+    }
+
+    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(key.keycode), key.keycode);
-  CallbackAddKey(key);
+  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)
@@ -1006,7 +1033,8 @@ void CCECClient::CheckKeypressTimeout(void)
     uint64_t iNow = GetTimeMs();
 
     if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN &&
-        iNow - m_buttontime > CEC_BUTTON_TIMEOUT)
+          ((m_iCurrentButton == COMBO_KEY && iNow - m_buttontime > COMBO_TIMEOUT_MS) ||
+          (m_iCurrentButton != COMBO_KEY && iNow - m_buttontime > CEC_BUTTON_TIMEOUT)))
     {
       key.duration = (unsigned int) (iNow - m_buttontime);
       key.keycode = m_iCurrentButton;
index be72448a5127fb0218021b37051b3eacab1cc171..f19e8186c37f556427f5a0d6613b4c63719c3f06 100644 (file)
@@ -178,7 +178,7 @@ namespace CEC
     virtual int                   MenuStateChanged(const cec_menu_state newState);
     virtual void                  Alert(const libcec_alert type, const libcec_parameter &param) { CallbackAlert(type, param); }
     virtual void                  AddLog(const cec_log_message &message) { CallbackAddLog(message); }
-    virtual void                  AddKey(void);
+    virtual void                  AddKey(bool bSendComboKey = false);
     virtual void                  AddKey(const cec_keypress &key);
     virtual void                  SetCurrentButton(const cec_user_control_code iButtonCode);
     virtual void                  CheckKeypressTimeout(void);