summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/remote.c b/remote.c
index bf5b41f..2ba5b22 100644
--- a/remote.c
+++ b/remote.c
@@ -1,10 +1,10 @@
/*
* remote.c: Interface to the Remote Control Unit
*
- * See the main source file 'osm.c' for copyright information and
+ * See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: remote.c 1.2 2000/04/15 16:00:51 kls Exp $
+ * $Id: remote.c 1.6 2000/04/24 09:45:56 kls Exp $
*/
#include "remote.h"
@@ -17,6 +17,9 @@
#include <unistd.h>
#include "tools.h"
+#define REPEATLIMIT 100 // ms
+#define REPEATDELAY 250 // ms
+
cRcIo::cRcIo(char *DeviceName)
{
dp = 0;
@@ -25,7 +28,6 @@ cRcIo::cRcIo(char *DeviceName)
address = 0xFFFF;
t = 0;
firstTime = lastTime = 0;
- minDelta = 0;
lastCommand = 0;
if ((f = open(DeviceName, O_RDWR | O_NONBLOCK)) >= 0) {
struct termios t;
@@ -35,8 +37,11 @@ cRcIo::cRcIo(char *DeviceName)
if (tcsetattr(f, TCSAFLUSH, &t) == 0)
return;
}
+ LOG_ERROR_STR(DeviceName);
close(f);
}
+ else
+ LOG_ERROR_STR(DeviceName);
f = -1;
}
@@ -46,9 +51,8 @@ cRcIo::~cRcIo()
close(f);
}
-int cRcIo::ReceiveByte(bool Wait)
+bool cRcIo::InputAvailable(bool Wait)
{
- // Returns the byte if one was received within 1 second, -1 otherwise
if (f >= 0) {
fd_set set;
struct timeval timeout;
@@ -56,13 +60,19 @@ int cRcIo::ReceiveByte(bool Wait)
timeout.tv_usec = Wait ? 0 : 10000;
FD_ZERO(&set);
FD_SET(f, &set);
- if (select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0) {
- if (FD_ISSET(f, &set)) {
- unsigned char b;
- if (read(f, &b, 1) == 1)
- return b;
- }
- }
+ if (select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0)
+ return FD_ISSET(f, &set);
+ }
+ return false;
+}
+
+int cRcIo::ReceiveByte(bool Wait)
+{
+ // Returns the byte if one was received within a timeout, -1 otherwise
+ if (InputAvailable(Wait)) {
+ unsigned char b;
+ if (read(f, &b, 1) == 1)
+ return b;
}
return -1;
}
@@ -112,7 +122,6 @@ bool cRcIo::SetCode(unsigned char Code, unsigned short Address)
{
code = Code;
address = Address;
- minDelta = 200;
return SendCommand(code);
}
@@ -157,12 +166,10 @@ bool cRcIo::GetCommand(unsigned int *Command, unsigned short *Address)
// let's have a timeout to avoid getting overrun by commands
int now = time_ms();
int delta = now - lastTime;
- if (delta < minDelta)
- minDelta = delta; // dynamically adjust to the smallest delta
lastTime = now;
- if (delta < minDelta * 1.3) { // if commands come in rapidly...
- if (now - firstTime < 250)
- return false; // ...repeat function kicks in after 250ms
+ if (delta < REPEATLIMIT) { // if commands come in rapidly...
+ if (now - firstTime < REPEATDELAY)
+ return false; // ...repeat function kicks in after a short delay
return true;
}
}
@@ -209,12 +216,12 @@ bool cRcIo::Number(int n, bool Hex)
bool cRcIo::String(char *s)
{
- char *chars = mode == modeH ? "0123456789ABCDEF" : "0123456789-EHLP ";
+ const char *chars = mode == modeH ? "0123456789ABCDEF" : "0123456789-EHLP ";
int n = 0;
for (int i = 0; *s && i < 4; s++, i++) {
n <<= 4;
- for (char *c = chars; *c; c++) {
+ for (const char *c = chars; *c; c++) {
if (*c == *s) {
n |= c - chars;
break;