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/Models') 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/Models') 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/Models/AccelGUI.cs | 11 +-- grapher/Models/Options/CapOptions.cs | 22 +++--- grapher/Models/Options/OffsetOptions.cs | 124 ++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 16 deletions(-) create mode 100644 grapher/Models/Options/OffsetOptions.cs (limited to 'grapher/Models') 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; + } + } +} -- cgit v1.2.3