add ability to get ttxpid from python
[enigma2.git] / lib / driver / rcinput.cpp
1 #include <lib/driver/rcinput.h>
2
3 #include <lib/base/eerror.h>
4
5 #include <sys/ioctl.h>
6 #include <linux/input.h>
7 #include <sys/stat.h>
8
9 #include <lib/base/ebase.h>
10 #include <lib/base/init.h>
11 #include <lib/base/init_num.h>
12 #include <lib/driver/input_fake.h>
13
14 void eRCDeviceInputDev::handleCode(int rccode)
15 {
16         struct input_event *ev = (struct input_event *)rccode;
17         if (ev->type!=EV_KEY)
18                 return;
19 //      eDebug("%x %x %x", ev->value, ev->code, ev->type);
20         switch (ev->value)
21         {
22         case 0:
23                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, eRCKey::flagBreak));
24                 break;
25         case 1:
26                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, 0));
27                 break;
28         case 2:
29                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, eRCKey::flagRepeat));
30                 break;
31         }
32 }
33
34 eRCDeviceInputDev::eRCDeviceInputDev(eRCInputEventDriver *driver): eRCDevice(driver->getDeviceName(), driver)
35 {
36 }
37
38 const char *eRCDeviceInputDev::getDescription() const
39 {
40         return id.c_str();
41 }
42
43 class eInputDeviceInit
44 {
45         ePtrList<eRCInputEventDriver> m_drivers;
46         ePtrList<eRCDeviceInputDev> m_devices;
47 public:
48         eInputDeviceInit()
49         {
50                 int i = 0;
51                 while (1)
52                 {
53                         struct stat s;
54                         char filename[128];
55                         sprintf(filename, "/dev/input/event%d", i);
56                         if (stat(filename, &s))
57                                 break;
58                         eRCInputEventDriver *p;
59                         m_drivers.push_back(p = new eRCInputEventDriver(filename));
60                         m_devices.push_back(new eRCDeviceInputDev(p));
61                         ++i;
62                 }
63                 eDebug("Found %d input devices!", i);
64         }
65         
66         ~eInputDeviceInit()
67         {
68                 while (m_drivers.size())
69                 {
70                         delete m_devices.back();
71                         m_devices.pop_back();
72                         delete m_drivers.back();
73                         m_drivers.pop_back();
74                 }
75         }
76 };
77
78 eAutoInitP0<eInputDeviceInit> init_rcinputdev(eAutoInitNumbers::rc+1, "input device driver");