1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <errno.h>
7 #include <fcntl.h>
8 #include <pthread.h>
9 
10 #include <lirc/lirc_client.h>
11 #include "lirc.h"
12 
13 /*-----------------------------------------------------------------------*/
14 
15 static int debug = 0;
16 static struct lirc_config *config = NULL;
17 
lirc_fbi_init()18 int lirc_fbi_init()
19 {
20     int fd;
21     if (-1 == (fd = lirc_init("fbi",debug))) {
22 	if (debug)
23 	    fprintf(stderr,"lirc: no infrared remote support available\n");
24 	return -1;
25     }
26     if (0 != lirc_readconfig(NULL,&config,NULL)) {
27 	config = NULL;
28     }
29     if (debug)
30 	fprintf(stderr, "lirc: ~/.lircrc file %sfound\n",
31 		config ? "" : "not ");
32 
33     fcntl(fd,F_SETFL,O_NONBLOCK);
34     fcntl(fd,F_SETFD,FD_CLOEXEC);
35     if (debug)
36 	fprintf(stderr,"lirc: init ok\n");
37 
38     return fd;
39 }
40 
lirc_fbi_havedata(int * rc,char key[11])41 int lirc_fbi_havedata(int* rc, char key[11])
42 {
43     char *code,*cmd;
44     int ret=-1;
45 
46     while (lirc_nextcode(&code) == 0  &&  code != NULL) {
47 	ret = 0;
48 	if (config) {
49 	    /* use ~/.lircrc */
50 	    while (lirc_code2char(config,code,&cmd)==0 && cmd != NULL) {
51 		memset(key,0,11);
52 		strncpy(key,cmd,10);
53 		*rc = strlen(cmd);
54 		if (debug)
55 		    fprintf(stderr,"lirc: cmd \"%s\"\n", cmd);
56 	    }
57 	}
58 	free(code);
59     }
60     return ret;
61 }
62