mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
More modifications to the LIRC interface
This commit is contained in:
parent
6c23dbf25f
commit
6fd3dbc3f1
50
remote.c
50
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.14 2000/09/21 16:57:56 kls Exp $
|
* $Id: remote.c 1.15 2000/10/03 10:49:58 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
@ -339,6 +339,7 @@ bool cRcIoRCU::DetectCode(unsigned char *Code, unsigned short *Address)
|
|||||||
|
|
||||||
cRcIoLIRC::cRcIoLIRC(char *DeviceName)
|
cRcIoLIRC::cRcIoLIRC(char *DeviceName)
|
||||||
{
|
{
|
||||||
|
repeat = 1;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
strcpy(addr.sun_path, DeviceName);
|
strcpy(addr.sun_path, DeviceName);
|
||||||
@ -361,33 +362,28 @@ cRcIoLIRC::~cRcIoLIRC()
|
|||||||
|
|
||||||
const char *cRcIoLIRC::ReceiveString(void)
|
const char *cRcIoLIRC::ReceiveString(void)
|
||||||
{
|
{
|
||||||
char buf[LIRC_BUFFER_SIZE];
|
int oldrepeat = 1;
|
||||||
int repeat = 1;
|
|
||||||
const int startTime = time_ms();
|
|
||||||
|
|
||||||
// Wait up to REPEATLIMIT ms for a new command, skip repetition of last command while waiting.
|
if (repeat != 0) {
|
||||||
do {
|
Flush();
|
||||||
if (InputAvailable(false) && (read(f, buf, sizeof(buf)) > 21)) {
|
if (repeat != 0) {
|
||||||
sscanf(buf, "%*x %x %7s", &repeat, keyName); // '7' in '%7s' is LIRC_KEY_BUF-1!
|
oldrepeat = repeat;
|
||||||
if (repeat == 0) {
|
Flush(REPEATLIMIT);
|
||||||
firstTime = time_ms();
|
|
||||||
return keyName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} while (time_ms() < startTime + REPEATLIMIT);
|
}
|
||||||
|
|
||||||
// No new command encountered while skipping old repetitions - wait for new command.
|
|
||||||
repeat = 1;
|
|
||||||
if (InputAvailable(true) && (read(f, buf, sizeof(buf)) > 21))
|
|
||||||
sscanf(buf, "%*x %x %7s", &repeat, keyName); // '7' in '%7s' is LIRC_KEY_BUF-1!
|
|
||||||
|
|
||||||
if (repeat == 0) {
|
if (repeat == 0) {
|
||||||
firstTime = time_ms();
|
firstTime = time_ms();
|
||||||
|
repeat = 1;
|
||||||
return keyName;
|
return keyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always ignore first repeat, as it often comes in too early.
|
if ((repeat > 1) && (repeat != oldrepeat) && (time_ms() > firstTime + REPEATDELAY)) {
|
||||||
return (repeat == 1) || (time_ms() < firstTime + REPEATDELAY) ? NULL : keyName;
|
repeat = 1;
|
||||||
|
return keyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cRcIoLIRC::Flush(int WaitMs)
|
void cRcIoLIRC::Flush(int WaitMs)
|
||||||
@ -395,14 +391,10 @@ void cRcIoLIRC::Flush(int WaitMs)
|
|||||||
char buf[LIRC_BUFFER_SIZE];
|
char buf[LIRC_BUFFER_SIZE];
|
||||||
int t0 = time_ms();
|
int t0 = time_ms();
|
||||||
|
|
||||||
for (;;) {
|
do {
|
||||||
while (InputAvailable(false)) {
|
if (InputAvailable(false) && (read(f, buf, sizeof(buf)) > 21))
|
||||||
read(f, buf, sizeof(buf));
|
sscanf(buf, "%*x %x %7s", &repeat, keyName); // '7' in '%7s' is LIRC_KEY_BUF-1!
|
||||||
t0 = time_ms();
|
} while ((repeat != 0) && (time_ms() < t0 + WaitMs));
|
||||||
}
|
|
||||||
if (time_ms() - t0 >= WaitMs)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cRcIoLIRC::InputAvailable(bool Wait)
|
bool cRcIoLIRC::InputAvailable(bool Wait)
|
||||||
|
5
remote.h
5
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.9 2000/09/19 17:39:36 kls Exp $
|
* $Id: remote.h 1.10 2000/10/03 10:45:35 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __REMOTE_H
|
#ifndef __REMOTE_H
|
||||||
@ -29,7 +29,7 @@ public:
|
|||||||
virtual void SetPoints(unsigned char Dp, bool On) {}
|
virtual void SetPoints(unsigned char Dp, bool On) {}
|
||||||
virtual bool String(char *s) { return true; }
|
virtual bool String(char *s) { return true; }
|
||||||
virtual bool DetectCode(unsigned char *Code, unsigned short *Address) { return true; }
|
virtual bool DetectCode(unsigned char *Code, unsigned short *Address) { return true; }
|
||||||
virtual void Flush(int WaitMs = 0) {}
|
virtual void Flush(int WaitMs = 0) = 0;
|
||||||
virtual bool InputAvailable(bool Wait = false) = 0;
|
virtual bool InputAvailable(bool Wait = false) = 0;
|
||||||
virtual bool GetCommand(unsigned int *Command, unsigned short *Address = NULL) = 0;
|
virtual bool GetCommand(unsigned int *Command, unsigned short *Address = NULL) = 0;
|
||||||
};
|
};
|
||||||
@ -81,6 +81,7 @@ private:
|
|||||||
enum { LIRC_KEY_BUF = 8, LIRC_BUFFER_SIZE = 128 };
|
enum { LIRC_KEY_BUF = 8, LIRC_BUFFER_SIZE = 128 };
|
||||||
cFile f;
|
cFile f;
|
||||||
char keyName[LIRC_KEY_BUF];
|
char keyName[LIRC_KEY_BUF];
|
||||||
|
int repeat;
|
||||||
const char *ReceiveString(void);
|
const char *ReceiveString(void);
|
||||||
public:
|
public:
|
||||||
cRcIoLIRC(char *DeviceName);
|
cRcIoLIRC(char *DeviceName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user