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 eRCDevice::eRCDevice(std::string id, eRCDriver *driver): driver(driver), id(id)
40 input=driver->getInput();
41 driver->addCodeListener(this);
42 eRCInput::getInstance()->addDevice(id, this);
45 eRCDevice::~eRCDevice()
47 driver->removeCodeListener(this);
48 eRCInput::getInstance()->removeDevice(id.c_str());
51 eRCDriver::eRCDriver(eRCInput *input): input(input), enabled(1)
55 eRCDriver::~eRCDriver()
57 for (std::list<eRCDevice*>::iterator i=listeners.begin(); i!=listeners.end(); ++i)
61 void eRCShortDriver::keyPressed(int)
66 if (read(handle, &rccode, 2)!=2)
68 if (enabled && !input->islocked())
69 for (std::list<eRCDevice*>::iterator i(listeners.begin()); i!=listeners.end(); ++i)
70 (*i)->handleCode(rccode);
74 eRCShortDriver::eRCShortDriver(const char *filename): eRCDriver(eRCInput::getInstance())
76 handle=open(filename, O_RDONLY|O_NONBLOCK);
79 eDebug("failed to open %s", filename);
83 sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
84 CONNECT(sn->activated, eRCShortDriver::keyPressed);
85 eRCInput::getInstance()->setFile(handle);
89 eRCShortDriver::~eRCShortDriver()
97 void eRCInputEventDriver::keyPressed(int)
99 struct input_event ev;
102 if (read(handle, &ev, sizeof(struct input_event))!=sizeof(struct input_event))
104 if (enabled && !input->islocked())
105 for (std::list<eRCDevice*>::iterator i(listeners.begin()); i!=listeners.end(); ++i)
106 (*i)->handleCode((int)&ev);
110 eRCInputEventDriver::eRCInputEventDriver(const char *filename): eRCDriver(eRCInput::getInstance())
112 handle=open(filename, O_RDONLY|O_NONBLOCK);
115 eDebug("failed to open %s", filename);
119 sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
120 CONNECT(sn->activated, eRCInputEventDriver::keyPressed);
121 eRCInput::getInstance()->setFile(handle);
125 std::string eRCInputEventDriver::getDeviceName()
129 ::ioctl(handle, EVIOCGNAME(128), name);
133 eRCInputEventDriver::~eRCInputEventDriver()
141 eRCConfig::eRCConfig()
146 eRCConfig::~eRCConfig()
151 void eRCConfig::set( int delay, int repeat )
157 void eRCConfig::reload()
161 if ( eConfig::getInstance()->getKey("/ezap/rc/repeatRate", rrate) )
163 eConfig::getInstance()->getKey("/ezap/rc/repeatDelay", rdelay);
166 void eRCConfig::save()
168 eConfig::getInstance()->setKey("/ezap/rc/repeatRate", rrate);
169 eConfig::getInstance()->setKey("/ezap/rc/repeatDelay", rdelay);
172 eRCInput *eRCInput::instance;
180 keyboardMode = kmAll;
183 eRCInput::~eRCInput()
187 void eRCInput::close()
191 bool eRCInput::open()
202 void eRCInput::unlock()
208 void eRCInput::setFile(int newh)
213 void eRCInput::addDevice(const std::string &id, eRCDevice *dev)
215 devices.insert(std::pair<std::string,eRCDevice*>(id, dev));
218 void eRCInput::removeDevice(const std::string &id)
223 eRCDevice *eRCInput::getDevice(const std::string &id)
225 std::map<std::string,eRCDevice*>::iterator i=devices.find(id);
226 if (i == devices.end())
228 eDebug("failed, possible choices are:");
229 for (std::map<std::string,eRCDevice*>::iterator i=devices.begin(); i != devices.end(); ++i)
230 eDebug("%s", i->first.c_str());
236 std::map<std::string,eRCDevice*,eRCInput::lstr> &eRCInput::getDevices()
241 eAutoInitP0<eRCInput> init_rcinput(eAutoInitNumbers::rc, "RC Input layer");