Clamp some force feedback values to 0-0x7fff range, fixed mixup between weak/strong rumble

This commit is contained in:
Ingo Ruhnke 2009-01-24 18:35:41 +01:00
parent 8bc7461d1a
commit 1b5f64654e
2 changed files with 24 additions and 18 deletions

View file

@ -116,6 +116,11 @@ ForceFeedbackEffect::ForceFeedbackEffect()
{
}
int clamp(int lhs, int rhs, int v)
{
return std::max(lhs, std::min(v, rhs));
}
ForceFeedbackEffect::ForceFeedbackEffect(const struct ff_effect& effect)
: playing(false),
count(0),
@ -139,37 +144,37 @@ ForceFeedbackEffect::ForceFeedbackEffect(const struct ff_effect& effect)
switch(effect.type)
{
case FF_CONSTANT:
start_weak_magnitude = abs(effect.u.constant.level);
start_strong_magnitude = abs(effect.u.constant.level);
end_weak_magnitude = abs(effect.u.constant.level);
end_strong_magnitude = abs(effect.u.constant.level);
start_weak_magnitude = clamp(0, 0x7fff, abs(effect.u.constant.level));
start_strong_magnitude = clamp(0, 0x7fff, abs(effect.u.constant.level));
end_weak_magnitude = clamp(0, 0x7fff, abs(effect.u.constant.level));
end_strong_magnitude = clamp(0, 0x7fff, abs(effect.u.constant.level));
envelope = effect.u.constant.envelope;
break;
case FF_PERIODIC:
start_weak_magnitude = abs(effect.u.periodic.magnitude);
start_strong_magnitude = abs(effect.u.periodic.magnitude);
end_weak_magnitude = abs(effect.u.periodic.magnitude);
end_strong_magnitude = abs(effect.u.periodic.magnitude);
start_weak_magnitude = clamp(0, 0x7fff, abs(effect.u.periodic.magnitude));
start_strong_magnitude = clamp(0, 0x7fff, abs(effect.u.periodic.magnitude));
end_weak_magnitude = clamp(0, 0x7fff, abs(effect.u.periodic.magnitude));
end_strong_magnitude = clamp(0, 0x7fff, abs(effect.u.periodic.magnitude));
envelope = effect.u.periodic.envelope;
break;
case FF_RAMP:
start_weak_magnitude = abs(effect.u.ramp.start_level);
start_strong_magnitude = abs(effect.u.ramp.start_level);
end_weak_magnitude = abs(effect.u.ramp.end_level);
end_strong_magnitude = abs(effect.u.ramp.end_level);
start_weak_magnitude = clamp(0, 0x7fff, abs(effect.u.ramp.start_level));
start_strong_magnitude = clamp(0, 0x7fff, abs(effect.u.ramp.start_level));
end_weak_magnitude = clamp(0, 0x7fff, abs(effect.u.ramp.end_level));
end_strong_magnitude = clamp(0, 0x7fff, abs(effect.u.ramp.end_level));
envelope = effect.u.ramp.envelope;
break;
case FF_RUMBLE:
start_weak_magnitude = effect.u.rumble.weak_magnitude;
start_strong_magnitude = effect.u.rumble.strong_magnitude;
end_weak_magnitude = effect.u.rumble.weak_magnitude;
end_strong_magnitude = effect.u.rumble.strong_magnitude;
start_weak_magnitude = clamp(0, 0x7fff, effect.u.rumble.weak_magnitude);
start_strong_magnitude = clamp(0, 0x7fff, effect.u.rumble.strong_magnitude);
end_weak_magnitude = clamp(0, 0x7fff, effect.u.rumble.weak_magnitude);
end_strong_magnitude = clamp(0, 0x7fff, effect.u.rumble.strong_magnitude);
break;
default:

View file

@ -231,8 +231,9 @@ LinuxUinput::update(int msec_delta)
if (ff_callback)
{
ff_callback(ff_handler->get_weak_magnitude() / 128,
ff_handler->get_strong_magnitude() / 128);
ff_callback(ff_handler->get_strong_magnitude() / 128,
ff_handler->get_weak_magnitude() / 128);
}
struct input_event ev;