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-power jvc-power
|
||||||
#alias ircd-eject jvc-eject
|
#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-A jvc-1
|
||||||
alias lcdproc-B jvc-2
|
alias lcdproc-B jvc-2
|
||||||
alias lcdproc-C jvc-3
|
alias lcdproc-C jvc-3
|
||||||
|
|||||||
+65
-78
@@ -27,37 +27,16 @@
|
|||||||
#include "report.h"
|
#include "report.h"
|
||||||
#include "irman.h"
|
#include "irman.h"
|
||||||
|
|
||||||
char *progname = "irmanin";
|
|
||||||
|
|
||||||
char *codes[] = {
|
CodeMap codemap[] = {
|
||||||
/* dummy */ NULL,
|
{ "", "" }, /* dummy: ir_register_command() needs offset > 0 */
|
||||||
/* KeyToLcd */ "lcdproc-A",
|
{ "lcdproc-Up", "Up" },
|
||||||
/* KeyToLcd */ "lcdproc-B",
|
{ "lcdproc-Down", "Down" },
|
||||||
/* KeyToLcd */ "lcdproc-C",
|
{ "lcdproc-Left", "Left" },
|
||||||
/* KeyToLcd */ "lcdproc-D",
|
{ "lcdproc-Right", "Right" },
|
||||||
/* KeyToLcd */ "lcdproc-E",
|
{ "lcdproc-Enter", "Enter" },
|
||||||
/* KeyToLcd */ "lcdproc-F",
|
{ "lcdproc-Escape", "Escape" },
|
||||||
/* KeyToLcd */ "lcdproc-G",
|
{ NULL, NULL }
|
||||||
/* 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
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@@ -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)
|
//void sigterm(int sig)
|
||||||
//{
|
//{
|
||||||
// ir_free_commands();
|
// ir_free_commands();
|
||||||
@@ -78,104 +62,107 @@ char *codes[] = {
|
|||||||
MODULE_EXPORT int
|
MODULE_EXPORT int
|
||||||
irmanin_init (Driver *drvthis)
|
irmanin_init (Driver *drvthis)
|
||||||
{
|
{
|
||||||
char device[256];
|
PrivateData *p;
|
||||||
char *ptrdevice;
|
char *ptrdevice = NULL;
|
||||||
char config[256];
|
char *ptrconfig = NULL;
|
||||||
char *ptrconfig;
|
|
||||||
|
|
||||||
char *portname;
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
char *filename;
|
|
||||||
|
|
||||||
ptrconfig = NULL;
|
/* Allocate and store private data */
|
||||||
ptrdevice = NULL;
|
p = (PrivateData *) calloc(1, sizeof(PrivateData));
|
||||||
|
if (p == NULL)
|
||||||
|
return -1;
|
||||||
|
if (drvthis->store_private_ptr(drvthis, p))
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* Read config file */
|
/* Read config file */
|
||||||
|
|
||||||
/* What device should be used */
|
/* What device should be used */
|
||||||
strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0,
|
strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0,
|
||||||
""), sizeof(device));
|
""), sizeof(p->device));
|
||||||
device[sizeof(device)-1] = '\0';
|
p->device[sizeof(p->device)-1] = '\0';
|
||||||
if (*device != '\0') ptrdevice = device;
|
if (p->device[0] != '\0')
|
||||||
|
ptrdevice = p->device;
|
||||||
|
|
||||||
/* What config file should be used */
|
/* What config file should be used */
|
||||||
strncpy(config, drvthis->config_get_string(drvthis->name, "Config", 0,
|
strncpy(p->config, drvthis->config_get_string(drvthis->name, "Config", 0,
|
||||||
""), sizeof(config));
|
""), sizeof(p->config));
|
||||||
config[sizeof(config)-1] = '\0';
|
p->config[sizeof(p->config)-1] = '\0';
|
||||||
if (*config != '\0') ptrconfig = config;
|
if (p->config[0] != '\0')
|
||||||
|
ptrconfig = p->config;
|
||||||
|
|
||||||
/* End of config file parsing */
|
/* End of config file parsing */
|
||||||
|
|
||||||
if (ir_init_commands(ptrconfig, 1) < 0) {
|
if (ir_init_commands(ptrconfig, 1) < 0) {
|
||||||
report(RPT_ERR, "error initialising commands: %s\n", strerror (errno));
|
report(RPT_ERR, "%s: error initialising commands: %s", drvthis->name, strerror(errno));
|
||||||
exit (1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
portname = ir_default_portname ();
|
p->portname = ir_default_portname();
|
||||||
if (portname == NULL) {
|
if (p->portname == NULL) {
|
||||||
if (ptrdevice != NULL) {
|
if (ptrdevice != NULL) {
|
||||||
portname = ptrdevice;
|
p->portname = ptrdevice;
|
||||||
} else {
|
} else {
|
||||||
report(RPT_ERR, "error no device defined\n");
|
report(RPT_ERR, "%s: error no device defined", drvthis->name);
|
||||||
exit (1);
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drvthis->getkey = irmanin_getkey;
|
for (i = 1; codemap[i].irman != NULL; i++) {
|
||||||
drvthis->close = irmanin_close;
|
if (ir_register_command((char *) codemap[i].irman, i) < 0) {
|
||||||
|
|
||||||
for (i = 1; codes[i] != NULL; i++) {
|
|
||||||
if (ir_register_command (codes[i], i) < 0) {
|
|
||||||
if (errno == ENOENT) {
|
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 {
|
} 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;
|
errno = 0;
|
||||||
if (ir_init (portname) < 0) {
|
if (ir_init(p->portname) < 0) {
|
||||||
report(RPT_ERR, "%s: error initialising Irman: `%s'\n", strerror (errno), portname);
|
report(RPT_ERR, "%s: error initialising Irman %s: %s",
|
||||||
exit (1);
|
drvthis->name, p->portname, strerror(errno));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1; // 200 is arbitrary. (must be 1 or more)
|
return 1; // return success
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
irmanin_close (Driver *drvthis)
|
irmanin_close (Driver *drvthis)
|
||||||
{
|
{
|
||||||
//if (drvthis->framebuf != NULL)
|
PrivateData *p = drvthis->private_data;
|
||||||
// free (drvthis->framebuf);
|
|
||||||
//drvthis->framebuf = NULL;
|
if (p != NULL)
|
||||||
|
free(p);
|
||||||
|
drvthis->store_private_ptr(drvthis, NULL);
|
||||||
|
|
||||||
ir_free_commands();
|
ir_free_commands();
|
||||||
ir_finish();
|
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
|
char *
|
||||||
irmanin_getkey (Driver *drvthis)
|
irmanin_get_key (Driver *drvthis)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int cmd;
|
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:
|
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;
|
break;
|
||||||
case IR_CMD_UNKNOWN:
|
case IR_CMD_UNKNOWN:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
key = (char) ('A' - 1 + cmd);
|
if ((cmd > 0) && (cmd < 7)) // only 6 keys, startinig at ofset 1
|
||||||
|
key = codemap[cmd].lcdproc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
#ifndef LCD_IRMANIN__H
|
#ifndef LCD_IRMANIN__H
|
||||||
#define 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 int irmanin_init (Driver *drvthis);
|
||||||
MODULE_EXPORT void irmanin_close (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
|
#endif
|
||||||
|
|||||||
+43
-57
@@ -46,11 +46,13 @@
|
|||||||
#include "report.h"
|
#include "report.h"
|
||||||
|
|
||||||
typedef struct lircin_private_data {
|
typedef struct lircin_private_data {
|
||||||
char *progname;
|
char *lircrc;
|
||||||
|
char *prog;
|
||||||
int lircin_fd;
|
int lircin_fd;
|
||||||
struct lirc_config *lircin_irconfig;
|
struct lirc_config *lircin_irconfig;
|
||||||
} PrivateData;
|
} PrivateData;
|
||||||
|
|
||||||
|
|
||||||
MODULE_EXPORT char *api_version = API_VERSION;
|
MODULE_EXPORT char *api_version = API_VERSION;
|
||||||
MODULE_EXPORT int stay_in_foreground = 0;
|
MODULE_EXPORT int stay_in_foreground = 0;
|
||||||
MODULE_EXPORT int supports_multiple = 0;
|
MODULE_EXPORT int supports_multiple = 0;
|
||||||
@@ -63,8 +65,7 @@ MODULE_EXPORT char *symbol_prefix = "lircin_";
|
|||||||
MODULE_EXPORT int
|
MODULE_EXPORT int
|
||||||
lircin_init (Driver *drvthis)
|
lircin_init (Driver *drvthis)
|
||||||
{
|
{
|
||||||
char s[200]="";
|
char s[256] = "";
|
||||||
char *lircrc, *prog;
|
|
||||||
|
|
||||||
PrivateData *p;
|
PrivateData *p;
|
||||||
|
|
||||||
@@ -80,92 +81,64 @@ lircin_init (Driver *drvthis)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise the PrivateData structure */
|
/* Initialise the PrivateData structure */
|
||||||
p->progname=NULL;
|
p->lircrc = NULL;
|
||||||
strncpy( s, "lircin", sizeof( s) );
|
p->prog = NULL;
|
||||||
|
p->lircin_irconfig = NULL;
|
||||||
p->progname = malloc( strlen( s) + 1 );
|
p->lircin_fd = -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;
|
|
||||||
|
|
||||||
/* READ CONFIG FILE:*/
|
/* READ CONFIG FILE:*/
|
||||||
|
|
||||||
/* Get location of lircrc to be used */
|
/* Get location of lircrc to be used */
|
||||||
strcpy(s, "");
|
|
||||||
if (drvthis->config_get_string ( drvthis->name , "lircrc" , 0 , NULL) != NULL)
|
if (drvthis->config_get_string ( drvthis->name , "lircrc" , 0 , NULL) != NULL)
|
||||||
strncpy(s, drvthis->config_get_string ( drvthis->name , "lircrc" , 0 , ""), sizeof(s));
|
strncpy(s, drvthis->config_get_string ( drvthis->name , "lircrc" , 0 , ""), sizeof(s));
|
||||||
|
|
||||||
if (strcmp(s, "") != 0) {
|
if (*s != '\0') {
|
||||||
s[sizeof(s)-1]=0;
|
s[sizeof(s)-1] = '\0';
|
||||||
lircrc=malloc(strlen(s)+1);
|
p->lircrc = malloc(strlen(s) + 1);
|
||||||
if( lircrc == NULL ) {
|
if( p->lircrc == NULL ) {
|
||||||
report( RPT_ERR, "%s: Could not allocate new memory.", drvthis->name );
|
report( RPT_ERR, "%s: Could not allocate new memory.", drvthis->name );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strcpy(lircrc,s);
|
strcpy(p->lircrc, s);
|
||||||
report (RPT_INFO,"%s: Using lircrc: %s", drvthis->name, lircrc);
|
report (RPT_INFO,"%s: Using lircrc: %s", drvthis->name, p->lircrc);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
report (RPT_INFO,"%s: Using default lircrc: ~/.lircrc", drvthis->name);
|
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 */
|
/* 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 , LIRCIN_DEF_PROG), sizeof(s));
|
||||||
strncpy(s, drvthis->config_get_string ( drvthis->name , "prog" , 0 , ""), sizeof(s));
|
|
||||||
|
|
||||||
if (strcmp(s, "") != 0) {
|
p->prog = malloc(strlen(s) + 1);
|
||||||
s[sizeof(s)-1]=0;
|
if( p->prog == NULL ) {
|
||||||
report (RPT_INFO,"%s: Using prog: %s", drvthis->name, prog);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
strcpy(s, LIRCIN_DEF_PROG);
|
|
||||||
}
|
|
||||||
prog=malloc(strlen(s)+1);
|
|
||||||
if( prog == NULL ) {
|
|
||||||
report( RPT_ERR, "%s: Could not allocate new memory.", drvthis->name );
|
report( RPT_ERR, "%s: Could not allocate new memory.", drvthis->name );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strcpy(prog,s);
|
strcpy(p->prog, s);
|
||||||
report (RPT_INFO,"%s: Using prog: %s", drvthis->name, prog);
|
report (RPT_INFO, "%s: Using prog: %s", drvthis->name, p->prog);
|
||||||
|
|
||||||
/* End of config file parsing */
|
/* End of config file parsing */
|
||||||
|
|
||||||
/* open socket to lirc */
|
/* open socket to lirc */
|
||||||
|
if (-1 == (p->lircin_fd = lirc_init (p->prog, LIRCIN_VERBOSELY))) {
|
||||||
if (-1 == (p->lircin_fd = lirc_init (prog, LIRCIN_VERBOSELY))) {
|
|
||||||
if (p->progname)
|
|
||||||
free (p->progname);
|
|
||||||
p->progname = NULL;
|
|
||||||
report( RPT_ERR, "%s: Could not connect to lircd.", drvthis->name );
|
report( RPT_ERR, "%s: Could not connect to lircd.", drvthis->name );
|
||||||
|
|
||||||
|
lircin_close( drvthis);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != lirc_readconfig (lircrc, &p->lircin_irconfig, NULL)) {
|
if (0 != lirc_readconfig (p->lircrc, &p->lircin_irconfig, NULL)) {
|
||||||
lirc_deinit ();
|
|
||||||
|
|
||||||
close (p->lircin_fd);
|
|
||||||
|
|
||||||
if (p->progname)
|
|
||||||
free (p->progname);
|
|
||||||
p->progname = NULL;
|
|
||||||
report( RPT_ERR, "%s: lirc_readconfig() failed.", drvthis->name );
|
report( RPT_ERR, "%s: lirc_readconfig() failed.", drvthis->name );
|
||||||
|
|
||||||
|
lircin_close( drvthis);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* socket shouldn't block lcdd */
|
/* socket shouldn't block lcdd */
|
||||||
|
|
||||||
if (fcntl(p->lircin_fd, F_SETFL, O_NONBLOCK) < 0){
|
if (fcntl(p->lircin_fd, F_SETFL, O_NONBLOCK) < 0){
|
||||||
report(RPT_ERR, "%s: Unable to change lircin_fd(%d) to O_NONBLOCK: %s",
|
report(RPT_ERR, "%s: Unable to change lircin_fd(%d) to O_NONBLOCK: %s",
|
||||||
drvthis->name, p->lircin_fd, strerror(errno));
|
drvthis->name, p->lircin_fd, strerror(errno));
|
||||||
|
|
||||||
lircin_close( drvthis);
|
lircin_close( drvthis);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -183,14 +156,27 @@ lircin_close (Driver *drvthis)
|
|||||||
{
|
{
|
||||||
PrivateData * p = drvthis->private_data;
|
PrivateData * p = drvthis->private_data;
|
||||||
|
|
||||||
|
if (p != NULL) {
|
||||||
|
if (p->lircrc != NULL)
|
||||||
|
free(p->lircrc);
|
||||||
|
p->lircrc = NULL;
|
||||||
|
|
||||||
|
if (p->prog != NULL)
|
||||||
|
free(p->prog);
|
||||||
|
p->prog = NULL;
|
||||||
|
|
||||||
|
if (p->lircin_irconfig != NULL)
|
||||||
lirc_freeconfig (p->lircin_irconfig);
|
lirc_freeconfig (p->lircin_irconfig);
|
||||||
|
p->lircin_irconfig = NULL;
|
||||||
|
|
||||||
|
if (p->lircin_fd >= 0)
|
||||||
lirc_deinit ();
|
lirc_deinit ();
|
||||||
|
|
||||||
close (p->lircin_fd);
|
close (p->lircin_fd);
|
||||||
|
p->lircin_fd = -1;
|
||||||
|
|
||||||
if (p->progname)
|
free(p);
|
||||||
free (p->progname);
|
}
|
||||||
p->progname = NULL;
|
drvthis->store_private_ptr(drvthis, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user