diff options
Diffstat (limited to 'grapher/Models')
19 files changed, 269 insertions, 19 deletions
diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index eb30864..d986369 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -286,7 +286,8 @@ namespace grapher.Models accelCalculator.DPI, accelCalculator.PollRate, autoWriteMenuItem, - showLastMouseMoveMenuItem); + showLastMouseMoveMenuItem, + showVelocityGainToolStripMenuItem); return new AccelGUI( form, diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index a140c90..f2a6c7c 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -62,16 +62,47 @@ namespace grapher.Models.Calculations double lastInputMagnitude = 0; double lastOutputMagnitude = 0; + double maxRatio = 0.0; + double minRatio = Double.MaxValue; + double maxSlope = 0.0; + double minSlope = Double.MaxValue; + foreach (var magnitudeDatum in magnitudeData) { + if (magnitudeDatum.magnitude <=0) + { + continue; + } + var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime); var outMagnitude = Magnitude(output.Item1, output.Item2); + var ratio = magnitudeDatum.magnitude > 0 ? outMagnitude / magnitudeDatum.magnitude : starter; + + if (ratio > maxRatio) + { + maxRatio = ratio; + } + + if (ratio < minRatio) + { + minRatio = ratio; + } var inDiff = magnitudeDatum.magnitude - lastInputMagnitude; var outDiff = outMagnitude - lastOutputMagnitude; var slope = inDiff > 0 ? outDiff / inDiff : starter; + if (slope > maxSlope) + { + maxSlope = slope; + } + + if (slope < minSlope) + { + minSlope = slope; + } + if (!data.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) { data.AccelPoints.Add(magnitudeDatum.magnitude, ratio); @@ -92,6 +123,10 @@ namespace grapher.Models.Calculations } data.OrderedVelocityPointsList.AddRange(data.VelocityPoints.Values.ToList()); + data.MaxAccel = maxRatio; + data.MinAccel = minRatio; + data.MaxGain = maxSlope; + data.MinGain = minSlope; } public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, DriverSettings settings, ICollection<MagnitudeData> magnitudeData) @@ -100,6 +135,12 @@ namespace grapher.Models.Calculations double lastOutputMagnitudeX = 0; double lastOutputMagnitudeY = 0; + double maxRatio = 0.0; + double minRatio = Double.MaxValue; + double maxSlope = 0.0; + double minSlope = Double.MaxValue; + + Sensitivity = GetSens(ref settings); foreach (var magnitudeDatum in magnitudeData) @@ -118,6 +159,26 @@ namespace grapher.Models.Calculations var xRatio = settings.sensitivity.x * ratio; var yRatio = settings.sensitivity.y * ratio; + if (xRatio > maxRatio) + { + maxRatio = xRatio; + } + + if (xRatio < minRatio) + { + minRatio = xRatio; + } + + if (yRatio > maxRatio) + { + maxRatio = yRatio; + } + + if (yRatio < minRatio) + { + minRatio = yRatio; + } + if (!data.X.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) { data.X.AccelPoints.Add(magnitudeDatum.magnitude, xRatio); @@ -137,6 +198,26 @@ namespace grapher.Models.Calculations var xSlope = inDiff > 0 ? xOutDiff / inDiff : settings.sensitivity.x; var ySlope = inDiff > 0 ? yOutDiff / inDiff : settings.sensitivity.y; + if (xSlope > maxSlope) + { + maxSlope = xSlope; + } + + if (xSlope < minSlope) + { + minSlope = xSlope; + } + + if (ySlope > maxSlope) + { + maxSlope = ySlope; + } + + if (ySlope < minSlope) + { + minSlope = ySlope; + } + if (!data.X.VelocityPoints.ContainsKey(magnitudeDatum.magnitude)) { data.X.VelocityPoints.Add(magnitudeDatum.magnitude, xOut); @@ -163,6 +244,10 @@ namespace grapher.Models.Calculations } data.Combined.OrderedVelocityPointsList.AddRange(data.Combined.VelocityPoints.Values.ToList()); + data.Combined.MaxAccel = maxRatio; + data.Combined.MinAccel = minRatio; + data.Combined.MaxGain = maxSlope; + data.Combined.MinGain = minSlope; } public ReadOnlyCollection<MagnitudeData> GetMagnitudes() diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index fbf1944..54685a2 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -23,6 +23,14 @@ namespace grapher.Models.Calculations public SortedDictionary<double, double> AccelPoints { get; } + public double MaxAccel { get; set; } + + public double MinAccel { get; set; } + + public double MaxGain { get; set; } + + public double MinGain { get; set; } + public SortedDictionary<double, double> VelocityPoints { get; } public SortedDictionary<double, double> GainPoints { get; } @@ -54,7 +62,6 @@ namespace grapher.Models.Calculations { var velIdx = GetVelocityIndex(outVelocityValue); - velIdx = Math.Min(velIdx, VelocityPoints.Count - 1); values = (VelocityPoints.ElementAt(velIdx).Key, AccelPoints.ElementAt(velIdx).Value, GainPoints.ElementAt(velIdx).Value); OutVelocityToPoints.Add(outVelocityValue, values); return values; @@ -81,6 +88,7 @@ namespace grapher.Models.Calculations } velIdx = Math.Min(velIdx, VelocityPoints.Count - 1); + velIdx = Math.Max(velIdx, 0); return velIdx; } diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index d22ab78..a0e99c8 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -149,6 +149,11 @@ namespace grapher ChartState.Calculate(accel, settings); } + public void SetLogarithmic(bool x, bool y) + { + ChartState.SetLogarithmic(x, y); + } + private static void SetupCharts( ChartXY sensitivityChart, ChartXY velocityChart, diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index ea67e83..e1c7d01 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -100,5 +100,29 @@ namespace grapher.Models.Charts.ChartState GainChart.Hide(); form.Height = SensitivityChart.Height + borderHeight; } + + public void SetLogarithmic(bool x, bool y) + { + if (x) + { + ChartXY.SetLogarithmic(SensitivityChart.ChartX); + ChartXY.SetLogarithmic(GainChart.ChartX); + } + else + { + ChartXY.SetStandard(SensitivityChart.ChartX); + ChartXY.SetStandard(GainChart.ChartX); + } + + if (y) + { + ChartXY.SetLogarithmic(SensitivityChart.ChartY); + ChartXY.SetLogarithmic(GainChart.ChartY); + } + { + ChartXY.SetStandard(SensitivityChart.ChartY); + ChartXY.SetStandard(GainChart.ChartY); + } + } } } diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index 17cd68a..f4b6b8f 100644 --- a/grapher/Models/Charts/ChartState/CombinedState.cs +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -36,6 +36,8 @@ namespace grapher.Models.Charts.ChartState SensitivityChart.Bind(Data.Combined.AccelPoints); VelocityChart.Bind(Data.Combined.VelocityPoints); GainChart.Bind(Data.Combined.GainPoints); + SensitivityChart.SetMinMax(Data.Combined.MinAccel, Data.Combined.MaxAccel); + GainChart.SetMinMax(Data.Combined.MinGain, Data.Combined.MaxGain); } public override void Calculate(ManagedAccel accel, DriverSettings settings) diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index bbc0c28..6bfaac5 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -38,6 +38,8 @@ namespace grapher.Models.Charts.ChartState SensitivityChart.BindXYCombined(Data.X.AccelPoints, Data.Y.AccelPoints); VelocityChart.BindXYCombined(Data.X.VelocityPoints, Data.Y.VelocityPoints); GainChart.BindXYCombined(Data.X.GainPoints, Data.Y.GainPoints); + SensitivityChart.SetMinMax(Data.Combined.MinAccel, Data.Combined.MaxAccel); + GainChart.SetMinMax(Data.Combined.MinGain, Data.Combined.MaxGain); } public override void Calculate(ManagedAccel accel, DriverSettings settings) diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index 69dc335..b775853 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -65,6 +65,9 @@ namespace grapher.Models.Charts.ChartState SensitivityChart.BindXY(Data.X.AccelPoints, Data.Y.AccelPoints); VelocityChart.BindXY(Data.X.VelocityPoints, Data.Y.VelocityPoints); GainChart.BindXY(Data.X.GainPoints, Data.Y.GainPoints); + + SensitivityChart.SetMinMaxXY(Data.X.MinAccel, Data.X.MaxAccel, Data.Y.MinAccel, Data.Y.MaxAccel); + GainChart.SetMinMaxXY(Data.X.MinGain, Data.X.MaxGain, Data.Y.MinGain, Data.Y.MaxGain); } public override void Calculate(ManagedAccel accel, DriverSettings settings) diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index fdd0258..c30c993 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -100,6 +100,9 @@ namespace grapher chart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; chart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; + chart.ChartAreas[0].AxisX.LabelStyle.Format = "0.##"; + chart.ChartAreas[0].AxisY.LabelStyle.Format = "0.##"; + chart.ChartAreas[0].CursorY.Interval = 0.001; chart.ChartAreas[0].CursorX.AutoScroll = true; @@ -128,10 +131,29 @@ namespace grapher pointTwo.Get(out x, out y); chart.Series[3].Points.DataBindXY(x, y); } - chart.Update(); } } + public static void SetLogarithmic(Chart chart) + { + /* + chart.ChartAreas[0].AxisX.Minimum = 0.001; + chart.ChartAreas[0].AxisX.Maximum = 3500; + chart.ChartAreas[0].AxisY.Minimum = 0.001; + chart.ChartAreas[0].AxisY.Maximum = 10; + chart.ChartAreas[0].AxisX.IsLogarithmic = true; + chart.ChartAreas[0].AxisY.IsLogarithmic = true; + */ + } + + public static void SetStandard(Chart chart) + { + /* + chart.ChartAreas[0].AxisX.IsLogarithmic = false; + chart.ChartAreas[0].AxisY.IsLogarithmic = false; + */ + } + public void SetPointBinds(PointData combined, PointData x, PointData y) { CombinedPointData = combined; @@ -168,18 +190,47 @@ namespace grapher public void Bind(IDictionary data) { ChartX.Series[0].Points.DataBindXY(data.Keys, data.Values); + ChartX.Series[2].IsVisibleInLegend = false; + ChartX.Series[2].Points.Clear(); } public void BindXY(IDictionary dataX, IDictionary dataY) { ChartX.Series[0].Points.DataBindXY(dataX.Keys, dataX.Values); ChartY.Series[0].Points.DataBindXY(dataY.Keys, dataY.Values); + ChartX.Series[2].IsVisibleInLegend = false; + ChartX.Series[2].Points.Clear(); } public void BindXYCombined(IDictionary dataX, IDictionary dataY) { ChartX.Series[0].Points.DataBindXY(dataX.Keys, dataX.Values); ChartX.Series[2].Points.DataBindXY(dataY.Keys, dataY.Values); + ChartX.Series[2].IsVisibleInLegend = true; + } + + public void SetMinMax(double min, double max) + { + if (min < max) + { + ChartX.ChartAreas[0].AxisY.Minimum = min; + ChartX.ChartAreas[0].AxisY.Maximum = max; + } + } + + public void SetMinMaxXY(double minX, double maxX, double minY, double maxY) + { + if (minX < maxX) + { + ChartX.ChartAreas[0].AxisY.Minimum = minX; + ChartX.ChartAreas[0].AxisY.Maximum = maxX; + } + + if (minY < maxY) + { + ChartY.ChartAreas[0].AxisY.Minimum = minY; + ChartY.ChartAreas[0].AxisY.Maximum = maxY; + } } public void SetCombined() diff --git a/grapher/Models/Mouse/MouseData.cs b/grapher/Models/Mouse/MouseData.cs new file mode 100644 index 0000000..e59a969 --- /dev/null +++ b/grapher/Models/Mouse/MouseData.cs @@ -0,0 +1,49 @@ +using System; + +namespace grapher.Models.Mouse +{ + public class MouseData + { + #region Constructors + + public MouseData() + { + Lock = new Object(); + X = 0; + Y = 0; + } + + #endregion Constructors + + #region Properties + + public Object Lock { get; } + + private int X { get; set; } + private int Y { get; set; } + + public void Set(int x, int y) + { + lock (Lock) + { + X = x; + Y = y; + } + } + + #endregion Properties + + #region Methods + + public void Get(out int x, out int y) + { + lock (Lock) + { + x = X; + y = Y; + } + } + + #endregion Methods + } +} diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 405110e..86b1c2e 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -682,6 +682,7 @@ namespace grapher.Models.Mouse ContainingForm = containingForm; Display = display; AccelCharts = accelCharts; + MouseData = new MouseData(); RAWINPUTDEVICE device = new RAWINPUTDEVICE(); device.WindowHandle = ContainingForm.Handle; @@ -705,6 +706,8 @@ namespace grapher.Models.Mouse private AccelCharts AccelCharts { get; } + private MouseData MouseData { get; } + private double PollTime { get; } #endregion Properties diff --git a/grapher/Models/Mouse/PointData.cs b/grapher/Models/Mouse/PointData.cs index 374c52e..e3f44ea 100644 --- a/grapher/Models/Mouse/PointData.cs +++ b/grapher/Models/Mouse/PointData.cs @@ -9,8 +9,8 @@ namespace grapher.Models.Mouse public PointData() { Lock = new Object(); - X = new double[] { 0 }; - Y = new double[] { 0 }; + X = new double[] { 0.01 }; + Y = new double[] { 0.01 }; } #endregion Constructors diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index bc0d368..11a7f10 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -24,6 +24,7 @@ namespace grapher.Models.Options OptionsTitle.Top = TopAnchor; IsTitleMode = true; + Hidden = false; SetRegularMode(); } @@ -35,9 +36,10 @@ namespace grapher.Models.Options public AccelTypeOptions Options { get; } - public bool IsTitleMode { get; private set; } + private bool Hidden { get; set; } + public void SetRegularMode() { if (IsTitleMode) @@ -67,6 +69,7 @@ namespace grapher.Models.Options OptionsTitle.Hide(); ActiveValuesTitle.Hide(); Options.Hide(); + Hidden = true; } public void Show() @@ -78,6 +81,7 @@ namespace grapher.Models.Options ActiveValuesTitle.Show(); Options.Show(); + Hidden = false; } public void DisplayTitle() @@ -106,7 +110,10 @@ namespace grapher.Models.Options public void SetActiveValues(int mode, AccelArgs args) { - Options.SetActiveValues(mode, args); + if (!Hidden) + { + Options.SetActiveValues(mode, args); + } } public void AlignActiveValues() diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 917ac5c..9bd42f5 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -17,10 +17,10 @@ namespace grapher new LinearLayout(), new ClassicLayout(), new NaturalLayout(), + new NaturalGainLayout(), new PowerLayout(), new LogarithmLayout(), - new NaturalGainLayout(), - new SigmoidGainLayout(), + new MotivityLayout(), new OffLayout() }.ToDictionary(k => k.Name); @@ -63,6 +63,7 @@ namespace grapher #endregion Constructors #region Properties + public AccelCharts AccelCharts { get; } public Button WriteButton { get; } @@ -179,11 +180,12 @@ namespace grapher public void SetActiveValues(int index, AccelArgs args) { - var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name; - AccelTypeActiveValue.SetValue(name); + AccelerationType = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value; + AccelTypeActiveValue.SetValue(AccelerationType.Name); + AccelDropdown.SelectedIndex = AccelerationType.Index; Weight.SetActiveValue(args.weight); - Cap.SetActiveValues(args.gainCap, args.scaleCap, args.gainCap > 0); + Cap.SetActiveValues(args.gainCap, args.scaleCap, args.gainCap > 0 || args.scaleCap <= 0); Offset.SetActiveValue(args.offset, args.legacy_offset); Acceleration.SetActiveValue(args.accel); LimitOrExponent.SetActiveValue(args.exponent); diff --git a/grapher/Models/Options/ActiveValueLabel.cs b/grapher/Models/Options/ActiveValueLabel.cs index 18a4400..66817ab 100644 --- a/grapher/Models/Options/ActiveValueLabel.cs +++ b/grapher/Models/Options/ActiveValueLabel.cs @@ -5,11 +5,6 @@ namespace grapher.Models.Options { public class ActiveValueLabel { - #region Constants - - - #endregion Constants - #region Fields private string _prefix; diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 6ec9d31..720cb13 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -130,6 +130,10 @@ namespace grapher.Models.Options settings.args.x, settings.args.y, settings.combineMagnitudes); + + AccelCharts.SetLogarithmic( + OptionSetX.Options.AccelerationType.LogarithmicCharts, + OptionSetY.Options.AccelerationType.LogarithmicCharts); } public void OnWholeClicked(object sender, EventArgs e) diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs index d42187c..5f9307c 100644 --- a/grapher/Models/Serialized/DriverSettings.cs +++ b/grapher/Models/Serialized/DriverSettings.cs @@ -8,7 +8,7 @@ namespace grapher.Models.Serialized public enum AccelMode { - linear, classic, natural, naturalgain, sigmoidgain, power, logarithm, noaccel + linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel } #endregion Enumerations diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index 2543104..84e681b 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -33,6 +33,9 @@ namespace grapher.Models.Serialized [JsonProperty(Order = 4)] public bool ShowLastMouseMove { get; set; } + [JsonProperty(Order = 4)] + public bool ShowVelocityAndGain { get; set; } + #endregion Properties } } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index ccffc3f..cac2bd0 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -13,13 +13,15 @@ namespace grapher.Models.Serialized Field dpiField, Field pollRateField, ToolStripMenuItem autoWrite, - ToolStripMenuItem showLastMouseMove) + ToolStripMenuItem showLastMouseMove, + ToolStripMenuItem showVelocityAndGain) { ActiveAccel = activeAccel; DpiField = dpiField; PollRateField = pollRateField; AutoWriteMenuItem = autoWrite; ShowLastMouseMoveMenuItem = showLastMouseMove; + ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; } #endregion Constructors @@ -38,6 +40,8 @@ namespace grapher.Models.Serialized private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } + private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } + #endregion Properties #region Methods @@ -53,6 +57,7 @@ namespace grapher.Models.Serialized DPI = (int)DpiField.Data, PollRate = (int)PollRateField.Data, ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, + ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, }; RawAccelSettings.Save(); @@ -69,6 +74,7 @@ namespace grapher.Models.Serialized PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; + ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; } public void Startup() |