@interface JSAction : NSObject
@property (assign) void *cookie;
-@property (assign) int index;
@property (copy) NSArray *children;
@property (weak) id base;
@property (copy) NSString *name;
@implementation JSAction
@synthesize cookie;
-@synthesize index;
@synthesize children;
@synthesize base;
@synthesize name;
if ((self = [super init])) {
self.children = @[[[JSAction alloc] initWithName:@"Low" base:self],
[[JSAction alloc] initWithName:@"High" base:self]];
- self.index = newIndex;
self.offset = offset_;
self.scale = scale_;
- self.name = [[NSString alloc] initWithFormat: @"Axis %d", self.index];
+ self.name = [[NSString alloc] initWithFormat: @"Axis %d", newIndex];
}
return self;
}
- (id)initWithName:(NSString *)name_ idx:(int)idx max:(int)max_ {
if ((self = [super init])) {
- self.index = idx;
self.max = max_;
if (name_.length)
- self.name = [NSString stringWithFormat:@"Button %d - %@", self.index, name_];
+ self.name = [NSString stringWithFormat:@"Button %d - %@", idx, name_];
else
- self.name = [NSString stringWithFormat:@"Button %d", self.index];
+ self.name = [NSString stringWithFormat:@"Button %d", idx];
}
return self;
}
@interface JSActionHat : JSAction
+- (id)initWithIndex:(int)index;
+
@end
@implementation JSActionHat
-- (id)init {
+- (id)initWithIndex:(int)index {
if ((self = [super init])) {
- self.children = @[[[JSAction alloc] initWithName:@"Up" base: self],
- [[JSAction alloc] initWithName:@"Down" base: self],
- [[JSAction alloc] initWithName:@"Left" base: self],
- [[JSAction alloc] initWithName:@"Right" base: self]];
- // TODO(jfw): Should have an indexed name, like everything else.
- self.name = @"Hat switch";
+ self.children = @[[[JSAction alloc] initWithName:@"Up" base:self],
+ [[JSAction alloc] initWithName:@"Down" base:self],
+ [[JSAction alloc] initWithName:@"Left" base:self],
+ [[JSAction alloc] initWithName:@"Right" base:self]];
+ self.name = [NSString stringWithFormat:@"Hat Switch %d", index];
}
return self;
}
int buttons = 0;
int axes = 0;
+ int hats = 0;
for (int i = 0; i < CFArrayGetCount(elements); i++) {
IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
idx:++buttons
max:max];
} else if (usage == kHIDUsage_GD_Hatswitch) {
- action = [[JSActionHat alloc] init];
+ action = [[JSActionHat alloc] initWithIndex:++hats];
} else if (usage >= kHIDUsage_GD_X && usage <= kHIDUsage_GD_Rz) {
// TODO(jfw): Scaling equation doesn't seem right if min != 0.
action = [[JSActionAnalog alloc] initWithIndex:++axes