2 Copyright 2004-2005 Chris Tallon 2009 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <sys/socket.h>
22 #include "remotelirc.h"
27 #define LIRC_BUFFER_SIZE 128
30 RemoteLirc::RemoteLirc()
39 RemoteLirc::~RemoteLirc()
43 int RemoteLirc::init(char* devName)
45 if (initted) return 0;
48 address.sun_family = AF_UNIX;
50 strcpy(address.sun_path, devName);
51 if (!sockConnect()) return 0;
53 device = open(devName, O_RDONLY);
63 int RemoteLirc::shutdown()
65 if (!initted) return 0;
72 int RemoteLirc::sockConnect()
74 if ((device = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) {
75 if (connect(device, (struct sockaddr *)&address, sizeof(address)) >= 0)
77 Log::getInstance()->log("Remote", Log::INFO, "Connecting lircd failed %s", address.sun_path);
82 Log::getInstance()->log("Remote", Log::INFO, "Creating socket failed");
84 Log::getInstance()->log("Remote", Log::DEBUG, "Creating socket successfull");
89 int RemoteLirc::getDevice()
91 if (!initted) return 0;
95 UCHAR RemoteLirc::getButtonPress(int waitType)
98 how = 1 - start new wait
99 how = 2 - continue wait
104 struct timeval* passToSelect = NULL;
105 char buffer[LIRC_BUFFER_SIZE];
113 else if (waitType == 1)
119 else if (waitType == 2)
121 if ((tv.tv_sec == 0) && (tv.tv_usec == 0)) // protection in case timer = 0
128 else if (waitType == 3)
135 FD_SET(device, &readfds);
137 retval = select(device + 1, &readfds, NULL, NULL, &tv);
138 // 0 = nothing happened
139 // 1 = data arrived (actually num of descriptors that changed)
140 // other value = signal or error
141 if (retval == 0) return NA_NONE;
142 if (retval == -1) return NA_SIGNAL;
144 int count = read(device, &buffer, sizeof(LIRC_BUFFER_SIZE));
147 int input=NA_UNKNOWN;
148 if (sscanf(buffer, "%d", &input) != 1) {
149 Log::getInstance()->log("Remote", Log::DEBUG, "ERROR: unparseable lirc command: %s", buffer);
153 Log::getInstance()->log("Remote", Log::DEBUG, "Button %x", input);
155 return (UCHAR) TranslateHWC(input);
160 void RemoteLirc::clearBuffer()
162 // while(getButtonPress(3) != NA_NONE);
165 UCHAR RemoteLirc::TranslateHWCFixed(ULLONG code)
191 void RemoteLirc::InitHWCListwithDefaults()
193 translist[0x9e] = VOLUMEUP;
194 translist[0x9f] = VOLUMEDOWN;
195 translist[0x94] = CHANNELUP;
196 translist[0x90] = CHANNELDOWN;
199 translist[0xf1] = ZERO;
200 translist[0xf2] = ONE;
201 translist[0xf3] = TWO;
202 translist[0xf4] = THREE;
203 translist[0xf5] = FOUR;
204 translist[0xf6] = FIVE;
205 translist[0xf7] = SIX;
206 translist[0xf8] = SEVEN;
207 translist[0xf9] = EIGHT;
208 translist[0xfa] = NINE;
209 translist[0xd2] = POWER;
210 translist[0x91] = GO;
211 translist[0xde] = RED;
212 translist[0xdf] = GREEN;
213 translist[0xe0] = YELLOW;
214 translist[0xe2] = BLUE;
216 translist[0xe1] = MUTE;
217 translist[0xd5] = REVERSE;
218 translist[0xd6] = FORWARD;
219 translist[0x1b] = STOP;
220 translist[0xea] = PAUSE;
221 translist[0xe9] = PLAY;
222 translist[0xdb] = SKIPBACK;
223 translist[0xdc] = SKIPFORWARD;
226 translist[0xda] = FULL;
232 char* RemoteLirc::HCWDesc(ULLONG hcw)
241 case 0x01: strncpy(ret,tr("Suspend") ,20);break;
242 case 0x09: strncpy(ret,tr("Menu") ,20);break;
243 case 0x0d: strncpy(ret,tr("Enter") ,20);break;
244 case 0x1b: strncpy(ret,tr("Stop") ,20);break;
245 case 0x8A: strncpy(ret,tr("TV mode") ,20);break;
246 case 0x8c: strncpy(ret,tr("Setup") ,20);break;
247 case 0x8D: strncpy(ret,tr("Return") ,20);break;
248 case 0x90: strncpy(ret,tr("Repeat") ,20);break;
249 case 0x91: strncpy(ret,tr("Time Seek"),20);break;
250 case 0x94: strncpy(ret,tr("Title") ,20);break;
251 case 0x95: strncpy(ret,tr("Info") ,20);break;
252 case 0x9e: strncpy(ret,tr("Volume up") ,20);break;
253 case 0x9f: strncpy(ret,tr("Volume down") ,20);break;
254 case 0xa8: strncpy(ret,tr("up") ,20);break;
255 case 0xaa: strncpy(ret,tr("Left") ,20);break;
256 case 0xab: strncpy(ret,tr("Right") ,20);break;
257 case 0xa9: strncpy(ret,tr("Down") ,20);break;
258 case 0xd0: strncpy(ret,tr("Home") ,20);break;
259 case 0xd2: strncpy(ret,tr("Stand by") ,20);break;
260 case 0xd5: strncpy(ret,tr("Backward") ,20);break;
261 case 0xd6: strncpy(ret,tr("Forward") ,20);break;
262 case 0xd8: strncpy(ret,tr("Audio") ,20);break;
263 case 0xd9: strncpy(ret,tr("Slow") ,20);break;
264 case 0xda: strncpy(ret,tr("Zoom") ,20);break;
265 case 0xdb: strncpy(ret,tr("Previous") ,20);break;
266 case 0xde: strncpy(ret,tr("Red") ,20);break;
267 case 0xdc: strncpy(ret,tr("Next") ,20);break;
268 case 0xdf: strncpy(ret,tr("Green") ,20);break;
269 case 0xe0: strncpy(ret,tr("Yellow") ,20);break;
270 case 0xe1: strncpy(ret,tr("Mute") ,20);break;
271 case 0xe2: strncpy(ret,tr("Blue") ,20);break;
272 case 0xe9: strncpy(ret,tr("Play") ,20);break;
273 case 0xea: strncpy(ret,tr("Pause") ,20);break;
274 case 0xeb: strncpy(ret,tr("Subtitle") ,20);break;
275 case 0xec: strncpy(ret,tr("Angle") ,20);break;
276 case 0xef: strncpy(ret,tr("Eject") ,20);break;
277 case 0xf1: strncpy(ret,tr("0") ,20);break;
278 case 0xf2: strncpy(ret,tr("1") ,20);break;
279 case 0xf3: strncpy(ret,tr("2") ,20);break;
280 case 0xf4: strncpy(ret,tr("3") ,20);break;
281 case 0xf5: strncpy(ret,tr("4") ,20);break;
282 case 0xf6: strncpy(ret,tr("5") ,20);break;
283 case 0xf7: strncpy(ret,tr("6") ,20);break;
284 case 0xf8: strncpy(ret,tr("7") ,20);break;
285 case 0xf9: strncpy(ret,tr("8") ,20);break;
286 case 0xfA: strncpy(ret,tr("9") ,20);break;
287 case 0xFC: strncpy(ret,tr("Caps") ,20);break;
288 case 0xFD: strncpy(ret,tr("File mode") ,20);break;
293 sprintf(ret,"R: %X",ri);