X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJDevice.m;h=b03898f906a380da8f804ef3eb947ac3d02b7630;hp=a5efd96fed9453e2afd4e76341282d1793cce1ef;hb=eb9ae7c6c0504f07fe058e9be43ec26763be4591;hpb=79b05c3cf1c75bc4f7078acde43aaf4215c6408a diff --git a/Classes/NJDevice.m b/Classes/NJDevice.m index a5efd96..b03898f 100644 --- a/Classes/NJDevice.m +++ b/Classes/NJDevice.m @@ -12,7 +12,7 @@ #import "NJInputHat.h" #import "NJInputButton.h" -static NSArray *InputsForElement(IOHIDDeviceRef device, id base) { +static NSArray *InputsForElement(IOHIDDeviceRef device, id parent) { CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); NSMutableArray *children = [NSMutableArray arrayWithCapacity:CFArrayGetCount(elements)]; @@ -20,14 +20,13 @@ static NSArray *InputsForElement(IOHIDDeviceRef device, id base) { int axes = 0; int hats = 0; - for (int i = 0; i < CFArrayGetCount(elements); i++) { + for (CFIndex i = 0; i < CFArrayGetCount(elements); i++) { IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i); - int type = IOHIDElementGetType(element); - unsigned usage = IOHIDElementGetUsage(element); - unsigned usagePage = IOHIDElementGetUsagePage(element); - long max = IOHIDElementGetPhysicalMax(element); - long min = IOHIDElementGetPhysicalMin(element); - CFStringRef elName = IOHIDElementGetName(element); + IOHIDElementType type = IOHIDElementGetType(element); + uint32_t usage = IOHIDElementGetUsage(element); + uint32_t usagePage = IOHIDElementGetUsagePage(element); + CFIndex max = IOHIDElementGetPhysicalMax(element); + CFIndex min = IOHIDElementGetPhysicalMin(element); NJInput *input = nil; @@ -36,23 +35,24 @@ static NSArray *InputsForElement(IOHIDDeviceRef device, id base) { || type == kIOHIDElementTypeInput_Button)) continue; - if (max - min == 1 || usagePage == kHIDPage_Button || type == kIOHIDElementTypeInput_Button) { - input = [[NJInputButton alloc] initWithName:(__bridge NSString *)elName - idx:++buttons - max:max]; + if (max - min == 1 + || usagePage == kHIDPage_Button + || type == kIOHIDElementTypeInput_Button) { + input = [[NJInputButton alloc] initWithElement:element + index:++buttons + parent:parent]; } else if (usage == kHIDUsage_GD_Hatswitch) { - input = [[NJInputHat alloc] initWithIndex:++hats]; + input = [[NJInputHat alloc] initWithElement:element + index:++hats + parent:parent]; } else if (usage >= kHIDUsage_GD_X && usage <= kHIDUsage_GD_Rz) { - input = [[NJInputAnalog alloc] initWithIndex:++axes - rawMin:min - rawMax:max]; + input = [[NJInputAnalog alloc] initWithElement:element + index:++axes + parent:parent]; } else { continue; } - // TODO(jfw): Should be moved into better constructors. - input.base = base; - input.cookie = IOHIDElementGetCookie(element); [children addObject:input]; } @@ -61,16 +61,16 @@ static NSArray *InputsForElement(IOHIDDeviceRef device, id base) { } @implementation NJDevice { - int vendorId; - int productId; + int _vendorId; + int _productId; } - (id)initWithDevice:(IOHIDDeviceRef)dev { - if ((self = [super initWithName:nil did:nil base:nil])) { + if ((self = [super initWithName:nil eid:nil parent:nil])) { self.device = dev; self.productName = (__bridge NSString *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductKey)); - vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)) intValue]; - productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)) intValue]; + _vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)) intValue]; + _productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)) intValue]; self.children = InputsForElement(dev, self); } return self; @@ -80,12 +80,8 @@ static NSArray *InputsForElement(IOHIDDeviceRef device, id base) { return [NSString stringWithFormat:@"%@ #%d", _productName, _index]; } -- (id)base { - return nil; -} - - (NSString *)uid { - return [NSString stringWithFormat: @"%d:%d:%d", vendorId, productId, _index]; + return [NSString stringWithFormat:@"%d:%d:%d", _vendorId, _productId, _index]; } - (NJInput *)findInputByCookie:(IOHIDElementCookie)cookie {