From 7ff79f4e711c2d55daf667092cfce0289b1a7a9b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 1 Sep 2020 22:28:45 -0400 Subject: add 1s write delay to driver --- grapher/Models/AccelGUI.cs | 12 ++++++++++-- grapher/Models/Serialized/DriverSettings.cs | 29 ++++++++++++++++++++-------- grapher/Models/Serialized/SettingsManager.cs | 24 +++++++---------------- 3 files changed, 38 insertions(+), 27 deletions(-) (limited to 'grapher') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index a15dba8..7a32b4e 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -102,7 +102,7 @@ namespace grapher public void UpdateActiveSettingsFromFields() { - Settings.UpdateActiveSettings(new DriverSettings + var settings = new DriverSettings { rotation = Rotation.Field.Data, sensitivity = new Vec2 @@ -133,8 +133,16 @@ namespace grapher } }, minimumTime = .4 + }; + + Settings.UpdateActiveSettings(settings, () => + { + AccelForm.Invoke((MethodInvoker)delegate + { + UpdateGraph(); + }); }); - UpdateGraph(); + } public void UpdateGraph() diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs index 91d7e9f..4595bf2 100644 --- a/grapher/Models/Serialized/DriverSettings.cs +++ b/grapher/Models/Serialized/DriverSettings.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using System.Threading; namespace grapher.Models.Serialized { @@ -37,6 +38,7 @@ namespace grapher.Models.Serialized { private static readonly IntPtr UnmanagedSettingsHandle = Marshal.AllocHGlobal(Marshal.SizeOf()); + private static object UnmanagedSettingsLock = new object(); public double rotation; public bool combineMagnitudes; @@ -51,21 +53,32 @@ namespace grapher.Models.Serialized return Marshal.PtrToStructure(UnmanagedSettingsHandle); } - public static void SetActive(DriverSettings settings) + public static void SetActive(DriverSettings settings, Action unmanagedActionBefore = null) { - Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false); - DriverInterop.SetActiveSettings(UnmanagedSettingsHandle); + new Thread(() => + { + lock (UnmanagedSettingsLock) + { + Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false); + unmanagedActionBefore?.Invoke(UnmanagedSettingsHandle); + DriverInterop.SetActiveSettings(UnmanagedSettingsHandle); + } + }).Start(); + } - public void SendToDriver() + public void SendToDriver(Action unmanagedActionBefore = null) { - SetActive(this); + SetActive(this, unmanagedActionBefore); } - public void SendToDriverAndUpdate(ManagedAccel accel) + public void SendToDriverAndUpdate(ManagedAccel accel, Action betweenAccelAndWrite = null) { - SendToDriver(); - accel.UpdateFromSettings(UnmanagedSettingsHandle); + SendToDriver(settingsHandle => + { + accel.UpdateFromSettings(settingsHandle); + betweenAccelAndWrite?.Invoke(); + }); } public bool verify() diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index fc58387..c300bde 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -28,12 +28,10 @@ namespace grapher.Models.Serialized private ToolStripMenuItem AutoWriteMenuItem { get; set; } - public void UpdateActiveSettings(DriverSettings settings) + public void UpdateActiveSettings(DriverSettings settings, Action afterAccelSettingsUpdate = null) { - try + settings.SendToDriverAndUpdate(ActiveAccel, () => { - settings.SendToDriverAndUpdate(ActiveAccel); - RawAccelSettings.AccelerationSettings = settings; RawAccelSettings.GUISettings = new GUISettings { @@ -43,23 +41,15 @@ namespace grapher.Models.Serialized }; RawAccelSettings.Save(); - } - catch (DriverWriteCDException) - { - Console.WriteLine("write on cooldown"); - } + + afterAccelSettingsUpdate?.Invoke(); + }); } public void UpdateActiveAccelFromFileSettings(DriverSettings settings) { - try - { - settings.SendToDriverAndUpdate(ActiveAccel); - } - catch (DriverWriteCDException) - { - Console.WriteLine("write on cd during file init"); - } + settings.SendToDriverAndUpdate(ActiveAccel); + DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; -- cgit v1.2.3 From 01f870a493378a62ab76dcbf5dc37c0390ca7afe Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 3 Sep 2020 19:36:44 -0700 Subject: Refactor for nice gain offset --- grapher/Models/AccelGUI.cs | 1 + grapher/Models/Serialized/DriverSettings.cs | 1 + 2 files changed, 2 insertions(+) (limited to 'grapher') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 7a32b4e..1657074 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -120,6 +120,7 @@ namespace grapher x = new AccelArgs { offset = Offset.Field.Data, + legacy_offset = 0, weight = Weight.Fields.X, gainCap = Cap.VelocityGainCap, scaleCap = Cap.SensitivityCapX, diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs index 4595bf2..cdccf88 100644 --- a/grapher/Models/Serialized/DriverSettings.cs +++ b/grapher/Models/Serialized/DriverSettings.cs @@ -13,6 +13,7 @@ namespace grapher.Models.Serialized public struct AccelArgs { public double offset; + public double legacy_offset; public double accel; public double limit; public double exponent; -- cgit v1.2.3 From 2fbc4b3d504962c2462d7aec98f5f389e5333164 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 3 Sep 2020 20:10:43 -0700 Subject: Add offset options to GUI, make gain options default --- grapher/Form1.Designer.cs | 64 ++++++++++++----- grapher/Form1.cs | 11 ++- grapher/Models/AccelGUI.cs | 11 +-- grapher/Models/Options/CapOptions.cs | 22 +++--- grapher/Models/Options/OffsetOptions.cs | 124 ++++++++++++++++++++++++++++++++ grapher/grapher.csproj | 1 + 6 files changed, 196 insertions(+), 37 deletions(-) create mode 100644 grapher/Models/Options/OffsetOptions.cs (limited to 'grapher') diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 70455ce..a7a3e16 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -93,8 +93,8 @@ namespace grapher this.ScaleMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.advancedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.capStyleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.sensitivityToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.velocityGainToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.gainCapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.legacyCapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.startupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AccelerationChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); @@ -114,6 +114,9 @@ namespace grapher this.OffsetActiveLabel = new System.Windows.Forms.Label(); this.LimitExpActiveLabel = new System.Windows.Forms.Label(); this.MidpointActiveLabel = new System.Windows.Forms.Label(); + this.offsetStyleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.gainOffsetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.legacyOffsetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.VelocityChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.GainChart)).BeginInit(); @@ -491,7 +494,8 @@ namespace grapher // advancedToolStripMenuItem // this.advancedToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.capStyleToolStripMenuItem}); + this.capStyleToolStripMenuItem, + this.offsetStyleToolStripMenuItem}); this.advancedToolStripMenuItem.Name = "advancedToolStripMenuItem"; this.advancedToolStripMenuItem.Size = new System.Drawing.Size(72, 20); this.advancedToolStripMenuItem.Text = "Advanced"; @@ -499,25 +503,25 @@ namespace grapher // capStyleToolStripMenuItem // this.capStyleToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.sensitivityToolStripMenuItem, - this.velocityGainToolStripMenuItem}); + this.gainCapToolStripMenuItem, + this.legacyCapToolStripMenuItem}); this.capStyleToolStripMenuItem.Name = "capStyleToolStripMenuItem"; - this.capStyleToolStripMenuItem.Size = new System.Drawing.Size(123, 22); + this.capStyleToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.capStyleToolStripMenuItem.Text = "Cap Style"; // - // sensitivityToolStripMenuItem + // gainCapToolStripMenuItem // - this.sensitivityToolStripMenuItem.Checked = true; - this.sensitivityToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; - this.sensitivityToolStripMenuItem.Name = "sensitivityToolStripMenuItem"; - this.sensitivityToolStripMenuItem.Size = new System.Drawing.Size(142, 22); - this.sensitivityToolStripMenuItem.Text = "Sensitivity"; + this.gainCapToolStripMenuItem.Checked = true; + this.gainCapToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.gainCapToolStripMenuItem.Name = "gainCapToolStripMenuItem"; + this.gainCapToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.gainCapToolStripMenuItem.Text = "Gain (Default)"; // - // velocityGainToolStripMenuItem + // legacyCapToolStripMenuItem // - this.velocityGainToolStripMenuItem.Name = "velocityGainToolStripMenuItem"; - this.velocityGainToolStripMenuItem.Size = new System.Drawing.Size(142, 22); - this.velocityGainToolStripMenuItem.Text = "Velocity Gain"; + this.legacyCapToolStripMenuItem.Name = "legacyCapToolStripMenuItem"; + this.legacyCapToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.legacyCapToolStripMenuItem.Text = "Legacy"; // // startupToolStripMenuItem // @@ -737,6 +741,27 @@ namespace grapher this.MidpointActiveLabel.TabIndex = 47; this.MidpointActiveLabel.Text = "0"; // + // offsetStyleToolStripMenuItem + // + this.offsetStyleToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.gainOffsetToolStripMenuItem, + this.legacyOffsetToolStripMenuItem}); + this.offsetStyleToolStripMenuItem.Name = "offsetStyleToolStripMenuItem"; + this.offsetStyleToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.offsetStyleToolStripMenuItem.Text = "Offset Style"; + // + // gainOffsetToolStripMenuItem + // + this.gainOffsetToolStripMenuItem.Name = "gainOffsetToolStripMenuItem"; + this.gainOffsetToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.gainOffsetToolStripMenuItem.Text = "Gain (Default)"; + // + // legacyOffsetToolStripMenuItem + // + this.legacyOffsetToolStripMenuItem.Name = "legacyOffsetToolStripMenuItem"; + this.legacyOffsetToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.legacyOffsetToolStripMenuItem.Text = "Legacy"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -840,8 +865,8 @@ namespace grapher private System.Windows.Forms.ToolStripMenuItem showVelocityGainToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem advancedToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem capStyleToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem sensitivityToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem velocityGainToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem gainCapToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem legacyCapToolStripMenuItem; private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChartY; private System.Windows.Forms.DataVisualization.Charting.Chart VelocityChartY; private System.Windows.Forms.DataVisualization.Charting.Chart GainChartY; @@ -867,6 +892,9 @@ namespace grapher private System.Windows.Forms.Label MidpointActiveLabel; private System.Windows.Forms.ToolStripMenuItem startupToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem AutoWriteMenuItem; + private System.Windows.Forms.ToolStripMenuItem offsetStyleToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem gainOffsetToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem legacyOffsetToolStripMenuItem; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 37f67f8..ba0730c 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -104,6 +104,11 @@ namespace grapher new ActiveValueLabel(OffsetActiveLabel, ActiveValueTitle), "Offset"); + var offsetOptions = new OffsetOptions( + gainOffsetToolStripMenuItem, + legacyOffsetToolStripMenuItem, + offset); + // The name and layout of these options is handled by AccelerationOptions object. var acceleration = new Option( new Field(accelerationBox, this, 0), @@ -138,8 +143,8 @@ namespace grapher new ActiveValueLabel(AccelTypeActiveLabel, ActiveValueTitle)); var capOptions = new CapOptions( - sensitivityToolStripMenuItem, - velocityGainToolStripMenuItem, + gainCapToolStripMenuItem, + legacyCapToolStripMenuItem, cap, weight); @@ -163,7 +168,7 @@ namespace grapher rotation, weight, capOptions, - offset, + offsetOptions, acceleration, limitOrExponent, midpoint, diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 1657074..a7d5d49 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -1,5 +1,6 @@ using grapher.Models.Calculations; using grapher.Models.Mouse; +using grapher.Models.Options; using grapher.Models.Serialized; using System; using System.CodeDom; @@ -28,7 +29,7 @@ namespace grapher Option rotation, OptionXY weight, CapOptions cap, - Option offset, + OffsetOptions offset, Option acceleration, Option limtOrExp, Option midpoint, @@ -82,7 +83,7 @@ namespace grapher public CapOptions Cap { get; } - public Option Offset { get; } + public OffsetOptions Offset { get; } public Option Acceleration { get; } @@ -119,8 +120,8 @@ namespace grapher { x = new AccelArgs { - offset = Offset.Field.Data, - legacy_offset = 0, + offset = Offset.Offset, + legacy_offset = Offset.LegacyOffset, weight = Weight.Fields.X, gainCap = Cap.VelocityGainCap, scaleCap = Cap.SensitivityCapX, @@ -163,7 +164,7 @@ namespace grapher Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y); Rotation.SetActiveValue(settings.rotation); AccelerationOptions.SetActiveValue((int)settings.modes.x); - Offset.SetActiveValue(settings.args.x.offset); + Offset.SetActiveValue(settings.args.x.offset, settings.args.y.offset); Weight.SetActiveValues(settings.args.x.weight, settings.args.x.weight); Acceleration.SetActiveValue(settings.args.x.accel); // rate, powerscale LimitOrExponent.SetActiveValue(settings.args.x.limit); //exp, powerexp diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs index 493561a..87bac88 100644 --- a/grapher/Models/Options/CapOptions.cs +++ b/grapher/Models/Options/CapOptions.cs @@ -14,27 +14,27 @@ namespace grapher public const string GainCapFormatString = "0.##"; public CapOptions( - ToolStripMenuItem sensitivityCapCheck, ToolStripMenuItem velocityGainCapCheck, + ToolStripMenuItem legacyCapCheck, OptionXY capOption, OptionXY weightOption) { - SensitivityCapCheck = sensitivityCapCheck; VelocityGainCapCheck = velocityGainCapCheck; + LegacyCapCheck = legacyCapCheck; CapOption = capOption; WeightOption = weightOption; - SensitivityCapCheck.Click += new System.EventHandler(OnSensitivityCapCheckClick); + LegacyCapCheck.Click += new System.EventHandler(OnSensitivityCapCheckClick); VelocityGainCapCheck.Click += new System.EventHandler(OnVelocityGainCapCheckClick); - SensitivityCapCheck.CheckedChanged += new System.EventHandler(OnSensitivityCapCheckedChange); + LegacyCapCheck.CheckedChanged += new System.EventHandler(OnSensitivityCapCheckedChange); VelocityGainCapCheck.CheckedChanged += new System.EventHandler(OnVelocityGainCapCheckedChange); - EnableSensitivityCap(); + EnableVelocityGainCap(); } - public ToolStripMenuItem SensitivityCapCheck { get; } + public ToolStripMenuItem LegacyCapCheck { get; } public ToolStripMenuItem VelocityGainCapCheck { get; } @@ -104,10 +104,10 @@ namespace grapher void OnSensitivityCapCheckClick(object sender, EventArgs e) { - if (!SensitivityCapCheck.Checked) + if (!LegacyCapCheck.Checked) { VelocityGainCapCheck.Checked = false; - SensitivityCapCheck.Checked = true; + LegacyCapCheck.Checked = true; } } @@ -116,13 +116,13 @@ namespace grapher if (!VelocityGainCapCheck.Checked) { VelocityGainCapCheck.Checked = true; - SensitivityCapCheck.Checked = false; + LegacyCapCheck.Checked = false; } } void OnSensitivityCapCheckedChange(object sender, EventArgs e) { - if (SensitivityCapCheck.Checked == true) + if (LegacyCapCheck.Checked == true) { EnableSensitivityCap(); } @@ -130,7 +130,7 @@ namespace grapher void OnVelocityGainCapCheckedChange(object sender, EventArgs e) { - if (SensitivityCapCheck.Checked == true) + if (LegacyCapCheck.Checked == true) { EnableVelocityGainCap(); } diff --git a/grapher/Models/Options/OffsetOptions.cs b/grapher/Models/Options/OffsetOptions.cs new file mode 100644 index 0000000..0b01ab9 --- /dev/null +++ b/grapher/Models/Options/OffsetOptions.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class OffsetOptions + { + public OffsetOptions( + ToolStripMenuItem velocityGainOffsetCheck, + ToolStripMenuItem legacyOffsetCheck, + Option offsetOption) + { + VelocityGainOffsetCheck = velocityGainOffsetCheck; + LegacyOffsetCheck = legacyOffsetCheck; + OffsetOption = offsetOption; + + VelocityGainOffsetCheck.Click += new System.EventHandler(OnVelocityGainOffsetClick); + LegacyOffsetCheck.Click += new System.EventHandler(OnLegacyOffsetClick); + + VelocityGainOffsetCheck.CheckedChanged += new System.EventHandler(OnVelocityGainOffsetCheckedChange); + LegacyOffsetCheck.CheckedChanged += new System.EventHandler(OnLegacyOffsetCheckedChange); + + VelocityGainOffsetCheck.Checked = true; + } + + public ToolStripMenuItem VelocityGainOffsetCheck { get; } + + public ToolStripMenuItem LegacyOffsetCheck { get; } + + public Option OffsetOption { get; } + + public bool IsLegacy { get; private set; } + + public double LegacyOffset + { + get + { + if (IsLegacy) + { + return OffsetOption.Field.Data; + } + else + { + return 0; + } + } + } + + public double Offset + { + get + { + if (IsLegacy) + { + return 0; + } + else + { + return OffsetOption.Field.Data; + } + } + } + + public void SetActiveValue(double offset, double legacyOffset) + { + if (offset > 0) + { + OffsetOption.SetActiveValue(offset); + } + else + { + OffsetOption.SetActiveValue(legacyOffset); + } + } + + public void OnVelocityGainOffsetClick(object sender, EventArgs e) + { + if (!VelocityGainOffsetCheck.Checked) + { + VelocityGainOffsetCheck.Checked = true; + LegacyOffsetCheck.Checked = false; + } + } + + public void OnLegacyOffsetClick(object sender, EventArgs e) + { + if (!LegacyOffsetCheck.Checked) + { + LegacyOffsetCheck.Checked = true; + VelocityGainOffsetCheck.Checked = false; + } + } + + public void OnVelocityGainOffsetCheckedChange(object sender, EventArgs e) + { + if (VelocityGainOffsetCheck.Checked) + { + EnableVelocityGainOffset(); + } + } + + public void OnLegacyOffsetCheckedChange(object sender, EventArgs e) + { + if (LegacyOffsetCheck.Checked) + { + EnableLegacyOffset(); + } + } + + public void EnableVelocityGainOffset() + { + IsLegacy = false; + } + + public void EnableLegacyOffset() + { + IsLegacy = true; + } + } +} diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index d34e678..28322bb 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -85,6 +85,7 @@ + -- cgit v1.2.3