linux-kernel - 如何使用 FF_CONSTANT 进行 Linux 的力反馈?
问题描述
我无法利用FF_CONSTANT力效应。我的尝试代码是:
struct ff_effect joy_effect_, joy_effect_2;
if (iwantconstantforce)
{
joy_effect_.id = -1;
joy_effect_.type = FF_CONSTANT;
joy_effect_.direction = 0x0000; // down
joy_effect_.replay.length = 100;
joy_effect_.replay.delay = 0;
joy_effect_.trigger.button = 0;
joy_effect_.trigger.interval = 100;
joy_effect_.u.constant.level = 65535;
joy_effect_.u.constant.envelope.attack_length = joy_effect_.replay.length / 10;
joy_effect_.u.constant.envelope.fade_length = joy_effect_.replay.length / 10;
joy_effect_.u.constant.envelope.attack_level = joy_effect_.u.constant.level / 10;
joy_effect_.u.constant.envelope.fade_level = joy_effect_.u.constant.level / 10;
}
我可以使用以下代码产生 FF_SPRING 和 FF_DAMPER 效果。
if (youwantdampereffect)
{
joy_effect_.id = -1;
joy_effect_.direction = 0; // down
joy_effect_.type = FF_DAMPER;
joy_effect_.replay.length = 20;
joy_effect_.replay.delay = 0;
joy_effect_.u.condition[0].right_saturation = 65535;
joy_effect_.u.condition[0].left_saturation = 65535;
joy_effect_.u.condition[0].right_coeff = 65535 / 2;
joy_effect_.u.condition[0].left_coeff = 65535 / 2;
joy_effect_.u.condition[0].deadband = 0;
joy_effect_.u.condition[0].center = 0;
int ret = ioctl(ff_fd_, EVIOCSFF, &joy_effect_); // upload the effect
}
if (youwantspringeffect)
{
joy_effect_2.id = -1;
joy_effect_2.direction = 0; // down
joy_effect_2.type = FF_SPRING;
joy_effect_2.replay.length = 20;
joy_effect_2.replay.delay = 0;
joy_effect_2.u.condition[0].right_saturation = 65535 / 2;
joy_effect_2.u.condition[0].left_saturation = 65535 / 2;
joy_effect_2.u.condition[0].right_coeff = 32767;
joy_effect_2.u.condition[0].left_coeff = 32767;
joy_effect_2.u.condition[0].deadband = 0;
joy_effect_2.u.condition[0].center = 0;
int ret = ioctl(ff_fd_, EVIOCSFF, &joy_effect_2); // upload the effect
}
我没有找到任何关于什么是恒定力效应的感觉或何时使用它有意义的信息。有人可以简要介绍它的重要性和用法吗?
谢谢 :)
解决方案
推荐阅读
- html - 我可以通过 HTML5 中的按钮临时切换 novalidate 以保存表单的当前状态吗
- java - 将变量从 Dialog 传递到 Listview 片段
- extjs - 在 BorderLayout 中心面板上设置 minWidth?
- design-patterns - 分离策略模式返回的类型
- ios - 内容不适合时的 UIView 多行 [iOS]
- javascript - 为什么我的代码会抛出错误“原型不存在”?
- ruby-on-rails - 如何提交多个下拉列表以及其他参数?
- r - 如何从一系列字符中选择唯一的字符串
- python - ImportError:没有名为 nltk.classify 的模块
- android - 认证成功后如何完成活动