]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/kbdd/kbdd-patched-20040904/fellowes.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / kbdd / kbdd-patched-20040904 / fellowes.patch
1 --- kbd.c       2004-07-06 08:07:38.000000000 -0700
2 +++ ../kbdd.works/kbd.c 2005-01-01 07:59:00.000000000 -0800
3 @@ -21,12 +21,14 @@
4  #include <stdlib.h>
5  #include <sys/types.h>
6  #include <sys/stat.h>
7 +#include <sys/ioctl.h>
8  #include <fcntl.h>
9  #include <termios.h>
10  #include <unistd.h>
11  #include <string.h>
12  #include <errno.h>
13  #include <limits.h>
14 +#include <signal.h>
15  
16  #include "keyboards.h"
17  #include "dev_uinput.h"
18 @@ -37,6 +39,7 @@
19  
20  char debug=0;
21  int uindev=0;
22 +static int reinit=0;
23  char TTY_PORT[PATH_MAX];
24  
25  int open_serial(char *port, speed_t  baud)
26 @@ -122,6 +125,250 @@
27  return 0;
28  }
29  
30 +int stowaway_init(int fd)
31 +{
32 +int status;
33 +unsigned char buf[16];
34 +fd_set fds;
35 +struct timeval tv;
36 +       
37 +       ioctl(fd, TIOCMGET, &status);
38 +       status |= TIOCM_DTR;  /* Set DTR */
39 +       status &= ~TIOCM_RTS; /* Clear RTS */
40 +       ioctl(fd, TIOCMSET, &status);
41 +       
42 +       /* Unfortunately, DCD seems to be high all of the time on H3900, so the following can't be used */
43 +       /* ioctl(fd, TIOCMIWAIT, TIOCM_CAR */
44 +       /* So we just wait instead */
45 +       usleep(1000000);
46 +       
47 +       ioctl(fd, TIOCMGET, &status);
48 +       status |= TIOCM_RTS;  /* Set RTS */
49 +       ioctl(fd, TIOCMSET, &status);
50 +       /* Stowaway will send back 0xFA 0xFD indicating successful init */
51 +       tv.tv_sec = 2;
52 +       tv.tv_usec = 0;
53 +       FD_ZERO(&fds);
54 +       FD_SET(fd, &fds);
55 +       if(select(fd+1, &fds, NULL, NULL, &tv)) {
56 +               read(fd, buf, 2);
57 +               if((buf[0] = 0xFA) && (buf[0] = 0xFD))
58 +                       if (debug) fprintf(stderr, "keyboard initialised\n");
59 +       }
60 +       
61 +       return 0;
62 +}
63 +
64 +void stowaway_sig(int sig) {
65 +       reinit = 1;
66 +}
67 +
68 +int stowaway(void)
69 +{
70 +int fd;
71 +unsigned char buf[16];
72 +char fn=0;
73 +struct sigaction act;
74 +int rc;
75 +
76 +       fd = open_serial(TTY_PORT, B9600);
77 +       if (fd <= 0)
78 +               return (-1);
79 +       
80 +       /* Make SIGHUP cause a reinit of the keyboard */
81 +       act.sa_handler = stowaway_sig;
82 +       sigemptyset(&act.sa_mask);
83 +       act.sa_flags = 0;
84 +       sigaction(SIGHUP, &act, NULL);
85 +
86 +       while (fd > 0) {
87 +               
88 +               stowaway_init(fd);
89 +                       
90 +               while (fd > 0) {
91 +                       rc = read (fd, buf, 1);
92 +                       if(rc == -1) {
93 +                               if(reinit) {
94 +                                       reinit = 0;
95 +                                       break;
96 +                               }
97 +                               else {
98 +                                       perror("read");
99 +                                       return 1;
100 +                               }
101 +                       }
102 +                       
103 +                       if ( ((unsigned char)buf[0] & (unsigned char)0x80) == 0 ) {
104 +                               if (debug) fprintf(stderr, "press: %d\n", buf[0]);
105 +                               if (buf[0] == 0x08) {
106 +                                       fn=1;
107 +                                       continue;
108 +                               }
109 +                               if (fn)
110 +                                       buf[0]=stowaway_function[buf[0]];
111 +                               else
112 +                                       buf[0]=stowaway_normal[buf[0]];
113 +                               if (debug) fprintf(stderr,"= 0x%02x\n", buf[0]);
114 +                               if (buf[0] > 0)
115 +                                       dev_uinput_key(uindev, (unsigned short)buf[0], KEY_PRESSED);
116 +                       } else {
117 +                               if (debug) fprintf(stderr, "rel. : %d\n", buf[0] & ~0x80);
118 +                               if ((buf[0] & ~0x80) == 0x08) {
119 +                                       fn = 0;
120 +                                       continue;
121 +                               }
122 +                               if (fn)
123 +                                       buf[0]=stowaway_function[(unsigned char)buf[0] & (unsigned char)~0x80];
124 +                               else
125 +                                       buf[0]=stowaway_normal[(unsigned char)buf[0] & (unsigned char)~0x80];
126 +                               if (debug) fprintf(stderr,"= 0x%02x\n", buf[0]);
127 +                               if (buf[0] > 0)
128 +                                       dev_uinput_key(uindev, (unsigned short)buf[0], KEY_RELEASED);
129 +                       }
130 +               }
131 +       }
132 +
133 +return 0;
134 +}
135 +
136 +
137 +int fellowes(void)
138 +{
139 +#define FELLOWES_GR_FN 33
140 +#define FELLOWES_BL_FN 34
141 +
142 +
143 +  int fd;
144 +  unsigned char buf[16];
145 +  char bluefn=0,greenfn=0;
146 +  struct sigaction act;
147 +  int rc;
148 +
149 +
150 +  fd = open_serial(TTY_PORT, B9600);
151 +  if (fd <= 0)
152 +    return (-1);
153 +  
154 +  /* Make SIGHUP cause a reinit of the keyboard */
155 +  act.sa_handler = stowaway_sig;
156 +  sigemptyset(&act.sa_mask);
157 +  act.sa_flags = 0;
158 +  sigaction(SIGHUP, &act, NULL);
159 +  
160 +  while (fd > 0) {
161 +    stowaway_init(fd);
162 +    
163 +    while (fd > 0) {
164 +      rc = read (fd, buf, 1);
165 +      if(rc == -1) {
166 +       if(reinit) {
167 +         reinit = 0;
168 +         break;
169 +       }
170 +       else {
171 +         perror("read");
172 +         return 1;
173 +       }
174 +      }
175 +      
176 +
177 +
178 +      if ( ((unsigned char)buf[0] & (unsigned char)0x80) == 0 ) {
179 +       /* KEY PRESSED */
180 +       if (debug) fprintf(stderr, "press: %d\n", buf[0]);
181 +       if (buf[0] == FELLOWES_BL_FN) {
182 +         bluefn=1;
183 +         continue;
184 +       }
185 +
186 +       if (buf[0] == FELLOWES_GR_FN)  {
187 +         greenfn=1;
188 +         dev_uinput_key(uindev,42,KEY_PRESSED);
189 +         continue;
190 +       }
191 +
192 +       if (bluefn)
193 +         buf[0]=fellowes_function[buf[0]];
194 +       else if (greenfn) {
195 +         buf[0]=fellowes_function[buf[0]];
196 +
197 +         /* fixup where green function is not shift blue function */
198 +         switch(buf[0]) {
199 +         case KEY_UP:
200 +           buf[0]=KEY_PAGEUP;
201 +           break;
202 +         case KEY_LEFT:
203 +           buf[0]=KEY_HOME;
204 +           break;
205 +         case KEY_DOWN:
206 +           buf[0]=KEY_PAGEDOWN;
207 +           break;
208 +         case KEY_RIGHT:
209 +           buf[0]=KEY_END;
210 +           break;
211 +         case KEY_INTL2:
212 +           buf[0]=KEY_INTL3;
213 +           break;
214 +           
215 +         }
216 +       } else
217 +         buf[0]=fellowes_normal[buf[0]];
218 +
219 +       if (debug) fprintf(stderr,"= 0x%02x\n", buf[0]);
220 +       if (buf[0] != KEY_RESERVED)
221 +         dev_uinput_key(uindev, (unsigned short)buf[0], KEY_PRESSED);
222 +
223 +      } else {
224 +       /* KEY RELEASED */
225 +       if (debug) fprintf(stderr, "rel. : %d\n", buf[0] & ~0x80);
226 +
227 +       if ((buf[0] & ~0x80) == FELLOWES_BL_FN) {
228 +         bluefn = 0;
229 +         continue;
230 +       }
231 +
232 +       if ((buf[0] & ~0x80) == FELLOWES_GR_FN) {
233 +         greenfn = 0;
234 +         dev_uinput_key(uindev,42,KEY_RELEASED);
235 +         continue;
236 +       }
237 +
238 +       if (bluefn)
239 +         buf[0]=fellowes_function[(unsigned char)buf[0] & (unsigned char)~0x80];
240 +       else if (greenfn) {
241 +         buf[0]=fellowes_function[(unsigned char)buf[0] & (unsigned char)~0x80];
242 +
243 +         /* fixup where green function is not shift blue function */
244 +         switch(buf[0]) {
245 +         case KEY_UP:
246 +           buf[0]=KEY_PAGEUP;
247 +           break;
248 +         case KEY_LEFT:
249 +           buf[0]=KEY_HOME;
250 +           break;
251 +         case KEY_DOWN:
252 +           buf[0]=KEY_PAGEDOWN;
253 +           break;
254 +         case KEY_RIGHT:
255 +           buf[0]=KEY_END;
256 +           break;
257 +         case KEY_INTL2:
258 +           buf[0]=KEY_INTL3;
259 +           break;
260 +         }
261 +       } else
262 +         buf[0]=fellowes_normal[(unsigned char)buf[0] & (unsigned char)~0x80];
263 +
264 +       if (debug) fprintf(stderr,"= 0x%02x\n", buf[0]);
265 +       if (buf[0] != KEY_RESERVED)
266 +         dev_uinput_key(uindev, (unsigned short)buf[0], KEY_RELEASED);
267 +      }
268 +    }
269 +  }
270 +  
271 +  return 0;
272 +}
273 +
274  
275  int snapntype(void)
276  {
277 @@ -177,6 +424,8 @@
278         fprintf (stderr, "-t <kbd type>\n");
279         fprintf (stderr, "\tspecify the serial keyboard type, supported are:\n");
280         fprintf (stderr, "\tfoldable - Compaq/HP foldable keyboard\n");
281 +       fprintf (stderr, "\tstowaway - Targus Stowaway keyboard\n");
282 +       fprintf (stderr, "\tfellowes - fellowes serial keyboard\n");
283         fprintf (stderr, "\tsnapntype- Snap'n'Type\n\n");
284         fprintf (stderr, "Example:\n\t%s -t foldable\n", arg0);
285  }
286 @@ -184,6 +433,8 @@
287  #define KBD_TYPE_NONE          0
288  #define KBD_TYPE_FOLDABLE      1
289  #define KBD_TYPE_SNAPNTYPE     2
290 +#define KBD_TYPE_STOWAWAY      3
291 +#define KBD_TYPE_FELLOWES      4
292  
293  int main(int argc, char **argv)
294  {
295 @@ -204,7 +455,13 @@
296                                         kbdtype = KBD_TYPE_FOLDABLE;
297                                 } else if (strncmp("snapntype", optarg, 9) == 0) {
298                                         kbdtype = KBD_TYPE_SNAPNTYPE;
299 +                               } else if (strncmp("stowaway", optarg, 8) == 0) {
300 +                                       kbdtype = KBD_TYPE_STOWAWAY;
301 +                               } else if (strncmp("fellowes", optarg, 8) == 0) {
302 +                                       kbdtype = KBD_TYPE_FELLOWES;
303                                 }
304 +                               else
305 +                                       fprintf(stderr, "unrecognised keyboard type %s\n", optarg);
306                                 break;
307                         case 'p':
308                                 strcpy(TTY_PORT, optarg);
309 @@ -226,6 +483,10 @@
310                 compaq_foldable();
311         else if (kbdtype == KBD_TYPE_SNAPNTYPE)
312                 snapntype();
313 +       else if (kbdtype == KBD_TYPE_STOWAWAY)
314 +               stowaway();
315 +       else if (kbdtype == KBD_TYPE_FELLOWES)
316 +               fellowes();
317  
318  return 0;
319  }
320 --- keyboards.h 2004-07-09 17:15:52.000000000 -0700
321 +++ ../kbdd.works/keyboards.h   2005-01-01 07:58:19.000000000 -0800
322 @@ -24,6 +24,7 @@
323  
324  #include "uinput.h"
325  
326 +
327  /***********************************************************************************
328   *   iConcepts
329   * 
330 @@ -139,6 +140,95 @@
331          108, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
332          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  };
333  
334 +/***********************************************************************************
335 + *   Targus Stowaway keyboard                                                     
336 + *
337 + * 9600 baud, 8N1
338 + *
339 + * Initialisation: raise DTR and drop RTS, wait for DCD pulse, then raise RTS
340 + *   keyboard will then send back 0xFA 0xFD
341 + *
342 + * Key down sends one byte
343 + * Key up sends one byte & 0x80, and if the key up is the last key up (ie, no more
344 + *   keys held down), then the key code & 0x80 is repeated
345 + ***********************************************************************************/
346 +
347 +static unsigned char stowaway_normal[128] = {
348 +      /*   0, 001, 002, 003, 004, 005, 006, 007, 008, 009 */
349 +/*000*/    2,   3,   4,  44,   5,   6,   7,   8,   0,  16,
350 +/*010*/   17,  18,  19,  20,  21,  41,  45,  30,  31,  32,
351 +/*020*/   33,  34,  35,  57,  58,  15,  29,   0,   0,   0,
352 +/*030*/    0,   0,   0,   0,   0,  56,   0,   0,   0,   0,
353 +/*040*/    0,   0,   0,   0,  46,  47,  48,  49,  12,  13,
354 +/*050*/   14,  87,   9,  10,  11,  57,  26,  27,  43, 220,
355 +/*060*/   22,  23,  24,  25,  40,  28, 219,   0,  36,  37,
356 +/*070*/   38,  39,  53, 144, 183,   0,  50,  51,  52,   0,
357 +/*080*/  111, 146, 155, 151,   0,   0,   0,   0,  42,  54,
358 +/*090*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
359 +/*100*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
360 +/*110*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
361 +/*120*/    0,   0,   0,   0,   0,   0,   0,   0,  };
362 +
363 +static unsigned char stowaway_function[128] = {
364 +      /*   0, 001, 002, 003, 004, 005, 006, 007, 008, 009 */
365 +/*000*/   59,  60,  61,   0,  62,  63,  64,  65,   0,   0,
366 +/*010*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
367 +/*020*/    0,   0,   0,   0,   0,   1,   0,   0,   0,   0,
368 +/*030*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
369 +/*040*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
370 +/*050*/   92,   0,  66,  67,  68,   0,   0,   0,   0,   0,
371 +/*060*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
372 +/*070*/    0,   0,   0, 104,   0,   0,   0,   0,   0,   0,
373 +/*080*/    0, 102, 109, 107,   0,   0,   0,   0,   0,   0,
374 +/*090*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
375 +/*100*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
376 +/*110*/    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
377 +/*120*/    0,   0,   0,   0,   0,   0,   0,   0,  };
378 +
379 +
380 +
381 +/***********************************************************************************
382 + *   ThinkOutside / Fellowes Stowaway XT
383 + *
384 + *  9600 baud, 8N1
385 + *
386 + *  Notes:
387 + *   the green function key is basically shift + scancode - handled elsewhere
388 + *
389 + ***********************************************************************************/
390 +unsigned char fellowes_normal[128] = {
391 +  /* 000 */ 0, 0, 0, KEY_Z, 0, 0, 0, 0, KEY_LEFTMETA, KEY_Q,
392 +  /* 010 */ KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, 0,KEY_X, KEY_A, KEY_S, KEY_D,
393 +  /* 020 */ KEY_F, KEY_G, KEY_H, KEY_SPACE, KEY_CAPSLOCK, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0,
394 +  /* 030 */ 0, 0, 0, 0, 0, KEY_LEFTALT, 0, 0, 0, 0,
395 +  /* 040 */ 0, 0, 0, 0, KEY_C, KEY_V, KEY_B, KEY_N, 0, 0,
396 +  /* 050 */ KEY_BACKSPACE, 0, 0, 0, 0, KEY_SPACE, KEY_MINUS, KEY_EQUAL, KEY_SLASH, 0,
397 +  /* 060 */ KEY_U, KEY_I, KEY_O, KEY_P, KEY_APOSTROPHE, KEY_ENTER, 0, 0, KEY_J, KEY_K,
398 +  /* 070 */ KEY_L, KEY_SEMICOLON, KEY_UP, 0, 0, 0, KEY_M, KEY_COMMA, KEY_DOT, 0,
399 +  /* 080 */ KEY_DELETE, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
400 +  /* 090 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
401 +  /* 100 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
402 +  /* 110 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
403 +  /* 120 */ 0, 0, 0, 0, 0, 0, 0, 0
404 +};
405 +
406 +unsigned fellowes_function[128] = {
407 +  /* 000 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_1,
408 +  /* 010 */ KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, 0, 0, KEY_F9, KEY_F10, KEY_F11,
409 +  /* 020 */ KEY_F12, 0, 0, 0, KEY_NUMLOCK, KEY_ESC, 0, 0, 0, 0,
410 +  /* 030 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
411 +  /* 040 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
412 +  /* 050 */ 0, 0, 0, 0, 0, 0, KEY_LEFTBRACE, KEY_RIGHTBRACE, KEY_BACKSLASH, 0,
413 +  /* 060 */ KEY_7, KEY_8, KEY_9, KEY_0, 0, 0, 0, 0, 0, 0,
414 +  /* 070 */ 0, KEY_WWW, KEY_UP, 0, 0, 0, 0, KEY_INTL1, KEY_INTL2, 0,
415 +  /* 080 */ 0, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0,
416 +  /* 090 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
417 +  /* 100 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
418 +  /* 110 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
419 +  /* 120 */ 0, 0, 0, 0, 0, 0, 0, 0
420 +};
421 +
422
423  
424  /***********************************************************************************
425   *   HP foldable keyboard