Skip to content

Commit c9c34cc

Browse files
committed
add device.ff_effects_count
1 parent 79d614f commit c9c34cc

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎evdev/device.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class InputDevice(object):
7878
'''
7979

8080
__slots__ = ('fn', 'fd', 'info', 'name', 'phys', '_rawcapabilities',
81-
'version')
81+
'version', 'ff_effects_count')
8282

8383
def __init__(self, dev):
8484
'''
@@ -109,6 +109,9 @@ def __init__(self, dev):
109109
#: The raw dictionary of device capabilities - see `:func:capabilities()`.
110110
self._rawcapabilities = _input.ioctl_capabilities(self.fd)
111111

112+
#: The number of force feedback effects the device can keep in its memory.
113+
self.ff_effects_count = _input.ioctl_EVIOCGEFFECTS(self.fd)
114+
112115
def __del__(self):
113116
if hasattr(self, 'fd') and self.fd is not None:
114117
try:

‎evdev/input.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@ int test_bit(const char* bitmask, int bit) {
3333
}
3434

3535

36-
// Useful for comparing input events as seen in the extension module
37-
// and as seen in python
38-
// static void
39-
// print_event(struct input_event *ev) {
40-
// fprintf(stderr, "[so] event: time %ld.%06ld, code %02d, type %02d, val %02d\n",
41-
// ev->time.tv_sec, ev->time.tv_usec,
42-
// ev->code, ev->type, ev->value
43-
// );
44-
// }
45-
46-
4736
// Read input event from a device and return a tuple that mimics input_event
4837
static PyObject *
4938
device_read(PyObject *self, PyObject *args)
@@ -354,6 +343,18 @@ get_sw_led_snd(PyObject *self, PyObject *args)
354343
}
355344

356345

346+
static PyObject *
347+
ioctl_EVIOCGEFFECTS(PyObject *self, PyObject *args)
348+
{
349+
int fd, ret, res;
350+
ret = PyArg_ParseTuple(args, "i", &fd);
351+
if (!ret) return NULL;
352+
353+
ret = ioctl(fd, EVIOCGEFFECTS, &res);
354+
return Py_BuildValue("i", res);
355+
}
356+
357+
357358
static PyMethodDef MethodTable[] = {
358359
{ "unpack", event_unpack, METH_VARARGS, "unpack a single input event" },
359360
{ "ioctl_devinfo", ioctl_devinfo, METH_VARARGS, "fetch input device info" },
@@ -362,6 +363,7 @@ static PyMethodDef MethodTable[] = {
362363
{ "ioctl_EVIOCSREP", ioctl_EVIOCSREP, METH_VARARGS},
363364
{ "ioctl_EVIOCGVERSION", ioctl_EVIOCGVERSION, METH_VARARGS},
364365
{ "ioctl_EVIOCGRAB", ioctl_EVIOCGRAB, METH_VARARGS},
366+
{ "ioctl_EVIOCGEFFECTS", ioctl_EVIOCGEFFECTS, METH_VARARGS, "fetch the number of effects the device can keep in its memory." },
365367
{ "get_sw_led_snd", get_sw_led_snd, METH_VARARGS},
366368
{ "device_read", device_read, METH_VARARGS, "read an input event from a device" },
367369
{ "device_read_many", device_read_many, METH_VARARGS, "read all available input events from a device" },

0 commit comments

Comments
 (0)