Skip to content

Commit

Permalink
Merge pull request #51 from Snoothy/fix/DeadZoneHelper
Browse files Browse the repository at this point in the history
Fix/dead zone helper
  • Loading branch information
Snoothy authored Oct 28, 2018
2 parents aa228b6 + 254262e commit 1e69e8b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [RC 0.5.2] - 2018-10-28
### Fixed
- Values other than 0 or 50 for DeadZone should now work properly - Maximum deflection should now be achievable again

## [RC 0.5.1] - 2018-10-28
### Added
- Interception Provider: Duplicate devices now have #2, #3 etc at end of name to differentiate them
- You no longer put a Provider into Bind Mode, you put a Device into Bind Mode (Bind Mode is still not implemented on the front end)
Expand Down
6 changes: 3 additions & 3 deletions UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ private void PrecalculateValues()
}
else
{
_deadzoneCutoff = (Constants.AxisMaxValue - (Constants.AxisMaxValue * (_percentage / 100.0)));
_scaleFactor = Math.Round(Constants.AxisMaxValue / _deadzoneCutoff);
_deadzoneCutoff = Constants.AxisMaxValue * (_percentage * 0.01);
_scaleFactor = Constants.AxisMaxValue / (Constants.AxisMaxValue - _deadzoneCutoff);
}
}

Expand All @@ -54,7 +54,7 @@ public long ApplyRangeDeadZone(long value)
var sign = Math.Sign(value);
var adjustedValue = (absValue - _deadzoneCutoff) * _scaleFactor;
var newValue = (long) Math.Round(adjustedValue * sign);
if (newValue == -32769) newValue = -32768;
if (newValue < -32768) newValue = -32768; // ToDo: Negative values can go up to -32777 (9 over), can this be improved?
//Debug.WriteLine($"Pre-DZ: {value}, Post-DZ: {newValue}, Cutoff: {_deadzoneCutoff}");
return newValue;
}
Expand Down
27 changes: 25 additions & 2 deletions UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public long DeadZoneHelperInitTests(long inputValue)
return helper.ApplyRangeDeadZone(inputValue);
}

[TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (50): Max returns Max")]
[TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (50): Min returns Min")]
[TestCase(0, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): 0 returns 0")]
[TestCase(16384, 50, ExpectedResult = 1, TestName = "DeadZoneHelper (50): Half Positive deflection is outside DZ")]
[TestCase(-16384, 50, ExpectedResult = -1, TestName = "DeadZoneHelper (50): Half Negative deflection is outside DZ")]
Expand All @@ -36,6 +34,31 @@ public long DeadZoneHelperValueTests(long inputValue, int percentage)
return helper.ApplyRangeDeadZone(inputValue);
}

[TestCase(Constants.AxisMaxValue, 10, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (10): Max returns Max")]
[TestCase(Constants.AxisMaxValue, 20, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (20): Max returns Max")]
[TestCase(Constants.AxisMaxValue, 30, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (30): Max returns Max")]
[TestCase(Constants.AxisMaxValue, 40, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (40): Max returns Max")]
[TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (50): Max returns Max")]
[TestCase(Constants.AxisMaxValue, 60, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (60): Max returns Max")]
[TestCase(Constants.AxisMaxValue, 70, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (70): Max returns Max")]
[TestCase(Constants.AxisMaxValue, 80, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (80): Max returns Max")]
[TestCase(Constants.AxisMaxValue, 90, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (90): Max returns Max")]

[TestCase(Constants.AxisMinValue, 10, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (10): Min returns Min")]
[TestCase(Constants.AxisMinValue, 20, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (20): Min returns Min")]
[TestCase(Constants.AxisMinValue, 30, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (30): Min returns Min")]
[TestCase(Constants.AxisMinValue, 40, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (40): Min returns Min")]
[TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (50): Min returns Min")]
[TestCase(Constants.AxisMinValue, 60, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (60): Min returns Min")]
[TestCase(Constants.AxisMinValue, 70, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (70): Min returns Min")]
[TestCase(Constants.AxisMinValue, 80, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (80): Min returns Min")]
[TestCase(Constants.AxisMinValue, 90, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (90): Min returns Min")]
public long DeadZoneHelperMaxTests(long inputValue, int percentage)
{
var helper = new DeadZoneHelper { Percentage = percentage };
return helper.ApplyRangeDeadZone(inputValue);
}

[TestCase(101, TestName = "DeadZoneHelper (101): Percentages over 100 should throw an exception")]
[TestCase(-1, TestName = "DeadZoneHelper (-1): Percentages below 0 should throw an exception")]
public void DeadZoneValidationTest(int percentage)
Expand Down

0 comments on commit 1e69e8b

Please sign in to comment.