Comment: | Add HIDGameControllerMapping |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
16aab59c3c36d805c08aa9483dfe2fa3 |
User & Date: | js on 2024-06-02 23:51:01 |
Other Links: | manifest | tags |
2024-06-03
| ||
00:31 | Make GCC happy again check-in: 4bee9b1b32 user: js tags: trunk | |
2024-06-02
| ||
23:51 | Add HIDGameControllerMapping check-in: 16aab59c3c user: js tags: trunk | |
22:17 | Fix missing import and fix typo check-in: 112d9a496f user: js tags: trunk | |
Modified Doxyfile from [a7728bfdca] to [9675d9af4d].
︙ | |||
45 46 47 48 49 50 51 | 45 46 47 48 49 50 51 52 53 | - + | OF_WARN_UNUSED_RESULT= \ OF_WEAK_UNAVAILABLE= \ SIGHUP \ SIGUSR1 \ SIGUSR2 MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES |
Modified src/hid/HIDEvdevGameController.h from [448b671f74] to [40e78502c5].
︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "HIDGameController.h" OF_ASSUME_NONNULL_BEGIN @class HIDGameControllerMapping; @interface HIDEvdevGameController: HIDGameController { OFString *_path; int _fd; bool _discardUntilReport; unsigned long *_evBits, *_keyBits, *_absBits; uint16_t _vendorID, _productID; OFString *_name; |
Modified src/hid/HIDEvdevGameController.m from [d527831ab5] to [3928045f56].
︙ | |||
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 | 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 | + + + - + + + | #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" #import "HIDGameControllerMapping.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 |
︙ | |||
258 259 260 261 262 263 264 | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | - + | if (value > max) value = max; return ((value - min) / (max - min) * 2) - 1; } @implementation HIDEvdevGameController |
︙ | |||
304 305 306 307 308 309 310 311 312 313 314 315 316 317 | 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | + | } - (instancetype)of_initWithPath: (OFString *)path { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding = [OFLocale encoding]; struct input_id inputID; char name[128]; OFMutableDictionary *buttons, *axes; _path = [path copy]; |
︙ | |||
353 354 355 356 357 358 359 | 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 | - + - - + - | if (ioctl(_fd, EVIOCGNAME(sizeof(name)), name) == -1) @throw [OFInitializationFailedException exception]; _name = [[OFString alloc] initWithCString: name encoding: encoding]; |
︙ | |||
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 | 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 443 444 445 446 447 448 449 450 451 | + + + + + + - - + | autorelease]; [axes setObject: axis forKey: axisName]; } } } [axes makeImmutable]; _mapping = [[HIDEvdevGameControllerMapping alloc] of_initWithButtons: buttons axes: axes]; [self of_pollState]; objc_autoreleasePoolPop(pool); } @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]; |
︙ | |||
466 467 468 469 470 471 472 | 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | - + | if (!OFBitSetIsSet(_keyBits, buttonIDs[i])) continue; name = buttonToName(buttonIDs[i]); if (name == nil) continue; |
︙ | |||
488 489 490 491 492 493 494 | 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 528 529 530 531 | - + + | continue; name = axisToName(axisIDs[i]); if (name == nil) continue; axis = (HIDEvdevGameControllerAxis *) |
︙ | |||
548 549 550 551 552 553 554 | 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 | - + - + + + | } break; case EV_KEY: name = buttonToName(event.code); if (name == nil) continue; |
︙ | |||
592 593 594 595 596 597 598 | 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | + + + + + + + + + + + + + + + + + + + + + | return OFOrderedDescending; if (selfIndex < otherIndex) return OFOrderedAscending; return OFOrderedSame; } @end @implementation HIDEvdevGameControllerAxis @end @implementation HIDEvdevGameControllerMapping - (instancetype)of_initWithButtons: (OFDictionary *)buttons axes: (OFDictionary *)axes { self = [super init]; @try { _buttons = [buttons retain]; _axes = [axes retain]; } @catch (id e) { [self release]; @throw e; } return self; } @end |
Modified src/hid/HIDGameController.h from [347fbd7215] to [e37811cd3f].
︙ | |||
27 28 29 30 31 32 33 | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | - + - - + + | # import <ObjFW/OFObject.h> # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN |
︙ | |||
58 59 60 61 62 63 64 | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | - + - - - - + - - - + - | /** * @brief The product ID of the controller or `nil` if unavailable. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *productID; /** |
︙ |
Modified src/hid/HIDGameController.m from [f3d0e406e6] to [1e275c1bfa].
︙ | |||
25 26 27 28 29 30 31 | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | - + | #import "OFSet.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include "HIDEvdevGameController.h" #endif @implementation HIDGameController |
︙ |
Modified src/hid/HIDGameControllerAxis.h from [37943879cb] to [876c2397e0].
︙ | |||
18 19 20 21 22 23 24 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | + + + - + | */ #import "HIDGameControllerElement.h" OF_ASSUME_NONNULL_BEGIN /** * @class HIDGameControllerAxis \ * HIDGameControllerAxis.h ObjFWHID/HIDGameControllerAxis.h * |
︙ |
Modified src/hid/HIDGameControllerButton.h from [e13894eaec] to [e6d7487002].
︙ | |||
18 19 20 21 22 23 24 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | + + + - + | */ #import "HIDGameControllerElement.h" OF_ASSUME_NONNULL_BEGIN /** * @class HIDGameControllerButton \ * HIDGameControllerButton.h ObjFWHID/HIDGameControllerButton.h * |
︙ |
Modified src/hid/HIDGameControllerDirectionalPad.h from [ba9425bef1] to [2c2bbf2751].
︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | + + + + | #import "HIDGameControllerElement.h" #import "HIDGameControllerAxis.h" #import "HIDGameControllerButton.h" OF_ASSUME_NONNULL_BEGIN /** * @class HIDGameControllerDirectionalPad \ * HIDGameControllerDirectionalPad.h \ * ObjFWHID/HIDGameControllerDirectionalPad.h * * @brief An directional pad or thumb stick of a game controller. */ OF_SUBCLASSING_RESTRICTED @interface HIDGameControllerDirectionalPad: HIDGameControllerElement { HIDGameControllerAxis *_xAxis, *_yAxis; HIDGameControllerButton *_upButton, *_downButton; |
︙ |
Modified src/hid/HIDGameControllerElement.h from [7e4d7b44de] to [721f4d8e3b].
︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | + + + | # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN /** * @class HIDGameControllerElement \ * HIDGameControllerElement.h ObjFWHID/HIDGameControllerElement.h * * @brief An element of a game controller, e.g. a button, an axis or a * directional pad. */ @interface HIDGameControllerElement: OFObject { OFString *_name; bool _analog; |
︙ |
Added src/hid/HIDGameControllerMapping.h version [9d245e3712].
|
Added src/hid/HIDGameControllerMapping.m version [5697f19019].
|
Modified src/hid/Makefile from [0ce62570af] to [02731ab3d0].
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | - - - + + + + | 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 \ |
︙ |
Modified src/test/OTAppDelegate.m from [1cc4b85cfa] to [e739358c29].
︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | + | #import "OFThread.h" #import "OFValue.h" #import "OTTestCase.h" #import "HIDGameController.h" #import "HIDGameControllerButton.h" #import "HIDGameControllerMapping.h" #import "OTAssertionFailedException.h" #import "OTTestSkippedException.h" #ifdef OF_IOS # include <CoreFoundation/CoreFoundation.h> #endif |
︙ | |||
283 284 285 286 287 288 289 | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | + - + | [OFStdOut writeLine: @"Press A to continue"]; for (;;) { void *pool = objc_autoreleasePoolPush(); HIDGameController *controller = [[HIDGameController controllers] objectAtIndex: 0]; HIDGameControllerButton *button = [controller.unmappedMapping.buttons |
︙ | |||
547 548 549 550 551 552 553 | 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | - + - + | for (;;) { void *pool = objc_autoreleasePoolPush(); HIDGameController *controller = [[HIDGameController controllers] objectAtIndex: 0]; HIDGameControllerButton *button = # ifdef OF_WII |
︙ |
Modified tests/gamecontroller/GameControllerTests.m from [b2c5ea408f] to [563268e4f8].
︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | + | #import "OFNumber.h" #import "OFStdIOStream.h" #import "OFThread.h" #import "HIDGameController.h" #import "HIDGameControllerAxis.h" #import "HIDGameControllerButton.h" #import "HIDGameControllerMapping.h" #import "OFReadFailedException.h" #if defined(OF_NINTENDO_DS) static size_t buttonsPerLine = 2; #elif defined(OF_NINTENDO_3DS) static size_t buttonsPerLine = 3; |
︙ | |||
78 79 80 81 82 83 84 85 | 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 | + + - + - - + + + - + | [OFStdOut clear]; } [OFStdOut setCursorPosition: OFMakePoint(0, 0)]; for (HIDGameController *controller in _controllers) { HIDGameControllerMapping *mapping = controller.unmappedMapping; OFArray OF_GENERIC(OFString *) *buttons = |
︙ | |||
125 126 127 128 129 130 131 132 133 | 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 | + - + + + + + + + + + | i = 0; } else [OFStdOut writeString: @" "]; } [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeString: @"\n"]; i = 0; for (OFString *name in axes) { HIDGameControllerAxis *axis = |
︙ |