@@ -293,6 +293,44 @@ ioctl_EVIOCGRAB(PyObject *self, PyObject *args)
293293}
294294
295295
296+ // todo: this function needs a better name
297+ static PyObject *
298+ get_sw_led_snd (PyObject * self , PyObject * args )
299+ {
300+ int i , max , fd , evtype , ret ;
301+ PyObject * res = PyList_New (0 );
302+
303+ ret = PyArg_ParseTuple (args , "ii" , & fd , & evtype );
304+ if (!ret ) return NULL ;
305+
306+ if (evtype == EV_LED )
307+ max = LED_MAX ;
308+ else if (evtype == EV_SW )
309+ max = SW_MAX ;
310+ else if (evtype == EV_SND )
311+ max = SND_MAX ;
312+
313+ char * bits = (char * ) malloc (max /8 );
314+ memset (bits , 0 , sizeof (bits ));
315+
316+ if (evtype == EV_LED )
317+ ret = ioctl (fd , EVIOCGLED (sizeof (bits )), bits );
318+ else if (evtype == EV_SW )
319+ ret = ioctl (fd , EVIOCGSW (sizeof (bits )), bits );
320+ else if (evtype == EV_SND )
321+ ret = ioctl (fd , EVIOCGSND (sizeof (bits )), bits );
322+
323+ for (i = 0 ; i < max ; i ++ ) {
324+ if (test_bit (bits , i )) {
325+ PyList_Append (res , Py_BuildValue ("i" , i ));
326+ }
327+ }
328+
329+ free (bits );
330+ return res ;
331+ }
332+
333+
296334static PyMethodDef MethodTable [] = {
297335 { "unpack" , event_unpack , METH_VARARGS , "unpack a single input event" },
298336 { "ioctl_devinfo" , ioctl_devinfo , METH_VARARGS , "fetch input device info" },
@@ -301,6 +339,7 @@ static PyMethodDef MethodTable[] = {
301339 { "ioctl_EVIOCSREP" , ioctl_EVIOCSREP , METH_VARARGS },
302340 { "ioctl_EVIOCGVERSION" , ioctl_EVIOCGVERSION , METH_VARARGS },
303341 { "ioctl_EVIOCGRAB" , ioctl_EVIOCGRAB , METH_VARARGS },
342+ { "get_sw_led_snd" , get_sw_led_snd , METH_VARARGS },
304343 { "device_read" , device_read , METH_VARARGS , "read an input event from a device" },
305344 { "device_read_many" , device_read_many , METH_VARARGS , "read all available input events from a device" },
306345
0 commit comments