Comment: | Completely redesign and rewrite ObjFWHID
Right now only evdev is supported, support for others will be added back |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
39639cd987e8dc1a7d086ff9a2eaed68 |
User & Date: | js on 2024-06-02 21:24:25 |
Other Links: | manifest | tags |
2024-06-02
| ||
22:17 | Fix missing import and fix typo check-in: 112d9a496f user: js tags: trunk | |
21:24 | Completely redesign and rewrite ObjFWHID check-in: 39639cd987 user: js tags: trunk | |
2024-05-29
| ||
20:14 | Fix forwarding-mips-elf.S check-in: 449265c5ec user: js tags: trunk | |
Renamed and modified src/hid/OFEvdevGameController.h [c297eb99a1] to src/hid/HIDEvdevGameController.h [448b671f74].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | | < | > | < < < < < < < < < < < < < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "HIDGameController.h" OF_ASSUME_NONNULL_BEGIN @interface HIDEvdevGameController: HIDGameController { OFString *_path; int _fd; bool _discardUntilReport; unsigned long *_evBits, *_keyBits, *_absBits; uint16_t _vendorID, _productID; OFString *_name; OFDictionary OF_GENERIC(OFString *, HIDGameControllerButton *) *_buttons; OFDictionary OF_GENERIC(OFString *, HIDGameControllerAxis *) *_axes; } - (instancetype)of_initWithPath: (OFString *)path OF_METHOD_FAMILY(init); - (void)of_pollState; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/OFEvdevGameController.m [bcc812f365] to src/hid/HIDEvdevGameController.m [d527831ab5].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #include "config.h" #include <errno.h> #include <fcntl.h> #include <unistd.h> | | > | > < < < < < < | < < < < < | < < < < | < < > | | < < < | < < | < < | | > > > > > > > > > > > > > > > > > > | | < < | | | | | | | | | > > | | > > | > > | | | < | > | | | | | | | | | | | > > > > > > | | | < > | | | | | | | | | | | > > > > > > | | | | < | > | | | > | | | | < | | > > > > > > | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | > > > | | | | | | | | | | | | | | | | | < < < < < < | < < < < < < | | < < | < < < > > > > > > > > > > > > > > > > > > > > | > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < < | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | #include "config.h" #include <errno.h> #include <fcntl.h> #include <unistd.h> #import "HIDEvdevGameController.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "HIDGameControllerAxis.h" #import "HIDGameControllerButton.h" #include <sys/ioctl.h> #include <linux/input.h> #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" @interface HIDEvdevGameControllerAxis: HIDGameControllerAxis { @public int32_t _minValue, _maxValue; } @end @implementation HIDEvdevGameControllerAxis @end static const uint16_t buttonIDs[] = { 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_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, BTN_TRIGGER_HAPPY5, BTN_TRIGGER_HAPPY6, BTN_TRIGGER_HAPPY7, BTN_TRIGGER_HAPPY8, BTN_TRIGGER_HAPPY9, BTN_TRIGGER_HAPPY10, BTN_TRIGGER_HAPPY11, BTN_TRIGGER_HAPPY12, BTN_TRIGGER_HAPPY13, BTN_TRIGGER_HAPPY14, BTN_TRIGGER_HAPPY15, BTN_TRIGGER_HAPPY16, BTN_TRIGGER_HAPPY17, BTN_TRIGGER_HAPPY18, BTN_TRIGGER_HAPPY19, BTN_TRIGGER_HAPPY20, BTN_TRIGGER_HAPPY21, BTN_TRIGGER_HAPPY22, BTN_TRIGGER_HAPPY23, BTN_TRIGGER_HAPPY24, BTN_TRIGGER_HAPPY25, BTN_TRIGGER_HAPPY26, BTN_TRIGGER_HAPPY27, BTN_TRIGGER_HAPPY28, BTN_TRIGGER_HAPPY29, BTN_TRIGGER_HAPPY30, BTN_TRIGGER_HAPPY31, BTN_TRIGGER_HAPPY32, BTN_TRIGGER_HAPPY33, BTN_TRIGGER_HAPPY34, BTN_TRIGGER_HAPPY35, BTN_TRIGGER_HAPPY36, BTN_TRIGGER_HAPPY37, BTN_TRIGGER_HAPPY38, BTN_TRIGGER_HAPPY39, BTN_TRIGGER_HAPPY40 }; static const uint16_t axisIDs[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ, ABS_THROTTLE, ABS_RUDDER, ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y, ABS_HAT3X, ABS_HAT3Y }; static OFString * buttonToName(uint16_t button) { switch (button) { case BTN_A: return @"A"; case BTN_B: return @"B"; case BTN_C: return @"C"; case BTN_X: return @"X"; case BTN_Y: return @"Y"; case BTN_Z: return @"Z"; case BTN_TL: return @"TL"; case BTN_TR: return @"TR"; case BTN_TL2: return @"TL2"; case BTN_TR2: return @"TR2"; case BTN_SELECT: return @"Select"; case BTN_START: return @"Start"; case BTN_MODE: return @"Mode"; case BTN_THUMBL: return @"Thumb L"; case BTN_THUMBR: return @"Thumb R"; case BTN_DPAD_UP: return @"DPad Up"; case BTN_DPAD_DOWN: return @"DPad Down"; case BTN_DPAD_LEFT: return @"DPad Left"; case BTN_DPAD_RIGHT: return @"DPad Right"; case BTN_TRIGGER_HAPPY1: return @"Trigger Happy 1"; case BTN_TRIGGER_HAPPY2: return @"Trigger Happy 2"; case BTN_TRIGGER_HAPPY3: return @"Trigger Happy 3"; case BTN_TRIGGER_HAPPY4: return @"Trigger Happy 4"; case BTN_TRIGGER_HAPPY5: return @"Trigger Happy 5"; case BTN_TRIGGER_HAPPY6: return @"Trigger Happy 6"; case BTN_TRIGGER_HAPPY7: return @"Trigger Happy 7"; case BTN_TRIGGER_HAPPY8: return @"Trigger Happy 8"; case BTN_TRIGGER_HAPPY9: return @"Trigger Happy 9"; case BTN_TRIGGER_HAPPY10: return @"Trigger Happy 10"; case BTN_TRIGGER_HAPPY11: return @"Trigger Happy 11"; case BTN_TRIGGER_HAPPY12: return @"Trigger Happy 12"; case BTN_TRIGGER_HAPPY13: return @"Trigger Happy 13"; case BTN_TRIGGER_HAPPY14: return @"Trigger Happy 14"; case BTN_TRIGGER_HAPPY15: return @"Trigger Happy 15"; case BTN_TRIGGER_HAPPY16: return @"Trigger Happy 16"; case BTN_TRIGGER_HAPPY17: return @"Trigger Happy 17"; case BTN_TRIGGER_HAPPY18: return @"Trigger Happy 18"; case BTN_TRIGGER_HAPPY19: return @"Trigger Happy 19"; case BTN_TRIGGER_HAPPY20: return @"Trigger Happy 20"; case BTN_TRIGGER_HAPPY21: return @"Trigger Happy 21"; case BTN_TRIGGER_HAPPY22: return @"Trigger Happy 22"; case BTN_TRIGGER_HAPPY23: return @"Trigger Happy 23"; case BTN_TRIGGER_HAPPY24: return @"Trigger Happy 24"; case BTN_TRIGGER_HAPPY25: return @"Trigger Happy 25"; case BTN_TRIGGER_HAPPY26: return @"Trigger Happy 26"; case BTN_TRIGGER_HAPPY27: return @"Trigger Happy 27"; case BTN_TRIGGER_HAPPY28: return @"Trigger Happy 28"; case BTN_TRIGGER_HAPPY29: return @"Trigger Happy 29"; case BTN_TRIGGER_HAPPY30: return @"Trigger Happy 30"; case BTN_TRIGGER_HAPPY31: return @"Trigger Happy 31"; case BTN_TRIGGER_HAPPY32: return @"Trigger Happy 32"; case BTN_TRIGGER_HAPPY33: return @"Trigger Happy 33"; case BTN_TRIGGER_HAPPY34: return @"Trigger Happy 34"; case BTN_TRIGGER_HAPPY35: return @"Trigger Happy 35"; case BTN_TRIGGER_HAPPY36: return @"Trigger Happy 36"; case BTN_TRIGGER_HAPPY37: return @"Trigger Happy 37"; case BTN_TRIGGER_HAPPY38: return @"Trigger Happy 38"; case BTN_TRIGGER_HAPPY39: return @"Trigger Happy 39"; case BTN_TRIGGER_HAPPY40: return @"Trigger Happy 40"; default: return nil; } } static OFString * axisToName(uint16_t axis) { switch (axis) { case ABS_X: return @"X"; case ABS_Y: return @"Y"; case ABS_Z: return @"Z"; case ABS_RX: return @"RX"; case ABS_RY: return @"RY"; case ABS_RZ: return @"RZ"; case ABS_THROTTLE: return @"Throttle"; case ABS_RUDDER: return @"Rudder"; case ABS_WHEEL: return @"Wheel"; case ABS_GAS: return @"Gas"; case ABS_BRAKE: return @"Brake"; case ABS_HAT0X: return @"HAT0X"; case ABS_HAT0Y: return @"HAT0Y"; case ABS_HAT1X: return @"HAT1X"; case ABS_HAT1Y: return @"HAT1Y"; case ABS_HAT2X: return @"HAT2X"; case ABS_HAT2Y: return @"HAT2Y"; case ABS_HAT3X: return @"HAT3X"; case ABS_HAT3Y: return @"HAT3Y"; default: return nil; } } static float scale(float value, float min, float max) { if (value < min) value = min; if (value > max) value = max; return ((value - min) / (max - min) * 2) - 1; } @implementation HIDEvdevGameController @synthesize name = _name, buttons = _buttons, axes = _axes; + (OFArray OF_GENERIC(HIDGameController *) *)controllers { OFMutableArray *controllers = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (OFString *device in [[OFFileManager defaultManager] contentsOfDirectoryAtPath: @"/dev/input"]) { OFString *path; HIDGameController *controller; if (![device hasPrefix: @"event"]) continue; path = [@"/dev/input" stringByAppendingPathComponent: device]; @try { controller = [[[HIDEvdevGameController alloc] of_initWithPath: path] autorelease]; } @catch (OFOpenItemFailedException *e) { if (e.errNo == EACCES) continue; @throw e; } @catch (OFInvalidArgumentException *e) { |
︙ | ︙ | |||
280 281 282 283 284 285 286 | - (instancetype)of_initWithPath: (OFString *)path { self = [super init]; @try { OFStringEncoding encoding = [OFLocale encoding]; | < < < < > > > > | > > | | 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | - (instancetype)of_initWithPath: (OFString *)path { self = [super init]; @try { OFStringEncoding encoding = [OFLocale encoding]; struct input_id inputID; char name[128]; OFMutableDictionary *buttons, *axes; _path = [path copy]; if ((_fd = open([_path cStringWithEncoding: encoding], O_RDONLY | O_NONBLOCK)) == -1) @throw [OFOpenItemFailedException exceptionWithPath: _path mode: @"r" errNo: errno]; _evBits = OFAllocZeroedMemory(OFRoundUpToPowerOf2(OF_ULONG_BIT, EV_MAX) / OF_ULONG_BIT, sizeof(unsigned long)); if (ioctl(_fd, EVIOCGBIT(0, OFRoundUpToPowerOf2( OF_ULONG_BIT, EV_MAX) / OF_ULONG_BIT * sizeof(unsigned long)), _evBits) == -1) @throw [OFInitializationFailedException exception]; if (!OFBitSetIsSet(_evBits, EV_KEY)) @throw [OFInvalidArgumentException exception]; _keyBits = OFAllocZeroedMemory(OFRoundUpToPowerOf2(OF_ULONG_BIT, KEY_MAX) / OF_ULONG_BIT, sizeof(unsigned long)); if (ioctl(_fd, EVIOCGBIT(EV_KEY, OFRoundUpToPowerOf2( OF_ULONG_BIT, KEY_MAX) / OF_ULONG_BIT * |
︙ | ︙ | |||
326 327 328 329 330 331 332 | if (ioctl(_fd, EVIOCGNAME(sizeof(name)), name) == -1) @throw [OFInitializationFailedException exception]; _name = [[OFString alloc] initWithCString: name encoding: encoding]; | > | | | > | | > > > | | | > | | | > > | > > > > | > | | | > | < < | < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < < | < < < | < < < < < < < < < < < < < < < < | < < < | < < | < | | < < < < | | | | < | < < < > > | | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | if (ioctl(_fd, EVIOCGNAME(sizeof(name)), name) == -1) @throw [OFInitializationFailedException exception]; _name = [[OFString alloc] initWithCString: name encoding: encoding]; buttons = [[OFMutableDictionary alloc] init]; _buttons = buttons; for (size_t i = 0; i < sizeof(buttonIDs) / sizeof(*buttonIDs); i++) { if (OFBitSetIsSet(_keyBits, buttonIDs[i])) { OFString *buttonName; HIDGameControllerButton *button; buttonName = buttonToName(buttonIDs[i]); if (buttonName == nil) continue; button = [[[HIDGameControllerButton alloc] initWithName: buttonName] autorelease]; [buttons setObject: button forKey: buttonName]; } } [buttons makeImmutable]; axes = [[OFMutableDictionary alloc] init]; _axes = axes; if (OFBitSetIsSet(_evBits, EV_ABS)) { _absBits = OFAllocZeroedMemory(OFRoundUpToPowerOf2( OF_ULONG_BIT, ABS_MAX) / OF_ULONG_BIT, sizeof(unsigned long)); if (ioctl(_fd, EVIOCGBIT(EV_ABS, OFRoundUpToPowerOf2( OF_ULONG_BIT, ABS_MAX) / OF_ULONG_BIT * sizeof(unsigned long)), _absBits) == -1) @throw [OFInitializationFailedException exception]; for (size_t i = 0; i < sizeof(axisIDs) / sizeof(*axisIDs); i++) { if (OFBitSetIsSet(_absBits, axisIDs[i])) { OFString *axisName; HIDEvdevGameControllerAxis *axis; axisName = axisToName(axisIDs[i]); if (axisName == nil) continue; axis = [[[HIDEvdevGameControllerAxis alloc] initWithName: axisName] autorelease]; [axes setObject: axis forKey: axisName]; } } } [axes makeImmutable]; [self of_pollState]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_path release]; if (_fd != -1) close(_fd); OFFreeMemory(_evBits); OFFreeMemory(_keyBits); OFFreeMemory(_absBits); [_name release]; [_buttons release]; [_axes release]; [super dealloc]; } - (OFNumber *)vendorID { return [OFNumber numberWithUnsignedShort: _vendorID]; |
︙ | ︙ | |||
475 476 477 478 479 480 481 | if (ioctl(_fd, EVIOCGKEY(sizeof(keyState)), &keyState) == -1) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(keyState) errNo: errno]; | < < | < < < < | | < | < | < < | < < < < < < < < < < | | < | < < < < | < < | | | | < < | < < < < < < < < < < | < < < < < < < < < | < < > | > > < < > | < < > | < < < < | < < < < < < < < | | > | | | < | | | | | | | < < | < < | < < < < < < < < < < < > | > | 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 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 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | if (ioctl(_fd, EVIOCGKEY(sizeof(keyState)), &keyState) == -1) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(keyState) errNo: errno]; for (size_t i = 0; i < sizeof(buttonIDs) / sizeof(*buttonIDs); i++) { OFString *name; HIDGameControllerButton *button; if (!OFBitSetIsSet(_keyBits, buttonIDs[i])) continue; name = buttonToName(buttonIDs[i]); if (name == nil) continue; button = [_buttons objectForKey: name]; if (button == nil) continue; button.value = (OFBitSetIsSet(keyState, buttonIDs[i]) ? 1 : 0); } if (OFBitSetIsSet(_evBits, EV_ABS)) { for (size_t i = 0; i < sizeof(axisIDs) / sizeof(*axisIDs); i++) { struct input_absinfo info; OFString *name; HIDEvdevGameControllerAxis *axis; if (!OFBitSetIsSet(_absBits, axisIDs[i])) continue; name = axisToName(axisIDs[i]); if (name == nil) continue; axis = (HIDEvdevGameControllerAxis *) [_axes objectForKey: name]; if (axis == nil) continue; if (ioctl(_fd, EVIOCGABS(axisIDs[i]), &info) == -1) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(info) errNo: errno]; axis->_minValue = info.minimum; axis->_maxValue = info.maximum; axis.value = scale(info.value, info.minimum, info.maximum); } } } - (void)retrieveState { struct input_event event; for (;;) { OFString *name; HIDGameControllerButton *button; HIDEvdevGameControllerAxis *axis; errno = 0; if (read(_fd, &event, sizeof(event)) < (int)sizeof(event)) { if (errno == EWOULDBLOCK) return; |
︙ | ︙ | |||
639 640 641 642 643 644 645 | case EV_SYN: if (event.value == SYN_DROPPED) { _discardUntilReport = true; continue; } break; case EV_KEY: | | | | | | | > < | < | < < < < < < < < < < < < < < | | < | | < < < < < < < < < < < < < < < | | < | < | < < < < < < < | < | < < | < < < < < < < < < < < < < < < < < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | case EV_SYN: if (event.value == SYN_DROPPED) { _discardUntilReport = true; continue; } break; case EV_KEY: name = buttonToName(event.code); if (name == nil) continue; button = [_buttons objectForKey: name]; if (button == nil) continue; button.value = (event.value ? 1 : 0); break; case EV_ABS: name = axisToName(event.code); if (name == nil) continue; axis = (HIDEvdevGameControllerAxis *) [_axes objectForKey: name]; if (axis == nil) continue; axis.value = scale(event.value, axis->_minValue, axis->_maxValue); break; } } } - (OFComparisonResult)compare: (HIDEvdevGameController *)otherController { unsigned long long selfIndex, otherIndex; if (![otherController isKindOfClass: [HIDEvdevGameController class]]) @throw [OFInvalidArgumentException exception]; selfIndex = [_path substringFromIndex: 16].unsignedLongLongValue; otherIndex = [otherController->_path substringFromIndex: 16] .unsignedLongLongValue; if (selfIndex > otherIndex) return OFOrderedDescending; if (selfIndex < otherIndex) return OFOrderedAscending; return OFOrderedSame; } @end |
Renamed and modified src/hid/OFGameController.h [3ca0d701fd] to src/hid/HIDGameController.h [347fbd7215].
︙ | ︙ | |||
27 28 29 30 31 32 33 | # import <ObjFW/OFObject.h> # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < < | < < < | < | < < < < < < < < < | < < < < < < < < | | < < | < < < < < < < | | | < < < < < < < < < < | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | # import <ObjFW/OFObject.h> # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN @class HIDGameControllerAxis; @class HIDGameControllerButton; @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFNumber; /** * @brief A class for reading state from a game controller. */ @interface HIDGameController: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFArray <HIDGameController *> *controllers; #endif /** * @brief The name of the controller. */ @property (readonly, nonatomic, copy) OFString *name; /** * @brief The vendor ID of the controller or `nil` if unavailable. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *vendorID; /** * @brief The product ID of the controller or `nil` if unavailable. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *productID; /** * @brief A map of all button names to their @ref HIDGameControllerButton. */ @property (readonly, nonatomic) OFDictionary OF_GENERIC(OFString *, HIDGameControllerButton *) *buttons; /** * @brief A map of all axis names to their @ref HIDGameControllerAxis. */ @property (readonly, nonatomic) OFDictionary OF_GENERIC(OFString *, HIDGameControllerAxis *) *axes; /** * @brief Returns the available controllers. * * @return The available controllers */ + (OFArray OF_GENERIC(HIDGameController *) *)controllers; /** * @brief Retrieves the current state from the game controller. * * The state returned by @ref HIDGameController's methods does not change until * this method is called. * * @throw OFReadFailedException The controller's state could not be read */ - (void)retrieveState; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/OFGameController.m [49ccebbc34] to src/hid/HIDGameController.m [f3d0e406e6].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < | | < < < < < < < < | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "HIDGameController.h" #import "OFArray.h" #import "OFNumber.h" #import "OFSet.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include "HIDEvdevGameController.h" #endif @implementation HIDGameController @dynamic name, buttons, axes; + (OFArray OF_GENERIC(HIDGameController *) *)controllers { #if defined(OF_LINUX) && defined(OF_HAVE_FILES) return [HIDEvdevGameController controllers]; #else return [OFArray array]; #endif } - (instancetype)init { if ([self isMemberOfClass: [HIDGameController class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
111 112 113 114 115 116 117 | } - (void)retrieveState { OF_UNRECOGNIZED_SELECTOR } | < < < < < | < < < < < < < < < < < < | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | } - (void)retrieveState { OF_UNRECOGNIZED_SELECTOR } - (OFString *)description { if (self.vendorID != nil && self.productID != nil) return [OFString stringWithFormat: @"<%@: %@ [%04X:%04X]>", self.class, self.name, self.vendorID.unsignedShortValue, self.productID.unsignedShortValue]; else return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include "HIDEvdevGameController.m" #endif |
Added src/hid/HIDGameControllerAxis.h version [37943879cb].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "HIDGameControllerElement.h" OF_ASSUME_NONNULL_BEGIN /** * @brief An button of a game controller. */ @interface HIDGameControllerAxis: HIDGameControllerElement { float _value; OF_RESERVE_IVARS(HIDGameControllerButton, 4) } /** * @brief The value of the axis. */ @property (nonatomic) float value; @end OF_ASSUME_NONNULL_END |
Added src/hid/HIDGameControllerAxis.m version [9b1e5938fe].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "HIDGameControllerAxis.h" @implementation HIDGameControllerAxis @synthesize value = _value; - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Added src/hid/HIDGameControllerButton.h version [e13894eaec].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "HIDGameControllerElement.h" OF_ASSUME_NONNULL_BEGIN /** * @brief An button of a game controller. */ @interface HIDGameControllerButton: HIDGameControllerElement { float _value; OF_RESERVE_IVARS(HIDGameControllerButton, 4) } /** * @brief Whether the game controller button is pressed. */ @property (readonly, nonatomic, getter=isPressed) bool pressed; /** * @brief The pressure with which the button is pressed. */ @property (nonatomic) float value; @end OF_ASSUME_NONNULL_END |
Added src/hid/HIDGameControllerButton.m version [64b22e0918].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "HIDGameControllerButton.h" @implementation HIDGameControllerButton @synthesize value = _value; - (bool)isPressed { return (_value > 0); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Added src/hid/HIDGameControllerDirectionalPad.h version [ba9425bef1].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "HIDGameControllerElement.h" #import "HIDGameControllerAxis.h" #import "HIDGameControllerButton.h" OF_ASSUME_NONNULL_BEGIN /** * @brief An directional pad or thumb stick of a game controller. */ OF_SUBCLASSING_RESTRICTED @interface HIDGameControllerDirectionalPad: HIDGameControllerElement { HIDGameControllerAxis *_xAxis, *_yAxis; HIDGameControllerButton *_upButton, *_downButton; HIDGameControllerButton *_leftButton, *_rightButton; } /** * @brief The X axis of the directional pad. */ @property (readonly, nonatomic) HIDGameControllerAxis *xAxis; /** * @brief The Y axis of the directional pad. */ @property (readonly, nonatomic) HIDGameControllerAxis *yAxis; /** * @brief The up button of the directional pad. */ @property (readonly, nonatomic) HIDGameControllerButton *upButton; /** * @brief The down button of the directional pad. */ @property (readonly, nonatomic) HIDGameControllerButton *downButton; /** * @brief The left button of the directional pad. */ @property (readonly, nonatomic) HIDGameControllerButton *leftButton; /** * @brief The right button of the directional pad. */ @property (readonly, nonatomic) HIDGameControllerButton *rightButton; - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName: (OFString *)name xAxis: (HIDGameControllerAxis *)xAxis yAxis: (HIDGameControllerAxis *)yAxis; - (instancetype)initWithName: (OFString *)name upButton: (HIDGameControllerButton *)upButton downButton: (HIDGameControllerButton *)downButton leftButton: (HIDGameControllerButton *)leftButton rightButton: (HIDGameControllerButton *)rightButton; @end OF_ASSUME_NONNULL_END |
Added src/hid/HIDGameControllerDirectionalPad.m version [6db9de440f].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "HIDGameControllerDirectionalPad.h" #import "HIDGameControllerEmulatedAxis.h" #import "HIDGameControllerEmulatedButton.h" @implementation HIDGameControllerDirectionalPad @synthesize xAxis = _xAxis, yAxis = _yAxis; @synthesize upButton = _upButton, downButton = _downButton; @synthesize leftButton = _leftButton, rightButton = _rightButton; - (instancetype)initWithName: (OFString *)name { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name xAxis: (HIDGameControllerAxis *)xAxis yAxis: (HIDGameControllerAxis *)yAxis { self = [super initWithName: name]; @try { _xAxis = [xAxis retain]; _yAxis = [yAxis retain]; _upButton = [[HIDGameControllerEmulatedButton alloc] initWithAxis: _yAxis positive: false]; _downButton = [[HIDGameControllerEmulatedButton alloc] initWithAxis: _yAxis positive: true]; _leftButton = [[HIDGameControllerEmulatedButton alloc] initWithAxis: _xAxis positive: false]; _rightButton = [[HIDGameControllerEmulatedButton alloc] initWithAxis: _xAxis positive: true]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithName: (OFString *)name upButton: (HIDGameControllerButton *)upButton downButton: (HIDGameControllerButton *)downButton leftButton: (HIDGameControllerButton *)leftButton rightButton: (HIDGameControllerButton *)rightButton { self = [super initWithName: name]; @try { _upButton = [upButton retain]; _downButton = [downButton retain]; _leftButton = [leftButton retain]; _rightButton = [rightButton retain]; _xAxis = [[HIDGameControllerEmulatedAxis alloc] initWithNegativeButton: _leftButton positiveButton: _rightButton]; _yAxis = [[HIDGameControllerEmulatedAxis alloc] initWithNegativeButton: _upButton positiveButton: _downButton]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_xAxis release]; [_yAxis release]; [_upButton release]; [_downButton release]; [_leftButton release]; [_rightButton release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Added src/hid/HIDGameControllerElement.h version [7e4d7b44de].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #ifdef OBJFWHID_LOCAL_INCLUDES # import "OFObject.h" # import "OFString.h" #else # if defined(__has_feature) && __has_feature(modules) @import ObjFW; # else # import <ObjFW/OFObject.h> # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN /** * @brief An element of a game controller, e.g. a button, an axis or a * directional pad. */ @interface HIDGameControllerElement: OFObject { OFString *_name; bool _analog; OF_RESERVE_IVARS(HIDGameControllerElement, 4) } /** * @brief The name of the game controller element. */ @property (readonly, nonatomic) OFString *name; /** * @brief Whether the game controller element is analog. */ @property (readonly, nonatomic, getter=isAnalog) bool analog; - (instancetype)init OF_UNAVAILABLE; - (instancetype)initWithName: (OFString *)name OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Added src/hid/HIDGameControllerElement.m version [35eace7e5e].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "HIDGameControllerElement.h" @implementation HIDGameControllerElement @synthesize name = _name, analog = _analog; - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name { self = [super init]; @try { _name = [name copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_name release]; [super dealloc]; } @end |
Added src/hid/HIDGameControllerEmulatedAxis.h version [f06104d6f6].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "HIDGameControllerAxis.h" OF_ASSUME_NONNULL_BEGIN @class HIDGameControllerButton; OF_SUBCLASSING_RESTRICTED @interface HIDGameControllerEmulatedAxis: HIDGameControllerAxis { HIDGameControllerButton *_negativeButton, *_positiveButton; } - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; - (instancetype) initWithNegativeButton: (HIDGameControllerButton *)negativeButton positiveButton: (HIDGameControllerButton *)positiveButton; @end OF_ASSUME_NONNULL_END |
Added src/hid/HIDGameControllerEmulatedAxis.m version [01c06a1ab0].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "config.h" #import "HIDGameControllerEmulatedAxis.h" #import "HIDGameControllerButton.h" @implementation HIDGameControllerEmulatedAxis - (instancetype)initWithName: (OFString *)name { OF_INVALID_INIT_METHOD } - (instancetype) initWithNegativeButton: (HIDGameControllerButton *)negativeButton positiveButton: (HIDGameControllerButton *)positiveButton { void *pool = objc_autoreleasePoolPush(); OFString *name;; @try { name = [OFString stringWithFormat: @"%@ and %@ as emulated axis", negativeButton.name, positiveButton.name]; } @catch (id e) { [self release]; @throw e; } self = [super initWithName: name]; objc_autoreleasePoolPop(pool); _negativeButton = [negativeButton retain]; _positiveButton = [positiveButton retain]; return self; } - (void)dealloc { [_negativeButton release]; [_positiveButton release]; [super dealloc]; } - (void)setValue: (float)value { OF_UNRECOGNIZED_SELECTOR } - (float)value { if (_negativeButton.pressed && _positiveButton.pressed) return -0; if (_negativeButton.pressed) return -1; if (_positiveButton.pressed) return 1; return 0; } @end |
Added src/hid/HIDGameControllerEmulatedButton.h version [3f0e6ab4ac].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "HIDGameControllerButton.h" OF_ASSUME_NONNULL_BEGIN @class HIDGameControllerAxis; OF_SUBCLASSING_RESTRICTED @interface HIDGameControllerEmulatedButton: HIDGameControllerButton { HIDGameControllerAxis *_axis; bool _positive; } - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; - (instancetype)initWithAxis: (HIDGameControllerAxis *)axis positive: (bool)positive; @end OF_ASSUME_NONNULL_END |
Added src/hid/HIDGameControllerEmulatedButton.m version [fb0b1a22a4].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "HIDGameControllerEmulatedButton.h" #import "HIDGameControllerAxis.h" @implementation HIDGameControllerEmulatedButton: HIDGameControllerButton - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE { OF_INVALID_INIT_METHOD } - (instancetype)initWithAxis: (HIDGameControllerAxis *)axis positive: (bool)positive { void *pool = objc_autoreleasePoolPush(); OFString *name; @try { name = [OFString stringWithFormat: @"%@ %@ as emulated button", (positive ? @"Positive" : @"Negative"), axis.name]; } @catch (id e) { [self release]; @throw e; } self = [super initWithName: name]; objc_autoreleasePoolPop(pool); _axis = [axis retain]; _positive = positive; return self; } - (void)dealloc { [_axis release]; [super dealloc]; } - (bool)isPressed { if (_positive) return (_axis.value > 0); else return (_axis.value < 0); } @end |
Modified src/hid/Makefile from [8756119022] to [0ce62570af].
1 2 3 4 5 6 7 8 9 10 11 | include ../../extra.mk DISTCLEAN = Info.plist SHARED_LIB = ${OBJFWHID_SHARED_LIB} STATIC_LIB = ${OBJFWHID_STATIC_LIB} FRAMEWORK = ${OBJFWHID_FRAMEWORK} LIB_MAJOR = ${OBJFWHID_LIB_MAJOR} LIB_MINOR = ${OBJFWHID_LIB_MINOR} LIB_PATCH = ${OBJFWHID_LIB_PATCH} | | > > > | > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | include ../../extra.mk DISTCLEAN = Info.plist SHARED_LIB = ${OBJFWHID_SHARED_LIB} STATIC_LIB = ${OBJFWHID_STATIC_LIB} FRAMEWORK = ${OBJFWHID_FRAMEWORK} LIB_MAJOR = ${OBJFWHID_LIB_MAJOR} LIB_MINOR = ${OBJFWHID_LIB_MINOR} LIB_PATCH = ${OBJFWHID_LIB_PATCH} SRCS = HIDGameController.m \ HIDGameControllerAxis.m \ HIDGameControllerButton.m \ HIDGameControllerDirectionalPad.m \ HIDGameControllerElement.m INCLUDES := ${SRCS:.m=.h} \ ObjFWHID.h SRCS += HIDGameControllerEmulatedAxis.m \ HIDGameControllerEmulatedButton.m includesubdir = ObjFWHID include ../../buildsys.mk install-extra: i=ObjFWHID.oc; \ |
︙ | ︙ |
Deleted src/hid/OFCombinedJoyConsGameController.h version [56e6c1cdbc].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFCombinedJoyConsGameController.m version [44f0093bf7].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFNintendo3DSGameController.h version [600e88c786].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFNintendo3DSGameController.m version [5d5a974908].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFNintendoDSGameController.h version [a3f594eb12].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFNintendoDSGameController.m version [76ee0663ed].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFWiiGameController.h version [967feef34b].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFWiiGameController.m version [c3b51e1e66].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFXInputGameController.h version [393b179dcd].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OFXInputGameController.m version [965b558ea8].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/hid/ObjFWHID.h from [e3220aba7e] to [d1a844bf10].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | > > > | 13 14 15 16 17 18 19 20 21 22 23 24 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "HIDGameController.h" #import "HIDGameControllerElement.h" #import "HIDGameControllerButton.h" #import "HIDGameControllerAxis.h" #import "HIDGameControllerDirectionalPad.h" |
Modified src/test/OTAppDelegate.m from [747d91c177] to [6e4666d486].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #import "OFSet.h" #import "OFStdIOStream.h" #import "OFThread.h" #import "OFValue.h" #import "OTTestCase.h" | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #import "OFSet.h" #import "OFStdIOStream.h" #import "OFThread.h" #import "OFValue.h" #import "OTTestCase.h" #import "HIDGameController.h" #import "OTAssertionFailedException.h" #import "OTTestSkippedException.h" #ifdef OF_IOS # include <CoreFoundation/CoreFoundation.h> #endif |
︙ | ︙ | |||
279 280 281 282 283 284 285 | if (status == StatusFailed) { #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { void *pool = objc_autoreleasePoolPush(); | | | > > | < | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | if (status == StatusFailed) { #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { void *pool = objc_autoreleasePoolPush(); HIDGameController *controller = [[HIDGameController controllers] objectAtIndex: 0]; HIDGameControllerButton *button = [controller.buttons objectForKey: @"A"]; [controller retrieveState]; if (button.pressed) break; [OFThread waitForVerticalBlank]; objc_autoreleasePoolPop(pool); } #elif defined(OF_NINTENDO_SWITCH) |
︙ | ︙ | |||
541 542 543 544 545 546 547 | [OFStdOut writeLine: @"Press Home button to exit"]; # else [OFStdOut writeLine: @"Press Start button to exit"]; # endif for (;;) { void *pool = objc_autoreleasePoolPush(); | | | > > > > > > < | < < < < < | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | [OFStdOut writeLine: @"Press Home button to exit"]; # else [OFStdOut writeLine: @"Press Start button to exit"]; # endif for (;;) { void *pool = objc_autoreleasePoolPush(); HIDGameController *controller = [[HIDGameController controllers] objectAtIndex: 0]; HIDGameControlelrButton *button = # ifdef OF_WII [controller.buttons objectForKey: @"Home"]; # else [controller.buttons objectForKey: @"Start"]; # endif [controller retrieveState]; if (button.pressed) break; [OFThread waitForVerticalBlank]; objc_autoreleasePoolPop(pool); } #elif defined(OF_NINTENDO_SWITCH) |
︙ | ︙ |
Modified tests/gamecontroller/GameControllerTests.m from [1bbc654209] to [b2c5ea408f].
︙ | ︙ | |||
18 19 20 21 22 23 24 | */ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFColor.h" | < < | | > > > > | < < | < < < < < < < < < < < < < < < < < < < < | | | > > > | < > < < < | | | | > > | | < | | < < < < < | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | */ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFColor.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFStdIOStream.h" #import "OFThread.h" #import "HIDGameController.h" #import "HIDGameControllerAxis.h" #import "HIDGameControllerButton.h" #import "OFReadFailedException.h" #if defined(OF_NINTENDO_DS) static size_t buttonsPerLine = 2; #elif defined(OF_NINTENDO_3DS) static size_t buttonsPerLine = 3; #else static size_t buttonsPerLine = 5; #endif #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) # define red maroon # define yellow olive # define gray silver #endif @interface GameControllerTests: OFObject <OFApplicationDelegate> { OFMutableArray OF_GENERIC(HIDGameController *) *_controllers; OFDate *_lastControllersUpdate; } @end OF_APPLICATION_DELEGATE(GameControllerTests) @implementation GameControllerTests - (void)applicationDidFinishLaunching: (OFNotification *)notification { #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) [OFStdIOStream setUpConsole]; #endif for (;;) { void *pool = objc_autoreleasePoolPush(); if (_lastControllersUpdate == nil || -[_lastControllersUpdate timeIntervalSinceNow] > 1) { [_controllers release]; [_lastControllersUpdate release]; _controllers = [[HIDGameController controllers] mutableCopy]; _lastControllersUpdate = [[OFDate alloc] init]; [OFStdOut clear]; } [OFStdOut setCursorPosition: OFMakePoint(0, 0)]; for (HIDGameController *controller in _controllers) { OFArray OF_GENERIC(OFString *) *buttons = controller.buttons.allKeys.sortedArray; OFArray OF_GENERIC(OFString *) *axes = controller.axes.allKeys.sortedArray; size_t i = 0; [OFStdOut setForegroundColor: [OFColor green]]; [OFStdOut writeString: controller.description]; @try { [controller retrieveState]; } @catch (OFReadFailedException *e) { [OFStdOut setForegroundColor: [OFColor red]]; [OFStdOut writeFormat: @"\n%@", e.description]; continue; } for (OFString *name in buttons) { HIDGameControllerButton *button = [controller.buttons objectForKey: name]; if (i == 0) [OFStdOut writeString: @"\n"]; if (button.value == 1) [OFStdOut setForegroundColor: [OFColor red]]; else if (button.value > 0.5) [OFStdOut setForegroundColor: [OFColor yellow]]; else if (button.value > 0) [OFStdOut setForegroundColor: [OFColor green]]; else [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeFormat: @"[%@]", button.name]; if (++i == buttonsPerLine) { i = 0; } else [OFStdOut writeString: @" "]; } [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeString: @"\n"]; for (OFString *name in axes) { HIDGameControllerAxis *axis = [controller.axes objectForKey: name]; [OFStdOut writeFormat: @"%@: %5.2f ", name, axis.value]; } [OFStdOut writeString: @"\n"]; } #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) [OFThread waitForVerticalBlank]; #else [OFThread sleepForTimeInterval: 1.f / 60.f]; #endif objc_autoreleasePoolPop(pool); } } @end |