diff options
Diffstat (limited to 'remote.c')
-rw-r--r-- | remote.c | 50 |
1 files changed, 25 insertions, 25 deletions
@@ -6,7 +6,7 @@ * * Ported to LIRC by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16. * - * $Id: remote.c 1.13 2000/09/19 17:40:52 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,23 +362,27 @@ cRcIoLIRC::~cRcIoLIRC() const char *cRcIoLIRC::ReceiveString(void) { - char buf[LIRC_BUFFER_SIZE]; + int oldrepeat = 1; - while (InputAvailable(true)) { - if (read(f, buf, sizeof(buf)) > 21) { - const int now = time_ms(); - int repeat; - sscanf(buf, "%*s %x %7s", &repeat, keyName); // '7' in '%7s' is LIRC_KEY_BUF-1! - if (repeat == 0) { - firstTime = lastTime = now; - return keyName; - } - else if ((now > firstTime + REPEATDELAY) && (now > lastTime + REPEATLIMIT)) { - lastTime = now; - return keyName; - } - } + if (repeat != 0) { + Flush(); + if (repeat != 0) { + oldrepeat = repeat; + Flush(REPEATLIMIT); } + } + + if (repeat == 0) { + firstTime = time_ms(); + repeat = 1; + return keyName; + } + + if ((repeat > 1) && (repeat != oldrepeat) && (time_ms() > firstTime + REPEATDELAY)) { + repeat = 1; + return keyName; + } + return NULL; } @@ -386,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) @@ -403,7 +404,6 @@ bool cRcIoLIRC::InputAvailable(bool Wait) bool cRcIoLIRC::GetCommand(unsigned int *Command, unsigned short *) { - Flush(); if (Command) { const char *cmd = ReceiveString(); if (cmd) { |