From bc61fa0da87310229e7a665c972f475f09d7a86b Mon Sep 17 00:00:00 2001 From: robijn Date: Wed, 27 Mar 2002 22:46:46 +0000 Subject: [PATCH] Updated lirc driver --- server/drivers/lircin.c | 142 ++++++++++++++++++---------------------- server/drivers/lircin.h | 28 ++++++-- 2 files changed, 89 insertions(+), 81 deletions(-) diff --git a/server/drivers/lircin.c b/server/drivers/lircin.c index ec663ec..ccc4861 100644 --- a/server/drivers/lircin.c +++ b/server/drivers/lircin.c @@ -1,107 +1,66 @@ -#include +/* This is the LCDproc driver for LIRC infrared devices (http://www.lirc.org) + + Copyright (C) 2000, Harald Klein + 2002, Rene Wagner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +*/ + + #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -#define __u32 unsigned int -#define __u8 unsigned char - -#include "shared/str.h" - -#define NAME_LENGTH 128 +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include "lcd.h" #include "lircin.h" +#include "report.h" + char *progname = "lircin"; -int fd; -char buf[256]; -struct sockaddr_un addr; +static int fd; static struct lirc_config *config; -// Vars for the server core MODULE_EXPORT char *api_version = API_VERSION; MODULE_EXPORT int stay_in_foreground = 0; MODULE_EXPORT int supports_multiple = 0; -MODULE_EXPORT char *symbol_prefix = "LB216_"; +MODULE_EXPORT char *symbol_prefix = "lircin_"; - -////////////////////////////////////////////////////////////////////////// -////////////////////// Base "class" to derive from /////////////////////// -////////////////////////////////////////////////////////////////////////// - -//void sigterm(int sig) -//{ -// ir_free_commands(); -// ir_finish(); -// raise(sig); -//} - -MODULE_EXPORT void -lircin_close (Driver * drvthis) -{ - lirc_freeconfig (config); - lirc_deinit (); -} - -////////////////////////////////////////////////////////////////////// -// Tries to read a character from an input device... -// -// Return 0 for "nothing available". -// -MODULE_EXPORT char -lircin_getkey (Driver * drvthis) -{ - char key; - char *ir, *cmd; - - if (!(ir = lirc_nextir ())) { - return 0; - } else { - if (!(cmd = lirc_ir2char (config, ir))) - return 0; - - printf ("lirc: \"%s\"\n", cmd); - sscanf (cmd, "%c", &key); - printf ("\n%c\n", key); - free (ir); - return key; - } - - return 0; -} - -//////////////////////////////////////////////////////////// -// init() should set up any device-specific stuff, and -// point all the function pointers. +/*********************************************************** + * init() should set up any device-specific stuff, and + * point all the function pointers. + */ MODULE_EXPORT int -lircin_init (Driver * drvthis, char *args) +lircin_init (Driver *drvthis, char *args) { -/* assign funktions */ - /* open socket to lirc */ - if (-1 == (fd = lirc_init ("lcdd", 1))) { - fprintf (stderr, "no infrared remote support available\n"); + if (-1 == (fd = lirc_init ("lcdd", LIRCIN_VERBOSELY))) { + report( RPT_ERR, "lirc: Could not connect to lircd." ); return -1; } if (0 != lirc_readconfig (NULL, &config, NULL)) { lirc_deinit (); + report( RPT_ERR, "lirc: lirc_readconfig() failed." ); return -1; } fcntl (fd, F_SETFL, O_NONBLOCK); @@ -114,3 +73,32 @@ lircin_init (Driver * drvthis, char *args) return 0; } + +/********************************************************************* + * Closes the device + */ +MODULE_EXPORT void +lircin_close (Driver *drvthis) +{ + lirc_freeconfig (config); + lirc_deinit (); +} + +/********************************************************************* + * Tries to read a character from an input device... + * + * Return NULL for "nothing available". + */ +MODULE_EXPORT char * +lircin_get_key (Driver *drvthis) +{ + char *code=NULL, *cmd=NULL; + + if ( (lirc_nextcode(&code)==0) && (code!=NULL) ) { + if ( (lirc_code2char(config,code,&cmd)==0) && (cmd!=NULL) ) { + report (RPT_DEBUG, "lirc: \"%s\"", cmd); + } + free (code); + } + return cmd; +} diff --git a/server/drivers/lircin.h b/server/drivers/lircin.h index 0129f4c..aef23e4 100644 --- a/server/drivers/lircin.h +++ b/server/drivers/lircin.h @@ -1,10 +1,30 @@ +/* This is the LCDproc driver for LIRC infrared devices (http://www.lirc.org) + + Copyright (C) 2000, Harald Klein + 2002, Rene Wagner + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +*/ + #ifndef LCD_LIRCIN_H #define LCD_LIRCIN_H -#include "lcd.h" +MODULE_EXPORT int lircin_init (Driver *drvthis, char *args); +MODULE_EXPORT void lircin_close (Driver *drvthis); +MODULE_EXPORT char * lircin_get_key (Driver *drvthis); -MODULE_EXPORT int lircin_init (Driver * drvthis, char *args); -MODULE_EXPORT void lircin_close (Driver * drvthis); -MODULE_EXPORT char lircin_getkey (Driver * drvthis); +#define LIRCIN_VERBOSELY 1 #endif