Forked Enjoy, mouse movement
[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 = [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],
16 nil
17 ];
18 [subActions retain];
19 index = newIndex;
20 name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)];
21 }
22 return self;
23 }
24
25 -(id) findSubActionForValue: (IOHIDValueRef) value {
26 if ([[subActions objectAtIndex: 2] active]) {
27 return [subActions objectAtIndex: 2]; // TODO?
28 }
29
30 //Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]];
31
32 int raw = IOHIDValueGetIntegerValue(value);
33 double parsed = offset + scale * raw;
34
35 if(parsed < -0.3) // fixed?!
36 return [subActions objectAtIndex: 0];
37 else if(parsed > 0.3)
38 return [subActions objectAtIndex: 1];
39 return NULL;
40 }
41
42 -(void) notifyEvent: (IOHIDValueRef) value {
43 // Analog action is always active
44 [[subActions objectAtIndex: 2] setActive: true];
45
46 int raw = IOHIDValueGetIntegerValue(value);
47 double parsed = offset + scale * raw;
48
49 [[subActions objectAtIndex: 0] setActive: (parsed < -0.3)];
50 [[subActions objectAtIndex: 1] setActive: (parsed > 0.3)];
51 }
52
53 @synthesize offset, scale;
54
55
56 @end