diff options
| author | a1xd <[email protected]> | 2020-08-22 22:33:45 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-22 22:33:45 -0400 |
| commit | 252637e53ca42353061dc3118e8625af6edc348f (patch) | |
| tree | 26ea73edae996242eaef559485309fb9c66f4d30 | |
| parent | Merge pull request #15 from JacobPalecki/GUI (diff) | |
| parent | delete personal settings.json left in repo (diff) | |
| download | rawaccel-252637e53ca42353061dc3118e8625af6edc348f.tar.xz rawaccel-252637e53ca42353061dc3118e8625af6edc348f.zip | |
Merge pull request #16 from JacobPalecki/Misc
Gain Styles, Settings File, and other miscellaneous
27 files changed, 1229 insertions, 98 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp index 60b7362..f280e3e 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -36,7 +36,7 @@ namespace rawaccel { /// <summary> Coefficients applied to acceleration per axis.</summary> vec2d weight = { 1, 1 }; - /// <summary> Generally, the acceleration ramp rate. + /// <summary> Generally, the acceleration ramp rate.</summary> double speed_coeff = 0; accel_base(const accel_args& args) { diff --git a/common/accel-naturalgain.hpp b/common/accel-naturalgain.hpp new file mode 100644 index 0000000..95c0be2 --- /dev/null +++ b/common/accel-naturalgain.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include <math.h> + +#include "accel-base.hpp" + +namespace rawaccel { + + /// <summary> Struct to hold "natural" (vanishing difference) gain implementation. </summary> + struct accel_naturalgain : accel_base { + double limit = 1; + double midpoint = 0; + + accel_naturalgain(const accel_args& args) : accel_base(args) { + verify(args); + + limit = args.limit - 1; + speed_coeff /= limit; + } + + inline double accelerate(double speed) const { + // f(x) = k((e^(-mx)-1)/mx + 1) + double scaled_speed = speed_coeff * speed; + return limit * (((exp(-scaled_speed) - 1) / scaled_speed) + 1); + } + + void verify(const accel_args& args) const { + if (args.limit <= 1) bad_arg("limit must be greater than 1"); + } + }; + +} diff --git a/common/accel-sigmoid.hpp b/common/accel-sigmoid.hpp index 5bbe58f..dc2066d 100644 --- a/common/accel-sigmoid.hpp +++ b/common/accel-sigmoid.hpp @@ -19,7 +19,7 @@ namespace rawaccel { } inline double accelerate(double speed) const { - //f(x) = k/(1+e^(-m(c-x))) + //f(x) = k/(1+e^(-m(x-c))) return limit / (exp(-speed_coeff * (speed - midpoint)) + 1); } diff --git a/common/accel-sigmoidgain.hpp b/common/accel-sigmoidgain.hpp new file mode 100644 index 0000000..0a2e54d --- /dev/null +++ b/common/accel-sigmoidgain.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include <math.h> + +#include "accel-base.hpp" + +namespace rawaccel { + + /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary> + struct accel_sigmoidgain : accel_base { + double limit = 1; + double midpoint = 0; + double additive_constant = 0; + double integration_constant = 0; + + accel_sigmoidgain(const accel_args& args) : accel_base(args) { + verify(args); + + limit = args.limit - 1; + midpoint = args.midpoint; + additive_constant = exp(speed_coeff*midpoint); + integration_constant = log(1 + additive_constant); + } + + inline double accelerate(double speed) const { + //f(x) = k/(1+e^(-m(c-x))) + double scaled_speed = speed_coeff * speed; + return limit * ((log(additive_constant+exp(scaled_speed)) - integration_constant)/scaled_speed); + } + + void verify(const accel_args& args) const { + if (args.limit <= 1) bad_arg("exponent must be greater than 1"); + if (args.midpoint < 0) bad_arg("midpoint must not be negative"); + } + }; + +} diff --git a/common/common.vcxitems b/common/common.vcxitems index 9696ac6..2e9265c 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -19,9 +19,11 @@ <ClInclude Include="$(MSBuildThisFileDirectory)accel-linear.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-logarithmic.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)accel-naturalgain.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-noaccel.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-power.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoid.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoidgain.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-error.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" /> diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 8dc4825..23a8214 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -9,8 +9,10 @@ #include "accel-linear.hpp" #include "accel-classic.hpp" #include "accel-natural.hpp" +#include "accel-naturalgain.hpp" #include "accel-logarithmic.hpp" #include "accel-sigmoid.hpp" +#include "accel-sigmoidgain.hpp" #include "accel-power.hpp" #include "accel-noaccel.hpp" @@ -76,7 +78,7 @@ namespace rawaccel { }; /// <summary> Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call. </summary> - using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_noaccel>; + using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_naturalgain, accel_sigmoidgain, accel_noaccel>; /// <summary> Struct to hold information about applying a gain cap. </summary> struct velocity_gain_cap { @@ -183,6 +185,8 @@ namespace rawaccel { vec2<accel_scale_clamp> clamp; velocity_gain_cap gain_cap = velocity_gain_cap(); + + accel_args impl_args; accel_function(const accel_fn_args& args) { if (args.time_min <= 0) bad_arg("min time must be positive"); @@ -190,6 +194,7 @@ namespace rawaccel { accel.tag = args.accel_mode; accel.visit([&](auto& impl) { impl = { args.acc_args }; }); + impl_args = args.acc_args; time_min = args.time_min; speed_offset = args.acc_args.offset; diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index f30de99..ac438a1 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -85,14 +85,35 @@ namespace grapher this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.graphsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.showVelocityGainToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.scaleByDPIToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dPIToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DPITextBox = new System.Windows.Forms.ToolStripTextBox(); + this.pollRateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.PollRateTextBox = new System.Windows.Forms.ToolStripTextBox(); + this.ScaleMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.advancedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.capStyleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sensitivityToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.velocityGainToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.startupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AccelerationChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.VelocityChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.GainChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.MouseLabel = new System.Windows.Forms.Label(); + this.ActiveValueTitle = new System.Windows.Forms.Label(); + this.SensitivityActiveXLabel = new System.Windows.Forms.Label(); + this.SensitivityActiveYLabel = new System.Windows.Forms.Label(); + this.RotationActiveLabel = new System.Windows.Forms.Label(); + this.AccelTypeActiveLabel = new System.Windows.Forms.Label(); + this.AccelerationActiveLabel = new System.Windows.Forms.Label(); + this.CapActiveXLabel = new System.Windows.Forms.Label(); + this.WeightActiveXLabel = new System.Windows.Forms.Label(); + this.WeightActiveYLabel = new System.Windows.Forms.Label(); + this.CapActiveYLabel = new System.Windows.Forms.Label(); + this.OffsetActiveLabel = new System.Windows.Forms.Label(); + this.LimitExpActiveLabel = new System.Windows.Forms.Label(); + this.MidpointActiveLabel = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.VelocityChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.GainChart)).BeginInit(); @@ -110,7 +131,7 @@ namespace grapher this.AccelerationChart.ChartAreas.Add(chartArea1); legend1.Name = "Legend1"; this.AccelerationChart.Legends.Add(legend1); - this.AccelerationChart.Location = new System.Drawing.Point(240, 0); + this.AccelerationChart.Location = new System.Drawing.Point(333, 0); this.AccelerationChart.Name = "AccelerationChart"; series1.ChartArea = "ChartArea1"; series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; @@ -351,7 +372,7 @@ namespace grapher this.VelocityChart.ChartAreas.Add(chartArea2); legend2.Name = "Legend1"; this.VelocityChart.Legends.Add(legend2); - this.VelocityChart.Location = new System.Drawing.Point(240, 334); + this.VelocityChart.Location = new System.Drawing.Point(333, 334); this.VelocityChart.Name = "VelocityChart"; series3.ChartArea = "ChartArea1"; series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; @@ -376,7 +397,7 @@ namespace grapher this.GainChart.ChartAreas.Add(chartArea3); legend3.Name = "Legend1"; this.GainChart.Legends.Add(legend3); - this.GainChart.Location = new System.Drawing.Point(240, 647); + this.GainChart.Location = new System.Drawing.Point(333, 647); this.GainChart.Name = "GainChart"; series5.ChartArea = "ChartArea1"; series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; @@ -398,10 +419,11 @@ namespace grapher this.menuStrip1.BackColor = System.Drawing.SystemColors.ControlLight; this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.graphsToolStripMenuItem, - this.advancedToolStripMenuItem}); + this.advancedToolStripMenuItem, + this.startupToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1693, 24); + this.menuStrip1.Size = new System.Drawing.Size(1786, 24); this.menuStrip1.TabIndex = 30; this.menuStrip1.Text = "menuStrip1"; // @@ -409,7 +431,8 @@ namespace grapher // this.graphsToolStripMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.graphsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.showVelocityGainToolStripMenuItem}); + this.showVelocityGainToolStripMenuItem, + this.scaleByDPIToolStripMenuItem}); 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); @@ -418,9 +441,53 @@ namespace grapher // showVelocityGainToolStripMenuItem // this.showVelocityGainToolStripMenuItem.Name = "showVelocityGainToolStripMenuItem"; - this.showVelocityGainToolStripMenuItem.Size = new System.Drawing.Size(187, 22); + this.showVelocityGainToolStripMenuItem.Size = new System.Drawing.Size(198, 22); this.showVelocityGainToolStripMenuItem.Text = "Show Velocity && Gain"; // + // scaleByDPIToolStripMenuItem + // + this.scaleByDPIToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.dPIToolStripMenuItem, + this.pollRateToolStripMenuItem, + this.ScaleMenuItem}); + this.scaleByDPIToolStripMenuItem.Name = "scaleByDPIToolStripMenuItem"; + this.scaleByDPIToolStripMenuItem.Size = new System.Drawing.Size(198, 22); + this.scaleByDPIToolStripMenuItem.Text = "Scale by Mouse Settngs"; + // + // dPIToolStripMenuItem + // + this.dPIToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.DPITextBox}); + this.dPIToolStripMenuItem.Name = "dPIToolStripMenuItem"; + this.dPIToolStripMenuItem.Size = new System.Drawing.Size(169, 22); + this.dPIToolStripMenuItem.Text = "DPI"; + // + // DPITextBox + // + this.DPITextBox.Font = new System.Drawing.Font("Segoe UI", 9F); + this.DPITextBox.Name = "DPITextBox"; + this.DPITextBox.Size = new System.Drawing.Size(100, 23); + // + // pollRateToolStripMenuItem + // + this.pollRateToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.PollRateTextBox}); + this.pollRateToolStripMenuItem.Name = "pollRateToolStripMenuItem"; + this.pollRateToolStripMenuItem.Size = new System.Drawing.Size(169, 22); + this.pollRateToolStripMenuItem.Text = "Poll Rate"; + // + // PollRateTextBox + // + this.PollRateTextBox.Font = new System.Drawing.Font("Segoe UI", 9F); + this.PollRateTextBox.Name = "PollRateTextBox"; + this.PollRateTextBox.Size = new System.Drawing.Size(100, 23); + // + // ScaleMenuItem + // + this.ScaleMenuItem.Name = "ScaleMenuItem"; + this.ScaleMenuItem.Size = new System.Drawing.Size(169, 22); + this.ScaleMenuItem.Text = "Re-scale by above"; + // // advancedToolStripMenuItem // this.advancedToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -452,6 +519,23 @@ namespace grapher this.velocityGainToolStripMenuItem.Size = new System.Drawing.Size(142, 22); this.velocityGainToolStripMenuItem.Text = "Velocity Gain"; // + // startupToolStripMenuItem + // + this.startupToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.AutoWriteMenuItem}); + this.startupToolStripMenuItem.Name = "startupToolStripMenuItem"; + this.startupToolStripMenuItem.Size = new System.Drawing.Size(57, 20); + this.startupToolStripMenuItem.Text = "Startup"; + // + // AutoWriteMenuItem + // + this.AutoWriteMenuItem.Checked = true; + this.AutoWriteMenuItem.CheckOnClick = true; + this.AutoWriteMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.AutoWriteMenuItem.Name = "AutoWriteMenuItem"; + this.AutoWriteMenuItem.Size = new System.Drawing.Size(229, 22); + this.AutoWriteMenuItem.Text = "Apply Settings File on Startup"; + // // AccelerationChartY // chartArea4.AxisX.Title = "Speed (counts/ms)"; @@ -460,7 +544,7 @@ namespace grapher this.AccelerationChartY.ChartAreas.Add(chartArea4); legend4.Name = "Legend1"; this.AccelerationChartY.Legends.Add(legend4); - this.AccelerationChartY.Location = new System.Drawing.Point(969, 0); + this.AccelerationChartY.Location = new System.Drawing.Point(1062, 0); this.AccelerationChartY.Name = "AccelerationChartY"; series7.ChartArea = "ChartArea1"; series7.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; @@ -485,7 +569,7 @@ namespace grapher this.VelocityChartY.ChartAreas.Add(chartArea5); legend5.Name = "Legend1"; this.VelocityChartY.Legends.Add(legend5); - this.VelocityChartY.Location = new System.Drawing.Point(970, 334); + this.VelocityChartY.Location = new System.Drawing.Point(1062, 334); this.VelocityChartY.Name = "VelocityChartY"; series9.ChartArea = "ChartArea1"; series9.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; @@ -510,7 +594,7 @@ namespace grapher this.GainChartY.ChartAreas.Add(chartArea6); legend6.Name = "Legend1"; this.GainChartY.Legends.Add(legend6); - this.GainChartY.Location = new System.Drawing.Point(970, 647); + this.GainChartY.Location = new System.Drawing.Point(1062, 647); this.GainChartY.Name = "GainChartY"; series11.ChartArea = "ChartArea1"; series11.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; @@ -536,11 +620,141 @@ namespace grapher this.MouseLabel.TabIndex = 34; this.MouseLabel.Text = "Last (x, y): (x, y)"; // + // ActiveValueTitle + // + this.ActiveValueTitle.AutoSize = true; + this.ActiveValueTitle.Location = new System.Drawing.Point(248, 30); + this.ActiveValueTitle.Name = "ActiveValueTitle"; + this.ActiveValueTitle.Size = new System.Drawing.Size(67, 13); + this.ActiveValueTitle.TabIndex = 35; + this.ActiveValueTitle.Text = "Active Value"; + // + // SensitivityActiveXLabel + // + this.SensitivityActiveXLabel.AutoSize = true; + this.SensitivityActiveXLabel.Location = new System.Drawing.Point(258, 49); + this.SensitivityActiveXLabel.Name = "SensitivityActiveXLabel"; + this.SensitivityActiveXLabel.Size = new System.Drawing.Size(14, 13); + this.SensitivityActiveXLabel.TabIndex = 36; + this.SensitivityActiveXLabel.Text = "X"; + // + // SensitivityActiveYLabel + // + this.SensitivityActiveYLabel.AutoSize = true; + this.SensitivityActiveYLabel.Location = new System.Drawing.Point(286, 50); + this.SensitivityActiveYLabel.Name = "SensitivityActiveYLabel"; + this.SensitivityActiveYLabel.Size = new System.Drawing.Size(14, 13); + this.SensitivityActiveYLabel.TabIndex = 37; + this.SensitivityActiveYLabel.Text = "Y"; + // + // RotationActiveLabel + // + this.RotationActiveLabel.AutoSize = true; + this.RotationActiveLabel.Location = new System.Drawing.Point(268, 75); + this.RotationActiveLabel.Name = "RotationActiveLabel"; + this.RotationActiveLabel.Size = new System.Drawing.Size(13, 13); + this.RotationActiveLabel.TabIndex = 38; + this.RotationActiveLabel.Text = "0"; + // + // AccelTypeActiveLabel + // + this.AccelTypeActiveLabel.AutoSize = true; + this.AccelTypeActiveLabel.Location = new System.Drawing.Point(258, 98); + this.AccelTypeActiveLabel.Name = "AccelTypeActiveLabel"; + this.AccelTypeActiveLabel.Size = new System.Drawing.Size(41, 13); + this.AccelTypeActiveLabel.TabIndex = 39; + this.AccelTypeActiveLabel.Text = "Default"; + // + // AccelerationActiveLabel + // + this.AccelerationActiveLabel.AutoSize = true; + this.AccelerationActiveLabel.Location = new System.Drawing.Point(268, 128); + this.AccelerationActiveLabel.Name = "AccelerationActiveLabel"; + this.AccelerationActiveLabel.Size = new System.Drawing.Size(13, 13); + this.AccelerationActiveLabel.TabIndex = 40; + this.AccelerationActiveLabel.Text = "0"; + // + // CapActiveXLabel + // + this.CapActiveXLabel.AutoSize = true; + this.CapActiveXLabel.Location = new System.Drawing.Point(259, 151); + this.CapActiveXLabel.Name = "CapActiveXLabel"; + this.CapActiveXLabel.Size = new System.Drawing.Size(13, 13); + this.CapActiveXLabel.TabIndex = 41; + this.CapActiveXLabel.Text = "0"; + // + // WeightActiveXLabel + // + this.WeightActiveXLabel.AutoSize = true; + this.WeightActiveXLabel.Location = new System.Drawing.Point(259, 180); + this.WeightActiveXLabel.Name = "WeightActiveXLabel"; + this.WeightActiveXLabel.Size = new System.Drawing.Size(13, 13); + this.WeightActiveXLabel.TabIndex = 42; + this.WeightActiveXLabel.Text = "0"; + // + // WeightActiveYLabel + // + this.WeightActiveYLabel.AutoSize = true; + this.WeightActiveYLabel.Location = new System.Drawing.Point(286, 180); + this.WeightActiveYLabel.Name = "WeightActiveYLabel"; + this.WeightActiveYLabel.Size = new System.Drawing.Size(13, 13); + this.WeightActiveYLabel.TabIndex = 43; + this.WeightActiveYLabel.Text = "0"; + // + // CapActiveYLabel + // + this.CapActiveYLabel.AutoSize = true; + this.CapActiveYLabel.Location = new System.Drawing.Point(286, 151); + this.CapActiveYLabel.Name = "CapActiveYLabel"; + this.CapActiveYLabel.Size = new System.Drawing.Size(13, 13); + this.CapActiveYLabel.TabIndex = 44; + this.CapActiveYLabel.Text = "0"; + // + // OffsetActiveLabel + // + this.OffsetActiveLabel.AutoSize = true; + this.OffsetActiveLabel.Location = new System.Drawing.Point(268, 206); + this.OffsetActiveLabel.Name = "OffsetActiveLabel"; + this.OffsetActiveLabel.Size = new System.Drawing.Size(13, 13); + this.OffsetActiveLabel.TabIndex = 45; + this.OffsetActiveLabel.Text = "0"; + // + // LimitExpActiveLabel + // + this.LimitExpActiveLabel.AutoSize = true; + this.LimitExpActiveLabel.Location = new System.Drawing.Point(268, 232); + this.LimitExpActiveLabel.Name = "LimitExpActiveLabel"; + this.LimitExpActiveLabel.Size = new System.Drawing.Size(13, 13); + this.LimitExpActiveLabel.TabIndex = 46; + this.LimitExpActiveLabel.Text = "0"; + // + // MidpointActiveLabel + // + this.MidpointActiveLabel.AutoSize = true; + this.MidpointActiveLabel.Location = new System.Drawing.Point(268, 255); + this.MidpointActiveLabel.Name = "MidpointActiveLabel"; + this.MidpointActiveLabel.Size = new System.Drawing.Size(13, 13); + this.MidpointActiveLabel.TabIndex = 47; + this.MidpointActiveLabel.Text = "0"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1693, 958); + this.ClientSize = new System.Drawing.Size(1786, 958); + this.Controls.Add(this.MidpointActiveLabel); + this.Controls.Add(this.LimitExpActiveLabel); + this.Controls.Add(this.OffsetActiveLabel); + this.Controls.Add(this.CapActiveYLabel); + this.Controls.Add(this.WeightActiveYLabel); + this.Controls.Add(this.WeightActiveXLabel); + this.Controls.Add(this.CapActiveXLabel); + this.Controls.Add(this.AccelerationActiveLabel); + this.Controls.Add(this.AccelTypeActiveLabel); + this.Controls.Add(this.RotationActiveLabel); + this.Controls.Add(this.SensitivityActiveYLabel); + this.Controls.Add(this.SensitivityActiveXLabel); + this.Controls.Add(this.ActiveValueTitle); this.Controls.Add(this.MouseLabel); this.Controls.Add(this.GainChartY); this.Controls.Add(this.VelocityChartY); @@ -632,6 +846,27 @@ namespace grapher private System.Windows.Forms.DataVisualization.Charting.Chart VelocityChartY; private System.Windows.Forms.DataVisualization.Charting.Chart GainChartY; private System.Windows.Forms.Label MouseLabel; + private System.Windows.Forms.ToolStripMenuItem scaleByDPIToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem dPIToolStripMenuItem; + private System.Windows.Forms.ToolStripTextBox DPITextBox; + private System.Windows.Forms.ToolStripMenuItem pollRateToolStripMenuItem; + private System.Windows.Forms.ToolStripTextBox PollRateTextBox; + private System.Windows.Forms.ToolStripMenuItem ScaleMenuItem; + private System.Windows.Forms.Label ActiveValueTitle; + private System.Windows.Forms.Label SensitivityActiveXLabel; + private System.Windows.Forms.Label SensitivityActiveYLabel; + private System.Windows.Forms.Label RotationActiveLabel; + private System.Windows.Forms.Label AccelTypeActiveLabel; + private System.Windows.Forms.Label AccelerationActiveLabel; + private System.Windows.Forms.Label CapActiveXLabel; + private System.Windows.Forms.Label WeightActiveXLabel; + private System.Windows.Forms.Label WeightActiveYLabel; + private System.Windows.Forms.Label CapActiveYLabel; + private System.Windows.Forms.Label OffsetActiveLabel; + private System.Windows.Forms.Label LimitExpActiveLabel; + private System.Windows.Forms.Label MidpointActiveLabel; + private System.Windows.Forms.ToolStripMenuItem startupToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem AutoWriteMenuItem; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index d8db6fc..d6f7990 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -9,12 +9,15 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; +using grapher.Models.Calculations; +using grapher.Models.Options; +using grapher.Models.Serialized; namespace grapher { public enum accel_mode { - linear=1, classic, natural, logarithmic, sigmoid, power, noaccel + linear=1, classic, natural, logarithmic, sigmoid, power, naturalgain, sigmoidgain, noaccel } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -89,6 +92,7 @@ namespace grapher Marshal.FreeHGlobal(args_ptr); + var accelCharts = new AccelCharts( this, new ChartXY(AccelerationChart, AccelerationChartY), @@ -97,17 +101,81 @@ namespace grapher showVelocityGainToolStripMenuItem, new CheckBox[] { sensXYLock, weightXYLock, capXYLock }); + ActiveValueTitle.AutoSize = false; + ActiveValueTitle.Left = LockXYLabel.Left + LockXYLabel.Width; + ActiveValueTitle.Width = AccelerationChart.Left - ActiveValueTitle.Left; + ActiveValueTitle.TextAlign = ContentAlignment.MiddleCenter; - var sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity", accelCharts); - var rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation"); - var weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight", accelCharts); - var cap = new OptionXY(capBoxX, capBoxY, capXYLock, this, 0, capLabel, "Cap", accelCharts); - var offset = new Option(offsetBox, this, 0, offsetLabel, "Offset"); + var sensitivity = new OptionXY( + sensitivityBoxX, + sensitivityBoxY, + sensXYLock, + this, + 1, + sensitivityLabel, + new ActiveValueLabelXY( + new ActiveValueLabel(SensitivityActiveXLabel, ActiveValueTitle), + new ActiveValueLabel(SensitivityActiveYLabel, ActiveValueTitle)), + "Sensitivity", + accelCharts); + + var rotation = new Option( + rotationBox, + this, + 0, + rotationLabel, + new ActiveValueLabel(RotationActiveLabel, ActiveValueTitle), + "Rotation"); + + var weight = new OptionXY( + weightBoxFirst, + weightBoxSecond, + weightXYLock, + this, + 1, + weightLabel, + new ActiveValueLabelXY( + new ActiveValueLabel(WeightActiveXLabel, ActiveValueTitle), + new ActiveValueLabel(WeightActiveYLabel, ActiveValueTitle)), + "Weight", + accelCharts); + + var cap = new OptionXY( + capBoxX, + capBoxY, + capXYLock, + this, + 0, + capLabel, + new ActiveValueLabelXY( + new ActiveValueLabel(CapActiveXLabel, ActiveValueTitle), + new ActiveValueLabel(CapActiveYLabel, ActiveValueTitle)), + "Cap", + accelCharts); + + var offset = new Option( + offsetBox, + this, + 0, + offsetLabel, + new ActiveValueLabel(OffsetActiveLabel, ActiveValueTitle), + "Offset"); // The name and layout of these options is handled by AccelerationOptions object. - 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); + var acceleration = new Option( + new Field(accelerationBox, this, 0), + constantOneLabel, + new ActiveValueLabel(AccelerationActiveLabel, ActiveValueTitle)); + + var limitOrExponent = new Option( + new Field(limitBox, this, 2), + constantTwoLabel, + new ActiveValueLabel(LimitExpActiveLabel, ActiveValueTitle)); + + var midpoint = new Option( + new Field(midpointBox, this, 0), + constantThreeLabel, + new ActiveValueLabel(MidpointActiveLabel, ActiveValueTitle)); var accelerationOptions = new AccelOptions( accelTypeDrop, @@ -123,7 +191,8 @@ namespace grapher weight, cap, }, - writeButton); + writeButton, + new ActiveValueLabel(AccelTypeActiveLabel, ActiveValueTitle)); var capOptions = new CapOptions( sensitivityToolStripMenuItem, @@ -131,10 +200,21 @@ namespace grapher cap, weight); + var accelCalculator = new AccelCalculator( + new Field(DPITextBox.TextBox, this, AccelCalculator.DefaultDPI), + new Field(PollRateTextBox.TextBox, this, AccelCalculator.DefaultPollRate)); + + var settings = new SettingsManager( + managedAcceleration, + accelCalculator.DPI, + accelCalculator.PollRate, + AutoWriteMenuItem); + AccelGUI = new AccelGUI( this, + accelCalculator, accelCharts, - managedAcceleration, + settings, accelerationOptions, sensitivity, rotation, @@ -145,7 +225,9 @@ namespace grapher limitOrExponent, midpoint, writeButton, - MouseLabel); + MouseLabel, + ScaleMenuItem, + AutoWriteMenuItem); } #endregion Constructor @@ -175,21 +257,7 @@ namespace grapher private void writeButton_Click(object sender, EventArgs e) { - 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.SensitivityCapX, - AccelGUI.Cap.SensitivityCapY, - AccelGUI.Offset.Field.Data, - AccelGUI.Acceleration.Field.Data, - AccelGUI.LimitOrExponent.Field.Data, - AccelGUI.Midpoint.Field.Data, - AccelGUI.Cap.VelocityGainCap); - AccelGUI.UpdateGraph(); + AccelGUI.UpdateActiveSettingsFromFields(); } #endregion Methods diff --git a/grapher/Layouts/NaturalGainLayout.cs b/grapher/Layouts/NaturalGainLayout.cs new file mode 100644 index 0000000..e062850 --- /dev/null +++ b/grapher/Layouts/NaturalGainLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class NaturalGainLayout : LayoutBase + { + public NaturalGainLayout() + : base() + { + Name = "NaturalGain"; + Index = 7; + ShowOptions = new bool[] { true, true, true, false }; + OptionNames = new string[] { Offset, Acceleration, Limit, string.Empty }; + } + } +} diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs index cecba05..087885f 100644 --- a/grapher/Layouts/OffLayout.cs +++ b/grapher/Layouts/OffLayout.cs @@ -12,7 +12,7 @@ namespace grapher.Layouts : base() { Name = "Off"; - Index = 7; + Index = 9; ShowOptions = new bool[] { false, false, false, false }; OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty }; ShowOptionsXY = new bool[] { false, false }; diff --git a/grapher/Layouts/SigmoidGainLayout.cs b/grapher/Layouts/SigmoidGainLayout.cs new file mode 100644 index 0000000..c620925 --- /dev/null +++ b/grapher/Layouts/SigmoidGainLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class SigmoidGainLayout : LayoutBase + { + public SigmoidGainLayout() + : base() + { + Name = "SigmoidGain"; + Index = 8; + ShowOptions = new bool[] { true, true, true, true }; + OptionNames = new string[] { Offset, Acceleration, Limit, Midpoint }; + } + } +} diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 8eb2226..e0dcc03 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -1,5 +1,6 @@ using grapher.Models.Calculations; using grapher.Models.Mouse; +using grapher.Models.Serialized; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -18,8 +19,9 @@ namespace grapher public AccelGUI( RawAcceleration accelForm, + AccelCalculator accelCalculator, AccelCharts accelCharts, - ManagedAccel managedAccel, + SettingsManager settings, AccelOptions accelOptions, OptionXY sensitivity, Option rotation, @@ -30,11 +32,13 @@ namespace grapher Option limtOrExp, Option midpoint, Button writeButton, - Label mouseMoveLabel) + Label mouseMoveLabel, + ToolStripMenuItem scaleMenuItem, + ToolStripMenuItem autoWriteMenuItem) { AccelForm = accelForm; + AccelCalculator = accelCalculator; AccelCharts = accelCharts; - ManagedAcceleration = managedAccel; AccelerationOptions = accelOptions; Sensitivity = sensitivity; Rotation = rotation; @@ -45,11 +49,14 @@ namespace grapher LimitOrExponent = limtOrExp; Midpoint = midpoint; WriteButton = writeButton; - - ManagedAcceleration.ReadFromDriver(); + ScaleMenuItem = scaleMenuItem; + Settings = settings; + Settings.Startup(); UpdateGraph(); MouseWatcher = new MouseWatcher(AccelForm, mouseMoveLabel, AccelCharts); + + ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); } #endregion constructors @@ -58,9 +65,11 @@ namespace grapher public RawAcceleration AccelForm { get; } + public AccelCalculator AccelCalculator { get; } + public AccelCharts AccelCharts { get; } - public ManagedAccel ManagedAcceleration { get; } + public SettingsManager Settings { get; } public AccelOptions AccelerationOptions { get; } @@ -84,17 +93,55 @@ namespace grapher public MouseWatcher MouseWatcher { get; } + public ToolStripMenuItem ScaleMenuItem { get; } + #endregion properties #region methods + public void UpdateActiveSettingsFromFields() + { + Settings.UpdateActiveSettings( + AccelerationOptions.AccelerationIndex, + Rotation.Field.Data, + Sensitivity.Fields.X, + Sensitivity.Fields.Y, + Weight.Fields.X, + Weight.Fields.Y, + Cap.SensitivityCapX, + Cap.SensitivityCapY, + Offset.Field.Data, + Acceleration.Field.Data, + LimitOrExponent.Field.Data, + Midpoint.Field.Data, + Cap.VelocityGainCap); + UpdateGraph(); + } public void UpdateGraph() { - AccelCalculator.Calculate(AccelCharts.AccelData, ManagedAcceleration); + AccelCalculator.Calculate(AccelCharts.AccelData, Settings.ActiveAccel); AccelCharts.Bind(); + UpdateActiveValueLabels(); } + public void UpdateActiveValueLabels() + { + Sensitivity.SetActiveValues(Settings.ActiveAccel.SensitivityX, Settings.ActiveAccel.SensitivityY); + Rotation.SetActiveValue(Settings.ActiveAccel.Rotation); + AccelerationOptions.SetActiveValue(Settings.ActiveAccel.Type); + Offset.SetActiveValue(Settings.ActiveAccel.Offset); + Acceleration.SetActiveValue(Settings.ActiveAccel.Acceleration); + Cap.SetActiveValues(Settings.ActiveAccel.GainCap, Settings.ActiveAccel.CapX, Settings.ActiveAccel.CapY, Settings.ActiveAccel.GainCapEnabled); + Weight.SetActiveValues(Settings.ActiveAccel.WeightX, Settings.ActiveAccel.WeightY); + LimitOrExponent.SetActiveValue(Settings.ActiveAccel.LimitExp); + Midpoint.SetActiveValue(Settings.ActiveAccel.Midpoint); + } + + private void OnScaleMenuItemClick(object sender, EventArgs e) + { + UpdateGraph(); + } #endregion methods } diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index bba3c32..63ed281 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -4,13 +4,17 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace grapher.Models.Calculations { - public static class AccelCalculator + public class AccelCalculator { - public const int MaxCombined = 100; - public const int MaxXY = 150; + public const int DefaultDPI = 1200; + public const int DefaultPollRate = 1000; + public const int Resolution = 100; + public const double MaxMultiplier = 85; + public const double XYToCombinedRatio = 1.3; public struct MagnitudeData { @@ -19,17 +23,38 @@ namespace grapher.Models.Calculations public int y; } - public static ReadOnlyCollection<MagnitudeData> MagnitudesCombined = GetMagnitudes(); - public static ReadOnlyCollection<MagnitudeData> MagnitudesX = GetMagnitudesX(); - public static ReadOnlyCollection<MagnitudeData> MagnitudesY = GetMagnitudesY(); - public static void Calculate(AccelData data, ManagedAccel accel) + public AccelCalculator(Field dpi, Field pollRate) { + DPI = dpi; + PollRate = pollRate; + } + + public ReadOnlyCollection<MagnitudeData> MagnitudesCombined { get; private set; } + + public ReadOnlyCollection<MagnitudeData> MagnitudesX { get; private set; } + + public ReadOnlyCollection<MagnitudeData> MagnitudesY { get; private set; } + + public Field DPI { get; private set; } + + public Field PollRate { get; private set; } + + private double CombinedMaxVelocity { get; set; } + + private double XYMaxVelocity { get; set; } + + private int Increment { get; set; } + + public void Calculate(AccelData data, ManagedAccel accel) + { + ScaleByMouseSettings(); + data.Clear(); - Calculate(data.Combined, accel, accel.GetSensitivityX(), MagnitudesCombined); - Calculate(data.X, accel, accel.GetSensitivityX(), MagnitudesX); - Calculate(data.Y, accel, accel.GetSensitivityY(), MagnitudesY); + Calculate(data.Combined, accel, accel.SensitivityX, MagnitudesCombined); + Calculate(data.X, accel, accel.SensitivityX, MagnitudesX); + Calculate(data.Y, accel, accel.SensitivityY, MagnitudesY); } public static void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection<MagnitudeData> magnitudeData) @@ -70,12 +95,12 @@ namespace grapher.Models.Calculations data.OrderedVelocityPointsList.AddRange(data.VelocityPoints.Values.ToList()); } - public static ReadOnlyCollection<MagnitudeData> GetMagnitudes() + public ReadOnlyCollection<MagnitudeData> GetMagnitudes() { var magnitudes = new List<MagnitudeData>(); - for (int i = 0; i < MaxCombined; i++) + for (int i = 0; i < CombinedMaxVelocity; i+=Increment) { - for (int j = 0; j <= i; j++) + for (int j = 0; j <= i; j+=Increment) { MagnitudeData magnitudeData; magnitudeData.magnitude = Magnitude(i, j); @@ -90,11 +115,11 @@ namespace grapher.Models.Calculations return magnitudes.AsReadOnly(); } - public static ReadOnlyCollection<MagnitudeData> GetMagnitudesX() + public ReadOnlyCollection<MagnitudeData> GetMagnitudesX() { var magnitudes = new List<MagnitudeData>(); - for (int i = 0; i < MaxXY; i++) + for (int i = 0; i < XYMaxVelocity; i+=Increment) { MagnitudeData magnitudeData; magnitudeData.magnitude = i; @@ -106,11 +131,11 @@ namespace grapher.Models.Calculations return magnitudes.AsReadOnly(); } - public static ReadOnlyCollection<MagnitudeData> GetMagnitudesY() + public ReadOnlyCollection<MagnitudeData> GetMagnitudesY() { var magnitudes = new List<MagnitudeData>(); - for (int i = 0; i < MaxXY; i++) + for (int i = 0; i < XYMaxVelocity; i+=Increment) { MagnitudeData magnitudeData; magnitudeData.magnitude = i; @@ -141,5 +166,16 @@ namespace grapher.Models.Calculations { return Magnitude(x, y) / time; } + + public void ScaleByMouseSettings() + { + var dpiPollFactor = DPI.Data / PollRate.Data; + CombinedMaxVelocity = dpiPollFactor * MaxMultiplier; + Increment = (int) Math.Floor(CombinedMaxVelocity / Resolution); + XYMaxVelocity = CombinedMaxVelocity * 1.5; + MagnitudesCombined = GetMagnitudes(); + MagnitudesX = GetMagnitudesX(); + MagnitudesY = GetMagnitudesY(); + } } } diff --git a/grapher/Models/Options/AccelOptions.cs b/grapher/Models/Options/AccelOptions.cs index b233552..cd7c4e5 100644 --- a/grapher/Models/Options/AccelOptions.cs +++ b/grapher/Models/Options/AccelOptions.cs @@ -1,4 +1,5 @@ using grapher.Layouts; +using grapher.Models.Options; using System; using System.Collections.Generic; using System.Linq; @@ -22,6 +23,8 @@ namespace grapher new LogLayout(), new SigmoidLayout(), new PowerLayout(), + new NaturalGainLayout(), + new SigmoidGainLayout(), new OffLayout() }.ToDictionary(k => k.Name); @@ -29,7 +32,8 @@ namespace grapher ComboBox accelDropdown, Option[] options, OptionXY[] optionsXY, - Button writeButton) + Button writeButton, + ActiveValueLabel activeValueLabel) { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); @@ -49,6 +53,7 @@ namespace grapher Options = options; OptionsXY = optionsXY; WriteButton = writeButton; + ActiveValueLabel = activeValueLabel; Layout("Default"); } @@ -59,10 +64,18 @@ namespace grapher public int AccelerationIndex { get; private set; } + public ActiveValueLabel ActiveValueLabel { get; } + public Option[] Options { get; } public OptionXY[] OptionsXY { get; } + public void SetActiveValue(int index) + { + var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name; + ActiveValueLabel.SetValue(name); + } + private void OnIndexChanged(object sender, EventArgs e) { var accelerationTypeString = AccelDropdown.SelectedItem.ToString(); diff --git a/grapher/Models/Options/ActiveValueLabel.cs b/grapher/Models/Options/ActiveValueLabel.cs new file mode 100644 index 0000000..138775a --- /dev/null +++ b/grapher/Models/Options/ActiveValueLabel.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class ActiveValueLabel + { + public const string DefaultFormatString = "0.######"; + public static readonly Color ActiveValueFontColor = Color.FromArgb(255, 65, 65, 65); + + private string _prefix; + private string _value; + + public ActiveValueLabel(Label valueLabel, Label centeringLabel) + { + ValueLabel = valueLabel; + ValueLabel.ForeColor = ActiveValueFontColor; + Left = centeringLabel.Left; + Width = centeringLabel.Width; + ValueLabel.AutoSize = false; + ValueLabel.TextAlign = ContentAlignment.MiddleCenter; + + FormatString = DefaultFormatString; + Prefix = string.Empty; + } + + public Label ValueLabel { get; } + + public string FormatString { get; set; } + + public string Prefix + { + get { return _prefix; } + set + { + _prefix = value; + RefreshText(); + } + } + + private string Value + { + get { return _value; } + set + { + _value = value; + RefreshText(); + } + } + + public int Left + { + get + { + return ValueLabel.Left; + } + + set + { + ValueLabel.Left = value; + } + } + + public int Width + { + get + { + return ValueLabel.Width; + } + + set + { + ValueLabel.Width = value; + } + } + + public void Hide() + { + ValueLabel.Hide(); + } + + public void Show() + { + ValueLabel.Show(); + } + + public void SetValue(double value) + { + SetValue(value.ToString(FormatString)); + } + + public void SetValue(string value) + { + Value = value; + } + + public void RefreshText() + { + ValueLabel.Text = string.IsNullOrWhiteSpace(Prefix) ? Value: $"{Prefix}: {Value}"; + } + } +} diff --git a/grapher/Models/Options/ActiveValueLabelXY.cs b/grapher/Models/Options/ActiveValueLabelXY.cs new file mode 100644 index 0000000..12506e9 --- /dev/null +++ b/grapher/Models/Options/ActiveValueLabelXY.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Options +{ + public class ActiveValueLabelXY + { + public const int ActiveLabelXYSeparation = 2; + public const string ShortenedFormatString = "0.###"; + + public ActiveValueLabelXY( + ActiveValueLabel x, + ActiveValueLabel y) + { + X = x; + Y = y; + + FullWidth = x.Width; + ShortenedWidth = (FullWidth - ActiveLabelXYSeparation) / 2; + + Y.Left = X.Left + ShortenedWidth + ActiveLabelXYSeparation; + Y.Width = ShortenedWidth; + Y.FormatString = ShortenedFormatString; + + Combined = false; + SetCombined(); + } + + public ActiveValueLabel X { get; } + + public ActiveValueLabel Y { get; } + + public bool Combined { get; private set; } + + private int FullWidth { get; } + + private int ShortenedWidth { get; } + + public void SetValues(double x, double y) + { + X.SetValue(x); + Y.SetValue(y); + + if (x == y) + { + SetCombined(); + } + else + { + SetSeparate(); + } + } + + public void SetCombined() + { + if (!Combined) + { + X.FormatString = ActiveValueLabel.DefaultFormatString; + X.Width = FullWidth; + X.Prefix = string.Empty; + Y.Hide(); + } + + Combined = true; + } + + public void SetSeparate() + { + if (Combined) + { + X.FormatString = ShortenedFormatString; + X.Width = ShortenedWidth; + X.Prefix = "X"; + Y.Prefix = "Y"; + Y.Show(); + } + + Combined = false; + } + } +} diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs index 2ee7f6b..493561a 100644 --- a/grapher/Models/Options/CapOptions.cs +++ b/grapher/Models/Options/CapOptions.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Options; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,6 +10,9 @@ namespace grapher { public class CapOptions { + + public const string GainCapFormatString = "0.##"; + public CapOptions( ToolStripMenuItem sensitivityCapCheck, ToolStripMenuItem velocityGainCapCheck, @@ -30,13 +34,13 @@ namespace grapher EnableSensitivityCap(); } - ToolStripMenuItem SensitivityCapCheck { get; } + public ToolStripMenuItem SensitivityCapCheck { get; } - ToolStripMenuItem VelocityGainCapCheck { get; } + public ToolStripMenuItem VelocityGainCapCheck { get; } - OptionXY CapOption { get; } + public OptionXY CapOption { get; } - OptionXY WeightOption { get; } + public OptionXY WeightOption { get; } public double SensitivityCapX { get @@ -82,6 +86,22 @@ namespace grapher public bool IsSensitivityGain { get; private set; } + public void SetActiveValues(double gainCap, double sensCapX, double sensCapY, bool capGainEnabled) + { + if (capGainEnabled) + { + CapOption.ActiveValueLabels.X.FormatString = GainCapFormatString; + CapOption.ActiveValueLabels.X.Prefix = "Gain"; + CapOption.SetActiveValues(gainCap, gainCap); + } + else + { + CapOption.ActiveValueLabels.X.FormatString = ActiveValueLabel.DefaultFormatString; + CapOption.ActiveValueLabels.X.Prefix = string.Empty; + CapOption.SetActiveValues(sensCapX, sensCapY); + } + } + void OnSensitivityCapCheckClick(object sender, EventArgs e) { if (!SensitivityCapCheck.Checked) diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs index eb5105e..bacd760 100644 --- a/grapher/Models/Options/Option.cs +++ b/grapher/Models/Options/Option.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Options; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,19 +10,42 @@ namespace grapher { public class Option { - public Option(Field field, Label label) + public Option( + Field field, + Label label, + ActiveValueLabel activeValueLabel) { Field = field; Label = label; + ActiveValueLabel = activeValueLabel; } - public Option(TextBox box, Form containingForm, double defaultData, Label label) - : this(new Field(box, containingForm, defaultData), label) + public Option( + TextBox box, + Form containingForm, + double defaultData, + Label label, + ActiveValueLabel activeValueLabel) + : this( + new Field(box, containingForm, defaultData), + label, + activeValueLabel) { } - public Option(TextBox box, Form containingForm, double defaultData, Label label, string startingName) - : this(box, containingForm, defaultData, label) + public Option( + TextBox box, + Form containingForm, + double defaultData, + Label label, + ActiveValueLabel activeValueLabel, + string startingName) + : this( + box, + containingForm, + defaultData, + label, + activeValueLabel) { SetName(startingName); } @@ -30,22 +54,36 @@ namespace grapher public Label Label { get; } + public ActiveValueLabel ActiveValueLabel { get; } + public void SetName(string name) { Label.Text = name; Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0)); } + public void SetActiveValue(double value) + { + ActiveValueLabel.SetValue(value); + } + public void Hide() { Field.Box.Hide(); Label.Hide(); + ActiveValueLabel.Hide(); } public void Show() { Field.Box.Show(); Label.Show(); + ActiveValueLabel.Show(); + } + + public void UpdateActiveValue(double value) + { + ActiveValueLabel.SetValue(value); } public void Show(string name) diff --git a/grapher/Models/Options/OptionXY.cs b/grapher/Models/Options/OptionXY.cs index 90a46d7..b22bb78 100644 --- a/grapher/Models/Options/OptionXY.cs +++ b/grapher/Models/Options/OptionXY.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Options; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,10 +10,11 @@ namespace grapher { public class OptionXY { - public OptionXY(FieldXY fields, Label label) + public OptionXY(FieldXY fields, Label label, ActiveValueLabelXY activeValueLabels) { Fields = fields; Label = label; + ActiveValueLabels = activeValueLabels; } public OptionXY( @@ -22,8 +24,9 @@ namespace grapher Form containingForm, double defaultData, Label label, - AccelCharts accelCharts) - : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData, accelCharts), label) + AccelCharts accelCharts, + ActiveValueLabelXY activeValueLabels) + : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData, accelCharts), label, activeValueLabels) { } @@ -34,6 +37,7 @@ namespace grapher Form containingForm, double defaultData, Label label, + ActiveValueLabelXY activeValueLabels, string startingName, AccelCharts accelCharts): this( @@ -43,7 +47,8 @@ namespace grapher containingForm, defaultData, label, - accelCharts) + accelCharts, + activeValueLabels) { SetName(startingName); } @@ -52,12 +57,19 @@ namespace grapher public Label Label { get; } + public ActiveValueLabelXY ActiveValueLabels { get; } + public void SetName(string name) { Label.Text = name; Label.Left = Convert.ToInt32((Fields.XField.Box.Left / 2.0) - (Label.Width / 2.0)); } + public void SetActiveValues(double x, double y) + { + ActiveValueLabels.SetValues(x, y); + } + public void Hide() { Fields.Hide(); diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs new file mode 100644 index 0000000..7c8e9a4 --- /dev/null +++ b/grapher/Models/Serialized/GUISettings.cs @@ -0,0 +1,33 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Serialized +{ + [Serializable] + public class GUISettings + { + public GUISettings() {} + + public GUISettings(bool autoWrite, int dpi, int pollRate) + { + AutoWriteToDriverOnStartup = autoWrite; + DPI = dpi; + PollRate = pollRate; + } + + [JsonProperty(Order = 1)] + public bool AutoWriteToDriverOnStartup { get; set; } + + [JsonProperty(Order = 2)] + public int DPI { get; set; } + + [JsonProperty(Order = 3)] + public int PollRate { get; set; } + } +} diff --git a/grapher/Models/Serialized/ModifierArgs.cs b/grapher/Models/Serialized/ModifierArgs.cs new file mode 100644 index 0000000..206a3c9 --- /dev/null +++ b/grapher/Models/Serialized/ModifierArgs.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Serialized +{ + public enum accel_mode + { + linear=1, classic, natural, logarithmic, sigmoid, power, naturalgain, sigmoidgain, noaccel + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + [Serializable] + public struct vec2d + { + public double x; + public double y; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + [Serializable] + public struct accel_args + { + public double offset; + public double accel; + public double limit; + public double exponent; + public double midpoint; + public double power_scale; + public double gain_cap; + public vec2d weight; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + [Serializable] + public struct accel_fn_args + { + public accel_args acc_args; + public int accel_mode; + public double time_min; + public vec2d cap; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + [Serializable] + public struct modifier_args + { + public double degrees; + public vec2d sens; + public accel_fn_args acc_fn_args; + + public modifier_args(ManagedAccel managedAccel) + { + degrees = managedAccel.Rotation; + sens.x = managedAccel.SensitivityX; + sens.y = managedAccel.SensitivityY; + acc_fn_args.accel_mode = managedAccel.Type; + acc_fn_args.time_min = managedAccel.MinimumTime; + acc_fn_args.cap.x = managedAccel.CapX; + acc_fn_args.cap.y = managedAccel.CapY; + acc_fn_args.acc_args.accel = managedAccel.Acceleration; + acc_fn_args.acc_args.exponent = managedAccel.LimitExp; + acc_fn_args.acc_args.gain_cap = managedAccel.GainCap; + acc_fn_args.acc_args.limit = managedAccel.LimitExp; + acc_fn_args.acc_args.midpoint = managedAccel.Midpoint; + acc_fn_args.acc_args.offset = managedAccel.Offset; + acc_fn_args.acc_args.power_scale = managedAccel.PowerScale; + acc_fn_args.acc_args.weight.x = managedAccel.WeightX; + acc_fn_args.acc_args.weight.y = managedAccel.WeightY; + } + } +} diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs new file mode 100644 index 0000000..21a7f0c --- /dev/null +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -0,0 +1,84 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Serialized +{ + [Serializable] + public class RawAccelSettings + { + public const string DefaultSettingsFileName = @"settings.json"; + public static readonly string ExecutingDirectory = AppDomain.CurrentDomain.BaseDirectory; + public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, DefaultSettingsFileName); + public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings + { + MissingMemberHandling = MissingMemberHandling.Error, + }; + + public RawAccelSettings() { } + + public RawAccelSettings( + ManagedAccel managedAccel, + GUISettings guiSettings) + { + AccelerationSettings = new modifier_args(managedAccel); + GUISettings = guiSettings; + } + + + public GUISettings GUISettings { get; set; } + + public modifier_args AccelerationSettings { get; set; } + + public static RawAccelSettings Load() + { + return Load(DefaultSettingsFile); + } + + public static RawAccelSettings Load(string file) + { + if (!Exists(file)) + { + throw new Exception($"Settings file does not exist at {file}"); + } + + RawAccelSettings deserializedSettings; + try + { + deserializedSettings = JsonConvert.DeserializeObject<RawAccelSettings>(File.ReadAllText(file), SerializerSettings); + } + catch(Exception e) + { + throw new Exception($"Settings file at {file} does not contain valid Raw Accel Settings.", e); + } + + return deserializedSettings; + } + + public static bool Exists() + { + return Exists(DefaultSettingsFile); + } + + public static bool Exists(string file) + { + return File.Exists(file); + } + + public void Save() + { + Save(DefaultSettingsFile); + } + + public void Save(string file) + { + File.WriteAllText(file, JsonConvert.SerializeObject(this, Formatting.Indented)); + } + } +} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs new file mode 100644 index 0000000..848606d --- /dev/null +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Serialized +{ + public class SettingsManager + { + public SettingsManager( + ManagedAccel activeAccel, + Field dpiField, + Field pollRateField, + ToolStripMenuItem autoWrite) + { + ActiveAccel = activeAccel; + DpiField = dpiField; + PollRateField = pollRateField; + AutoWriteMenuItem = autoWrite; + } + + public ManagedAccel ActiveAccel { get; } + + public RawAccelSettings RawAccelSettings { get; private set; } + + private Field DpiField { get; set; } + + private Field PollRateField { get; set; } + + private ToolStripMenuItem AutoWriteMenuItem { get; set; } + + public void UpdateActiveSettings( + int mode, + double degrees, + double sensitivityX, + double sensitivityY, + double weightX, + double weightY, + double capX, + double capY, + double offset, + double accel, + double limitOrExp, + double midpoint, + double gainCap) + { + ActiveAccel.UpdateAccel( + mode, + degrees, + sensitivityX, + sensitivityY, + weightX, + weightY, + capX, + capY, + offset, + accel, + limitOrExp, + midpoint, + gainCap); + + RawAccelSettings.AccelerationSettings = new modifier_args(ActiveAccel); + RawAccelSettings.GUISettings = new GUISettings + { + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data + }; + + RawAccelSettings.Save(); + } + + public void UpdateActiveAccelFromFileSettings() + { + ActiveAccel.UpdateAccel( + RawAccelSettings.AccelerationSettings.acc_fn_args.accel_mode, + RawAccelSettings.AccelerationSettings.degrees, + RawAccelSettings.AccelerationSettings.sens.x, + RawAccelSettings.AccelerationSettings.sens.y, + RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.weight.x, + RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.weight.y, + RawAccelSettings.AccelerationSettings.acc_fn_args.cap.x, + RawAccelSettings.AccelerationSettings.acc_fn_args.cap.y, + RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.offset, + RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.accel, + RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.exponent, + RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.midpoint, + RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.gain_cap); + DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); + PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); + AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; + } + + public void Startup() + { + ActiveAccel.ReadFromDriver(); + + if(RawAccelSettings.Exists()) + { + RawAccelSettings = RawAccelSettings.Load(); + if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) + { + UpdateActiveAccelFromFileSettings(); + } + } + else + { + RawAccelSettings = new RawAccelSettings( + ActiveAccel, + new GUISettings + { + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data + }); + RawAccelSettings.Save(); + } + } + } +} diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index cbda661..6e03ae0 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -33,6 +33,9 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Windows.Forms.DataVisualization" /> @@ -47,6 +50,8 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="Layouts\NaturalGainLayout.cs" /> + <Compile Include="Layouts\SigmoidGainLayout.cs" /> <Compile Include="Models\Calculations\AccelCalculator.cs" /> <Compile Include="Models\Calculations\AccelChartData.cs" /> <Compile Include="Models\Calculations\AccelData.cs" /> @@ -56,6 +61,8 @@ <Compile Include="Models\Mouse\MouseWatcher.cs" /> <Compile Include="Models\Mouse\PointData.cs" /> <Compile Include="Models\Options\AccelOptions.cs" /> + <Compile Include="Models\Options\ActiveValueLabel.cs" /> + <Compile Include="Models\Options\ActiveValueLabelXY.cs" /> <Compile Include="Models\Options\CapOptions.cs" /> <Compile Include="Models\Charts\ChartXY.cs" /> <Compile Include="Models\Fields\Field.cs" /> @@ -77,6 +84,10 @@ <Compile Include="Layouts\SigmoidLayout.cs" /> <Compile Include="Models\Options\Option.cs" /> <Compile Include="Models\Options\OptionXY.cs" /> + <Compile Include="Models\Serialized\GUISettings.cs" /> + <Compile Include="Models\Serialized\ModifierArgs.cs" /> + <Compile Include="Models\Serialized\RawAccelSettings.cs" /> + <Compile Include="Models\Serialized\SettingsManager.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <EmbeddedResource Include="Form1.resx"> @@ -91,6 +102,7 @@ <AutoGen>True</AutoGen> <DependentUpon>Resources.resx</DependentUpon> </Compile> + <None Include="packages.config" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> <LastGenOutput>Settings.Designer.cs</LastGenOutput> diff --git a/grapher/packages.config b/grapher/packages.config new file mode 100644 index 0000000..a9de8b5 --- /dev/null +++ b/grapher/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" /> +</packages>
\ No newline at end of file diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index 6a92caa..dcc9606 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -5,16 +5,6 @@ using namespace rawaccel; using namespace System; -double ManagedAccel::GetSensitivityX() -{ - return modifier_instance->sensitivity.x; -} - -double ManagedAccel::GetSensitivityY() -{ - return modifier_instance->sensitivity.y; -} - Tuple<double, double>^ ManagedAccel::Accelerate(int x, int y, double time) { vec2d input_vec2d = { @@ -41,7 +31,7 @@ void ManagedAccel::UpdateAccel( double midpoint, double gain_cap) { - modifier_args args{}; + modifier_args args = modifier_args{}; args.acc_fn_args.accel_mode = mode; args.degrees = rotation; args.sens.x = sensitivityX; @@ -62,8 +52,26 @@ void ManagedAccel::UpdateAccel( delete temp_modifier; ReadFromDriver(); + } +double ManagedAccel::SensitivityX::get() { return modifier_instance->sensitivity.x; } +double ManagedAccel::SensitivityY::get() { return modifier_instance->sensitivity.y; } +double ManagedAccel::Rotation::get() { return atan(modifier_instance->rotate.rot_vec.y / modifier_instance->rotate.rot_vec.x) * 180 / M_PI; } +int ManagedAccel::Type::get() { return modifier_instance->accel_fn.accel.tag; } +double ManagedAccel::Acceleration::get() { return modifier_instance->accel_fn.impl_args.accel; } +double ManagedAccel::CapX::get() { return modifier_instance->accel_fn.clamp.x.hi; } +double ManagedAccel::CapY::get() { return modifier_instance->accel_fn.clamp.y.hi; } +double ManagedAccel::GainCap::get() { return modifier_instance->accel_fn.gain_cap.threshold; } +bool ManagedAccel::GainCapEnabled::get() { return modifier_instance->accel_fn.gain_cap.cap_gain_enabled; } +double ManagedAccel::WeightX::get() { return modifier_instance->accel_fn.impl_args.weight.x; } +double ManagedAccel::WeightY::get() { return modifier_instance->accel_fn.impl_args.weight.y; } +double ManagedAccel::Offset::get() { return modifier_instance->accel_fn.speed_offset; } +double ManagedAccel::LimitExp::get() { return modifier_instance->accel_fn.impl_args.limit; } +double ManagedAccel::Midpoint::get() { return modifier_instance->accel_fn.impl_args.midpoint; } +double ManagedAccel::MinimumTime::get() { return modifier_instance->accel_fn.time_min; } +double ManagedAccel::PowerScale::get() { return modifier_instance->accel_fn.impl_args.power_scale; } + void ManagedAccel::WriteToDriver() { driverWriter->writeToDriver(modifier_instance); diff --git a/wrapper/wrapper.hpp b/wrapper/wrapper.hpp index b086672..3643eb5 100644 --- a/wrapper/wrapper.hpp +++ b/wrapper/wrapper.hpp @@ -25,6 +25,9 @@ public: driverWriter = new wrapper_io(); } + // Empty constructor needed for serialization + ManagedAccel() {} + virtual ~ManagedAccel() { if (modifier_instance!= nullptr) @@ -40,10 +43,23 @@ public: } } - double GetSensitivityX(); - - double GetSensitivityY(); - + // Duplicate all relevant rawaccel struct members here for access and display in GUI + property double SensitivityX { double get(); } + property double SensitivityY { double get(); } + property double Rotation { double get(); } + property int Type { int get(); } + property double Acceleration { double get(); } + property bool GainCapEnabled { bool get(); } + property double CapX { double get(); } + property double CapY { double get(); } + property double GainCap { double get(); } + property double WeightX { double get(); } + property double WeightY { double get(); } + property double Offset { double get(); } + property double LimitExp { double get(); } + property double Midpoint { double get(); } + property double MinimumTime { double get(); } + property double PowerScale { double get(); } mouse_modifier* GetInstance() { return modifier_instance; |