mirror of
				https://github.com/vdr-projects/vdr.git
				synced 2025-03-01 10:50:46 +00:00 
			
		
		
		
	Fixed/improved LIRC key handling
This commit is contained in:
		
							
								
								
									
										10
									
								
								config.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								config.c
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
				
			|||||||
 * See the main source file 'vdr.c' for copyright information and
 | 
					 * See the main source file 'vdr.c' for copyright information and
 | 
				
			||||||
 * how to reach the author.
 | 
					 * how to reach the author.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * $Id: config.c 1.8 2000/07/15 12:39:20 kls Exp $
 | 
					 * $Id: config.c 1.9 2000/07/15 16:35:18 kls Exp $
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
@@ -54,6 +54,12 @@ void cKeys::Clear(void)
 | 
				
			|||||||
      k->code = 0;
 | 
					      k->code = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void cKeys::SetDummyValues(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  for (tKey *k = keys; k->type != kNone; k++)
 | 
				
			||||||
 | 
					      k->code = k->type + 1; // '+1' to avoid 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool cKeys::Load(char *FileName)
 | 
					bool cKeys::Load(char *FileName)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  isyslog(LOG_INFO, "loading %s", FileName);
 | 
					  isyslog(LOG_INFO, "loading %s", FileName);
 | 
				
			||||||
@@ -150,7 +156,7 @@ unsigned int cKeys::Encode(const char *Command)
 | 
				
			|||||||
{  
 | 
					{  
 | 
				
			||||||
  if (Command != NULL) {
 | 
					  if (Command != NULL) {
 | 
				
			||||||
     const tKey *k = keys;
 | 
					     const tKey *k = keys;
 | 
				
			||||||
     while ((k->type != kNone) && strncmp(k->name, Command, strlen(k->name)) != 0) // must use 'strncmp()' because LIRC delivers trailing characters!
 | 
					     while ((k->type != kNone) && strcmp(k->name, Command) != 0)
 | 
				
			||||||
           k++;
 | 
					           k++;
 | 
				
			||||||
     return k->code;
 | 
					     return k->code;
 | 
				
			||||||
     }
 | 
					     }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								config.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								config.h
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
				
			|||||||
 * See the main source file 'vdr.c' for copyright information and
 | 
					 * See the main source file 'vdr.c' for copyright information and
 | 
				
			||||||
 * how to reach the author.
 | 
					 * how to reach the author.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * $Id: config.h 1.7 2000/06/24 13:42:32 kls Exp $
 | 
					 * $Id: config.h 1.8 2000/07/15 16:26:57 kls Exp $
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef __CONFIG_H
 | 
					#ifndef __CONFIG_H
 | 
				
			||||||
@@ -50,6 +50,7 @@ public:
 | 
				
			|||||||
  tKey *keys;
 | 
					  tKey *keys;
 | 
				
			||||||
  cKeys(void);
 | 
					  cKeys(void);
 | 
				
			||||||
  void Clear(void);
 | 
					  void Clear(void);
 | 
				
			||||||
 | 
					  void SetDummyValues(void);
 | 
				
			||||||
  bool Load(char *FileName = NULL);
 | 
					  bool Load(char *FileName = NULL);
 | 
				
			||||||
  bool Save(void);
 | 
					  bool Save(void);
 | 
				
			||||||
  unsigned int Encode(const char *Command);
 | 
					  unsigned int Encode(const char *Command);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								remote.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								remote.c
									
									
									
									
									
								
							@@ -6,7 +6,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * Ported to LIRC by Carsten Koch <Carsten.Koch@icem.de>  2000-06-16.
 | 
					 * Ported to LIRC by Carsten Koch <Carsten.Koch@icem.de>  2000-06-16.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * $Id: remote.c 1.9 2000/07/15 12:19:50 kls Exp $
 | 
					 * $Id: remote.c 1.10 2000/07/15 16:34:35 kls Exp $
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "remote.h"
 | 
					#include "remote.h"
 | 
				
			||||||
@@ -365,17 +365,20 @@ cRcIoLIRC::~cRcIoLIRC()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const char *cRcIoLIRC::ReceiveString(void)
 | 
					const char *cRcIoLIRC::ReceiveString(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  char buf[LIRC_BUFFER_SIZE];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  while (InputAvailable(true)) {
 | 
					  while (InputAvailable(true)) {
 | 
				
			||||||
        if (read(f, buf, sizeof(buf)) > 21) {
 | 
					        if (read(f, buf, sizeof(buf)) > 21) {
 | 
				
			||||||
           const int repeat = 10 * (buf[17] - '0') + (buf[18] - '0');
 | 
					 | 
				
			||||||
           const int now = time_ms();
 | 
					           const int now = time_ms();
 | 
				
			||||||
 | 
					           int repeat;
 | 
				
			||||||
 | 
					           sscanf(buf, "%*s %x %7s", &repeat, keyName); // '7' in '%7s' is LIRC_KEY_BUF-1!
 | 
				
			||||||
           if (repeat == 0) {
 | 
					           if (repeat == 0) {
 | 
				
			||||||
              firstTime = lastTime = now;
 | 
					              firstTime = lastTime = now;
 | 
				
			||||||
              return buf + 20;
 | 
					              return keyName;
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
           else if ((now > firstTime + REPEATDELAY) && (now > lastTime + REPEATLIMIT)) {
 | 
					           else if ((now > firstTime + REPEATDELAY) && (now > lastTime + REPEATLIMIT)) {
 | 
				
			||||||
              lastTime = now;
 | 
					              lastTime = now;
 | 
				
			||||||
              return buf + 20;
 | 
					              return keyName;
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
           }
 | 
					           }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -384,6 +387,7 @@ const char *cRcIoLIRC::ReceiveString(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void cRcIoLIRC::Flush(int WaitSeconds)
 | 
					void cRcIoLIRC::Flush(int WaitSeconds)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  char buf[LIRC_BUFFER_SIZE];
 | 
				
			||||||
  time_t t0 = time(NULL);
 | 
					  time_t t0 = time(NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (;;) {
 | 
					  for (;;) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								remote.h
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								remote.h
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
				
			|||||||
 * See the main source file 'vdr.c' for copyright information and
 | 
					 * See the main source file 'vdr.c' for copyright information and
 | 
				
			||||||
 * how to reach the author.
 | 
					 * how to reach the author.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * $Id: remote.h 1.6 2000/06/24 15:52:56 kls Exp $
 | 
					 * $Id: remote.h 1.7 2000/07/15 16:32:43 kls Exp $
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef __REMOTE_H
 | 
					#ifndef __REMOTE_H
 | 
				
			||||||
@@ -75,9 +75,9 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class cRcIoLIRC : public cRcIoBase {
 | 
					class cRcIoLIRC : public cRcIoBase {
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
  enum { LIRC_BUFFER_SIZE = 128 };
 | 
					  enum { LIRC_KEY_BUF = 8, LIRC_BUFFER_SIZE = 128 };
 | 
				
			||||||
  int f;
 | 
					  int f;
 | 
				
			||||||
  char buf[LIRC_BUFFER_SIZE];
 | 
					  char keyName[LIRC_KEY_BUF];
 | 
				
			||||||
  const char *ReceiveString(void);
 | 
					  const char *ReceiveString(void);
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  cRcIoLIRC(char *DeviceName);
 | 
					  cRcIoLIRC(char *DeviceName);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								vdr.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								vdr.c
									
									
									
									
									
								
							@@ -22,7 +22,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * The project's page is at http://www.cadsoft.de/people/kls/vdr
 | 
					 * The project's page is at http://www.cadsoft.de/people/kls/vdr
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * $Id: vdr.c 1.20 2000/07/15 11:45:05 kls Exp $
 | 
					 * $Id: vdr.c 1.21 2000/07/15 16:26:57 kls Exp $
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <signal.h>
 | 
					#include <signal.h>
 | 
				
			||||||
@@ -58,7 +58,9 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  Channels.Load("channels.conf");
 | 
					  Channels.Load("channels.conf");
 | 
				
			||||||
  Timers.Load("timers.conf");
 | 
					  Timers.Load("timers.conf");
 | 
				
			||||||
#ifndef REMOTE_LIRC
 | 
					#ifdef REMOTE_LIRC
 | 
				
			||||||
 | 
					  Keys.SetDummyValues();
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
  if (!Keys.Load(KEYS_CONF))
 | 
					  if (!Keys.Load(KEYS_CONF))
 | 
				
			||||||
     Interface.LearnKeys();
 | 
					     Interface.LearnKeys();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user