如何使用 python evdev 向设备发送隆隆声效果
How to send a rumble effect to a device using 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)
我喜欢向使用 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)