Skip to main content
 首页 » 编程设计

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

2024年10月24日21dyllove98

我喜欢使用 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)