[c5c522c] | 1 | /* irmanin.c - test/demo of LIBIR's to interface with lcdproc (LCDd) */ |
---|
| 2 | /* Copyright (C) 1999 David Glaude loosely based on workmanir.c */ |
---|
| 3 | /* workmanir.c - test/demo of LIBIR's high level command functions */ |
---|
| 4 | /* Copyright (C) 1998 Tom Wheeley, see file COPYING for details */ |
---|
| 5 | #include <config.h> |
---|
| 6 | #include <stdlib.h> |
---|
| 7 | #include <stdio.h> |
---|
| 8 | #include <unistd.h> |
---|
| 9 | #include <termios.h> |
---|
| 10 | #include <fcntl.h> |
---|
| 11 | #include <string.h> |
---|
| 12 | #include <sys/errno.h> |
---|
| 13 | #include <sys/ioctl.h> |
---|
| 14 | #include <sys/types.h> |
---|
| 15 | #include <errno.h> |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #define __u32 unsigned int |
---|
| 19 | #define __u8 unsigned char |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | #include "../../shared/debug.h" |
---|
| 23 | #include "../../shared/str.h" |
---|
| 24 | |
---|
| 25 | #define NAME_LENGTH 128 |
---|
| 26 | |
---|
| 27 | #include "lcd.h" |
---|
| 28 | #include "irmanin.h" |
---|
| 29 | #include "../../../libirman-0.4.1b/irman.h" |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | char *progname = "irmanin"; |
---|
| 33 | |
---|
| 34 | char *codes[] = { |
---|
| 35 | /* dummy */ NULL, |
---|
| 36 | /* KeyToLcd */ "lcdproc-A", |
---|
| 37 | /* KeyToLcd */ "lcdproc-B", |
---|
| 38 | /* KeyToLcd */ "lcdproc-C", |
---|
| 39 | /* KeyToLcd */ "lcdproc-D", |
---|
| 40 | /* KeyToLcd */ "lcdproc-E", |
---|
| 41 | /* KeyToLcd */ "lcdproc-F", |
---|
| 42 | /* KeyToLcd */ "lcdproc-G", |
---|
| 43 | /* KeyToLcd */ "lcdproc-H", |
---|
| 44 | /* KeyToLcd */ "lcdproc-I", |
---|
| 45 | /* KeyToLcd */ "lcdproc-J", |
---|
| 46 | /* KeyToLcd */ "lcdproc-K", |
---|
| 47 | /* KeyToLcd */ "lcdproc-L", |
---|
| 48 | /* KeyToLcd */ "lcdproc-M", |
---|
| 49 | /* KeyToLcd */ "lcdproc-N", |
---|
| 50 | /* KeyToLcd */ "lcdproc-O", |
---|
| 51 | /* KeyToLcd */ "lcdproc-P", |
---|
| 52 | /* KeyToLcd */ "lcdproc-Q", |
---|
| 53 | /* KeyToLcd */ "lcdproc-R", |
---|
| 54 | /* KeyToLcd */ "lcdproc-S", |
---|
| 55 | /* KeyToLcd */ "lcdproc-T", |
---|
| 56 | /* KeyToLcd */ "lcdproc-U", |
---|
| 57 | /* KeyToLcd */ "lcdproc-V", |
---|
| 58 | /* KeyToLcd */ "lcdproc-W", |
---|
| 59 | /* KeyToLcd */ "lcdproc-X", |
---|
| 60 | /* KeyToLcd */ "lcdproc-Y", |
---|
| 61 | /* KeyToLcd */ "lcdproc-Z", |
---|
| 62 | /* end */ NULL |
---|
| 63 | }; |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | ////////////////////////////////////////////////////////////////////////// |
---|
| 68 | ////////////////////// Base "class" to derive from /////////////////////// |
---|
| 69 | ////////////////////////////////////////////////////////////////////////// |
---|
| 70 | |
---|
| 71 | lcd_logical_driver *irmanin; |
---|
| 72 | |
---|
| 73 | //void sigterm(int sig) |
---|
| 74 | //{ |
---|
| 75 | // ir_free_commands(); |
---|
| 76 | // ir_finish(); |
---|
| 77 | // raise(sig); |
---|
| 78 | //} |
---|
| 79 | |
---|
| 80 | //////////////////////////////////////////////////////////// |
---|
| 81 | // init() should set up any device-specific stuff, and |
---|
| 82 | // point all the function pointers. |
---|
| 83 | int irmanin_init(struct lcd_logical_driver *driver, char *args) |
---|
| 84 | { |
---|
| 85 | char device[256]; |
---|
| 86 | char *ptrdevice; |
---|
| 87 | char config[256]; |
---|
| 88 | char *ptrconfig; |
---|
| 89 | |
---|
| 90 | char *portname; |
---|
| 91 | |
---|
| 92 | char *argv[64]; |
---|
| 93 | int argc, i, j; |
---|
| 94 | char *filename; |
---|
| 95 | |
---|
| 96 | ptrconfig=NULL; |
---|
| 97 | ptrdevice=NULL; |
---|
| 98 | |
---|
| 99 | irmanin = driver; |
---|
| 100 | |
---|
| 101 | argc = get_args(argv, args, 64); |
---|
| 102 | |
---|
| 103 | for(i=0; i<argc; i++) |
---|
| 104 | { |
---|
| 105 | //printf("Arg(%i): %s\n", i, argv[i]); |
---|
| 106 | if(0 == strcmp(argv[i], "-d") || |
---|
| 107 | 0 == strcmp(argv[i], "--device")) |
---|
| 108 | { |
---|
| 109 | if(i + 1 > argc) { |
---|
| 110 | fprintf(stderr, "irmanin_init: %s requires an argument\n", |
---|
| 111 | argv[i]); |
---|
| 112 | return -1; |
---|
| 113 | } |
---|
| 114 | strcpy(device, argv[++i]); |
---|
| 115 | ptrdevice=device; |
---|
| 116 | } |
---|
| 117 | else if(0 == strcmp(argv[i], "-c") || |
---|
| 118 | 0 == strcmp(argv[i], "--config")) |
---|
| 119 | { |
---|
| 120 | if(i + 1 > argc) { |
---|
| 121 | fprintf(stderr, "irmanin_init: %s requires an argument\n", |
---|
| 122 | argv[i]); |
---|
| 123 | return -1; |
---|
| 124 | } |
---|
| 125 | strcpy(config, argv[++i]); |
---|
| 126 | ptrconfig=config; |
---|
| 127 | } |
---|
| 128 | else if(0 == strcmp(argv[i], "-h") || |
---|
| 129 | 0 == strcmp(argv[i], "--help")) |
---|
| 130 | { |
---|
| 131 | printf("LCDproc IrMan input driver\n" |
---|
| 132 | "\t-d\t--device\tSelect the input device to use\n" |
---|
| 133 | "\t-d\t--config\tSelect the configuration file to use\n" |
---|
| 134 | "\t-h\t--help\t\tShow this help information\n"); |
---|
| 135 | return -1; |
---|
| 136 | } |
---|
| 137 | else |
---|
| 138 | { |
---|
| 139 | printf("Invalid parameter: %s\n", argv[i]); |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | if (ir_init_commands(ptrconfig, 1) < 0) { |
---|
| 144 | fprintf(stderr, "error initialising commands: %s\n", strerror(errno)); |
---|
| 145 | exit(1); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | portname = ir_default_portname(); |
---|
| 149 | if(portname==NULL){ |
---|
| 150 | if(ptrdevice==NULL){ |
---|
| 151 | portname=ptrdevice; |
---|
| 152 | }else{ |
---|
| 153 | fprintf(stderr, "error no device defined\n"); |
---|
| 154 | exit(1); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | driver->getkey = irmanin_getkey; |
---|
| 159 | driver->close = irmanin_close; |
---|
| 160 | |
---|
| 161 | for (i=1; codes[i] != NULL; i++) { |
---|
| 162 | if (ir_register_command(codes[i], i) < 0) { |
---|
| 163 | if (errno == ENOENT) { |
---|
| 164 | fprintf(stderr, "%s: no code set for `%s'\n", progname, codes[i]); |
---|
| 165 | } else { |
---|
| 166 | fprintf(stderr, "error registering `%s': `%s'\n", codes[i], strerror(errno)); |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | errno = 0; |
---|
| 172 | if (ir_init(portname) < 0) { |
---|
| 173 | fprintf(stderr, "%s: error initialising Irman: `%s'\n", strerror(errno), portname); |
---|
| 174 | exit(1); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | return 1; // 200 is arbitrary. (must be 1 or more) |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | void irmanin_close() |
---|
| 182 | { |
---|
| 183 | if(irmanin->framebuf != NULL) free(irmanin->framebuf); |
---|
| 184 | |
---|
| 185 | irmanin->framebuf = NULL; |
---|
| 186 | |
---|
| 187 | ir_free_commands(); |
---|
| 188 | ir_finish(); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | ////////////////////////////////////////////////////////////////////// |
---|
| 193 | // Tries to read a character from an input device... |
---|
| 194 | // |
---|
| 195 | // Return 0 for "nothing available". |
---|
| 196 | // |
---|
| 197 | char irmanin_getkey() |
---|
| 198 | { |
---|
| 199 | int i; |
---|
| 200 | int cmd; |
---|
| 201 | char key; |
---|
| 202 | |
---|
| 203 | key=(char)0; |
---|
| 204 | switch (cmd=ir_poll_command()) { |
---|
| 205 | case IR_CMD_ERROR: |
---|
| 206 | fprintf(stderr, "%s: error reading command: %s\n", progname, strerror(errno)); |
---|
| 207 | break; |
---|
| 208 | case IR_CMD_UNKNOWN: |
---|
| 209 | break; |
---|
| 210 | default: |
---|
| 211 | key=(char)('A'-1+cmd); |
---|
| 212 | break; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | return key; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | /* end of irmanin.c */ |
---|