diff options
Diffstat (limited to 'grapher/Form1.cs')
| -rw-r--r-- | grapher/Form1.cs | 186 |
1 files changed, 81 insertions, 105 deletions
diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 3807d2a..237a25d 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -55,16 +55,9 @@ namespace grapher public partial class RawAcceleration : Form { - public struct MagnitudeData - { - public double magnitude; - public int x; - public int y; - } #region Constructor - public static ReadOnlyCollection<MagnitudeData> Magnitudes = GetMagnitudes(); public RawAcceleration() { @@ -90,39 +83,57 @@ namespace grapher IntPtr args_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(args)); Marshal.StructureToPtr(args, args_ptr, false); - ManagedAcceleration = new ManagedAccel(args_ptr); + var managedAcceleration = new ManagedAccel(args_ptr); Marshal.FreeHGlobal(args_ptr); - Sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity"); - Rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation"); - Weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight"); - Cap = new OptionXY(capBoxX, capBoxY, capXYLock, this, 0, capLabel, "Cap"); - Offset = new Option(offsetBox, this, 0, offsetLabel, "Offset"); + var sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity"); + var rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation"); + var weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight"); + var cap = new OptionXY(capBoxX, capBoxY, capXYLock, this, 0, capLabel, "Cap"); + var offset = new Option(offsetBox, this, 0, offsetLabel, "Offset"); // The name and layout of these options is handled by AccelerationOptions object. - Acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); - LimitOrExponent = new Option(new Field(limitBox, this, 2), constantTwoLabel); - Midpoint = new Option(new Field(midpointBox, this, 0), constantThreeLabel); + var acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); + var limitOrExponent = new Option(new Field(limitBox, this, 2), constantTwoLabel); + var midpoint = new Option(new Field(midpointBox, this, 0), constantThreeLabel); - AccelerationOptions = new AccelOptions( + var accelerationOptions = new AccelOptions( accelTypeDrop, new Option[] { - Offset, - Acceleration, - LimitOrExponent, - Midpoint, + offset, + acceleration, + limitOrExponent, + midpoint, }, new OptionXY[] { - Weight, - Cap, + weight, + cap, }, writeButton); - UpdateGraph(); - + AccelGUI = new AccelGUI( + this, + new AccelCharts( + this, + AccelerationChart, + VelocityChart, + GainChart, + showVelocityGainToolStripMenuItem), + managedAcceleration, + accelerationOptions, + sensitivity, + rotation, + weight, + cap, + offset, + acceleration, + limitOrExponent, + midpoint, + writeButton); + this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); this.AccelerationChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; @@ -141,114 +152,79 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; - } - #endregion Constructor - #region Properties + this.VelocityChart.ChartAreas[0].AxisX.RoundAxisValues(); - public ManagedAccel ManagedAcceleration { get; set; } + this.VelocityChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + this.VelocityChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; - private AccelOptions AccelerationOptions { get; set; } + this.VelocityChart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + this.VelocityChart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; - private OptionXY Sensitivity { get; set; } + this.VelocityChart.ChartAreas[0].CursorY.Interval = 0.001; - private Option Rotation { get; set; } + this.VelocityChart.ChartAreas[0].CursorX.AutoScroll = true; + this.VelocityChart.ChartAreas[0].CursorY.AutoScroll = true; - private OptionXY Weight { get; set; } + this.VelocityChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + this.VelocityChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; - private OptionXY Cap { get; set; } + this.VelocityChart.ChartAreas[0].CursorX.IsUserEnabled = true; + this.VelocityChart.ChartAreas[0].CursorY.IsUserEnabled = true; - private Option Offset { get; set; } - private Option Acceleration { get; set; } + this.GainChart.ChartAreas[0].AxisX.RoundAxisValues(); - private Option LimitOrExponent { get; set; } + this.GainChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + this.GainChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; - private Option Midpoint { get; set; } + this.GainChart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + this.GainChart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; - #endregion Properties + this.GainChart.ChartAreas[0].CursorY.Interval = 0.001; - #region Methods - - public static ReadOnlyCollection<MagnitudeData> GetMagnitudes() - { - var magnitudes = new List<MagnitudeData>(); - for (int i = 0; i < 100; i++) - { - for (int j = 0; j <= i; j++) - { - MagnitudeData magnitudeData; - magnitudeData.magnitude = Magnitude(i, j); - magnitudeData.x = i; - magnitudeData.y = j; - magnitudes.Add(magnitudeData); - } - } - - magnitudes.Sort((m1, m2) => m1.magnitude.CompareTo(m2.magnitude)); - - return magnitudes.AsReadOnly(); - } + this.GainChart.ChartAreas[0].CursorX.AutoScroll = true; + this.GainChart.ChartAreas[0].CursorY.AutoScroll = true; - public static double Magnitude(int x, int y) - { - return Math.Sqrt(x * x + y * y); - } + this.GainChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + this.GainChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; - public static double Magnitude(double x, double y) - { - return Math.Sqrt(x * x + y * y); + this.GainChart.ChartAreas[0].CursorX.IsUserEnabled = true; + this.GainChart.ChartAreas[0].CursorY.IsUserEnabled = true; } - private void Form1_Load(object sender, EventArgs e) - { - - } + #endregion Constructor - private void UpdateGraph() - { - var orderedPoints = new SortedDictionary<double, double>(); + #region Properties - foreach (var magnitudeData in Magnitudes) - { - var output = ManagedAcceleration.Accelerate(magnitudeData.x, magnitudeData.y, 1); + public AccelGUI AccelGUI { get; } - var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = magnitudeData.magnitude > 0 ? outMagnitude / magnitudeData.magnitude : Sensitivity.Fields.X; + #endregion Properties - if (!orderedPoints.ContainsKey(magnitudeData.magnitude)) - { - orderedPoints.Add(magnitudeData.magnitude, ratio); - } - } + #region Methods - var series = this.AccelerationChart.Series.FirstOrDefault(); - series.Points.Clear(); + private void Form1_Load(object sender, EventArgs e) + { - foreach (var point in orderedPoints) - { - series.Points.AddXY(point.Key, point.Value); - } } private void writeButton_Click(object sender, EventArgs e) { - ManagedAcceleration.UpdateAccel( - AccelerationOptions.AccelerationIndex, - Rotation.Field.Data, - Sensitivity.Fields.X, - Sensitivity.Fields.Y, - Weight.Fields.X, - Weight.Fields.Y, - Cap.Fields.X, - Cap.Fields.Y, - Offset.Field.Data, - Acceleration.Field.Data, - LimitOrExponent.Field.Data, - Midpoint.Field.Data); - ManagedAcceleration.WriteToDriver(); - UpdateGraph(); + AccelGUI.ManagedAcceleration.UpdateAccel( + AccelGUI.AccelerationOptions.AccelerationIndex, + AccelGUI.Rotation.Field.Data, + AccelGUI.Sensitivity.Fields.X, + AccelGUI.Sensitivity.Fields.Y, + AccelGUI.Weight.Fields.X, + AccelGUI.Weight.Fields.Y, + AccelGUI.Cap.Fields.X, + AccelGUI.Cap.Fields.Y, + AccelGUI.Offset.Field.Data, + AccelGUI.Acceleration.Field.Data, + AccelGUI.LimitOrExponent.Field.Data, + AccelGUI.Midpoint.Field.Data); + AccelGUI.UpdateGraph(); } #endregion Methods |