Index: src/hid/Makefile
==================================================================
--- src/hid/Makefile
+++ src/hid/Makefile
@@ -18,13 +18,15 @@
OHGamepad.m \
${USE_SRCS_EVDEV} \
${USE_SRCS_NINTENDO_3DS} \
${USE_SRCS_NINTENDO_DS} \
${USE_SRCS_XINPUT}
-SRCS_EVDEV = OHEvdevDualSense.m \
- OHEvdevGameController.m \
- OHEvdevGamepad.m
+SRCS_EVDEV = OHEvdevDualSense.m \
+ OHEvdevDualShock4.m \
+ OHEvdevGameController.m \
+ OHEvdevGamepad.m \
+ OHEvdevPlayStationGamepad.m
SRCS_NINTENDO_3DS = OHNintendo3DSGameController.m \
OHNintendo3DSGamepad.m
SRCS_NINTENDO_DS = OHNintendoDSGameController.m
SRCS_XINPUT = OHXInputGameController.m \
OHXInputGamepad.m
Index: src/hid/OHEvdevDualSense.h
==================================================================
--- src/hid/OHEvdevDualSense.h
+++ src/hid/OHEvdevDualSense.h
@@ -15,13 +15,13 @@
* You should have received a copy of the GNU Lesser General Public License
* version 3.0 along with this program. If not, see
* .
*/
-#import "OHEvdevGamepad.h"
+#import "OHEvdevPlayStationGamepad.h"
OF_ASSUME_NONNULL_BEGIN
-@interface OHEvdevDualSense: OHEvdevGamepad
+@interface OHEvdevDualSense: OHEvdevPlayStationGamepad
@end
OF_ASSUME_NONNULL_END
Index: src/hid/OHEvdevDualSense.m
==================================================================
--- src/hid/OHEvdevDualSense.m
+++ src/hid/OHEvdevDualSense.m
@@ -19,92 +19,12 @@
#include "config.h"
#import "OHEvdevDualSense.h"
#import "OFDictionary.h"
-#import "OHGameControllerEmulatedTriggerButton.h"
-
-#import "OFInvalidArgumentException.h"
@implementation OHEvdevDualSense
-- (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons
-{
- OFMutableDictionary *buttons =
- [[_rawProfile.buttons mutableCopy] autorelease];
-
- [buttons setObject: self.leftTriggerButton forKey: @"L2"];
- [buttons setObject: self.rightTriggerButton forKey: @"R2"];
-
- [buttons makeImmutable];
-
- return buttons;
-}
-
-- (OHGameControllerButton *)northButton
-{
- return [_rawProfile.buttons objectForKey: @"Triangle"];
-}
-
-- (OHGameControllerButton *)southButton
-{
- return [_rawProfile.buttons objectForKey: @"Cross"];
-}
-
-- (OHGameControllerButton *)westButton
-{
- return [_rawProfile.buttons objectForKey: @"Square"];
-}
-
-- (OHGameControllerButton *)eastButton
-{
- return [_rawProfile.buttons objectForKey: @"Circle"];
-}
-
-- (OHGameControllerButton *)leftShoulderButton
-{
- return [_rawProfile.buttons objectForKey: @"L1"];
-}
-
-- (OHGameControllerButton *)leftTriggerButton
-{
- return [[[OHGameControllerEmulatedTriggerButton alloc]
- initWithName: @"L2"
- axis: [_rawProfile.axes objectForKey: @"Z"]] autorelease];
-}
-
-- (OHGameControllerButton *)rightTriggerButton
-{
- return [[[OHGameControllerEmulatedTriggerButton alloc]
- initWithName: @"R2"
- axis: [_rawProfile.axes objectForKey: @"RZ"]] autorelease];
-}
-
-- (OHGameControllerButton *)rightShoulderButton
-{
- return [_rawProfile.buttons objectForKey: @"R1"];
-}
-
-- (OHGameControllerButton *)leftThumbstickButton
-{
- return [_rawProfile.buttons objectForKey: @"L3"];
-}
-
-- (OHGameControllerButton *)rightThumbstickButton
-{
- return [_rawProfile.buttons objectForKey: @"R3"];
-}
-
-- (OHGameControllerButton *)menuButton
-{
- return [_rawProfile.buttons objectForKey: @"Options"];
-}
-
- (OHGameControllerButton *)optionsButton
{
return [_rawProfile.buttons objectForKey: @"Create"];
}
-
-- (OHGameControllerButton *)homeButton
-{
- return [_rawProfile.buttons objectForKey: @"PS"];
-}
@end
ADDED src/hid/OHEvdevDualShock4.h
Index: src/hid/OHEvdevDualShock4.h
==================================================================
--- /dev/null
+++ src/hid/OHEvdevDualShock4.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2008-2024 Jonathan Schleifer
+ *
+ * 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
+ * .
+ */
+
+#import "OHEvdevPlayStationGamepad.h"
+
+OF_ASSUME_NONNULL_BEGIN
+
+@interface OHEvdevDualShock4: OHEvdevPlayStationGamepad
+@end
+
+OF_ASSUME_NONNULL_END
ADDED src/hid/OHEvdevDualShock4.m
Index: src/hid/OHEvdevDualShock4.m
==================================================================
--- /dev/null
+++ src/hid/OHEvdevDualShock4.m
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2008-2024 Jonathan Schleifer
+ *
+ * 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
+ * .
+ */
+
+#include "config.h"
+
+#import "OHEvdevDualShock4.h"
+#import "OFDictionary.h"
+
+@implementation OHEvdevDualShock4
+- (OHGameControllerButton *)optionsButton
+{
+ return [_rawProfile.buttons objectForKey: @"Share"];
+}
+@end
Index: src/hid/OHEvdevGameController.m
==================================================================
--- src/hid/OHEvdevGameController.m
+++ src/hid/OHEvdevGameController.m
@@ -30,10 +30,11 @@
#import "OFFileManager.h"
#import "OFLocale.h"
#import "OFNumber.h"
#import "OHEvdevDualSense.h"
+#import "OHEvdevDualShock4.h"
#import "OHEvdevGamepad.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerProfile.h"
@@ -84,11 +85,12 @@
};
static OFString *
buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID)
{
- if (vendorID == OHVendorIDSony && productID == OHProductIDDualSense) {
+ if (vendorID == OHVendorIDSony && (productID == OHProductIDDualSense ||
+ productID == OHProductIDDualShock4)) {
switch (button) {
case BTN_NORTH:
return @"Triangle";
case BTN_SOUTH:
return @"Cross";
@@ -108,16 +110,21 @@
return @"L3";
case BTN_THUMBR:
return @"R3";
case BTN_START:
return @"Options";
- case BTN_SELECT:
- return @"Create";
case BTN_MODE:
return @"PS";
}
}
+
+ if (vendorID == OHVendorIDSony && productID == OHProductIDDualSense)
+ if (button == BTN_SELECT)
+ return @"Create";
+ if (vendorID == OHVendorIDSony && productID == OHProductIDDualShock4)
+ if (button == BTN_SELECT)
+ return @"Share";
switch (button) {
case BTN_A:
return @"A";
case BTN_B:
@@ -633,10 +640,14 @@
{
@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
return [[[OHEvdevGamepad alloc]
initWithController: self] autorelease];
} @catch (OFInvalidArgumentException *e) {
ADDED src/hid/OHEvdevPlayStationGamepad.h
Index: src/hid/OHEvdevPlayStationGamepad.h
==================================================================
--- /dev/null
+++ src/hid/OHEvdevPlayStationGamepad.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2008-2024 Jonathan Schleifer
+ *
+ * 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
+ * .
+ */
+
+#import "OHEvdevGamepad.h"
+
+OF_ASSUME_NONNULL_BEGIN
+
+@interface OHEvdevPlayStationGamepad: OHEvdevGamepad
+@end
+
+OF_ASSUME_NONNULL_END
ADDED src/hid/OHEvdevPlayStationGamepad.m
Index: src/hid/OHEvdevPlayStationGamepad.m
==================================================================
--- /dev/null
+++ src/hid/OHEvdevPlayStationGamepad.m
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2008-2024 Jonathan Schleifer
+ *
+ * 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
+ * .
+ */
+
+#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"];
+
+ [buttons makeImmutable];
+
+ return buttons;
+}
+
+- (OHGameControllerButton *)northButton
+{
+ return [_rawProfile.buttons objectForKey: @"Triangle"];
+}
+
+- (OHGameControllerButton *)southButton
+{
+ return [_rawProfile.buttons objectForKey: @"Cross"];
+}
+
+- (OHGameControllerButton *)westButton
+{
+ return [_rawProfile.buttons objectForKey: @"Square"];
+}
+
+- (OHGameControllerButton *)eastButton
+{
+ return [_rawProfile.buttons objectForKey: @"Circle"];
+}
+
+- (OHGameControllerButton *)leftShoulderButton
+{
+ return [_rawProfile.buttons objectForKey: @"L1"];
+}
+
+- (OHGameControllerButton *)leftTriggerButton
+{
+ return [[[OHGameControllerEmulatedTriggerButton alloc]
+ initWithName: @"L2"
+ axis: [_rawProfile.axes objectForKey: @"Z"]] autorelease];
+}
+
+- (OHGameControllerButton *)rightTriggerButton
+{
+ return [[[OHGameControllerEmulatedTriggerButton alloc]
+ initWithName: @"R2"
+ axis: [_rawProfile.axes objectForKey: @"RZ"]] autorelease];
+}
+
+- (OHGameControllerButton *)rightShoulderButton
+{
+ return [_rawProfile.buttons objectForKey: @"R1"];
+}
+
+- (OHGameControllerButton *)leftThumbstickButton
+{
+ return [_rawProfile.buttons objectForKey: @"L3"];
+}
+
+- (OHGameControllerButton *)rightThumbstickButton
+{
+ return [_rawProfile.buttons objectForKey: @"R3"];
+}
+
+- (OHGameControllerButton *)menuButton
+{
+ return [_rawProfile.buttons objectForKey: @"Options"];
+}
+
+- (OHGameControllerButton *)homeButton
+{
+ return [_rawProfile.buttons objectForKey: @"PS"];
+}
+@end
Index: src/hid/OHGameController.h
==================================================================
--- src/hid/OHGameController.h
+++ src/hid/OHGameController.h
@@ -98,10 +98,11 @@
#ifdef __cplusplus
extern "C" {
#endif
extern const uint16_t OHVendorIDSony;
+extern const uint16_t OHProductIDDualShock4;
extern const uint16_t OHProductIDDualSense;
#ifdef __cplusplus
}
#endif
Index: src/hid/OHGameController.m
==================================================================
--- src/hid/OHGameController.m
+++ src/hid/OHGameController.m
@@ -37,10 +37,11 @@
#ifdef OF_NINTENDO_3DS
# import "OHNintendo3DSGameController.h"
#endif
const uint16_t OHVendorIDSony = 0x054C;
+const uint16_t OHProductIDDualShock4 = 0x09CC;
const uint16_t OHProductIDDualSense = 0x0CE6;
@implementation OHGameController
@dynamic name, rawProfile;