ObjFW  Check-in [afae3291bf]

Overview
Comment:ObjFWHID: Change prefix to OH

Let's leave 3 letter prefixes to 3rd parties.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: afae3291bff5cad99191b902e6e4e81c711893566fe204467ee1a059a0e84377
User & Date: js on 2024-06-03 19:39:51
Other Links: manifest | tags
Context
2024-06-03
19:45
Rename OHGameController{Mapping -> Profile} check-in: f333689336 user: js tags: trunk
19:39
ObjFWHID: Change prefix to OH check-in: afae3291bf user: js tags: trunk
00:31
Make GCC happy again check-in: 4bee9b1b32 user: js tags: trunk
Changes

Modified Doxyfile from [9675d9af4d] to [92b4e406bf].

45
46
47
48
49
50
51
52

53
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
IGNORE_PREFIX = HID OF OF_ OT OT_
IGNORE_PREFIX = OF OF_ OH OT OT_
EXTRACT_STATIC = yes

Modified src/hid/Makefile from [02731ab3d0] to [044fff7e3a].

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
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











-
-
-
-
-
-
+
+
+
+
+
+




-
-
+
+







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		\
       HIDGameControllerMapping.m
SRCS = OHGameController.m		\
       OHGameControllerAxis.m		\
       OHGameControllerButton.m		\
       OHGameControllerDirectionalPad.m	\
       OHGameControllerElement.m	\
       OHGameControllerMapping.m

INCLUDES := ${SRCS:.m=.h}	\
	    ObjFWHID.h

SRCS += HIDGameControllerEmulatedAxis.m		\
	HIDGameControllerEmulatedButton.m
SRCS += OHGameControllerEmulatedAxis.m		\
	OHGameControllerEmulatedButton.m

includesubdir = ObjFWHID

include ../../buildsys.mk

install-extra:
	i=ObjFWHID.oc; \

Renamed and modified src/hid/HIDEvdevGameController.h [40e78502c5] to src/hid/OHEvdevGameController.h [80bc5a0e55].

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
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"
#import "OHGameController.h"

OF_ASSUME_NONNULL_BEGIN

@class HIDGameControllerMapping;
@class OHGameControllerMapping;

@interface HIDEvdevGameController: HIDGameController
@interface OHEvdevGameController: OHGameController
{
	OFString *_path;
	int _fd;
	bool _discardUntilReport;
	unsigned long *_evBits, *_keyBits, *_absBits;
	uint16_t _vendorID, _productID;
	OFString *_name;
	HIDGameControllerMapping *_mapping;
	OHGameControllerMapping *_mapping;
}

- (instancetype)of_initWithPath: (OFString *)path OF_METHOD_FAMILY(init);
- (void)of_pollState;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/HIDEvdevGameController.m [3e3a114e9f] to src/hid/OHEvdevGameController.m [a90f4bebdd].

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
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







-
+







-
-
-
+
+
+










-
+






-
+








#include "config.h"

#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

#import "HIDEvdevGameController.h"
#import "OHEvdevGameController.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"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerMapping.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
@interface OHEvdevGameControllerAxis: OHGameControllerAxis
{
@public
	int32_t _minValue, _maxValue;
}
@end

@interface HIDEvdevGameControllerMapping: HIDGameControllerMapping
@interface OHEvdevGameControllerMapping: OHGameControllerMapping
- (instancetype)of_initWithButtons: (OFDictionary *)buttons
			      axes: (OFDictionary *)axes OF_METHOD_FAMILY(init);
@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,
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
291
292
293
294
295
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
291
292
293
294
295







-
+


-
+







-
+







-
+







		value = min;
	if (value > max)
		value = max;

	return ((value - min) / (max - min) * 2) - 1;
}

@implementation HIDEvdevGameController
@implementation OHEvdevGameController
@synthesize name = _name, unmappedMapping = _mapping;

