X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Joystick.m;h=2d50fa4d87124ae572c66b856b58236c96bf8c49;hp=8fa67919789fde788b7c9bd807e787d63f21146a;hb=d2b45b2c32dcc7c3cc553b62252ca48842e08d48;hpb=530009447c5bbd360ac5023979cffc6d32a28df3 diff --git a/Joystick.m b/Joystick.m index 8fa6791..2d50fa4 100644 --- a/Joystick.m +++ b/Joystick.m @@ -5,36 +5,26 @@ // Created by Sam McCall on 4/05/09. // -@implementation Joystick - +@implementation Joystick { + NSMutableArray *children; +} -@synthesize vendorId, productId, productName, name, index, device, children; +@synthesize vendorId, productId, productName, index, device, children; --(id)initWithDevice: (IOHIDDeviceRef) newDevice { - if(self=[super init]) { - children = [[NSMutableArray alloc]init]; - - device = newDevice; - productName = (NSString*)IOHIDDeviceGetProperty( device, CFSTR(kIOHIDProductKey) ); - vendorId = [(NSNumber*)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue]; - productId = [(NSNumber*)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue]; +- (id)initWithDevice: (IOHIDDeviceRef) newDevice { + if ((self = [super init])) { + children = [[NSMutableArray alloc] init]; - name = productName; + self.device = newDevice; + self.productName = (__bridge NSString *)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); + self.vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue]; + self.productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue]; } return self; } --(void) setIndex: (int) newIndex { - index = newIndex; - name = [[NSString alloc] initWithFormat: @"%@ #%d", productName, (index+1)]; -} --(int) index { - return index; -} - --(void) invalidate { - IOHIDDeviceClose(device, kIOHIDOptionsTypeNone); - NSLog(@"Removed a device: %@", [self name]); +- (NSString *)name { + return [[NSString alloc] initWithFormat: @"%@ #%d", productName, index + 1]; } -(id) base { @@ -42,13 +32,13 @@ } -(void) populateActions { - NSArray* elements = (NSArray*)IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); + NSArray* elements = (NSArray*)CFBridgingRelease(IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone)); int buttons = 0; int axes = 0; for(int i=0; i<[elements count]; i++) { - IOHIDElementRef element = (IOHIDElementRef)[elements objectAtIndex: i]; + IOHIDElementRef element = (__bridge IOHIDElementRef)elements[i]; int type = IOHIDElementGetType(element); int usage = IOHIDElementGetUsage(element); int usagePage = IOHIDElementGetUsagePage(element); @@ -70,7 +60,7 @@ } if((max - min == 1) || usagePage == kHIDPage_Button || type == kIOHIDElementTypeInput_Button) { - action = [[JSActionButton alloc] initWithIndex: buttons++ andName: (NSString *)elName]; + action = [[JSActionButton alloc] initWithIndex: buttons++ andName: (__bridge NSString *)elName]; [(JSActionButton*)action setMax: max]; } else if(usage == 0x39) action = [[JSActionHat alloc] init]; @@ -96,8 +86,8 @@ - (JSAction*) findActionByCookie: (void*) cookie { for(int i=0; i<[children count]; i++) - if([[children objectAtIndex:i]cookie] == cookie) - return (JSAction*)[children objectAtIndex:i]; + if([children[i]cookie] == cookie) + return (JSAction*)children[i]; return NULL; }