update irman driver to v0.5 API, lirc as well
This commit is contained in:
@@ -53,6 +53,13 @@ alias ircd-next jvc-fwd
|
||||
#alias ircd-power jvc-power
|
||||
#alias ircd-eject jvc-eject
|
||||
|
||||
alias lcdproc-Up jvc-1
|
||||
alias lcdproc-Down jvc-2
|
||||
alias lcdproc-Left jvc-3
|
||||
alias lcdproc-Right jvc-4
|
||||
alias lcdproc-Enter jvc-5
|
||||
alias lcdproc-Escape jvc-6
|
||||
|
||||
alias lcdproc-A jvc-1
|
||||
alias lcdproc-B jvc-2
|
||||
alias lcdproc-C jvc-3
|
||||
|
||||
+70
-83
@@ -27,37 +27,16 @@
|
||||
#include "report.h"
|
||||
#include "irman.h"
|
||||
|
||||
char *progname = "irmanin";
|
||||
|
||||
char *codes[] = {
|
||||
/* 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
|
||||
CodeMap codemap[] = {
|
||||
{ "", "" }, /* dummy: ir_register_command() needs offset > 0 */
|
||||
{ "lcdproc-Up", "Up" },
|
||||
{ "lcdproc-Down", "Down" },
|
||||
{ "lcdproc-Left", "Left" },
|
||||
{ "lcdproc-Right", "Right" },
|
||||
{ "lcdproc-Enter", "Enter" },
|
||||
{ "lcdproc-Escape", "Escape" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -65,6 +44,11 @@ char *codes[] = {
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
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 = "irmanin_";
|
||||
|
||||
//void sigterm(int sig)
|
||||
//{
|
||||
// ir_free_commands();
|
||||
@@ -78,104 +62,107 @@ char *codes[] = {
|
||||
MODULE_EXPORT int
|
||||
irmanin_init (Driver *drvthis)
|
||||
{
|
||||
char device[256];
|
||||
char *ptrdevice;
|
||||
char config[256];
|
||||
char *ptrconfig;
|
||||
|
||||
char *portname;
|
||||
|
||||
PrivateData *p;
|
||||
char *ptrdevice = NULL;
|
||||
char *ptrconfig = NULL;
|
||||
int i;
|
||||
char *filename;
|
||||
|
||||
ptrconfig = NULL;
|
||||
ptrdevice = NULL;
|
||||
|
||||
/* Allocate and store private data */
|
||||
p = (PrivateData *) calloc(1, sizeof(PrivateData));
|
||||
if (p == NULL)
|
||||
return -1;
|
||||
if (drvthis->store_private_ptr(drvthis, p))
|
||||
return -1;
|
||||
|
||||
/* Read config file */
|
||||
|
||||
/* 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;
|
||||
strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0,
|
||||
""), sizeof(p->device));
|
||||
p->device[sizeof(p->device)-1] = '\0';
|
||||
if (p->device[0] != '\0')
|
||||
ptrdevice = p->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;
|
||||
strncpy(p->config, drvthis->config_get_string(drvthis->name, "Config", 0,
|
||||
""), sizeof(p->config));
|
||||
p->config[sizeof(p->config)-1] = '\0';
|
||||
if (p->config[0] != '\0')
|
||||
ptrconfig = p->config;
|
||||
|
||||
/* End of config file parsing */
|
||||
|
||||
if (ir_init_commands (ptrconfig, 1) < 0) {
|
||||
report(RPT_ERR, "error initialising commands: %s\n", strerror (errno));
|
||||
exit (1);
|
||||
if (ir_init_commands(ptrconfig, 1) < 0) {
|
||||
report(RPT_ERR, "%s: error initialising commands: %s", drvthis->name, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
portname = ir_default_portname ();
|
||||
if (portname == NULL) {
|
||||
p->portname = ir_default_portname();
|
||||
if (p->portname == NULL) {
|
||||
if (ptrdevice != NULL) {
|
||||
portname = ptrdevice;
|
||||
p->portname = ptrdevice;
|
||||
} else {
|
||||
report(RPT_ERR, "error no device defined\n");
|
||||
exit (1);
|
||||
report(RPT_ERR, "%s: error no device defined", drvthis->name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
drvthis->getkey = irmanin_getkey;
|
||||
drvthis->close = irmanin_close;
|
||||
|
||||
for (i = 1; codes[i] != NULL; i++) {
|
||||
if (ir_register_command (codes[i], i) < 0) {
|
||||
for (i = 1; codemap[i].irman != NULL; i++) {
|
||||
if (ir_register_command((char *) codemap[i].irman, i) < 0) {
|
||||
if (errno == ENOENT) {
|
||||
report(RPT_WARNING, "%s: no code set for `%s'\n", progname, codes[i]);
|
||||
report(RPT_WARNING, "%s: no code set for `%s'",
|
||||
drvthis->name, codemap[i].irman);
|
||||
} else {
|
||||
report(RPT_WARNING, "error registering `%s': `%s'\n", codes[i], strerror (errno));
|
||||
report(RPT_WARNING, "%s: error registering `%s': %s",
|
||||
drvthis->name, codemap[i].irman, strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
if (ir_init (portname) < 0) {
|
||||
report(RPT_ERR, "%s: error initialising Irman: `%s'\n", strerror (errno), portname);
|
||||
exit (1);
|
||||
if (ir_init(p->portname) < 0) {
|
||||
report(RPT_ERR, "%s: error initialising Irman %s: %s",
|
||||
drvthis->name, p->portname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1; // 200 is arbitrary. (must be 1 or more)
|
||||
return 1; // return success
|
||||
}
|
||||
|
||||
void
|
||||
irmanin_close (Driver *drvthis)
|
||||
{
|
||||
//if (drvthis->framebuf != NULL)
|
||||
// free (drvthis->framebuf);
|
||||
//drvthis->framebuf = NULL;
|
||||
PrivateData *p = drvthis->private_data;
|
||||
|
||||
ir_free_commands ();
|
||||
ir_finish ();
|
||||
if (p != NULL)
|
||||
free(p);
|
||||
drvthis->store_private_ptr(drvthis, NULL);
|
||||
|
||||
ir_free_commands();
|
||||
ir_finish();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Tries to read a character from an input device...
|
||||
// Tries to read a LCDproc character string from an input device...
|
||||
//
|
||||
// Return 0 for "nothing available".
|
||||
// Return NULL for "nothing available".
|
||||
//
|
||||
char
|
||||
irmanin_getkey (Driver *drvthis)
|
||||
char *
|
||||
irmanin_get_key (Driver *drvthis)
|
||||
{
|
||||
int i;
|
||||
int cmd;
|
||||
char key;
|
||||
const char *key = NULL;
|
||||
|
||||
key = (char) 0;
|
||||
switch (cmd = ir_poll_command ()) {
|
||||
switch (cmd = ir_poll_command()) {
|
||||
case IR_CMD_ERROR:
|
||||
report(RPT_WARNING, "%s: error reading command: %s\n", progname, strerror (errno));
|
||||
report(RPT_WARNING, "%s: error reading command: %s",
|
||||
drvthis->name, strerror(errno));
|
||||
break;
|
||||
case IR_CMD_UNKNOWN:
|
||||
break;
|
||||
default:
|
||||
key = (char) ('A' - 1 + cmd);
|
||||
if ((cmd > 0) && (cmd < 7)) // only 6 keys, startinig at ofset 1
|
||||
key = codemap[cmd].lcdproc;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
#ifndef LCD_IRMANIN__H
|
||||
#define LCD_IRMANIN_H
|
||||
|
||||
typedef struct _codemap {
|
||||
const char *irman;
|
||||
const char *lcdproc;
|
||||
} CodeMap;
|
||||
|
||||
typedef struct driver_private_data {
|
||||
char device[256];
|
||||
char config[256];
|
||||
char *portname;
|
||||
} PrivateData;
|
||||
|
||||
MODULE_EXPORT int irmanin_init (Driver *drvthis);
|
||||
MODULE_EXPORT void irmanin_close (Driver *drvthis);
|
||||
MODULE_EXPORT char irmanin_getkey (Driver *drvthis);
|
||||
MODULE_EXPORT char *irmanin_get_key (Driver *drvthis);
|
||||
|
||||
#endif
|
||||
|
||||
+48
-62
@@ -46,10 +46,12 @@
|
||||
#include "report.h"
|
||||
|
||||
typedef struct lircin_private_data {
|
||||
char *progname;
|
||||
char *lircrc;
|
||||
char *prog;
|
||||
int lircin_fd;
|
||||
struct lirc_config *lircin_irconfig;
|
||||
} PrivateData;
|
||||
} PrivateData;
|
||||
|
||||
|
||||
MODULE_EXPORT char *api_version = API_VERSION;
|
||||
MODULE_EXPORT int stay_in_foreground = 0;
|
||||
@@ -63,8 +65,7 @@ MODULE_EXPORT char *symbol_prefix = "lircin_";
|
||||
MODULE_EXPORT int
|
||||
lircin_init (Driver *drvthis)
|
||||
{
|
||||
char s[200]="";
|
||||
char *lircrc, *prog;
|
||||
char s[256] = "";
|
||||
|
||||
PrivateData *p;
|
||||
|
||||
@@ -80,92 +81,64 @@ lircin_init (Driver *drvthis)
|
||||
}
|
||||
|
||||
/* Initialise the PrivateData structure */
|
||||
p->progname=NULL;
|
||||
strncpy( s, "lircin", sizeof( s) );
|
||||
|
||||
p->progname = malloc( strlen( s) + 1 );
|
||||
if( p->progname == NULL ) {
|
||||
report( RPT_ERR, "%s: Could not allocate new memory.", drvthis->name );
|
||||
return -1;
|
||||
}
|
||||
strcpy( p->progname, s );
|
||||
|
||||
/* Initialise local pointers */
|
||||
lircrc=NULL;
|
||||
prog=NULL;
|
||||
p->lircrc = NULL;
|
||||
p->prog = NULL;
|
||||
p->lircin_irconfig = NULL;
|
||||
p->lircin_fd = -1;
|
||||
|
||||
/* READ CONFIG FILE:*/
|
||||
|
||||
/* Get location of lircrc to be used */
|
||||
strcpy(s, "");
|
||||
if (drvthis->config_get_string ( drvthis->name , "lircrc" , 0 , NULL) != NULL)
|
||||
strncpy(s, drvthis->config_get_string ( drvthis->name , "lircrc" , 0 , ""), sizeof(s));
|
||||
|
||||
if (strcmp(s, "") != 0) {
|
||||
s[sizeof(s)-1]=0;
|
||||
lircrc=malloc(strlen(s)+1);
|
||||
if( lircrc == NULL ) {
|
||||
if (*s != '\0') {
|
||||
s[sizeof(s)-1] = '\0';
|
||||
p->lircrc = malloc(strlen(s) + 1);
|
||||
if( p->lircrc == NULL ) {
|
||||
report( RPT_ERR, "%s: Could not allocate new memory.", drvthis->name );
|
||||
return -1;
|
||||
}
|
||||
strcpy(lircrc,s);
|
||||
report (RPT_INFO,"%s: Using lircrc: %s", drvthis->name, lircrc);
|
||||
strcpy(p->lircrc, s);
|
||||
report (RPT_INFO,"%s: Using lircrc: %s", drvthis->name, p->lircrc);
|
||||
}
|
||||
else {
|
||||
report (RPT_INFO,"%s: Using default lircrc: ~/.lircrc", drvthis->name);
|
||||
}
|
||||
|
||||
/* FIXME: This shouldn't be neccessary */
|
||||
strcpy(s, "");
|
||||
|
||||
/* Get program identifier "prog=..." to be used */
|
||||
if (drvthis->config_get_string ( drvthis->name , "prog" , 0 , NULL) != NULL)
|
||||
strncpy(s, drvthis->config_get_string ( drvthis->name , "prog" , 0 , ""), sizeof(s));
|
||||
strncpy(s, drvthis->config_get_string ( drvthis->name , "Prog" , 0 , LIRCIN_DEF_PROG), sizeof(s));
|
||||
|
||||
if (strcmp(s, "") != 0) {
|
||||
s[sizeof(s)-1]=0;
|
||||
report (RPT_INFO,"%s: Using prog: %s", drvthis->name, prog);
|
||||
}
|
||||
else {
|
||||
strcpy(s, LIRCIN_DEF_PROG);
|
||||
}
|
||||
prog=malloc(strlen(s)+1);
|
||||
if( prog == NULL ) {
|
||||
p->prog = malloc(strlen(s) + 1);
|
||||
if( p->prog == NULL ) {
|
||||
report( RPT_ERR, "%s: Could not allocate new memory.", drvthis->name );
|
||||
return -1;
|
||||
}
|
||||
strcpy(prog,s);
|
||||
report (RPT_INFO,"%s: Using prog: %s", drvthis->name, prog);
|
||||
strcpy(p->prog, s);
|
||||
report (RPT_INFO, "%s: Using prog: %s", drvthis->name, p->prog);
|
||||
|
||||
/* End of config file parsing */
|
||||
|
||||
/* open socket to lirc */
|
||||
|
||||
if (-1 == (p->lircin_fd = lirc_init (prog, LIRCIN_VERBOSELY))) {
|
||||
if (p->progname)
|
||||
free (p->progname);
|
||||
p->progname = NULL;
|
||||
if (-1 == (p->lircin_fd = lirc_init (p->prog, LIRCIN_VERBOSELY))) {
|
||||
report( RPT_ERR, "%s: Could not connect to lircd.", drvthis->name );
|
||||
|
||||
lircin_close( drvthis);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != lirc_readconfig (lircrc, &p->lircin_irconfig, NULL)) {
|
||||
lirc_deinit ();
|
||||
|
||||
close (p->lircin_fd);
|
||||
|
||||
if (p->progname)
|
||||
free (p->progname);
|
||||
p->progname = NULL;
|
||||
if (0 != lirc_readconfig (p->lircrc, &p->lircin_irconfig, NULL)) {
|
||||
report( RPT_ERR, "%s: lirc_readconfig() failed.", drvthis->name );
|
||||
|
||||
lircin_close( drvthis);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* socket shouldn't block lcdd */
|
||||
|
||||
if (fcntl(p->lircin_fd, F_SETFL, O_NONBLOCK) < 0){
|
||||
report(RPT_ERR, "%s: Unable to change lircin_fd(%d) to O_NONBLOCK: %s",
|
||||
drvthis->name, p->lircin_fd, strerror(errno));
|
||||
|
||||
lircin_close( drvthis);
|
||||
return -1;
|
||||
}
|
||||
@@ -183,14 +156,27 @@ lircin_close (Driver *drvthis)
|
||||
{
|
||||
PrivateData * p = drvthis->private_data;
|
||||
|
||||
lirc_freeconfig (p->lircin_irconfig);
|
||||
lirc_deinit ();
|
||||
if (p != NULL) {
|
||||
if (p->lircrc != NULL)
|
||||
free(p->lircrc);
|
||||
p->lircrc = NULL;
|
||||
|
||||
close (p->lircin_fd);
|
||||
if (p->prog != NULL)
|
||||
free(p->prog);
|
||||
p->prog = NULL;
|
||||
|
||||
if (p->lircin_irconfig != NULL)
|
||||
lirc_freeconfig (p->lircin_irconfig);
|
||||
p->lircin_irconfig = NULL;
|
||||
|
||||
if (p->lircin_fd >= 0)
|
||||
lirc_deinit ();
|
||||
close (p->lircin_fd);
|
||||
p->lircin_fd = -1;
|
||||
|
||||
if (p->progname)
|
||||
free (p->progname);
|
||||
p->progname = NULL;
|
||||
free(p);
|
||||
}
|
||||
drvthis->store_private_ptr(drvthis, NULL);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -203,9 +189,9 @@ lircin_get_key (Driver *drvthis)
|
||||
{
|
||||
PrivateData * p = drvthis->private_data;
|
||||
|
||||
char *code=NULL, *cmd=NULL;
|
||||
char *code = NULL, *cmd = NULL;
|
||||
|
||||
if ( (lirc_nextcode(&code)==0) && (code!=NULL) ) {
|
||||
if ( (lirc_nextcode(&code) == 0) && (code != NULL) ) {
|
||||
if ( (lirc_code2char(p->lircin_irconfig,code,&cmd)==0) && (cmd!=NULL) ) {
|
||||
report (RPT_DEBUG, "%s: \"%s\"", drvthis->name, cmd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user