Comment: | ObjFWHID: Make profiles implementation independent |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ddaa4f35d0498a5cd93e0d0e2a074aca |
User & Date: | js on 2024-06-17 00:37:04 |
Other Links: | manifest | tags |
2024-06-17
| ||
00:47 | ObjFWHID: Internal rename check-in: 7d118b8085 user: js tags: trunk | |
00:37 | ObjFWHID: Make profiles implementation independent check-in: ddaa4f35d0 user: js tags: trunk | |
2024-06-16
| ||
21:54 | OHXInputExtendedGamepad -> OHXbox360Gamepad check-in: 318e342850 user: js tags: trunk | |
Modified src/hid/Makefile from [761e5efb16] to [ebf0da59ae].
︙ | ︙ | |||
10 11 12 13 14 15 16 | LIB_PATCH = ${OBJFWHID_LIB_PATCH} SRCS = OHCombinedJoyCons.m \ OHGameController.m \ OHGameControllerAxis.m \ OHGameControllerButton.m \ OHGameControllerDirectionalPad.m \ | | > > > > > > > > > > > > > > | | | | | | < < | < | < | < < < < < < < < < < | 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 | LIB_PATCH = ${OBJFWHID_LIB_PATCH} SRCS = OHCombinedJoyCons.m \ OHGameController.m \ OHGameControllerAxis.m \ OHGameControllerButton.m \ OHGameControllerDirectionalPad.m \ OHGameControllerElement.m INCLUDES := ${SRCS:.m=.h} \ OHExtendedGamepad.h \ OHGameControllerProfile.h \ OHGamepad.h \ ObjFWHID.h SRCS += OHDualSenseGamepad.m \ OHDualShock4Gamepad.m \ OHGameControllerEmulatedAxis.m \ OHGameControllerEmulatedButton.m \ OHGameControllerEmulatedTriggerButton.m \ OHStadiaGamepad.m \ OHXboxGamepad.m \ ${USE_SRCS_EVDEV} \ ${USE_SRCS_NINTENDO_3DS} \ ${USE_SRCS_NINTENDO_DS} \ ${USE_SRCS_NINTENDO_SWITCH} \ ${USE_SRCS_WII} \ ${USE_SRCS_XINPUT} SRCS_EVDEV = OHEvdevExtendedGamepad.m \ OHEvdevGameController.m \ OHEvdevGameControllerProfile.m SRCS_NINTENDO_3DS = OHNintendo3DSExtendedGamepad.m \ OHNintendo3DSGameController.m SRCS_NINTENDO_DS = OHNintendoDSGamepad.m \ OHNintendoDSGameController.m SRCS_NINTENDO_SWITCH = OHNintendoSwitchExtendedGamepad.m \ OHNintendoSwitchGameController.m SRCS_WII = OHWiiClassicController.m \ OHWiiGameController.m \ OHWiimote.m \ OHWiimoteWithNunchuk.m SRCS_XINPUT = OHXInputGameController.m includesubdir = ObjFWHID include ../../buildsys.mk install-extra: i=ObjFWHID.oc; \ |
︙ | ︙ |
Modified src/hid/OHCombinedJoyCons.m from [d9750ce99f] to [90a7f9c337].
︙ | ︙ | |||
61 62 63 64 65 66 67 | if (leftJoyCon.productID.unsignedShortValue != OHProductIDLeftJoyCon || rightJoyCon.productID.unsignedShortValue != OHProductIDRightJoyCon) @throw [OFInvalidArgumentException exception]; | | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | if (leftJoyCon.productID.unsignedShortValue != OHProductIDLeftJoyCon || rightJoyCon.productID.unsignedShortValue != OHProductIDRightJoyCon) @throw [OFInvalidArgumentException exception]; _leftJoyCon = [leftJoyCon.profile retain]; _rightJoyCon = [rightJoyCon.profile retain]; leftButtons = _leftJoyCon.buttons; rightButtons = _rightJoyCon.buttons; buttons = [OFMutableDictionary dictionaryWithCapacity: leftButtons.count + rightButtons.count]; [buttons addEntriesFromDictionary: leftButtons]; |
︙ | ︙ |
Renamed and modified src/hid/OHEvdevDualSense.h [08dcd8d0d7] to src/hid/OHDualSenseGamepad.h [cbc8819966].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * 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/>. */ | | > > > | > > > > | 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" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # import "OHEvdevGameController.h" #endif OF_ASSUME_NONNULL_BEGIN @interface OHDualSenseGamepad: OFObject <OHExtendedGamepad, #if defined(OF_LINUX) && defined(OF_HAVE_FILES) OHEvdevMapping #endif > @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/OHEvdevDualSense.m [08296e1a60] to src/hid/OHDualSenseGamepad.m [3943959c39].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * 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" | | > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > | > > | 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 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 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 249 250 251 252 253 254 255 256 257 258 259 260 261 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 | * 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 "OHDualSenseGamepad.h" #import "OFDictionary.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" #import "OHGameControllerEmulatedTriggerButton.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include <linux/input.h> #endif static OFString *const buttonNames[] = { @"Triangle", @"Cross", @"Square", @"Circle", @"L1", @"R1", @"L3", @"R3", @"Options", @"Create", @"PS" }; static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); @implementation OHDualSenseGamepad @synthesize buttons = _buttons, directionalPads = _directionalPads; - (instancetype)init { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *buttons = [OFMutableDictionary dictionaryWithCapacity: numButtons]; OHGameControllerButton *button; OFMutableDictionary *directionalPads; OHGameControllerAxis *axis, *xAxis, *yAxis; OHGameControllerDirectionalPad *directionalPad; for (size_t i = 0; i < numButtons; i++) { button = [[[OHGameControllerButton alloc] initWithName: buttonNames[i]] autorelease]; [buttons setObject: button forKey: buttonNames[i]]; } axis = [[[OHGameControllerAxis alloc] initWithName: @"L2"] autorelease]; button = [[[OHGameControllerEmulatedTriggerButton alloc] initWithName: @"L2" axis: axis] autorelease]; [buttons setObject: button forKey: @"L2"]; axis = [[[OHGameControllerAxis alloc] initWithName: @"R2"] autorelease]; button = [[[OHGameControllerEmulatedTriggerButton alloc] initWithName: @"R2" axis: axis] autorelease]; [buttons setObject: button forKey: @"R2"]; [buttons makeImmutable]; _buttons = [buttons retain]; directionalPads = [OFMutableDictionary dictionaryWithCapacity: 3]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"X"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"Y"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"Left Stick" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"Left Stick"]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"RX"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"RY"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"Right Stick" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"Right Stick"]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"D-Pad X"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"D-Pad Y"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"D-Pad" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"D-Pad"]; [directionalPads makeImmutable]; _directionalPads = [directionalPads retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_buttons release]; [_directionalPads release]; [super dealloc]; } - (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes { return [OFDictionary dictionary]; } - (OHGameControllerButton *)northButton { return [_buttons objectForKey: @"Triangle"]; } - (OHGameControllerButton *)southButton { return [_buttons objectForKey: @"Cross"]; } - (OHGameControllerButton *)westButton { return [_buttons objectForKey: @"Square"]; } - (OHGameControllerButton *)eastButton { return [_buttons objectForKey: @"Circle"]; } - (OHGameControllerButton *)leftShoulderButton { return [_buttons objectForKey: @"L1"]; } - (OHGameControllerButton *)rightShoulderButton { return [_buttons objectForKey: @"R1"]; } - (OHGameControllerButton *)leftTriggerButton { return [_buttons objectForKey: @"L2"]; } - (OHGameControllerButton *)rightTriggerButton { return [_buttons objectForKey: @"R2"]; } - (OHGameControllerButton *)leftThumbstickButton { return [_buttons objectForKey: @"L3"]; } - (OHGameControllerButton *)rightThumbstickButton { return [_buttons objectForKey: @"R3"]; } - (OHGameControllerButton *)menuButton { return [_buttons objectForKey: @"Options"]; } - (OHGameControllerButton *)optionsButton { return [_buttons objectForKey: @"Create"]; } - (OHGameControllerButton *)homeButton { return [_buttons objectForKey: @"PS"]; } - (OHGameControllerDirectionalPad *)leftThumbstick { return [_directionalPads objectForKey: @"Left Stick"]; } - (OHGameControllerDirectionalPad *)rightThumbstick { return [_directionalPads objectForKey: @"Right Stick"]; } - (OHGameControllerDirectionalPad *)dPad { return [_directionalPads objectForKey: @"D-Pad"]; } #if defined(OF_LINUX) && defined(OF_HAVE_FILES) - (OHGameControllerButton *)oh_buttonForEvdevButton: (uint16_t)button { OFString *name; switch (button) { case BTN_NORTH: name = @"Triangle"; break; case BTN_SOUTH: name = @"Cross"; break; case BTN_WEST: name = @"Square"; break; case BTN_EAST: name = @"Circle"; break; case BTN_TL: name = @"L1"; break; case BTN_TR: name = @"R1"; break; case BTN_THUMBL: name = @"L3"; break; case BTN_THUMBR: name = @"R3"; break; case BTN_START: name = @"Options"; break; case BTN_SELECT: name = @"Create"; break; case BTN_MODE: name = @"PS"; break; default: return nil; } return [_buttons objectForKey: name]; } - (OHGameControllerAxis *)oh_axisForEvdevAxis: (uint16_t)axis { switch (axis) { case ABS_X: return [[_directionalPads objectForKey: @"Left Stick"] xAxis]; case ABS_Y: return [[_directionalPads objectForKey: @"Left Stick"] yAxis]; case ABS_RX: return [[_directionalPads objectForKey: @"Right Stick"] xAxis]; case ABS_RY: return [[_directionalPads objectForKey: @"Right Stick"] yAxis]; case ABS_HAT0X: return [[_directionalPads objectForKey: @"D-Pad"] xAxis]; case ABS_HAT0Y: return [[_directionalPads objectForKey: @"D-Pad"] yAxis]; case ABS_Z: return ((OHGameControllerEmulatedTriggerButton *) [_buttons objectForKey: @"L2"]).axis; case ABS_RZ: return ((OHGameControllerEmulatedTriggerButton *) [_buttons objectForKey: @"R2"]).axis; default: return nil; } } #endif @end |
Renamed and modified src/hid/OHEvdevDualShock4.h [95fc4e91aa] to src/hid/OHDualShock4Gamepad.h [03fc4fb34d].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * 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/>. */ | | > > > | > > > > | 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" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # import "OHEvdevGameController.h" #endif OF_ASSUME_NONNULL_BEGIN @interface OHDualShock4Gamepad: OFObject <OHExtendedGamepad, #if defined(OF_LINUX) && defined(OF_HAVE_FILES) OHEvdevMapping #endif > @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/OHEvdevDualShock4.m [8fd86b557a] to src/hid/OHDualShock4Gamepad.m [67cdfbaf35].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * 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" | | > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > | > > | 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 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 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 249 250 251 252 253 254 255 256 257 258 259 260 261 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 | * 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 "OHDualShock4Gamepad.h" #import "OFDictionary.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" #import "OHGameControllerEmulatedTriggerButton.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include <linux/input.h> #endif static OFString *const buttonNames[] = { @"Triangle", @"Cross", @"Square", @"Circle", @"L1", @"R1", @"L3", @"R3", @"Options", @"Share", @"PS" }; static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); @implementation OHDualShock4Gamepad @synthesize buttons = _buttons, directionalPads = _directionalPads; - (instancetype)init { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *buttons = [OFMutableDictionary dictionaryWithCapacity: numButtons]; OHGameControllerButton *button; OFMutableDictionary *directionalPads; OHGameControllerAxis *axis, *xAxis, *yAxis; OHGameControllerDirectionalPad *directionalPad; for (size_t i = 0; i < numButtons; i++) { button = [[[OHGameControllerButton alloc] initWithName: buttonNames[i]] autorelease]; [buttons setObject: button forKey: buttonNames[i]]; } axis = [[[OHGameControllerAxis alloc] initWithName: @"L2"] autorelease]; button = [[[OHGameControllerEmulatedTriggerButton alloc] initWithName: @"L2" axis: axis] autorelease]; [buttons setObject: button forKey: @"L2"]; axis = [[[OHGameControllerAxis alloc] initWithName: @"R2"] autorelease]; button = [[[OHGameControllerEmulatedTriggerButton alloc] initWithName: @"R2" axis: axis] autorelease]; [buttons setObject: button forKey: @"R2"]; [buttons makeImmutable]; _buttons = [buttons retain]; directionalPads = [OFMutableDictionary dictionaryWithCapacity: 3]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"X"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"Y"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"Left Stick" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"Left Stick"]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"RX"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"RY"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"Right Stick" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"Right Stick"]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"D-Pad X"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"D-Pad Y"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"D-Pad" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"D-Pad"]; [directionalPads makeImmutable]; _directionalPads = [directionalPads retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_buttons release]; [_directionalPads release]; [super dealloc]; } - (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes { return [OFDictionary dictionary]; } - (OHGameControllerButton *)northButton { return [_buttons objectForKey: @"Triangle"]; } - (OHGameControllerButton *)southButton { return [_buttons objectForKey: @"Cross"]; } - (OHGameControllerButton *)westButton { return [_buttons objectForKey: @"Square"]; } - (OHGameControllerButton *)eastButton { return [_buttons objectForKey: @"Circle"]; } - (OHGameControllerButton *)leftShoulderButton { return [_buttons objectForKey: @"L1"]; } - (OHGameControllerButton *)rightShoulderButton { return [_buttons objectForKey: @"R1"]; } - (OHGameControllerButton *)leftTriggerButton { return [_buttons objectForKey: @"L2"]; } - (OHGameControllerButton *)rightTriggerButton { return [_buttons objectForKey: @"R2"]; } - (OHGameControllerButton *)leftThumbstickButton { return [_buttons objectForKey: @"L3"]; } - (OHGameControllerButton *)rightThumbstickButton { return [_buttons objectForKey: @"R3"]; } - (OHGameControllerButton *)menuButton { return [_buttons objectForKey: @"Options"]; } - (OHGameControllerButton *)optionsButton { return [_buttons objectForKey: @"Share"]; } - (OHGameControllerButton *)homeButton { return [_buttons objectForKey: @"PS"]; } - (OHGameControllerDirectionalPad *)leftThumbstick { return [_directionalPads objectForKey: @"Left Stick"]; } - (OHGameControllerDirectionalPad *)rightThumbstick { return [_directionalPads objectForKey: @"Right Stick"]; } - (OHGameControllerDirectionalPad *)dPad { return [_directionalPads objectForKey: @"D-Pad"]; } #if defined(OF_LINUX) && defined(OF_HAVE_FILES) - (OHGameControllerButton *)oh_buttonForEvdevButton: (uint16_t)button { OFString *name; switch (button) { case BTN_NORTH: name = @"Triangle"; break; case BTN_SOUTH: name = @"Cross"; break; case BTN_WEST: name = @"Square"; break; case BTN_EAST: name = @"Circle"; break; case BTN_TL: name = @"L1"; break; case BTN_TR: name = @"R1"; break; case BTN_THUMBL: name = @"L3"; break; case BTN_THUMBR: name = @"R3"; break; case BTN_START: name = @"Options"; break; case BTN_SELECT: name = @"Share"; break; case BTN_MODE: name = @"PS"; break; default: return nil; } return [_buttons objectForKey: name]; } - (OHGameControllerAxis *)oh_axisForEvdevAxis: (uint16_t)axis { switch (axis) { case ABS_X: return [[_directionalPads objectForKey: @"Left Stick"] xAxis]; case ABS_Y: return [[_directionalPads objectForKey: @"Left Stick"] yAxis]; case ABS_RX: return [[_directionalPads objectForKey: @"Right Stick"] xAxis]; case ABS_RY: return [[_directionalPads objectForKey: @"Right Stick"] yAxis]; case ABS_HAT0X: return [[_directionalPads objectForKey: @"D-Pad"] xAxis]; case ABS_HAT0Y: return [[_directionalPads objectForKey: @"D-Pad"] yAxis]; case ABS_Z: return ((OHGameControllerEmulatedTriggerButton *) [_buttons objectForKey: @"L2"]).axis; case ABS_RZ: return ((OHGameControllerEmulatedTriggerButton *) [_buttons objectForKey: @"R2"]).axis; default: return nil; } } #endif @end |
Modified src/hid/OHEvdevExtendedGamepad.h from [b25eb5bac7] to [5c3f6ac566].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * 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/>. */ | | < < | < < < | < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * 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 "OHEvdevGameControllerProfile.h" OF_ASSUME_NONNULL_BEGIN @interface OHEvdevExtendedGamepad: OHEvdevGameControllerProfile <OHExtendedGamepad> @end OF_ASSUME_NONNULL_END |
Modified src/hid/OHEvdevExtendedGamepad.m from [f71df4684b] to [bb1ee3755e].
︙ | ︙ | |||
24 25 26 27 28 29 30 | #import "OHEvdevGameController.h" #import "OHGameControllerDirectionalPad.h" #import "OHGameControllerEmulatedTriggerButton.h" #import "OFInvalidArgumentException.h" @implementation OHEvdevExtendedGamepad | | > > > > | > > > > < < | > < < < < < < < | < | | | < | 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 91 92 93 94 95 | #import "OHEvdevGameController.h" #import "OHGameControllerDirectionalPad.h" #import "OHGameControllerEmulatedTriggerButton.h" #import "OFInvalidArgumentException.h" @implementation OHEvdevExtendedGamepad - (instancetype)initWithKeyBits: (unsigned long *)keyBits evBits: (unsigned long *)evBits absBits: (unsigned long *)absBits vendorID: (uint16_t)vendorID productID: (uint16_t)productID { self = [super initWithKeyBits: keyBits evBits: evBits absBits: absBits vendorID: vendorID productID: productID]; @try { void *pool = objc_autoreleasePoolPush(); if (self.northButton == nil || self.southButton == nil || self.westButton == nil || self.eastButton == nil || self.leftShoulderButton == nil || self.rightShoulderButton == nil || self.leftTriggerButton == nil || self.rightTriggerButton == nil || self.menuButton == nil || self.optionsButton == nil || self.leftThumbstick == nil || self.rightThumbstick == nil || self.dPad == nil) object_setClass(self, [OHEvdevGameControllerProfile class]); objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *)buttons { OFMutableDictionary *buttons = [[_buttons mutableCopy] autorelease]; [buttons removeObjectForKey: @"D-Pad Up"]; [buttons removeObjectForKey: @"D-Pad Down"]; [buttons removeObjectForKey: @"D-Pad Left"]; [buttons removeObjectForKey: @"D-Pad Right"]; if ([_axes objectForKey: @"Z"] != nil) [buttons setObject: self.leftTriggerButton forKey: @"LT"]; if ([_axes objectForKey: @"RZ"] != nil) [buttons setObject: self.rightTriggerButton forKey: @"RT"]; [buttons makeImmutable]; return buttons; } - (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes { OFMutableDictionary *axes = [[_axes mutableCopy] autorelease]; [axes removeObjectForKey: @"X"]; [axes removeObjectForKey: @"Y"]; [axes removeObjectForKey: @"RX"]; [axes removeObjectForKey: @"RY"]; [axes removeObjectForKey: @"Z"]; [axes removeObjectForKey: @"RZ"]; |
︙ | ︙ | |||
110 111 112 113 114 115 116 | @"Left Thumbstick", self.leftThumbstick, @"Right Thumbstick", self.rightThumbstick, @"D-Pad", self.dPad, nil]; } - (OHGameControllerButton *)northButton { | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 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 | @"Left Thumbstick", self.leftThumbstick, @"Right Thumbstick", self.rightThumbstick, @"D-Pad", self.dPad, nil]; } - (OHGameControllerButton *)northButton { return [_buttons objectForKey: @"Y"]; } - (OHGameControllerButton *)southButton { return [_buttons objectForKey: @"A"]; } - (OHGameControllerButton *)westButton { return [_buttons objectForKey: @"X"]; } - (OHGameControllerButton *)eastButton { return [_buttons objectForKey: @"B"]; } - (OHGameControllerButton *)leftShoulderButton { return [_buttons objectForKey: @"LB"]; } - (OHGameControllerButton *)rightShoulderButton { return [_buttons objectForKey: @"RB"]; } - (OHGameControllerButton *)leftTriggerButton { OHGameControllerAxis *axis = [_axes objectForKey: @"Z"]; if (axis != nil) return [[[OHGameControllerEmulatedTriggerButton alloc] initWithName: @"LT" axis: axis] autorelease]; return [_buttons objectForKey: @"LT"]; } - (OHGameControllerButton *)rightTriggerButton { OHGameControllerAxis *axis = [_axes objectForKey: @"RZ"]; if (axis != nil) return [[[OHGameControllerEmulatedTriggerButton alloc] initWithName: @"RT" axis: axis] autorelease]; return [_buttons objectForKey: @"RT"]; } - (OHGameControllerButton *)leftThumbstickButton { return [_buttons objectForKey: @"LSB"]; } - (OHGameControllerButton *)rightThumbstickButton { return [_buttons objectForKey: @"RSB"]; } - (OHGameControllerButton *)menuButton { return [_buttons objectForKey: @"Start"]; } - (OHGameControllerButton *)optionsButton { return [_buttons objectForKey: @"Back"]; } - (OHGameControllerButton *)homeButton { return [_buttons objectForKey: @"Guide"]; } - (OHGameControllerDirectionalPad *)leftThumbstick { OHGameControllerAxis *xAxis = [_axes objectForKey: @"X"]; OHGameControllerAxis *yAxis = [_axes objectForKey: @"Y"]; if (xAxis == nil || yAxis == nil) return nil; return [[[OHGameControllerDirectionalPad alloc] initWithName: @"Left Thumbstick" xAxis: xAxis yAxis: yAxis] autorelease]; } - (OHGameControllerDirectionalPad *)rightThumbstick { OHGameControllerAxis *xAxis = [_axes objectForKey: @"RX"]; OHGameControllerAxis *yAxis = [_axes objectForKey: @"RY"]; if (xAxis == nil || yAxis == nil) return nil; return [[[OHGameControllerDirectionalPad alloc] initWithName: @"Right Thumbstick" xAxis: xAxis yAxis: yAxis] autorelease]; } - (OHGameControllerDirectionalPad *)dPad { OHGameControllerAxis *xAxis = [_axes objectForKey: @"HAT0X"]; OHGameControllerAxis *yAxis = [_axes objectForKey: @"HAT0Y"]; OHGameControllerButton *up, *down, *left, *right; if (xAxis != nil && yAxis != nil) return [[[OHGameControllerDirectionalPad alloc] initWithName: @"D-Pad" xAxis: xAxis yAxis: yAxis] autorelease]; up = [_buttons objectForKey: @"D-Pad Up"]; down = [_buttons objectForKey: @"D-Pad Down"]; left = [_buttons objectForKey: @"D-Pad Left"]; right = [_buttons objectForKey: @"D-Pad Right"]; if (up != nil && down != nil && left != nil && right != nil) return [[[OHGameControllerDirectionalPad alloc] initWithName: @"D-Pad" up: up down: down left: left right: right] autorelease]; return nil; } @end |
Modified src/hid/OHEvdevGameController.h from [0dab2fe07e] to [d9553f88d1].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | * <https://www.gnu.org/licenses/>. */ #import "OHGameController.h" #import "OHGameControllerProfile.h" OF_ASSUME_NONNULL_BEGIN @interface OHEvdevGameController: OHGameController { OFString *_path; int _fd; bool _discardUntilReport; unsigned long *_evBits, *_keyBits, *_absBits; uint16_t _vendorID, _productID; OFString *_name; | > > > > > | > > > > > | 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 | * <https://www.gnu.org/licenses/>. */ #import "OHGameController.h" #import "OHGameControllerProfile.h" OF_ASSUME_NONNULL_BEGIN @protocol OHEvdevMapping <OFObject> - (OHGameControllerButton *)oh_buttonForEvdevButton: (uint16_t)button; - (OHGameControllerAxis *)oh_axisForEvdevAxis: (uint16_t)axis; @end @interface OHEvdevGameController: OHGameController { OFString *_path; int _fd; bool _discardUntilReport; unsigned long *_evBits, *_keyBits, *_absBits; uint16_t _vendorID, _productID; OFString *_name; id <OHGameControllerProfile, OHEvdevMapping> _profile; } - (instancetype)initWithPath: (OFString *)path; - (void)oh_pollState; @end extern const uint16_t OHEvdevButtonIDs[]; extern const size_t OHNumEvdevButtonIDs; extern const uint16_t OHEvdevAxisIDs[]; extern const size_t OHNumEvdevAxisIDs; OF_ASSUME_NONNULL_END |
Modified src/hid/OHEvdevGameController.m from [548d505db7] to [758671613d].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #import "OFArray.h" #import "OFDictionary.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" | | | | > < < < < < < < < < < < < < < < < < | > > | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | 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 91 92 93 94 95 96 97 98 99 100 | #import "OFArray.h" #import "OFDictionary.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OHDualSenseGamepad.h" #import "OHDualShock4Gamepad.h" #import "OHEvdevExtendedGamepad.h" #import "OHGameControllerAxis+Private.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerProfile.h" #import "OHStadiaGamepad.h" #include <sys/ioctl.h> #include <linux/input.h> #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" const uint16_t OHEvdevButtonIDs[] = { 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, BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, BTN_TRIGGER_HAPPY5, BTN_TRIGGER_HAPPY6, BTN_TRIGGER_HAPPY7, BTN_TRIGGER_HAPPY8, BTN_TRIGGER_HAPPY9, BTN_TRIGGER_HAPPY10, BTN_TRIGGER_HAPPY11, BTN_TRIGGER_HAPPY12, BTN_TRIGGER_HAPPY13, BTN_TRIGGER_HAPPY14, BTN_TRIGGER_HAPPY15, BTN_TRIGGER_HAPPY16, BTN_TRIGGER_HAPPY17, BTN_TRIGGER_HAPPY18, BTN_TRIGGER_HAPPY19, BTN_TRIGGER_HAPPY20, BTN_TRIGGER_HAPPY21, BTN_TRIGGER_HAPPY22, BTN_TRIGGER_HAPPY23, BTN_TRIGGER_HAPPY24, BTN_TRIGGER_HAPPY25, BTN_TRIGGER_HAPPY26, BTN_TRIGGER_HAPPY27, BTN_TRIGGER_HAPPY28, BTN_TRIGGER_HAPPY29, BTN_TRIGGER_HAPPY30, BTN_TRIGGER_HAPPY31, BTN_TRIGGER_HAPPY32, BTN_TRIGGER_HAPPY33, BTN_TRIGGER_HAPPY34, BTN_TRIGGER_HAPPY35, BTN_TRIGGER_HAPPY36, BTN_TRIGGER_HAPPY37, BTN_TRIGGER_HAPPY38, BTN_TRIGGER_HAPPY39, BTN_TRIGGER_HAPPY40 }; const size_t OHNumEvdevButtonIDs = sizeof(OHEvdevButtonIDs) / sizeof(*OHEvdevButtonIDs); const uint16_t OHEvdevAxisIDs[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ, ABS_THROTTLE, ABS_RUDDER, ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y, ABS_HAT3X, ABS_HAT3Y }; const size_t OHNumEvdevAxisIDs = sizeof(OHEvdevAxisIDs) / sizeof(*OHEvdevAxisIDs); static float scale(float value, float min, float max) { if (value < min) value = min; if (value > max) value = max; return ((value - min) / (max - min) * 2) - 1; } @implementation OHEvdevGameController @synthesize name = _name, profile = _profile; + (OFArray OF_GENERIC(OHGameController *) *)controllers { OFMutableArray *controllers = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (OFString *device in [[OFFileManager defaultManager] |
︙ | ︙ | |||
451 452 453 454 455 456 457 | self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding = [OFLocale encoding]; struct input_id inputID; char name[128]; | < | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding = [OFLocale encoding]; struct input_id inputID; char name[128]; _path = [path copy]; if ((_fd = open([_path cStringWithEncoding: encoding], O_RDONLY | O_NONBLOCK)) == -1) @throw [OFOpenItemFailedException exceptionWithPath: _path |
︙ | ︙ | |||
497 498 499 500 501 502 503 | if (ioctl(_fd, EVIOCGNAME(sizeof(name)), name) == -1) @throw [OFInitializationFailedException exception]; _name = [[OFString alloc] initWithCString: name encoding: encoding]; | < < < < < < < < < < < < < < < < < < < < < | < < < < < > > | | < | > > | < < | < < < < < | | | | > > > | 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 | if (ioctl(_fd, EVIOCGNAME(sizeof(name)), name) == -1) @throw [OFInitializationFailedException exception]; _name = [[OFString alloc] initWithCString: name encoding: encoding]; if (OFBitSetIsSet(_evBits, EV_ABS)) { _absBits = OFAllocZeroedMemory(OFRoundUpToPowerOf2( OF_ULONG_BIT, ABS_MAX) / OF_ULONG_BIT, sizeof(unsigned long)); if (ioctl(_fd, EVIOCGBIT(EV_ABS, OFRoundUpToPowerOf2( OF_ULONG_BIT, ABS_MAX) / OF_ULONG_BIT * sizeof(unsigned long)), _absBits) == -1) @throw [OFInitializationFailedException exception]; } if (_vendorID == OHVendorIDSony && _productID == OHProductIDDualSense) _profile = [[OHDualSenseGamepad alloc] init]; else if (_vendorID == OHVendorIDSony && _productID == OHProductIDDualShock4) _profile = [[OHDualShock4Gamepad alloc] init]; else if (_vendorID == OHVendorIDGoogle && _productID == OHProductIDStadiaController) _profile = [[OHStadiaGamepad alloc] init]; else _profile = [[OHEvdevExtendedGamepad alloc] initWithKeyBits: _keyBits evBits: _evBits absBits: _absBits vendorID: _vendorID productID: _productID]; [self oh_pollState]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
576 577 578 579 580 581 582 | close(_fd); OFFreeMemory(_evBits); OFFreeMemory(_keyBits); OFFreeMemory(_absBits); [_name release]; | | | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | close(_fd); OFFreeMemory(_evBits); OFFreeMemory(_keyBits); OFFreeMemory(_absBits); [_name release]; [_profile release]; [super dealloc]; } - (OFNumber *)vendorID { return [OFNumber numberWithUnsignedShort: _vendorID]; |
︙ | ︙ | |||
602 603 604 605 606 607 608 | if (ioctl(_fd, EVIOCGKEY(sizeof(keyState)), &keyState) == -1) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(keyState) errNo: errno]; | | < < | | < < | < | | < < | | < < < | | < | > | | < | | 259 260 261 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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | if (ioctl(_fd, EVIOCGKEY(sizeof(keyState)), &keyState) == -1) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(keyState) errNo: errno]; for (size_t i = 0; i < OHNumEvdevButtonIDs; i++) { OHGameControllerButton *button; if (!OFBitSetIsSet(_keyBits, OHEvdevButtonIDs[i])) continue; button = [_profile oh_buttonForEvdevButton: OHEvdevButtonIDs[i]]; if (button == nil) continue; if (OFBitSetIsSet(keyState, OHEvdevButtonIDs[i])) button.value = 1.f; else button.value = 0.f; } if (OFBitSetIsSet(_evBits, EV_ABS)) { for (size_t i = 0; i < OHNumEvdevAxisIDs; i++) { struct input_absinfo info; OHGameControllerAxis *axis; if (!OFBitSetIsSet(_absBits, OHEvdevAxisIDs[i])) continue; axis = [_profile oh_axisForEvdevAxis: OHEvdevAxisIDs[i]]; if (axis == nil) continue; if (ioctl(_fd, EVIOCGABS(OHEvdevAxisIDs[i]), &info) == -1) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(info) errNo: errno]; axis.oh_minRawValue = info.minimum; axis.oh_maxRawValue = info.maximum; axis.value = scale(info.value, info.minimum, info.maximum); } } } - (void)retrieveState { void *pool = objc_autoreleasePoolPush(); struct input_event event; for (;;) { OHGameControllerButton *button; OHGameControllerAxis *axis; errno = 0; if (read(_fd, &event, sizeof(event)) < (int)sizeof(event)) { if (errno == EWOULDBLOCK) { objc_autoreleasePoolPop(pool); return; |
︙ | ︙ | |||
698 699 700 701 702 703 704 | case EV_SYN: if (event.value == SYN_DROPPED) { _discardUntilReport = true; continue; } break; case EV_KEY: | < < < | < < < < | < < | > > > | < < < < < < < < < < < | < < | | < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | case EV_SYN: if (event.value == SYN_DROPPED) { _discardUntilReport = true; continue; } break; case EV_KEY: button = [_profile oh_buttonForEvdevButton: event.code]; if (button == nil) continue; if (event.value) button.value = 1.f; else button.value = 0.f; break; case EV_ABS: axis = [_profile oh_axisForEvdevAxis: event.code]; if (axis == nil) continue; axis.value = scale(event.value, axis.oh_minRawValue, axis.oh_maxRawValue); break; } } } - (id <OHGamepad>)gamepad { if ([_profile conformsToProtocol: @protocol(OHGamepad)]) return (id <OHGamepad>)_profile; return nil; } - (id <OHExtendedGamepad>)extendedGamepad { if ([_profile conformsToProtocol: @protocol(OHExtendedGamepad)]) return (id <OHExtendedGamepad>)_profile; return nil; } - (OFComparisonResult)compare: (OHEvdevGameController *)otherController { unsigned long long selfIndex, otherIndex; 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 |
Added src/hid/OHEvdevGameControllerProfile.h version [88f0042619].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * 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 "OHEvdevGameController.h" #import "OHGameControllerProfile.h" OF_ASSUME_NONNULL_BEGIN @interface OHEvdevGameControllerProfile: OFObject <OHGameControllerProfile, OHEvdevMapping> { OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons; OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *_axes; uint16_t _vendorID, _productID; } - (instancetype)initWithKeyBits: (unsigned long *)keyBits evBits: (unsigned long *)evBits absBits: (unsigned long *)absBits vendorID: (uint16_t)vendorID productID: (uint16_t)productID; @end OF_ASSUME_NONNULL_END |
Added src/hid/OHEvdevGameControllerProfile.m version [9b605a4be7].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 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 249 250 251 252 253 254 255 256 257 258 259 260 261 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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | /* * 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 "OHEvdevGameControllerProfile.h" #import "OFDictionary.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #include <linux/input.h> static OFString * buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID) { if (vendorID == OHVendorIDNintendo && productID == OHProductIDLeftJoyCon) { switch (button) { case BTN_TL: return @"L"; case BTN_TL2: return @"ZL"; case BTN_THUMBL: return @"Left Thumbstick"; case BTN_SELECT: return @"-"; case BTN_Z: return @"Capture"; case BTN_TR: return @"SL"; case BTN_TR2: return @"SR"; } } else if (vendorID == OHVendorIDNintendo && productID == OHProductIDRightJoyCon) { switch (button) { case BTN_NORTH: return @"X"; case BTN_SOUTH: return @"B"; case BTN_WEST: return @"Y"; case BTN_EAST: return @"A"; case BTN_TR: return @"R"; case BTN_TR2: return @"ZR"; case BTN_THUMBR: return @"Right Thumbstick"; case BTN_START: return @"+"; case BTN_MODE: return @"Home"; case BTN_TL: return @"SL"; case BTN_TL2: return @"SR"; } } else if (vendorID == OHVendorIDNintendo && productID == OHProductIDN64Controller) { switch (button) { case BTN_SELECT: return @"C-Pad Up"; case BTN_X: return @"C-Pad Down"; case BTN_Y: return @"C-Pad Left"; case BTN_C: return @"C-Pad Right"; case BTN_TL: return @"L"; case BTN_TR: return @"R"; case BTN_TL2: return @"Z"; case BTN_TR2: return @"ZR"; case BTN_MODE: return @"Home"; case BTN_Z: return @"Capture"; } } switch (button) { case BTN_A: return @"A"; case BTN_B: return @"B"; case BTN_C: return @"C"; case BTN_X: return @"X"; case BTN_Y: return @"Y"; case BTN_Z: return @"Z"; case BTN_TL: return @"LB"; case BTN_TR: return @"RB"; case BTN_TL2: return @"LT"; case BTN_TR2: return @"RT"; case BTN_SELECT: return @"Back"; case BTN_START: return @"Start"; case BTN_MODE: return @"Guide"; case BTN_THUMBL: return @"LSB"; case BTN_THUMBR: return @"RSB"; case BTN_DPAD_UP: return @"D-Pad Up"; case BTN_DPAD_DOWN: return @"D-Pad Down"; case BTN_DPAD_LEFT: return @"D-Pad Left"; case BTN_DPAD_RIGHT: return @"D-Pad Right"; case BTN_TRIGGER_HAPPY1: return @"Trigger Happy 1"; case BTN_TRIGGER_HAPPY2: return @"Trigger Happy 2"; case BTN_TRIGGER_HAPPY3: return @"Trigger Happy 3"; case BTN_TRIGGER_HAPPY4: return @"Trigger Happy 4"; case BTN_TRIGGER_HAPPY5: return @"Trigger Happy 5"; case BTN_TRIGGER_HAPPY6: return @"Trigger Happy 6"; case BTN_TRIGGER_HAPPY7: return @"Trigger Happy 7"; case BTN_TRIGGER_HAPPY8: return @"Trigger Happy 8"; case BTN_TRIGGER_HAPPY9: return @"Trigger Happy 9"; case BTN_TRIGGER_HAPPY10: return @"Trigger Happy 10"; case BTN_TRIGGER_HAPPY11: return @"Trigger Happy 11"; case BTN_TRIGGER_HAPPY12: return @"Trigger Happy 12"; case BTN_TRIGGER_HAPPY13: return @"Trigger Happy 13"; case BTN_TRIGGER_HAPPY14: return @"Trigger Happy 14"; case BTN_TRIGGER_HAPPY15: return @"Trigger Happy 15"; case BTN_TRIGGER_HAPPY16: return @"Trigger Happy 16"; case BTN_TRIGGER_HAPPY17: return @"Trigger Happy 17"; case BTN_TRIGGER_HAPPY18: return @"Trigger Happy 18"; case BTN_TRIGGER_HAPPY19: return @"Trigger Happy 19"; case BTN_TRIGGER_HAPPY20: return @"Trigger Happy 20"; case BTN_TRIGGER_HAPPY21: return @"Trigger Happy 21"; case BTN_TRIGGER_HAPPY22: return @"Trigger Happy 22"; case BTN_TRIGGER_HAPPY23: return @"Trigger Happy 23"; case BTN_TRIGGER_HAPPY24: return @"Trigger Happy 24"; case BTN_TRIGGER_HAPPY25: return @"Trigger Happy 25"; case BTN_TRIGGER_HAPPY26: return @"Trigger Happy 26"; case BTN_TRIGGER_HAPPY27: return @"Trigger Happy 27"; case BTN_TRIGGER_HAPPY28: return @"Trigger Happy 28"; case BTN_TRIGGER_HAPPY29: return @"Trigger Happy 29"; case BTN_TRIGGER_HAPPY30: return @"Trigger Happy 30"; case BTN_TRIGGER_HAPPY31: return @"Trigger Happy 31"; case BTN_TRIGGER_HAPPY32: return @"Trigger Happy 32"; case BTN_TRIGGER_HAPPY33: return @"Trigger Happy 33"; case BTN_TRIGGER_HAPPY34: return @"Trigger Happy 34"; case BTN_TRIGGER_HAPPY35: return @"Trigger Happy 35"; case BTN_TRIGGER_HAPPY36: return @"Trigger Happy 36"; case BTN_TRIGGER_HAPPY37: return @"Trigger Happy 37"; case BTN_TRIGGER_HAPPY38: return @"Trigger Happy 38"; case BTN_TRIGGER_HAPPY39: return @"Trigger Happy 39"; case BTN_TRIGGER_HAPPY40: return @"Trigger Happy 40"; default: return nil; } } static OFString * axisToName(uint16_t axis) { switch (axis) { case ABS_X: return @"X"; case ABS_Y: return @"Y"; case ABS_Z: return @"Z"; case ABS_RX: return @"RX"; case ABS_RY: return @"RY"; case ABS_RZ: return @"RZ"; case ABS_THROTTLE: return @"Throttle"; case ABS_RUDDER: return @"Rudder"; case ABS_WHEEL: return @"Wheel"; case ABS_GAS: return @"Gas"; case ABS_BRAKE: return @"Brake"; case ABS_HAT0X: return @"HAT0X"; case ABS_HAT0Y: return @"HAT0Y"; case ABS_HAT1X: return @"HAT1X"; case ABS_HAT1Y: return @"HAT1Y"; case ABS_HAT2X: return @"HAT2X"; case ABS_HAT2Y: return @"HAT2Y"; case ABS_HAT3X: return @"HAT3X"; case ABS_HAT3Y: return @"HAT3Y"; default: return nil; } } @implementation OHEvdevGameControllerProfile @synthesize buttons = _buttons, axes = _axes; - (instancetype)initWithKeyBits: (unsigned long *)keyBits evBits: (unsigned long *)evBits absBits: (unsigned long *)absBits vendorID: (uint16_t)vendorID productID: (uint16_t)productID { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *buttons, *axes; buttons = [OFMutableDictionary dictionary]; for (size_t i = 0; i < OHNumEvdevButtonIDs; i++) { if (OFBitSetIsSet(keyBits, OHEvdevButtonIDs[i])) { OFString *buttonName; OHGameControllerButton *button; buttonName = buttonToName(OHEvdevButtonIDs[i], vendorID, productID); if (buttonName == nil) continue; button = [[[OHGameControllerButton alloc] initWithName: buttonName] autorelease]; [buttons setObject: button forKey: buttonName]; } } [buttons makeImmutable]; axes = [OFMutableDictionary dictionary]; if (OFBitSetIsSet(evBits, EV_ABS)) { for (size_t i = 0; i < OHNumEvdevAxisIDs; i++) { if (OFBitSetIsSet(absBits, OHEvdevAxisIDs[i])) { OFString *axisName; OHGameControllerAxis *axis; axisName = axisToName(OHEvdevAxisIDs[i]); if (axisName == nil) continue; axis = [[[OHGameControllerAxis alloc] initWithName: axisName] autorelease]; [axes setObject: axis forKey: axisName]; } } } [axes makeImmutable]; _buttons = [buttons retain]; _axes = [axes retain]; _vendorID = vendorID; _productID = productID; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_buttons release]; [_axes release]; [super dealloc]; } - (OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *) *) directionalPads { return [OFDictionary dictionary]; } - (OHGameControllerButton *)oh_buttonForEvdevButton: (uint16_t)button { OFString *name; if ((name = buttonToName(button, _vendorID, _productID)) == nil) return nil; return [_buttons objectForKey: name]; } - (OHGameControllerAxis *)oh_axisForEvdevAxis: (uint16_t)axis { OFString *name; if ((name = axisToName(axis)) == nil) return nil; return [_axes objectForKey: name]; } @end |
Deleted src/hid/OHEvdevPlayStationExtendedGamepad.h version [09600485c0].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/hid/OHEvdevPlayStationExtendedGamepad.m version [0482667023].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/hid/OHGameController.h from [526e49cd36] to [ce18140fea].
︙ | ︙ | |||
65 66 67 68 69 70 71 | /** * @brief The product ID of the controller or `nil` if unavailable. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *productID; /** | | < | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | /** * @brief The product ID of the controller or `nil` if unavailable. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *productID; /** * @brief The profile for the game controller. */ @property (readonly, nonatomic) id <OHGameControllerProfile> profile; /** * @brief The gamepad profile for the game controller, or `nil` if not * supported. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id <OHGamepad> gamepad; |
︙ | ︙ |
Modified src/hid/OHGameController.m from [f031e78d5e] to [84aa11a3e7].
︙ | ︙ | |||
50 51 52 53 54 55 56 | const uint16_t OHProductIDDualSense = 0x0CE6; const uint16_t OHProductIDLeftJoyCon = 0x2006; const uint16_t OHProductIDRightJoyCon = 0x2007; const uint16_t OHProductIDN64Controller = 0x2019; const uint16_t OHProductIDStadiaController = 0x9400; @implementation OHGameController | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | const uint16_t OHProductIDDualSense = 0x0CE6; const uint16_t OHProductIDLeftJoyCon = 0x2006; const uint16_t OHProductIDRightJoyCon = 0x2007; const uint16_t OHProductIDN64Controller = 0x2019; const uint16_t OHProductIDStadiaController = 0x9400; @implementation OHGameController @dynamic name, profile; + (OFArray OF_GENERIC(OHGameController *) *)controllers { #if defined(OF_LINUX) && defined(OF_HAVE_FILES) return [OHEvdevGameController controllers]; #elif defined(OF_WINDOWS) return [OHXInputGameController controllers]; |
︙ | ︙ |
Added src/hid/OHGameControllerAxis+Private.h version [23ec35d35c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * 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 "OHGameControllerAxis.h" OF_ASSUME_NONNULL_BEGIN @interface OHGameControllerAxis () #if defined(OF_LINUX) && defined(OF_HAVE_FILES) @property (nonatomic, setter=oh_setMinRawValue:) int32_t oh_minRawValue; @property (nonatomic, setter=oh_setMaxRawValue:) int32_t oh_maxRawValue; #endif @end OF_ASSUME_NONNULL_END |
Modified src/hid/OHGameControllerAxis.h from [a18496dca4] to [5d35977b0a].
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * OHGameControllerAxis.h ObjFWHID/OHGameControllerAxis.h * * @brief An axis of a game controller. */ @interface OHGameControllerAxis: OHGameControllerElement { float _value; OF_RESERVE_IVARS(OHGameControllerButton, 4) } /** * @brief The value of the axis. */ @property (nonatomic) float value; | > > > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * OHGameControllerAxis.h ObjFWHID/OHGameControllerAxis.h * * @brief An axis of a game controller. */ @interface OHGameControllerAxis: OHGameControllerElement { float _value; #if defined(OF_LINUX) && defined(OF_HAVE_FILES) int32_t _minRawValue, _maxRawValue; #endif OF_RESERVE_IVARS(OHGameControllerButton, 4) } /** * @brief The value of the axis. */ @property (nonatomic) float value; |
︙ | ︙ |
Modified src/hid/OHGameControllerAxis.m from [0113b75889] to [6d133f6e40].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameControllerAxis.h" @implementation OHGameControllerAxis @synthesize value = _value; - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end | > > > > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameControllerAxis.h" #import "OHGameControllerAxis+Private.h" @implementation OHGameControllerAxis @synthesize value = _value; #if defined(OF_LINUX) && defined(OF_HAVE_FILES) @synthesize oh_minRawValue = _minRawValue, oh_maxRawValue = _maxRawValue; #endif - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Modified src/hid/OHGameControllerEmulatedTriggerButton.h from [be397ce686] to [7b4bceb90d].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | @class OHGameControllerAxis; OF_SUBCLASSING_RESTRICTED @interface OHGameControllerEmulatedTriggerButton: OHGameControllerButton { OHGameControllerAxis *_axis; } - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName: (OFString *)name axis: (OHGameControllerAxis *)axis; @end OF_ASSUME_NONNULL_END | > > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | @class OHGameControllerAxis; OF_SUBCLASSING_RESTRICTED @interface OHGameControllerEmulatedTriggerButton: OHGameControllerButton { OHGameControllerAxis *_axis; } @property (readonly, nonatomic) OHGameControllerAxis *axis; - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName: (OFString *)name axis: (OHGameControllerAxis *)axis; @end OF_ASSUME_NONNULL_END |
Modified src/hid/OHGameControllerEmulatedTriggerButton.m from [276359729c] to [e85e338284].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include "config.h" #import "OHGameControllerEmulatedTriggerButton.h" #import "OHGameControllerAxis.h" @implementation OHGameControllerEmulatedTriggerButton - (instancetype)initWithName: (OFString *)name { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name axis: (OHGameControllerAxis *)axis | > > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include "config.h" #import "OHGameControllerEmulatedTriggerButton.h" #import "OHGameControllerAxis.h" @implementation OHGameControllerEmulatedTriggerButton @synthesize axis = _axis; - (instancetype)initWithName: (OFString *)name { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name axis: (OHGameControllerAxis *)axis |
︙ | ︙ |
Modified src/hid/OHNintendo3DSGameController.m from [6bc450a66c] to [2f027499a1].
︙ | ︙ | |||
144 145 146 147 148 149 150 | } - (OFString *)name { return @"Nintendo 3DS"; } | | | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | } - (OFString *)name { return @"Nintendo 3DS"; } - (id <OHGameControllerProfile>)profile { return _extendedGamepad; } - (id <OHGamepad>)gamepad { return _extendedGamepad; |
︙ | ︙ |
Modified src/hid/OHNintendoDSGameController.m from [7132510c4f] to [7056d0ab9e].
︙ | ︙ | |||
105 106 107 108 109 110 111 | } - (OFString *)name { return @"Nintendo DS"; } | | | 105 106 107 108 109 110 111 112 113 114 115 116 | } - (OFString *)name { return @"Nintendo DS"; } - (id <OHGameControllerProfile>)profile { return _gamepad; } @end |
Modified src/hid/OHNintendoSwitchGameController.m from [2baa5a5492] to [a788c8cea8].
︙ | ︙ | |||
156 157 158 159 160 161 162 | } - (OFString *)name { return @"Nintendo Switch"; } | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | } - (OFString *)name { return @"Nintendo Switch"; } - (id <OHGameControllerProfile>)profile { return _extendedGamepad; } - (id <OHGamepad>)gamepad { return _extendedGamepad; |
︙ | ︙ |
Renamed and modified src/hid/OHEvdevStadiaExtendedGamepad.h [f8d23d688f] to src/hid/OHStadiaGamepad.h [fb081487e9].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * 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/>. */ | | > > > | > > > > | 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" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # import "OHEvdevGameController.h" #endif OF_ASSUME_NONNULL_BEGIN @interface OHStadiaGamepad: OFObject <OHExtendedGamepad, #if defined(OF_LINUX) && defined(OF_HAVE_FILES) OHEvdevMapping #endif > @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/OHEvdevStadiaExtendedGamepad.m [9baf34190b] to src/hid/OHStadiaGamepad.m [f14cc5d0c1].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * 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" | | > > > > > > > > > > > | > | > > > > > | > > > > > | > > > > | > > > > > > | > > > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > | < | | > > | > | > > | > | > > | < < | | > | | | | | < < < < < < | | | | | | > > > > > < | | > | > > > | > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 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 249 250 251 252 253 254 255 256 257 258 259 260 261 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 296 | * 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 "OHStadiaGamepad.h" #import "OFDictionary.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" #import "OHGameControllerEmulatedTriggerButton.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include <linux/input.h> #endif static OFString *const buttonNames[] = { @"A", @"B", @"X", @"Y", @"L1", @"R1", @"L3", @"R3", @"Menu", @"Options", @"Capture", @"Stadia", @"Assistant" }; static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames); @implementation OHStadiaGamepad @synthesize buttons = _buttons, directionalPads = _directionalPads; - (instancetype)init { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *buttons = [OFMutableDictionary dictionaryWithCapacity: numButtons]; OHGameControllerButton *button; OFMutableDictionary *directionalPads; OHGameControllerAxis *axis, *xAxis, *yAxis; OHGameControllerDirectionalPad *directionalPad; for (size_t i = 0; i < numButtons; i++) { button = [[[OHGameControllerButton alloc] initWithName: buttonNames[i]] autorelease]; [buttons setObject: button forKey: buttonNames[i]]; } axis = [[[OHGameControllerAxis alloc] initWithName: @"L2"] autorelease]; button = [[[OHGameControllerEmulatedTriggerButton alloc] initWithName: @"L2" axis: axis] autorelease]; [buttons setObject: button forKey: @"L2"]; axis = [[[OHGameControllerAxis alloc] initWithName: @"R2"] autorelease]; button = [[[OHGameControllerEmulatedTriggerButton alloc] initWithName: @"R2" axis: axis] autorelease]; [buttons setObject: button forKey: @"R2"]; [buttons makeImmutable]; _buttons = [buttons retain]; directionalPads = [OFMutableDictionary dictionaryWithCapacity: 3]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"X"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"Y"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"Left Stick" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"Left Stick"]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"RX"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"RY"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"Right Stick" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"Right Stick"]; xAxis = [[[OHGameControllerAxis alloc] initWithName: @"D-Pad X"] autorelease]; yAxis = [[[OHGameControllerAxis alloc] initWithName: @"D-Pad Y"] autorelease]; directionalPad = [[[OHGameControllerDirectionalPad alloc] initWithName: @"D-Pad" xAxis: xAxis yAxis: yAxis] autorelease]; [directionalPads setObject: directionalPad forKey: @"D-Pad"]; [directionalPads makeImmutable]; _directionalPads = [directionalPads retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_buttons release]; [_directionalPads release]; [super dealloc]; } - (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes { return [OFDictionary dictionary]; } - (OHGameControllerButton *)northButton { return [_buttons objectForKey: @"Y"]; } - (OHGameControllerButton *)southButton { return [_buttons objectForKey: @"A"]; } - (OHGameControllerButton *)westButton { return [_buttons objectForKey: @"X"]; } - (OHGameControllerButton *)eastButton { return [_buttons objectForKey: @"B"]; } - (OHGameControllerButton *)leftShoulderButton { return [_buttons objectForKey: @"L1"]; } - (OHGameControllerButton *)rightShoulderButton { return [_buttons objectForKey: @"R1"]; } - (OHGameControllerButton *)leftTriggerButton { return [_buttons objectForKey: @"L2"]; } - (OHGameControllerButton *)rightTriggerButton { return [_buttons objectForKey: @"R2"]; } - (OHGameControllerButton *)leftThumbstickButton { return [_buttons objectForKey: @"L3"]; } - (OHGameControllerButton *)rightThumbstickButton { return [_buttons objectForKey: @"R3"]; } - (OHGameControllerButton *)menuButton { return [_buttons objectForKey: @"Menu"]; } - (OHGameControllerButton *)optionsButton { return [_buttons objectForKey: @"Options"]; } - (OHGameControllerButton *)homeButton { return [_buttons objectForKey: @"Stadia"]; } - (OHGameControllerDirectionalPad *)leftThumbstick { return [_directionalPads objectForKey: @"Left Stick"]; } - (OHGameControllerDirectionalPad *)rightThumbstick { return [_directionalPads objectForKey: @"Right Stick"]; } - (OHGameControllerDirectionalPad *)dPad { return [_directionalPads objectForKey: @"D-Pad"]; } #if defined(OF_LINUX) && defined(OF_HAVE_FILES) - (OHGameControllerButton *)oh_buttonForEvdevButton: (uint16_t)button { OFString *name; switch (button) { case BTN_A: name = @"A"; break; case BTN_B: name = @"B"; break; case BTN_X: name = @"X"; break; case BTN_Y: name = @"Y"; break; case BTN_TL: name = @"L1"; break; case BTN_TR: name = @"R1"; break; case BTN_THUMBL: name = @"L3"; break; case BTN_THUMBR: name = @"R3"; break; case BTN_START: name = @"Menu"; break; case BTN_SELECT: name = @"Options"; break; case BTN_MODE: name = @"Stadia"; break; case BTN_TRIGGER_HAPPY1: name = @"Assistant"; break; case BTN_TRIGGER_HAPPY2: name = @"Capture"; break; default: return nil; } return [_buttons objectForKey: name]; } - (OHGameControllerAxis *)oh_axisForEvdevAxis: (uint16_t)axis { switch (axis) { case ABS_X: return [[_directionalPads objectForKey: @"Left Stick"] xAxis]; case ABS_Y: return [[_directionalPads objectForKey: @"Left Stick"] yAxis]; case ABS_Z: return [[_directionalPads objectForKey: @"Right Stick"] xAxis]; case ABS_RZ: return [[_directionalPads objectForKey: @"Right Stick"] yAxis]; case ABS_HAT0X: return [[_directionalPads objectForKey: @"D-Pad"] xAxis]; case ABS_HAT0Y: return [[_directionalPads objectForKey: @"D-Pad"] yAxis]; case ABS_BRAKE: return ((OHGameControllerEmulatedTriggerButton *) [_buttons objectForKey: @"L2"]).axis; case ABS_GAS: return ((OHGameControllerEmulatedTriggerButton *) [_buttons objectForKey: @"R2"]).axis; default: return nil; } } #endif @end |
Modified src/hid/OHWiiGameController.h from [a940a20263] to [7fb9593e8b].
︙ | ︙ | |||
21 22 23 24 25 26 27 | OF_ASSUME_NONNULL_BEGIN @interface OHWiiGameController: OHGameController { int32_t _index; uint32_t _type; | | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | OF_ASSUME_NONNULL_BEGIN @interface OHWiiGameController: OHGameController { int32_t _index; uint32_t _type; id <OHGameControllerProfile> _profile; } - (instancetype)initWithIndex: (int32_t)index type: (uint32_t)type; @end OF_ASSUME_NONNULL_END |
Modified src/hid/OHWiiGameController.m from [b6f18a05d5] to [d2411fda9b].
︙ | ︙ | |||
47 48 49 50 51 52 53 | if (value >= center) return (value - center) / (max - center); else return (value - center) / (center - min); } @implementation OHWiiGameController | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | if (value >= center) return (value - center) / (max - center); else return (value - center) / (center - min); } @implementation OHWiiGameController @synthesize profile = _profile; + (void)initialize { if (self != [OHWiiGameController class]) return; if (WPAD_Init() != WPAD_ERR_NONE) |
︙ | ︙ | |||
91 92 93 94 95 96 97 | self = [super init]; @try { _index = index; _type = type; if (type == WPAD_EXP_CLASSIC) | | | | | | | | 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 | self = [super init]; @try { _index = index; _type = type; if (type == WPAD_EXP_CLASSIC) _profile = [[OHWiiClassicController alloc] init]; else if (type == WPAD_EXP_NUNCHUK) _profile = [[OHWiimoteWithNunchuk alloc] init]; else _profile = [[OHWiimote alloc] init]; [self retrieveState]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_profile release]; [super dealloc]; } - (void)retrieveState { OFDictionary *buttons = _profile.buttons; OFDictionary *directionalPads = _profile.directionalPads; WPADData *data; if (WPAD_ReadPending(_index, NULL) < WPAD_ERR_NONE) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(WPADData) errNo: 0]; |
︙ | ︙ | |||
237 238 239 240 241 242 243 | else return @"Wiimote"; } - (id <OHGamepad>)gamepad { if (_type == WPAD_EXP_CLASSIC) | | | | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | else return @"Wiimote"; } - (id <OHGamepad>)gamepad { if (_type == WPAD_EXP_CLASSIC) return (id <OHGamepad>)_profile; return nil; } - (id <OHExtendedGamepad>)extendedGamepad { if (_type == WPAD_EXP_CLASSIC) return (id <OHExtendedGamepad>)_profile; return nil; } @end |
Modified src/hid/OHXInputGameController.m from [ee160f8921] to [cc3b87f597].
︙ | ︙ | |||
22 23 24 25 26 27 28 | #import "OHXInputGameController.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" | | | 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 "OHXboxGamepad.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #include <xinput.h> #ifndef XINPUT_GAMEPAD_GUIDE |
︙ | ︙ | |||
137 138 139 140 141 142 143 | capabilities.vendorID]; _productID = [[OFNumber alloc] initWithUnsignedShort: capabilities.productID]; } } | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | capabilities.vendorID]; _productID = [[OFNumber alloc] initWithUnsignedShort: capabilities.productID]; } } _extendedGamepad = [[OHXboxGamepad alloc] initWithHasGuideButton: (XInputVersion != 910)]; [self retrieveState]; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
233 234 235 236 237 238 239 | case 910: return @"XInput 9.1.0 device"; } return nil; } | | | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | case 910: return @"XInput 9.1.0 device"; } return nil; } - (id <OHGameControllerProfile>)profile { return _extendedGamepad; } - (id <OHGamepad>)gamepad { return _extendedGamepad; } @end |
Renamed and modified src/hid/OHXbox360Gamepad.h [8f67ee8fff] to src/hid/OHXboxGamepad.h [f497fe2896].
︙ | ︙ | |||
17 18 19 20 21 22 23 | * <https://www.gnu.org/licenses/>. */ #import "OHExtendedGamepad.h" OF_ASSUME_NONNULL_BEGIN | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * <https://www.gnu.org/licenses/>. */ #import "OHExtendedGamepad.h" OF_ASSUME_NONNULL_BEGIN @interface OHXboxGamepad: OFObject <OHExtendedGamepad> { OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons; OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *) *_directionalPads; } - (instancetype)initWithHasGuideButton: (bool)hasGuideButton; |
︙ | ︙ |
Renamed and modified src/hid/OHXbox360Gamepad.m [f7be1c6812] to src/hid/OHXboxGamepad.m [822fa91559].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * 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" | | | | 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 | * 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 "OHXboxGamepad.h" #import "OFDictionary.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.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 OHXboxGamepad @synthesize buttons = _buttons, directionalPads = _directionalPads; - (instancetype)init { return [self initWithHasGuideButton: true]; } |
︙ | ︙ | |||
55 56 57 58 59 60 61 | for (size_t i = 0; i < numButtons; i++) { OHGameControllerButton *button; if ([buttonNames[i] isEqual: @"Guide"] && !hasGuideButton) continue; | | | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | for (size_t i = 0; i < numButtons; i++) { OHGameControllerButton *button; if ([buttonNames[i] isEqual: @"Guide"] && !hasGuideButton) continue; button = [[[OHGameControllerButton alloc] initWithName: buttonNames[i]] autorelease]; [buttons setObject: button forKey: buttonNames[i]]; } [buttons makeImmutable]; _buttons = [buttons retain]; directionalPads = [OFMutableDictionary dictionaryWithCapacity: 3]; |
︙ | ︙ |
Modified tests/gamecontroller/GameControllerTests.m from [c3617c1d54] to [a4fbbbb68a].
︙ | ︙ | |||
207 208 209 210 211 212 213 | [OFStdOut clear]; } [OFStdOut setCursorPosition: OFMakePoint(0, 0)]; for (OHGameController *controller in _controllers) { | | < < < | < < | 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | [OFStdOut clear]; } [OFStdOut setCursorPosition: OFMakePoint(0, 0)]; for (OHGameController *controller in _controllers) { id <OHGameControllerProfile> profile = controller.profile; [OFStdOut setForegroundColor: [OFColor green]]; [OFStdOut writeLine: controller.description]; @try { [controller retrieveState]; } @catch (OFReadFailedException *e) { |
︙ | ︙ |