+ (OFArray OF_GENERIC(HIDGameController *) *)controllers
+ (OFArray OF_GENERIC(OHGameController *) *)controllers
{
	OFMutableArray *controllers = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();

	for (OFString *device in [[OFFileManager defaultManager]
	    contentsOfDirectoryAtPath: @"/dev/input"]) {
		OFString *path;
		HIDGameController *controller;
		OHGameController *controller;

		if (![device hasPrefix: @"event"])
			continue;

		path = [@"/dev/input" stringByAppendingPathComponent: device];

		@try {
			controller = [[[HIDEvdevGameController alloc]
			controller = [[[OHEvdevGameController alloc]
			    of_initWithPath: path] autorelease];
		} @catch (OFOpenItemFailedException *e) {
			if (e.errNo == EACCES)
				continue;

			@throw e;
		} @catch (OFInvalidArgumentException *e) {
364
365
366
367
368
369
370
371

372
373
374
375
376
377

378
379
380
381
382
383
384
364
365
366
367
368
369
370

371
372
373
374
375
376

377
378
379
380
381
382
383
384







-
+





-
+







						 encoding: encoding];

		buttons = [OFMutableDictionary dictionary];
		for (size_t i = 0; i < sizeof(buttonIDs) / sizeof(*buttonIDs);
		    i++) {
			if (OFBitSetIsSet(_keyBits, buttonIDs[i])) {
				OFString *buttonName;
				HIDGameControllerButton *button;
				OHGameControllerButton *button;

				buttonName = buttonToName(buttonIDs[i]);
				if (buttonName == nil)
					continue;

				button = [[[HIDGameControllerButton alloc]
				button = [[[OHGameControllerButton alloc]
				    initWithName: buttonName] autorelease];

				[buttons setObject: button forKey: buttonName];
			}
		}
		[buttons makeImmutable];

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
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







-
+





-
+









-
+







				@throw [OFInitializationFailedException
				    exception];

			for (size_t i = 0;
			    i < sizeof(axisIDs) / sizeof(*axisIDs); i++) {
				if (OFBitSetIsSet(_absBits, axisIDs[i])) {
					OFString *axisName;
					HIDEvdevGameControllerAxis *axis;
					OHEvdevGameControllerAxis *axis;

					axisName = axisToName(axisIDs[i]);
					if (axisName == nil)
						continue;

					axis = [[[HIDEvdevGameControllerAxis
					axis = [[[OHEvdevGameControllerAxis
					    alloc] initWithName: axisName]
					    autorelease];

					[axes setObject: axis forKey: axisName];
				}
			}
		}
		[axes makeImmutable];

		_mapping = [[HIDEvdevGameControllerMapping alloc]
		_mapping = [[OHEvdevGameControllerMapping alloc]
		    of_initWithButtons: buttons
				  axes: axes];

		[self of_pollState];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
466
467
468
469
470
471
472
473

474
475
476
477
478
479
480
466
467
468
469
470
471
472

473
474
475
476
477
478
479
480







-
+







		    exceptionWithObject: self
			requestedLength: sizeof(keyState)
				  errNo: errno];

	for (size_t i = 0; i < sizeof(buttonIDs) / sizeof(*buttonIDs);
	    i++) {
		OFString *name;
		HIDGameControllerButton *button;
		OHGameControllerButton *button;

		if (!OFBitSetIsSet(_keyBits, buttonIDs[i]))
			continue;

		name = buttonToName(buttonIDs[i]);
		if (name == nil)
			continue;
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
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 (OFBitSetIsSet(_evBits, EV_ABS)) {
		for (size_t i = 0; i < sizeof(axisIDs) / sizeof(*axisIDs);
		    i++) {
			struct input_absinfo info;
			OFString *name;
			HIDEvdevGameControllerAxis *axis;
			OHEvdevGameControllerAxis *axis;

			if (!OFBitSetIsSet(_absBits, axisIDs[i]))
				continue;

			name = axisToName(axisIDs[i]);
			if (name == nil)
				continue;

			axis = (HIDEvdevGameControllerAxis *)
			axis = (OHEvdevGameControllerAxis *)
			    [_mapping.axes objectForKey: name];
			if (axis == nil)
				continue;

			if (ioctl(_fd, EVIOCGABS(axisIDs[i]), &info) == -1)
				@throw [OFReadFailedException
				    exceptionWithObject: self
525
526
527
528
529
530
531
532
533


534
535
536
537
538
539
540
525
526
527
528
529
530
531


532
533
534
535
536
537
538
539
540







-
-
+
+







- (void)retrieveState
{
	void *pool = objc_autoreleasePoolPush();
	struct input_event event;

	for (;;) {
		OFString *name;
		HIDGameControllerButton *button;
		HIDEvdevGameControllerAxis *axis;
		OHGameControllerButton *button;
		OHEvdevGameControllerAxis *axis;

		errno = 0;

		if (read(_fd, &event, sizeof(event)) < (int)sizeof(event)) {
			if (errno == EWOULDBLOCK)
				return;

576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591
592
593
594
595
596
597
598

599
600
601
602

603
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
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597

598
599
600
601

602
603
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







-
+














-
+



-
+















-
+


-
+








			break;
		case EV_ABS:
			name = axisToName(event.code);
			if (name == nil)
				continue;

			axis = (HIDEvdevGameControllerAxis *)
			axis = (OHEvdevGameControllerAxis *)
			    [_mapping.axes objectForKey: name];
			if (axis == nil)
				continue;

			axis.value = scale(event.value,
			   axis->_minValue, axis->_maxValue);

			break;
		}
	}

	objc_autoreleasePoolPop(pool);
}

- (OFComparisonResult)compare: (HIDEvdevGameController *)otherController
- (OFComparisonResult)compare: (OHEvdevGameController *)otherController
{
	unsigned long long selfIndex, otherIndex;

	if (![otherController isKindOfClass: [HIDEvdevGameController class]])
	if (![otherController isKindOfClass: [OHEvdevGameController 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

@implementation HIDEvdevGameControllerAxis
@implementation OHEvdevGameControllerAxis
@end

@implementation HIDEvdevGameControllerMapping
@implementation OHEvdevGameControllerMapping
- (instancetype)of_initWithButtons: (OFDictionary *)buttons
			      axes: (OFDictionary *)axes
{
	self = [super init];

	@try {
		_buttons = [buttons retain];

Renamed and modified src/hid/HIDGameController.h [e37811cd3f] to src/hid/OHGameController.h [5ae1f17798].

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
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







-


+


-
+



-
+


-
+







#  import <ObjFW/OFObject.h>
#  import <ObjFW/OFString.h>
# endif
#endif

OF_ASSUME_NONNULL_BEGIN

@class HIDGameControllerMapping;
@class OFArray OF_GENERIC(ObjectType);
@class OFNumber;
@class OHGameControllerMapping;

/**
 * @class HIDGameController HIDGameController.h ObjFWHID/HIDGameController.h
 * @class OHGameController OHGameController.h ObjFWHID/OHGameController.h
 *
 * @brief A class for reading state from a game controller.
 */
@interface HIDGameController: OFObject
@interface OHGameController: OFObject
#ifdef OF_HAVE_CLASS_PROPERTIES
@property (class, readonly, nonatomic)
    OFArray <HIDGameController *> *controllers;
    OFArray <OHGameController *> *controllers;
#endif

/**
 * @brief The name of the controller.
 */
@property (readonly, nonatomic, copy) OFString *name;

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
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







-
+






-
+




-
+








 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *productID;

/**
 * @brief An unmapped mapping for the game controller, meaning no remapping is
 *	  being performed.
 */
@property (readonly, nonatomic) HIDGameControllerMapping *unmappedMapping;
@property (readonly, nonatomic) OHGameControllerMapping *unmappedMapping;

/**
 * @brief Returns the available controllers.
 *
 * @return The available controllers
 */
+ (OFArray OF_GENERIC(HIDGameController *) *)controllers;
+ (OFArray OF_GENERIC(OHGameController *) *)controllers;

/**
 * @brief Retrieves the current state from the game controller.
 *
 * The state returned by @ref HIDGameController's methods does not change until
 * The state returned by @ref OHGameController'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/HIDGameController.m [1e275c1bfa] to src/hid/OHGameController.m [b33f3a4512].

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
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 "OHGameController.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFSet.h"

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "HIDEvdevGameController.h"
# include "OHEvdevGameController.h"
#endif

@implementation HIDGameController
@implementation OHGameController
@dynamic name, unmappedMapping;

+ (OFArray OF_GENERIC(HIDGameController *) *)controllers
+ (OFArray OF_GENERIC(OHGameController *) *)controllers
{
#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
	return [HIDEvdevGameController controllers];
	return [OHEvdevGameController controllers];
#else
	return [OFArray array];
#endif
}

- (instancetype)init
{
	if ([self isMemberOfClass: [HIDGameController class]]) {
	if ([self isMemberOfClass: [OHGameController class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

81
82
83
84
85
86
87
88

89
81
82
83
84
85
86
87

88
89







-
+

	else
		return [OFString stringWithFormat: @"<%@: %@>",
						   self.class, self.name];
}
@end

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "HIDEvdevGameController.m"
# include "OHEvdevGameController.m"
#endif

Renamed and modified src/hid/HIDGameControllerAxis.h [876c2397e0] to src/hid/OHGameControllerAxis.h [a18496dca4].

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
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







-
+




-
-
+
+



-
+


-
+







 * 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 "OHGameControllerElement.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class HIDGameControllerAxis \
 *	  HIDGameControllerAxis.h ObjFWHID/HIDGameControllerAxis.h
 * @class OHGameControllerAxis \
 *	  OHGameControllerAxis.h ObjFWHID/OHGameControllerAxis.h
 *
 * @brief An axis of a game controller.
 */
@interface HIDGameControllerAxis: HIDGameControllerElement
@interface OHGameControllerAxis: OHGameControllerElement
{
	float _value;
	OF_RESERVE_IVARS(HIDGameControllerButton, 4)
	OF_RESERVE_IVARS(OHGameControllerButton, 4)
}

/**
 * @brief The value of the axis.
 */
@property (nonatomic) float value;
@end

Renamed and modified src/hid/HIDGameControllerAxis.m [9b1e5938fe] to src/hid/OHGameControllerAxis.m [0113b75889].

15
16
17
18
19
20
21
22

23
24

25
26
27
28
29
30
31
15
16
17
18
19
20
21

22
23

24
25
26
27
28
29
30
31







-
+

-
+







 * 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"
#import "OHGameControllerAxis.h"

@implementation HIDGameControllerAxis
@implementation OHGameControllerAxis
@synthesize value = _value;

- (OFString *)description
{
	return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end

Renamed and modified src/hid/HIDGameControllerButton.h [e6d7487002] to src/hid/OHGameControllerButton.h [1613a4493a].

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
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







-
+




-
-
+
+



-
+


-
+







 * 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 "OHGameControllerElement.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class HIDGameControllerButton \
 *	  HIDGameControllerButton.h ObjFWHID/HIDGameControllerButton.h
 * @class OHGameControllerButton \
 *	  OHGameControllerButton.h ObjFWHID/OHGameControllerButton.h
 *
 * @brief A button of a game controller.
 */
@interface HIDGameControllerButton: HIDGameControllerElement
@interface OHGameControllerButton: OHGameControllerElement
{
	float _value;
	OF_RESERVE_IVARS(HIDGameControllerButton, 4)
	OF_RESERVE_IVARS(OHGameControllerButton, 4)
}

/**
 * @brief Whether the game controller button is pressed.
 */
@property (readonly, nonatomic, getter=isPressed) bool pressed;

Renamed and modified src/hid/HIDGameControllerButton.m [64b22e0918] to src/hid/OHGameControllerButton.m [558ba95814].

15
16
17
18
19
20
21
22

23
24

25
26
27
28
29
30
31
15
16
17
18
19
20
21

22
23

24
25
26
27
28
29
30
31







-
+

-
+







 * 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"
#import "OHGameControllerButton.h"

@implementation HIDGameControllerButton
@implementation OHGameControllerButton
@synthesize value = _value;

- (bool)isPressed
{
	return (_value > 0);
}

Renamed and modified src/hid/HIDGameControllerDirectionalPad.h [2c2bbf2751] to src/hid/OHGameControllerDirectionalPad.h [773f283b6a].

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
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







-
-
-
+
+
+




-
-
-
+
+
+




-
+

-
-
-
+
+
+





-
+




-
+




-
+




-
+




-
+




-
+




-
-
+
+


-
-
-
-
+
+
+
+



 * 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"
#import "OHGameControllerElement.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class HIDGameControllerDirectionalPad \
 *	  HIDGameControllerDirectionalPad.h \
 *	  ObjFWHID/HIDGameControllerDirectionalPad.h
 * @class OHGameControllerDirectionalPad \
 *	  OHGameControllerDirectionalPad.h 
 *	  ObjFWHID/OHGameControllerDirectionalPad.h
 *
 * @brief An directional pad or thumb stick of a game controller.
 */
OF_SUBCLASSING_RESTRICTED
@interface HIDGameControllerDirectionalPad: HIDGameControllerElement
@interface OHGameControllerDirectionalPad: OHGameControllerElement
{
	HIDGameControllerAxis *_xAxis, *_yAxis;
	HIDGameControllerButton *_upButton, *_downButton;
	HIDGameControllerButton *_leftButton, *_rightButton;
	OHGameControllerAxis *_xAxis, *_yAxis;
	OHGameControllerButton *_upButton, *_downButton;
	OHGameControllerButton *_leftButton, *_rightButton;
}

/**
 * @brief The X axis of the directional pad.
 */
@property (readonly, nonatomic) HIDGameControllerAxis *xAxis;
@property (readonly, nonatomic) OHGameControllerAxis *xAxis;

/**
 * @brief The Y axis of the directional pad.
 */
@property (readonly, nonatomic) HIDGameControllerAxis *yAxis;
@property (readonly, nonatomic) OHGameControllerAxis *yAxis;

/**
 * @brief The up button of the directional pad.
 */
@property (readonly, nonatomic) HIDGameControllerButton *upButton;
@property (readonly, nonatomic) OHGameControllerButton *upButton;

/**
 * @brief The down button of the directional pad.
 */
@property (readonly, nonatomic) HIDGameControllerButton *downButton;
@property (readonly, nonatomic) OHGameControllerButton *downButton;

/**
 * @brief The left button of the directional pad.
 */
@property (readonly, nonatomic) HIDGameControllerButton *leftButton;
@property (readonly, nonatomic) OHGameControllerButton *leftButton;

/**
 * @brief The right button of the directional pad.
 */
@property (readonly, nonatomic) HIDGameControllerButton *rightButton;
@property (readonly, nonatomic) OHGameControllerButton *rightButton;

- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;

- (instancetype)initWithName: (OFString *)name
		       xAxis: (HIDGameControllerAxis *)xAxis
		       yAxis: (HIDGameControllerAxis *)yAxis;
		       xAxis: (OHGameControllerAxis *)xAxis
		       yAxis: (OHGameControllerAxis *)yAxis;

- (instancetype)initWithName: (OFString *)name
		    upButton: (HIDGameControllerButton *)upButton
		  downButton: (HIDGameControllerButton *)downButton
		  leftButton: (HIDGameControllerButton *)leftButton
		 rightButton: (HIDGameControllerButton *)rightButton;
		    upButton: (OHGameControllerButton *)upButton
		  downButton: (OHGameControllerButton *)downButton
		  leftButton: (OHGameControllerButton *)leftButton
		 rightButton: (OHGameControllerButton *)rightButton;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/HIDGameControllerDirectionalPad.m [6db9de440f] to src/hid/OHGameControllerDirectionalPad.m [f54e2d335a].

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
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







-
-
-
+
+
+

-
+










-
-
+
+







-
+


-
+


-
+


-
+











-
-
-
-
+
+
+
+









-
+


-
+







 * 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"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerEmulatedAxis.h"
#import "OHGameControllerEmulatedButton.h"

@implementation HIDGameControllerDirectionalPad
@implementation OHGameControllerDirectionalPad
@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
		       xAxis: (OHGameControllerAxis *)xAxis
		       yAxis: (OHGameControllerAxis *)yAxis
{
	self = [super initWithName: name];

	@try {
		_xAxis = [xAxis retain];
		_yAxis = [yAxis retain];

		_upButton = [[HIDGameControllerEmulatedButton alloc]
		_upButton = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _yAxis
			positive: false];
		_downButton = [[HIDGameControllerEmulatedButton alloc]
		_downButton = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _yAxis
			positive: true];
		_leftButton = [[HIDGameControllerEmulatedButton alloc]
		_leftButton = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _xAxis
			positive: false];
		_rightButton = [[HIDGameControllerEmulatedButton alloc]
		_rightButton = [[OHGameControllerEmulatedButton 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
		    upButton: (OHGameControllerButton *)upButton
		  downButton: (OHGameControllerButton *)downButton
		  leftButton: (OHGameControllerButton *)leftButton
		 rightButton: (OHGameControllerButton *)rightButton
{
	self = [super initWithName: name];

	@try {
		_upButton = [upButton retain];
		_downButton = [downButton retain];
		_leftButton = [leftButton retain];
		_rightButton = [rightButton retain];

		_xAxis = [[HIDGameControllerEmulatedAxis alloc]
		_xAxis = [[OHGameControllerEmulatedAxis alloc]
		    initWithNegativeButton: _leftButton
			    positiveButton: _rightButton];
		_yAxis = [[HIDGameControllerEmulatedAxis alloc]
		_yAxis = [[OHGameControllerEmulatedAxis alloc]
		    initWithNegativeButton: _upButton
			    positiveButton: _downButton];
	} @catch (id e) {
		[self release];
		@throw e;
	}

Renamed and modified src/hid/HIDGameControllerElement.h [721f4d8e3b] to src/hid/OHGameControllerElement.h [32fde53c9e].

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
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







-
-
+
+




-
+



-
+







#  import <ObjFW/OFString.h>
# endif
#endif

OF_ASSUME_NONNULL_BEGIN

/**
 * @class HIDGameControllerElement \
 *	  HIDGameControllerElement.h ObjFWHID/HIDGameControllerElement.h
 * @class OHGameControllerElement \
 *	  OHGameControllerElement.h ObjFWHID/OHGameControllerElement.h
 *
 * @brief An element of a game controller, e.g. a button, an axis or a
 *	  directional pad.
 */
@interface HIDGameControllerElement: OFObject
@interface OHGameControllerElement: OFObject
{
	OFString *_name;
	bool _analog;
	OF_RESERVE_IVARS(HIDGameControllerElement, 4)
	OF_RESERVE_IVARS(OHGameControllerElement, 4)
}

/**
 * @brief The name of the game controller element.
 */
@property (readonly, nonatomic) OFString *name;

Renamed and modified src/hid/HIDGameControllerElement.m [35eace7e5e] to src/hid/OHGameControllerElement.m [e28f3ca624].

15
16
17
18
19
20
21
22

23
24

25
26
27
28
29
30
31
15
16
17
18
19
20
21

22
23

24
25
26
27
28
29
30
31







-
+

-
+







 * 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"
#import "OHGameControllerElement.h"

@implementation HIDGameControllerElement
@implementation OHGameControllerElement
@synthesize name = _name, analog = _analog;

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

Renamed and modified src/hid/HIDGameControllerEmulatedAxis.h [f06104d6f6] to src/hid/OHGameControllerEmulatedAxis.h [a0f65c5e9a].

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
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







-
+



-
+


-
+

-
+




-
-
+
+



 * 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"
#import "OHGameControllerAxis.h"

OF_ASSUME_NONNULL_BEGIN

@class HIDGameControllerButton;
@class OHGameControllerButton;

OF_SUBCLASSING_RESTRICTED
@interface HIDGameControllerEmulatedAxis: HIDGameControllerAxis
@interface OHGameControllerEmulatedAxis: OHGameControllerAxis
{
	HIDGameControllerButton *_negativeButton, *_positiveButton;
	OHGameControllerButton *_negativeButton, *_positiveButton;
}

- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;
- (instancetype)
    initWithNegativeButton: (HIDGameControllerButton *)negativeButton
	    positiveButton: (HIDGameControllerButton *)positiveButton;
    initWithNegativeButton: (OHGameControllerButton *)negativeButton
	    positiveButton: (OHGameControllerButton *)positiveButton;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/HIDGameControllerEmulatedAxis.m [01c06a1ab0] to src/hid/OHGameControllerEmulatedAxis.m [d60d8c7150].

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
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







-
-
+
+

-
+





-
-
-
+
+


-
+







 * 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"
#import "OHGameControllerEmulatedAxis.h"
#import "OHGameControllerButton.h"

@implementation HIDGameControllerEmulatedAxis
@implementation OHGameControllerEmulatedAxis
- (instancetype)initWithName: (OFString *)name
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)
    initWithNegativeButton: (HIDGameControllerButton *)negativeButton
	    positiveButton: (HIDGameControllerButton *)positiveButton
- (instancetype)initWithNegativeButton: (OHGameControllerButton *)negativeButton
			positiveButton: (OHGameControllerButton *)positiveButton
{
	void *pool = objc_autoreleasePoolPush();
	OFString *name;;
	OFString *name;

	@try {
		name = [OFString stringWithFormat:
		    @"%@ and %@ as emulated axis",
		    negativeButton.name, positiveButton.name];
	} @catch (id e) {
		[self release];

Renamed and modified src/hid/HIDGameControllerEmulatedButton.h [3f0e6ab4ac] to src/hid/OHGameControllerEmulatedButton.h [1f52540e1f].

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
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







-
+



-
+


-
+

-
+




-
+




 * 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"
#import "OHGameControllerButton.h"

OF_ASSUME_NONNULL_BEGIN

@class HIDGameControllerAxis;
@class OHGameControllerAxis;

OF_SUBCLASSING_RESTRICTED
@interface HIDGameControllerEmulatedButton: HIDGameControllerButton
@interface OHGameControllerEmulatedButton: OHGameControllerButton
{
	HIDGameControllerAxis *_axis;
	OHGameControllerAxis *_axis;
	bool _positive;
}

- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;
- (instancetype)initWithAxis: (HIDGameControllerAxis *)axis
- (instancetype)initWithAxis: (OHGameControllerAxis *)axis
		    positive: (bool)positive;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/HIDGameControllerEmulatedButton.m [921a669bf3] to src/hid/OHGameControllerEmulatedButton.m [1d9492427b].

15
16
17
18
19
20
21
22
23


24
25

26
27
28
29
30
31

32
33
34
35
36
37
38
15
16
17
18
19
20
21


22
23
24

25
26
27
28
29
30

31
32
33
34
35
36
37
38







-
-
+
+

-
+





-
+







 * 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"
#import "OHGameControllerEmulatedButton.h"
#import "OHGameControllerAxis.h"

@implementation HIDGameControllerEmulatedButton: HIDGameControllerButton
@implementation OHGameControllerEmulatedButton: OHGameControllerButton
- (instancetype)initWithName: (OFString *)name
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithAxis: (HIDGameControllerAxis *)axis
- (instancetype)initWithAxis: (OHGameControllerAxis *)axis
		    positive: (bool)positive
{
	void *pool = objc_autoreleasePoolPush();
	OFString *name;

	@try {
		name = [OFString stringWithFormat:

Renamed and modified src/hid/HIDGameControllerMapping.h [9d245e3712] to src/hid/OHGameControllerMapping.h [c9756630f5].

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
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







+
-
-
-
+
+
+
-


-
-
+
+

-
+

-
+

-
+
-
-
-
+
+

-
-
+
+
+
-

-
+


-
+


-
+


-
+



-
+


-
+



#  import <ObjFW/OFObject.h>
#  import <ObjFW/OFString.h>
# endif
#endif

OF_ASSUME_NONNULL_BEGIN

@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class HIDGameControllerAxis;
@class HIDGameControllerButton;
@class HIDGameControllerDirectionalPad;
@class OHGameControllerAxis;
@class OHGameControllerButton;
@class OHGameControllerDirectionalPad;
@class OFDictionary OF_GENERIC(KeyType, ObjectType);

/**
 * @class HIDGameControllerMapping \
 *	  HIDGameControllerMapping.h ObjFWHID/HIDGameControllerMapping.h
 * @class OHGameControllerMapping \
 *	  OHGameControllerMapping.h ObjFWHID/OHGameControllerMapping.h
 *
 * @brief A mapping for a @ref HIDGameController.
 * @brief A mapping for a @ref OHGameController.
 */
@interface HIDGameControllerMapping: OFObject
@interface OHGameControllerMapping: OFObject
{
	OFDictionary OF_GENERIC(OFString *, HIDGameControllerButton *)
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	    *_buttons;
	OFDictionary OF_GENERIC(OFString *, HIDGameControllerAxis *) *_axes;
	OFDictionary OF_GENERIC(OFString *, HIDGameControllerDirectionalPad *)
	OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *_axes;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *_directionalPads;
	OF_RESERVE_IVARS(HIDGameControllerMapping, 4)
}
	OF_RESERVE_IVARS(OHGameControllerMapping, 4)
}


/**
 * @brief A map of all button names to their @ref HIDGameControllerButton.
 * @brief A map of all button names to their @ref OHGameControllerButton.
 */
@property (readonly, nonatomic)
    OFDictionary OF_GENERIC(OFString *, HIDGameControllerButton *) *buttons;
    OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *buttons;

/**
 * @brief A map of all axis names to their @ref HIDGameControllerAxis.
 * @brief A map of all axis names to their @ref OHGameControllerAxis.
 */
@property (readonly, nonatomic)
    OFDictionary OF_GENERIC(OFString *, HIDGameControllerAxis *) *axes;
    OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *axes;

/**
 * @brief A map of all directional pads to their
 *	  @ref HIDGameControllerDirectionalPad.
 *	  @ref OHGameControllerDirectionalPad.
 */
@property (readonly, nonatomic) OFDictionary OF_GENERIC(OFString *,
    HIDGameControllerDirectionalPad *) *directionalPads;
    OHGameControllerDirectionalPad *) *directionalPads;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/HIDGameControllerMapping.m [16d8c69c01] to src/hid/OHGameControllerMapping.m [f68efd6f5e].

15
16
17
18
19
20
21
22

23
24
25

26
27
28
29
30
31
32
15
16
17
18
19
20
21

22
23
24

25
26
27
28
29
30
31
32







-
+


-
+







 * 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 "HIDGameControllerMapping.h"
#import "OHGameControllerMapping.h"
#import "OFDictionary.h"

@implementation HIDGameControllerMapping: OFObject
@implementation OHGameControllerMapping: OFObject
@synthesize buttons = _buttons, axes = _axes;
@synthesize directionalPads = _directionalPads;

- (void)dealloc
{
	[_buttons release];
	[_axes release];

Modified src/hid/ObjFWHID.h from [d1a844bf10] to [2704e96f7e].

13
14
15
16
17
18
19
20
21
22
23
24





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"
#import "OHGameController.h"
#import "OHGameControllerElement.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerDirectionalPad.h"

Modified src/test/OTAppDelegate.m from [e739358c29] to [c2558fe049].

26
27
28
29
30
31
32
33
34
35



36
37
38
39
40
41
42
26
27
28
29
30
31
32



33
34
35
36
37
38
39
40
41
42







-
-
-
+
+
+







#import "OFSet.h"
#import "OFStdIOStream.h"
#import "OFThread.h"
#import "OFValue.h"

#import "OTTestCase.h"

#import "HIDGameController.h"
#import "HIDGameControllerButton.h"
#import "HIDGameControllerMapping.h"
#import "OHGameController.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerMapping.h"

#import "OTAssertionFailedException.h"
#import "OTTestSkippedException.h"

#ifdef OF_IOS
# include <CoreFoundation/CoreFoundation.h>
#endif
281
282
283
284
285
286
287
288
289
290



291
292
293
294
295
296
297
281
282
283
284
285
286
287



288
289
290
291
292
293
294
295
296
297







-
-
-
+
+
+







	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 =
			OHGameController *controller =
			    [[OHGameController controllers] objectAtIndex: 0];
			OHGameControllerButton *button =
			    [controller.unmappedMapping.buttons
			    objectForKey: @"A"];

			[controller retrieveState];

			if (button.pressed)
				break;
545
546
547
548
549
550
551
552
553
554



555
556
557
558
559
560
561
545
546
547
548
549
550
551



552
553
554
555
556
557
558
559
560
561







-
-
-
+
+
+







	[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];
		HIDGameControllerButton *button =
		OHGameController *controller =
		    [[OHGameController controllers] objectAtIndex: 0];
		OHGameControllerButton *button =
# ifdef OF_WII
		    [controller.unmappedMapping.buttons objectForKey: @"Home"];
# else
		    [controller.unmappedMapping.buttons objectForKey: @"Start"];
# endif

		[controller retrieveState];

Modified tests/gamecontroller/GameControllerTests.m from [563268e4f8] to [f7c9148fed].

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
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







-
-
-
-
+
+
+
+



















-
+







#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 "HIDGameControllerMapping.h"
#import "OHGameController.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerMapping.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;
	OFMutableArray OF_GENERIC(OHGameController *) *_controllers;
	OFDate *_lastControllersUpdate;
}
@end

OF_APPLICATION_DELEGATE(GameControllerTests)

@implementation GameControllerTests
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
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







-
+








-
-
+
+




















-
+







		void *pool = objc_autoreleasePoolPush();

		if (_lastControllersUpdate == nil ||
		    -[_lastControllersUpdate timeIntervalSinceNow] > 1) {
			[_controllers release];
			[_lastControllersUpdate release];

			_controllers = [[HIDGameController controllers]
			_controllers = [[OHGameController controllers]
			    mutableCopy];
			_lastControllersUpdate = [[OFDate alloc] init];

			[OFStdOut clear];
		}

		[OFStdOut setCursorPosition: OFMakePoint(0, 0)];

		for (HIDGameController *controller in _controllers) {
			HIDGameControllerMapping *mapping =
		for (OHGameController *controller in _controllers) {
			OHGameControllerMapping *mapping =
			    controller.unmappedMapping;
			OFArray OF_GENERIC(OFString *) *buttons =
			    mapping.buttons.allKeys.sortedArray;
			OFArray OF_GENERIC(OFString *) *axes =
			    mapping.axes.allKeys.sortedArray;
			size_t i;

			[OFStdOut setForegroundColor: [OFColor green]];
			[OFStdOut writeString: controller.description];

			@try {
				[controller retrieveState];
			} @catch (OFReadFailedException *e) {
				[OFStdOut setForegroundColor: [OFColor red]];
				[OFStdOut writeFormat: @"\n%@", e.description];
				continue;
			}

			i = 0;
			for (OFString *name in buttons) {
				HIDGameControllerButton *button =
				OHGameControllerButton *button =
				    [mapping.buttons objectForKey: name];

				if (i == 0)
					[OFStdOut writeString: @"\n"];

				if (button.value == 1)
					[OFStdOut setForegroundColor:
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145







-
+







					[OFStdOut writeString: @" "];
			}
			[OFStdOut setForegroundColor: [OFColor gray]];
			[OFStdOut writeString: @"\n"];

			i = 0;
			for (OFString *name in axes) {
				HIDGameControllerAxis *axis =
				OHGameControllerAxis *axis =
				    [mapping.axes objectForKey: name];

				if (i == 0)
					[OFStdOut writeString: @"\n"];

				[OFStdOut writeFormat: @"%@: %5.2f ",
						       name, axis.value];