ObjFW  Check-in [998339ff24]

Overview
Comment:OHGamepad: Move some elements to OHExtendedGamepad

This allows to have a profile for limited gamepads such as found on the
Nintendo DS rather than only having the raw profile for those.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 998339ff24279ce362e574bf382bacc9f3ea85057cdef6dfd28ee77bbfefd625
User & Date: js on 2024-06-09 11:43:49
Other Links: manifest | tags
Context
2024-06-09
11:51
Several fixes for the last commit check-in: fc2b668c57 user: js tags: trunk
11:43
OHGamepad: Move some elements to OHExtendedGamepad check-in: 998339ff24 user: js tags: trunk
11:17
ObjFWHID: Add OHCombinedJoyCons check-in: 1ba9cce376 user: js tags: trunk
Changes

Modified src/hid/Makefile from [c9eb22f3ea] to [68a99cecdd].

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
31
32
33
34
35
36
37
38
39
40
41
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		\

       OHGameController.m		\
       OHGameControllerAxis.m		\
       OHGameControllerButton.m		\
       OHGameControllerDirectionalPad.m	\
       OHGameControllerElement.m	\
       OHGameControllerProfile.m	\
       OHGamepad.m			\
       ${USE_SRCS_EVDEV}		\
       ${USE_SRCS_NINTENDO_3DS}		\
       ${USE_SRCS_NINTENDO_DS}		\
       ${USE_SRCS_XINPUT}
SRCS_EVDEV = OHEvdevDualSense.m			\
	     OHEvdevDualShock4.m		\

	     OHEvdevGameController.m		\
	     OHEvdevGamepad.m			\
	     OHEvdevPlayStationGamepad.m	\
	     OHEvdevStadiaGamepad.m
SRCS_NINTENDO_3DS = OHNintendo3DSGameController.m	\
		    OHNintendo3DSGamepad.m
SRCS_NINTENDO_DS = OHNintendoDSGameController.m
SRCS_XINPUT = OHXInputGameController.m	\
	      OHXInputGamepad.m

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

SRCS += OHGameControllerEmulatedAxis.m		\
	OHGameControllerEmulatedButton.m	\
	OHGameControllerEmulatedTriggerButton.m












>











|
|
>
|
<
|
|

|

|
|







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
31
32
33
34
35
36
37
38
39
40
41
42
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		\
       OHExtendedGamepad.m		\
       OHGameController.m		\
       OHGameControllerAxis.m		\
       OHGameControllerButton.m		\
       OHGameControllerDirectionalPad.m	\
       OHGameControllerElement.m	\
       OHGameControllerProfile.m	\
       OHGamepad.m			\
       ${USE_SRCS_EVDEV}		\
       ${USE_SRCS_NINTENDO_3DS}		\
       ${USE_SRCS_NINTENDO_DS}		\
       ${USE_SRCS_XINPUT}
SRCS_EVDEV = OHEvdevDualSense.m				\
	     OHEvdevDualShock4.m			\
	     OHEvdevExtendedGamepad.m			\
	     OHEvdevGameController.m			\

	     OHEvdevPlayStationExtendedGamepad.m	\
	     OHEvdevStadiaExtendedGamepad.m
SRCS_NINTENDO_3DS = OHNintendo3DSGameController.m	\
		    OHNintendo3DSExtendedGamepad.m
SRCS_NINTENDO_DS = OHNintendoDSGameController.m
SRCS_XINPUT = OHXInputExtendedGamepad.m	\
	      OHXInputGameController.m

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

SRCS += OHGameControllerEmulatedAxis.m		\
	OHGameControllerEmulatedButton.m	\
	OHGameControllerEmulatedTriggerButton.m

Modified src/hid/OHCombinedJoyCons.h from [8697cf7759] to [3b3290c60a].

20
21
22
23
24
25
26


27
28
29
30
31
32
33
#import "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@class OHGameController;

/**


 * @brief Combines a left and a right Joy-Con into a gamepad.
 */
@interface OHCombinedJoyCons: OHGamepad
{
	OHGameControllerProfile *_leftJoyCon, *_rightJoyCon;
}








>
>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#import "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@class OHGameController;

/**
 * @class OHCombinedJoyCons OHCombinedJoyCons.h ObjFWHID/OHCombinedJoyCons.h
 *
 * @brief Combines a left and a right Joy-Con into a gamepad.
 */
@interface OHCombinedJoyCons: OHGamepad
{
	OHGameControllerProfile *_leftJoyCon, *_rightJoyCon;
}

Modified src/hid/OHEvdevDualSense.h from [79e40a9eed] to [08dcd8d0d7].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHEvdevPlayStationGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHEvdevDualSense: OHEvdevPlayStationGamepad
@end

OF_ASSUME_NONNULL_END







|



