451ab91e |
1 | /*************************************************************************** |
2 | lirc.c - handle lirc input events to Mupen64Plus |
3 | ------------------- |
4 | begin : Friday 11 Jan 2008 |
5 | copyright : (C) 2008 by DarkJezter |
6 | ***************************************************************************/ |
7 | |
8 | /*************************************************************************** |
9 | * * |
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. * |
14 | * * |
15 | ***************************************************************************/ |
16 | |
17 | // Functions for LIRC support |
18 | |
19 | #ifdef WITH_LIRC |
20 | |
21 | #include <stdlib.h> |
22 | #include <sys/poll.h> |
23 | #include <string.h> |
24 | #include <ctype.h> |
25 | #include <lirc/lirc_client.h> |
26 | |
27 | #include "api/m64p_types.h" |
28 | #include "api/callbacks.h" |
29 | #include "plugin/plugin.h" |
30 | |
31 | #include "lirc.h" |
32 | #include "main.h" |
33 | #include "savestates.h" |
34 | |
35 | static struct lirc_config *g_config; |
36 | static int g_lircfd = 0; |
37 | |
38 | void lircStart(void) |
39 | { |
40 | if((g_lircfd = lirc_init("mupen64plus", 1)) != -1) |
41 | { |
42 | g_config = NULL; |
43 | if(lirc_readconfig(NULL, &g_config, NULL) == 0) |
44 | DebugMessage(M64MSG_INFO, "LIRC input system started successfully"); |
45 | else |
46 | DebugMessage(M64MSG_WARNING, "LIRC disabled: Error reading lircrc!"); |
47 | } |
48 | else |
49 | DebugMessage(M64MSG_WARNING, "LIRC disabled: Error contacting daemon!"); |
50 | } |
51 | |
52 | void lircStop(void) |
53 | { |
54 | if(g_lircfd!=-1) |
55 | { |
56 | if(g_config != NULL) |
57 | { |
58 | lirc_freeconfig(g_config); |
59 | g_config = NULL; |
60 | } |
61 | lirc_deinit(); |
62 | DebugMessage(M64MSG_INFO, "LIRC system shut down"); |
63 | } |
64 | } |
65 | |
66 | void lircCheckInput(void) |
67 | { |
68 | struct pollfd lircpoll; |
69 | lircpoll.fd = g_lircfd; |
70 | lircpoll.events = POLLIN; |
71 | |
72 | if(poll(&lircpoll, 1, 0) > 0) |
73 | { |
74 | char *code; |
75 | char *c; |
76 | int ret; |
77 | |
78 | if(lirc_nextcode(&code) == 0 && code != NULL) |
79 | { |
80 | while((ret = lirc_code2char(g_config, code, &c)) == 0 && c!=NULL) |
81 | { |
82 | char *c_ind = c; |
83 | while(*c_ind != '\0') |
84 | { |
85 | *c_ind = toupper(*c_ind); |
86 | c_ind++; |
87 | } |
88 | DebugMessage(M64MSG_VERBOSE, "LIRC Execing command \"%s\"", c); |
89 | |
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) |
95 | main_stop(); |
96 | else if(strcmp(c, "FULLSCREEN") == 0) |
97 | gfx.changeWindow(); |
98 | else if(strcmp(c, "MUTE") == 0) |
99 | main_volume_mute(); |
100 | else if(strcmp(c, "VOL+") == 0) |
101 | main_volume_up(); |
102 | else if(strcmp(c, "VOL-") == 0) |
103 | main_volume_down(); |
104 | else if(strcmp(c, "SCREENSHOT") == 0) |
105 | main_take_next_screenshot(); |
106 | else if(strcmp(c, "SPEED+") == 0) |
107 | main_speedup(5); |
108 | else if(strcmp(c, "SPEED-") == 0) |
109 | main_speeddown(5); |
110 | else if(strcmp(c, "ADVANCE") == 0) |
111 | main_advance_one(); |
112 | else if(strcmp(c, "PAUSE") == 0) |
113 | main_toggle_pause(); |
114 | else |
115 | { |
116 | int val = ((int)c[0])-((int) '0'); |
117 | if (val >= 0 && val <= 9) |
118 | savestates_select_slot( val ); |
119 | } |
120 | } |
121 | free(code); |
122 | } |
123 | } |
124 | } |
125 | |
126 | #endif //WITH_LIRC |
127 | |