Index: src/hid/OFEvdevGameController.m ================================================================== --- src/hid/OFEvdevGameController.m +++ src/hid/OFEvdevGameController.m @@ -71,14 +71,14 @@ /* Google controllers */ static const uint16_t productIDStadia = 0x9400; static const uint16_t buttons[] = { - BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_TL2, - BTN_TR2, BTN_SELECT, BTN_START, BTN_MODE, BTN_THUMBL, BTN_THUMBR, - BTN_DPAD_UP, BTN_DPAD_DOWN, BTN_DPAD_LEFT, BTN_DPAD_RIGHT, - BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2 + BTN_A, BTN_B, BTN_X, BTN_Y, BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, + BTN_SELECT, BTN_START, BTN_MODE, BTN_THUMBL, BTN_THUMBR, BTN_DPAD_UP, + BTN_DPAD_DOWN, BTN_DPAD_LEFT, BTN_DPAD_RIGHT, BTN_TRIGGER_HAPPY1, + BTN_TRIGGER_HAPPY2 }; static OFGameControllerButton buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID) { @@ -105,22 +105,18 @@ return OFGameControllerSRButton; } } else if (vendorID == vendorIDNintendo && productID == productIDN64Controller) { switch (button) { - case BTN_A: - return OFGameControllerAButton; case BTN_B: - return OFGameControllerBButton; + return OFGameControllerWestButton; case BTN_SELECT: - return OFGameControllerCPadUpButton; case BTN_X: - return OFGameControllerCPadDownButton; case BTN_Y: - return OFGameControllerCPadLeftButton; case BTN_C: - return OFGameControllerCPadRightButton; + /* Used to emulate right analog stick. */ + return nil; case BTN_Z: return OFGameControllerCaptureButton; } } else if (vendorID == vendorIDSony && (productID == productIDDualSense || @@ -173,14 +169,10 @@ return OFGameControllerStartButton; case BTN_SELECT: return OFGameControllerSelectButton; case BTN_MODE: return OFGameControllerHomeButton; - case BTN_C: - return OFGameControllerCButton; - case BTN_Z: - return OFGameControllerZButton; } return nil; } @@ -367,10 +359,18 @@ _rightAnalogStickMinX = infoX.minimum; _rightAnalogStickMaxX = infoX.maximum; _rightAnalogStickMinY = infoY.minimum; _rightAnalogStickMaxY = infoY.maximum; } + + if (_vendorID == vendorIDNintendo && + _productID == productIDN64Controller && + OFBitSetIsSet(keyBits, BTN_Y) && + OFBitSetIsSet(keyBits, BTN_C) && + OFBitSetIsSet(keyBits, BTN_SELECT) && + OFBitSetIsSet(keyBits, BTN_X)) + _hasRightAnalogStick = true; if (OFBitSetIsSet(absBits, ABS_HAT0X) && OFBitSetIsSet(absBits, ABS_HAT0Y)) { [_buttons addObject: OFGameControllerDPadLeftButton]; @@ -478,10 +478,34 @@ if (event.value) [_pressedButtons addObject: button]; else [_pressedButtons removeObject: button]; } + + /* Use C buttons to emulate right analog stick */ + if (_vendorID == vendorIDNintendo && + _productID == productIDN64Controller) { + switch (event.code) { + case BTN_Y: + _rightAnalogStickPosition.x += + (event.value ? -1 : 1); + break; + case BTN_C: + _rightAnalogStickPosition.x += + (event.value ? 1 : -1); + break; + case BTN_SELECT: + _rightAnalogStickPosition.y += + (event.value ? -1 : 1); + break; + case BTN_X: + _rightAnalogStickPosition.y += + (event.value ? 1 : -1); + break; + } + } + break; case EV_ABS: if (event.code == ABS_X) _leftAnalogStickPosition.x = scale(event.value, _leftAnalogStickMinX, _leftAnalogStickMaxX); Index: src/hid/OFGameController.h ================================================================== --- src/hid/OFGameController.h +++ src/hid/OFGameController.h @@ -59,20 +59,10 @@ * * @ref OFGameControllerDPadRightButton * * @ref OFGameControllerStartButton * * @ref OFGameControllerSelectButton * * @ref OFGameControllerHomeButton * * @ref OFGameControllerCaptureButton - * * @ref OFGameControllerAButton - * * @ref OFGameControllerBButton - * * @ref OFGameControllerCButton - * * @ref OFGameControllerXButton - * * @ref OFGameControllerYButton - * * @ref OFGameControllerZButton - * * @ref OFGameControllerCPadUpButton - * * @ref OFGameControllerCPadDownButton - * * @ref OFGameControllerCPadLeftButton - * * @ref OFGameControllerCPadRightButton * * @ref OFGameControllerSLButton * * @ref OFGameControllerSRButton * * @ref OFGameControllerAssistantButton */ typedef OFConstantString *OFGameControllerButton; @@ -169,60 +159,10 @@ /** * @brief The Capture button on a game controller. */ extern const OFGameControllerButton OFGameControllerCaptureButton; -/** - * @brief The A button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerAButton; - -/** - * @brief The B button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerBButton; - -/** - * @brief The C button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerCButton; - -/** - * @brief The X button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerXButton; - -/** - * @brief The Y button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerYButton; - -/** - * @brief The Z button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerZButton; - -/** - * @brief The C-Pad Up button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerCPadUpButton; - -/** - * @brief The C-Pad Down button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerCPadDownButton; - -/** - * @brief The C-Pad Left button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerCPadLeftButton; - -/** - * @brief The C-Pad Right button on a game controller. - */ -extern const OFGameControllerButton OFGameControllerCPadRightButton; - /** * @brief The SL button on a game controller. */ extern const OFGameControllerButton OFGameControllerSLButton; @@ -287,17 +227,23 @@ */ @property (readonly, nonatomic) OFPoint leftAnalogStickPosition; /** * @brief Whether the controller has a right analog stick. + * + * @note The Nintendo 64 controller has no right analog stick, however, the C + * buttons are used to emulate one. */ @property (readonly, nonatomic) bool hasRightAnalogStick; /** * @brief The position of the right analog stick. * * The range is from (-1, -1) to (1, 1). + * + * @note The Nintendo 64 controller has no right analog stick, however, the C + * buttons are used to emulate one. */ @property (readonly, nonatomic) OFPoint rightAnalogStickPosition; /** * @brief Returns the available controllers. Index: src/hid/OFGameController.m ================================================================== --- src/hid/OFGameController.m +++ src/hid/OFGameController.m @@ -60,20 +60,10 @@ const OFGameControllerButton OFGameControllerDPadRightButton = @"D-Pad Right"; const OFGameControllerButton OFGameControllerStartButton = @"Start"; const OFGameControllerButton OFGameControllerSelectButton = @"Select"; const OFGameControllerButton OFGameControllerHomeButton = @"Home"; const OFGameControllerButton OFGameControllerCaptureButton = @"Capture"; -const OFGameControllerButton OFGameControllerAButton = @"A"; -const OFGameControllerButton OFGameControllerBButton = @"B"; -const OFGameControllerButton OFGameControllerCButton = @"C"; -const OFGameControllerButton OFGameControllerXButton = @"X"; -const OFGameControllerButton OFGameControllerYButton = @"Y"; -const OFGameControllerButton OFGameControllerZButton = @"Z"; -const OFGameControllerButton OFGameControllerCPadUpButton = @"C-Pad Up"; -const OFGameControllerButton OFGameControllerCPadDownButton = @"C-Pad Down"; -const OFGameControllerButton OFGameControllerCPadLeftButton = @"C-Pad Left"; -const OFGameControllerButton OFGameControllerCPadRightButton = @"C-Pad Right"; const OFGameControllerButton OFGameControllerSLButton = @"SL"; const OFGameControllerButton OFGameControllerSRButton = @"SR"; const OFGameControllerButton OFGameControllerAssistantButton = @"Assistant"; @implementation OFGameController