Differences From Artifact [9baf34190b]:
- File
src/hid/OHEvdevStadiaExtendedGamepad.m
— part of check-in
[998339ff24]
at
2024-06-09 11:43:49
on branch trunk
— 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. (user: js, size: 3303) [annotate] [blame] [check-ins using]
To Artifact [f14cc5d0c1]:
- File src/hid/OHStadiaGamepad.m — part of check-in [ddaa4f35d0] at 2024-06-17 00:37:04 on branch trunk — ObjFWHID: Make profiles implementation independent (user: js, size: 7204) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
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 |