Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joystick input for Windows & Linux #380

Merged
merged 27 commits into from
Jan 7, 2025
Merged

Joystick input for Windows & Linux #380

merged 27 commits into from
Jan 7, 2025

Conversation

dylwhich
Copy link
Collaborator

@dylwhich dylwhich commented Jan 7, 2025

Description

Joystick inputs! They work on Windows and Linux, I haven't attempted OSX at all.

On both platforms, the joystick must be connected before the emulator starts. If the joystick is disconnected, the emulator will not attempt to reconnect to it.

Also in support of arcade-y things, I fixed the emulator display not being centered properly in fullscreen and some other situations that come up more often now that the LEDs have moved.

Test Instructions

It's more or less plug and play! On Windows, will open the first joystick device available. On Linux, will open /dev/input/js0.

  1. Plug in a swadge to USB
  2. Open up Gamepad mode and start in Computer mode
  3. Start the emulator
  4. It should Just Work!
  5. Try the Touch Test and Accel Test modes, and also everything else.
  6. Open the emulator in fullscreen

Ticket Links

Readiness Checklist

  • I have run make format to format the changes
  • I have compiled the firmware and the changes have no warnings
  • I have compiled the emulator and the changes have no warnings
  • I have run make cppcheck and checked that cppcheck_result.txt has no warnings for the changes
  • I have added doxygen comments to any code used by more than one Swadge mode. This includes /*! \file comments with Design Philosophy, Usage, and Example sections for new headers.
  • I have run make docs and checked that doxy_warnings.txt has no warnings for the new code

@dylwhich dylwhich requested a review from AEFeinstein January 7, 2025 03:37
// 4. Update the last state to match the new data returned
// 5. If nothing is different, set pendingState = false;
JOYINFOEX winEvent = {0};
// what the hell kind of API requires this
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows API!

}
}
} while (0);
#elif defined(EMU_LINUX)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems nicer

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too but in fairness to windows I wrapped the linux API pretty tightly and just made the windows one comply with that which looks a bit more ugly lol

case DPAD_AXIS_Y:
{
buttonBit_t curState = 0;
if (joystickExt.axisData[DPAD_AXIS_X] < 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on the actual Swadge the D-Pad is four discrete buttons, but here's it's a proper D-Pad, so the hardware can handle simultaneous up/down presses while the joystick cannot. I don't think it matters, just a point of interest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah that's true, probably not something we'd realistically need to support anyway. This is also just how the swadge maps the D-pad in gamepad mode, and I guess it's pretty standard since a switch controller also maps its D-pad the same way.

@AEFeinstein AEFeinstein merged commit 6a3287e into main Jan 7, 2025
6 checks passed
@AEFeinstein AEFeinstein deleted the joystick-input branch January 7, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants