Improved LIRC timing for repeat function (cont'd)

This commit is contained in:
Klaus Schmidinger 2013-01-31 12:13:39 +01:00
parent d95804fec3
commit 250419d2c9
1 changed files with 22 additions and 12 deletions

34
lirc.c
View File

@ -6,7 +6,7 @@
*
* LIRC support added by Carsten Koch <Carsten.Koch@icem.de> 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;
}
}
}