use long instead of int where pointers are casted
[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         int len=id.length();
77         int idx=0;
78         while(idx <= len-8)
79         {
80                 if (!strncasecmp(&id[idx++], "KEYBOARD", 8))
81                 {
82                         iskeyboard=true;
83                         break;
84                 }
85         }
86         eDebug("Input device \"%s\" is %sa keyboard.", id.c_str(), iskeyboard ? "" : "not ");
87
88 }
89
90 const char *eRCDeviceInputDev::getDescription() const
91 {
92         return id.c_str();
93 }
94
95 class eInputDeviceInit
96 {
97         ePtrList<eRCInputEventDriver> m_drivers;
98         ePtrList<eRCDeviceInputDev> m_devices;
99 public:
100         eInputDeviceInit()
101         {
102                 int i = 0;
103                 while (1)
104                 {
105                         struct stat s;
106                         char filename[128];
107                         sprintf(filename, "/dev/input/event%d", i);
108                         if (stat(filename, &s))
109                                 break;
110                         eRCInputEventDriver *p;
111                         m_drivers.push_back(p = new eRCInputEventDriver(filename));
112                         m_devices.push_back(new eRCDeviceInputDev(p));
113                         ++i;
114                 }
115                 eDebug("Found %d input devices!", i);
116         }
117         
118         ~eInputDeviceInit()
119         {
120                 while (m_drivers.size())
121                 {
122                         delete m_devices.back();
123                         m_devices.pop_back();
124                         delete m_drivers.back();
125                         m_drivers.pop_back();
126                 }
127         }
128 };
129
130 eAutoInitP0<eInputDeviceInit> init_rcinputdev(eAutoInitNumbers::rc+1, "input device driver");