Skip to content

Commit

Permalink
constants!
Browse files Browse the repository at this point in the history
  • Loading branch information
citelao committed May 14, 2015
1 parent e5cf286 commit a56ba65
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
5 changes: 5 additions & 0 deletions JSActionAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@

@interface JSActionAnalog : JSAction {
double min, max;

double discreteThreshold;
double analogThreshold;
}

@property(readwrite) double min;
@property(readwrite) double max;
@property(readwrite) double discreteThreshold;
@property(readwrite) double analogThreshold;

- (id) initWithIndex: (int)newIndex;
-(double) getRealValue: (int) value;
Expand Down
37 changes: 20 additions & 17 deletions JSActionAnalog.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ @implementation JSActionAnalog

- (id) initWithIndex: (int)newIndex {
if(self = [super init]) {
subActions = [NSArray arrayWithObjects:
[[SubAction alloc] initWithIndex: 0 name: @"Low" base: self],
[[SubAction alloc] initWithIndex: 1 name: @"High" base: self],
[[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self],
nil
];
[subActions retain];
index = newIndex;
name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)];
}
subActions = [NSArray arrayWithObjects:
[[SubAction alloc] initWithIndex: 0 name: @"Low" base: self],
[[SubAction alloc] initWithIndex: 1 name: @"High" base: self],
[[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self],
nil
];
[subActions retain];
index = newIndex;
name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)];

analogThreshold = 0.1;
discreteThreshold = 0.3;
}
return self;
}

Expand All @@ -27,7 +30,7 @@ -(id) findSubActionForValue: (IOHIDValueRef) value {
double parsed = [self getRealValue: raw];

if ([[subActions objectAtIndex: 2] active]) {
if (fabs(parsed) < 0.3) {
if (fabs(parsed) < analogThreshold) {
return NULL;
}

Expand All @@ -36,9 +39,9 @@ -(id) findSubActionForValue: (IOHIDValueRef) value {

//Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]];

if(parsed < -0.3) // fixed?!
if(parsed < -discreteThreshold) // fixed?!
return [subActions objectAtIndex: 0];
else if(parsed > 0.3)
else if(parsed > discreteThreshold)
return [subActions objectAtIndex: 1];
return NULL;
}
Expand All @@ -47,18 +50,18 @@ -(void) notifyEvent: (IOHIDValueRef) value {
int raw = IOHIDValueGetIntegerValue(value);
double parsed = [self getRealValue: raw];

[[subActions objectAtIndex: 2] setActive: (fabs(parsed) > 0.3)];
[[subActions objectAtIndex: 2] setActive: (fabs(parsed) > analogThreshold)];

[[subActions objectAtIndex: 0] setActive: (parsed < -0.3)];
[[subActions objectAtIndex: 1] setActive: (parsed > 0.3)];
[[subActions objectAtIndex: 0] setActive: (parsed < -discreteThreshold)];
[[subActions objectAtIndex: 1] setActive: (parsed > discreteThreshold)];
}

-(double) getRealValue: (int)value {
double parsed = -1.0 + 2.0 * (value - min - 0.5) / (max - min);
return parsed;
}

@synthesize min, max;
@synthesize min, max, discreteThreshold, analogThreshold;


@end

0 comments on commit a56ba65

Please sign in to comment.