Wii U and Wiimote controllers have the same vendorID and productID even though they have different controllers, they are only differentiable by their name. We do use the device name to find the OEDeviceDescription but we do not use it to find parsed bindings, as a result a Wii U controller may get the bindings or a Wiimote or vice-versa and not work properly. Add a flag to the controller representation to indicate whether the product name should be matched and make that part of the OEDeviceDescription -hash and -isEqual: methods.

This commit is contained in:
clobber
2019-12-06 20:12:02 -08:00
parent 2ab8a70db7
commit 3f00c3140a
3 changed files with 25 additions and 11 deletions
+1 -7
View File
@@ -86,22 +86,16 @@ static NSArray<OEControllerDescription *> *_knownControllerDescriptions;
// Some devices have no HID Product string descriptor
if(product == nil) product = @"Unknown USB Gamepad";
OEControllerDescription *potentialControllerDescription;
for (OEControllerDescription *controllerDescription in _knownControllerDescriptions) {
for (OEDeviceDescription *deviceDescription in [controllerDescription deviceDescriptions]) {
if (deviceDescription.vendorID != vendorID || deviceDescription.productID != productID)
continue;
if ([deviceDescription.product isEqualToString:product])
if (!deviceDescription.requiresNameMatch || [deviceDescription.product isEqualToString:product])
return [controllerDescription OE_controllerDescription];
potentialControllerDescription = controllerDescription;
}
}
if (potentialControllerDescription)
return [potentialControllerDescription OE_controllerDescription];
return [[OEControllerDescription alloc] OE_initWithVendorID:vendorID productID:productID name:product];
}
+1
View File
@@ -37,6 +37,7 @@
@property(readonly) NSUInteger vendorID;
@property(readonly) NSUInteger productID;
@property(readonly) uint32_t cookie;
@property(readonly) BOOL requiresNameMatch;
@property(readonly) NSString *identifier;
@property(readonly) NSString *controllerIdentifier;
+23 -4
View File
@@ -38,6 +38,7 @@
_vendorID = [representation[@"OEControllerVendorID"] integerValue];
_productID = [representation[@"OEControllerProductID"] integerValue];
_cookie = [representation[@"OEControllerCookie"] unsignedShortValue];
_requiresNameMatch = [representation[@"OEControllerRequiresNameMatch"] boolValue];
_genericDeviceIdentifier = [NSString stringWithFormat:@"OEGenericDeviceIdentifier_%ld_%ld", _vendorID, _productID];
_controllerDescription = controllerDescription;
}
@@ -66,17 +67,35 @@
- (NSUInteger)hash;
{
return _vendorID << 32 | _productID;
NSUInteger hash = _vendorID << 32 | _productID;
if (_requiresNameMatch) {
hash ^= _product.hash;
}
return hash;
}
- (BOOL)isEqual:(OEDeviceDescription *)object;
{
if(self == object) return YES;
if([object isKindOfClass:[OEDeviceDescription class]])
return _vendorID == object->_vendorID && _productID == object->_productID;
if(![object isKindOfClass:[OEDeviceDescription class]])
return NO;
return NO;
if (_vendorID != object->_vendorID)
return NO;
if (_productID != object->_productID)
return NO;
if (_requiresNameMatch != object->_requiresNameMatch)
return NO;
if (!_requiresNameMatch)
return YES;
return [_product isEqualToString:object->_product];
}
- (NSString *)description