summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2000-07-15 12:39:20 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2000-07-15 12:39:20 +0200
commit20019e7ce51b9e14ce28f96b263b76e6becd4184 (patch)
tree183c0f3bac333786eb71f6825ce40412b8cb7ab4 /remote.c
parent5c574ffb7bba34506479247bf6d924e090bc2d10 (diff)
downloadvdr-20019e7ce51b9e14ce28f96b263b76e6becd4184.tar.gz
vdr-20019e7ce51b9e14ce28f96b263b76e6becd4184.tar.bz2
Added support for LIRC remote control0.0.6
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c218
1 files changed, 176 insertions, 42 deletions
diff --git a/remote.c b/remote.c
index 816670fa..e3786c5c 100644
--- a/remote.c
+++ b/remote.c
@@ -4,7 +4,9 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: remote.c 1.8 2000/06/17 17:43:05 kls Exp $
+ * 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 $
*/
#include "remote.h"
@@ -15,20 +17,82 @@
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
+
+#if defined REMOTE_LIRC
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/un.h>
+#endif
+
+#include "config.h"
#include "tools.h"
#define REPEATLIMIT 100 // ms
#define REPEATDELAY 250 // ms
-cRcIo::cRcIo(char *DeviceName)
+// --- cRcIoBase -------------------------------------------------------------
+
+cRcIoBase::cRcIoBase(void)
+{
+ t = 0;
+ firstTime = lastTime = 0;
+ lastCommand = 0;
+}
+
+cRcIoBase::~cRcIoBase()
+{
+}
+
+// --- cRcIoKBD --------------------------------------------------------------
+
+#if defined REMOTE_KBD
+
+cRcIoKBD::cRcIoKBD(void)
+{
+}
+
+cRcIoKBD::~cRcIoKBD()
+{
+}
+
+void cRcIoKBD::Flush(int WaitSeconds)
+{
+ time_t t0 = time(NULL);
+
+ timeout(10);
+ for (;;) {
+ while (getch() > 0)
+ t0 = time(NULL);
+ if (time(NULL) - t0 >= WaitSeconds)
+ break;
+ }
+}
+
+bool cRcIoKBD::InputAvailable(bool Wait)
+{
+ timeout(Wait ? 1000 : 10);
+ return true;//XXX
+}
+
+bool cRcIoKBD::GetCommand(unsigned int *Command, unsigned short *)
+{
+ if (Command) {
+ *Command = getch();
+ return *Command > 0;
+ }
+ return false;
+}
+
+// --- cRcIoRCU --------------------------------------------------------------
+
+#elif defined REMOTE_RCU
+
+cRcIoRCU::cRcIoRCU(char *DeviceName)
{
dp = 0;
mode = modeB;
code = 0;
address = 0xFFFF;
- t = 0;
- firstTime = lastTime = 0;
- lastCommand = 0;
lastNumber = 0;
if ((f = open(DeviceName, O_RDWR | O_NONBLOCK)) >= 0) {
struct termios t;
@@ -46,28 +110,13 @@ cRcIo::cRcIo(char *DeviceName)
f = -1;
}
-cRcIo::~cRcIo()
+cRcIoRCU::~cRcIoRCU()
{
if (f >= 0)
close(f);
}
-bool cRcIo::InputAvailable(bool Wait)
-{
- if (f >= 0) {
- fd_set set;
- struct timeval timeout;
- timeout.tv_sec = Wait ? 1 : 0;
- timeout.tv_usec = Wait ? 0 : 10000;
- FD_ZERO(&set);
- FD_SET(f, &set);
- if (select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0)
- return FD_ISSET(f, &set);
- }
- return false;
-}
-
-int cRcIo::ReceiveByte(bool Wait)
+int cRcIoRCU::ReceiveByte(bool Wait)
{
// Returns the byte if one was received within a timeout, -1 otherwise
if (InputAvailable(Wait)) {
@@ -80,7 +129,7 @@ int cRcIo::ReceiveByte(bool Wait)
return -1;
}
-bool cRcIo::SendByteHandshake(unsigned char c)
+bool cRcIoRCU::SendByteHandshake(unsigned char c)
{
if (f >= 0) {
int w = write(f, &c, 1);
@@ -104,7 +153,7 @@ bool cRcIo::SendByteHandshake(unsigned char c)
return false;
}
-bool cRcIo::SendByte(unsigned char c)
+bool cRcIoRCU::SendByte(unsigned char c)
{
for (int retry = 5; retry--;) {
if (SendByteHandshake(c))
@@ -113,7 +162,20 @@ bool cRcIo::SendByte(unsigned char c)
return false;
}
-void cRcIo::Flush(int WaitSeconds)
+bool cRcIoRCU::SetCode(unsigned char Code, unsigned short Address)
+{
+ code = Code;
+ address = Address;
+ return SendCommand(code);
+}
+
+bool cRcIoRCU::SetMode(unsigned char Mode)
+{
+ mode = Mode;
+ return SendCommand(mode);
+}
+
+void cRcIoRCU::Flush(int WaitSeconds)
{
time_t t0 = time(NULL);
@@ -125,20 +187,12 @@ void cRcIo::Flush(int WaitSeconds)
}
}
-bool cRcIo::SetCode(unsigned char Code, unsigned short Address)
+bool cRcIoRCU::InputAvailable(bool Wait)
{
- code = Code;
- address = Address;
- return SendCommand(code);
+ return DataAvailable(f, Wait);
}
-bool cRcIo::SetMode(unsigned char Mode)
-{
- mode = Mode;
- return SendCommand(mode);
-}
-
-bool cRcIo::GetCommand(unsigned int *Command, unsigned short *Address)
+bool cRcIoRCU::GetCommand(unsigned int *Command, unsigned short *Address)
{
#pragma pack(1)
union {
@@ -191,17 +245,17 @@ bool cRcIo::GetCommand(unsigned int *Command, unsigned short *Address)
return false;
}
-bool cRcIo::SendCommand(unsigned char Cmd)
+bool cRcIoRCU::SendCommand(unsigned char Cmd)
{
return SendByte(Cmd | 0x80);
}
-bool cRcIo::Digit(int n, int v)
+bool cRcIoRCU::Digit(int n, int v)
{
return SendByte(((n & 0x03) << 5) | (v & 0x0F) | (((dp >> n) & 0x01) << 4));
}
-bool cRcIo::Number(int n, bool Hex)
+bool cRcIoRCU::Number(int n, bool Hex)
{
if (!Hex) {
char buf[8];
@@ -222,7 +276,7 @@ bool cRcIo::Number(int n, bool Hex)
return SendCommand(mode);
}
-bool cRcIo::String(char *s)
+bool cRcIoRCU::String(char *s)
{
const char *chars = mode == modeH ? "0123456789ABCDEF" : "0123456789-EHLP ";
int n = 0;
@@ -239,7 +293,7 @@ bool cRcIo::String(char *s)
return Number(n, true);
}
-void cRcIo::SetPoints(unsigned char Dp, bool On)
+void cRcIoRCU::SetPoints(unsigned char Dp, bool On)
{
if (On)
dp |= Dp;
@@ -248,7 +302,7 @@ void cRcIo::SetPoints(unsigned char Dp, bool On)
Number(lastNumber, true);
}
-bool cRcIo::DetectCode(unsigned char *Code, unsigned short *Address)
+bool cRcIoRCU::DetectCode(unsigned char *Code, unsigned short *Address)
{
// Caller should initialize 'Code' to 0 and call DetectCode()
// until it returns true. Whenever DetectCode() returns false
@@ -282,3 +336,83 @@ bool cRcIo::DetectCode(unsigned char *Code, unsigned short *Address)
return false;
}
+// --- cRcIoLIRC -------------------------------------------------------------
+
+#elif defined REMOTE_LIRC
+
+cRcIoLIRC::cRcIoLIRC(char *DeviceName)
+{
+ struct sockaddr_un addr;
+ addr.sun_family = AF_UNIX;
+ strcpy(addr.sun_path, DeviceName);
+ f = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (f >= 0) {
+ if (connect(f, (struct sockaddr *)&addr, sizeof(addr)) >= 0)
+ return;
+ LOG_ERROR_STR(DeviceName);
+ close(f);
+ }
+ else
+ LOG_ERROR_STR(DeviceName);
+ f = -1;
+}
+
+cRcIoLIRC::~cRcIoLIRC()
+{
+ if (f >= 0)
+ close(f);
+}
+
+const char *cRcIoLIRC::ReceiveString(void)
+{
+ while (InputAvailable(true)) {
+ if (read(f, buf, sizeof(buf)) > 21) {
+ const int repeat = 10 * (buf[17] - '0') + (buf[18] - '0');
+ const int now = time_ms();
+ if (repeat == 0) {
+ firstTime = lastTime = now;
+ return buf + 20;
+ }
+ else if ((now > firstTime + REPEATDELAY) && (now > lastTime + REPEATLIMIT)) {
+ lastTime = now;
+ return buf + 20;
+ }
+ }
+ }
+ return NULL;
+}
+
+void cRcIoLIRC::Flush(int WaitSeconds)
+{
+ time_t t0 = time(NULL);
+
+ for (;;) {
+ while (InputAvailable(false)) {
+ read(f, buf, sizeof(buf));
+ t0 = time(NULL);
+ }
+ if (time(NULL) - t0 >= WaitSeconds)
+ break;
+ }
+}
+
+bool cRcIoLIRC::InputAvailable(bool Wait)
+{
+ return DataAvailable(f, Wait);
+}
+
+bool cRcIoLIRC::GetCommand(unsigned int *Command, unsigned short *)
+{
+ Flush();
+ if (Command) {
+ const char *cmd = ReceiveString();
+ if (cmd) {
+ *Command = Keys.Encode(cmd);
+ return true;
+ }
+ }
+ return false;
+}
+
+#endif
+