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

Author Topic: Possible reason why a PS4 joystick doesn't work under macOS  (Read 3057 times)

0 Members and 3 Guests are viewing this topic.

AshleyF

  • Newbie
  • *
  • Posts: 30
    • View Profile
Possible reason why a PS4 joystick doesn't work under macOS
« on: November 08, 2016, 10:10:03 am »
Dear All,

On examining JoystickImpl.cpp in the OSX folder for the source code of SFML, I think I may have discovered why SFML still doesn't yet work correctly with my PS4 controller on my iMac.

Before examining the source code, I checked with my existing SFML joystick handler what was and what wasn't detected with my PS4 controller.

All 8 axes were detected correctly, but the PovX and PovY were not listed as detected when tested for individually. I checked the source I'd written on my PC and SFML detects them correctly on the PC.

I have listed the source below to help you in the context of this bug tracking and I think the possible bug in the source code is at the end of the source listing:

// Go through all connected elements.
    for (int i = 0; i < elementsCount; ++i)
    {
        IOHIDElementRef element = (IOHIDElementRef) CFArrayGetValueAtIndex(elements, i);
        switch (IOHIDElementGetType(element))
        {
            case kIOHIDElementTypeInput_Misc:
                switch (IOHIDElementGetUsage(element))
                {
                    case kHIDUsage_GD_X:  m_axis[Joystick::X] = element; break;
                    case kHIDUsage_GD_Y:  m_axis[Joystick::Y] = element; break;
                    case kHIDUsage_GD_Z:  m_axis[Joystick::Z] = element; break;
                    case kHIDUsage_GD_Rx: m_axis[Joystick::U] = element; break;
                    case kHIDUsage_GD_Ry: m_axis[Joystick::V] = element; break;
                    case kHIDUsage_GD_Rz: m_axis[Joystick::R] = element; break;
                    default: break;
                    // kHIDUsage_GD_Vx, kHIDUsage_GD_Vy, kHIDUsage_GD_Vz are ignored.
                }
                break;

            case kIOHIDElementTypeInput_Button:
                if (m_buttons.size() < Joystick::ButtonCount) // If we have free slot...
                    m_buttons.push_back(element); // ...we add this element to the list
                // Else: too many buttons. We ignore this one.
                break;

            default: // Make compiler happy
                break;
        }
    }

If you examine the above source code, you will notice that it does not have a case statement for kHIDUsage_GD_PovX and kHIDUsage_GD_PovY.

Do you think that this could be the cause of the error?

Kind regards,

AshleyF

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Possible reason why a PS4 joystick doesn't work under macOS
« Reply #1 on: November 15, 2016, 06:20:29 pm »
Hi,

I don't have time to dig into this part of SFML before at least a few weeks. If you manage to make it works, let me know. Patch always welcome.
SFML / OS X developer