Slight refactoring of -OE_deviceHandlerClassForIOHIDDevice: (and removal of unused functions)

This commit is contained in:
Daniele Cattaneo
2019-08-31 00:05:24 +02:00
parent 1fb8e2cdff
commit 75d11f2436
10 changed files with 61 additions and 55 deletions
+1 -21
View File
@@ -60,26 +60,6 @@ NSString *const OEDeviceManagerDeviceHandlerUserInfoKey = @"OEDeviceMa
static void OEHandle_DeviceMatchingCallback(void *inContext, IOReturn inResult, void *inSender, IOHIDDeviceRef inIOHIDDeviceRef);
static BOOL OE_isWiimoteControllerName(NSString *name)
{
return [name hasPrefix:@"Nintendo RVL-CNT-01"];
}
static BOOL OE_isPS3ControllerName(NSString *name)
{
return [name hasPrefix:@"PLAYSTATION(R)3 Controller"];
}
static BOOL OE_isPS4ControllerName(NSString *name)
{
return [name hasPrefix:@"Wireless Controller"];
}
static BOOL OE_isXboxControllerName(NSString *name)
{
return [name isEqualToString:@"Controller"];
}
static const void * kOEBluetoothDevicePairSyncStyleKey = &kOEBluetoothDevicePairSyncStyleKey;
@interface IOBluetoothDevicePair (SyncStyle)
@@ -564,7 +544,7 @@ static const void * kOEBluetoothDevicePairSyncStyleKey = &kOEBluetoothDevicePair
// Check to make sure BT device name has Wiimote prefix. Note that there are multiple
// possible device names ("Nintendo RVL-CNT-01" and "Nintendo RVL-CNT-01-TR" at the
// time of writing), so we don't do an exact string match.
if(!OE_isWiimoteControllerName([obj name]))
if(![OEWiimoteHIDDeviceHandler canHandleDeviceWithName:[obj name]])
return;
[obj openConnection];
+2
View File
@@ -35,6 +35,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (id<OEHIDDeviceParser>)deviceParser;
+ (BOOL)canHandleDevice:(IOHIDDeviceRef)device;
- (instancetype)initWithDeviceDescription:(nullable OEDeviceDescription *)deviceDescription NS_UNAVAILABLE;
- (instancetype)initWithIOHIDDevice:(IOHIDDeviceRef)aDevice deviceDescription:(nullable OEDeviceDescription *)deviceDescription NS_DESIGNATED_INITIALIZER;
+5
View File
@@ -68,6 +68,11 @@ NS_ASSUME_NONNULL_BEGIN
return parser;
}
+ (BOOL)canHandleDevice:(IOHIDDeviceRef)device
{
return YES;
}
- (instancetype)initWithDeviceDescription:(nullable OEDeviceDescription *)deviceDescription
{
return nil;
+6 -34
View File
@@ -48,26 +48,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)OE_eventWithElement:(IOHIDElementRef)element value:(NSInteger)value;
@end
static BOOL OE_isWiimoteControllerName(NSString *name)
{
return [name hasPrefix:@"Nintendo RVL-CNT-01"];
}
static BOOL OE_isPS3ControllerName(NSString *name)
{
return [name hasPrefix:@"PLAYSTATION(R)3 Controller"];
}
static BOOL OE_isPS4ControllerName(NSString *name)
{
return [name hasPrefix:@"Wireless Controller"];
}
static BOOL OE_isXboxControllerName(NSString *name)
{
return [name isEqualToString:@"Controller"];
}
@interface _OEHIDDeviceAttributes : NSObject
- (instancetype)init NS_UNAVAILABLE;
@@ -115,24 +95,16 @@ static BOOL OE_isXboxControllerName(NSString *name)
- (Class)OE_deviceHandlerClassForIOHIDDevice:(IOHIDDeviceRef)aDevice
{
NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(aDevice, CFSTR(kIOHIDProductKey));
if(OE_isWiimoteControllerName(deviceName))
if([OEWiimoteHIDDeviceHandler canHandleDevice:aDevice])
return [OEWiimoteHIDDeviceHandler class];
else if(OE_isPS3ControllerName(deviceName))
else if([OEPS3HIDDeviceHandler canHandleDevice:aDevice])
return [OEPS3HIDDeviceHandler class];
else if(OE_isPS4ControllerName(deviceName))
else if([OEPS4HIDDeviceHandler canHandleDevice:aDevice])
return [OEPS4HIDDeviceHandler class];
else if(OE_isXboxControllerName(deviceName))
else if([OEXBox360HIDDeviceHander canHandleDevice:aDevice])
return [OEXBox360HIDDeviceHander class];
if ([deviceName isEqualToString:@"Pro Controller"]) {
NSNumber *vid = (__bridge id)IOHIDDeviceGetProperty(aDevice, CFSTR(kIOHIDVendorIDKey));
NSNumber *pid = (__bridge id)IOHIDDeviceGetProperty(aDevice, CFSTR(kIOHIDProductIDKey));
if ([vid integerValue] == 0x57E && [pid integerValue] == 0x2009) {
return [OESwitchProControllerHIDDeviceHandler class];
}
}
else if ([OESwitchProControllerHIDDeviceHandler canHandleDevice:aDevice])
return [OESwitchProControllerHIDDeviceHandler class];
return [OEHIDDeviceHandler class];
}
+6
View File
@@ -18,6 +18,12 @@ NS_ASSUME_NONNULL_BEGIN
uint8_t _reportBuffer[128];
}
+ (BOOL)canHandleDevice:(IOHIDDeviceRef)device
{
NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
return [deviceName hasPrefix:@"Wireless Controller"];
}
- (BOOL)connect
{
+6
View File
@@ -35,6 +35,12 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OEPS4HIDDeviceHandler {
}
+ (BOOL)canHandleDevice:(IOHIDDeviceRef)device
{
NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
return [deviceName hasPrefix:@"PLAYSTATION(R)3 Controller"];
}
- (BOOL)connect
{
// Unfortunately, HID stops responding after sending an output report.
@@ -177,6 +177,22 @@ static OEHACProControllerStickCalibration OEHACConvertCalibration(
}
+ (BOOL)canHandleDevice:(IOHIDDeviceRef)aDevice
{
NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(aDevice, CFSTR(kIOHIDProductKey));
if ([deviceName isEqualToString:@"Pro Controller"]) {
NSNumber *vid = (__bridge id)IOHIDDeviceGetProperty(aDevice, CFSTR(kIOHIDVendorIDKey));
NSNumber *pid = (__bridge id)IOHIDDeviceGetProperty(aDevice, CFSTR(kIOHIDProductIDKey));
if ([vid integerValue] == 0x57E && [pid integerValue] == 0x2009) {
return YES;
}
}
return NO;
}
- (instancetype)initWithIOHIDDevice:(IOHIDDeviceRef)aDevice deviceDescription:(nullable OEDeviceDescription *)deviceDescription
{
self = [super initWithIOHIDDevice:aDevice deviceDescription:deviceDescription];
@@ -64,6 +64,8 @@ extern NSString *const OEWiimoteDeviceHandlerDidDisconnectNotification;
@property(nonatomic, getter=isExpansionPortEnabled) BOOL expansionPortEnabled;
@property(nonatomic, getter=isExpansionPortAttached, readonly) BOOL expansionPortAttached;
+ (BOOL)canHandleDeviceWithName:(NSString *)name;
@end
NS_ASSUME_NONNULL_END
+11
View File
@@ -308,6 +308,17 @@ static void OE_wiimoteIOHIDReportCallback(void *context,
return parser;
}
+ (BOOL)canHandleDevice:(IOHIDDeviceRef)device
{
NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
return [self canHandleDeviceWithName:deviceName];
}
+ (BOOL)canHandleDeviceWithName:(NSString *)name
{
return [name hasPrefix:@"Nintendo RVL-CNT-01"];
}
- (instancetype)initWithIOHIDDevice:(IOHIDDeviceRef)aDevice deviceDescription:(nullable OEDeviceDescription *)deviceDescription
{
if((self = [super initWithIOHIDDevice:aDevice deviceDescription:deviceDescription]))
+6
View File
@@ -16,6 +16,12 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OEXBox360HIDDeviceHander
+ (BOOL)canHandleDevice:(IOHIDDeviceRef)device
{
NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
return [deviceName isEqualToString:@"Controller"];
}
- (void)setDeviceNumber:(NSUInteger)deviceNumber
{
// see: http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo#toc3