mirror of
https://github.com/OpenEmu/OpenEmu-SDK.git
synced 2025-11-01 10:15:12 +00:00
Enable auto-calibration only when the range of inputs seen is larger than the deadzone.
Fixes controllers that exhibit some jitter when the sticks are resting (for example the PS4 controller)
This commit is contained in:
@@ -97,7 +97,7 @@ static inline OEAutoCalibration OEAutoCalibrationMake(int min, int max)
|
||||
- (OEAutoCalibration)calibrationForControlCookie:(NSUInteger)controlCookie;
|
||||
- (void)setCalibration:(OEAutoCalibration)calibration forControlCookie:(NSUInteger)controlCookie;
|
||||
|
||||
- (CGFloat)scaledValue:(CGFloat)rawValue forAxis:(OEHIDEventAxis)axis controlCookie:(NSUInteger)cookie withMiddle:(CGFloat)middle;
|
||||
- (CGFloat)scaledValue:(CGFloat)rawValue forAxis:(OEHIDEventAxis)axis controlCookie:(NSUInteger)cookie withDefaultMin:(CGFloat)amin max:(CGFloat)amax;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -216,10 +216,11 @@ static NSString *const OEDeviceHandlerUniqueIdentifierKey = @"OEDeviceHandlerUni
|
||||
_deadZones[@([[controlDesc genericEvent] cookie])] = @(deadZone);
|
||||
}
|
||||
|
||||
- (CGFloat)scaledValue:(CGFloat)rawValue forAxis:(OEHIDEventAxis)axis controlCookie:(NSUInteger)cookie withMiddle:(CGFloat)middle
|
||||
- (CGFloat)scaledValue:(CGFloat)rawValue forAxis:(OEHIDEventAxis)axis controlCookie:(NSUInteger)cookie withDefaultMin:(CGFloat)amin max:(CGFloat)amax
|
||||
{
|
||||
FIXME("move all scaling logic here from OEHIDEvent in a *clean* way");
|
||||
OEAutoCalibration cal = [self calibrationForControlCookie:cookie];
|
||||
int middle = (amin + amax) / 2.0;
|
||||
BOOL changed = NO;
|
||||
if (rawValue < cal.min)
|
||||
{
|
||||
@@ -237,6 +238,11 @@ static NSString *const OEDeviceHandlerUniqueIdentifierKey = @"OEDeviceHandlerUni
|
||||
cookie, rawValue, cal.min, cal.max);
|
||||
[self setCalibration:cal forControlCookie:cookie];
|
||||
}
|
||||
|
||||
CGFloat deadZone = [self deadZoneForControlCookie:cookie];
|
||||
if (((CGFloat)(cal.max - cal.min) / (amax - amin)) < (deadZone * 1.5)) {
|
||||
return -100; // not enough samples
|
||||
}
|
||||
|
||||
if(cal.min >= 0)
|
||||
{
|
||||
@@ -245,9 +251,6 @@ static NSString *const OEDeviceHandlerUniqueIdentifierKey = @"OEDeviceHandlerUni
|
||||
cal.max -= middle;
|
||||
}
|
||||
|
||||
if (cal.min == cal.max)
|
||||
return -100; // not enough samples
|
||||
|
||||
if(rawValue < 0) return -rawValue / (CGFloat)cal.min;
|
||||
else if(rawValue > 0) return rawValue / (CGFloat)cal.max;
|
||||
|
||||
|
||||
@@ -744,7 +744,7 @@ static CGEventSourceRef _keyboardEventSource;
|
||||
NSInteger min = IOHIDElementGetLogicalMin(elem);
|
||||
NSInteger max = IOHIDElementGetLogicalMax(elem);
|
||||
CGFloat deadZone = [aDeviceHandler deadZoneForControlCookie:_cookie];
|
||||
CGFloat scaledValue = [aDeviceHandler scaledValue:value forAxis:_data.axis.axis controlCookie:_cookie withMiddle:(min+max)/2+1];
|
||||
CGFloat scaledValue = [aDeviceHandler scaledValue:value forAxis:_data.axis.axis controlCookie:_cookie withDefaultMin:min max:max];
|
||||
if (scaledValue < -1.001 || scaledValue > 1.001) {
|
||||
/* device handler does not handle scaling */
|
||||
scaledValue = _OEScaledValueForAxis(min,
|
||||
|
||||
@@ -918,8 +918,7 @@ enum {
|
||||
|
||||
- (void)OE_dispatchAxisEventWithAxis:(OEHIDEventAxis)axis minimum:(NSInteger)minimum value:(NSInteger)value maximum:(NSInteger)maximum timestamp:(NSTimeInterval)timestamp cookie:(NSUInteger)cookie;
|
||||
{
|
||||
CGFloat middle = (minimum + maximum) * 0.5;
|
||||
CGFloat scaledValue = [self scaledValue:value forAxis:axis controlCookie:cookie withMiddle:middle];
|
||||
CGFloat scaledValue = [self scaledValue:value forAxis:axis controlCookie:cookie withDefaultMin:minimum max:maximum];
|
||||
[self dispatchEvent:[OEHIDEvent axisEventWithDeviceHandler:self timestamp:timestamp axis:axis value:scaledValue cookie:cookie]];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user