diff options
| author | Jacob Palecki <[email protected]> | 2020-09-27 21:13:03 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-27 21:13:03 -0700 |
| commit | 5d8700a462b4798c02f4a73bc66d2a69a4920ae1 (patch) | |
| tree | 3a2b71991a6efce65be9af0c303ec2b59bdebff4 /grapher | |
| parent | Set tab order (diff) | |
| parent | Merge pull request #26 from a1xd/argcheck (diff) | |
| download | rawaccel-5d8700a462b4798c02f4a73bc66d2a69a4920ae1.tar.xz rawaccel-5d8700a462b4798c02f4a73bc66d2a69a4920ae1.zip | |
Merge and fix write button
Diffstat (limited to 'grapher')
| -rw-r--r-- | grapher/Form1.Designer.cs | 237 | ||||
| -rw-r--r-- | grapher/Form1.cs | 20 | ||||
| -rw-r--r-- | grapher/Layouts/ClassicLayout.cs | 4 | ||||
| -rw-r--r-- | grapher/Layouts/DefaultLayout.cs | 4 | ||||
| -rw-r--r-- | grapher/Layouts/LayoutBase.cs | 26 | ||||
| -rw-r--r-- | grapher/Layouts/LinearLayout.cs | 4 | ||||
| -rw-r--r-- | grapher/Layouts/MotivityLayout.cs | 4 | ||||
| -rw-r--r-- | grapher/Layouts/NaturalGainLayout.cs | 4 | ||||
| -rw-r--r-- | grapher/Layouts/NaturalLayout.cs | 4 | ||||
| -rw-r--r-- | grapher/Layouts/OffLayout.cs | 4 | ||||
| -rw-r--r-- | grapher/Layouts/PowerLayout.cs | 6 | ||||
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 22 | ||||
| -rw-r--r-- | grapher/Models/AccelGUIFactory.cs | 64 | ||||
| -rw-r--r-- | grapher/Models/Options/AccelOptionSet.cs | 8 | ||||
| -rw-r--r-- | grapher/Models/Options/AccelTypeOptions.cs | 56 | ||||
| -rw-r--r-- | grapher/Models/Options/ApplyOptions.cs | 6 | ||||
| -rw-r--r-- | grapher/Models/Options/OffsetOptions.cs | 11 | ||||
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 27 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 51 |
19 files changed, 416 insertions, 146 deletions
diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 1950f51..8d7bfd8 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -84,7 +84,7 @@ namespace grapher this.weightLabelX = new System.Windows.Forms.Label(); this.weightBoxY = new System.Windows.Forms.TextBox(); this.limitBoxX = new System.Windows.Forms.TextBox(); - this.constantTwoLabelX = new System.Windows.Forms.Label(); + this.limitLabelX = new System.Windows.Forms.Label(); this.midpointBoxX = new System.Windows.Forms.TextBox(); this.constantThreeLabelX = new System.Windows.Forms.Label(); this.offsetBoxX = new System.Windows.Forms.TextBox(); @@ -133,7 +133,7 @@ namespace grapher this.WeightActiveYLabel = new System.Windows.Forms.Label(); this.CapActiveYLabel = new System.Windows.Forms.Label(); this.OffsetActiveXLabel = new System.Windows.Forms.Label(); - this.LimitExpActiveXLabel = new System.Windows.Forms.Label(); + this.LimitActiveXLabel = new System.Windows.Forms.Label(); this.MidpointActiveXLabel = new System.Windows.Forms.Label(); this.accelerationBoxY = new System.Windows.Forms.TextBox(); this.offsetBoxY = new System.Windows.Forms.TextBox(); @@ -142,19 +142,31 @@ namespace grapher this.accelTypeDropY = new System.Windows.Forms.ComboBox(); this.AccelerationActiveLabelY = new System.Windows.Forms.Label(); this.OffsetActiveYLabel = new System.Windows.Forms.Label(); - this.LimitExpActiveYLabel = new System.Windows.Forms.Label(); + this.LimitActiveYLabel = new System.Windows.Forms.Label(); this.MidpointActiveYLabel = new System.Windows.Forms.Label(); this.ByComponentXYLock = new System.Windows.Forms.CheckBox(); this.constantOneLabelY = new System.Windows.Forms.Label(); this.capLabelY = new System.Windows.Forms.Label(); this.weightLabelY = new System.Windows.Forms.Label(); this.offsetLabelY = new System.Windows.Forms.Label(); - this.constantTwoLabelY = new System.Windows.Forms.Label(); + this.limitLabelY = new System.Windows.Forms.Label(); this.constantThreeLabelY = new System.Windows.Forms.Label(); this.OptionSetXTitle = new System.Windows.Forms.Label(); this.OptionSetYTitle = new System.Windows.Forms.Label(); this.AccelTypeActiveLabelY = new System.Windows.Forms.Label(); this.ActiveValueTitleY = new System.Windows.Forms.Label(); + this.expLabelY = new System.Windows.Forms.Label(); + this.ExpActiveYLabel = new System.Windows.Forms.Label(); + this.expBoxY = new System.Windows.Forms.TextBox(); + this.ExpActiveXLabel = new System.Windows.Forms.Label(); + this.expLabelX = new System.Windows.Forms.Label(); + this.expBoxX = new System.Windows.Forms.TextBox(); + this.scaleLabelY = new System.Windows.Forms.Label(); + this.ScaleActiveYLabel = new System.Windows.Forms.Label(); + this.scaleBoxY = new System.Windows.Forms.TextBox(); + this.ScaleActiveXLabel = new System.Windows.Forms.Label(); + this.scaleLabelX = new System.Windows.Forms.Label(); + this.scaleBoxX = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.VelocityChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.GainChart)).BeginInit(); @@ -311,19 +323,19 @@ namespace grapher this.limitBoxX.Size = new System.Drawing.Size(76, 20); this.limitBoxX.TabIndex = 9; // - // constantTwoLabelX + // limitLabelX // - this.constantTwoLabelX.AutoSize = true; - this.constantTwoLabelX.Location = new System.Drawing.Point(24, 244); - this.constantTwoLabelX.Name = "constantTwoLabelX"; - this.constantTwoLabelX.Size = new System.Drawing.Size(78, 13); - this.constantTwoLabelX.TabIndex = 16; - this.constantTwoLabelX.Text = "Limit/Exponent"; - this.constantTwoLabelX.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.limitLabelX.AutoSize = true; + this.limitLabelX.Location = new System.Drawing.Point(24, 244); + this.limitLabelX.Name = "limitLabelX"; + this.limitLabelX.Size = new System.Drawing.Size(28, 13); + this.limitLabelX.TabIndex = 16; + this.limitLabelX.Text = "Limit"; + this.limitLabelX.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // midpointBoxX // - this.midpointBoxX.Location = new System.Drawing.Point(105, 267); + this.midpointBoxX.Location = new System.Drawing.Point(105, 297); this.midpointBoxX.Name = "midpointBoxX"; this.midpointBoxX.Size = new System.Drawing.Size(76, 20); this.midpointBoxX.TabIndex = 10; @@ -331,7 +343,7 @@ namespace grapher // constantThreeLabelX // this.constantThreeLabelX.AutoSize = true; - this.constantThreeLabelX.Location = new System.Drawing.Point(34, 270); + this.constantThreeLabelX.Location = new System.Drawing.Point(34, 300); this.constantThreeLabelX.Name = "constantThreeLabelX"; this.constantThreeLabelX.Size = new System.Drawing.Size(47, 13); this.constantThreeLabelX.TabIndex = 18; @@ -357,9 +369,10 @@ namespace grapher // // writeButton // - this.writeButton.Location = new System.Drawing.Point(154, 270); + this.writeButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); + this.writeButton.Location = new System.Drawing.Point(177, 359); this.writeButton.Name = "writeButton"; - this.writeButton.Size = new System.Drawing.Size(76, 23); + this.writeButton.Size = new System.Drawing.Size(128, 40); this.writeButton.TabIndex = 19; this.writeButton.Text = "Apply"; this.writeButton.UseVisualStyleBackColor = true; @@ -875,19 +888,19 @@ namespace grapher this.OffsetActiveXLabel.TabIndex = 45; this.OffsetActiveXLabel.Text = "0"; // - // LimitExpActiveXLabel + // LimitActiveXLabel // - this.LimitExpActiveXLabel.AutoSize = true; - this.LimitExpActiveXLabel.Location = new System.Drawing.Point(196, 244); - this.LimitExpActiveXLabel.Name = "LimitExpActiveXLabel"; - this.LimitExpActiveXLabel.Size = new System.Drawing.Size(13, 13); - this.LimitExpActiveXLabel.TabIndex = 46; - this.LimitExpActiveXLabel.Text = "0"; + this.LimitActiveXLabel.AutoSize = true; + this.LimitActiveXLabel.Location = new System.Drawing.Point(196, 244); + this.LimitActiveXLabel.Name = "LimitActiveXLabel"; + this.LimitActiveXLabel.Size = new System.Drawing.Size(13, 13); + this.LimitActiveXLabel.TabIndex = 46; + this.LimitActiveXLabel.Text = "0"; // // MidpointActiveXLabel // this.MidpointActiveXLabel.AutoSize = true; - this.MidpointActiveXLabel.Location = new System.Drawing.Point(196, 270); + this.MidpointActiveXLabel.Location = new System.Drawing.Point(196, 300); this.MidpointActiveXLabel.Name = "MidpointActiveXLabel"; this.MidpointActiveXLabel.Size = new System.Drawing.Size(13, 13); this.MidpointActiveXLabel.TabIndex = 47; @@ -916,7 +929,7 @@ namespace grapher // // midpointBoxY // - this.midpointBoxY.Location = new System.Drawing.Point(331, 267); + this.midpointBoxY.Location = new System.Drawing.Point(331, 297); this.midpointBoxY.Name = "midpointBoxY"; this.midpointBoxY.Size = new System.Drawing.Size(76, 20); this.midpointBoxY.TabIndex = 18; @@ -948,19 +961,19 @@ namespace grapher this.OffsetActiveYLabel.TabIndex = 54; this.OffsetActiveYLabel.Text = "0"; // - // LimitExpActiveYLabel + // LimitActiveYLabel // - this.LimitExpActiveYLabel.AutoSize = true; - this.LimitExpActiveYLabel.Location = new System.Drawing.Point(413, 244); - this.LimitExpActiveYLabel.Name = "LimitExpActiveYLabel"; - this.LimitExpActiveYLabel.Size = new System.Drawing.Size(13, 13); - this.LimitExpActiveYLabel.TabIndex = 55; - this.LimitExpActiveYLabel.Text = "0"; + this.LimitActiveYLabel.AutoSize = true; + this.LimitActiveYLabel.Location = new System.Drawing.Point(413, 244); + this.LimitActiveYLabel.Name = "LimitActiveYLabel"; + this.LimitActiveYLabel.Size = new System.Drawing.Size(13, 13); + this.LimitActiveYLabel.TabIndex = 55; + this.LimitActiveYLabel.Text = "0"; // // MidpointActiveYLabel // this.MidpointActiveYLabel.AutoSize = true; - this.MidpointActiveYLabel.Location = new System.Drawing.Point(413, 270); + this.MidpointActiveYLabel.Location = new System.Drawing.Point(413, 300); this.MidpointActiveYLabel.Name = "MidpointActiveYLabel"; this.MidpointActiveYLabel.Size = new System.Drawing.Size(13, 13); this.MidpointActiveYLabel.TabIndex = 56; @@ -1013,19 +1026,19 @@ namespace grapher this.offsetLabelY.TabIndex = 61; this.offsetLabelY.Text = "Offset"; // - // constantTwoLabelY + // limitLabelY // - this.constantTwoLabelY.AutoSize = true; - this.constantTwoLabelY.Location = new System.Drawing.Point(264, 244); - this.constantTwoLabelY.Name = "constantTwoLabelY"; - this.constantTwoLabelY.Size = new System.Drawing.Size(51, 13); - this.constantTwoLabelY.TabIndex = 62; - this.constantTwoLabelY.Text = "Limit/Exp"; + this.limitLabelY.AutoSize = true; + this.limitLabelY.Location = new System.Drawing.Point(264, 244); + this.limitLabelY.Name = "limitLabelY"; + this.limitLabelY.Size = new System.Drawing.Size(28, 13); + this.limitLabelY.TabIndex = 62; + this.limitLabelY.Text = "Limit"; // // constantThreeLabelY // this.constantThreeLabelY.AutoSize = true; - this.constantThreeLabelY.Location = new System.Drawing.Point(264, 270); + this.constantThreeLabelY.Location = new System.Drawing.Point(264, 300); this.constantThreeLabelY.Name = "constantThreeLabelY"; this.constantThreeLabelY.Size = new System.Drawing.Size(47, 13); this.constantThreeLabelY.TabIndex = 63; @@ -1067,24 +1080,138 @@ namespace grapher this.ActiveValueTitleY.TabIndex = 67; this.ActiveValueTitleY.Text = "Current"; // + // expLabelY + // + this.expLabelY.AutoSize = true; + this.expLabelY.Location = new System.Drawing.Point(264, 273); + this.expLabelY.Name = "expLabelY"; + this.expLabelY.Size = new System.Drawing.Size(52, 13); + this.expLabelY.TabIndex = 73; + this.expLabelY.Text = "Exponent"; + // + // ExpActiveYLabel + // + this.ExpActiveYLabel.AutoSize = true; + this.ExpActiveYLabel.Location = new System.Drawing.Point(413, 273); + this.ExpActiveYLabel.Name = "ExpActiveYLabel"; + this.ExpActiveYLabel.Size = new System.Drawing.Size(13, 13); + this.ExpActiveYLabel.TabIndex = 72; + this.ExpActiveYLabel.Text = "0"; + // + // expBoxY + // + this.expBoxY.Location = new System.Drawing.Point(331, 270); + this.expBoxY.Name = "expBoxY"; + this.expBoxY.Size = new System.Drawing.Size(76, 20); + this.expBoxY.TabIndex = 71; + // + // ExpActiveXLabel + // + this.ExpActiveXLabel.AutoSize = true; + this.ExpActiveXLabel.Location = new System.Drawing.Point(196, 273); + this.ExpActiveXLabel.Name = "ExpActiveXLabel"; + this.ExpActiveXLabel.Size = new System.Drawing.Size(13, 13); + this.ExpActiveXLabel.TabIndex = 70; + this.ExpActiveXLabel.Text = "0"; + // + // expLabelX + // + this.expLabelX.AutoSize = true; + this.expLabelX.Location = new System.Drawing.Point(24, 273); + this.expLabelX.Name = "expLabelX"; + this.expLabelX.Size = new System.Drawing.Size(52, 13); + this.expLabelX.TabIndex = 69; + this.expLabelX.Text = "Exponent"; + this.expLabelX.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // expBoxX + // + this.expBoxX.Location = new System.Drawing.Point(105, 270); + this.expBoxX.Name = "expBoxX"; + this.expBoxX.Size = new System.Drawing.Size(76, 20); + this.expBoxX.TabIndex = 68; + // + // scaleLabelY + // + this.scaleLabelY.AutoSize = true; + this.scaleLabelY.Location = new System.Drawing.Point(264, 330); + this.scaleLabelY.Name = "scaleLabelY"; + this.scaleLabelY.Size = new System.Drawing.Size(34, 13); + this.scaleLabelY.TabIndex = 79; + this.scaleLabelY.Text = "Scale"; + // + // ScaleActiveYLabel + // + this.ScaleActiveYLabel.AutoSize = true; + this.ScaleActiveYLabel.Location = new System.Drawing.Point(413, 330); + this.ScaleActiveYLabel.Name = "ScaleActiveYLabel"; + this.ScaleActiveYLabel.Size = new System.Drawing.Size(13, 13); + this.ScaleActiveYLabel.TabIndex = 78; + this.ScaleActiveYLabel.Text = "0"; + // + // scaleBoxY + // + this.scaleBoxY.Location = new System.Drawing.Point(331, 327); + this.scaleBoxY.Name = "scaleBoxY"; + this.scaleBoxY.Size = new System.Drawing.Size(76, 20); + this.scaleBoxY.TabIndex = 77; + // + // ScaleActiveXLabel + // + this.ScaleActiveXLabel.AutoSize = true; + this.ScaleActiveXLabel.Location = new System.Drawing.Point(196, 330); + this.ScaleActiveXLabel.Name = "ScaleActiveXLabel"; + this.ScaleActiveXLabel.Size = new System.Drawing.Size(13, 13); + this.ScaleActiveXLabel.TabIndex = 76; + this.ScaleActiveXLabel.Text = "0"; + // + // scaleLabelX + // + this.scaleLabelX.AutoSize = true; + this.scaleLabelX.Location = new System.Drawing.Point(34, 330); + this.scaleLabelX.Name = "scaleLabelX"; + this.scaleLabelX.Size = new System.Drawing.Size(34, 13); + this.scaleLabelX.TabIndex = 75; + this.scaleLabelX.Text = "Scale"; + this.scaleLabelX.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // scaleBoxX + // + this.scaleBoxX.Location = new System.Drawing.Point(105, 327); + this.scaleBoxX.Name = "scaleBoxX"; + this.scaleBoxX.Size = new System.Drawing.Size(76, 20); + this.scaleBoxX.TabIndex = 74; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1884, 956); + this.Controls.Add(this.scaleLabelY); + this.Controls.Add(this.ScaleActiveYLabel); + this.Controls.Add(this.scaleBoxY); + this.Controls.Add(this.ScaleActiveXLabel); + this.Controls.Add(this.scaleLabelX); + this.Controls.Add(this.scaleBoxX); + this.Controls.Add(this.expLabelY); + this.Controls.Add(this.ExpActiveYLabel); + this.Controls.Add(this.expBoxY); + this.Controls.Add(this.ExpActiveXLabel); + this.Controls.Add(this.expLabelX); + this.Controls.Add(this.expBoxX); this.Controls.Add(this.ActiveValueTitleY); this.Controls.Add(this.AccelTypeActiveLabelY); this.Controls.Add(this.OptionSetYTitle); this.Controls.Add(this.OptionSetXTitle); this.Controls.Add(this.constantThreeLabelY); - this.Controls.Add(this.constantTwoLabelY); + this.Controls.Add(this.limitLabelY); this.Controls.Add(this.offsetLabelY); this.Controls.Add(this.weightLabelY); this.Controls.Add(this.capLabelY); this.Controls.Add(this.constantOneLabelY); this.Controls.Add(this.ByComponentXYLock); this.Controls.Add(this.MidpointActiveYLabel); - this.Controls.Add(this.LimitExpActiveYLabel); + this.Controls.Add(this.LimitActiveYLabel); this.Controls.Add(this.OffsetActiveYLabel); this.Controls.Add(this.AccelerationActiveLabelY); this.Controls.Add(this.accelTypeDropY); @@ -1093,7 +1220,7 @@ namespace grapher this.Controls.Add(this.offsetBoxY); this.Controls.Add(this.accelerationBoxY); this.Controls.Add(this.MidpointActiveXLabel); - this.Controls.Add(this.LimitExpActiveXLabel); + this.Controls.Add(this.LimitActiveXLabel); this.Controls.Add(this.OffsetActiveXLabel); this.Controls.Add(this.CapActiveYLabel); this.Controls.Add(this.WeightActiveYLabel); @@ -1120,7 +1247,7 @@ namespace grapher this.Controls.Add(this.offsetBoxX); this.Controls.Add(this.constantThreeLabelX); this.Controls.Add(this.midpointBoxX); - this.Controls.Add(this.constantTwoLabelX); + this.Controls.Add(this.limitLabelX); this.Controls.Add(this.limitBoxX); this.Controls.Add(this.weightBoxY); this.Controls.Add(this.weightLabelX); @@ -1170,7 +1297,7 @@ namespace grapher private System.Windows.Forms.Label weightLabelX; private System.Windows.Forms.TextBox weightBoxY; private System.Windows.Forms.TextBox limitBoxX; - private System.Windows.Forms.Label constantTwoLabelX; + private System.Windows.Forms.Label limitLabelX; private System.Windows.Forms.TextBox midpointBoxX; private System.Windows.Forms.Label constantThreeLabelX; private System.Windows.Forms.TextBox offsetBoxX; @@ -1210,7 +1337,7 @@ namespace grapher private System.Windows.Forms.Label WeightActiveYLabel; private System.Windows.Forms.Label CapActiveYLabel; private System.Windows.Forms.Label OffsetActiveXLabel; - private System.Windows.Forms.Label LimitExpActiveXLabel; + private System.Windows.Forms.Label LimitActiveXLabel; private System.Windows.Forms.Label MidpointActiveXLabel; private System.Windows.Forms.ToolStripMenuItem startupToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem AutoWriteMenuItem; @@ -1224,14 +1351,14 @@ namespace grapher private System.Windows.Forms.ComboBox accelTypeDropY; private System.Windows.Forms.Label AccelerationActiveLabelY; private System.Windows.Forms.Label OffsetActiveYLabel; - private System.Windows.Forms.Label LimitExpActiveYLabel; + private System.Windows.Forms.Label LimitActiveYLabel; private System.Windows.Forms.Label MidpointActiveYLabel; private System.Windows.Forms.CheckBox ByComponentXYLock; private System.Windows.Forms.Label constantOneLabelY; private System.Windows.Forms.Label capLabelY; private System.Windows.Forms.Label weightLabelY; private System.Windows.Forms.Label offsetLabelY; - private System.Windows.Forms.Label constantTwoLabelY; + private System.Windows.Forms.Label limitLabelY; private System.Windows.Forms.Label constantThreeLabelY; private System.Windows.Forms.Label OptionSetXTitle; private System.Windows.Forms.Label OptionSetYTitle; @@ -1241,6 +1368,18 @@ namespace grapher private System.Windows.Forms.ToolStripMenuItem legacyOffsetToolStripMenuItem; private System.Windows.Forms.Label ActiveValueTitleY; private System.Windows.Forms.ToolStripMenuItem showLastMouseMoveToolStripMenuItem; + private System.Windows.Forms.Label expLabelY; + private System.Windows.Forms.Label ExpActiveYLabel; + private System.Windows.Forms.TextBox expBoxY; + private System.Windows.Forms.Label ExpActiveXLabel; + private System.Windows.Forms.Label expLabelX; + private System.Windows.Forms.TextBox expBoxX; + private System.Windows.Forms.Label scaleLabelY; + private System.Windows.Forms.Label ScaleActiveYLabel; + private System.Windows.Forms.TextBox scaleBoxY; + private System.Windows.Forms.Label ScaleActiveXLabel; + private System.Windows.Forms.Label scaleLabelX; + private System.Windows.Forms.TextBox scaleBoxX; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index aa3d2ef..6f61c65 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -72,8 +72,12 @@ namespace grapher offsetBoxY, accelerationBoxX, accelerationBoxY, + scaleBoxX, + scaleBoxY, limitBoxX, limitBoxY, + expBoxX, + expBoxY, midpointBoxX, midpointBoxY, sensXYLock, @@ -89,8 +93,12 @@ namespace grapher offsetLabelY, constantOneLabelX, constantOneLabelY, - constantTwoLabelX, - constantTwoLabelY, + scaleLabelX, + scaleLabelY, + limitLabelX, + limitLabelY, + expLabelX, + expLabelY, constantThreeLabelX, constantThreeLabelY, ActiveValueTitle, @@ -106,8 +114,12 @@ namespace grapher OffsetActiveYLabel, AccelerationActiveLabelX, AccelerationActiveLabelY, - LimitExpActiveXLabel, - LimitExpActiveYLabel, + ScaleActiveXLabel, + ScaleActiveYLabel, + LimitActiveXLabel, + LimitActiveYLabel, + ExpActiveXLabel, + ExpActiveYLabel, MidpointActiveXLabel, MidpointActiveYLabel, AccelTypeActiveLabelX, diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs index 572566f..8403c5d 100644 --- a/grapher/Layouts/ClassicLayout.cs +++ b/grapher/Layouts/ClassicLayout.cs @@ -11,10 +11,12 @@ namespace grapher.Layouts Index = (int)AccelMode.classic; AccelLayout = new OptionLayout(true, Acceleration); + ScaleLayout = new OptionLayout(false, string.Empty); CapLayout = new OptionLayout(true, Cap); WeightLayout = new OptionLayout(true, Weight); OffsetLayout = new OptionLayout(true, Offset); - LimExpLayout = new OptionLayout(true, Exponent); + LimitLayout = new OptionLayout(false, string.Empty); + ExponentLayout = new OptionLayout(true, Exponent); MidpointLayout = new OptionLayout(false, string.Empty); } } diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs index cf6f87f..c8cce6d 100644 --- a/grapher/Layouts/DefaultLayout.cs +++ b/grapher/Layouts/DefaultLayout.cs @@ -13,10 +13,12 @@ namespace grapher.Layouts LogarithmicCharts = false; AccelLayout = new OptionLayout(true, Acceleration); + ScaleLayout = new OptionLayout(true, Scale); CapLayout = new OptionLayout(true, Cap); WeightLayout = new OptionLayout(true, Weight); OffsetLayout = new OptionLayout(true, Offset); - LimExpLayout = new OptionLayout(true, $"{Limit}\\{Exponent}"); + LimitLayout = new OptionLayout(true, Limit); + ExponentLayout = new OptionLayout(true, Exponent); MidpointLayout = new OptionLayout(true, Midpoint); } } diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs index 04f5189..c380397 100644 --- a/grapher/Layouts/LayoutBase.cs +++ b/grapher/Layouts/LayoutBase.cs @@ -18,10 +18,12 @@ namespace grapher.Layouts public LayoutBase() { AccelLayout = new OptionLayout(false, string.Empty); + ScaleLayout = new OptionLayout(false, string.Empty); CapLayout = new OptionLayout(false, string.Empty); WeightLayout = new OptionLayout(false, string.Empty); OffsetLayout = new OptionLayout(false, string.Empty); - LimExpLayout = new OptionLayout(false, string.Empty); + LimitLayout = new OptionLayout(false, string.Empty); + ExponentLayout = new OptionLayout(false, string.Empty); MidpointLayout = new OptionLayout(false, string.Empty); ButtonEnabled = true; @@ -42,22 +44,28 @@ namespace grapher.Layouts protected OptionLayout AccelLayout { get; set; } + protected OptionLayout ScaleLayout { get; set; } + protected OptionLayout CapLayout { get; set; } protected OptionLayout WeightLayout { get; set; } protected OptionLayout OffsetLayout { get; set; } - protected OptionLayout LimExpLayout { get; set; } + protected OptionLayout LimitLayout { get; set; } + + protected OptionLayout ExponentLayout { get; set; } protected OptionLayout MidpointLayout { get; set; } public void Layout( IOption accelOption, + IOption scaleOption, IOption capOption, IOption weightOption, IOption offsetOption, - IOption limExpOption, + IOption limitOption, + IOption expOption, IOption midpointOption, Button button, int top) @@ -68,10 +76,12 @@ namespace grapher.Layouts foreach (var option in new (OptionLayout, IOption)[] { (AccelLayout, accelOption), + (ScaleLayout, scaleOption), (CapLayout, capOption), (WeightLayout, weightOption), (OffsetLayout, offsetOption), - (LimExpLayout, limExpOption), + (LimitLayout, limitOption), + (ExponentLayout, expOption), (MidpointLayout, midpointOption)}) { option.Item1.Layout(option.Item2); @@ -94,18 +104,22 @@ namespace grapher.Layouts public void Layout( IOption accelOption, + IOption scaleOption, IOption capOption, IOption weightOption, IOption offsetOption, - IOption limExpOption, + IOption limitOption, + IOption expOption, IOption midpointOption, Button button) { Layout(accelOption, + scaleOption, capOption, weightOption, offsetOption, - limExpOption, + limitOption, + expOption, midpointOption, button, accelOption.Top); diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs index e87c851..0412a2a 100644 --- a/grapher/Layouts/LinearLayout.cs +++ b/grapher/Layouts/LinearLayout.cs @@ -12,10 +12,12 @@ namespace grapher.Layouts LogarithmicCharts = false; AccelLayout = new OptionLayout(true, Acceleration); + ScaleLayout = new OptionLayout(false, string.Empty); CapLayout = new OptionLayout(true, Cap); WeightLayout = new OptionLayout(true, Weight); OffsetLayout = new OptionLayout(true, Offset); - LimExpLayout = new OptionLayout(false, string.Empty); + LimitLayout = new OptionLayout(false, string.Empty); + ExponentLayout = new OptionLayout(false, string.Empty); MidpointLayout = new OptionLayout(false, string.Empty); } } diff --git a/grapher/Layouts/MotivityLayout.cs b/grapher/Layouts/MotivityLayout.cs index c555ef0..839de58 100644 --- a/grapher/Layouts/MotivityLayout.cs +++ b/grapher/Layouts/MotivityLayout.cs @@ -17,10 +17,12 @@ namespace grapher.Layouts LogarithmicCharts = true; AccelLayout = new OptionLayout(true, Acceleration); + ScaleLayout = new OptionLayout(false, string.Empty); CapLayout = new OptionLayout(false, string.Empty); WeightLayout = new OptionLayout(true, Weight); OffsetLayout = new OptionLayout(false, string.Empty); - LimExpLayout = new OptionLayout(true, Motivity); + LimitLayout = new OptionLayout(true, Motivity); + ExponentLayout = new OptionLayout(false, string.Empty); MidpointLayout = new OptionLayout(true, Midpoint); } } diff --git a/grapher/Layouts/NaturalGainLayout.cs b/grapher/Layouts/NaturalGainLayout.cs index b9cf75e..12daed3 100644 --- a/grapher/Layouts/NaturalGainLayout.cs +++ b/grapher/Layouts/NaturalGainLayout.cs @@ -12,10 +12,12 @@ namespace grapher.Layouts LogarithmicCharts = false; AccelLayout = new OptionLayout(true, Acceleration); + ScaleLayout = new OptionLayout(false, string.Empty); CapLayout = new OptionLayout(false, string.Empty); WeightLayout = new OptionLayout(true, Weight); OffsetLayout = new OptionLayout(true, Offset); - LimExpLayout = new OptionLayout(true, Limit); + LimitLayout = new OptionLayout(true, Limit); + ExponentLayout = new OptionLayout(false, string.Empty); MidpointLayout = new OptionLayout(false, string.Empty); } } diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs index 59895df..44129f9 100644 --- a/grapher/Layouts/NaturalLayout.cs +++ b/grapher/Layouts/NaturalLayout.cs @@ -12,10 +12,12 @@ namespace grapher.Layouts LogarithmicCharts = false; AccelLayout = new OptionLayout(true, Acceleration); + ScaleLayout = new OptionLayout(false, string.Empty); CapLayout = new OptionLayout(false, string.Empty); WeightLayout = new OptionLayout(true, Weight); OffsetLayout = new OptionLayout(true, Offset); - LimExpLayout = new OptionLayout(true, Limit); + LimitLayout = new OptionLayout(true, Limit); + ExponentLayout = new OptionLayout(false, string.Empty); MidpointLayout = new OptionLayout(false, string.Empty); } } diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs index c47ea39..664e364 100644 --- a/grapher/Layouts/OffLayout.cs +++ b/grapher/Layouts/OffLayout.cs @@ -13,10 +13,12 @@ namespace grapher.Layouts LogarithmicCharts = false; AccelLayout = new OptionLayout(false, string.Empty); + ScaleLayout = new OptionLayout(false, string.Empty); CapLayout = new OptionLayout(false, string.Empty); WeightLayout = new OptionLayout(false, string.Empty); OffsetLayout = new OptionLayout(false, string.Empty); - LimExpLayout = new OptionLayout(false, string.Empty); + LimitLayout = new OptionLayout(false, string.Empty); + ExponentLayout = new OptionLayout(false, string.Empty); MidpointLayout = new OptionLayout(false, string.Empty); } } diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs index e12ac4a..1911813 100644 --- a/grapher/Layouts/PowerLayout.cs +++ b/grapher/Layouts/PowerLayout.cs @@ -11,11 +11,13 @@ namespace grapher.Layouts Index = (int)AccelMode.power; LogarithmicCharts = false; - AccelLayout = new OptionLayout(true, Scale); + AccelLayout = new OptionLayout(false, string.Empty); + ScaleLayout = new OptionLayout(true, Scale); CapLayout = new OptionLayout(true, Cap); WeightLayout = new OptionLayout(true, Weight); OffsetLayout = new OptionLayout(true, Offset); - LimExpLayout = new OptionLayout(true, Exponent); + LimitLayout = new OptionLayout(false, string.Empty); + ExponentLayout = new OptionLayout(true, Exponent); MidpointLayout = new OptionLayout(false, string.Empty); } } diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 1fff4c3..c9c4ed0 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -3,6 +3,7 @@ using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; using System; +using System.Drawing; using System.Windows.Forms; namespace grapher @@ -72,6 +73,8 @@ namespace grapher public void UpdateActiveSettingsFromFields() { + var driverSettings = Settings.RawAccelSettings.AccelerationSettings; + var settings = new DriverSettings { rotation = ApplyOptions.Rotation.Field.Data, @@ -82,13 +85,20 @@ namespace grapher }, combineMagnitudes = ApplyOptions.IsWhole, modes = ApplyOptions.GetModes(), - args = ApplyOptions.GetArgs(), - minimumTime = .4 + args = ApplyOptions.GetUpdatedArgs(ref driverSettings.args), + minimumTime = driverSettings.minimumTime }; WriteButtonDelay(); - Settings.UpdateActiveSettings(settings); - RefreshOnRead(); + SettingsErrors errors = Settings.TryUpdateActiveSettings(settings); + if (errors.Empty()) + { + RefreshOnRead(); + } + else + { + WriteButton.Text = "bad args"; + } } public void RefreshOnRead() @@ -126,7 +136,7 @@ namespace grapher { Timer buttonTimer = new Timer(); buttonTimer.Enabled = true; - buttonTimer.Interval = Convert.ToInt32(ManagedAccel.WriteDelay); + buttonTimer.Interval = Convert.ToInt32(DriverInterop.WriteDelayMs); buttonTimer.Tick += new System.EventHandler(OnButtonTimerTick); return buttonTimer; } @@ -141,12 +151,14 @@ namespace grapher { WriteButton.Text = Constants.WriteButtonDefaultText; WriteButton.Enabled = true; + WriteButton.Update(); } private void SetWriteButtonDelay() { WriteButton.Enabled = false; WriteButton.Text = $"{Constants.WriteButtonDelayText} : {ButtonTimer.Interval} ms"; + WriteButton.Update(); } private void OnScaleMenuItemClick(object sender, EventArgs e) diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 469fcf7..9f557f3 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -46,8 +46,12 @@ namespace grapher.Models TextBox offsetBoxY, TextBox accelerationBoxX, TextBox accelerationBoxY, + TextBox scaleBoxX, + TextBox scaleBoxY, TextBox limitBoxX, TextBox limitBoxY, + TextBox expBoxX, + TextBox expBoxY, TextBox midpointBoxX, TextBox midpointBoxY, CheckBox sensXYLock, @@ -63,8 +67,12 @@ namespace grapher.Models Label offsetLabelY, Label constantOneLabelX, Label constantOneLabelY, - Label constantTwoLabelX, - Label constantTwoLabelY, + Label scaleLabelX, + Label scaleLabelY, + Label limitLabelX, + Label limitLabelY, + Label expLabelX, + Label expLabelY, Label constantThreeLabelX, Label constantThreeLabelY, Label activeValueTitleX, @@ -80,8 +88,12 @@ namespace grapher.Models Label offsetActiveLabelY, Label accelerationActiveLabelX, Label accelerationActiveLabelY, - Label limitExpActiveLabelX, - Label limitExpActiveLabelY, + Label scaleActiveLabelX, + Label scaleActiveLabelY, + Label limitActiveLabelX, + Label limitActiveLabelY, + Label expActiveLabelX, + Label expActiveLabelY, Label midpointActiveLabelX, Label midpointActiveLabelY, Label accelTypeActiveLabelX, @@ -203,16 +215,40 @@ namespace grapher.Models new ActiveValueLabel(accelerationActiveLabelY, activeValueTitleY), optionSetYLeft); - var limitOrExponentX = new Option( + var scaleX = new Option( + new Field(scaleBoxX, form, 0), + scaleLabelX, + new ActiveValueLabel(scaleActiveLabelX, activeValueTitleX), + 0); + + var scaleY = new Option( + new Field(scaleBoxY, form, 0), + scaleLabelY, + new ActiveValueLabel(scaleActiveLabelY, activeValueTitleY), + optionSetYLeft); + + var limitX = new Option( new Field(limitBoxX, form, 2), - constantTwoLabelX, - new ActiveValueLabel(limitExpActiveLabelX, activeValueTitleX), + limitLabelX, + new ActiveValueLabel(limitActiveLabelX, activeValueTitleX), 0); - var limitOrExponentY = new Option( + var limitY = new Option( new Field(limitBoxY, form, 2), - constantTwoLabelY, - new ActiveValueLabel(limitExpActiveLabelY, activeValueTitleY), + limitLabelY, + new ActiveValueLabel(limitActiveLabelY, activeValueTitleY), + optionSetYLeft); + + var exponentX = new Option( + new Field(expBoxX, form, 2), + expLabelX, + new ActiveValueLabel(expActiveLabelX, activeValueTitleX), + 0); + + var exponentY = new Option( + new Field(expBoxY, form, 2), + expLabelY, + new ActiveValueLabel(expActiveLabelY, activeValueTitleY), optionSetYLeft); var midpointX = new Option( @@ -240,10 +276,12 @@ namespace grapher.Models var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, accelerationX, + scaleX, capOptionsX, weightX, offsetOptionsX, - limitOrExponentX, + limitX, + exponentX, midpointX, writeButton, new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX)); @@ -251,10 +289,12 @@ namespace grapher.Models var accelerationOptionsY = new AccelTypeOptions( accelTypeDropY, accelerationY, + scaleY, capOptionsY, weightY, offsetOptionsY, - limitOrExponentY, + limitY, + exponentY, midpointY, writeButton, new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY)); diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index 11a7f10..53c39af 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -98,14 +98,14 @@ namespace grapher.Models.Options Options.Top = TopAnchor; } - public void SetArgs(ref AccelArgs args) + public void SetArgs(ref AccelArgs args, ref /*readonly*/ AccelArgs last) { - Options.SetArgs(ref args); + Options.SetArgs(ref args, ref last); } - public AccelArgs GenerateArgs() + public AccelArgs GenerateArgs(ref /*readonly*/ AccelArgs last) { - return Options.GenerateArgs(); + return Options.GenerateArgs(ref last); } public void SetActiveValues(int mode, AccelArgs args) diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 573e9b9..9a4ab7c 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -30,10 +30,12 @@ namespace grapher public AccelTypeOptions( ComboBox accelDropdown, Option acceleration, + Option scale, CapOptions cap, Option weight, OffsetOptions offset, - Option limitOrExponent, + Option limit, + Option exponent, Option midpoint, Button writeButton, ActiveValueLabel accelTypeActiveValue) @@ -44,10 +46,12 @@ namespace grapher AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); Acceleration = acceleration; + Scale = scale; Cap = cap; Weight = weight; Offset = offset; - LimitOrExponent = limitOrExponent; + Limit = limit; + Exponent = exponent; Midpoint = midpoint; WriteButton = writeButton; AccelTypeActiveValue = accelTypeActiveValue; @@ -82,13 +86,17 @@ namespace grapher public Option Acceleration { get; } + public Option Scale { get; } + public CapOptions Cap { get; } public Option Weight { get; } public OffsetOptions Offset { get; } - public Option LimitOrExponent { get; } + public Option Limit { get; } + + public Option Exponent { get; } public Option Midpoint { get; } @@ -158,10 +166,12 @@ namespace grapher AccelTypeActiveValue.Hide(); Acceleration.Hide(); + Scale.Hide(); Cap.Hide(); Weight.Hide(); Offset.Hide(); - LimitOrExponent.Hide(); + Limit.Hide(); + Exponent.Hide(); Midpoint.Hide(); } @@ -185,9 +195,11 @@ namespace grapher Weight.SetActiveValue(args.weight); Cap.SetActiveValues(args.gainCap, args.scaleCap, args.gainCap > 0 || args.scaleCap <= 0); - Offset.SetActiveValue(args.offset, args.legacy_offset); - Acceleration.SetActiveValue(args.accel); - LimitOrExponent.SetActiveValue(args.exponent); + Offset.SetActiveValue(args.offset, args.legacyOffset); + Acceleration.SetActiveValue(args.acceleration); + Scale.SetActiveValue(args.scale); + Limit.SetActiveValue(args.limit); + Exponent.SetActiveValue(args.exponent); Midpoint.SetActiveValue(args.midpoint); } @@ -213,26 +225,24 @@ namespace grapher Width = Acceleration.Field.Width; } - public void SetArgs(ref AccelArgs args) + public void SetArgs(ref AccelArgs args, ref /*readonly*/ AccelArgs last) { - args.accel = Acceleration.Field.Data; - args.rate = Acceleration.Field.Data; - args.powerScale = Acceleration.Field.Data; + args.acceleration = Acceleration.Visible ? Acceleration.Field.Data : last.acceleration; + args.scale = Scale.Visible ? Scale.Field.Data : last.scale; args.gainCap = Cap.VelocityGainCap; args.scaleCap = Cap.SensitivityCap; - args.limit = LimitOrExponent.Field.Data; - args.exponent = LimitOrExponent.Field.Data; - args.powerExponent = LimitOrExponent.Field.Data; + args.limit = Limit.Visible ? Limit.Field.Data : last.limit; + args.exponent = Exponent.Visible ? Exponent.Field.Data : last.exponent; args.offset = Offset.Offset; - args.legacy_offset = Offset.LegacyOffset; - args.midpoint = Midpoint.Field.Data; - args.weight = Weight.Field.Data; + args.legacyOffset = Offset.IsLegacy; + args.midpoint = Midpoint.Visible ? Midpoint.Field.Data : last.midpoint; + args.weight = Weight.Visible ? Weight.Field.Data : last.weight; } - public AccelArgs GenerateArgs() + public AccelArgs GenerateArgs(ref /*readonly*/ AccelArgs last) { AccelArgs args = new AccelArgs(); - SetArgs(ref args); + SetArgs(ref args, ref last); return args; } @@ -240,10 +250,12 @@ namespace grapher { AccelTypeActiveValue.Align(); Acceleration.AlignActiveValues(); + Scale.AlignActiveValues(); Cap.AlignActiveValues(); Offset.AlignActiveValues(); Weight.AlignActiveValues(); - LimitOrExponent.AlignActiveValues(); + Limit.AlignActiveValues(); + Exponent.AlignActiveValues(); Midpoint.AlignActiveValues(); } @@ -269,10 +281,12 @@ namespace grapher AccelerationType.Layout( Acceleration, + Scale, Cap, Weight, Offset, - LimitOrExponent, + Limit, + Exponent, Midpoint, WriteButton, top); diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index c2ed498..51c80ea 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -89,14 +89,14 @@ namespace grapher.Models.Options }; } - public Vec2<AccelArgs> GetArgs() + public Vec2<AccelArgs> GetUpdatedArgs(ref /*readonly*/ Vec2<AccelArgs> last) { - var xArgs = OptionSetX.GenerateArgs(); + var xArgs = OptionSetX.GenerateArgs(ref last.x); return new Vec2<AccelArgs> { x = xArgs, - y = ByComponentVectorXYLock.Checked ? xArgs : OptionSetY.GenerateArgs() + y = ByComponentVectorXYLock.Checked ? xArgs : OptionSetY.GenerateArgs(ref last.y) }; } diff --git a/grapher/Models/Options/OffsetOptions.cs b/grapher/Models/Options/OffsetOptions.cs index b351ab5..c6bee75 100644 --- a/grapher/Models/Options/OffsetOptions.cs +++ b/grapher/Models/Options/OffsetOptions.cs @@ -128,16 +128,9 @@ namespace grapher.Models.Options OffsetOption.Show(name); } - public void SetActiveValue(double offset, double legacyOffset) + public void SetActiveValue(double offset, bool legacy) { - if (offset > 0) - { - OffsetOption.SetActiveValue(offset); - } - else - { - OffsetOption.SetActiveValue(legacyOffset); - } + OffsetOption.SetActiveValue(offset); } public override void AlignActiveValues() diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 3f5aebc..570a6c8 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -1,6 +1,8 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.IO; +using System.Linq; namespace grapher.Models.Serialized { @@ -13,9 +15,8 @@ namespace grapher.Models.Serialized public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, Constants.DefaultSettingsFileName); public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings { - MissingMemberHandling = MissingMemberHandling.Error, + MissingMemberHandling = MissingMemberHandling.Ignore, }; - #endregion Fields #region Constructors @@ -33,9 +34,10 @@ namespace grapher.Models.Serialized #endregion Constructors #region Properties - + [JsonProperty(Required = Required.Always)] public GUISettings GUISettings { get; set; } + [JsonProperty(DriverSettings.Key, Required = Required.Always)] public DriverSettings AccelerationSettings { get; set; } #endregion Properties @@ -51,15 +53,17 @@ namespace grapher.Models.Serialized { try { - return JsonConvert.DeserializeObject<RawAccelSettings>(File.ReadAllText(file), SerializerSettings); + var settings = JsonConvert.DeserializeObject<RawAccelSettings>(File.ReadAllText(file), SerializerSettings); + if (settings is null) throw new JsonException($"{file} contains invalid JSON"); + return settings; } catch (FileNotFoundException e) { throw new FileNotFoundException($"Settings file does not exist at {file}", e); } - catch (JsonSerializationException e) + catch (JsonException e) { - throw new JsonSerializationException($"Settings file at {file} does not contain valid Raw Accel Settings.", e); + throw new JsonException($"Settings file at {file} does not contain valid Raw Accel Settings.", e); } } @@ -80,7 +84,16 @@ namespace grapher.Models.Serialized public void Save(string file) { - File.WriteAllText(file, JsonConvert.SerializeObject(this, Formatting.Indented)); + JObject thisJO = JObject.FromObject(this); + AddComments(thisJO); + File.WriteAllText(file, thisJO.ToString(Formatting.Indented)); + } + + private void AddComments(JObject thisJO) + { + string modes = string.Join(" | ", Enum.GetNames(typeof(AccelMode))); + ((JObject)thisJO[DriverSettings.Key]) + .AddFirst(new JProperty("### Mode Types ###", modes)); } #endregion Methods diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 26160f5..93cf42b 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -47,28 +47,31 @@ namespace grapher.Models.Serialized #region Methods - public void UpdateActiveSettings(DriverSettings settings) + public SettingsErrors TryUpdateActiveSettings(DriverSettings settings) { - ActiveAccel.UpdateFromSettings(settings); - SendToDriver(settings); + var errors = TryUpdateAccel(settings); - RawAccelSettings.AccelerationSettings = settings; - RawAccelSettings.GUISettings = new GUISettings + if (errors.Empty()) { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data, - ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, - }; + RawAccelSettings.AccelerationSettings = settings; + RawAccelSettings.GUISettings = new GUISettings + { + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data, + ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, + ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, + }; - RawAccelSettings.Save(); + RawAccelSettings.Save(); + } + + return errors; } public void UpdateActiveAccelFromFileSettings(DriverSettings settings) - { - ActiveAccel.UpdateFromSettings(settings); - SendToDriver(settings); + { + TryUpdateAccel(settings); DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); @@ -77,9 +80,23 @@ namespace grapher.Models.Serialized ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; } + public SettingsErrors TryUpdateAccel(DriverSettings settings) + { + var errors = SendToDriverSafe(settings); + if (errors.Empty()) ActiveAccel.UpdateFromSettings(settings); + return errors; + } + public static void SendToDriver(DriverSettings settings) { - new Thread(() => DriverInterop.SetActiveSettings(settings)).Start(); + new Thread(() => DriverInterop.Write(settings)).Start(); + } + + public static SettingsErrors SendToDriverSafe(DriverSettings settings) + { + var errors = DriverInterop.GetSettingsErrors(settings); + if (errors.Empty()) SendToDriver(settings); + return errors; } public void Startup() @@ -95,7 +112,7 @@ namespace grapher.Models.Serialized } return; } - catch (JsonSerializationException e) + catch (JsonException e) { Console.WriteLine($"bad settings: {e}"); } |