Skip to content

Commit

Permalink
fix axis when not aligned on 0
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Adenis-Lamarre <[email protected]>
  • Loading branch information
nadenislamarre authored and garbear committed May 27, 2024
1 parent ea825e8 commit 6a88107
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/api/udev/JoystickUdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,13 @@ bool CJoystickUdev::ScanEvents(void)
const unsigned int axisIndex = it->second.axisIndex;
const input_absinfo& info = it->second.axisInfo;

if (event.value >= 0)
SetAxisValue(axisIndex, event.value, info.maximum);
int middle = (info.minimum + info.maximum) / 2;
int length = (info.maximum - info.minimum) / 2;

if (std::abs(event.value - middle) > length / 2)
SetAxisValue(axisIndex, event.value - middle, length);
else
SetAxisValue(axisIndex, event.value, -info.minimum);
SetAxisValue(axisIndex, 0, length);
}
}
break;
Expand Down

0 comments on commit 6a88107

Please sign in to comment.