|



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHEvdevPlayStationExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHEvdevDualSense: OHEvdevPlayStationExtendedGamepad
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHEvdevDualShock4.h from [0ed4cfaf34] to [95fc4e91aa].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHEvdevPlayStationGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHEvdevDualShock4: OHEvdevPlayStationGamepad
@end

OF_ASSUME_NONNULL_END







|



|



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHEvdevPlayStationExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHEvdevDualShock4: OHEvdevPlayStationExtendedGamepad
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/OHEvdevGamepad.h [f433593f5a] to src/hid/OHEvdevExtendedGamepad.h [6c2895c0ea].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * 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 "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@class OHEvdevGameController;
@class OHGameControllerProfile;

@interface OHEvdevGamepad: OHGamepad
{
	OHGameControllerProfile *_rawProfile;
}

- (instancetype)initWithController: (OHEvdevGameController *)controller;
@end








|






|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * 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 "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@class OHEvdevGameController;
@class OHGameControllerProfile;

@interface OHEvdevExtendedGamepad: OHExtendedGamepad
{
	OHGameControllerProfile *_rawProfile;
}

- (instancetype)initWithController: (OHEvdevGameController *)controller;
@end

Renamed and modified src/hid/OHEvdevGamepad.m [deafbe8df3] to src/hid/OHEvdevExtendedGamepad.m [f71df4684b].

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 * 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 "OHEvdevGamepad.h"
#import "OFDictionary.h"
#import "OHEvdevGameController.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerEmulatedTriggerButton.h"

#import "OFInvalidArgumentException.h"

@implementation OHEvdevGamepad
- (instancetype)initWithController: (OHEvdevGameController *)controller
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();








|







|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 * 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 "OHEvdevExtendedGamepad.h"
#import "OFDictionary.h"
#import "OHEvdevGameController.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerEmulatedTriggerButton.h"

#import "OFInvalidArgumentException.h"

@implementation OHEvdevExtendedGamepad
- (instancetype)initWithController: (OHEvdevGameController *)controller
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

Modified src/hid/OHEvdevGameController.m from [1aae3bc76f] to [c35ba635a9].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#import "OFDictionary.h"
#import "OFFileManager.h"
#import "OFLocale.h"
#import "OFNumber.h"

#import "OHEvdevDualSense.h"
#import "OHEvdevDualShock4.h"
#import "OHEvdevGamepad.h"
#import "OHEvdevStadiaGamepad.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerProfile.h"

#include <sys/ioctl.h>
#include <linux/input.h>








|
|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#import "OFDictionary.h"
#import "OFFileManager.h"
#import "OFLocale.h"
#import "OFNumber.h"

#import "OHEvdevDualSense.h"
#import "OHEvdevDualShock4.h"
#import "OHEvdevExtendedGamepad.h"
#import "OHEvdevStadiaExtendedGamepad.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerProfile.h"

#include <sys/ioctl.h>
#include <linux/input.h>

727
728
729
730
731
732
733





734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
			break;
		}
	}
}

- (OHGamepad *)gamepad
{





	@try {
		if (_vendorID == OHVendorIDSony &&
		    _productID == OHProductIDDualSense)
			return [[[OHEvdevDualSense alloc]
			    initWithController: self] autorelease];
		else if (_vendorID == OHVendorIDSony &&
		    _productID == OHProductIDDualShock4)
			return [[[OHEvdevDualShock4 alloc]
			    initWithController: self] autorelease];
		else if (_vendorID == OHVendorIDGoogle &&
		    _productID == OHProductIDStadiaController)
			return [[[OHEvdevStadiaGamepad alloc]
			    initWithController: self] autorelease];
		else
			return [[[OHEvdevGamepad alloc]
			    initWithController: self] autorelease];
	} @catch (OFInvalidArgumentException *e) {
		return nil;
	}
}

- (OFComparisonResult)compare: (OHEvdevGameController *)otherController







>
>
>
>
>











|


|







727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
			break;
		}
	}
}

- (OHGamepad *)gamepad
{
	return self.extendedGamepad;
}

- (OHExtendedGamepad *)extendedGamepad
{
	@try {
		if (_vendorID == OHVendorIDSony &&
		    _productID == OHProductIDDualSense)
			return [[[OHEvdevDualSense alloc]
			    initWithController: self] autorelease];
		else if (_vendorID == OHVendorIDSony &&
		    _productID == OHProductIDDualShock4)
			return [[[OHEvdevDualShock4 alloc]
			    initWithController: self] autorelease];
		else if (_vendorID == OHVendorIDGoogle &&
		    _productID == OHProductIDStadiaController)
			return [[[OHEvdevStadiaExtendedGamepad alloc]
			    initWithController: self] autorelease];
		else
			return [[[OHEvdevExtendedGamepad alloc]
			    initWithController: self] autorelease];
	} @catch (OFInvalidArgumentException *e) {
		return nil;
	}
}

- (OFComparisonResult)compare: (OHEvdevGameController *)otherController

