diff options
| author | a1xd <[email protected]> | 2020-09-25 18:46:04 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-09-25 18:46:04 -0400 |
| commit | fd184b6ffeaf5b1d1dceb7de58a8ebb7c3d8c760 (patch) | |
| tree | 4e00b478ac1d888c50beaa782733cf52c61d038b /grapher/Models/Serialized | |
| parent | Merge pull request #22 from JacobPalecki/GUI (diff) | |
| download | rawaccel-fd184b6ffeaf5b1d1dceb7de58a8ebb7c3d8c760.tar.xz rawaccel-fd184b6ffeaf5b1d1dceb7de58a8ebb7c3d8c760.zip | |
add initial writer
move managed settings into wrapper
move gui build into driver build dir
Diffstat (limited to 'grapher/Models/Serialized')
| -rw-r--r-- | grapher/Models/Serialized/DriverSettings.cs | 117 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 41 |
2 files changed, 23 insertions, 135 deletions
diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs deleted file mode 100644 index 5f9307c..0000000 --- a/grapher/Models/Serialized/DriverSettings.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Threading; - -namespace grapher.Models.Serialized -{ - #region Enumerations - - public enum AccelMode - { - linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel - } - - #endregion Enumerations - - #region Structs - - [StructLayout(LayoutKind.Sequential)] - public struct AccelArgs - { - public double offset; - public double legacy_offset; - public double accel; - public double limit; - public double exponent; - public double midpoint; - public double powerScale; - public double powerExponent; - public double weight; - public double rate; - public double scaleCap; - public double gainCap; - }; - - [StructLayout(LayoutKind.Sequential)] - public struct Vec2 <T> - { - public T x; - public T y; - } - - #endregion Structs - - [StructLayout(LayoutKind.Sequential)] - [Serializable] - public class DriverSettings - { - #region Fields - - private static readonly IntPtr UnmanagedSettingsHandle = - Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>()); - private static object UnmanagedSettingsLock = new object(); - - public double rotation; - public bool combineMagnitudes; - public Vec2<AccelMode> modes; - public Vec2<AccelArgs> args; - public Vec2<double> sensitivity; - public double minimumTime; - - #endregion Fields - - #region Methods - - public static DriverSettings GetActive() - { - DriverInterop.GetActiveSettings(UnmanagedSettingsHandle); - return Marshal.PtrToStructure<DriverSettings>(UnmanagedSettingsHandle); - } - - public static void SetActive(DriverSettings settings, Action<IntPtr> unmanagedActionBefore = null) - { - new Thread(() => - { - lock (UnmanagedSettingsLock) - { - Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false); - unmanagedActionBefore?.Invoke(UnmanagedSettingsHandle); - DriverInterop.SetActiveSettings(UnmanagedSettingsHandle); - } - }).Start(); - - } - - public void SendToDriver(Action<IntPtr> unmanagedActionBefore = null) - { - SetActive(this, unmanagedActionBefore); - } - - public void SendToDriverAndUpdate(ManagedAccel accel, Action betweenAccelAndWrite = null) - { - SendToDriver(settingsHandle => - { - accel.UpdateFromSettings(settingsHandle); - betweenAccelAndWrite?.Invoke(); - }); - } - - public bool verify() - { - /* - if (args.accel < 0 || args.rate < 0) - bad_arg("accel can not be negative, use a negative weight to compensate"); - if (args.rate > 1) bad_arg("rate can not be greater than 1"); - if (args.exponent <= 1) bad_arg("exponent must be greater than 1"); - if (args.limit <= 1) bad_arg("limit must be greater than 1"); - if (args.power_scale <= 0) bad_arg("scale must be positive"); - if (args.power_exp <= 0) bad_arg("exponent must be positive"); - if (args.midpoint < 0) bad_arg("midpoint must not be negative"); - if (args.time_min <= 0) bad_arg("min time must be positive"); - */ - return true; - } - - #endregion Methods - } -} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index cac2bd0..26160f5 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using System; using System.Windows.Forms; +using System.Threading; namespace grapher.Models.Serialized { @@ -46,29 +47,28 @@ namespace grapher.Models.Serialized #region Methods - public void UpdateActiveSettings(DriverSettings settings, Action afterAccelSettingsUpdate = null) + public void UpdateActiveSettings(DriverSettings settings) { - settings.SendToDriverAndUpdate(ActiveAccel, () => - { - RawAccelSettings.AccelerationSettings = settings; - RawAccelSettings.GUISettings = new GUISettings - { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data, - ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, - }; + ActiveAccel.UpdateFromSettings(settings); + SendToDriver(settings); - RawAccelSettings.Save(); + RawAccelSettings.AccelerationSettings = settings; + RawAccelSettings.GUISettings = new GUISettings + { + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data, + ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, + ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, + }; - afterAccelSettingsUpdate?.Invoke(); - }); + RawAccelSettings.Save(); } public void UpdateActiveAccelFromFileSettings(DriverSettings settings) - { - settings.SendToDriverAndUpdate(ActiveAccel); + { + ActiveAccel.UpdateFromSettings(settings); + SendToDriver(settings); DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); @@ -77,6 +77,11 @@ namespace grapher.Models.Serialized ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; } + public static void SendToDriver(DriverSettings settings) + { + new Thread(() => DriverInterop.SetActiveSettings(settings)).Start(); + } + public void Startup() { if (RawAccelSettings.Exists()) @@ -97,7 +102,7 @@ namespace grapher.Models.Serialized } RawAccelSettings = new RawAccelSettings( - DriverSettings.GetActive(), + DriverInterop.GetActiveSettings(), new GUISettings { AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, |