summaryrefslogtreecommitdiff
path: root/grapher/Models
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
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')
-rw-r--r--grapher/Models/AccelGUI.cs12
-rw-r--r--grapher/Models/Serialized/DriverSettings.cs29
-rw-r--r--grapher/Models/Serialized/SettingsManager.cs24
3 files changed, 38 insertions, 27 deletions
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<double>
@@ -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<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()
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;