Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: OSX XBox Controller Z trigger and dpad not recognised  (Read 3147 times)

0 Members and 1 Guest are viewing this topic.

Haize

  • Newbie
  • *
  • Posts: 15
    • View Profile
OSX XBox Controller Z trigger and dpad not recognised
« on: November 01, 2023, 05:47:09 pm »
This is similar to a previous post https://en.sfml-dev.org/forums/index.php?topic=23034.msg160158#msg160158, but I thought I'd create a new post as that one is over five years old.

I'm using SFML 2.6. When using my xbox controller I get no input from the triggers or dpad. I tested using some other controller testing software and the trigger and dpad worked as expected, so the issue seems to be with SFML. Is this a known issue?

I should also mention that the Z axis, which is the axis I would have expected the trigger to be assinged to, is actually assigned to the right analog stick X axis (so does the horizontal input for the analog stick which uses R for vertical input).

Any help would be appreciated.

Thanks.
« Last Edit: November 01, 2023, 05:48:47 pm by Haize »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: OSX XBox Controller Z trigger and dpad not recognised
« Reply #1 on: November 07, 2023, 12:04:12 pm »
Which controller are you using? It is an official Xbox one?

You mention that you get no input from the triggers. Although I'm pretty sure this isn't the issue, make sure you don't press them together.

