]> git.webhop.me Git - getrc.git/commitdiff
* initial commit
authorsvenhoefer <svenhoefer@svenhoefer.com>
Tue, 14 Aug 2012 20:09:42 +0000 (22:09 +0200)
committersvenhoefer <svenhoefer@svenhoefer.com>
Tue, 14 Aug 2012 20:09:42 +0000 (22:09 +0200)
getrc.c [new file with mode: 0644]
io.c [new file with mode: 0644]
io.h [new file with mode: 0644]

diff --git a/getrc.c b/getrc.c
new file mode 100644 (file)
index 0000000..1b4e152
--- /dev/null
+++ b/getrc.c
@@ -0,0 +1,38 @@
+#include <string.h>
+#include <stdio.h>
+#include <time.h>
+//#include <linux/delay.h>
+//#include "getrc.h"
+#include "io.h"
+
+int main (int argc, char **argv)
+{
+int rv='X',i;
+char *key=NULL;
+int tmo=0;
+       InitRC();
+       for(i=1; i<argc; i++)
+       {
+               if(strstr(argv[i],"key=")==argv[i])
+               {
+                       key=argv[i]+4;
+               }
+               if(strstr(argv[i],"timeout=")==argv[i])
+               {
+                       if(sscanf(argv[i]+8,"%d",&tmo)!=1)
+                       {
+                               tmo=0;
+                       }
+               }
+       }
+
+       rv=GetRCCode(key, tmo);
+       
+       CloseRC();
+
+       printf("%c\n",rv);
+       return rv;
+}
+
+
+
diff --git a/io.c b/io.c
new file mode 100644 (file)
index 0000000..32af32a
--- /dev/null
+++ b/io.c
@@ -0,0 +1,152 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include <locale.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/fb.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/dir.h>
+#include <sys/stat.h>
+#include <linux/input.h>
+
+#include "io.h"
+
+#define RC_DEVICE      "/dev/input/nevis_ir"
+
+struct input_event ev;
+static unsigned short rccode=-1;
+static int rc;
+
+int InitRC(void)
+{
+       rc = open(RC_DEVICE, O_RDONLY);
+       if(rc == -1) 
+       {
+               perror("getrc <open remote control>");
+               exit(1);
+       }
+       fcntl(rc, F_SETFL, O_NONBLOCK);
+       return 1;
+}
+
+int CloseRC(void)
+{
+       close(rc);
+       return 1;
+}
+
+int RCKeyPressed(void)
+{
+       if(read(rc, &ev, sizeof(ev)) == sizeof(ev))
+       {
+               if(ev.code)
+               {
+                       rccode=ev.code;
+                       return 1;
+               }
+       }
+       rccode = -1;
+       return 0;
+}
+
+int Translate(int code)
+{
+       int rv=-1;
+       
+       switch(code)
+       {
+               case KEY_0:
+               case KEY_1:
+               case KEY_2:
+               case KEY_3:
+               case KEY_4:
+               case KEY_5:
+               case KEY_6:
+               case KEY_7:
+               case KEY_8:
+               case KEY_9:                             rv = 0x29+code;
+                       break;
+
+               case KEY_UP:                    rv = 'C'; break;
+               case KEY_DOWN:                  rv = 'D'; break;
+               case KEY_LEFT:                  rv = 'B'; break;
+               case KEY_RIGHT:                 rv = 'A'; break;
+               case KEY_OK:                    rv = 'E'; break;
+               case KEY_RED:                   rv = 'J'; break;
+               case KEY_GREEN:                 rv = 'H'; break;
+               case KEY_YELLOW:                rv = 'I'; break;
+               case KEY_BLUE:                  rv = 'K'; break;
+               case KEY_VOLUMEUP:              rv = 'L'; break;
+               case KEY_VOLUMEDOWN:    rv = 'M'; break;
+               case KEY_MUTE:                  rv = 'F'; break;
+               case KEY_HELP:                  rv = 'N'; break;
+               case KEY_SETUP:                 rv = 'O'; break;
+               case KEY_HOME:                  rv = 'P'; break;
+               case KEY_POWER:                 rv = 'G'; break;
+
+               case KEY_PAGEUP:                rv = 'Q'; break;
+               case KEY_PAGEDOWN:              rv = 'R'; break;
+               case KEY_TVR:                   rv = 'S'; break;
+               case KEY_TTX:                   rv = 'T'; break;
+               case KEY_COOL:                  rv = 'U'; break;
+               case KEY_FAV:                   rv = 'V'; break;
+               case KEY_EPG:                   rv = 'W'; break;
+               case KEY_VF:                    rv = 'Y'; break;
+               case KEY_SAT:                   rv = 'Z'; break;
+               case KEY_SKIPP:                 rv = 'a'; break;
+               case KEY_SKIPM:                 rv = 'b'; break;
+               case KEY_TS:                    rv = 'c'; break;
+               case KEY_AUDIO:                 rv = 'd'; break;
+               case KEY_REW:                   rv = 'e'; break;
+               case KEY_FWD:                   rv = 'f'; break;
+               case KEY_HOLD:                  rv = 'g'; break;
+               case KEY_REC:                   rv = 'h'; break;
+               case KEY_STOP:                  rv = 'i'; break;
+               case KEY_PLAY:                  rv = 'j'; break;
+
+               default:                        rccode = -1;
+       }
+
+       return rv;
+
+}
+
+int GetRCCode(char *key, int timeout)
+{
+int tmo=timeout;
+       
+       timeout>>=1;
+       
+       if(key)
+       {
+               while(Translate(rccode)!=(int)(*key))
+               {
+                       RCKeyPressed();
+                       usleep(10000L);
+                       if(tmo &&((timeout-=10)<=0))
+                       {
+                               return 'X';
+                       }
+               }
+       }
+       else
+       {
+               while(!RCKeyPressed())
+               {
+                       usleep(10000L);
+                       if(tmo &&((timeout-=10)<=0))
+                       {
+                               return 'X';
+                       }
+               }
+       }
+       return Translate(rccode);
+}
+
diff --git a/io.h b/io.h
new file mode 100644 (file)
index 0000000..79f61f6
--- /dev/null
+++ b/io.h
@@ -0,0 +1,69 @@
+#ifndef __IO_H__
+
+#define __IO_H__
+
+#define RC_DEVICE      "/dev/input/nevis_ir"
+
+// rc codes
+
+#undef KEY_0
+#undef KEY_EPG
+#undef KEY_SAT
+#undef KEY_STOP
+#undef KEY_PLAY
+
+#define KEY_0                                  1  
+#define KEY_1                                  2   
+#define KEY_2                                  3   
+#define KEY_3                                  4   
+#define KEY_4                                  5   
+#define KEY_5                                  6   
+#define KEY_6                                  7   
+#define KEY_7                                  8   
+#define KEY_8                                  9   
+#define KEY_9                                  10   
+#define KEY_BACKSPACE           14   
+#define KEY_UP                  103   
+#define KEY_LEFT                105   
+#define KEY_RIGHT               106   
+#define KEY_DOWN                108   
+#define KEY_MUTE                113   
+#define KEY_VOLUMEDOWN          114   
+#define KEY_VOLUMEUP            115   
+#define KEY_POWER               116   
+#define KEY_HELP                138   
+#define KEY_HOME                102   
+#define KEY_SETUP               141   
+#define KEY_PAGEUP              104   
+#define KEY_PAGEDOWN            109   
+#define KEY_OK                         0x160         /* in patched input.h */
+#define KEY_RED                        0x18e         /* in patched input.h */
+#define KEY_GREEN                      0x18f         /* in patched input.h */
+#define KEY_YELLOW                     0x190         /* in patched input.h */
+#define KEY_BLUE                       0x191         /* in patched input.h */
+
+#define KEY_TVR                                        0x179
+#define KEY_TTX                                        0x184
+#define KEY_COOL                               0x1A1
+#define KEY_FAV                                        0x16C
+#define KEY_EPG                                        0x16D
+#define KEY_VF                                 0x175
+
+#define KEY_SAT                                        0x17D
+#define KEY_SKIPP                              0x197
+#define KEY_SKIPM                              0x19C
+#define KEY_TS                                 0x167
+#define KEY_AUDIO                              0x188
+#define KEY_REW                                        0x0A8
+#define KEY_FWD                                        0x09F
+#define KEY_HOLD                               0x077
+#define KEY_REC                                        0x0A7
+#define KEY_STOP                               0x080
+#define KEY_PLAY                               0x0CF
+
+int InitRC(void);
+int CloseRC(void);
+int RCKeyPressed(void);
+int GetRCCode(char *key, int timeout);
+
+#endif