diff options
author | bobo1on1 <bobo1on1@svn> | 2010-04-02 22:31:27 +0000 |
---|---|---|
committer | bobo1on1 <bobo1on1@svn> | 2010-04-02 22:31:27 +0000 |
commit | 53fb145bba225c876bdac134ae702c42e7095d15 (patch) | |
tree | c0a932d38c48ec43a81965e5dadd41b4ceacb576 /guilib | |
parent | a837162d8d739ef066ed9922df0e0470e1c7dbe7 (diff) |
added: lirc.send builtin
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@28982 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'guilib')
-rw-r--r-- | guilib/common/IRServerSuite/IRServerSuite.h | 1 | ||||
-rw-r--r-- | guilib/common/LIRC.cpp | 57 | ||||
-rw-r--r-- | guilib/common/LIRC.h | 4 |
3 files changed, 61 insertions, 1 deletions
diff --git a/guilib/common/IRServerSuite/IRServerSuite.h b/guilib/common/IRServerSuite/IRServerSuite.h index e80761268f..aede253f0b 100644 --- a/guilib/common/IRServerSuite/IRServerSuite.h +++ b/guilib/common/IRServerSuite/IRServerSuite.h @@ -41,6 +41,7 @@ public: //lirc stuff, not implemented bool IsInUse() {return false;} void setUsed(bool value); + void AddSendCommand(const CStdString& command) {} protected: virtual void Process(); diff --git a/guilib/common/LIRC.cpp b/guilib/common/LIRC.cpp index d21add8205..88308d6e87 100644 --- a/guilib/common/LIRC.cpp +++ b/guilib/common/LIRC.cpp @@ -31,6 +31,8 @@ CRemoteControl::CRemoteControl() m_bLogConnectFailure = true; m_lastInitAttempt = -5000; m_initRetryPeriod = 5000; + m_inReply = false; + m_nrSending = 0; Reset(); } @@ -78,6 +80,10 @@ void CRemoteControl::Disconnect() } if (m_inotify_fd >= 0) close(m_inotify_fd); + + m_inReply = false; + m_nrSending = 0; + m_sendData.clear(); } } @@ -115,7 +121,7 @@ void CRemoteControl::Initialize() opts = (opts | O_NONBLOCK); if (fcntl(m_fd,F_SETFL,opts) != -1) { - if ((m_file = fdopen(m_fd, "r")) != NULL) + if ((m_file = fdopen(m_fd, "r+")) != NULL) { // Setup inotify so we can disconnect if lircd is restarted if ((m_inotify_fd = inotify_init()) >= 0) @@ -216,6 +222,24 @@ void CRemoteControl::Update() char deviceName[128]; sscanf(m_buf, "%s %s %s %s", &scanCode[0], &repeatStr[0], &buttonName[0], &deviceName[0]); + //beginning of lirc reply packet + //we get one when lirc is done sending something + if (!m_inReply && strcmp("BEGIN", scanCode) == 0) + { + m_inReply = true; + continue; + } + else if (m_inReply && strcmp("END", scanCode) == 0) //end of lirc reply packet + { + m_inReply = false; + if (m_nrSending > 0) + m_nrSending--; + continue; + } + + if (m_inReply) + continue; + // Some template LIRC configuration have button names in apostrophes or quotes. // If we got a quoted button name, strip 'em unsigned int buttonNameLen = strlen(buttonName); @@ -247,8 +271,29 @@ void CRemoteControl::Update() m_button = 0; } } + + //drop commands when already sending + //because keypresses come in faster than lirc can send we risk hammering the daemon with commands + if (m_nrSending > 0) + { + m_sendData.clear(); + } + else if (!m_sendData.empty()) + { + fputs(m_sendData.c_str(), m_file); + fflush(m_file); + + //nr of newlines equals nr of commands + for (int i = 0; i < (int)m_sendData.size(); i++) + if (m_sendData[i] == '\n') + m_nrSending++; + + m_sendData.clear(); + } + if (feof(m_file) != 0) Disconnect(); + m_skipHold = false; } @@ -261,3 +306,13 @@ bool CRemoteControl::IsHolding() { return m_isHolding; } + +void CRemoteControl::AddSendCommand(const CStdString& command) +{ + if (!m_bInitialized || !m_used) + return; + + m_sendData += command; + m_sendData += '\n'; +} + diff --git a/guilib/common/LIRC.h b/guilib/common/LIRC.h index 3cb43f1fee..b695b0fb53 100644 --- a/guilib/common/LIRC.h +++ b/guilib/common/LIRC.h @@ -19,6 +19,7 @@ public: void setUsed(bool value); bool IsInUse() const { return m_used; } bool IsInitialized() const { return m_bInitialized; } + void AddSendCommand(const CStdString& command); private: int m_fd; @@ -37,6 +38,9 @@ private: uint32_t m_firstClickTime; CStdString m_deviceName; bool CheckDevice(); + CStdString m_sendData; + bool m_inReply; + int m_nrSending; }; extern CRemoteControl g_RemoteControl; |