Files
lcdproc/server/drivers/irmanin.c
T

186 lines
4.2 KiB
C
Raw Normal View History

1999-12-09 23:15:14 +00:00
/* irmanin.c - test/demo of LIBIR's to interface with lcdproc (LCDd) */
/* Copyright (C) 1999 David Glaude loosely based on workmanir.c */
/* workmanir.c - test/demo of LIBIR's high level command functions */
/* Copyright (C) 1998 Tom Wheeley, see file COPYING for details */
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <errno.h>
#define __u32 unsigned int
#define __u8 unsigned char
#include "shared/debug.h"
#include "shared/str.h"
1999-12-09 23:15:14 +00:00
#define NAME_LENGTH 128
#include "lcd.h"
#include "irmanin.h"
2005-01-29 18:49:29 +00:00
#include "report.h"
#include "irman.h"
1999-12-09 23:15:14 +00:00
char *progname = "irmanin";
char *codes[] = {
2000-04-03 22:13:57 +00:00
/* dummy */ NULL,
/* KeyToLcd */ "lcdproc-A",
/* KeyToLcd */ "lcdproc-B",
/* KeyToLcd */ "lcdproc-C",
/* KeyToLcd */ "lcdproc-D",
/* KeyToLcd */ "lcdproc-E",
/* KeyToLcd */ "lcdproc-F",
/* KeyToLcd */ "lcdproc-G",
/* KeyToLcd */ "lcdproc-H",
/* KeyToLcd */ "lcdproc-I",
/* KeyToLcd */ "lcdproc-J",
/* KeyToLcd */ "lcdproc-K",
/* KeyToLcd */ "lcdproc-L",
/* KeyToLcd */ "lcdproc-M",
/* KeyToLcd */ "lcdproc-N",
/* KeyToLcd */ "lcdproc-O",
/* KeyToLcd */ "lcdproc-P",
/* KeyToLcd */ "lcdproc-Q",
/* KeyToLcd */ "lcdproc-R",
/* KeyToLcd */ "lcdproc-S",
/* KeyToLcd */ "lcdproc-T",
/* KeyToLcd */ "lcdproc-U",
/* KeyToLcd */ "lcdproc-V",
/* KeyToLcd */ "lcdproc-W",
/* KeyToLcd */ "lcdproc-X",
/* KeyToLcd */ "lcdproc-Y",
/* KeyToLcd */ "lcdproc-Z",
/* end */ NULL
1999-12-09 23:15:14 +00:00
};
//////////////////////////////////////////////////////////////////////////
////////////////////// Base "class" to derive from ///////////////////////
//////////////////////////////////////////////////////////////////////////
//void sigterm(int sig)
//{
// ir_free_commands();
// ir_finish();
// raise(sig);
//}
////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and
// point all the function pointers.
2002-02-21 22:50:12 +00:00
MODULE_EXPORT int
irmanin_init (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char device[256];
char *ptrdevice;
char config[256];
char *ptrconfig;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
char *portname;
1999-12-09 23:15:14 +00:00
2005-01-29 18:49:29 +00:00
int i;
2000-04-03 22:13:57 +00:00
char *filename;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
ptrconfig = NULL;
ptrdevice = NULL;
2005-01-29 18:49:29 +00:00
/* Read config file */
1999-12-09 23:15:14 +00:00
2005-01-29 18:49:29 +00:00
/* What device should be used */
strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0,
""), sizeof(device));
device[sizeof(device)-1] = '\0';
if (*device != '\0') ptrdevice = device;
/* What config file should be used */
strncpy(config, drvthis->config_get_string(drvthis->name, "Config", 0,
""), sizeof(config));
config[sizeof(config)-1] = '\0';
if (*config != '\0') ptrconfig = config;
/* End of config file parsing */
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if (ir_init_commands (ptrconfig, 1) < 0) {
2005-01-29 18:49:29 +00:00
report(RPT_ERR, "error initialising commands: %s\n", strerror (errno));
2000-04-03 22:13:57 +00:00
exit (1);
}
2000-04-03 22:13:57 +00:00
portname = ir_default_portname ();
if (portname == NULL) {
2005-01-29 18:49:29 +00:00
if (ptrdevice != NULL) {
2000-04-03 22:13:57 +00:00
portname = ptrdevice;
} else {
2005-01-29 18:49:29 +00:00
report(RPT_ERR, "error no device defined\n");
2000-04-03 22:13:57 +00:00
exit (1);
}
}
1999-12-09 23:15:14 +00:00
2005-01-29 18:49:29 +00:00
drvthis->getkey = irmanin_getkey;
drvthis->close = irmanin_close;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
for (i = 1; codes[i] != NULL; i++) {
if (ir_register_command (codes[i], i) < 0) {
if (errno == ENOENT) {
2005-01-29 18:49:29 +00:00
report(RPT_WARNING, "%s: no code set for `%s'\n", progname, codes[i]);
2000-04-03 22:13:57 +00:00
} else {
2005-01-29 18:49:29 +00:00
report(RPT_WARNING, "error registering `%s': `%s'\n", codes[i], strerror (errno));
2000-04-03 22:13:57 +00:00
}
}
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
errno = 0;
if (ir_init (portname) < 0) {
2005-01-29 18:49:29 +00:00
report(RPT_ERR, "%s: error initialising Irman: `%s'\n", strerror (errno), portname);
2000-04-03 22:13:57 +00:00
exit (1);
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return 1; // 200 is arbitrary. (must be 1 or more)
1999-12-09 23:15:14 +00:00
}
void
irmanin_close (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
//if (drvthis->framebuf != NULL)
// free (drvthis->framebuf);
//drvthis->framebuf = NULL;
2000-04-03 22:13:57 +00:00
ir_free_commands ();
ir_finish ();
1999-12-09 23:15:14 +00:00
}
//////////////////////////////////////////////////////////////////////
// Tries to read a character from an input device...
//
// Return 0 for "nothing available".
//
char
irmanin_getkey (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
int i;
int cmd;
char key;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
key = (char) 0;
switch (cmd = ir_poll_command ()) {
case IR_CMD_ERROR:
2005-01-29 18:49:29 +00:00
report(RPT_WARNING, "%s: error reading command: %s\n", progname, strerror (errno));
2000-04-03 22:13:57 +00:00
break;
case IR_CMD_UNKNOWN:
break;
default:
key = (char) ('A' - 1 + cmd);
break;
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return key;
1999-12-09 23:15:14 +00:00
}
/* end of irmanin.c */