ObjFW  Check-in [15ab9bba82]

Overview
Comment:ObjFWHID: OHCombinedJoyCons -> OHJoyConPair
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 15ab9bba8213c25fd4d810f0686d6095962b5d8a52bcaf7457b02fc473fa65d2
User & Date: js on 2024-07-01 18:52:48
Other Links: manifest | tags
Context
2024-07-04
18:45
Make conformance to OHEvdevMapping private check-in: 146b11b201 user: js tags: trunk
2024-07-01
18:52
ObjFWHID: OHCombinedJoyCons -> OHJoyConPair check-in: 15ab9bba82 user: js tags: trunk
18:41
ObjFWHID: Make most profiles public check-in: dfaf830200 user: js tags: trunk
Changes

Modified src/hid/Makefile from [70f9c3c1c0] to [27f78be24f].

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











-
-
+







+







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 = OHCombinedJoyCons.m		\
       OHDualSenseGamepad.m		\
SRCS = OHDualSenseGamepad.m		\
       OHDualShock4Gamepad.m		\
       OHExtendedN64Controller.m	\
       OHGameController.m		\
       OHGameControllerAxis.m		\
       OHGameControllerButton.m		\
       OHGameControllerDirectionalPad.m	\
       OHGameControllerElement.m	\
       OHJoyConPair.m			\
       OHLeftJoyCon.m			\
       OHN64Controller.m		\
       OHRightJoyCon.m			\
       OHStadiaGamepad.m		\
       OHXboxGamepad.m

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

Renamed and modified src/hid/OHCombinedJoyCons.h [3ff7fc7f86] to src/hid/OHJoyConPair.h [343333c252].

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







+
+


-
+




-
+

-
-
+
+






-
+
-

-
-
-
+
+
+

-
-
+
+




-
-
+
+

-
-
-
+
+
+

-
-
+
+



#import "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@class OHGameController;
@class OHGameControllerButton;
@class OHGameControllerDirectionalPad;
@class OHLeftJoyCon;
@class OHRightJoyCon;

/**
 * @class OHCombinedJoyCons OHCombinedJoyCons.h ObjFWHID/ObjFWHID.h
 * @class OHJoyConPair OHJoyConPair.h ObjFWHID/ObjFWHID.h
 *
 * @brief Combines a left and a right Joy-Con into a gamepad.
 */
OF_SUBCLASSING_RESTRICTED
@interface OHCombinedJoyCons: OFObject <OHExtendedGamepad>
@interface OHJoyConPair: OFObject <OHExtendedGamepad>
{
	id <OHGameControllerProfile> _leftJoyCon;
	id <OHGameControllerProfile> _rightJoyCon;
	OHLeftJoyCon *_leftJoyCon;
	OHRightJoyCon *_rightJoyCon;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *_directionalPads;
}

/**
 * @brief Creates a new @ref OHCombinedJoyCons with the specified left and
 * @brief Creates a new Joy-Con pair with the specified left and right Joy-Con.
 *	  right Joy-Con.
 *
 * @param leftJoyCon The left Joy-Con
 * @param rightJoyCon The right Joy-Con
 * @return An new @ref OHCombinedJoyCons
 * @param leftJoyCon The left Joy-Con for the pair
 * @param rightJoyCon The right Joy-Con for the pair
 * @return An new Joy-Con pair
 */
+ (instancetype)gamepadWithLeftJoyCon: (OHGameController *)leftJoyCon
			  rightJoyCon: (OHGameController *)rightJoyCon;
+ (instancetype)gamepadWithLeftJoyCon: (OHLeftJoyCon *)leftJoyCon
			  rightJoyCon: (OHRightJoyCon *)rightJoyCon;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated @ref OHCombinedJoyCons with the
 *	  specified left and right Joy-Con.
 * @brief Initializes an already allocated Joy-Con pair with the specified left
 *	  and right Joy-Con.
 *
 * @param leftJoyCon The left Joy-Con
 * @param rightJoyCon The right Joy-Con
 * @return An initialized @ref OHCombinedJoyCons
 * @param leftJoyCon The left Joy-Con for the pair
 * @param rightJoyCon The right Joy-Con for the pair
 * @return An initialized Joy-Con pair
 */
- (instancetype)initWithLeftJoyCon: (OHGameController *)leftJoyCon
		       rightJoyCon: (OHGameController *)rightJoyCon;
- (instancetype)initWithLeftJoyCon: (OHLeftJoyCon *)leftJoyCon
		       rightJoyCon: (OHRightJoyCon *)rightJoyCon;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/OHCombinedJoyCons.m [0639ff2a5d] to src/hid/OHJoyConPair.m [581b1be473].

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







-
+




+
+



-
+


-
-
+
+










-
-
+
+





-


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

-
-
-

-
-
-
+
+
+







 * 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 "OHCombinedJoyCons.h"
#import "OHJoyConPair.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameController.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHLeftJoyCon.h"
#import "OHRightJoyCon.h"

#import "OFInvalidArgumentException.h"

@implementation OHCombinedJoyCons
@implementation OHJoyConPair
@synthesize buttons = _buttons, directionalPads = _directionalPads;

+ (instancetype)gamepadWithLeftJoyCon: (OHGameController *)leftJoyCon
			  rightJoyCon: (OHGameController *)rightJoyCon
