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/eerror.h>
14 * note on the enigma input layer:
15 * the enigma input layer (rc*) supports n different devices which
16 * all have completely different interfaces, mapped down to 32bit +
17 * make/break/release codes mapped down (via xml files) to "actions".
18 * this was necessary to support multiple remote controls with proprietary
19 * interfaces. now everybody is using input devices, and thus adding
20 * another input layer seems to be a bit overkill. BUT:
21 * image a remote control with two hundred buttons. each and every function
22 * in enigma can be bound to a button. no need to use them twice.
23 * for example, you would have KEY_MENU assigned to a menu for setup etc.,
24 * but no audio and video settings, since you have special keys for that,
25 * and you don't want to display a big menu with entries that are available
26 * with another single key.
27 * then image a remote control with ten buttons. do you really want to waste
28 * KEY_MENU for a simple menu? you need the audio/video settings there too.
29 * take this just as a (bad) example. another (better) example might be front-
30 * button-keys. usually you have KEY_UP, KEY_DOWN, KEY_POWER. you don't want
31 * them to behave like the remote-control-KEY_UP, KEY_DOWN and KEY_POWER,
33 * so here we can map same keys of different input devices to different
37 eRCDevice::eRCDevice(std::string id, eRCDriver *driver): driver(driver), id(id)
39 input=driver->getInput();
40 driver->addCodeListener(this);
41 eRCInput::getInstance()->addDevice(id, this);
44 eRCDevice::~eRCDevice()
46 driver->removeCodeListener(this);
47 eRCInput::getInstance()->removeDevice(id.c_str());
50 eRCDriver::eRCDriver(eRCInput *input): input(input), enabled(1)
54 eRCDriver::~eRCDriver()
56 for (std::list<eRCDevice*>::iterator i=listeners.begin(); i!=listeners.end(); ++i)
60 void eRCShortDriver::keyPressed(int)
65 if (read(handle, &rccode, 2)!=2)
67 if (enabled && !input->islocked())
68 for (std::list<eRCDevice*>::iterator i(listeners.begin()); i!=listeners.end(); ++i)
69 (*i)->handleCode(rccode);
73 eRCShortDriver::eRCShortDriver(const char *filename): eRCDriver(eRCInput::getInstance())
75 handle=open(filename, O_RDONLY|O_NONBLOCK);
78 eDebug("failed to open %s", filename);
82 sn=eSocketNotifier::create(eApp, handle, eSocketNotifier::Read);
83 CONNECT(sn->activated, eRCShortDriver::keyPressed);
84 eRCInput::getInstance()->setFile(handle);
88 eRCShortDriver::~eRCShortDriver()
94 void eRCInputEventDriver::keyPressed(int)
96 struct input_event ev;
99 if (read(handle, &ev, sizeof(struct input_event))!=sizeof(struct input_event))
101 if (enabled && !input->islocked())
102 for (std::list<eRCDevice*>::iterator i(listeners.begin()); i!=listeners.end(); ++i)
103 (*i)->handleCode((long)&ev);
107 eRCInputEventDriver::eRCInputEventDriver(const char *filename): eRCDriver(eRCInput::getInstance())
109 handle=open(filename, O_RDONLY|O_NONBLOCK);
112 eDebug("failed to open %s", filename);
116 sn=eSocketNotifier::create(eApp, handle, eSocketNotifier::Read);
117 CONNECT(sn->activated, eRCInputEventDriver::keyPressed);
118 eRCInput::getInstance()->setFile(handle);
122 std::string eRCInputEventDriver::getDeviceName()
126 ::ioctl(handle, EVIOCGNAME(128), name);
130 eRCInputEventDriver::~eRCInputEventDriver()
136 eRCConfig::eRCConfig()
141 eRCConfig::~eRCConfig()
146 void eRCConfig::set( int delay, int repeat )
152 void eRCConfig::reload()
158 void eRCConfig::save()
162 eRCInput *eRCInput::instance;
170 keyboardMode = kmNone;
173 eRCInput::~eRCInput()
177 void eRCInput::close()
181 bool eRCInput::open()
192 void eRCInput::unlock()
198 void eRCInput::setFile(int newh)
203 void eRCInput::addDevice(const std::string &id, eRCDevice *dev)
205 devices.insert(std::pair<std::string,eRCDevice*>(id, dev));
208 void eRCInput::removeDevice(const std::string &id)
213 eRCDevice *eRCInput::getDevice(const std::string &id)
215 std::map<std::string,eRCDevice*>::iterator i=devices.find(id);
216 if (i == devices.end())
218 eDebug("failed, possible choices are:");
219 for (std::map<std::string,eRCDevice*>::iterator i=devices.begin(); i != devices.end(); ++i)
220 eDebug("%s", i->first.c_str());
226 std::map<std::string,eRCDevice*,eRCInput::lstr> &eRCInput::getDevices()
231 eAutoInitP0<eRCInput> init_rcinput(eAutoInitNumbers::rc, "RC Input layer");