diff options
| author | Jacob Palecki <[email protected]> | 2020-09-04 01:15:12 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-04 01:15:12 -0700 |
| commit | 87ee655d3c0ba3cdb0ca71a1b66aeb02c8c6aa70 (patch) | |
| tree | a2ca5c42352737e3dab48ec854c1cd068a282e46 /grapher/Models/Serialized | |
| parent | The menus mostly work (diff) | |
| parent | Merge pull request #19 from JacobPalecki/gainOffset (diff) | |
| download | rawaccel-87ee655d3c0ba3cdb0ca71a1b66aeb02c8c6aa70.tar.xz rawaccel-87ee655d3c0ba3cdb0ca71a1b66aeb02c8c6aa70.zip | |
Merge with master
Diffstat (limited to 'grapher/Models/Serialized')
| -rw-r--r-- | grapher/Models/Serialized/DriverSettings.cs | 30 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 24 |
2 files changed, 29 insertions, 25 deletions
diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs index e0b5d4a..ecd4d51 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 { @@ -18,6 +19,7 @@ namespace grapher.Models.Serialized public struct AccelArgs { public double offset; + public double legacy_offset; public double accel; public double limit; public double exponent; @@ -47,6 +49,7 @@ namespace grapher.Models.Serialized private static readonly IntPtr UnmanagedSettingsHandle = Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>()); + private static object UnmanagedSettingsLock = new object(); public double rotation; public bool combineMagnitudes; @@ -65,21 +68,32 @@ namespace grapher.Models.Serialized return Marshal.PtrToStructure<DriverSettings>(UnmanagedSettingsHandle); } - public static void SetActive(DriverSettings settings) + public static void SetActive(DriverSettings settings, Action<IntPtr> 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<IntPtr> 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 7f018cf..d7cf590 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -38,12 +38,10 @@ namespace grapher.Models.Serialized #region Methods - 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 { @@ -53,23 +51,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; |