gvalkov / python-evdev

Python bindings for the Linux input subsystem
https://python-evdev.rtfd.org/
BSD 3-Clause "New" or "Revised" License
334 stars 112 forks source link

Documentation fix #190

Closed doron-kahana closed 6 months ago

doron-kahana commented 1 year ago

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)
sezanzeb commented 1 year ago

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?

doron-kahana commented 1 year ago

Sure thing.

gvalkov commented 6 months ago

Thanks. Fixed in 596dc52.