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=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
83 CONNECT(sn->activated, eRCShortDriver::keyPressed);
84 eRCInput::getInstance()->setFile(handle);
88 eRCShortDriver::~eRCShortDriver()
96 void eRCInputEventDriver::keyPressed(int)
98 struct input_event ev;
101 if (read(handle, &ev, sizeof(struct input_event))!=sizeof(struct input_event))
103 if (enabled && !input->islocked())
104 for (std::list<eRCDevice*>::iterator i(listeners.begin()); i!=listeners.end(); ++i)
105 (*i)->handleCode((int)&ev);
109 eRCInputEventDriver::eRCInputEventDriver(const char *filename): eRCDriver(eRCInput::getInstance())
111 handle=open(filename, O_RDONLY|O_NONBLOCK);
114 eDebug("failed to open %s", filename);
118 sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
119 CONNECT(sn->activated, eRCInputEventDriver::keyPressed);
120 eRCInput::getInstance()->setFile(handle);
124 std::string eRCInputEventDriver::getDeviceName()
128 ::ioctl(handle, EVIOCGNAME(128), name);
132 eRCInputEventDriver::~eRCInputEventDriver()
140 eRCConfig::eRCConfig()
145 eRCConfig::~eRCConfig()
150 void eRCConfig::set( int delay, int repeat )
156 void eRCConfig::reload()
162 void eRCConfig::save()
166 eRCInput *eRCInput::instance;
174 keyboardMode = kmAll;
177 eRCInput::~eRCInput()
181 void eRCInput::close()
185 bool eRCInput::open()
196 void eRCInput::unlock()
202 void eRCInput::setFile(int newh)
207 void eRCInput::addDevice(const std::string &id, eRCDevice *dev)
209 devices.insert(std::pair<std::string,eRCDevice*>(id, dev));
212 void eRCInput::removeDevice(const std::string &id)
217 eRCDevice *eRCInput::getDevice(const std::string &id)
219 std::map<std::string,eRCDevice*>::iterator i=devices.find(id);
220 if (i == devices.end())
222 eDebug("failed, possible choices are:");
223 for (std::map<std::string,eRCDevice*>::iterator i=devices.begin(); i != devices.end(); ++i)
224 eDebug("%s", i->first.c_str());
230 std::map<std::string,eRCDevice*,eRCInput::lstr> &eRCInput::getDevices()
235 eAutoInitP0<eRCInput> init_rcinput(eAutoInitNumbers::rc, "RC Input layer");