+ (instancetype)gamepadWithLeftJoyCon: (OHLeftJoyCon *)leftJoyCon
			  rightJoyCon: (OHRightJoyCon *)rightJoyCon
{
	return [[[self alloc] initWithLeftJoyCon: leftJoyCon
				     rightJoyCon: rightJoyCon] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithLeftJoyCon: (OHGameController *)leftJoyCon
		       rightJoyCon: (OHGameController *)rightJoyCon
- (instancetype)initWithLeftJoyCon: (OHLeftJoyCon *)leftJoyCon
		       rightJoyCon: (OHRightJoyCon *)rightJoyCon
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFDictionary *leftButtons, *rightButtons;
		OFMutableDictionary *buttons, *directionalPads;

		if (leftJoyCon.vendorID.unsignedShortValue !=
		    OHVendorIDNintendo ||
		    rightJoyCon.vendorID.unsignedShortValue !=
		    OHVendorIDNintendo)
			@throw [OFInvalidArgumentException exception];

		if (leftJoyCon.productID.unsignedShortValue !=
		    OHProductIDLeftJoyCon ||
		    rightJoyCon.productID.unsignedShortValue !=
		    OHProductIDRightJoyCon)
			@throw [OFInvalidArgumentException exception];

		_leftJoyCon = [leftJoyCon.profile retain];
		_rightJoyCon = [rightJoyCon.profile retain];
		_leftJoyCon = [leftJoyCon retain];
		_rightJoyCon = [rightJoyCon retain];

		leftButtons = _leftJoyCon.buttons;
		rightButtons = _rightJoyCon.buttons;

		buttons = [OFMutableDictionary dictionaryWithCapacity:
		    leftButtons.count + rightButtons.count];
		[buttons addEntriesFromDictionary: leftButtons];
		[buttons addEntriesFromDictionary: rightButtons];
		    _leftJoyCon.buttons.count + _rightJoyCon.buttons.count];
		[buttons addEntriesFromDictionary: _leftJoyCon.buttons];
		[buttons addEntriesFromDictionary: _rightJoyCon.buttons];
		[buttons removeObjectForKey: @"SL"];
		[buttons removeObjectForKey: @"SR"];
		[buttons makeImmutable];
		_buttons = [buttons retain];

		directionalPads =
		    [OFMutableDictionary dictionaryWithCapacity: 3];

Modified src/hid/ObjFWHID.h from [72da477079] to [edb5eb74fe].

22
23
24
25
26
27
28
29
30
31
32
33
34
35


36
37
22
23
24
25
26
27
28

29
30
31
32

33
34
35
36
37







-




-

+
+


#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerProfile.h"
#import "OHGamepad.h"
#import "OHExtendedGamepad.h"

#import "OHCombinedJoyCons.h"
#import "OHDualSenseGamepad.h"
#import "OHDualShock4Gamepad.h"
#import "OHExtendedN64Controller.h"
#import "OHLeftJoyCon.h"
#import "OHN64Controller.h"
#import "OHRightJoyCon.h"
#import "OHJoyConPair.h"
#import "OHN64Controller.h"
#import "OHStadiaGamepad.h"
#import "OHXboxGamepad.h"

Modified tests/gamecontroller/GameControllerTests.m from [a4fbbbb68a] to [fd38b501b0].

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38



39
40
41
42
43
44
45
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







-







+
+
+







#import "OFColor.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OFStdIOStream.h"
#import "OFThread.h"

#import "OHCombinedJoyCons.h"
#import "OHExtendedGamepad.h"
#import "OHGameController.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerProfile.h"
#import "OHGamepad.h"
#import "OHJoyConPair.h"
#import "OHLeftJoyCon.h"
#import "OHRightJoyCon.h"

#import "OFReadFailedException.h"

#if defined(OF_NINTENDO_DS)
static size_t buttonsPerLine = 2;
#elif defined(OF_NINTENDO_3DS)
static size_t buttonsPerLine = 3;
191
192
193
194
195
196
197

198

199
200
201
202
203
204
205
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
208







+
-
+







	consoleInit(NULL);

	while (appletMainLoop()) {
#else
	for (;;) {
#endif
		void *pool = objc_autoreleasePoolPush();
		OHLeftJoyCon *leftJoyCon = nil;
		OHGameController *leftJoyCon = nil, *rightJoyCon = nil;
		OHRightJoyCon *rightJoyCon = nil;

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

			_controllers = [[OHGameController controllers] retain];
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
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







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



-
+




-
+

-
+







				[OFStdOut setForegroundColor: [OFColor red]];
				[OFStdOut writeString: e.description];
				continue;
			}

			printProfile(profile);

			if (controller.vendorID.unsignedShortValue ==
			    OHVendorIDNintendo) {
				if (controller.productID.unsignedShortValue ==
				    OHProductIDLeftJoyCon)
					leftJoyCon = controller;
			if ([profile isKindOfClass: [OHLeftJoyCon class]])
				leftJoyCon = (OHLeftJoyCon *)profile;
				if (controller.productID.unsignedShortValue ==
				    OHProductIDRightJoyCon)
					rightJoyCon = controller;
			else if ([profile isKindOfClass: [OHRightJoyCon class]])
				rightJoyCon = (OHRightJoyCon *)profile;
			}
		}

		if (leftJoyCon != nil && rightJoyCon != nil) {
			OHCombinedJoyCons *combinedJoyCons = [OHCombinedJoyCons
			OHJoyConPair *joyConPair = [OHJoyConPair
			    gamepadWithLeftJoyCon: leftJoyCon
				      rightJoyCon: rightJoyCon];

			[OFStdOut setForegroundColor: [OFColor green]];
			[OFStdOut writeLine: @"Combined Joy-Cons"];
			[OFStdOut writeLine: @"Joy-Con Pair"];

			printProfile(combinedJoyCons);
			printProfile(joyConPair);
		}

#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS)
		[OFThread waitForVerticalBlank];
#elif defined(OF_NINTENDO_SWITCH)
		consoleUpdate(NULL);
#else