// 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 {
}
-(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[i];
+ IOHIDElementRef element = (__bridge IOHIDElementRef)elements[i];
int type = IOHIDElementGetType(element);
int usage = IOHIDElementGetUsage(element);
int usagePage = IOHIDElementGetUsagePage(element);
}
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];