From 250419d2c9fce77bdd4714d0d7a0debbd893db51 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Thu, 31 Jan 2013 12:13:39 +0100 Subject: Improved LIRC timing for repeat function (cont'd) --- lirc.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'lirc.c') diff --git a/lirc.c b/lirc.c index 67b955c5..d9bcd66b 100644 --- a/lirc.c +++ b/lirc.c @@ -6,7 +6,7 @@ * * LIRC support added by Carsten Koch 2000-06-16. * - * $Id: lirc.c 2.2 2013/01/30 11:56:38 kls Exp $ + * $Id: lirc.c 2.3 2013/01/31 12:13:39 kls Exp $ */ #include "lirc.h" @@ -15,7 +15,6 @@ #define REPEATDELAY 300 // ms #define REPEATFREQ 100 // ms -#define REPEATTIMEOUT 150 // ms #define RECONNECTDELAY 3000 // ms cLircRemote::cLircRemote(const char *DeviceName) @@ -63,8 +62,10 @@ void cLircRemote::Action(void) { cTimeMs FirstTime; cTimeMs LastTime; + cTimeMs ThisTime; char buf[LIRC_BUFFER_SIZE]; char LastKeyName[LIRC_KEY_BUF] = ""; + bool pressed = false; bool repeat = false; int timeout = -1; @@ -94,12 +95,15 @@ void cLircRemote::Action(void) esyslog("ERROR: unparseable lirc command: %s", buf); continue; } + int Delta = ThisTime.Elapsed(); // the time between two subsequent LIRC events + ThisTime.Set(); if (count == 0) { if (strcmp(KeyName, LastKeyName) == 0 && FirstTime.Elapsed() < REPEATDELAY) continue; // skip keys coming in too fast if (repeat) Put(LastKeyName, false, true); strcpy(LastKeyName, KeyName); + pressed = true; repeat = false; FirstTime.Set(); timeout = -1; @@ -110,18 +114,24 @@ void cLircRemote::Action(void) continue; // skip same keys coming in too fast else { repeat = true; - timeout = REPEATTIMEOUT; + timeout = Delta * 10 / 9; } - LastTime.Set(); - Put(KeyName, repeat); + if (pressed) + LastTime.Set(); + Put(KeyName, repeat); } - else if (repeat) { // the last one was a repeat, so let's generate a release - if (LastTime.Elapsed() >= REPEATTIMEOUT) { - Put(LastKeyName, false, true); - repeat = false; - *LastKeyName = 0; - timeout = -1; - } + else if (pressed && repeat) { // the last one was a repeat, so let's generate a release + Put(LastKeyName, false, true); + pressed = false; + repeat = false; + *LastKeyName = 0; + timeout = -1; + } + else { + pressed = false; + repeat = false; + *LastKeyName = 0; + timeout = -1; } } } -- cgit v1.2.3