It seems weird that the right analog stick is using Z and R for its axis when there are perfectly good pairs of axes for them (mine doesn't even use the R axis at all!).

Does this mean that you can only get input on left axis pair and Z/R pair (and all the buttons)? That is, none of the other axes are getting input at all?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: OSX XBox Controller Z trigger and dpad not recognised
« Reply #2 on: November 07, 2023, 02:29:14 pm »
Could you provide a code example and the respective input/output.

Thrasher said he has a Xbox controller, so maybe he can test it on his macOS machine.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Haize

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: OSX XBox Controller Z trigger and dpad not recognised
« Reply #3 on: November 09, 2023, 12:01:02 pm »
Hello. Thanks for the replies.

Which controller are you using? It is an official Xbox one?

You mention that you get no input from the triggers. Although I'm pretty sure this isn't the issue, make sure you don't press them together.

It seems weird that the right analog stick is using Z and R for its axis when there are perfectly good pairs of axes for them (mine doesn't even use the R axis at all!).

Does this mean that you can only get input on left axis pair and Z/R pair (and all the buttons)? That is, none of the other axes are getting input at all?

To answer @Hapax:
- Yes, I'm using an official wireless xbox PC controller
- I've been pressing the two triggers seperately and together, get no input either way
- Yeah, it's wierd that I'm getting R & Z axis inputs mapped to the right analog stick :shrug:
- I'm not sure I understand the question. Currently X & Y are mapped to the left analog stick and R & Z to the right analog stick. In regards to the buttons - A, B, X, Y, right shoulder, left shoulder, left axis press, right axis press, and the left menu button (one below and to the left of the central X box button) all work. But I don't get anything for the Dpad or the other menu button below and to the right of the central X box button don't register any input.

@eXpl0it3r here's some testing code I've written as requested:

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Joystick.hpp>
#include <iostream>

std::string axisToString(const sf::Joystick::Axis axis) {
  switch (axis) {
    case sf::Joystick::Axis::PovX:
      return "PovX";
    case sf::Joystick::Axis::PovY:
      return "PovY";
    case sf::Joystick::Axis::R:
      return "R";
    case sf::Joystick::Axis::U:
      return "U";
    case sf::Joystick::Axis::V:
      return "V";
    case sf::Joystick::Axis::X:
      return "X";
    case sf::Joystick::Axis::Y:
      return "Y";
    case sf::Joystick::Axis::Z:
      return "Z";
    default:
      return "";
  }
}

int main() {
  sf::RenderWindow window(sf::VideoMode(800, 600), "Test Gamepad");

  sf::Joystick::update();
  std::vector<sf::Joystick::Axis> connectedAxis;
  int numButtons = 0;
  int gamePadIdx = -1;
  for (int i = 0; i < sf::Joystick::Count; i++) {
    if (sf::Joystick::isConnected(i)) {
      gamePadIdx = i;
      std::cout << "found connected gamepad at idx: " << gamePadIdx
                << std::endl;

      numButtons = sf::Joystick::getButtonCount(gamePadIdx);
      std::cout << "number of buttons: " << numButtons << std::endl;

      connectedAxis.clear();

      for (int i = sf::Joystick::Axis::X; i < sf::Joystick::AxisCount; i++) {
        sf::Joystick::Axis axis = static_cast<sf::Joystick::Axis>(i);
        if (sf::Joystick::hasAxis(gamePadIdx, axis)) {
          std::cout << "has axis: " << axisToString(axis) << std::endl;
          connectedAxis.push_back(axis);
        }
      }

      break;
    }
  }

  while (window.isOpen()) {
    sf::Event event;
    while (window.pollEvent(event)) {
      switch (event.type) {
        case sf::Event::Closed: {
          std::cout << "shutting down" << std::endl;
          window.close();
          break;
        }
        case sf::Event::KeyPressed: {
          if (event.key.code == sf::Keyboard::Escape) {
            std::cout << "shutting down" << std::endl;
            window.close();
          }
          break;
        }
        case sf::Event::JoystickConnected: {
          // Don't override if there's already a joystick id
          if (gamePadIdx == -1) {
            gamePadIdx = event.joystickConnect.joystickId;

            std::cout << "found connected gamepad at idx: " << gamePadIdx
                      << std::endl;

            numButtons = sf::Joystick::getButtonCount(gamePadIdx);
            std::cout << "number of buttons: " << numButtons << std::endl;

            connectedAxis.clear();

            for (int i = sf::Joystick::Axis::X; i < sf::Joystick::AxisCount;
                 i++) {
              sf::Joystick::Axis axis = static_cast<sf::Joystick::Axis>(i);
              if (sf::Joystick::hasAxis(gamePadIdx, axis)) {
                std::cout << "has axis: " << axisToString(axis) << std::endl;
                connectedAxis.push_back(axis);
              }
            }
          }
          break;
        }
        case sf::Event::JoystickDisconnected: {
          if (event.joystickConnect.joystickId == gamePadIdx) {
            std::cout << "gamepad disconnected at idx: " << gamePadIdx
                      << std::endl;
            gamePadIdx = -1;
          }
        }
        default:
          break;
      }
    }

    if (gamePadIdx != -1) {
      // Log axis movement
      static const float deadZone = 20.f;
      for (int i = 0; i < connectedAxis.size(); i++) {
        const float axisPos =
            sf::Joystick::getAxisPosition(gamePadIdx, connectedAxis);

        if (std::abs(axisPos) > deadZone) {
          std::cout << "Axis: " << axisToString(connectedAxis)
                    << ", Pos: " << axisPos << std::endl;
        }
      }

      // Log button presses
      for (int i = 0; i < numButtons; i++) {
        if (sf::Joystick::isButtonPressed(gamePadIdx, i)) {
          std::cout << "Button: " << i << " is pressed" << std::endl;
        }
      }
    }
  }
}


When I run this code locally with a controller already connected (wirelessly or wired) I get the output:

Unexpected usage for element of Page Generic Desktop: 0x1
Unexpected usage for element of Page Generic Desktop: 0x1
Joystick (vendor/product id: 0x45e/0xb20) range is an unexpected one: [1, 8]
found connected gamepad at idx: 0
number of buttons: 15
has axis: X
has axis: Y
has axis: Z
has axis: R


The first three lines seem to indicate something isn't right with how the mac OS platform functions are being called, maybe in https://github.com/SFML/SFML/blob/2.6.x/src/SFML/Window/OSX/JoystickImpl.cpp (I hadn't seen this log before as I first discovered this issue when writing a game which was outputting a lot to stdout owing to another library).

When testing the axis and buttons I get the corresponding stdout for the results I mentioned earlier:
> I'm not sure I understand the question. Currently X & Y are mapped to the left analog stick and R & Z to the right analog stick. In regards to the buttons - A, B, X, Y, right shoulder, left shoulder, left axis press, right axis press, and the left menu button (one below and to the left of the central X box button) all work. But I don't get anything for the Dpad or the other menu button below and to the right of the central X box button don't register and input.

I should also mention I've been building from the 2.6.x branch and I'm using macOS 12.7.1, maybe I need to downgrade the SFML version I'm using?

Hope that helps, let me know if you need any more information or testing.

Many Thanks,
Haize
« Last Edit: November 09, 2023, 07:49:24 pm by Haize »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: OSX XBox Controller Z trigger and dpad not recognised
« Reply #4 on: November 10, 2023, 03:56:56 pm »
Thrasher said on Discord that he might get around to testing it on the weekend on his macOS machine with an Xbox controller.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Haize

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: OSX XBox Controller Z trigger and dpad not recognised
« Reply #5 on: November 10, 2023, 06:23:07 pm »
Great stuff. Thank you kindly.