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
2001-05-25 03:14:27 +00:00
#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"
#include "../../../libirman-0.4.1b/irman.h"
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 ///////////////////////
//////////////////////////////////////////////////////////////////////////
lcd_logical_driver * irmanin ;
//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.
2000-03-30 20:20:41 +00:00
int
irmanin_init ( struct lcd_logical_driver * driver , char * args )
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
2000-04-03 22:13:57 +00:00
char * argv [ 64 ];
int argc , i , j ;
char * filename ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
ptrconfig = NULL ;
ptrdevice = NULL ;
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
irmanin = driver ;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
argc = get_args ( argv , args , 64 );
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
for ( i = 0 ; i < argc ; i ++ ) {
//printf("Arg(%i): %s\n", i, argv[i]);
if ( 0 == strcmp ( argv [ i ], "-d" ) || 0 == strcmp ( argv [ i ], "--device" )) {
if ( i + 1 > argc ) {
fprintf ( stderr , "irmanin_init: %s requires an argument \n " , argv [ i ]);
return - 1 ;
}
strcpy ( device , argv [ ++ i ]);
ptrdevice = device ;
} else if ( 0 == strcmp ( argv [ i ], "-c" ) || 0 == strcmp ( argv [ i ], "--config" )) {
if ( i + 1 > argc ) {
fprintf ( stderr , "irmanin_init: %s requires an argument \n " , argv [ i ]);
return - 1 ;
}
strcpy ( config , argv [ ++ i ]);
ptrconfig = config ;
} else if ( 0 == strcmp ( argv [ i ], "-h" ) || 0 == strcmp ( argv [ i ], "--help" )) {
printf ( "LCDproc IrMan input driver \n " " \t -d \t --device \t Select the input device to use \n " " \t -d \t --config \t Select the configuration file to use \n " " \t -h \t --help \t\t Show this help information \n " );
return - 1 ;
} else {
printf ( "Invalid parameter: %s \n " , argv [ i ]);
}
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if ( ir_init_commands ( ptrconfig , 1 ) < 0 ) {
fprintf ( stderr , "error initialising commands: %s \n " , strerror ( errno ));
exit ( 1 );
}
2000-03-30 20:20:41 +00:00
2000-04-03 22:13:57 +00:00
portname = ir_default_portname ();
if ( portname == NULL ) {
if ( ptrdevice == NULL ) {
portname = ptrdevice ;
} else {
fprintf ( stderr , "error no device defined \n " );
exit ( 1 );
}
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
driver -> getkey = irmanin_getkey ;
driver -> 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 ) {
fprintf ( stderr , "%s: no code set for `%s' \n " , progname , codes [ i ]);
} else {
fprintf ( stderr , "error registering `%s': `%s' \n " , codes [ i ], strerror ( errno ));
}
}
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
errno = 0 ;
if ( ir_init ( portname ) < 0 ) {
fprintf ( stderr , "%s: error initialising Irman: `%s' \n " , strerror ( errno ), portname );
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
}
2000-03-30 20:20:41 +00:00
void
irmanin_close ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
if ( irmanin -> framebuf != NULL )
free ( irmanin -> framebuf );
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
irmanin -> framebuf = NULL ;
2000-03-30 20:20:41 +00:00
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".
//
2000-03-30 20:20:41 +00:00
char
irmanin_getkey ()
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 :
fprintf ( stderr , "%s: error reading command: %s \n " , progname , strerror ( errno ));
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 */