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]];
16 name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)];
21 -(id) findSubActionForValue: (IOHIDValueRef) value {
22 if ([subActions[2] active]) {
23 return subActions[2]; // TODO?
26 //Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]];
28 int raw = IOHIDValueGetIntegerValue(value);
29 double parsed = [self getRealValue: raw];
31 if(parsed < -0.3) // fixed?!
38 -(void) notifyEvent: (IOHIDValueRef) value {
39 // Analog action is always active
40 [subActions[2] setActive: true];
42 int raw = IOHIDValueGetIntegerValue(value);
43 double parsed = [self getRealValue: raw];
45 [subActions[0] setActive: (parsed < -0.3)];
46 [subActions[1] setActive: (parsed > 0.3)];
49 -(double) getRealValue: (int)value {
50 double parsed = offset + scale * value;
54 @synthesize offset, scale;