diff options
28 files changed, 575 insertions, 195 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp index d536923..5106268 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -5,15 +5,13 @@ namespace rawaccel { /// <summary> Struct to hold arguments for an acceleration function. </summary> struct accel_args { double offset = 0; - double legacy_offset = 0; + bool legacy_offset = false; double accel = 0; + double scale = 1; double limit = 2; double exponent = 2; - double midpoint = 0; - double power_scale = 1; - double power_exp = 0.05; + double midpoint = 10; double weight = 1; - double rate = 0; double scale_cap = 0; double gain_cap = 0; }; @@ -33,14 +31,16 @@ namespace rawaccel { struct additive_accel : accel_val_base<Func> { additive_accel(const accel_args& args) : accel_val_base(args) { - legacy_offset = args.offset <= 0 && args.legacy_offset > 0; - offset = legacy_offset ? args.legacy_offset : args.offset; + legacy_offset = args.legacy_offset; + offset = args.offset; weight = args.weight; } inline double operator()(double speed) const { double offset_speed = speed - offset; - return offset_speed > 0 ? ( legacy_offset ? 1 + fn.legacy_offset(offset_speed) * weight : 1 + fn(offset_speed) * weight) : 1; + if (offset_speed <= 0) return 1; + if (legacy_offset) return 1 + fn.legacy_offset(offset_speed) * weight; + return 1 + fn(offset_speed) * weight; } }; diff --git a/common/accel-motivity.hpp b/common/accel-motivity.hpp index a37d1ce..f88320b 100644 --- a/common/accel-motivity.hpp +++ b/common/accel-motivity.hpp @@ -23,7 +23,7 @@ namespace rawaccel { double subtractive_constant; motivity_impl(const accel_args& args) : - rate(pow(10,args.rate)), limit(2*log10(args.limit)), midpoint(log10(args.midpoint)) + rate(pow(10,args.accel)), limit(2*log10(args.limit)), midpoint(log10(args.midpoint)) { subtractive_constant = limit / 2; } diff --git a/common/accel-power.hpp b/common/accel-power.hpp index 1abfdd1..5d0c451 100644 --- a/common/accel-power.hpp +++ b/common/accel-power.hpp @@ -12,7 +12,7 @@ namespace rawaccel { double exponent; power_impl(const accel_args& args) : - scale(args.power_scale), exponent(args.power_exp) + scale(args.scale), exponent(args.exponent) {} inline double operator()(double speed) const { diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index 1a513ac..aeb89e8 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -7,6 +7,7 @@ namespace rawaccel { using milliseconds = double; inline constexpr milliseconds WRITE_DELAY = 1000; + inline constexpr milliseconds DEFAULT_TIME_MIN = 0.4; enum class accel_mode { linear, classic, natural, naturalgain, power, motivity, noaccel @@ -18,7 +19,7 @@ namespace rawaccel { vec2<accel_mode> modes = { accel_mode::noaccel, accel_mode::noaccel }; vec2<accel_args> argsv; vec2d sens = { 1, 1 }; - milliseconds time_min = 0.4; + milliseconds time_min = DEFAULT_TIME_MIN; }; } diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 14db883..d325abe 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -16,8 +16,6 @@ namespace rawaccel { - using milliseconds = double; - /// <summary> Struct to hold vector rotation details. </summary> struct rotator { diff --git a/driver/driver.cpp b/driver/driver.cpp index 4dd3d62..5fa1dd1 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -151,9 +151,8 @@ Return Value: DebugPrint(("Ioctl received into filter control object.\n")); if (InputBufferLength == sizeof(ra::settings)) { - // 1 second wait LARGE_INTEGER interval; - interval.QuadPart = -10000000; + interval.QuadPart = static_cast<LONGLONG>(ra::WRITE_DELAY) * -10000; KeDelayExecutionThread(KernelMode, FALSE, &interval); status = WdfRequestRetrieveInputBuffer( @@ -172,7 +171,7 @@ Return Value: ra::settings new_settings = *reinterpret_cast<ra::settings*>(buffer); - if (new_settings.time_min <= 0 || _isnanf(new_settings.time_min)) { + if (new_settings.time_min <= 0 || _isnanf(static_cast<float>(new_settings.time_min))) { new_settings.time_min = ra::settings{}.time_min; } diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index c6a895d..3c39eaf 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 = 15; // - // 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 = 17; @@ -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 = 21; 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 = 51; @@ -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..5b37e81 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; } 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}"); } diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index 3307b8d..72ebdc7 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -9,29 +9,33 @@ using namespace System; using namespace System::Runtime::InteropServices; +using namespace Newtonsoft::Json; + +[JsonConverter(Converters::StringEnumConverter::typeid)] public enum class AccelMode { linear, classic, natural, naturalgain, power, motivity, noaccel }; +[JsonObject(ItemRequired = Required::Always)] [StructLayout(LayoutKind::Sequential)] public value struct AccelArgs { double offset; - double legacy_offset; - double accel; + [MarshalAs(UnmanagedType::U1)] + bool legacyOffset; + double acceleration; + double scale; double limit; double exponent; double midpoint; - double powerScale; - double powerExponent; double weight; - double rate; double scaleCap; double gainCap; }; generic <typename T> +[JsonObject(ItemRequired = Required::Always)] [StructLayout(LayoutKind::Sequential)] public value struct Vec2 { @@ -39,18 +43,35 @@ public value struct Vec2 T y; }; -[Serializable] +[JsonObject(ItemRequired = Required::Always)] [StructLayout(LayoutKind::Sequential)] public ref struct DriverSettings { + literal String^ Key = "Driver settings"; + + [JsonProperty("Degrees of rotation")] double rotation; + + [JsonProperty("Use x as whole/combined accel")] [MarshalAs(UnmanagedType::U1)] bool combineMagnitudes; + + [JsonProperty("Accel modes")] Vec2<AccelMode> modes; + + [JsonProperty("Accel parameters")] Vec2<AccelArgs> args; + + [JsonProperty("Sensitivity")] Vec2<double> sensitivity; - [NonSerialized] + + [JsonProperty(Required = Required::Default)] double minimumTime; + + bool ShouldSerializeminimumTime() + { + return minimumTime > 0 && minimumTime != DEFAULT_TIME_MIN; + } }; @@ -102,14 +123,62 @@ void update_modifier(mouse_modifier& mod, DriverSettings^ managed, vec2<si_pair* }); } +using error_list_t = Collections::Generic::List<String^>; + +error_list_t^ get_accel_errors(AccelMode mode, AccelArgs^ args) +{ + accel_mode m = (accel_mode)mode; + + auto is_mode = [m](auto... modes) { return ((m == modes) || ...); }; + + using am = accel_mode; + + auto error_list = gcnew error_list_t(); + + if (args->acceleration > 1 && is_mode(am::natural, am::naturalgain)) + error_list->Add("acceleration can not be greater than 1"); + else if (args->acceleration < 0) + error_list->Add("acceleration can not be negative, use a negative weight to compensate"); + + if (args->scale <= 0) + error_list->Add("scale must be positive"); + + if (args->exponent <= 1 && is_mode(am::classic)) + error_list->Add("exponent must be greater than 1"); + else if (args->exponent <= 0) + error_list->Add("exponent must be positive"); + + if (args->limit <= 1) + error_list->Add("limit must be greater than 1"); + + if (args->midpoint <= 0) + error_list->Add("midpoint must be positive"); + + return error_list; +} + +public ref class SettingsErrors +{ +public: + error_list_t^ x; + error_list_t^ y; + + bool Empty() + { + return x->Count == 0 && y->Count == 0; + } +}; + public ref struct DriverInterop { + literal double WriteDelayMs = WRITE_DELAY; + static DriverSettings^ GetActiveSettings() { return get_active(); } - static void SetActiveSettings(DriverSettings^ args) + static void Write(DriverSettings^ args) { set_active(args); } @@ -119,22 +188,21 @@ public ref struct DriverInterop return get_default(); } - using error_list_t = Collections::Generic::List<String^>; + static SettingsErrors^ GetSettingsErrors(DriverSettings^ args) + { + auto errors = gcnew SettingsErrors(); + + errors->x = get_accel_errors(args->modes.x, args->args.x); + + if (args->combineMagnitudes) errors->y = gcnew error_list_t(); + else errors->y = get_accel_errors(args->modes.y, args->args.y); + + return errors; + } - static error_list_t^ GetErrors(AccelArgs^ args) + static error_list_t^ GetAccelErrors(AccelMode mode, AccelArgs^ args) { - auto error_list = gcnew error_list_t(); - - if (args->accel < 0 || args->rate < 0) - error_list->Add("accel can not be negative, use a negative weight to compensate"); - if (args->rate > 1) error_list->Add("rate can not be greater than 1"); - if (args->exponent <= 1) error_list->Add("exponent must be greater than 1"); - if (args->limit <= 1) error_list->Add("limit must be greater than 1"); - if (args->powerScale <= 0) error_list->Add("scale must be positive"); - if (args->powerExponent <= 0) error_list->Add("exponent must be positive"); - if (args->midpoint < 0) error_list->Add("midpoint must not be negative"); - - return error_list; + return get_accel_errors(mode, args); } }; @@ -150,7 +218,6 @@ public ref class ManagedAccel #endif public: - static initonly double WriteDelay = WRITE_DELAY; virtual ~ManagedAccel() { diff --git a/wrapper/wrapper.vcxproj b/wrapper/wrapper.vcxproj index 8484c22..37060ad 100644 --- a/wrapper/wrapper.vcxproj +++ b/wrapper/wrapper.vcxproj @@ -74,6 +74,9 @@ <ClCompile Include="wrapper.cpp" /> <ClCompile Include="wrapper_io.cpp" /> </ItemGroup> + <ItemGroup> + <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/writer/Program.cs b/writer/Program.cs index 7f9c37c..2d4128f 100644 --- a/writer/Program.cs +++ b/writer/Program.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Microsoft.CSharp.RuntimeBinder; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -6,24 +7,67 @@ using System.IO; namespace writer { + class Program { + static void Send(JToken settingsToken) + { + var settings = settingsToken.ToObject<DriverSettings>(); + + var errors = DriverInterop.GetSettingsErrors(settings); + if (errors.Empty()) + { + DriverInterop.Write(settings); + return; + } + + foreach (var err in errors.x) + { + Console.WriteLine(err + (settings.combineMagnitudes ? "" : " (x)")); + } + foreach (var err in errors.y) + { + Console.WriteLine(err + " (y)"); + } + } + static void Main(string[] args) { + if (args.Length != 1 || args[0].Equals("help")) + { + Console.WriteLine("USAGE: {0} <file>", System.AppDomain.CurrentDomain.FriendlyName); + return; + } + + if (!File.Exists(args[0])) + { + Console.WriteLine("Settings file not found at {0}", args[0]); + return; + } + try { - var serializerSettings = new JsonSerializerSettings + var JO = JObject.Parse(File.ReadAllText(args[0])); + + if (JO.ContainsKey(DriverSettings.Key)) { - MissingMemberHandling = MissingMemberHandling.Error, - }; - var token = JObject.Parse(File.ReadAllText(args[0]))["AccelerationSettings"]; - var settings = token.ToObject<DriverSettings>(JsonSerializer.Create(serializerSettings)); - DriverInterop.SetActiveSettings(settings); + Send(JO[DriverSettings.Key]); + return; + } + + Send(JO); + } + catch (JsonException e) + { + Console.WriteLine("Settings invalid:\n{0}", e.Message.ToString()); + } + catch (DriverNotInstalledException) + { + Console.WriteLine("Driver is not installed"); } catch (Exception e) - { - Console.WriteLine(e); - Console.ReadLine(); + { + Console.WriteLine("Error: {0}", e.Message.ToString()); } } } |