aboutsummaryrefslogblamecommitdiff
path: root/multimedia/vdr-plugin-remote/files/patch-uhid1
blob: b14f4fb36fbd84fd03bad0a8b2ee0d7f418bd306 (plain) (tree)






























































































































































































































































                                                                                      
--- a/remote.c
+++ a/remote.c
@@ -15,7 +15,9 @@
 #include <sys/fcntl.h>
 #include <getopt.h>
 #include <termios.h>
+#ifdef REMOTE_FEATURE_DEVINPUT
 #include <linux/input.h>
+#endif
 #include "i18n.h"
 #include "remote.h"
 #ifdef REMOTE_FEATURE_TCPIP
@@ -25,6 +27,9 @@
 
 
 #define NUMREMOTES      10        // maximum number of remote control devices
+#ifdef REMOTE_FEATURE_UHID
+#define UHID_DEFAULT_READSIZE 8   // default size of uhid reads
+#endif
  
 #define AV7110_KEYMAP_DEVICE      "/proc/av7110_ir"
 #if 0
@@ -183,6 +188,7 @@ void cRemoteGeneric::Action(void)
 int identifyInputDevice(const int fh, char *name)
 // ---------------------------------------------------------------------------
 {
+#ifdef REMOTE_FEATURE_DEVINPUT
     char description[256];
 
     // check name of input device
@@ -196,11 +202,13 @@ int identifyInputDevice(const int fh, ch
 
     if (strstr(description, "DVB") || strstr(description, "dvb"))
         return 2;
+#endif
 
     return 0;
 }
 
 
+#ifdef REMOTE_FEATURE_DEVINPUT
 // ---------------------------------------------------------------------------
 bool cRemoteDevInput::loadKeymap(const char *devname, uint32_t options)
 // ---------------------------------------------------------------------------
@@ -454,6 +462,68 @@ bool cRemoteDevInput::keyPressed(uint64_
 {
     return (code & 0xFFFF00000000ULL);
 }
+#endif // REMOTE_FEATURE_DEVINPUT
+
+
+/*****************************************************************************/
+
+
+#ifdef REMOTE_FEATURE_UHID
+// ---------------------------------------------------------------------------
+cRemoteUhid::cRemoteUhid(const char *name, int f, char *d, int size)
+    :cRemoteGeneric(name, f, d)
+// ---------------------------------------------------------------------------
+{
+    Start();
+
+    readsize = size;
+    repeatcode = 0;
+    fcntl(f, F_SETFL, O_NONBLOCK);
+}
+
+
+// ---------------------------------------------------------------------------
+bool cRemoteUhid::Initialize()
+// ---------------------------------------------------------------------------
+{
+    return true;
+}
+
+
+// ---------------------------------------------------------------------------
+uint64_t cRemoteUhid::getKey(void)
+// ---------------------------------------------------------------------------
+{
+    int n;
+    uint64_t code = 0;
+
+    // XXX handle short reads properly on big-endian
+    n = read(fh, &code, readsize);
+    if (n <= 0) {
+        if (n < 0 && (errno == EAGAIN || errno == EINTR))
+            code = repeatcode;
+        else {
+            code = INVALID_KEY;
+            repeatcode = 0;
+        }
+    } else {
+        repeatcode = code;
+#if 1 //def PRINTFDEBUGGING
+        printf("code %jx\n", code);
+#endif
+    }
+
+    return code;
+}
+
+
+// ---------------------------------------------------------------------------
+bool cRemoteUhid::keyPressed(uint64_t code)
+// ---------------------------------------------------------------------------
+{
+    return ((code & ~0xffULL) != 0LL);
+}
+#endif // REMOTE_FEATURE_UHID
 
 
 /*****************************************************************************/
@@ -557,6 +627,9 @@ private:
   int  devcnt;
   char devtyp[NUMREMOTES];
   char *devnam[NUMREMOTES];
+#ifdef REMOTE_FEATURE_UHID
+  int  devsize[NUMREMOTES];
+#endif
   int  fh[NUMREMOTES];
 public:
   cPluginRemote(void);
@@ -604,6 +677,10 @@ const char *cPluginRemote::CommandLineHe
 // ---------------------------------------------------------------------------
 {
     return "  -i dev,   --input=dev    input device (/dev/input/... | autodetect)\n"
+#ifdef REMOTE_FEATURE_UHID
+           "  -h dev,   --uhid=dev     uhid(4) device (/dev/uhidX)\n"
+           "  -s size,  --uhidsize=size     uhid device read size\n"
+#endif
 #ifdef REMOTE_FEATURE_LIRC
            "  -l dev,   --lirc=dev     lirc device (/dev/lircd)\n"
 #endif
@@ -624,6 +701,10 @@ bool cPluginRemote::ProcessArgs(int argc
 {
     static struct option long_options[] =
             { { "input", required_argument, NULL, 'i' },
+#ifdef REMOTE_FEATURE_UHID
+              { "uhid",  required_argument, NULL, 'h' },
+              { "uhidsize",  required_argument, NULL, 's' },
+#endif
               { "lirc",  required_argument, NULL, 'l' },
               { "port",  required_argument, NULL, 'p' },
               { "tty",   required_argument, NULL, 't' },
@@ -631,11 +712,20 @@ bool cPluginRemote::ProcessArgs(int argc
               { NULL } };
     int c;
 
+#ifndef REMOTE_FEATURE_UHID
     while ((c = getopt_long(argc, argv, "i:l:p:t:T:", long_options, NULL)) != -1)
+#else
+    while ((c = getopt_long(argc, argv, "i:h:s:l:p:t:T:", long_options, NULL)) != -1)
+#endif
     {
+#ifdef REMOTE_FEATURE_UHID
+        int size;
+#endif
+
         switch (c)
         {
           case 'i':
+          case 'h':
           case 'l':
           case 'p':
           case 't':
@@ -647,8 +737,27 @@ bool cPluginRemote::ProcessArgs(int argc
               }
               devtyp[devcnt] = c;
               devnam[devcnt] = optarg;
+#ifdef REMOTE_FEATURE_UHID
+              devsize[devcnt] = UHID_DEFAULT_READSIZE;
+#endif
               devcnt++;
               break;
+#ifdef REMOTE_FEATURE_UHID
+          case 's':
+              if (!devcnt || devcnt > NUMREMOTES)
+              {
+                  esyslog("%s: uhidsize must come after uhid device", Name());
+                  return false;
+              }
+              size = atoi(optarg);
+              if (size <= 0 || size_t(size) > sizeof (int64_t))
+              {
+                  esyslog("%s: bad uhidsize %s", Name(), optarg);
+                  return false;
+              }
+              devsize[devcnt] = size;
+              break;
+#endif
 
           default:
               esyslog("%s: invalid argument", Name());
@@ -671,6 +780,7 @@ bool cPluginRemote::Start(void)
     RegisterI18n(remotePhrases);
 #endif
 
+#ifdef REMOTE_FEATURE_DEVINPUT
     // no device specified by the user, set default
     if (devcnt == 0)
     {
@@ -719,6 +829,7 @@ bool cPluginRemote::Start(void)
         if (devtyp[i] == 'i' && strcmp(devnam[i], "autodetect") == 0)
             devnam[i] = "/dev/input/ir";
     } // for i
+#endif
 
     for (int i = 0; i < devcnt; i++)
     {
@@ -769,9 +880,17 @@ bool cPluginRemote::Start(void)
 
         switch (devtyp[i])
         {
+#ifdef REMOTE_FEATURE_DEVINPUT
             case 'i':
                 new cRemoteDevInput(nam,fh[i],devnam[i]);
                 break;
+#endif
+
+#ifdef REMOTE_FEATURE_UHID
+            case 'h':
+                new cRemoteUhid(nam,fh[i],devnam[i],devsize[i]);
+                break;
+#endif
 
 #ifdef REMOTE_FEATURE_LIRC
             case 'l':
--- a/remote.h
+++ a/remote.h
@@ -82,6 +82,24 @@ public:
 
 
 
+#ifdef REMOTE_FEATURE_UHID
+/*****************************************************************************/
+class cRemoteUhid : protected cRemoteGeneric
+/*****************************************************************************/
+{
+private:
+  uint64_t repeatcode;
+  int readsize;
+protected:
+  virtual uint64_t getKey(void);
+  virtual bool keyPressed(uint64_t code);
+public:
+  cRemoteUhid(const char *name, int f, char *d, int size);
+  virtual bool Initialize(void);
+};
+#endif
+
+
 #ifdef REMOTE_FEATURE_LIRCOLD
 /*****************************************************************************/
 class cRemoteDevLirc : protected cRemoteGeneric