Overview
Comment: | OFGameController: Clean up buttons a bit
This also emulates a right analog stick using the C buttons on the N64 |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | gamecontroller |
Files: | files | file ages | folders |
SHA3-256: |
a0af8f40b8597b158c3616c515948492 |
User & Date: | js on 2024-05-20 15:48:03 |
Other Links: | branch diff | manifest | tags |
Context
2024-05-20
| ||
15:53 | OFGameController: No symbols for custom buttons check-in: cb4c3d09f4 user: js tags: gamecontroller | |
15:48 | OFGameController: Clean up buttons a bit check-in: a0af8f40b8 user: js tags: gamecontroller | |
10:49 | Doxyfile: Generate documentation for ObjFWHID check-in: 8ea353d943 user: js tags: gamecontroller | |
Changes
Modified src/hid/OFEvdevGameController.m from [3ddc2d6279] to [c33068523f].
︙ | ︙ | |||
69 70 71 72 73 74 75 | static const uint16_t productIDDualSense = 0x0CE6; static const uint16_t productIDDualShock4 = 0x09CC; /* Google controllers */ static const uint16_t productIDStadia = 0x9400; static const uint16_t buttons[] = { | | | | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | static const uint16_t productIDDualSense = 0x0CE6; static const uint16_t productIDDualShock4 = 0x09CC; /* Google controllers */ static const uint16_t productIDStadia = 0x9400; static const uint16_t buttons[] = { 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) { if (vendorID == vendorIDNintendo && productID == productIDLeftJoycon) { |
︙ | ︙ | |||
103 104 105 106 107 108 109 | return OFGameControllerSLButton; case BTN_TL2: return OFGameControllerSRButton; } } else if (vendorID == vendorIDNintendo && productID == productIDN64Controller) { switch (button) { | < < | < < < > | | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | return OFGameControllerSLButton; case BTN_TL2: return OFGameControllerSRButton; } } else if (vendorID == vendorIDNintendo && productID == productIDN64Controller) { switch (button) { case BTN_B: return OFGameControllerWestButton; case BTN_SELECT: case BTN_X: case BTN_Y: case BTN_C: /* Used to emulate right analog stick. */ return nil; case BTN_Z: return OFGameControllerCaptureButton; } } else if (vendorID == vendorIDSony && (productID == productIDDualSense || productID == productIDDualShock4)) { switch (button) { |
︙ | ︙ | |||
171 172 173 174 175 176 177 | return OFGameControllerDPadRightButton; case BTN_START: return OFGameControllerStartButton; case BTN_SELECT: return OFGameControllerSelectButton; case BTN_MODE: return OFGameControllerHomeButton; | < < < < | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | return OFGameControllerDPadRightButton; case BTN_START: return OFGameControllerStartButton; case BTN_SELECT: return OFGameControllerSelectButton; case BTN_MODE: return OFGameControllerHomeButton; } return nil; } static float scale(float value, float min, float max) |
︙ | ︙ | |||
365 366 367 368 369 370 371 372 373 374 375 376 377 378 | exception]; _rightAnalogStickMinX = infoX.minimum; _rightAnalogStickMaxX = infoX.maximum; _rightAnalogStickMinY = infoY.minimum; _rightAnalogStickMaxY = infoY.maximum; } if (OFBitSetIsSet(absBits, ABS_HAT0X) && OFBitSetIsSet(absBits, ABS_HAT0Y)) { [_buttons addObject: OFGameControllerDPadLeftButton]; [_buttons addObject: OFGameControllerDPadRightButton]; | > > > > > > > > | 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | exception]; _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]; [_buttons addObject: OFGameControllerDPadRightButton]; |
︙ | ︙ | |||
476 477 478 479 480 481 482 483 484 485 486 487 488 489 | if ((button = buttonToName(event.code, _vendorID, _productID)) != nil) { if (event.value) [_pressedButtons addObject: button]; else [_pressedButtons removeObject: button]; } break; case EV_ABS: if (event.code == ABS_X) _leftAnalogStickPosition.x = scale(event.value, _leftAnalogStickMinX, _leftAnalogStickMaxX); else if (event.code == ABS_Y) _leftAnalogStickPosition.y = scale(event.value, | > > > > > > > > > > > > > > > > > > > > > > > > | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | if ((button = buttonToName(event.code, _vendorID, _productID)) != nil) { 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); else if (event.code == ABS_Y) _leftAnalogStickPosition.y = scale(event.value, |
︙ | ︙ |
Modified src/hid/OFGameController.h from [377e60382e] to [c213cd4864].
︙ | ︙ | |||
57 58 59 60 61 62 63 | * * @ref OFGameControllerDPadDownButton * * @ref OFGameControllerDPadLeftButton * * @ref OFGameControllerDPadRightButton * * @ref OFGameControllerStartButton * * @ref OFGameControllerSelectButton * * @ref OFGameControllerHomeButton * * @ref OFGameControllerCaptureButton | < < < < < < < < < < | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | * * @ref OFGameControllerDPadDownButton * * @ref OFGameControllerDPadLeftButton * * @ref OFGameControllerDPadRightButton * * @ref OFGameControllerStartButton * * @ref OFGameControllerSelectButton * * @ref OFGameControllerHomeButton * * @ref OFGameControllerCaptureButton * * @ref OFGameControllerSLButton * * @ref OFGameControllerSRButton * * @ref OFGameControllerAssistantButton */ typedef OFConstantString *OFGameControllerButton; #ifdef __cplusplus |
︙ | ︙ | |||
167 168 169 170 171 172 173 | extern const OFGameControllerButton OFGameControllerHomeButton; /** * @brief The Capture button on a game controller. */ extern const OFGameControllerButton OFGameControllerCaptureButton; | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | extern const OFGameControllerButton OFGameControllerHomeButton; /** * @brief The Capture button on a game controller. */ extern const OFGameControllerButton OFGameControllerCaptureButton; /** * @brief The SL button on a game controller. */ extern const OFGameControllerButton OFGameControllerSLButton; /** * @brief The SR button on a game controller. |
︙ | ︙ | |||
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | * * The range is from (-1, -1) to (1, 1). */ @property (readonly, nonatomic) OFPoint leftAnalogStickPosition; /** * @brief Whether the controller has a right analog stick. */ @property (readonly, nonatomic) bool hasRightAnalogStick; /** * @brief The position of the right analog stick. * * The range is from (-1, -1) to (1, 1). */ @property (readonly, nonatomic) OFPoint rightAnalogStickPosition; /** * @brief Returns the available controllers. * * @return The available controllers | > > > > > > | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | * * The range is from (-1, -1) to (1, 1). */ @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. * * @return The available controllers |
︙ | ︙ |
Modified src/hid/OFGameController.m from [6850544fb5] to [4c858784ed].
︙ | ︙ | |||
58 59 60 61 62 63 64 | const OFGameControllerButton OFGameControllerDPadDownButton = @"D-Pad Down"; const OFGameControllerButton OFGameControllerDPadLeftButton = @"D-Pad Left"; const OFGameControllerButton OFGameControllerDPadRightButton = @"D-Pad Right"; const OFGameControllerButton OFGameControllerStartButton = @"Start"; const OFGameControllerButton OFGameControllerSelectButton = @"Select"; const OFGameControllerButton OFGameControllerHomeButton = @"Home"; const OFGameControllerButton OFGameControllerCaptureButton = @"Capture"; | < < < < < < < < < < | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | const OFGameControllerButton OFGameControllerDPadDownButton = @"D-Pad Down"; const OFGameControllerButton OFGameControllerDPadLeftButton = @"D-Pad Left"; const OFGameControllerButton OFGameControllerDPadRightButton = @"D-Pad Right"; const OFGameControllerButton OFGameControllerStartButton = @"Start"; const OFGameControllerButton OFGameControllerSelectButton = @"Select"; const OFGameControllerButton OFGameControllerHomeButton = @"Home"; const OFGameControllerButton OFGameControllerCaptureButton = @"Capture"; const OFGameControllerButton OFGameControllerSLButton = @"SL"; const OFGameControllerButton OFGameControllerSRButton = @"SR"; const OFGameControllerButton OFGameControllerAssistantButton = @"Assistant"; @implementation OFGameController @dynamic name, buttons, pressedButtons, hasLeftAnalogStick; @dynamic leftAnalogStickPosition, hasRightAnalogStick, rightAnalogStickPosition; |
︙ | ︙ |