5 // Created by Sam McCall on 5/05/09.
10 #import "JSActionAnalog.h"
12 static float normalize(long p, long min, long max) {
13 return 2 * (p - min) / (float)(max - min) - 1;
16 @implementation JSActionAnalog {
22 - (id)initWithIndex:(int)index rawMin:(long)rawMin_ rawMax:(long)rawMax_ {
23 if ((self = [super init])) {
24 self.name = [[NSString alloc] initWithFormat: @"Axis %d", index];
25 self.children = @[[[JSAction alloc] initWithName:@"Low" base:self],
26 [[JSAction alloc] initWithName:@"High" base:self]];
33 - (id)findSubActionForValue:(IOHIDValueRef)value {
34 float mag = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax);
36 return self.children[0];
37 else if (mag > DEAD_ZONE)
38 return self.children[1];
43 - (void)notifyEvent:(IOHIDValueRef)value {
44 magnitude = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax);
45 [self.children[0] setActive:magnitude < -DEAD_ZONE];
46 [self.children[1] setActive:magnitude > DEAD_ZONE];