Skip to content

Commit

Permalink
hid: Implement KEY_RSTICK_* & KEY_LSTICK_* (#466)
Browse files Browse the repository at this point in the history
* hid: Implement KEY_RSTICK_* & KEY_LSTICK_*

* Fix KEY_RSTICK_UP
  • Loading branch information
marysaka authored and AcK77 committed Oct 27, 2018
1 parent 00d4f44 commit 19152de
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Ryujinx.HLE/Hid/Hid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,64 @@ private void InitializeJoyconPair(
Device.Memory.WriteInt32(BaseControllerOffset + 0x24, (int)RightColorButtons);
}

private HidControllerButtons UpdateStickButtons(
HidJoystickPosition LeftStick,
HidJoystickPosition RightStick)
{
HidControllerButtons Result = 0;

if (RightStick.DX < 0)
{
Result |= HidControllerButtons.KEY_RSTICK_LEFT;
}

if (RightStick.DX > 0)
{
Result |= HidControllerButtons.KEY_RSTICK_RIGHT;
}

if (RightStick.DY < 0)
{
Result |= HidControllerButtons.KEY_RSTICK_DOWN;
}

if (RightStick.DY > 0)
{
Result |= HidControllerButtons.KEY_RSTICK_UP;
}

if (LeftStick.DX < 0)
{
Result |= HidControllerButtons.KEY_LSTICK_LEFT;
}

if (LeftStick.DX > 0)
{
Result |= HidControllerButtons.KEY_LSTICK_RIGHT;
}

if (LeftStick.DY < 0)
{
Result |= HidControllerButtons.KEY_LSTICK_DOWN;
}

if (LeftStick.DY > 0)
{
Result |= HidControllerButtons.KEY_LSTICK_UP;
}

return Result;
}

public void SetJoyconButton(
HidControllerId ControllerId,
HidControllerLayouts ControllerLayout,
HidControllerButtons Buttons,
HidJoystickPosition LeftStick,
HidJoystickPosition RightStick)
{
Buttons |= UpdateStickButtons(LeftStick, RightStick);

long ControllerOffset = HidPosition + HidControllersOffset;

ControllerOffset += (int)ControllerId * HidControllerSize;
Expand Down

0 comments on commit 19152de

Please sign in to comment.