Skip to content

Commit

Permalink
Merge pull request #8 from ToddLa/ios-14
Browse files Browse the repository at this point in the history
iOS 14
  • Loading branch information
zydeco committed Aug 3, 2021
2 parents 55cf95b + 018a64d commit e1ab229
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 60 deletions.
8 changes: 4 additions & 4 deletions SteamController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "SteamController/Info-iOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -461,7 +461,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "SteamController/Info-iOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -504,7 +504,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
TVOS_DEPLOYMENT_TARGET = 10.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -535,7 +535,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
TVOS_DEPLOYMENT_TARGET = 10.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down
2 changes: 2 additions & 0 deletions SteamController/SteamController.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ will be sent as soon as it's touched. Defaults to `YES`. */
@property (nonatomic, readonly, nullable) GCControllerButtonInput *steamBackButton;
/// The right pointing button to the right of the Steam button.
@property (nonatomic, readonly, nullable) GCControllerButtonInput *steamForwardButton;
/// The Steam button.
@property (nonatomic, readonly, nullable) GCControllerButtonInput *steamSteamButton;
@end

NS_ASSUME_NONNULL_END
Expand Down
16 changes: 14 additions & 2 deletions SteamController/SteamController.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ - (GCExtendedGamepad *)extendedGamepad {
return extendedGamepad;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (GCGamepad *)gamepad {
return (GCGamepad *)extendedGamepad;
}
#pragma clang diagnostic pop

- (GCMicroGamepad *)microGamepad {
return nil;
Expand Down Expand Up @@ -324,7 +327,8 @@ - (void)didReceiveInput:(uint16_t)packetType data:(NSData*)data {
snapshot.rightThumbstickButton = (state.buttons & SteamControllerButtonRightGrip);
snapshot.steamBackButton = (state.buttons & SteamControllerButtonBack);
snapshot.steamForwardButton = (state.buttons & SteamControllerButtonForward);

snapshot.steamSteamButton = (state.buttons & SteamControllerButtonSteam);

BOOL hasUpdatedPads[] = {
[SteamControllerMappingDPad] = NO,
[SteamControllerMappingLeftThumbstick] = NO,
Expand Down Expand Up @@ -369,7 +373,11 @@ - (void)didReceiveInput:(uint16_t)packetType data:(NSData*)data {
GSEventResetIdleTimer();
#endif

if (hasButtons && (state.buttons & SteamControllerButtonSteam)) {
if (_steamButtonCombinationHandler == nil) {
// Update client
extendedGamepad.state = snapshot;
}
else if (hasButtons && (state.buttons & SteamControllerButtonSteam)) {
// Handle steam button combos
handledSteamCombos |= [self handleSteamButtonCombos:(state.buttons & ~SteamControllerButtonSteam)];
} else if (hasButtons && (previousButtons & SteamControllerButtonSteam)) {
Expand Down Expand Up @@ -495,4 +503,8 @@ - (GCControllerButtonInput *)steamForwardButton {
return nil;
}

- (GCControllerButtonInput *)steamSteamButton {
return nil;
}

@end
3 changes: 3 additions & 0 deletions SteamController/SteamControllerExtendedGamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef struct {
#pragma mark - Steam Controller
BOOL steamBackButton;
BOOL steamForwardButton;
BOOL steamSteamButton;
} SteamControllerExtendedGamepadSnapshotData;
#pragma pack(pop)

Expand All @@ -71,8 +72,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly, nullable) SteamControllerButtonInput *rightThumbstickButton;
@property (nonatomic, readonly, nullable) SteamControllerButtonInput *buttonOptions;
@property (nonatomic, readonly, nullable) SteamControllerButtonInput *buttonMenu;
@property (nonatomic, readonly, nullable) SteamControllerButtonInput *buttonHome;
@property (nonatomic, readonly, nullable) SteamControllerButtonInput *steamBackButton;
@property (nonatomic, readonly, nullable) SteamControllerButtonInput *steamForwardButton;
@property (nonatomic, readonly, nullable) SteamControllerButtonInput *steamSteamButton;
@property (nonatomic, assign) SteamControllerExtendedGamepadSnapshotData state;

- (instancetype)initWithController:(SteamController*)controller;
Expand Down
10 changes: 8 additions & 2 deletions SteamController/SteamControllerExtendedGamepad.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ @implementation SteamControllerExtendedGamepad
SteamControllerButtonInput *leftThumbstickButton, *rightThumbstickButton;
SteamControllerButtonInput *leftTrigger, *rightTrigger;
SteamControllerButtonInput *buttonA, *buttonB, *buttonX, *buttonY;
SteamControllerButtonInput *steamBackButton, *steamForwardButton;
SteamControllerButtonInput *steamBackButton, *steamForwardButton, *steamSteamButton;
__weak SteamController *steamController;
SteamControllerExtendedGamepadSnapshotData state;
GCExtendedGamepadValueChangedHandler valueChangedHandler;
Expand All @@ -28,7 +28,7 @@ @implementation SteamControllerExtendedGamepad
@synthesize leftTrigger, rightTrigger;
@synthesize buttonA, buttonB, buttonX, buttonY;
@synthesize leftThumbstickButton, rightThumbstickButton;
@synthesize steamBackButton, steamForwardButton;
@synthesize steamBackButton, steamForwardButton, steamSteamButton;
@synthesize state;

- (instancetype)initWithController:(SteamController *)controller {
Expand Down Expand Up @@ -62,6 +62,7 @@ - (instancetype)initWithController:(SteamController *)controller {
}
steamBackButton = [[SteamControllerButtonInput alloc] initWithController:controller analog:NO];
steamForwardButton = [[SteamControllerButtonInput alloc] initWithController:controller analog:NO];
steamSteamButton = [[SteamControllerButtonInput alloc] initWithController:controller analog:NO];
}
return self;
}
Expand Down Expand Up @@ -105,6 +106,7 @@ - (void)setState:(SteamControllerExtendedGamepadSnapshotData)newState {
UpdateStateBool(rightThumbstickButton);
UpdateStateBool(steamBackButton);
UpdateStateBool(steamForwardButton);
UpdateStateBool(steamSteamButton);
}

- (void)didChangeValueForElement:(GCControllerElement*)element {
Expand All @@ -121,6 +123,10 @@ - (SteamControllerButtonInput *)buttonMenu {
return steamForwardButton;
}

- (SteamControllerButtonInput *)buttonHome {
return steamSteamButton;
}

- (void)setStateFromExtendedGamepad:(GCExtendedGamepad *)extendedGamepad {
// ignore
}
Expand Down
14 changes: 12 additions & 2 deletions SteamController/SteamControllerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
#import "SteamController.h"

@import CoreBluetooth;

#ifndef STEAMCONTROLLER_NO_SWIZZLING
@import ObjectiveC.runtime;
#endif

#ifndef STEAMCONTROLLER_NO_PRIVATE_API
@import Darwin.POSIX.dlfcn;
#endif

@interface SteamController (Private)
- (void)didConnect;
Expand Down Expand Up @@ -83,7 +89,7 @@ - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPe
}

- (void)centralManagerDidUpdateState:(nonnull CBCentralManager *)central {
if (central.state == CBCentralManagerStatePoweredOn) {
if (central.state == CBManagerStatePoweredOn) {
[self scanForControllers];
}
}
Expand All @@ -97,7 +103,7 @@ - (void)scanForControllers:(id)sender {
}

- (void)scanForControllers {
if (centralManager.state == CBCentralManagerStatePoweredOn) {
if (centralManager.state == CBManagerStatePoweredOn) {
[centralManager scanForPeripheralsWithServices:@[controllerServiceUUID] options:nil];
NSArray *peripherals = [centralManager retrieveConnectedPeripheralsWithServices:@[controllerServiceUUID]];
for (CBPeripheral *peripheral in peripherals) {
Expand All @@ -109,6 +115,9 @@ - (void)scanForControllers {
}
}

#pragma mark - Swizzling

#ifndef STEAMCONTROLLER_NO_SWIZZLING
+ (void)load {
Method m1 = class_getClassMethod([GCController class], @selector(controllers));
Method m2 = class_getClassMethod([SteamControllerManager class], @selector(controllers));
Expand All @@ -126,6 +135,7 @@ + (void)load {
NSArray<GCController*>* steamControllers = [SteamControllerManager sharedManager].controllers;
return [originalControllers arrayByAddingObjectsFromArray:steamControllers];
}
#endif

@end

Expand Down
2 changes: 2 additions & 0 deletions SteamControllerTestApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ @implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
#ifndef STEAMCONTROLLER_NO_PRIVATE_API
[SteamControllerManager listenForConnections];
#endif
return YES;
}

Expand Down
2 changes: 1 addition & 1 deletion SteamControllerTestApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
<outlet property="delegate" destination="OBr-5A-1bC" id="hup-Rp-g8J"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Steam Controller" id="cVo-jK-rHu"/>
<navigationItem key="navigationItem" title="Game Controllers" id="cVo-jK-rHu"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="2bK-2B-ESZ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
4 changes: 2 additions & 2 deletions SteamControllerTestApp/ControllerTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, weak) IBOutlet XYView *leftTrackpadView, *rightTrackpadView, *dpadView;
@property (nonatomic, weak) IBOutlet UIButton *leftShoulder, *leftTrigger, *rightShoulder, *rightTrigger;
@property (nonatomic, weak) IBOutlet UIButton *buttonA, *buttonB, *buttonX, *buttonY, *pauseButton;
@property (nonatomic, weak) IBOutlet UIButton *backButton, *forwardButton;
@property (nonatomic, weak) IBOutlet UIButton *buttonA, *buttonB, *buttonX, *buttonY;
@property (nonatomic, weak) IBOutlet UIButton *backButton, *forwardButton, *pauseButton, *homeButton, *menuButton;
@property (nonatomic, retain, nullable) GCController *controller;

@end
Expand Down
63 changes: 43 additions & 20 deletions SteamControllerTestApp/ControllerTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@
#import "XYView.h"
#import "SteamController.h"

@implementation ControllerTableViewCell
// declare these selectors, so we can use them, and ARC wont complain
@interface NSObject()
-(GCControllerButtonInput*)buttonHome;
-(GCControllerButtonInput*)buttonMenu;
-(GCControllerButtonInput*)buttonOptions;
@end

@implementation ControllerTableViewCell {
GCControllerButtonInput* _buttonHome;
GCControllerButtonInput* _buttonMenu;
GCControllerButtonInput* _buttonOptions;
}

- (void)awakeFromNib {
[super awakeFromNib];
Expand All @@ -33,11 +44,30 @@ - (void)setController:(GCController *)controller {
controller.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad * _Nonnull gamepad, GCControllerElement * _Nonnull element) {
[self didUpdateElement:element inGamepad:gamepad];
};
controller.controllerPausedHandler = ^(GCController * _Nonnull controller) {
self.pauseButton.selected = YES;
[self.pauseButton performSelector:@selector(setSelected:) withObject:nil afterDelay:0.2];
};
if ([controller isKindOfClass:[SteamController class]]) {

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
_buttonHome = [_controller.extendedGamepad respondsToSelector:@selector(buttonHome)] ? [_controller.extendedGamepad buttonHome] : nil;
_buttonMenu = [_controller.extendedGamepad respondsToSelector:@selector(buttonMenu)] ? [_controller.extendedGamepad buttonMenu] : nil;
_buttonOptions = [_controller.extendedGamepad respondsToSelector:@selector(buttonOptions)] ? [_controller.extendedGamepad buttonOptions] : nil;
#pragma clang diagnostic pop

if (_buttonHome != nil) {
self.homeButton = self.pauseButton;
[self.homeButton setTitle:@"HOME" forState:UIControlStateNormal];
}
else if (_buttonMenu != nil) {
self.menuButton = self.pauseButton;
[self.menuButton setTitle:@"MENU" forState:UIControlStateNormal];
}
else {
controller.controllerPausedHandler = ^(GCController * _Nonnull controller) {
self.pauseButton.selected = YES;
[self.pauseButton performSelector:@selector(setSelected:) withObject:nil afterDelay:0.2];
};
}
// if steamButtonCombinationHandler == nil the STEAM/HOME button will act like a normal button, else it will have combo-only behaviour
if (_buttonHome == nil && [controller isKindOfClass:[SteamController class]]) {
SteamController *steamController = (SteamController*)controller;
steamController.steamButtonCombinationHandler = ^(SteamController *controller, SteamControllerButton button, BOOL isDown) {
NSLog(@"Steam combo with button %@ %s", NSStringFromSteamControllerButton(button), isDown?"DOWN":"UP");
Expand Down Expand Up @@ -91,20 +121,13 @@ - (void)didUpdateElement:(GCControllerElement*)element inGamepad:(GCExtendedGame
[self.rightTrackpadView setX:gamepad.rightThumbstick.xAxis.value Y:gamepad.rightThumbstick.yAxis.value];
}

if (@available(iOS 13, *)) {
if (element == gamepad.buttonOptions) {
self.backButton.selected = gamepad.buttonOptions.pressed;
} else if (element == gamepad.buttonMenu) {
self.forwardButton.selected = gamepad.buttonMenu.pressed;
}
} else {
if (element == gamepad.steamBackButton) {
self.backButton.selected = gamepad.steamBackButton.pressed;
} else if (element == gamepad.steamForwardButton) {
self.forwardButton.selected = gamepad.steamForwardButton.pressed;
}
}

if (element == _buttonHome)
self.homeButton.selected = _buttonHome.pressed;
if (element == _buttonOptions)
self.backButton.selected = _buttonOptions.pressed;
if (element == _buttonMenu)
self.forwardButton.selected = _buttonMenu.pressed;

if (@available(iOS 12.1, *)) {
if (element == gamepad.leftThumbstickButton) {
self.leftTrackpadView.backgroundColor = gamepad.leftThumbstickButton.pressed ? [UIColor darkGrayColor] : [UIColor lightGrayColor];
Expand Down
4 changes: 2 additions & 2 deletions SteamControllerTestApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app uses bluetooth to communicate with Steam controllers.</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -41,7 +43,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app uses bluetooth to communicate with Steam controllers.</string>
</dict>
</plist>
Loading

0 comments on commit e1ab229

Please sign in to comment.