X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=JSActionHat.m;h=2cac39c77c4a22e4148be01fe6e78c52d6a82540;hp=6ed0ad13443b3c19737d6c6367f646c341c7b63d;hb=0238d141f06420e1a73eccd14ca73a7e29ad2a69;hpb=c6fb77859e508aaef686b7a5a6a12abe29178708 diff --git a/JSActionHat.m b/JSActionHat.m index 6ed0ad1..2cac39c 100644 --- a/JSActionHat.m +++ b/JSActionHat.m @@ -29,20 +29,19 @@ static BOOL active_fourway[20] = { @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; } - (id)findSubActionForValue:(IOHIDValueRef)value { - int parsed = IOHIDValueGetIntegerValue(value); + long parsed = IOHIDValueGetIntegerValue(value); switch (IOHIDElementGetLogicalMax(IOHIDValueGetElement(value))) { case 7: // 8-way switch, 0-7. switch (parsed) { @@ -82,8 +81,8 @@ static BOOL active_fourway[20] = { } - (void)notifyEvent:(IOHIDValueRef)value { - int parsed = IOHIDValueGetIntegerValue(value); - int size = IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)); + long parsed = IOHIDValueGetIntegerValue(value); + long size = IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)); // Skip first row in table if 0 is not neutral. if (size & 1) { parsed++;