Fix bug with unassigned axis, and add configurable deadzone option
This commit is contained in:
parent
a1993755b3
commit
4a015459c8
@ -136,6 +136,7 @@ enum {
|
||||
#define STICK_NUMBER @"stickNum" // Stick number 0 to 4
|
||||
#define STICK_AXBUT @"stickAxBt" // Axis or button number
|
||||
#define STICK_FUNCTION @"stickFunc" // Function of axis/button
|
||||
#define STICK_DEADZONE_SETTING @"JoystickAxesDeadzone" // Deadzone setting double 0.0 to 1.0.
|
||||
// shortcut to make code more readable when using enum as key for
|
||||
// an NSDictionary
|
||||
#define ENUMKEY(x) [NSString stringWithFormat: @"%d", x]
|
||||
@ -272,8 +273,6 @@ typedef struct
|
||||
- (BOOL) getButtonState:(int)function;
|
||||
- (double) getAxisState:(int)function;
|
||||
- (double) getSensitivity;
|
||||
- (double) deadZone;
|
||||
- (void) setDeadZone: (double)newValue;
|
||||
|
||||
// Transform raw axis state into actual axis state
|
||||
- (double) axisTransform: (double)axisvalue;
|
||||
|
@ -127,6 +127,10 @@ static id sSharedStickHandler = nil;
|
||||
case AXIS_ROLL:
|
||||
case AXIS_PITCH:
|
||||
case AXIS_YAW:
|
||||
if (axstate[function] == STICK_AXISUNASSIGNED)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return [self axisTransform:axstate[function]];
|
||||
default:
|
||||
return axstate[function];
|
||||
@ -575,7 +579,7 @@ static id sSharedStickHandler = nil;
|
||||
forKey:AXIS_SETTINGS];
|
||||
[defaults setObject:[self buttonFunctions]
|
||||
forKey:BUTTON_SETTINGS];
|
||||
|
||||
[defaults setFloat: deadzone forKey: STICK_DEADZONE_SETTING];
|
||||
[defaults synchronize];
|
||||
}
|
||||
|
||||
@ -612,6 +616,11 @@ static id sSharedStickHandler = nil;
|
||||
// Nothing to load - set useful defaults
|
||||
[self setDefaultMapping];
|
||||
}
|
||||
deadzone = [defaults oo_doubleForKey:STICK_DEADZONE_SETTING defaultValue:STICK_DEADZONE];
|
||||
if (deadzone < 0 || deadzone > 1)
|
||||
{
|
||||
deadzone = STICK_DEADZONE;
|
||||
}
|
||||
}
|
||||
|
||||
// These get overidden by subclasses
|
||||
|
Loading…
x
Reference in New Issue
Block a user