@@ -32,7 +32,7 @@ int test_bit(const char* bitmask, int bit) {
32
32
}
33
33
34
34
35
- // useful for comparing input events as seen in the extension module
35
+ // Useful for comparing input events as seen in the extension module
36
36
// and as seen in python
37
37
static void
38
38
print_event (struct input_event * ev ) {
@@ -137,12 +137,12 @@ ioctl_capabilities(PyObject *self, PyObject *args)
137
137
int ret = PyArg_ParseTuple (args , "i" , & fd );
138
138
if (!ret ) return NULL ;
139
139
140
- // @todo: figure out why fd gets zeroed on the ioctls after the
140
+ // @todo: figure out why fd gets zeroed on an ioctl after the
141
141
// refactoring and get rid of this workaround
142
142
const int _fd = fd ;
143
143
144
144
// Capabilities is a mapping of supported event types to lists of handled
145
- // evenes e.g: {1: [272, 273, 274, 275], 2: [0, 1, 6, 8]}
145
+ // events e.g: {1: [272, 273, 274, 275], 2: [0, 1, 6, 8]}
146
146
PyObject * capabilities = PyDict_New ();
147
147
PyObject * eventcodes = NULL ;
148
148
PyObject * capability = NULL ;
@@ -157,30 +157,35 @@ ioctl_capabilities(PyObject *self, PyObject *args)
157
157
// Build a dictionary of the device's capabilities
158
158
for (ev_type = 0 ; ev_type < EV_MAX ; ev_type ++ ) {
159
159
if (test_bit (ev_bits , ev_type )) {
160
+
160
161
capability = PyLong_FromLong (ev_type );
161
162
eventcodes = PyList_New (0 );
162
163
163
164
memset (& code_bits , 0 , sizeof (code_bits ));
164
165
ioctl (_fd , EVIOCGBIT (ev_type , KEY_MAX ), code_bits );
166
+
165
167
for (ev_code = 0 ; ev_code < KEY_MAX ; ev_code ++ ) {
166
168
if (test_bit (code_bits , ev_code )) {
169
+ // Get abs{min,max,fuzz,flat} values for ABS_* event codes
167
170
if (ev_type == EV_ABS ) {
168
171
memset (& abs_bits , 0 , sizeof (abs_bits ));
169
172
ioctl (_fd , EVIOCGABS (ev_code ), abs_bits );
170
173
171
- absdata = Py_BuildValue ("(iiiii)" , abs_bits [0 ], abs_bits [1 ],
172
- abs_bits [2 ], abs_bits [3 ], abs_bits [4 ],
173
- abs_bits [5 ]);
174
+ absdata = Py_BuildValue ("(iiiii)" , abs_bits [0 ], abs_bits [1 ], abs_bits [2 ],
175
+ abs_bits [3 ], abs_bits [4 ], abs_bits [5 ]);
174
176
175
177
absitem = Py_BuildValue ("(OO)" , PyLong_FromLong (ev_code ), absdata );
178
+
179
+ // absitem -> tuple(ABS_X, (0, 255, 0, 0))
176
180
PyList_Append (eventcodes , absitem );
177
- } else {
181
+ }
182
+ else {
178
183
PyList_Append (eventcodes , PyLong_FromLong (ev_code ));
179
184
}
180
-
181
185
}
182
186
}
183
-
187
+ // capabilities[EV_KEY] = [KEY_A, KEY_B, KEY_C, ...]
188
+ // capabilities[EV_ABS] = [(ABS_X, (0, 255, 0, 0)), ...]
184
189
PyDict_SetItem (capabilities , capability , eventcodes );
185
190
}
186
191
}
0 commit comments