ObjFW  Check-in [1da303e600]

Overview
Comment:OFGameController: Add quirks for Joycons
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | gamecontroller
Files: files | file ages | folders
SHA3-256: 1da303e60089e14dec24e2294baa25fb67cbf437705581d773a7f4a419d9b527
User & Date: js on 2024-05-11 10:19:32
Other Links: branch diff | manifest | tags
Context
2024-05-11
21:56
OFGameController: {north,south,west,east}Button check-in: 59b45e87d1 user: js tags: gamecontroller
10:19
OFGameController: Add quirks for Joycons check-in: 1da303e600 user: js tags: gamecontroller
10:06
OFGameController: Report vendor ID and product ID check-in: c0735ac803 user: js tags: gamecontroller
Changes

Modified src/OFGameController.h from [8e114313d9] to [dd47275cc1].

54
55
56
57
58
59
60


61
62
63
64
65
66
67
 *   * @ref OFGameControllerButtonDPadDown
 *   * @ref OFGameControllerButtonDPadLeft
 *   * @ref OFGameControllerButtonDPadRight
 *   * @ref OFGameControllerButtonCPadUp
 *   * @ref OFGameControllerButtonCPadDown
 *   * @ref OFGameControllerButtonCPadLeft
 *   * @ref OFGameControllerButtonCPadRight


 *   * @ref OFGameControllerButtonMode
 */
typedef OFConstantString *OFGameControllerButton;

