gvalkov/python-evdev

Documentation fix

doron-kahana opened this issue · 3 comments

https://github.com/gvalkov/python-evdev/blob/main/docs/tutorial.rst
In the section Injecting an FF-event into first FF-capable device found, time.sleep() accepts seconds and not ms,
the line should be time.sleep(duration_ms / 1000).

Full code:

from evdev import ecodes, InputDevice, ff, list_devices
import time

# Find first EV_FF capable event device (that we have permissions to use).
for name in list_devices():
    dev = InputDevice(name)
    if ecodes.EV_FF in dev.capabilities():
        break

rumble = ff.Rumble(strong_magnitude=0x0000, weak_magnitude=0xffff)
effect_type = ff.EffectType(ff_rumble_effect=rumble)
duration_ms = 1000

effect = ff.Effect(
    ecodes.FF_RUMBLE, -1, 0,
    ff.Trigger(0, 0),
    ff.Replay(duration_ms, 0),
    effect_type
)

repeat_count = 1
effect_id = dev.upload_effect(effect)
dev.write(ecodes.EV_FF, effect_id, repeat_count)
time.sleep(duration_ms / 1000)
dev.erase_effect(effect_id)

thanks. Could you please make a PR for this? And when you are at it, can you also please add ```py to each codeblock to enable syntax highlighting?

Sure thing.

Thanks. Fixed in 596dc52.