X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=JSActionAnalog.m;fp=JSActionAnalog.m;h=a1c57e8533c2668737b265a9cc1902471ed939e5;hp=0000000000000000000000000000000000000000;hb=530009447c5bbd360ac5023979cffc6d32a28df3;hpb=5f07baa8cb03a2f6aa06338bfeb31dad3c3ca29f diff --git a/JSActionAnalog.m b/JSActionAnalog.m new file mode 100644 index 0000000..a1c57e8 --- /dev/null +++ b/JSActionAnalog.m @@ -0,0 +1,56 @@ +// +// JSActionAnalog.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +@implementation JSActionAnalog + +- (id) initWithIndex: (int)newIndex { + if(self = [super init]) { + subActions = [NSArray arrayWithObjects: + [[SubAction alloc] initWithIndex: 0 name: @"Low" base: self], + [[SubAction alloc] initWithIndex: 1 name: @"High" base: self], + [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self], + nil + ]; + [subActions retain]; + index = newIndex; + name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)]; + } + return self; +} + +-(id) findSubActionForValue: (IOHIDValueRef) value { + if ([[subActions objectAtIndex: 2] active]) { + return [subActions objectAtIndex: 2]; // TODO? + } + + //Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]]; + + int raw = IOHIDValueGetIntegerValue(value); + double parsed = offset + scale * raw; + + if(parsed < -0.3) // fixed?! + return [subActions objectAtIndex: 0]; + else if(parsed > 0.3) + return [subActions objectAtIndex: 1]; + return NULL; +} + +-(void) notifyEvent: (IOHIDValueRef) value { + // Analog action is always active + [[subActions objectAtIndex: 2] setActive: true]; + + int raw = IOHIDValueGetIntegerValue(value); + double parsed = offset + scale * raw; + + [[subActions objectAtIndex: 0] setActive: (parsed < -0.3)]; + [[subActions objectAtIndex: 1] setActive: (parsed > 0.3)]; +} + +@synthesize offset, scale; + + +@end