'Convert to Modern Objective-C Syntax'...
[enjoyable.git] / JSActionAnalog.m
1 //
2 // JSActionAnalog.m
3 // Enjoy
4 //
5 // Created by Sam McCall on 5/05/09.
6 //
7
8 @implementation JSActionAnalog
9
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]];
15 [subActions retain];
16 index = newIndex;
17 name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)];
18 }
19 return self;
20 }
21
22 -(id) findSubActionForValue: (IOHIDValueRef) value {
23 if ([subActions[2] active]) {
24 return subActions[2]; // TODO?
25 }
26
27 //Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]];
28
29 int raw = IOHIDValueGetIntegerValue(value);
30 double parsed = [self getRealValue: raw];
31
32 if(parsed < -0.3) // fixed?!
33 return subActions[0];
34 else if(parsed > 0.3)
35 return subActions[1];
36 return NULL;
37 }
38
39 -(void) notifyEvent: (IOHIDValueRef) value {
40 // Analog action is always active
41 [subActions[2] setActive: true];
42
43 int raw = IOHIDValueGetIntegerValue(value);
44 double parsed = [self getRealValue: raw];
45
46 [subActions[0] setActive: (parsed < -0.3)];
47 [subActions[1] setActive: (parsed > 0.3)];
48 }
49
50 -(double) getRealValue: (int)value {
51 double parsed = offset + scale * value;
52 return parsed;
53 }
54
55 @synthesize offset, scale;
56
57
58 @end