diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-21 12:03:10 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-21 12:03:10 -0400 |
commit | c720f5655df159a630fa0290a0bd67c93e92b0bf (patch) | |
tree | 940d139d0ec1ff5201efddef6cc663166a8a2df3 /Documentation/DocBook/v4l/keytable.c.xml | |
parent | 33e6c1a0de818d3698cdab27c42915661011319d (diff) | |
parent | 84d6ae431f315e8973aac3c3fe1d550fc9240ef3 (diff) |
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6: (222 commits)
V4L/DVB (13033): pt1: Don't use a deprecated DMA_BIT_MASK macro
V4L/DVB (13029): radio-si4713: remove #include <linux/version.h>
V4L/DVB (13027): go7007: convert printks to v4l2_info
V4L/DVB (13026): s2250-board: Implement brightness and contrast controls
V4L/DVB (13025): s2250-board: Fix memory leaks
V4L/DVB (13024): go7007: Implement vidioc_g_std and vidioc_querystd
V4L/DVB (13023): go7007: Merge struct gofh and go declarations
V4L/DVB (13022): go7007: Fix mpeg controls
V4L/DVB (13021): go7007: Fix whitespace and line lengths
V4L/DVB (13020): go7007: Updates to Kconfig and Makefile
V4L/DVB (13019): video: initial support for ADV7180
V4L/DVB (13018): kzalloc failure ignored in au8522_probe()
V4L/DVB (13017): gspca: kmalloc failure ignored in sd_start()
V4L/DVB (13016): kmalloc failure ignored in lgdt3304_attach() and s921_attach()
V4L/DVB (13015): kmalloc failure ignored in m920x_firmware_download()
V4L/DVB (13014): Add support for Compro VideoMate E800 (DVB-T part only)
V4L/DVB (13013): FM TX: si4713: Kconfig: Fixed two typos.
V4L/DVB (13012): uvc: introduce missing kfree
V4L/DVB (13011): Change tuner type of BeholdTV cards
V4L/DVB (13009): gspca - stv06xx-hdcs: Reduce exposure range
...
Diffstat (limited to 'Documentation/DocBook/v4l/keytable.c.xml')
-rw-r--r-- | Documentation/DocBook/v4l/keytable.c.xml | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/Documentation/DocBook/v4l/keytable.c.xml b/Documentation/DocBook/v4l/keytable.c.xml new file mode 100644 index 000000000000..d53254a3be15 --- /dev/null +++ b/Documentation/DocBook/v4l/keytable.c.xml | |||
@@ -0,0 +1,172 @@ | |||
1 | <programlisting> | ||
2 | /* keytable.c - This program allows checking/replacing keys at IR | ||
3 | |||
4 | Copyright (C) 2006-2009 Mauro Carvalho Chehab <mchehab@infradead.org> | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation, version 2 of the License. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | */ | ||
15 | |||
16 | #include <ctype.h> | ||
17 | #include <errno.h> | ||
18 | #include <fcntl.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | #include <linux/input.h> | ||
23 | #include <sys/ioctl.h> | ||
24 | |||
25 | #include "parse.h" | ||
26 | |||
27 | void prtcode (int *codes) | ||
28 | { | ||
29 | struct parse_key *p; | ||
30 | |||
31 | for (p=keynames;p->name!=NULL;p++) { | ||
32 | if (p->value == (unsigned)codes[1]) { | ||
33 | printf("scancode 0x%04x = %s (0x%02x)\n", codes[0], p->name, codes[1]); | ||
34 | return; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | if (isprint (codes[1])) | ||
39 | printf("scancode %d = '%c' (0x%02x)\n", codes[0], codes[1], codes[1]); | ||
40 | else | ||
41 | printf("scancode %d = 0x%02x\n", codes[0], codes[1]); | ||
42 | } | ||
43 | |||
44 | int parse_code(char *string) | ||
45 | { | ||
46 | struct parse_key *p; | ||
47 | |||
48 | for (p=keynames;p->name!=NULL;p++) { | ||
49 | if (!strcasecmp(p->name, string)) { | ||
50 | return p->value; | ||
51 | } | ||
52 | } | ||
53 | return -1; | ||
54 | } | ||
55 | |||
56 | int main (int argc, char *argv[]) | ||
57 | { | ||
58 | int fd; | ||
59 | unsigned int i, j; | ||
60 | int codes[2]; | ||
61 | |||
62 | if (argc<2 || argc>4) { | ||
63 | printf ("usage: %s <device> to get table; or\n" | ||
64 | " %s <device> <scancode> <keycode>\n" | ||
65 | " %s <device> <keycode_file>\n",*argv,*argv,*argv); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | if ((fd = open(argv[1], O_RDONLY)) < 0) { | ||
70 | perror("Couldn't open input device"); | ||
71 | return(-1); | ||
72 | } | ||
73 | |||
74 | if (argc==4) { | ||
75 | int value; | ||
76 | |||
77 | value=parse_code(argv[3]); | ||
78 | |||
79 | if (value==-1) { | ||
80 | value = strtol(argv[3], NULL, 0); | ||
81 | if (errno) | ||
82 | perror("value"); | ||
83 | } | ||
84 | |||
85 | codes [0] = (unsigned) strtol(argv[2], NULL, 0); | ||
86 | codes [1] = (unsigned) value; | ||
87 | |||
88 | if(ioctl(fd, EVIOCSKEYCODE, codes)) | ||
89 | perror ("EVIOCSKEYCODE"); | ||
90 | |||
91 | if(ioctl(fd, EVIOCGKEYCODE, codes)==0) | ||
92 | prtcode(codes); | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | if (argc==3) { | ||
97 | FILE *fin; | ||
98 | int value; | ||
99 | char *scancode, *keycode, s[2048]; | ||
100 | |||
101 | fin=fopen(argv[2],"r"); | ||
102 | if (fin==NULL) { | ||
103 | perror ("opening keycode file"); | ||
104 | return -1; | ||
105 | } | ||
106 | |||
107 | /* Clears old table */ | ||
108 | for (j = 0; j < 256; j++) { | ||
109 | for (i = 0; i < 256; i++) { | ||
110 | codes[0] = (j << 8) | i; | ||
111 | codes[1] = KEY_RESERVED; | ||
112 | ioctl(fd, EVIOCSKEYCODE, codes); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | while (fgets(s,sizeof(s),fin)) { | ||
117 | scancode=strtok(s,"\n\t =:"); | ||
118 | if (!scancode) { | ||
119 | perror ("parsing input file scancode"); | ||
120 | return -1; | ||
121 | } | ||
122 | if (!strcasecmp(scancode, "scancode")) { | ||
123 | scancode = strtok(NULL,"\n\t =:"); | ||
124 | if (!scancode) { | ||
125 | perror ("parsing input file scancode"); | ||
126 | return -1; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | keycode=strtok(NULL,"\n\t =:("); | ||
131 | if (!keycode) { | ||
132 | perror ("parsing input file keycode"); | ||
133 | return -1; | ||
134 | } | ||
135 | |||
136 | // printf ("parsing %s=%s:", scancode, keycode); | ||
137 | value=parse_code(keycode); | ||
138 | // printf ("\tvalue=%d\n",value); | ||
139 | |||
140 | if (value==-1) { | ||
141 | value = strtol(keycode, NULL, 0); | ||
142 | if (errno) | ||
143 | perror("value"); | ||
144 | } | ||
145 | |||
146 | codes [0] = (unsigned) strtol(scancode, NULL, 0); | ||
147 | codes [1] = (unsigned) value; | ||
148 | |||
149 | // printf("\t%04x=%04x\n",codes[0], codes[1]); | ||
150 | if(ioctl(fd, EVIOCSKEYCODE, codes)) { | ||
151 | fprintf(stderr, "Setting scancode 0x%04x with 0x%04x via ",codes[0], codes[1]); | ||
152 | perror ("EVIOCSKEYCODE"); | ||
153 | } | ||
154 | |||
155 | if(ioctl(fd, EVIOCGKEYCODE, codes)==0) | ||
156 | prtcode(codes); | ||
157 | } | ||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | /* Get scancode table */ | ||
162 | for (j = 0; j < 256; j++) { | ||
163 | for (i = 0; i < 256; i++) { | ||
164 | codes[0] = (j << 8) | i; | ||
165 | if (!ioctl(fd, EVIOCGKEYCODE, codes) && codes[1] != KEY_RESERVED) | ||
166 | prtcode(codes); | ||
167 | } | ||
168 | } | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | </programlisting> | ||