5 // Created by Sam McCall on 5/05/09.
8 @implementation JSActionAnalog
10 - (id) initWithIndex: (int)newIndex {
11 if(self = [super init]) {
12 subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Low" base: self],
13 [[SubAction alloc] initWithIndex: 1 name: @"High" base: self],
14 [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self]];
17 name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)];
22 -(id) findSubActionForValue: (IOHIDValueRef) value {
23 if ([subActions[2] active]) {
24 return subActions[2]; // TODO?
27 //Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]];
29 int raw = IOHIDValueGetIntegerValue(value);
30 double parsed = [self getRealValue: raw];
32 if(parsed < -0.3) // fixed?!
39 -(void) notifyEvent: (IOHIDValueRef) value {
40 // Analog action is always active
41 [subActions[2] setActive: true];
43 int raw = IOHIDValueGetIntegerValue(value);
44 double parsed = [self getRealValue: raw];
46 [subActions[0] setActive: (parsed < -0.3)];
47 [subActions[1] setActive: (parsed > 0.3)];
50 -(double) getRealValue: (int)value {
51 double parsed = offset + scale * value;
55 @synthesize offset, scale;