2 Copyright 2004-2005 Chris Tallon
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 Remote* Remote::instance = NULL;
33 remoteType = OLDREMOTE;
41 Remote* Remote::getInstance()
46 int Remote::init(char* devName)
48 if (initted) return 0;
51 device = open(devName, O_RDONLY);
61 int Remote::shutdown()
63 if (!initted) return 0;
70 int Remote::getDevice()
72 if (!initted) return 0;
76 void Remote::setRemoteType(UCHAR newType)
78 if ((newType != OLDREMOTE) && (newType != NEWREMOTE)) return;
82 UCHAR Remote::getButtonPress(int waitType)
85 how = 1 - start new wait
86 how = 2 - continue wait
91 struct timeval* passToSelect = NULL;
99 else if (waitType == 1)
105 else if (waitType == 2)
107 if ((tv.tv_sec == 0) && (tv.tv_usec == 0)) // protection in case timer = 0
114 else if (waitType == 3)
121 FD_SET(device, &readfds);
123 retval = select(device + 1, &readfds, NULL, NULL, &tv);
124 // 0 = nothing happened
125 // 1 = data arrived (actually num of descriptors that changed)
126 // other value = signal or error
127 if (retval == 0) return NA_NONE;
128 if (retval == -1) return NA_SIGNAL;
130 int count = read(device, &input, 4);
133 input = (0X00FF0000 & input) >> 16;
134 Log::getInstance()->log("Remote", Log::DEBUG, "Button %i", input);
136 if (remoteType == OLDREMOTE)
138 if (input == VOLUMEDOWN) return DF_LEFT;
139 if (input == VOLUMEUP) return DF_RIGHT;
140 if (input == CHANNELUP) return DF_UP;
141 if (input == CHANNELDOWN) return DF_DOWN;
144 return (UCHAR) input;