vdr/lirc.c
Klaus Schmidinger 771986b89f Version 1.7.0
- Re-implemented handling of DVB-S2, which first appeared in version 1.5.14, but was
  revoked in version 1.5.15 in favor of making a stable version 1.6.0. VDR now
  requires the "multiproto" DVB driver, e.g. from http://jusst.de/hg/multiproto.
  Note that the channels.conf file now supports additional parameters, so you may
  want to make sure you have a backup of this file in case you need to go back to
  the previous version of VDR!
- Fixed displaying transponder data when it is modified (thanks to Reinhard Nissl).
- Fixed handling the counter in detection of pre 1.3.19 PS data (thanks to Reinhard
  Nissl).
- Improved logging system time changes to avoid problems on slow systems under
  heavy load (suggested by Helmut Auer).
- Now setting the thread name, so that it can be seen in 'top -H' (thanks to Rolf
  Ahrenberg).
- Fixed initializing the timer's flags in the cTimer copy constructor (thanks to
  Andreas Mair).
- Fixed setting the OSD level in the 'osddemo' example (thanks to Wolfgang Rohdewald).
- Increased the time between checking the CAM status to 500ms to avoid problems
  with some CAMs (reported by Arthur Konovalov).
2008-04-13 18:00:00 +02:00

127 lines
3.4 KiB
C

/*
* lirc.c: LIRC remote control
*
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* LIRC support added by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16.
*
* $Id: lirc.c 2.0 2006/05/28 08:48:13 kls Exp $
*/
#include "lirc.h"
#include <netinet/in.h>
#include <sys/socket.h>
#define REPEATDELAY 350 // ms
#define REPEATFREQ 100 // ms
#define REPEATTIMEOUT 500 // ms
#define RECONNECTDELAY 3000 // ms
cLircRemote::cLircRemote(const char *DeviceName)
:cRemote("LIRC")
,cThread("LIRC remote control")
{
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, DeviceName);
if (Connect()) {
Start();
return;
}
f = -1;
}
cLircRemote::~cLircRemote()
{
int fh = f;
f = -1;
Cancel();
if (fh >= 0)
close(fh);
}
bool cLircRemote::Connect(void)
{
if ((f = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) {
if (connect(f, (struct sockaddr *)&addr, sizeof(addr)) >= 0)
return true;
LOG_ERROR_STR(addr.sun_path);
close(f);
f = -1;
}
else
LOG_ERROR_STR(addr.sun_path);
return false;
}
bool cLircRemote::Ready(void)
{
return f >= 0;
}
void cLircRemote::Action(void)
{
cTimeMs FirstTime;
cTimeMs LastTime;
char buf[LIRC_BUFFER_SIZE];
char LastKeyName[LIRC_KEY_BUF] = "";
bool repeat = false;
int timeout = -1;
while (Running() && f >= 0) {
bool ready = cFile::FileReady(f, timeout);
int ret = ready ? safe_read(f, buf, sizeof(buf)) : -1;
if (ready && ret <= 0 ) {
esyslog("ERROR: lircd connection broken, trying to reconnect every %.1f seconds", float(RECONNECTDELAY) / 1000);
close(f);
f = -1;
while (Running() && f < 0) {
cCondWait::SleepMs(RECONNECTDELAY);
if (Connect()) {
isyslog("reconnected to lircd");
break;
}
}
}
if (ready && ret > 21) {
int count;
char KeyName[LIRC_KEY_BUF];
if (sscanf(buf, "%*x %x %29s", &count, KeyName) != 2) { // '29' in '%29s' is LIRC_KEY_BUF-1!
esyslog("ERROR: unparseable lirc command: %s", buf);
continue;
}
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);
repeat = false;
FirstTime.Set();
timeout = -1;
}
else {
if (LastTime.Elapsed() < REPEATFREQ)
continue; // repeat function kicks in after a short delay (after last key instead of first key)
if (FirstTime.Elapsed() < REPEATDELAY)
continue; // skip keys coming in too fast (for count != 0 as well)
repeat = true;
timeout = REPEATDELAY;
}
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;
}
}
}
}