1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

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

34
lirc.c
View File

@ -6,7 +6,7 @@
* *
* LIRC support added by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16. * 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" #include "lirc.h"
@ -15,7 +15,6 @@
#define REPEATDELAY 300 // ms #define REPEATDELAY 300 // ms
#define REPEATFREQ 100 // ms #define REPEATFREQ 100 // ms
#define REPEATTIMEOUT 150 // ms
#define RECONNECTDELAY 3000 // ms #define RECONNECTDELAY 3000 // ms
cLircRemote::cLircRemote(const char *DeviceName) cLircRemote::cLircRemote(const char *DeviceName)
@ -63,8 +62,10 @@ void cLircRemote::Action(void)
{ {
cTimeMs FirstTime; cTimeMs FirstTime;
cTimeMs LastTime; cTimeMs LastTime;
cTimeMs ThisTime;
char buf[LIRC_BUFFER_SIZE]; char buf[LIRC_BUFFER_SIZE];
char LastKeyName[LIRC_KEY_BUF] = ""; char LastKeyName[LIRC_KEY_BUF] = "";
bool pressed = false;
bool repeat = false; bool repeat = false;
int timeout = -1; int timeout = -1;
@ -94,12 +95,15 @@ void cLircRemote::Action(void)
esyslog("ERROR: unparseable lirc command: %s", buf); esyslog("ERROR: unparseable lirc command: %s", buf);
continue; continue;
} }
int Delta = ThisTime.Elapsed(); // the time between two subsequent LIRC events
ThisTime.Set();
if (count == 0) { if (count == 0) {
if (strcmp(KeyName, LastKeyName) == 0 && FirstTime.Elapsed() < REPEATDELAY) if (strcmp(KeyName, LastKeyName) == 0 && FirstTime.Elapsed() < REPEATDELAY)
continue; // skip keys coming in too fast continue; // skip keys coming in too fast
if (repeat) if (repeat)
Put(LastKeyName, false, true); Put(LastKeyName, false, true);
strcpy(LastKeyName, KeyName); strcpy(LastKeyName, KeyName);
pressed = true;
repeat = false; repeat = false;
FirstTime.Set(); FirstTime.Set();
timeout = -1; timeout = -1;
@ -110,18 +114,24 @@ void cLircRemote::Action(void)
continue; // skip same keys coming in too fast continue; // skip same keys coming in too fast
else { else {
repeat = true; repeat = true;
timeout = REPEATTIMEOUT; timeout = Delta * 10 / 9;
} }
LastTime.Set(); if (pressed)
Put(KeyName, repeat); LastTime.Set();
Put(KeyName, repeat);
} }
else if (repeat) { // the last one was a repeat, so let's generate a release else if (pressed && repeat) { // the last one was a repeat, so let's generate a release
if (LastTime.Elapsed() >= REPEATTIMEOUT) { Put(LastKeyName, false, true);
Put(LastKeyName, false, true); pressed = false;
repeat = false; repeat = false;
*LastKeyName = 0; *LastKeyName = 0;
timeout = -1; timeout = -1;
} }
else {
pressed = false;
repeat = false;
*LastKeyName = 0;
timeout = -1;
} }
} }
} }