如何使用python evdev发送隆隆声效果到设备



我喜欢使用python evdev发送隆隆声效果到设备。这应该通过upload_effect()函数实现,它需要一个缓冲区对象作为输入。

这是capabilities()所揭示的:

('EV_FF', 21L): [
    (['FF_EFFECT_MIN', 'FF_RUMBLE'], 80L),
    ('FF_PERIODIC', 81L),
    (['FF_SQUARE', 'FF_WAVEFORM_MIN'], 88L),
    ('FF_TRIANGLE', 89L),
    ('FF_SINE', 90L),
    ('FF_GAIN', 96L),
    ],

如何创建缓冲区?

Python-evdev 1.1.0支持强制反馈效果上传。下面是文档中的一个示例:

from evdev import ecodes, InputDevice, ff
# Find first EV_FF capable event device (that we have permissions
# to use).
for name in evdev.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)
dev.erase_effect(effect_id)

相关内容

  • 没有找到相关文章

最新更新