Renamed and modified src/hid/OHEvdevPlayStationGamepad.h [db950effb0] to src/hid/OHEvdevPlayStationExtendedGamepad.h [09600485c0].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHEvdevGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHEvdevPlayStationGamepad: OHEvdevGamepad
@end

OF_ASSUME_NONNULL_END







|



|



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHEvdevExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHEvdevPlayStationExtendedGamepad: OHEvdevExtendedGamepad
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/OHEvdevPlayStationGamepad.m [66dec8d718] to src/hid/OHEvdevPlayStationExtendedGamepad.m [0482667023].

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 * 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 "OHEvdevPlayStationGamepad.h"
#import "OFDictionary.h"
#import "OHGameControllerEmulatedTriggerButton.h"

@implementation OHEvdevPlayStationGamepad
- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons
{
	OFMutableDictionary *buttons =
	    [[_rawProfile.buttons mutableCopy] autorelease];

	[buttons setObject: self.leftTriggerButton forKey: @"L2"];
	[buttons setObject: self.rightTriggerButton forKey: @"R2"];







|



|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 * 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 "OHEvdevPlayStationExtendedGamepad.h"
#import "OFDictionary.h"
#import "OHGameControllerEmulatedTriggerButton.h"

@implementation OHEvdevPlayStationExtendedGamepad
- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons
{
	OFMutableDictionary *buttons =
	    [[_rawProfile.buttons mutableCopy] autorelease];

	[buttons setObject: self.leftTriggerButton forKey: @"L2"];
	[buttons setObject: self.rightTriggerButton forKey: @"R2"];

Renamed and modified src/hid/OHEvdevStadiaGamepad.h [0e795b0f7a] to src/hid/OHEvdevStadiaExtendedGamepad.h [f8d23d688f].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHEvdevGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHEvdevStadiaGamepad: OHEvdevGamepad
@end

OF_ASSUME_NONNULL_END







|



|



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHEvdevExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHEvdevStadiaExtendedGamepad: OHEvdevExtendedGamepad
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/OHEvdevStadiaGamepad.m [5fd88a7d3a] to src/hid/OHEvdevStadiaExtendedGamepad.m [9baf34190b].

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 * 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 "OHEvdevStadiaGamepad.h"
#import "OFDictionary.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerEmulatedTriggerButton.h"

@implementation OHEvdevStadiaGamepad
- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons
{
	OFMutableDictionary *buttons =
	    [[_rawProfile.buttons mutableCopy] autorelease];

	[buttons setObject: self.leftTriggerButton forKey: @"L2"];
	[buttons setObject: self.rightTriggerButton forKey: @"R2"];







|





|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 * 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 "OHEvdevStadiaExtendedGamepad.h"
#import "OFDictionary.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerEmulatedTriggerButton.h"

@implementation OHEvdevStadiaExtendedGamepad
- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons
{
	OFMutableDictionary *buttons =
	    [[_rawProfile.buttons mutableCopy] autorelease];

	[buttons setObject: self.leftTriggerButton forKey: @"L2"];
	[buttons setObject: self.rightTriggerButton forKey: @"R2"];

Added src/hid/OHExtendedGamepad.h version [921dcc6b86].































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3.0 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * 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 "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OHExtendedGamepad OHExtendedGamepad.h ObjFWHID/OHExtendedGamepad.h
 *
 * @brief A game controller profile representing a gamepad.
 */
@interface OHExtendedGamepad: OHGamepad
{
	OF_RESERVE_IVARS(OHExtendedGamepad, 4)
}

/**
 * @brief The left trigger button.
 */
@property (readonly, nonatomic) OHGameControllerButton *leftTriggerButton;

/**
 * @brief The right trigger button.
 */
@property (readonly, nonatomic) OHGameControllerButton *rightTriggerButton;

/**
 * @brief The left thumb stick button.
 *
 * This button is optional and may be `nil`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OHGameControllerButton *leftThumbstickButton;

/**
 * @brief The right thumb stick button.
 *
 * This button is optional and may be `nil`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OHGameControllerButton *rightThumbstickButton;

/**
 * @brief The home button.
 *
 * This button is optional and may be `nil`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OHGameControllerButton *homeButton;

/**
 * @brief The left thumb stick.
 */
@property (readonly, nonatomic) OHGameControllerDirectionalPad *leftThumbstick;

/**
 * @brief The right thumb stick.
 */
@property (readonly, nonatomic) OHGameControllerDirectionalPad *rightThumbstick;
@end

OF_ASSUME_NONNULL_END

Added src/hid/OHExtendedGamepad.m version [d21610a1a5].





















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3.0 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * 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/>.
 */

#include "config.h"

#import "OHExtendedGamepad.h"

@implementation OHExtendedGamepad
@dynamic leftTriggerButton, rightTriggerButton, leftThumbstick, rightThumbstick;
@dynamic dPad;

- (OHGameControllerButton *)leftThumbstickButton
{
	return nil;
}

- (OHGameControllerButton *)rightThumbstickButton
{
	return nil;
}

- (OHGameControllerButton *)homeButton
{
	return nil;
}
@end

Modified src/hid/OHGameController.h from [993476fab8] to [805ad805e2].

29
30
31
32
33
34
35

36
37
38
39
40
41
42
# endif
#endif

OF_ASSUME_NONNULL_BEGIN

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

@class OHGameControllerProfile;
@class OHGamepad;

/**
 * @class OHGameController OHGameController.h ObjFWHID/OHGameController.h
 *
 * @brief A class for reading state from a game controller.







>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# endif
#endif

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFNumber;
@class OHExtendedGamepad;
@class OHGameControllerProfile;
@class OHGamepad;

/**
 * @class OHGameController OHGameController.h ObjFWHID/OHGameController.h
 *
 * @brief A class for reading state from a game controller.
74
75
76
77
78
79
80







81
82
83
84
85
86
87

/**
 * @brief The gamepad profile for the game controller, or `nil` if not
 *	  supported.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OHGamepad *gamepad;








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








>
>
>
>
>
>
>







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

/**
 * @brief The gamepad profile for the game controller, or `nil` if not
 *	  supported.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OHGamepad *gamepad;

/**
 * @brief The extended gamepad profile for the game controller, or `nil` if not
 *	  supported.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OHExtendedGamepad *extendedGamepad;

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

Modified src/hid/OHGameController.m from [65e834b561] to [3129705f22].

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#include "config.h"

#import "OHGameController.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFSet.h"
#import "OHGamepad.h"

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# import "OHEvdevGameController.h"
#endif
#ifdef OF_WINDOWS
# import "OHXInputGameController.h"
#endif







<







19
20
21
22
23
24
25

26
27
28
29
30
31
32

#include "config.h"

#import "OHGameController.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFSet.h"


#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# import "OHEvdevGameController.h"
#endif
#ifdef OF_WINDOWS
# import "OHXInputGameController.h"
#endif
95
96
97
98
99
100
101





102
103
104
105
106
107
108
- (void)retrieveState
{
	OF_UNRECOGNIZED_SELECTOR
}

- (OHGamepad *)gamepad
{





	return nil;
}

- (OFString *)description
{
	if (self.vendorID != nil && self.productID != nil)
		return [OFString stringWithFormat:







>
>
>
>
>







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
- (void)retrieveState
{
	OF_UNRECOGNIZED_SELECTOR
}

- (OHGamepad *)gamepad
{
	return nil;
}

- (OHExtendedGamepad *)extendedGamepad
{
	return nil;
}

- (OFString *)description
{
	if (self.vendorID != nil && self.productID != nil)
		return [OFString stringWithFormat:

Modified src/hid/OHGamepad.h from [7b0ca0845a] to [a630442063].

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@property (readonly, nonatomic) OHGameControllerButton *leftShoulderButton;

/**
 * @brief The right shoulder button.
 */
@property (readonly, nonatomic) OHGameControllerButton *rightShoulderButton;

/**
 * @brief The left trigger button.
 */
@property (readonly, nonatomic) OHGameControllerButton *leftTriggerButton;

/**
 * @brief The right trigger button.
 */
@property (readonly, nonatomic) OHGameControllerButton *rightTriggerButton;

/**
 * @brief The left thumb stick button.
 *
 * This button is optional and may be `nil`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OHGameControllerButton *leftThumbstickButton;

/**
 * @brief The right thumb stick button.
 *
 * This button is optional and may be `nil`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OHGameControllerButton *rightThumbstickButton;

/**
 * @brief The menu button, sometimes also called start button.
 */
@property (readonly, nonatomic) OHGameControllerButton *menuButton;

/**
 * @brief The options button, sometimes also called select button.
 */
@property (readonly, nonatomic) OHGameControllerButton *optionsButton;

/**
 * @brief The home button.
 *
 * This button is optional and may be `nil`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OHGameControllerButton *homeButton;

/**
 * @brief The left thumb stick.
 */
@property (readonly, nonatomic) OHGameControllerDirectionalPad *leftThumbstick;

/**
 * @brief The right thumb stick.
 */
@property (readonly, nonatomic) OHGameControllerDirectionalPad *rightThumbstick;

/**
 * @brief The D-Pad.
 */
@property (readonly, nonatomic) OHGameControllerDirectionalPad *dPad;
@end

OF_ASSUME_NONNULL_END







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







57
58
59
60
61
62
63


























64
65
66
67
68
69
70
71
72
73


















74
75
76
77
78
79
80
@property (readonly, nonatomic) OHGameControllerButton *leftShoulderButton;

/**
 * @brief The right shoulder button.
 */
@property (readonly, nonatomic) OHGameControllerButton *rightShoulderButton;



























/**
 * @brief The menu button, sometimes also called start button.
 */
@property (readonly, nonatomic) OHGameControllerButton *menuButton;

/**
 * @brief The options button, sometimes also called select button.
 */
@property (readonly, nonatomic) OHGameControllerButton *optionsButton;



















/**
 * @brief The D-Pad.
 */
@property (readonly, nonatomic) OHGameControllerDirectionalPad *dPad;
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHGamepad.m from [704651d399] to [872795b145].

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

#include "config.h"

#import "OHGamepad.h"

@implementation OHGamepad
@dynamic northButton, southButton, westButton, eastButton, leftShoulderButton;
@dynamic rightShoulderButton, leftTriggerButton, rightTriggerButton;
@dynamic menuButton, optionsButton, leftThumbstick, rightThumbstick, dPad;

- (OHGameControllerButton *)leftThumbstickButton
{
	return nil;
}

- (OHGameControllerButton *)rightThumbstickButton
{
	return nil;
}

- (OHGameControllerButton *)homeButton
{
	return nil;
}
@end







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

19
20
21
22
23
24
25
26
















27

#include "config.h"

#import "OHGamepad.h"

@implementation OHGamepad
@dynamic northButton, southButton, westButton, eastButton, leftShoulderButton;
@dynamic rightShoulderButton, menuButton, optionsButton, dPad;
















@end

Renamed and modified src/hid/OHNintendo3DSGamepad.h [048d54d1d0] to src/hid/OHNintendo3DSExtendedGamepad.h [3b15d599d3].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHNintendo3DSGamepad: OHGamepad
@end

OF_ASSUME_NONNULL_END







|



|



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHNintendo3DSExtendedGamepad: OHExtendedGamepad
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/OHNintendo3DSGamepad.m [1b3ca013dd] to src/hid/OHNintendo3DSExtendedGamepad.m [d5489dc9dd].

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

static OFString *const buttonNames[] = {
	@"A", @"B", @"X", @"Y", @"L", @"R", @"ZL", @"ZR", @"Start", @"Select"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);

@implementation OHNintendo3DSGamepad
- (instancetype)init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =







|










|







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

static OFString *const buttonNames[] = {
	@"A", @"B", @"X", @"Y", @"L", @"R", @"ZL", @"ZR", @"Start", @"Select"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);

@implementation OHNintendo3DSExtendedGamepad
- (instancetype)init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =

Modified src/hid/OHNintendo3DSGameController.h from [938beb87f9] to [a76f031e8d].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * <https://www.gnu.org/licenses/>.
 */

#import "OHGameController.h"

OF_ASSUME_NONNULL_BEGIN

@class OHNintendo3DSGamepad;

@interface OHNintendo3DSGameController: OHGameController
{
	OHNintendo3DSGamepad *_gamepad;
}
@end

OF_ASSUME_NONNULL_END







|



|




17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * <https://www.gnu.org/licenses/>.
 */

#import "OHGameController.h"

OF_ASSUME_NONNULL_BEGIN

@class OHNintendo3DSExtendedGamepad;

@interface OHNintendo3DSGameController: OHGameController
{
	OHNintendo3DSExtendedGamepad *_extendedGamepad;
}
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHNintendo3DSGameController.m from [4800c3c390] to [01ae2ef5f1].

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
#import "OHNintendo3DSGameController.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHNintendo3DSGamepad.h"

#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"

#define id id_3ds
#include <3ds.h>
#undef id

static OFArray OF_GENERIC(OHGameController *) *controllers;

@implementation OHNintendo3DSGameController
@synthesize gamepad = _gamepad;

+ (void)initialize
{
	void *pool;

	if (self != [OHNintendo3DSGameController class])
		return;







|











|







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
#import "OHNintendo3DSGameController.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHNintendo3DSExtendedGamepad.h"

#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"

#define id id_3ds
#include <3ds.h>
#undef id

static OFArray OF_GENERIC(OHGameController *) *controllers;

@implementation OHNintendo3DSGameController
@synthesize extendedGamepad = _extendedGamepad;

+ (void)initialize
{
	void *pool;

	if (self != [OHNintendo3DSGameController class])
		return;
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143





144
}

- (instancetype)init
{
	self = [super init];

	@try {
		_gamepad = [[OHNintendo3DSGamepad alloc] init];

		[self retrieveState];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_gamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	u32 keys;
	circlePosition leftPos, rightPos;

	hidScanInput();

	keys = hidKeysHeld();
	hidCircleRead(&leftPos);
	hidCstickRead(&rightPos);

	[_gamepad.northButton setValue: !!(keys & KEY_X)];
	[_gamepad.southButton setValue: !!(keys & KEY_B)];
	[_gamepad.westButton setValue: !!(keys & KEY_Y)];
	[_gamepad.eastButton setValue: !!(keys & KEY_A)];
	[_gamepad.leftShoulderButton setValue: !!(keys & KEY_L)];
	[_gamepad.rightShoulderButton setValue: !!(keys & KEY_R)];
	[_gamepad.leftTriggerButton setValue: !!(keys & KEY_ZL)];
	[_gamepad.rightTriggerButton setValue: !!(keys & KEY_ZR)];
	[_gamepad.menuButton setValue: !!(keys & KEY_START)];
	[_gamepad.optionsButton setValue: !!(keys & KEY_SELECT)];

	if (leftPos.dx > 150)
		leftPos.dx = 150;
	if (leftPos.dx < -150)
		leftPos.dx = -150;
	if (leftPos.dy > 150)
		leftPos.dy = 150;
	if (leftPos.dy < -150)
		leftPos.dy = -150;

	if (rightPos.dx > 150)
		rightPos.dx = 150;
	if (rightPos.dx < -150)
		rightPos.dx = -150;
	if (rightPos.dy > 150)
		rightPos.dy = 150;
	if (rightPos.dy < -150)
		rightPos.dy = -150;

	_gamepad.leftThumbstick.xAxis.value = (float)leftPos.dx / 150;
	_gamepad.leftThumbstick.yAxis.value = -(float)leftPos.dy / 150;
	_gamepad.rightThumbstick.xAxis.value = (float)rightPos.dx / 150;
	_gamepad.rightThumbstick.yAxis.value = -(float)rightPos.dy / 150;


	[_gamepad.dPad.up setValue: !!(keys & KEY_DUP)];
	[_gamepad.dPad.down setValue: !!(keys & KEY_DDOWN)];
	[_gamepad.dPad.left setValue: !!(keys & KEY_DLEFT)];
	[_gamepad.dPad.right setValue: !!(keys & KEY_DRIGHT)];
}

- (OFString *)name
{
	return @"Nintendo 3DS";
}

- (OHGameControllerProfile *)rawProfile
{
	return _gamepad;
}





@end







|












|















|
|
|
|
|
|
|
|
|
|



















|
|
|
|
>

|
|
|
|









|

>
>
>
>
>

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
}

- (instancetype)init
{
	self = [super init];

	@try {
		_extendedGamepad = [[OHNintendo3DSExtendedGamepad alloc] init];

		[self retrieveState];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_extendedGamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	u32 keys;
	circlePosition leftPos, rightPos;

	hidScanInput();

	keys = hidKeysHeld();
	hidCircleRead(&leftPos);
	hidCstickRead(&rightPos);

	[_extendedGamepad.northButton setValue: !!(keys & KEY_X)];
	[_extendedGamepad.southButton setValue: !!(keys & KEY_B)];
	[_extendedGamepad.westButton setValue: !!(keys & KEY_Y)];
	[_extendedGamepad.eastButton setValue: !!(keys & KEY_A)];
	[_extendedGamepad.leftShoulderButton setValue: !!(keys & KEY_L)];
	[_extendedGamepad.rightShoulderButton setValue: !!(keys & KEY_R)];
	[_extendedGamepad.leftTriggerButton setValue: !!(keys & KEY_ZL)];
	[_extendedGamepad.rightTriggerButton setValue: !!(keys & KEY_ZR)];
	[_extendedGamepad.menuButton setValue: !!(keys & KEY_START)];
	[_extendedGamepad.optionsButton setValue: !!(keys & KEY_SELECT)];

	if (leftPos.dx > 150)
		leftPos.dx = 150;
	if (leftPos.dx < -150)
		leftPos.dx = -150;
	if (leftPos.dy > 150)
		leftPos.dy = 150;
	if (leftPos.dy < -150)
		leftPos.dy = -150;

	if (rightPos.dx > 150)
		rightPos.dx = 150;
	if (rightPos.dx < -150)
		rightPos.dx = -150;
	if (rightPos.dy > 150)
		rightPos.dy = 150;
	if (rightPos.dy < -150)
		rightPos.dy = -150;

	_extendedGamepad.leftThumbstick.xAxis.value = (float)leftPos.dx / 150;
	_extendedGamepad.leftThumbstick.yAxis.value = -(float)leftPos.dy / 150;
	_extendedGamepad.rightThumbstick.xAxis.value = (float)rightPos.dx / 150;
	_extendedGamepad.rightThumbstick.yAxis.value =
	    -(float)rightPos.dy / 150;

	[_extendedGamepad.dPad.up setValue: !!(keys & KEY_DUP)];
	[_extendedGamepad.dPad.down setValue: !!(keys & KEY_DDOWN)];
	[_extendedGamepad.dPad.left setValue: !!(keys & KEY_DLEFT)];
	[_extendedGamepad.dPad.right setValue: !!(keys & KEY_DRIGHT)];
}

- (OFString *)name
{
	return @"Nintendo 3DS";
}

- (OHGameControllerProfile *)rawProfile
{
	return _extendedGamepad;
}

- (OHGamepad *)gamepad
{
	return _extendedGamepad;
}
@end

Renamed and modified src/hid/OHXInputGamepad.h [2938c0d988] to src/hid/OHXInputExtendedGamepad.h [137e523e2b].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHXInputGamepad: OHGamepad
@end

OF_ASSUME_NONNULL_END







|



|



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * 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 "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHXInputExtendedGamepad: OHExtendedGamepad
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/hid/OHXInputGamepad.m [f110678448] to src/hid/OHXInputExtendedGamepad.m [3e95130dc5].

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/>.
 */

#include "config.h"

#import "OHXInputGamepad.h"
#import "OFDictionary.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHXInputGameController.h"

static OFString *const buttonNames[] = {
	@"A", @"B", @"X", @"Y", @"LB", @"RB", @"LT", @"RT", @"LSB", @"RSB",
	@"Start", @"Back", @"Guide"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);

@implementation OHXInputGamepad
- (instancetype)init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =







|












|







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/>.
 */

#include "config.h"

#import "OHXInputExtendedGamepad.h"
#import "OFDictionary.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHXInputGameController.h"

static OFString *const buttonNames[] = {
	@"A", @"B", @"X", @"Y", @"LB", @"RB", @"LT", @"RT", @"LSB", @"RSB",
	@"Start", @"Back", @"Guide"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);

@implementation OHXInputExtendedGamepad
- (instancetype)init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =

Modified src/hid/OHXInputGameController.h from [ea7d06ddf4] to [ad658e8625].

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#import "OHGameController.h"

#include <windows.h>

OF_ASSUME_NONNULL_BEGIN

@class OHXInputGamepad;

@interface OHXInputGameController: OHGameController
{
	DWORD _index;
	OFNumber *_Nullable _vendorID, *_Nullable _productID;
	OHXInputGamepad *_gamepad;
}

- (instancetype)oh_initWithIndex: (DWORD)index OF_METHOD_FAMILY(init);
@end

#ifdef __cplusplus
extern "C" {







|





|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#import "OHGameController.h"

#include <windows.h>

OF_ASSUME_NONNULL_BEGIN

@class OHXInputExtendedGamepad;

@interface OHXInputGameController: OHGameController
{
	DWORD _index;
	OFNumber *_Nullable _vendorID, *_Nullable _productID;
	OHXInputExtendedGamepad *_extendedGamepad;
}

- (instancetype)oh_initWithIndex: (DWORD)index OF_METHOD_FAMILY(init);
@end

#ifdef __cplusplus
extern "C" {

Modified src/hid/OHXInputGameController.m from [c422cbe7b4] to [7c14afb2ff].

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "OHXInputGameController.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHXInputGamepad.h"

#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"

#include <xinput.h>

#ifndef XINPUT_GAMEPAD_GUIDE







|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "OHXInputGameController.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHXInputExtendedGamepad.h"

#import "OFInitializationFailedException.h"
#import "OFReadFailedException.h"

#include <xinput.h>

#ifndef XINPUT_GAMEPAD_GUIDE
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62

int OHXInputVersion;
static WINAPI DWORD (*XInputGetStateFuncPtr)(DWORD, XINPUT_STATE *);
static WINAPI DWORD (*XInputGetCapabilitiesExFuncPtr)(DWORD, DWORD, DWORD,
    struct XInputCapabilitiesEx *);

@implementation OHXInputGameController
@synthesize vendorID = _vendorID, productID = _productID, gamepad = _gamepad;


+ (void)initialize
{
	HMODULE module;

	if (self != [OHXInputGameController class])
		return;







|
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

int OHXInputVersion;
static WINAPI DWORD (*XInputGetStateFuncPtr)(DWORD, XINPUT_STATE *);
static WINAPI DWORD (*XInputGetCapabilitiesExFuncPtr)(DWORD, DWORD, DWORD,
    struct XInputCapabilitiesEx *);

@implementation OHXInputGameController
@synthesize vendorID = _vendorID, productID = _productID;
@synthesize extendedGamepad = _extendedGamepad;

+ (void)initialize
{
	HMODULE module;

	if (self != [OHXInputGameController class])
		return;
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241





242
				    capabilities.vendorID];
				_productID = [[OFNumber alloc]
				    initWithUnsignedShort:
				    capabilities.productID];
			}
		}

		_gamepad = [[OHXInputGamepad alloc] init];

		[self retrieveState];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_vendorID release];
	[_productID release];
	[_gamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	XINPUT_STATE state = { 0 };

	if (XInputGetStateFuncPtr(_index, &state) != ERROR_SUCCESS)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: sizeof(state)
							    errNo: 0];

	_gamepad.northButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y);
	_gamepad.southButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_A);
	_gamepad.westButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_X);
	_gamepad.eastButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_B);
	_gamepad.leftShoulderButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
	_gamepad.rightShoulderButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
	_gamepad.leftThumbstickButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
	_gamepad.rightThumbstickButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
	_gamepad.menuButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_START);
	_gamepad.optionsButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK);
	if (OHXInputVersion != 910)
		_gamepad.homeButton.value =
		    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE);

	_gamepad.leftTriggerButton.value =
	    (float)state.Gamepad.bLeftTrigger / 255;
	_gamepad.rightTriggerButton.value =
	    (float)state.Gamepad.bRightTrigger / 255;

	_gamepad.leftThumbstick.xAxis.value =
	    (float)state.Gamepad.sThumbLX /
	    (state.Gamepad.sThumbLX < 0 ? -INT16_MIN : INT16_MAX);
	_gamepad.leftThumbstick.yAxis.value =
	    -(float)state.Gamepad.sThumbLY /
	    (state.Gamepad.sThumbLY < 0 ? -INT16_MIN : INT16_MAX);
	_gamepad.rightThumbstick.xAxis.value =
	    (float)state.Gamepad.sThumbRX /
	    (state.Gamepad.sThumbRX < 0 ? -INT16_MIN : INT16_MAX);
	_gamepad.rightThumbstick.yAxis.value =
	    -(float)state.Gamepad.sThumbRY /
	    (state.Gamepad.sThumbRY < 0 ? -INT16_MIN : INT16_MAX);

	_gamepad.dPad.up.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP);
	_gamepad.dPad.down.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
	_gamepad.dPad.left.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
	_gamepad.dPad.right.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
}

