summaryrefslogtreecommitdiff
path: root/grapher/Models/Serialized/DriverSettings.cs
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-09-02 16:19:11 -0700
committerJacob Palecki <[email protected]>2020-09-02 16:19:11 -0700
commit6b5fdf4e593c056df13de325fea7b6b35fbb750e (patch)
tree7f53e3be86a17097aafad43738a34e7c665cfcd0 /grapher/Models/Serialized/DriverSettings.cs
parentMerge pull request #1 from Sidiouth/sidi (diff)
parentMerge pull request #18 from a1xd/write-delay (diff)
downloadrawaccel-6b5fdf4e593c056df13de325fea7b6b35fbb750e.tar.xz
rawaccel-6b5fdf4e593c056df13de325fea7b6b35fbb750e.zip
Merge remote-tracking branch 'upstream/master' into master
Diffstat (limited to 'grapher/Models/Serialized/DriverSettings.cs')
-rw-r--r--grapher/Models/Serialized/DriverSettings.cs29
1 files changed, 21 insertions, 8 deletions
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<DriverSettings>());
+ private static object UnmanagedSettingsLock = new object();
public double rotation;
public bool combineMagnitudes;
@@ -51,21 +53,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()