DreamInfoHandler.py: strip data. refs #578
[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(long rccode)
15 {
16         struct input_event *ev = (struct input_event *)rccode;
17         if (ev->type!=EV_KEY)
18                 return;
19
20 //      eDebug("%x %x %x", ev->value, ev->code, ev->type);
21
22         if (ev->type!=EV_KEY)
23                 return;
24
25         int km = iskeyboard ? input->getKeyboardMode() : eRCInput::kmNone;
26
27 //      eDebug("keyboard mode %d", km);
28         
29         if (km == eRCInput::kmAll)
30                 return;
31
32         if (km == eRCInput::kmAscii)
33         {
34 //              eDebug("filtering.. %d", ev->code);
35                 bool filtered = ( ev->code > 0 && ev->code < 61 );
36                 switch (ev->code)
37                 {
38                         case KEY_RESERVED:
39                         case KEY_ESC:
40                         case KEY_TAB:
41                         case KEY_BACKSPACE:
42                         case KEY_ENTER:
43                         case KEY_LEFTCTRL:
44                         case KEY_RIGHTSHIFT:
45                         case KEY_LEFTALT:
46                         case KEY_CAPSLOCK:
47                         case KEY_INSERT:
48                         case KEY_DELETE:
49                         case KEY_MUTE:
50                                 filtered=false;
51                         default:
52                                 break;
53                 }
54                 if (filtered)
55                         return;
56 //              eDebug("passed!");
57         }
58
59         switch (ev->value)
60         {
61         case 0:
62                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, eRCKey::flagBreak));
63                 break;
64         case 1:
65                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, 0));
66                 break;
67         case 2:
68                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, eRCKey::flagRepeat));
69                 break;
70         }
71 }
72
73 eRCDeviceInputDev::eRCDeviceInputDev(eRCInputEventDriver *driver)
74         :eRCDevice(driver->getDeviceName(), driver), iskeyboard(false)
75 {
76         if (strcasestr(id.c_str(), "keyboard") != NULL)
77                 iskeyboard = true;
78         setExclusive(true);
79         eDebug("Input device \"%s\" is %sa keyboard.", id.c_str(), iskeyboard ? "" : "not ");
80 }
81
82 void eRCDeviceInputDev::setExclusive(bool b)
83 {
84         if (!iskeyboard)
85                 driver->setExclusive(b);
86 }
87
88 const char *eRCDeviceInputDev::getDescription() const
89 {
90         return id.c_str();
91 }
92
93 class eInputDeviceInit
94 {
95         ePtrList<eRCInputEventDriver> m_drivers;
96         ePtrList<eRCDeviceInputDev> m_devices;
97 public:
98         eInputDeviceInit()
99         {
100                 int i = 0;
101                 while (1)
102                 {
103                         struct stat s;
104                         char filename[128];
105                         sprintf(filename, "/dev/input/event%d", i);
106                         if (stat(filename, &s))
107                                 break;
108                         eRCInputEventDriver *p;
109                         m_drivers.push_back(p = new eRCInputEventDriver(filename));
110                         m_devices.push_back(new eRCDeviceInputDev(p));
111                         ++i;
112                 }
113                 eDebug("Found %d input devices!", i);
114         }
115         
116         ~eInputDeviceInit()
117         {
118                 while (m_drivers.size())
119                 {
120                         delete m_devices.back();
121                         m_devices.pop_back();
122                         delete m_drivers.back();
123                         m_drivers.pop_back();
124                 }
125         }
126 };
127
128 eAutoInitP0<eInputDeviceInit> init_rcinputdev(eAutoInitNumbers::rc+1, "input device driver");