From: svenhoefer Date: Tue, 14 Aug 2012 20:09:42 +0000 (+0200) Subject: * initial commit X-Git-Url: https://git.webhop.me/?a=commitdiff_plain;h=4bebd0840a77840fa7c97a0d7caa1c9c1f3be5f0;p=getrc.git * initial commit --- 4bebd0840a77840fa7c97a0d7caa1c9c1f3be5f0 diff --git a/getrc.c b/getrc.c new file mode 100644 index 0000000..1b4e152 --- /dev/null +++ b/getrc.c @@ -0,0 +1,38 @@ +#include +#include +#include +//#include +//#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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 "); + 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 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