1 #include <lib/driver/rc.h>
7 #include <linux/input.h>
9 #include <lib/base/init.h>
10 #include <lib/base/init_num.h>
11 #include <lib/base/econfig.h>
12 #include <lib/base/eerror.h>
15 * note on the enigma input layer:
16 * the enigma input layer (rc*) supports n different devices which
17 * all have completely different interfaces, mapped down to 32bit +
18 * make/break/release codes mapped down (via xml files) to "actions".
19 * this was necessary to support multiple remote controls with proprietary
20 * interfaces. now everybody is using input devices, and thus adding
21 * another input layer seems to be a bit overkill. BUT:
22 * image a remote control with two hundred buttons. each and every function
23 * in enigma can be bound to a button. no need to use them twice.
24 * for example, you would have KEY_MENU assigned to a menu for setup etc.,
25 * but no audio and video settings, since you have special keys for that,
26 * and you don't want to display a big menu with entries that are available
27 * with another single key.
28 * then image a remote control with ten buttons. do you really want to waste
29 * KEY_MENU for a simple menu? you need the audio/video settings there too.
30 * take this just as a (bad) example. another (better) example might be front-
31 * button-keys. usually you have KEY_UP, KEY_DOWN, KEY_POWER. you don't want
32 * them to behave like the remote-control-KEY_UP, KEY_DOWN and KEY_POWER,
34 * so here we can map same keys of different input devices to different
38 int eRCDevice::getKeyCompatibleCode(const eRCKey &) const
43 eRCDevice::eRCDevice(std::string id, eRCDriver *driver): driver(driver), id(id)
45 input=driver->getInput();
46 driver->addCodeListener(this);
47 eRCInput::getInstance()->addDevice(id, this);
50 eRCDevice::~eRCDevice()
52 driver->removeCodeListener(this);
53 eRCInput::getInstance()->removeDevice(id.c_str());
56 eRCDriver::eRCDriver(eRCInput *input): input(input), enabled(1)
60 eRCDriver::~eRCDriver()
62 for (std::list<eRCDevice*>::iterator i=listeners.begin(); i!=listeners.end(); ++i)
66 void eRCShortDriver::keyPressed(int)
71 if (read(handle, &rccode, 2)!=2)
73 if (enabled && !input->islocked())
74 for (std::list<eRCDevice*>::iterator i(listeners.begin()); i!=listeners.end(); ++i)
75 (*i)->handleCode(rccode);
79 eRCShortDriver::eRCShortDriver(const char *filename): eRCDriver(eRCInput::getInstance())
81 handle=open(filename, O_RDONLY|O_NONBLOCK);
84 eDebug("failed to open %s", filename);
88 sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
89 CONNECT(sn->activated, eRCShortDriver::keyPressed);
90 eRCInput::getInstance()->setFile(handle);
94 eRCShortDriver::~eRCShortDriver()
102 void eRCInputEventDriver::keyPressed(int)
104 struct input_event ev;
107 if (read(handle, &ev, sizeof(struct input_event))!=sizeof(struct input_event))
109 if (enabled && !input->islocked())
110 for (std::list<eRCDevice*>::iterator i(listeners.begin()); i!=listeners.end(); ++i)
111 (*i)->handleCode((int)&ev);
115 eRCInputEventDriver::eRCInputEventDriver(const char *filename): eRCDriver(eRCInput::getInstance())
117 handle=open(filename, O_RDONLY|O_NONBLOCK);
120 eDebug("failed to open %s", filename);
124 sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
125 CONNECT(sn->activated, eRCInputEventDriver::keyPressed);
126 eRCInput::getInstance()->setFile(handle);
130 std::string eRCInputEventDriver::getDeviceName()
134 ::ioctl(handle, EVIOCGNAME(128), name);
138 eRCInputEventDriver::~eRCInputEventDriver()
146 eRCConfig::eRCConfig()
151 eRCConfig::~eRCConfig()
156 void eRCConfig::set( int delay, int repeat )
162 void eRCConfig::reload()
166 if ( eConfig::getInstance()->getKey("/ezap/rc/repeatRate", rrate) )
168 eConfig::getInstance()->getKey("/ezap/rc/repeatDelay", rdelay);
171 void eRCConfig::save()
173 eConfig::getInstance()->setKey("/ezap/rc/repeatRate", rrate);
174 eConfig::getInstance()->setKey("/ezap/rc/repeatDelay", rdelay);
177 eRCInput *eRCInput::instance;
187 eRCInput::~eRCInput()
191 void eRCInput::close()
195 bool eRCInput::open()
206 void eRCInput::unlock()
212 void eRCInput::setFile(int newh)
217 void eRCInput::addDevice(const std::string &id, eRCDevice *dev)
219 devices.insert(std::pair<std::string,eRCDevice*>(id, dev));
222 void eRCInput::removeDevice(const std::string &id)
227 eRCDevice *eRCInput::getDevice(const std::string &id)
229 std::map<std::string,eRCDevice*>::iterator i=devices.find(id);
230 if (i == devices.end())
232 eDebug("failed, possible choices are:");
233 for (std::map<std::string,eRCDevice*>::iterator i=devices.begin(); i != devices.end(); ++i)
234 eDebug("%s", i->first.c_str());
240 std::map<std::string,eRCDevice*,eRCInput::lstr> &eRCInput::getDevices()
245 eAutoInitP0<eRCInput> init_rcinput(eAutoInitNumbers::rc, "RC Input layer");