- (OFString *)name
{
	switch (OHXInputVersion) {
	case 14:
		return @"XInput 1.4 device";
	case 13:
		return @"XInput 1.3 device";
	case 910:
		return @"XInput 9.1.0 device";
	}

	return nil;
}

- (OHGameControllerProfile *)rawProfile
{
	return _gamepad;
}





@end







|














|













|

|

|

|

|

|

|

|

|

|


|


|

|


|


|


|


|



|

|

|

|



















|

>
>
>
>
>

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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
218
219
220
221
222
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
				    capabilities.vendorID];
				_productID = [[OFNumber alloc]
				    initWithUnsignedShort:
				    capabilities.productID];
			}
		}

		_extendedGamepad = [[OHXInputExtendedGamepad alloc] init];

		[self retrieveState];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_vendorID release];
	[_productID release];
	[_extendedGamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	XINPUT_STATE state = { 0 };

	if (XInputGetStateFuncPtr(_index, &state) != ERROR_SUCCESS)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: sizeof(state)
							    errNo: 0];

	_extendedGamepad.northButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y);
	_extendedGamepad.southButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_A);
	_extendedGamepad.westButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_X);
	_extendedGamepad.eastButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_B);
	_extendedGamepad.leftShoulderButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
	_extendedGamepad.rightShoulderButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
	_extendedGamepad.leftThumbstickButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
	_extendedGamepad.rightThumbstickButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
	_extendedGamepad.menuButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_START);
	_extendedGamepad.optionsButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK);
	if (OHXInputVersion != 910)
		_extendedGamepad.homeButton.value =
		    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE);

	_extendedGamepad.leftTriggerButton.value =
	    (float)state.Gamepad.bLeftTrigger / 255;
	_extendedGamepad.rightTriggerButton.value =
	    (float)state.Gamepad.bRightTrigger / 255;

	_extendedGamepad.leftThumbstick.xAxis.value =
	    (float)state.Gamepad.sThumbLX /
	    (state.Gamepad.sThumbLX < 0 ? -INT16_MIN : INT16_MAX);
	_extendedGamepad.leftThumbstick.yAxis.value =
	    -(float)state.Gamepad.sThumbLY /
	    (state.Gamepad.sThumbLY < 0 ? -INT16_MIN : INT16_MAX);
	_extendedGamepad.rightThumbstick.xAxis.value =
	    (float)state.Gamepad.sThumbRX /
	    (state.Gamepad.sThumbRX < 0 ? -INT16_MIN : INT16_MAX);
	_extendedGamepad.rightThumbstick.yAxis.value =
	    -(float)state.Gamepad.sThumbRY /
	    (state.Gamepad.sThumbRY < 0 ? -INT16_MIN : INT16_MAX);

	_extendedGamepad.dPad.up.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP);
	_extendedGamepad.dPad.down.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
	_extendedGamepad.dPad.left.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
	_extendedGamepad.dPad.right.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
}

- (OFString *)name
{
	switch (OHXInputVersion) {
	case 14:
		return @"XInput 1.4 device";
	case 13:
		return @"XInput 1.3 device";
	case 910:
		return @"XInput 9.1.0 device";
	}

	return nil;
}

- (OHGameControllerProfile *)rawProfile
{
	return _extendedGamepad;
}

- (OHGamepad *)gamepad
{
	return _extendedGamepad;
}
@end

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

15
16
17
18
19
20
21
22
23
24




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











|
|

>
>
>
>
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * 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 "OHGameController.h"
#import "OHGameControllerElement.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerProfile.h"
#import "OHGamepad.h"
#import "OHExtendedGamepad.h"
#import "OHCombinedJoyCons.h"