Home

Dokumentation

Impressum

Dokumentation VDR
 

Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

lirc.c

Go to the documentation of this file.
00001 /*
00002  * lirc.c: LIRC remote control
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * LIRC support added by Carsten Koch <Carsten.Koch@icem.de>  2000-06-16.
00008  *
00009  * $Id: lirc.c 1.1 2002/09/29 13:16:33 kls Exp $
00010  */
00011 
00012 #include "lirc.h"
00013 #include <netinet/in.h>
00014 #include <sys/socket.h>
00015 #include <sys/un.h>
00016 
00017 #define REPEATLIMIT  20 // ms
00018 #define REPEATDELAY 350 // ms
00019 
00020 cLircRemote::cLircRemote(char *DeviceName)
00021 :cRemote("LIRC")
00022 {
00023   struct sockaddr_un addr;
00024   addr.sun_family = AF_UNIX;
00025   strcpy(addr.sun_path, DeviceName);
00026   if ((f = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) {
00027      if (connect(f, (struct sockaddr *)&addr, sizeof(addr)) >= 0) {
00028         Start();
00029         return;
00030         }
00031      LOG_ERROR_STR(DeviceName);
00032      close(f);
00033      }
00034   else
00035      LOG_ERROR_STR(DeviceName);
00036   f = -1;
00037 }
00038 
00039 cLircRemote::~cLircRemote()
00040 {
00041   Cancel();
00042 }
00043 
00044 void cLircRemote::Action(void)
00045 {
00046   dsyslog("LIRC remote control thread started (pid=%d)", getpid());
00047 
00048   int FirstTime = 0;
00049   int LastTime = 0;
00050   char buf[LIRC_BUFFER_SIZE];
00051   char LastKeyName[LIRC_KEY_BUF] = "";
00052   bool repeat = false;
00053 
00054   for (; f >= 0;) {
00055 
00056       LOCK_THREAD;
00057 
00058       if (cFile::FileReady(f, REPEATLIMIT) && safe_read(f, buf, sizeof(buf)) > 21) {
00059          int count;
00060          char KeyName[LIRC_KEY_BUF];
00061          sscanf(buf, "%*x %x %29s", &count, KeyName); // '29' in '%29s' is LIRC_KEY_BUF-1!
00062          int Now = time_ms();
00063          if (count == 0) {
00064             strcpy(LastKeyName, KeyName);
00065             repeat = false;
00066             FirstTime = Now;
00067             }
00068          else {
00069             if (Now - FirstTime < REPEATDELAY)
00070                continue; // repeat function kicks in after a short delay
00071             repeat = true;
00072             }
00073          LastTime = Now;
00074          Put(KeyName, repeat);
00075          }
00076       else if (repeat) { // the last one was a repeat, so let's generate a release
00077          if (time_ms() - LastTime > REPEATDELAY) {
00078             Put(LastKeyName, false, true);
00079             repeat = false;
00080             *LastKeyName = 0;
00081             }
00082          }
00083       }
00084 }

Generated on Wed Feb 5 23:30:09 2003 for VDR by doxygen1.3-rc2