Differences From Artifact [d527831ab5]:
- File
src/hid/HIDEvdevGameController.m
— part of check-in
[39639cd987]
at
2024-06-02 21:24:25
on branch trunk
— Completely redesign and rewrite ObjFWHID
Right now only evdev is supported, support for others will be added back
later. (user: js, size: 14502) [annotate] [blame] [check-ins using]
To Artifact [3928045f56]:
- File src/hid/HIDEvdevGameController.m — part of check-in [16aab59c3c] at 2024-06-02 23:51:01 on branch trunk — Add HIDGameControllerMapping (user: js, size: 15264) [annotate] [blame] [check-ins using]
︙ | |||
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 |