jkuhlmann / gainput

Cross-platform C++ input library supporting gamepads, keyboard, mouse, touch
http://gainput.johanneskuhlmann.de/
MIT License
858 stars 103 forks source link

Not support Xbox one Gamepad BOOL button #69

Closed breezZe closed 4 years ago

breezZe commented 4 years ago

I've got a Xbox one gamepad with bluetooth. Using sample/listenersample, all float signals were triggered rightly, while the Bool signals could not be detected,i.e, button A,B,X,Y and buttons LB,RB, etc.

Is there any solution for this? or not support bluetooth connection?

breezZe commented 4 years ago

I looked into your awesome code. While the Xbox wireless controller and Xbox 360 pad share all the same button dialect, so i added code in GainputInputDevicePadLinux.h as follows.

else if (strcmp(name, "Microsoft X-Box 360 pad") == 0 or strcmp(name, "Xbox Wireless Controller")==0)
        {
#ifdef GAINPUT_DEBUG
            GAINPUT_LOG("  --> known controller\n");
#endif
            buttonDialect_[6] = PadButtonSelect;
            buttonDialect_[9] = PadButtonL3;
            buttonDialect_[10] = PadButtonR3;
            buttonDialect_[7] = PadButtonStart;
            buttonDialect_[4] = PadButtonL1;
            buttonDialect_[5] = PadButtonR1;
            buttonDialect_[3] = PadButtonY;
            buttonDialect_[1] = PadButtonB;
            buttonDialect_[0] = PadButtonA;
            buttonDialect_[2] = PadButtonX;
            buttonDialect_[8] = PadButtonHome;

            axisDialect_[3] = PadButtonRightStickX;
            axisDialect_[4] = PadButtonRightStickY;
            axisDialect_[2] = PadButtonAxis4;
            axisDialect_[5] = PadButtonAxis5;
            axisDialect_[7] = PadButtonUp;
            axisDialect_[6] = PadButtonLeft;

            // Dummy entries for IsValidButton
            axisDialect_[-1] = PadButtonDown;
            axisDialect_[-2] = PadButtonRight;
        }
        else
        {
#ifdef GAINPUT_DEBUG
            GAINPUT_LOG("  --> unknown controller %s\n",name);
#endif
        }

I tested already and it things work ok for linux. Everybody who has same problem, you can clone for the forked and modified repo here. As problem solved, I close this issue.