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

Apple MFi controller buttons with the example of Nimbus+. Hack for a known Nimbus' problem. #1294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Apple MFi controller buttons with the example of Nimbus+. Hack for a …
…known Nimbus' problem.
  • Loading branch information
Viktor Sergiienko committed Mar 29, 2021
commit a66f38d1a3fbdd3ae19a43d74774f51d7c0ee60b
23 changes: 23 additions & 0 deletions CMake/mfi_defs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#SDL Joystick axis mapping (circle-pad)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Imo those changes should be defined during the cmake step:

cmake .. -DJOY_AXIS_LEFTX=0
...

Maybe adding this to the wiki page would be a good idea. But let's see what others think.

set(JOY_AXIS_LEFTX 0)
set(JOY_AXIS_LEFTY 1)

#SDL Joystick button mapping (A / B and X / Y inverted for MFi Nimbus Plus, at least)
set(JOY_BUTTON_A 1)
set(JOY_BUTTON_B 0)
set(JOY_BUTTON_X 3)
set(JOY_BUTTON_Y 2)
set(JOY_BUTTON_LEFTSHOULDER 4)
set(JOY_BUTTON_RIGHTSHOULDER 5)
set(JOY_BUTTON_BACK 15)
set(JOY_BUTTON_START 14)

# No use for it yet!
#set(JOY_BUTTON_MENU 16)

set(JOY_BUTTON_DPAD_DOWN 11)
set(JOY_BUTTON_DPAD_LEFT 13)
set(JOY_BUTTON_DPAD_UP 10)
set(JOY_BUTTON_DPAD_RIGHT 12)
set(JOY_BUTTON_TRIGGERLEFT 6)
set(JOY_BUTTON_TRIGGERRIGHT 7)
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ if(N3DS)
include(n3ds_defs)
endif()

if(APPLE)
include(mfi_defs)
endif()

if(PIE)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()
Expand Down
14 changes: 13 additions & 1 deletion SourceX/controls/devices/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,14 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event)
#endif
#ifdef JOY_AXIS_LEFTY
case JOY_AXIS_LEFTY:
leftStickYUnscaled = -event.jaxis.value;
// Work around Nimbus that reports inverted Y. No known fix,
// AFAIK, and no SDL remapping.
// https://forums.libsdl.org/viewtopic.php?p=51409
if (nimbus_axis_hack_) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this could be a more general flag option for the ini. Something like: "Joystick Invert Y-Axis".

It could even use it as a feature 🤷‍♂️

Copy link
Author

Choose a reason for hiding this comment

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

I was not sure about the usefulness of such a feature outside of this specific vendor, so I'd like to open a discussion.

Copy link
Collaborator

@yuripourre yuripourre Mar 29, 2021

Choose a reason for hiding this comment

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

leftStickYUnscaled = event.jaxis.value;
} else {
leftStickYUnscaled = -event.jaxis.value;
}
leftStickNeedsScaling = true;
break;
#endif
Expand Down Expand Up @@ -263,6 +270,11 @@ void Joystick::Add(int device_index)
#ifndef USE_SDL1
result.instance_id_ = SDL_JoystickInstanceID(result.sdl_joystick_);
#endif
if (strstr(SDL_JoystickNameForIndex(device_index), "Nimbus") != NULL) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove it if you move it to options.

SDL_Log("Applying Nimbus axis hack");
result.nimbus_axis_hack_ = true;
}

joysticks_->push_back(result);
sgbControllerActive = true;
}
Expand Down
1 change: 1 addition & 0 deletions SourceX/controls/devices/joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Joystick {

SDL_Joystick *sdl_joystick_ = NULL;
SDL_JoystickID instance_id_ = -1;
bool nimbus_axis_hack_ = false;
};

} // namespace dvl