diff options
author | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-12-21 16:42:14 -0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-12-21 16:42:14 -0200 |
commit | c7ee85bf91ba65273bd377fb01df5227e18db67f (patch) | |
tree | 7cb46780ccaf495c3ee84d549f2570685ff9f625 /v4l2-apps/util | |
parent | cd75b0ce0ae7333119fbe2b5739ac049d4cbfe43 (diff) | |
download | mediapointer-dvb-s2-c7ee85bf91ba65273bd377fb01df5227e18db67f.tar.gz mediapointer-dvb-s2-c7ee85bf91ba65273bd377fb01df5227e18db67f.tar.bz2 |
Add gen_keytables.pl to automatically generate IR keycodes and improved keytable
From: Mauro Carvalho Chehab <mchehab@infradead.org>
Keytable is now a 3 in 1 script:
calling with one argument, it reads keytable from a IR device
calling with two arguments, it writes a keytable at a IR device
calling with three arguments, it allows changing just one keymap
Of course, it is generic enough to work also with other event devices.
gen_keytables.pl will generate keyboard mappings, as defined at kernel module.
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'v4l2-apps/util')
-rw-r--r-- | v4l2-apps/util/Makefile | 18 | ||||
-rwxr-xr-x | v4l2-apps/util/gen_keytables.pl | 26 | ||||
-rw-r--r-- | v4l2-apps/util/keytable.c | 111 |
3 files changed, 140 insertions, 15 deletions
diff --git a/v4l2-apps/util/Makefile b/v4l2-apps/util/Makefile index 8c0277a6a..7d497c82b 100644 --- a/v4l2-apps/util/Makefile +++ b/v4l2-apps/util/Makefile @@ -20,3 +20,21 @@ qv4l2: install: include ../Make.rules + +parse.h: /usr/include/linux/input.h + @echo generating parse.h + @echo -en "struct parse_key {\n\tchar *name;\n\tunsigned int value;\n} " >parse.h + @echo -en "keynames[] = {\n" >>parse.h + + @more /usr/include/linux/input.h |perl -n \ + -e 'if (m/^\#define\s+(KEY_[^\s]+)\s+(0x[\d\w]+|[\d]+)/) ' \ + -e '{ printf "\t{\"%s\", %s},\n",$$1,$$2; }' \ + -e 'if (m/^\#define\s+(BTN_[^\s]+)\s+(0x[\d\w]+|[\d]+)/) ' \ + -e '{ printf "\t{\"%s\", %s},\n",$$1,$$2; }' \ + >> parse.h + @echo -en "\t{ NULL, 0}\n};\n" >>parse.h + +keytables: + ./gen_keytables.pl ../../v4l/ir-keymaps.c + +keytable: keytable.c parse.h keytables diff --git a/v4l2-apps/util/gen_keytables.pl b/v4l2-apps/util/gen_keytables.pl new file mode 100755 index 000000000..f183ab4d1 --- /dev/null +++ b/v4l2-apps/util/gen_keytables.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl +use strict; + +my $keyname=""; +while (<>) { +#IR_KEYTAB_TYPE ir_codes_proteus_2309[IR_KEYTAB_SIZE] = { + if (m/IR_KEYTAB_TYPE\s+(\w[\w\d_]+)/) { + $keyname = $1; + $keyname =~ s/^ir_codes_//; + + print "Generating keycodes/$keyname\n"; + open OUT, ">keycodes/$keyname"; + next; + } + if ($keyname ne "") { + if (m/(0x[\d\w]+).*(KEY_[^\s\,]+)/) { + printf OUT "%s %s\n",$1, $2; + next; + } + if (m/\}/) { + close OUT; + $keyname=""; + next; + } + } +} diff --git a/v4l2-apps/util/keytable.c b/v4l2-apps/util/keytable.c index f908f6065..93aa8973c 100644 --- a/v4l2-apps/util/keytable.c +++ b/v4l2-apps/util/keytable.c @@ -13,12 +13,16 @@ */ #include <ctype.h> +#include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <linux/input.h> #include <sys/ioctl.h> +#include "parse.h" + void prtcode (int *codes) { if (isprint (codes[1])) @@ -27,41 +31,118 @@ void prtcode (int *codes) printf("scancode %d = 0x%02x\n", codes[0], codes[1]); } +int parse_code(char *string) +{ + struct parse_key *p; + + for (p=keynames;p->name!=NULL;p++) { + if (!strcasecmp(p->name, string)) { + return p->value; + } + } + return -1; +} + int main (int argc, char *argv[]) { int fd; unsigned int i; int codes[2]; - if (argc!=2 && argc!=4) { + if (argc<2 || argc>4) { printf ("usage: %s <device> to get table; or\n" - " %s <device> <scancode> <keycode>\n",*argv,*argv); + " %s <device> <scancode> <keycode>\n" + " %s <device> <keycode_file>\n",*argv,*argv,*argv); return -1; } - if ((fd = open(argv[1], O_RDONLY)) < 0) { - perror("Couldn't open input device"); - return(-1); - } + if ((fd = open(argv[1], O_RDONLY)) < 0) { + perror("Couldn't open input device"); + return(-1); + } + + if (argc==4) { + int value; + + value=parse_code(argv[3]); + + if (value==-1) { + value = strtol(argv[3], NULL, 0); + if (errno) + perror("value"); + } + + codes [0] = (unsigned) strtol(argv[2], NULL, 0); + codes [1] = (unsigned) value; + + if(ioctl(fd, EVIOCSKEYCODE, codes)) + perror ("EVIOCSKEYCODE"); + + if(ioctl(fd, EVIOCGKEYCODE, codes)==0) + prtcode(codes); + return 0; + } + + if (argc==3) { + FILE *fin; + int value; + char *scancode, *keycode, s[2048]; + + fin=fopen(argv[2],"r"); + if (fin==NULL) { + perror ("opening keycode file"); + return -1; + } - if (argc==2) { - /* Get scancode table */ + /* Clears old table */ for (i=0;i<256;i++) { codes[0] = i; + codes[1] = 0; + ioctl(fd, EVIOCSKEYCODE, codes); + } + + while (fgets(s,sizeof(s),fin)) { + scancode=strtok(s,"\n\t =:"); + if (!scancode) { + perror ("parsing input file scancode"); + return -1; + } + + keycode=strtok(NULL,"\n\t "); + if (!keycode) { + perror ("parsing input file keycode"); + return -1; + } + + // printf ("parsing %s=%s:",scancode,keycode); + value=parse_code(keycode); + // printf ("\tvalue=%d\n",value); + + if (value==-1) { + value = strtol(keycode, NULL, 0); + if (errno) + perror("value"); + } + + codes [0] = (unsigned) strtol(scancode, NULL, 0); + codes [1] = (unsigned) value; + + if(ioctl(fd, EVIOCSKEYCODE, codes)) + perror ("EVIOCSKEYCODE"); + if(ioctl(fd, EVIOCGKEYCODE, codes)==0) prtcode(codes); -// else perror ("EVIOGCKEYCODE"); } - } else { - codes[0] = (unsigned) strtol(argv[2], NULL, 0); - codes[1] = (unsigned) strtol(argv[3], NULL, 0); - - if(ioctl(fd, EVIOCSKEYCODE, codes)) - perror ("EVIOCSKEYCODE"); + return 0; + } + /* Get scancode table */ + for (i=0;i<256;i++) { + codes[0] = i; if(ioctl(fd, EVIOCGKEYCODE, codes)==0) prtcode(codes); } return 0; } + |