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