diff options
| -rw-r--r-- | grapher/AccelCharts.cs | 95 | ||||
| -rw-r--r-- | grapher/AccelGUI.cs | 180 | ||||
| -rw-r--r-- | grapher/Form1.Designer.cs | 175 | ||||
| -rw-r--r-- | grapher/Form1.cs | 186 | ||||
| -rw-r--r-- | grapher/Form1.resx | 6 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 2 | ||||
| -rw-r--r-- | rawaccel.sln | 1 | ||||
| -rw-r--r-- | wrapper/wrapper.cpp | 14 | ||||
| -rw-r--r-- | wrapper/wrapper.hpp | 10 | ||||
| -rw-r--r-- | wrapper/wrapper.vcxproj | 4 | ||||
| -rw-r--r-- | wrapper/wrapper.vcxproj.filters | 4 | ||||
| -rw-r--r-- | wrapper/wrapper_io.cpp | 18 | ||||
| -rw-r--r-- | wrapper/wrapper_io.hpp (renamed from wrapper/wrapper_writer.hpp) | 3 | ||||
| -rw-r--r-- | wrapper/wrapper_writer.cpp | 9 |
14 files changed, 539 insertions, 168 deletions
diff --git a/grapher/AccelCharts.cs b/grapher/AccelCharts.cs new file mode 100644 index 0000000..62c60e5 --- /dev/null +++ b/grapher/AccelCharts.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; + +namespace grapher +{ + public class AccelCharts + { + public const int ChartSeparation = 10; + + /// <summary> Needed to show full contents in form. Unsure why. </summary> + public const int FormHeightPadding = 35; + + public AccelCharts( + Form form, + Chart sensitivityChart, + Chart velocityChart, + Chart gainChart, + ToolStripMenuItem enableVelocityAndGain) + { + ContaingForm = form; + SensitivityChart = sensitivityChart; + VelocityChart = velocityChart; + GainChart = gainChart; + EnableVelocityAndGain = enableVelocityAndGain; + + SensitivityChart.Top = 0; + VelocityChart.Height = SensitivityChart.Height; + VelocityChart.Top = SensitivityChart.Height + ChartSeparation; + GainChart.Height = SensitivityChart.Height; + GainChart.Top = VelocityChart.Top + VelocityChart.Height + ChartSeparation; + + Rectangle screenRectangle = ContaingForm.RectangleToScreen(ContaingForm.ClientRectangle); + FormBorderHeight = screenRectangle.Top - ContaingForm.Top; + + EnableVelocityAndGain.Click += new System.EventHandler(OnEnableClick); + EnableVelocityAndGain.CheckedChanged += new System.EventHandler(OnEnableCheckStateChange); + + HideVelocityAndGain(); + } + + public Form ContaingForm { get; } + + public Chart SensitivityChart { get; } + + public Chart VelocityChart { get; } + + public Chart GainChart { get; } + + public ToolStripMenuItem EnableVelocityAndGain { get; } + + private int FormBorderHeight { get; } + + private void OnEnableClick(object sender, EventArgs e) + { + EnableVelocityAndGain.Checked = !EnableVelocityAndGain.Checked; + } + + private void OnEnableCheckStateChange(object sender, EventArgs e) + { + if (EnableVelocityAndGain.Checked) + { + ShowVelocityAndGain(); + } + else + { + HideVelocityAndGain(); + } + } + + private void ShowVelocityAndGain() + { + VelocityChart.Show(); + GainChart.Show(); + ContaingForm.Height = SensitivityChart.Height + + ChartSeparation + + VelocityChart.Height + + ChartSeparation + + GainChart.Height + + FormBorderHeight; + } + + private void HideVelocityAndGain() + { + VelocityChart.Hide(); + GainChart.Hide(); + ContaingForm.Height = SensitivityChart.Height + FormBorderHeight; + } + } +} diff --git a/grapher/AccelGUI.cs b/grapher/AccelGUI.cs new file mode 100644 index 0000000..c660afe --- /dev/null +++ b/grapher/AccelGUI.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; + +namespace grapher +{ + public class AccelGUI + { + public struct MagnitudeData + { + public double magnitude; + public int x; + public int y; + } + + public static ReadOnlyCollection<MagnitudeData> Magnitudes = GetMagnitudes(); + + #region constructors + + public AccelGUI( + RawAcceleration accelForm, + AccelCharts accelCharts, + ManagedAccel managedAccel, + AccelOptions accelOptions, + OptionXY sensitivity, + Option rotation, + OptionXY weight, + OptionXY cap, + Option offset, + Option acceleration, + Option limtOrExp, + Option midpoint, + Button writeButton) + { + AccelForm = accelForm; + AccelCharts = accelCharts; + ManagedAcceleration = managedAccel; + AccelerationOptions = accelOptions; + Sensitivity = sensitivity; + Rotation = rotation; + Weight = weight; + Cap = cap; + Offset = offset; + Acceleration = acceleration; + LimitOrExponent = limtOrExp; + Midpoint = midpoint; + WriteButton = writeButton; + + OrderedAccelPoints = new SortedDictionary<double, double>(); + OrderedVelocityPoints = new SortedDictionary<double, double>(); + OrderedGainPoints = new SortedDictionary<double, double>(); + + + ManagedAcceleration.ReadFromDriver(); + UpdateGraph(); + } + + #endregion constructors + + #region properties + + public RawAcceleration AccelForm { get; } + + public AccelCharts AccelCharts { get; } + + public ManagedAccel ManagedAcceleration { get; } + + public AccelOptions AccelerationOptions { get; } + + public OptionXY Sensitivity { get; } + + public Option Rotation { get; } + + public OptionXY Weight { get; } + + public OptionXY Cap { get; } + + public Option Offset { get; } + + public Option Acceleration { get; } + + public Option LimitOrExponent { get; } + + public Option Midpoint { get; } + + public Button WriteButton { get; } + + public SortedDictionary<double, double> OrderedAccelPoints { get; } + + public SortedDictionary<double, double> OrderedVelocityPoints { get; } + + public SortedDictionary<double, double> OrderedGainPoints { get; } + + #endregion properties + + #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(); + } + + public static double Magnitude(int x, int y) + { + return Math.Sqrt(x * x + y * y); + } + + public static double Magnitude(double x, double y) + { + return Math.Sqrt(x * x + y * y); + } + + public void UpdateGraph() + { + OrderedAccelPoints.Clear(); + OrderedVelocityPoints.Clear(); + OrderedGainPoints.Clear(); + + double lastInputMagnitude = 0; + double lastOutputMagnitude = 0; + + foreach (var magnitudeData in Magnitudes) + { + var output = ManagedAcceleration.Accelerate(magnitudeData.x, magnitudeData.y, 1); + + var outMagnitude = Magnitude(output.Item1, output.Item2); + var ratio = magnitudeData.magnitude > 0 ? outMagnitude / magnitudeData.magnitude : Sensitivity.Fields.X; + + var inDiff = magnitudeData.magnitude - lastInputMagnitude; + var outDiff = outMagnitude - lastOutputMagnitude; + var slope = inDiff > 0 ? outDiff / inDiff : Sensitivity.Fields.X; + lastInputMagnitude = magnitudeData.magnitude; + lastOutputMagnitude = outMagnitude; + + if (!OrderedAccelPoints.ContainsKey(magnitudeData.magnitude)) + { + OrderedAccelPoints.Add(magnitudeData.magnitude, ratio); + } + + if (!OrderedVelocityPoints.ContainsKey(magnitudeData.magnitude)) + { + OrderedVelocityPoints.Add(magnitudeData.magnitude, outMagnitude); + } + + if (!OrderedGainPoints.ContainsKey(magnitudeData.magnitude)) + { + OrderedGainPoints.Add(magnitudeData.magnitude, slope); + } + + } + + AccelCharts.SensitivityChart.Series[0].Points.DataBindXY(OrderedAccelPoints.Keys, OrderedAccelPoints.Values); + AccelCharts.VelocityChart.Series[0].Points.DataBindXY(OrderedVelocityPoints.Keys, OrderedVelocityPoints.Values); + AccelCharts.GainChart.Series[0].Points.DataBindXY(OrderedGainPoints.Keys, OrderedGainPoints.Values); + } + + #endregion methods + } + +} diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 667abf1..1a268d6 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -30,9 +30,15 @@ namespace grapher /// </summary> private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea10 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend10 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series10 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea11 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend11 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series11 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea12 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend12 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series12 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBoxX = new System.Windows.Forms.TextBox(); @@ -59,32 +65,40 @@ namespace grapher this.capXYLock = new System.Windows.Forms.CheckBox(); this.weightXYLock = new System.Windows.Forms.CheckBox(); this.LockXYLabel = new System.Windows.Forms.Label(); + this.VelocityChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.GainChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.graphsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.showVelocityGainToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.VelocityChart)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.GainChart)).BeginInit(); + this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // AccelerationChart // - chartArea2.AxisX.Title = "Speed (counts/ms)"; - chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea2.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea2); - legend2.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend2); - this.AccelerationChart.Location = new System.Drawing.Point(242, 1); + chartArea10.AxisX.Title = "Speed (counts/ms)"; + chartArea10.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea10.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea10); + legend10.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend10); + this.AccelerationChart.Location = new System.Drawing.Point(242, 0); this.AccelerationChart.Name = "AccelerationChart"; - series2.ChartArea = "ChartArea1"; - series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series2.Legend = "Legend1"; - series2.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series2); - this.AccelerationChart.Size = new System.Drawing.Size(721, 312); + series10.ChartArea = "ChartArea1"; + series10.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series10.Legend = "Legend1"; + series10.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series10); + this.AccelerationChart.Size = new System.Drawing.Size(721, 328); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; // // accelTypeDrop // this.accelTypeDrop.FormattingEnabled = true; - this.accelTypeDrop.Location = new System.Drawing.Point(14, 89); + this.accelTypeDrop.Location = new System.Drawing.Point(24, 98); this.accelTypeDrop.Name = "accelTypeDrop"; this.accelTypeDrop.Size = new System.Drawing.Size(151, 21); this.accelTypeDrop.TabIndex = 2; @@ -92,7 +106,7 @@ namespace grapher // // sensitivityBoxX // - this.sensitivityBoxX.Location = new System.Drawing.Point(95, 37); + this.sensitivityBoxX.Location = new System.Drawing.Point(105, 46); this.sensitivityBoxX.Name = "sensitivityBoxX"; this.sensitivityBoxX.Size = new System.Drawing.Size(32, 20); this.sensitivityBoxX.TabIndex = 3; @@ -100,7 +114,7 @@ namespace grapher // sensitivityLabel // this.sensitivityLabel.AutoSize = true; - this.sensitivityLabel.Location = new System.Drawing.Point(14, 40); + this.sensitivityLabel.Location = new System.Drawing.Point(24, 49); this.sensitivityLabel.Name = "sensitivityLabel"; this.sensitivityLabel.Size = new System.Drawing.Size(54, 13); this.sensitivityLabel.TabIndex = 4; @@ -108,7 +122,7 @@ namespace grapher // // rotationBox // - this.rotationBox.Location = new System.Drawing.Point(95, 63); + this.rotationBox.Location = new System.Drawing.Point(105, 72); this.rotationBox.Name = "rotationBox"; this.rotationBox.Size = new System.Drawing.Size(70, 20); this.rotationBox.TabIndex = 5; @@ -116,7 +130,7 @@ namespace grapher // rotationLabel // this.rotationLabel.AutoSize = true; - this.rotationLabel.Location = new System.Drawing.Point(24, 66); + this.rotationLabel.Location = new System.Drawing.Point(34, 75); this.rotationLabel.Name = "rotationLabel"; this.rotationLabel.Size = new System.Drawing.Size(47, 13); this.rotationLabel.TabIndex = 6; @@ -124,7 +138,7 @@ namespace grapher // // accelerationBox // - this.accelerationBox.Location = new System.Drawing.Point(96, 116); + this.accelerationBox.Location = new System.Drawing.Point(106, 125); this.accelerationBox.Name = "accelerationBox"; this.accelerationBox.Size = new System.Drawing.Size(70, 20); this.accelerationBox.TabIndex = 7; @@ -132,7 +146,7 @@ namespace grapher // constantOneLabel // this.constantOneLabel.AutoSize = true; - this.constantOneLabel.Location = new System.Drawing.Point(14, 119); + this.constantOneLabel.Location = new System.Drawing.Point(24, 128); this.constantOneLabel.Name = "constantOneLabel"; this.constantOneLabel.Size = new System.Drawing.Size(66, 13); this.constantOneLabel.TabIndex = 9; @@ -141,7 +155,7 @@ namespace grapher // // capBoxX // - this.capBoxX.Location = new System.Drawing.Point(95, 142); + this.capBoxX.Location = new System.Drawing.Point(105, 151); this.capBoxX.Name = "capBoxX"; this.capBoxX.Size = new System.Drawing.Size(32, 20); this.capBoxX.TabIndex = 10; @@ -149,7 +163,7 @@ namespace grapher // capLabel // this.capLabel.AutoSize = true; - this.capLabel.Location = new System.Drawing.Point(24, 146); + this.capLabel.Location = new System.Drawing.Point(34, 155); this.capLabel.Name = "capLabel"; this.capLabel.Size = new System.Drawing.Size(26, 13); this.capLabel.TabIndex = 11; @@ -158,7 +172,7 @@ namespace grapher // // weightBoxFirst // - this.weightBoxFirst.Location = new System.Drawing.Point(95, 168); + this.weightBoxFirst.Location = new System.Drawing.Point(105, 177); this.weightBoxFirst.Name = "weightBoxFirst"; this.weightBoxFirst.Size = new System.Drawing.Size(32, 20); this.weightBoxFirst.TabIndex = 12; @@ -166,7 +180,7 @@ namespace grapher // weightLabel // this.weightLabel.AutoSize = true; - this.weightLabel.Location = new System.Drawing.Point(24, 171); + this.weightLabel.Location = new System.Drawing.Point(34, 180); this.weightLabel.Name = "weightLabel"; this.weightLabel.Size = new System.Drawing.Size(41, 13); this.weightLabel.TabIndex = 13; @@ -175,14 +189,14 @@ namespace grapher // // weightBoxSecond // - this.weightBoxSecond.Location = new System.Drawing.Point(134, 168); + this.weightBoxSecond.Location = new System.Drawing.Point(144, 177); this.weightBoxSecond.Name = "weightBoxSecond"; this.weightBoxSecond.Size = new System.Drawing.Size(32, 20); this.weightBoxSecond.TabIndex = 14; // // limitBox // - this.limitBox.Location = new System.Drawing.Point(95, 220); + this.limitBox.Location = new System.Drawing.Point(105, 229); this.limitBox.Name = "limitBox"; this.limitBox.Size = new System.Drawing.Size(70, 20); this.limitBox.TabIndex = 15; @@ -190,7 +204,7 @@ namespace grapher // constantTwoLabel // this.constantTwoLabel.AutoSize = true; - this.constantTwoLabel.Location = new System.Drawing.Point(14, 223); + this.constantTwoLabel.Location = new System.Drawing.Point(24, 232); this.constantTwoLabel.Name = "constantTwoLabel"; this.constantTwoLabel.Size = new System.Drawing.Size(78, 13); this.constantTwoLabel.TabIndex = 16; @@ -199,7 +213,7 @@ namespace grapher // // midpointBox // - this.midpointBox.Location = new System.Drawing.Point(95, 246); + this.midpointBox.Location = new System.Drawing.Point(105, 255); this.midpointBox.Name = "midpointBox"; this.midpointBox.Size = new System.Drawing.Size(70, 20); this.midpointBox.TabIndex = 17; @@ -207,7 +221,7 @@ namespace grapher // constantThreeLabel // this.constantThreeLabel.AutoSize = true; - this.constantThreeLabel.Location = new System.Drawing.Point(21, 249); + this.constantThreeLabel.Location = new System.Drawing.Point(31, 258); this.constantThreeLabel.Name = "constantThreeLabel"; this.constantThreeLabel.Size = new System.Drawing.Size(47, 13); this.constantThreeLabel.TabIndex = 18; @@ -216,7 +230,7 @@ namespace grapher // // offsetBox // - this.offsetBox.Location = new System.Drawing.Point(95, 194); + this.offsetBox.Location = new System.Drawing.Point(105, 203); this.offsetBox.Name = "offsetBox"; this.offsetBox.Size = new System.Drawing.Size(70, 20); this.offsetBox.TabIndex = 19; @@ -224,7 +238,7 @@ namespace grapher // offsetLabel // this.offsetLabel.AutoSize = true; - this.offsetLabel.Location = new System.Drawing.Point(24, 197); + this.offsetLabel.Location = new System.Drawing.Point(34, 206); this.offsetLabel.Name = "offsetLabel"; this.offsetLabel.Size = new System.Drawing.Size(35, 13); this.offsetLabel.TabIndex = 20; @@ -233,7 +247,7 @@ namespace grapher // // writeButton // - this.writeButton.Location = new System.Drawing.Point(47, 272); + this.writeButton.Location = new System.Drawing.Point(57, 281); this.writeButton.Name = "writeButton"; this.writeButton.Size = new System.Drawing.Size(102, 23); this.writeButton.TabIndex = 21; @@ -243,14 +257,14 @@ namespace grapher // // sensitivityBoxY // - this.sensitivityBoxY.Location = new System.Drawing.Point(133, 37); + this.sensitivityBoxY.Location = new System.Drawing.Point(143, 46); this.sensitivityBoxY.Name = "sensitivityBoxY"; this.sensitivityBoxY.Size = new System.Drawing.Size(32, 20); this.sensitivityBoxY.TabIndex = 22; // // capBoxY // - this.capBoxY.Location = new System.Drawing.Point(135, 142); + this.capBoxY.Location = new System.Drawing.Point(145, 151); this.capBoxY.Name = "capBoxY"; this.capBoxY.Size = new System.Drawing.Size(31, 20); this.capBoxY.TabIndex = 23; @@ -260,7 +274,7 @@ namespace grapher this.sensXYLock.AutoSize = true; this.sensXYLock.Checked = true; this.sensXYLock.CheckState = System.Windows.Forms.CheckState.Checked; - this.sensXYLock.Location = new System.Drawing.Point(188, 40); + this.sensXYLock.Location = new System.Drawing.Point(198, 49); this.sensXYLock.Name = "sensXYLock"; this.sensXYLock.Size = new System.Drawing.Size(15, 14); this.sensXYLock.TabIndex = 24; @@ -271,7 +285,7 @@ namespace grapher this.capXYLock.AutoSize = true; this.capXYLock.Checked = true; this.capXYLock.CheckState = System.Windows.Forms.CheckState.Checked; - this.capXYLock.Location = new System.Drawing.Point(188, 145); + this.capXYLock.Location = new System.Drawing.Point(198, 154); this.capXYLock.Name = "capXYLock"; this.capXYLock.Size = new System.Drawing.Size(15, 14); this.capXYLock.TabIndex = 25; @@ -282,7 +296,7 @@ namespace grapher this.weightXYLock.AutoSize = true; this.weightXYLock.Checked = true; this.weightXYLock.CheckState = System.Windows.Forms.CheckState.Checked; - this.weightXYLock.Location = new System.Drawing.Point(188, 171); + this.weightXYLock.Location = new System.Drawing.Point(198, 180); this.weightXYLock.Name = "weightXYLock"; this.weightXYLock.Size = new System.Drawing.Size(15, 14); this.weightXYLock.TabIndex = 26; @@ -291,17 +305,84 @@ namespace grapher // LockXYLabel // this.LockXYLabel.AutoSize = true; - this.LockXYLabel.Location = new System.Drawing.Point(165, 21); + this.LockXYLabel.Location = new System.Drawing.Point(175, 30); this.LockXYLabel.Name = "LockXYLabel"; this.LockXYLabel.Size = new System.Drawing.Size(60, 13); this.LockXYLabel.TabIndex = 27; this.LockXYLabel.Text = "Lock X && Y"; // + // VelocityChart + // + chartArea11.AxisX.Title = "Speed (count/ms)"; + chartArea11.AxisY.Title = "Output Speed (counts/ms)"; + chartArea11.Name = "ChartArea1"; + this.VelocityChart.ChartAreas.Add(chartArea11); + legend11.Name = "Legend1"; + this.VelocityChart.Legends.Add(legend11); + this.VelocityChart.Location = new System.Drawing.Point(242, 334); + this.VelocityChart.Name = "VelocityChart"; + series11.ChartArea = "ChartArea1"; + series11.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series11.Legend = "Legend1"; + series11.Name = "Mouse Velocity"; + this.VelocityChart.Series.Add(series11); + this.VelocityChart.Size = new System.Drawing.Size(721, 307); + this.VelocityChart.TabIndex = 28; + this.VelocityChart.Text = "chart1"; + // + // GainChart + // + chartArea12.AxisX.Title = "Speed (counts/ms)"; + chartArea12.AxisY.Title = "Slope of Velocity Chart"; + chartArea12.Name = "ChartArea1"; + this.GainChart.ChartAreas.Add(chartArea12); + legend12.Name = "Legend1"; + this.GainChart.Legends.Add(legend12); + this.GainChart.Location = new System.Drawing.Point(242, 647); + this.GainChart.Name = "GainChart"; + series12.ChartArea = "ChartArea1"; + series12.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series12.Legend = "Legend1"; + series12.Name = "Velocity Gain"; + this.GainChart.Series.Add(series12); + this.GainChart.Size = new System.Drawing.Size(721, 309); + this.GainChart.TabIndex = 29; + this.GainChart.Text = "chart1"; + // + // menuStrip1 + // + this.menuStrip1.BackColor = System.Drawing.SystemColors.ControlLight; + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.graphsToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(963, 24); + this.menuStrip1.TabIndex = 30; + this.menuStrip1.Text = "menuStrip1"; + // + // graphsToolStripMenuItem + // + this.graphsToolStripMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.graphsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.showVelocityGainToolStripMenuItem}); + this.graphsToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.graphsToolStripMenuItem.Name = "graphsToolStripMenuItem"; + this.graphsToolStripMenuItem.Size = new System.Drawing.Size(53, 20); + this.graphsToolStripMenuItem.Text = "Charts"; + // + // showVelocityGainToolStripMenuItem + // + this.showVelocityGainToolStripMenuItem.Name = "showVelocityGainToolStripMenuItem"; + this.showVelocityGainToolStripMenuItem.Size = new System.Drawing.Size(187, 22); + this.showVelocityGainToolStripMenuItem.Text = "Show Velocity && Gain"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(963, 312); + this.ClientSize = new System.Drawing.Size(963, 955); + this.Controls.Add(this.GainChart); + this.Controls.Add(this.VelocityChart); this.Controls.Add(this.LockXYLabel); this.Controls.Add(this.weightXYLock); this.Controls.Add(this.capXYLock); @@ -328,10 +409,15 @@ namespace grapher this.Controls.Add(this.sensitivityBoxX); this.Controls.Add(this.accelTypeDrop); this.Controls.Add(this.AccelerationChart); + this.Controls.Add(this.menuStrip1); this.Name = "RawAcceleration"; this.Text = "Raw Acceleration Graph"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.VelocityChart)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.GainChart)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -365,6 +451,11 @@ namespace grapher private System.Windows.Forms.CheckBox capXYLock; private System.Windows.Forms.CheckBox weightXYLock; private System.Windows.Forms.Label LockXYLabel; + private System.Windows.Forms.DataVisualization.Charting.Chart VelocityChart; + private System.Windows.Forms.DataVisualization.Charting.Chart GainChart; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem graphsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem showVelocityGainToolStripMenuItem; } } 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 diff --git a/grapher/Form1.resx b/grapher/Form1.resx index 1af7de1..32fcbfb 100644 --- a/grapher/Form1.resx +++ b/grapher/Form1.resx @@ -117,4 +117,10 @@ <resheader name="writer"> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> + <metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>17, 17</value> + </metadata> + <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> + <value>25</value> + </metadata> </root>
\ No newline at end of file diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index bd86a0c..1611fd3 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -47,6 +47,8 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="AccelCharts.cs" /> + <Compile Include="AccelGUI.cs" /> <Compile Include="AccelOptions.cs" /> <Compile Include="Field.cs" /> <Compile Include="FieldXY.cs" /> diff --git a/rawaccel.sln b/rawaccel.sln index 2235818..33735fd 100644 --- a/rawaccel.sln +++ b/rawaccel.sln @@ -23,6 +23,7 @@ Global GlobalSection(SharedMSBuildProjectFiles) = preSolution common-install\common-install.vcxitems*{058d66c6-d88b-4fdb-b0e4-0a6fe7483b95}*SharedItemsImports = 9 common\common.vcxitems*{24b4226f-1461-408f-a1a4-1371c97153ea}*SharedItemsImports = 9 + common\common.vcxitems*{28a3656f-a1de-405c-b547-191c32ec555f}*SharedItemsImports = 4 common\common.vcxitems*{60d6c942-ac20-4c05-a2be-54b5c966534d}*SharedItemsImports = 4 common-install\common-install.vcxitems*{896950d1-520a-420a-b6b1-73014b92a68c}*SharedItemsImports = 4 common-install\common-install.vcxitems*{a4097ff6-a6f0-44e8-b8d0-538d0fb75936}*SharedItemsImports = 4 diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index bd0574f..e29f08d 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -30,8 +30,6 @@ void ManagedAccel::UpdateAccel( double lim_exp, double midpoint) { - delete modifier_instance; - modifier_args args{}; args.acc_fn_args.accel_mode = mode; args.degrees = rotation; @@ -46,11 +44,21 @@ void ManagedAccel::UpdateAccel( args.acc_fn_args.acc_args.limit = lim_exp; args.acc_fn_args.acc_args.exponent = lim_exp; args.acc_fn_args.acc_args.midpoint = midpoint; + + mouse_modifier* temp_modifier = new mouse_modifier(args); + driverWriter->writeToDriver(temp_modifier); + delete temp_modifier; - modifier_instance = new mouse_modifier(args); + ReadFromDriver(); } void ManagedAccel::WriteToDriver() { driverWriter->writeToDriver(modifier_instance); } + +void ManagedAccel::ReadFromDriver() +{ + delete modifier_instance; + modifier_instance = driverWriter->readFromDriver(); +} diff --git a/wrapper/wrapper.hpp b/wrapper/wrapper.hpp index e8f100d..22a1b1e 100644 --- a/wrapper/wrapper.hpp +++ b/wrapper/wrapper.hpp @@ -5,7 +5,7 @@ #include <rawaccel.hpp> #include <accel-error.hpp> -#include "wrapper_writer.hpp" +#include "wrapper_io.hpp" using namespace rawaccel; using namespace System; @@ -14,18 +14,18 @@ public ref class ManagedAccel { protected: mouse_modifier* modifier_instance; - writer* driverWriter; + wrapper_io* driverWriter; public: ManagedAccel(mouse_modifier* accel) : modifier_instance(accel) { - driverWriter = new writer(); + driverWriter = new wrapper_io(); } ManagedAccel(System::IntPtr args) { modifier_instance = new mouse_modifier(*reinterpret_cast<modifier_args*>(args.ToPointer())); - driverWriter = new writer(); + driverWriter = new wrapper_io(); } virtual ~ManagedAccel() @@ -66,4 +66,6 @@ public: void WriteToDriver(); + + void ReadFromDriver(); };
\ No newline at end of file diff --git a/wrapper/wrapper.vcxproj b/wrapper/wrapper.vcxproj index bffbf8b..3407d6d 100644 --- a/wrapper/wrapper.vcxproj +++ b/wrapper/wrapper.vcxproj @@ -117,11 +117,11 @@ </ItemDefinitionGroup> <ItemGroup> <ClInclude Include="wrapper.hpp" /> - <ClInclude Include="wrapper_writer.hpp" /> + <ClInclude Include="wrapper_io.hpp" /> </ItemGroup> <ItemGroup> <ClCompile Include="wrapper.cpp" /> - <ClCompile Include="wrapper_writer.cpp" /> + <ClCompile Include="wrapper_io.cpp" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/wrapper/wrapper.vcxproj.filters b/wrapper/wrapper.vcxproj.filters index 28b22ba..60fcc9c 100644 --- a/wrapper/wrapper.vcxproj.filters +++ b/wrapper/wrapper.vcxproj.filters @@ -18,7 +18,7 @@ <ClInclude Include="wrapper.hpp"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="wrapper_writer.hpp"> + <ClInclude Include="wrapper_io.hpp"> <Filter>Header Files</Filter> </ClInclude> </ItemGroup> @@ -26,7 +26,7 @@ <ClCompile Include="wrapper.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="wrapper_writer.cpp"> + <ClCompile Include="wrapper_io.cpp"> <Filter>Source Files</Filter> </ClCompile> </ItemGroup> diff --git a/wrapper/wrapper_io.cpp b/wrapper/wrapper_io.cpp new file mode 100644 index 0000000..4284d60 --- /dev/null +++ b/wrapper/wrapper_io.cpp @@ -0,0 +1,18 @@ +#pragma once + +#include <rawaccel-io.hpp> +#include "wrapper_io.hpp" + +void wrapper_io::writeToDriver(rawaccel::mouse_modifier* modifier) +{ + rawaccel::write(*modifier); +} + +rawaccel::mouse_modifier* wrapper_io::readFromDriver() +{ + rawaccel::mouse_modifier modifier = rawaccel::read(); + rawaccel::mouse_modifier* mod_pnt = (rawaccel::mouse_modifier*)malloc(sizeof(rawaccel::mouse_modifier)); + memcpy(mod_pnt, &modifier, sizeof(rawaccel::mouse_modifier)); + + return mod_pnt; +} diff --git a/wrapper/wrapper_writer.hpp b/wrapper/wrapper_io.hpp index dcbef10..3427e3f 100644 --- a/wrapper/wrapper_writer.hpp +++ b/wrapper/wrapper_io.hpp @@ -2,6 +2,7 @@ #include <rawaccel.hpp> -struct writer { +struct wrapper_io { void writeToDriver(rawaccel::mouse_modifier* modifier); + rawaccel::mouse_modifier* readFromDriver(); };
\ No newline at end of file diff --git a/wrapper/wrapper_writer.cpp b/wrapper/wrapper_writer.cpp deleted file mode 100644 index da7c9bf..0000000 --- a/wrapper/wrapper_writer.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include <rawaccel-io.hpp> -#include "wrapper_writer.hpp" - -void writer::writeToDriver(rawaccel::mouse_modifier* modifier) -{ - rawaccel::write(*modifier); -} |