#ifdef __cplusplus
extern "C" {
#endif







>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 *   * @ref OFGameControllerButtonDPadDown
 *   * @ref OFGameControllerButtonDPadLeft
 *   * @ref OFGameControllerButtonDPadRight
 *   * @ref OFGameControllerButtonCPadUp
 *   * @ref OFGameControllerButtonCPadDown
 *   * @ref OFGameControllerButtonCPadLeft
 *   * @ref OFGameControllerButtonCPadRight
 *   * @ref OFGameControllerButtonSL
 *   * @ref OFGameControllerButtonSR
 *   * @ref OFGameControllerButtonMode
 */
typedef OFConstantString *OFGameControllerButton;

#ifdef __cplusplus
extern "C" {
#endif
182
183
184
185
186
187
188




















189
190
191
192
193
194
195
extern const OFGameControllerButton OFGameControllerButtonCPadLeft;

/**
 * @brief The C-Pad Right button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonCPadRight;





















/**
 * @brief The Mode button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonMode;
#ifdef __cplusplus
}
#endif







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
extern const OFGameControllerButton OFGameControllerButtonCPadLeft;

/**
 * @brief The C-Pad Right button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonCPadRight;

/**
 * @brief The + button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonPlus;

/**
 * @brief The - button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonMinus;

/**
 * @brief The SL button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonSL;

/**
 * @brief The SR button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonSR;

/**
 * @brief The Mode button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonMode;
#ifdef __cplusplus
}
#endif

Modified src/OFGameController.m from [0e2f40500d] to [31e4b70394].

42
43
44
45
46
47
48




49
50
51
52
53
54
55
const OFGameControllerButton OFGameControllerButtonDPadDown = @"D-Pad Down";
const OFGameControllerButton OFGameControllerButtonDPadLeft = @"D-Pad Left";
const OFGameControllerButton OFGameControllerButtonDPadRight = @"D-Pad Right";
const OFGameControllerButton OFGameControllerButtonCPadUp = @"C-Pad Up";
const OFGameControllerButton OFGameControllerButtonCPadDown = @"C-Pad Down";
const OFGameControllerButton OFGameControllerButtonCPadLeft = @"C-Pad Left";
const OFGameControllerButton OFGameControllerButtonCPadRight = @"C-Pad Right";




const OFGameControllerButton OFGameControllerButtonMode = @"Mode";

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "platform/Linux/OFGameController.m"
#elif defined(OF_WINDOWS)
# include "platform/Windows/OFGameController.m"
#elif defined(OF_NINTENDO_DS)







>
>
>
>







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const OFGameControllerButton OFGameControllerButtonDPadDown = @"D-Pad Down";
const OFGameControllerButton OFGameControllerButtonDPadLeft = @"D-Pad Left";
const OFGameControllerButton OFGameControllerButtonDPadRight = @"D-Pad Right";
const OFGameControllerButton OFGameControllerButtonCPadUp = @"C-Pad Up";
const OFGameControllerButton OFGameControllerButtonCPadDown = @"C-Pad Down";
const OFGameControllerButton OFGameControllerButtonCPadLeft = @"C-Pad Left";
const OFGameControllerButton OFGameControllerButtonCPadRight = @"C-Pad Right";
const OFGameControllerButton OFGameControllerButtonPlus = @"+";
const OFGameControllerButton OFGameControllerButtonMinus = @"-";
const OFGameControllerButton OFGameControllerButtonSL = @"SL";
const OFGameControllerButton OFGameControllerButtonSR = @"SR";
const OFGameControllerButton OFGameControllerButtonMode = @"Mode";

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "platform/Linux/OFGameController.m"
#elif defined(OF_WINDOWS)
# include "platform/Windows/OFGameController.m"
#elif defined(OF_NINTENDO_DS)

Modified src/platform/Linux/OFGameController.m from [8a31fda877] to [a552f91d7e].

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
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"

static const uint16_t vendorIDNintendo = 0x057E;


static const uint16_t productIDN64Controller = 0x2019;

@interface OFGameController ()
- (instancetype)of_initWithPath: (OFString *)path OF_METHOD_FAMILY(init);
@end

static const uint16_t buttons[] = {
	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
};

static OFGameControllerButton
buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID)
{
	if (vendorID == vendorIDNintendo &&


























	    productID == productIDN64Controller) {
		switch (button) {
		case BTN_TL2:
			return OFGameControllerButtonZ;
		case BTN_Y:
			return OFGameControllerButtonCPadLeft;
		case BTN_C:







>
>
















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"

static const uint16_t vendorIDNintendo = 0x057E;
static const uint16_t productIDLeftJoycon = 0x2006;
static const uint16_t productIDRightJoycon = 0x2007;
static const uint16_t productIDN64Controller = 0x2019;

@interface OFGameController ()
- (instancetype)of_initWithPath: (OFString *)path OF_METHOD_FAMILY(init);
@end

static const uint16_t buttons[] = {
	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
};

static OFGameControllerButton
buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID)
{
	if (vendorID == vendorIDNintendo &&
	    productID == productIDLeftJoycon) {
		switch (button) {
		case BTN_SELECT:
			return OFGameControllerButtonMinus;
		case BTN_Z:
			return OFGameControllerButtonCapture;
		case BTN_TR:
			return OFGameControllerButtonSL;
		case BTN_TR2:
			return OFGameControllerButtonSR;
		}
	} else if (vendorID == vendorIDNintendo &&
	    productID == productIDRightJoycon) {
		switch (button) {
		case BTN_B:
			return OFGameControllerButtonA;
		case BTN_A:
			return OFGameControllerButtonB;
		case BTN_START:
			return OFGameControllerButtonPlus;
		case BTN_TL:
			return OFGameControllerButtonSL;
		case BTN_TL2:
			return OFGameControllerButtonSR;
		}
	} else if (vendorID == vendorIDNintendo &&
	    productID == productIDN64Controller) {
		switch (button) {
		case BTN_TL2:
			return OFGameControllerButtonZ;
		case BTN_Y:
			return OFGameControllerButtonCPadLeft;
		case BTN_C:
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
		if (!OFBitSetIsSet(evBits, EV_KEY))
			@throw [OFInvalidArgumentException exception];

		if (ioctl(_fd, EVIOCGBIT(EV_KEY, sizeof(keyBits)), keyBits) ==
		    -1)
			@throw [OFInitializationFailedException exception];

		if (!OFBitSetIsSet(keyBits, BTN_GAMEPAD))

			@throw [OFInvalidArgumentException exception];

		if (ioctl(_fd, EVIOCGID, &inputID) == -1)
			@throw [OFInvalidArgumentException exception];

		_vendorID = inputID.vendor;
		_productID = inputID.product;







|
>







239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
		if (!OFBitSetIsSet(evBits, EV_KEY))
			@throw [OFInvalidArgumentException exception];

		if (ioctl(_fd, EVIOCGBIT(EV_KEY, sizeof(keyBits)), keyBits) ==
		    -1)
			@throw [OFInitializationFailedException exception];

		if (!OFBitSetIsSet(keyBits, BTN_GAMEPAD) &&
		    !OFBitSetIsSet(keyBits, BTN_DPAD_UP))
			@throw [OFInvalidArgumentException exception];

		if (ioctl(_fd, EVIOCGID, &inputID) == -1)
			@throw [OFInvalidArgumentException exception];

		_vendorID = inputID.vendor;
		_productID = inputID.product;