projects
/
enjoyable.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Allow JSON export of configurations.
[enjoyable.git]
/
JSActionAnalog.m
diff --git
a/JSActionAnalog.m
b/JSActionAnalog.m
index
7348e19
..
9c98f21
100644
(file)
--- a/
JSActionAnalog.m
+++ b/
JSActionAnalog.m
@@
-5,31
+5,33
@@
// Created by Sam McCall on 5/05/09.
//
// Created by Sam McCall on 5/05/09.
//
-// TODO: Dead zone should be configurable per-device.
#define DEAD_ZONE 0.3
#import "JSActionAnalog.h"
#define DEAD_ZONE 0.3
#import "JSActionAnalog.h"
+static float normalize(long p, long min, long max) {
+ return 2 * (p - min) / (float)(max - min) - 1;
+}
+
@implementation JSActionAnalog {
float magnitude;
@implementation JSActionAnalog {
float magnitude;
+ long rawMin;
+ long rawMax;
}
}
-@synthesize offset, scale;
-
-- (id)initWithIndex:(int)newIndex offset:(float)offset_ scale:(float)scale_ {
+- (id)initWithIndex:(int)index rawMin:(long)rawMin_ rawMax:(long)rawMax_ {
if ((self = [super init])) {
if ((self = [super init])) {
+ self.name = [[NSString alloc] initWithFormat: @"Axis %d", index];
self.children = @[[[JSAction alloc] initWithName:@"Low" base:self],
[[JSAction alloc] initWithName:@"High" base:self]];
self.children = @[[[JSAction alloc] initWithName:@"Low" base:self],
[[JSAction alloc] initWithName:@"High" base:self]];
- self.offset = offset_;
- self.scale = scale_;
- self.name = [[NSString alloc] initWithFormat: @"Axis %d", newIndex];
+ rawMax = rawMax_;
+ rawMin = rawMin_;
}
return self;
}
- (id)findSubActionForValue:(IOHIDValueRef)value {
}
return self;
}
- (id)findSubActionForValue:(IOHIDValueRef)value {
- int raw = IOHIDValueGetIntegerValue(value);
- float mag = offset + scale * raw;
+ float mag = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax);
if (mag < -DEAD_ZONE)
return self.children[0];
else if (mag > DEAD_ZONE)
if (mag < -DEAD_ZONE)
return self.children[0];
else if (mag > DEAD_ZONE)
@@
-39,8
+41,7
@@
}
- (void)notifyEvent:(IOHIDValueRef)value {
}
- (void)notifyEvent:(IOHIDValueRef)value {
- int raw = IOHIDValueGetIntegerValue(value);
- magnitude = offset + scale * raw;
+ magnitude = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax);
[self.children[0] setActive:magnitude < -DEAD_ZONE];
[self.children[1] setActive:magnitude > DEAD_ZONE];
}
[self.children[0] setActive:magnitude < -DEAD_ZONE];
[self.children[1] setActive:magnitude > DEAD_ZONE];
}