summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--remote.c50
-rw-r--r--remote.h5
2 files changed, 24 insertions, 31 deletions
diff --git a/remote.c b/remote.c
index d6bc0ce2..1bf81085 100644
--- a/remote.c
+++ b/remote.c
@@ -6,7 +6,7 @@
*
* Ported to LIRC by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16.
*
- * $Id: remote.c 1.14 2000/09/21 16:57:56 kls Exp $
+ * $Id: remote.c 1.15 2000/10/03 10:49:58 kls Exp $
*/
#include "remote.h"
@@ -339,6 +339,7 @@ bool cRcIoRCU::DetectCode(unsigned char *Code, unsigned short *Address)
cRcIoLIRC::cRcIoLIRC(char *DeviceName)
{
+ repeat = 1;
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, DeviceName);
@@ -361,33 +362,28 @@ cRcIoLIRC::~cRcIoLIRC()
const char *cRcIoLIRC::ReceiveString(void)
{
- char buf[LIRC_BUFFER_SIZE];
- int repeat = 1;
- const int startTime = time_ms();
+ int oldrepeat = 1;
- // Wait up to REPEATLIMIT ms for a new command, skip repetition of last command while waiting.
- do {
- if (InputAvailable(false) && (read(f, buf, sizeof(buf)) > 21)) {
- sscanf(buf, "%*x %x %7s", &repeat, keyName); // '7' in '%7s' is LIRC_KEY_BUF-1!
- if (repeat == 0) {
- firstTime = time_ms();
- return keyName;
- }
+ if (repeat != 0) {
+ Flush();
+ if (repeat != 0) {
+ oldrepeat = repeat;
+ Flush(REPEATLIMIT);
}
- } while (time_ms() < startTime + REPEATLIMIT);
-
- // No new command encountered while skipping old repetitions - wait for new command.
- repeat = 1;
- if (InputAvailable(true) && (read(f, buf, sizeof(buf)) > 21))
- sscanf(buf, "%*x %x %7s", &repeat, keyName); // '7' in '%7s' is LIRC_KEY_BUF-1!
+ }
if (repeat == 0) {
firstTime = time_ms();
+ repeat = 1;
+ return keyName;
+ }
+
+ if ((repeat > 1) && (repeat != oldrepeat) && (time_ms() > firstTime + REPEATDELAY)) {
+ repeat = 1;
return keyName;
}
-
- // Always ignore first repeat, as it often comes in too early.
- return (repeat == 1) || (time_ms() < firstTime + REPEATDELAY) ? NULL : keyName;
+
+ return NULL;
}
void cRcIoLIRC::Flush(int WaitMs)
@@ -395,14 +391,10 @@ void cRcIoLIRC::Flush(int WaitMs)
char buf[LIRC_BUFFER_SIZE];
int t0 = time_ms();
- for (;;) {
- while (InputAvailable(false)) {
- read(f, buf, sizeof(buf));
- t0 = time_ms();
- }
- if (time_ms() - t0 >= WaitMs)
- break;
- }
+ do {
+ if (InputAvailable(false) && (read(f, buf, sizeof(buf)) > 21))
+ sscanf(buf, "%*x %x %7s", &repeat, keyName); // '7' in '%7s' is LIRC_KEY_BUF-1!
+ } while ((repeat != 0) && (time_ms() < t0 + WaitMs));
}
bool cRcIoLIRC::InputAvailable(bool Wait)
diff --git a/remote.h b/remote.h
index 03f91555..75dc4ac1 100644
--- a/remote.h
+++ b/remote.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: remote.h 1.9 2000/09/19 17:39:36 kls Exp $
+ * $Id: remote.h 1.10 2000/10/03 10:45:35 kls Exp $
*/
#ifndef __REMOTE_H
@@ -29,7 +29,7 @@ public:
virtual void SetPoints(unsigned char Dp, bool On) {}
virtual bool String(char *s) { return true; }
virtual bool DetectCode(unsigned char *Code, unsigned short *Address) { return true; }
- virtual void Flush(int WaitMs = 0) {}
+ virtual void Flush(int WaitMs = 0) = 0;
virtual bool InputAvailable(bool Wait = false) = 0;
virtual bool GetCommand(unsigned int *Command, unsigned short *Address = NULL) = 0;
};
@@ -81,6 +81,7 @@ private:
enum { LIRC_KEY_BUF = 8, LIRC_BUFFER_SIZE = 128 };
cFile f;
char keyName[LIRC_KEY_BUF];
+ int repeat;
const char *ReceiveString(void);
public:
cRcIoLIRC(char *DeviceName);