1 /***************************************************************************
2 lirc.c - handle lirc input events to Mupen64Plus
4 begin : Friday 11 Jan 2008
5 copyright : (C) 2008 by DarkJezter
6 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 ***************************************************************************/
17 // Functions for LIRC support
25 #include <lirc/lirc_client.h>
27 #include "api/m64p_types.h"
28 #include "api/callbacks.h"
29 #include "plugin/plugin.h"
33 #include "savestates.h"
35 static struct lirc_config *g_config;
36 static int g_lircfd = 0;
40 if((g_lircfd = lirc_init("mupen64plus", 1)) != -1)
43 if(lirc_readconfig(NULL, &g_config, NULL) == 0)
44 DebugMessage(M64MSG_INFO, "LIRC input system started successfully");
46 DebugMessage(M64MSG_WARNING, "LIRC disabled: Error reading lircrc!");
49 DebugMessage(M64MSG_WARNING, "LIRC disabled: Error contacting daemon!");
58 lirc_freeconfig(g_config);
62 DebugMessage(M64MSG_INFO, "LIRC system shut down");
66 void lircCheckInput(void)
68 struct pollfd lircpoll;
69 lircpoll.fd = g_lircfd;
70 lircpoll.events = POLLIN;
72 if(poll(&lircpoll, 1, 0) > 0)
78 if(lirc_nextcode(&code) == 0 && code != NULL)
80 while((ret = lirc_code2char(g_config, code, &c)) == 0 && c!=NULL)
85 *c_ind = toupper(*c_ind);
88 DebugMessage(M64MSG_VERBOSE, "LIRC Execing command \"%s\"", c);
90 if(strcmp(c, "SAVE") == 0)
91 main_state_save(1, NULL); /* save in mupen64plus format using current slot */
92 else if(strcmp(c, "LOAD") == 0)
93 main_state_load(NULL); /* load using current slot */
94 else if(strcmp(c, "QUIT") == 0)
96 else if(strcmp(c, "FULLSCREEN") == 0)
98 else if(strcmp(c, "MUTE") == 0)
100 else if(strcmp(c, "VOL+") == 0)
102 else if(strcmp(c, "VOL-") == 0)
104 else if(strcmp(c, "SCREENSHOT") == 0)
105 main_take_next_screenshot();
106 else if(strcmp(c, "SPEED+") == 0)
108 else if(strcmp(c, "SPEED-") == 0)
110 else if(strcmp(c, "ADVANCE") == 0)
112 else if(strcmp(c, "PAUSE") == 0)
116 int val = ((int)c[0])-((int) '0');
117 if (val >= 0 && val <= 9)
118 savestates_select_slot( val );