diff options
| author | JacobPalecki <[email protected]> | 2020-08-31 23:03:46 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-31 23:03:46 -0700 |
| commit | 471fe599bab6ba0632ddd1dacd20c7fc42db0eee (patch) | |
| tree | 90a82ee14dbb112621657efbd2523ed35f59d154 /grapher | |
| parent | Merge pull request #16 from JacobPalecki/Misc (diff) | |
| parent | add independent xy accel to driver (diff) | |
| download | rawaccel-471fe599bab6ba0632ddd1dacd20c7fc42db0eee.tar.xz rawaccel-471fe599bab6ba0632ddd1dacd20c7fc42db0eee.zip | |
Merge pull request #17 from a1xd/indep
Indep
Diffstat (limited to 'grapher')
| -rw-r--r-- | grapher/Form1.cs | 77 | ||||
| -rw-r--r-- | grapher/Layouts/ClassicLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Layouts/DefaultLayout.cs | 6 | ||||
| -rw-r--r-- | grapher/Layouts/LayoutBase.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/LinearLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Layouts/LogLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Layouts/NaturalGainLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Layouts/NaturalLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Layouts/OffLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Layouts/PowerLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Layouts/SigmoidGainLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Layouts/SigmoidLayout.cs | 5 | ||||
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 72 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelCalculator.cs | 11 | ||||
| -rw-r--r-- | grapher/Models/Options/AccelOptions.cs | 5 | ||||
| -rw-r--r-- | grapher/Models/Serialized/DriverSettings.cs | 87 | ||||
| -rw-r--r-- | grapher/Models/Serialized/ModifierArgs.cs | 75 | ||||
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 25 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 115 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 29 |
20 files changed, 256 insertions, 293 deletions
diff --git a/grapher/Form1.cs b/grapher/Form1.cs index d6f7990..37f67f8 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -15,48 +15,6 @@ using grapher.Models.Serialized; namespace grapher { - public enum accel_mode - { - linear=1, classic, natural, logarithmic, sigmoid, power, naturalgain, sigmoidgain, noaccel - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public struct vec2d - { - public double x; - public double y; - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public struct accel_args - { - public double offset; - public double accel; - public double limit; - public double exponent; - public double midpoint; - public double power_scale; - public double gain_cap; - public vec2d weight; - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public struct accel_fn_args - { - public accel_args acc_args; - public int accel_mode; - public double time_min; - public vec2d cap; - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public struct modifier_args - { - public double degrees; - public vec2d sens; - public accel_fn_args acc_fn_args; - } - public partial class RawAcceleration : Form { @@ -66,32 +24,17 @@ namespace grapher public RawAcceleration() { InitializeComponent(); - modifier_args args; - - args.degrees = 0; - args.sens.x = 1; - args.sens.y = 1; - args.acc_fn_args.acc_args.offset = 0; - args.acc_fn_args.acc_args.accel = 0.01; - args.acc_fn_args.acc_args.limit = 2; - args.acc_fn_args.acc_args.exponent = 1; - args.acc_fn_args.acc_args.midpoint = 0; - args.acc_fn_args.acc_args.power_scale = 1; - args.acc_fn_args.acc_args.weight.x = 1; - args.acc_fn_args.acc_args.weight.y = 1; - args.acc_fn_args.acc_args.gain_cap = 0; - args.acc_fn_args.accel_mode = (int)accel_mode.natural; - args.acc_fn_args.time_min = 0.4; - args.acc_fn_args.cap.x = 0; - args.acc_fn_args.cap.y = 0; - - IntPtr args_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(args)); - Marshal.StructureToPtr(args, args_ptr, false); - var managedAcceleration = new ManagedAccel(args_ptr); - - Marshal.FreeHGlobal(args_ptr); + ManagedAccel activeAccel = null; + try + { + activeAccel = ManagedAccel.GetActiveAccel(); + } + catch (DriverNotInstalledException) + { + throw; + } var accelCharts = new AccelCharts( this, @@ -205,7 +148,7 @@ namespace grapher new Field(PollRateTextBox.TextBox, this, AccelCalculator.DefaultPollRate)); var settings = new SettingsManager( - managedAcceleration, + activeAccel, accelCalculator.DPI, accelCalculator.PollRate, AutoWriteMenuItem); diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs index 093f7fa..05f6c82 100644 --- a/grapher/Layouts/ClassicLayout.cs +++ b/grapher/Layouts/ClassicLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "Classic"; - Index = 2; + Index = (int)AccelMode.classic; ShowOptions = new bool[] { true, true, true, false }; OptionNames = new string[] { Offset, Acceleration, Exponent, string.Empty }; } diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs index 095afdf..42841d5 100644 --- a/grapher/Layouts/DefaultLayout.cs +++ b/grapher/Layouts/DefaultLayout.cs @@ -1,10 +1,12 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; + namespace grapher.Layouts { public class DefaultLayout : LayoutBase @@ -13,7 +15,7 @@ namespace grapher.Layouts : base() { Name = "Default"; - Index = 0; + Index = (int)AccelMode.noaccel; ShowOptions = new bool[] { true, true, true, true }; OptionNames = new string[] { Offset, Acceleration, $"{Limit}\\{Exponent}", Midpoint }; ButtonEnabled = false; diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs index a4d0827..3ae2e90 100644 --- a/grapher/Layouts/LayoutBase.cs +++ b/grapher/Layouts/LayoutBase.cs @@ -26,7 +26,7 @@ namespace grapher.Layouts /// <summary> /// Gets or sets mapping from acceleration type to identifying integer. - /// Must match order in tagged_union in rawaccel.hpp (which is 1-indexed, meaning 0 is off.) + /// Must match accel_mode defined in rawaccel-settings.h /// </summary> public int Index { get; internal set; } diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs index 2a0358e..0a79a64 100644 --- a/grapher/Layouts/LinearLayout.cs +++ b/grapher/Layouts/LinearLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "Linear"; - Index = 1; + Index = (int)AccelMode.linear; ShowOptions = new bool[] { true, true, false, false }; OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty }; } diff --git a/grapher/Layouts/LogLayout.cs b/grapher/Layouts/LogLayout.cs index ae1a8f5..1206fb3 100644 --- a/grapher/Layouts/LogLayout.cs +++ b/grapher/Layouts/LogLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "Logarithmic"; - Index = 4; + Index = (int)AccelMode.logarithmic; ShowOptions = new bool[] { true, true, false, false }; OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty }; } diff --git a/grapher/Layouts/NaturalGainLayout.cs b/grapher/Layouts/NaturalGainLayout.cs index e062850..9bb1ec8 100644 --- a/grapher/Layouts/NaturalGainLayout.cs +++ b/grapher/Layouts/NaturalGainLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "NaturalGain"; - Index = 7; + Index = (int)AccelMode.naturalgain; ShowOptions = new bool[] { true, true, true, false }; OptionNames = new string[] { Offset, Acceleration, Limit, string.Empty }; } diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs index 743135c..44c6c18 100644 --- a/grapher/Layouts/NaturalLayout.cs +++ b/grapher/Layouts/NaturalLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "Natural"; - Index = 3; + Index = (int)AccelMode.natural; ShowOptions = new bool[] { true, true, true, false }; OptionNames = new string[] { Offset, Acceleration, Limit, string.Empty }; } diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs index 087885f..ce7c149 100644 --- a/grapher/Layouts/OffLayout.cs +++ b/grapher/Layouts/OffLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "Off"; - Index = 9; + Index = (int)AccelMode.noaccel; ShowOptions = new bool[] { false, false, false, false }; OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty }; ShowOptionsXY = new bool[] { false, false }; diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs index da02cf5..c14083a 100644 --- a/grapher/Layouts/PowerLayout.cs +++ b/grapher/Layouts/PowerLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "Power"; - Index = 6; + Index = (int)AccelMode.power; ShowOptions = new bool[] { true, true, true, false }; OptionNames = new string[] { Offset, Scale, Exponent, string.Empty }; } diff --git a/grapher/Layouts/SigmoidGainLayout.cs b/grapher/Layouts/SigmoidGainLayout.cs index c620925..93214ec 100644 --- a/grapher/Layouts/SigmoidGainLayout.cs +++ b/grapher/Layouts/SigmoidGainLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "SigmoidGain"; - Index = 8; + Index = (int)AccelMode.sigmoidgain; ShowOptions = new bool[] { true, true, true, true }; OptionNames = new string[] { Offset, Acceleration, Limit, Midpoint }; } diff --git a/grapher/Layouts/SigmoidLayout.cs b/grapher/Layouts/SigmoidLayout.cs index 0dec3bf..1c7f0b9 100644 --- a/grapher/Layouts/SigmoidLayout.cs +++ b/grapher/Layouts/SigmoidLayout.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "Sigmoid"; - Index = 5; + Index = (int)AccelMode.sigmoid; ShowOptions = new bool[] { true, true, true, true }; OptionNames = new string[] { Offset, Acceleration, Limit, Midpoint }; } diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index e0dcc03..a15dba8 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -2,6 +2,7 @@ using grapher.Models.Mouse; using grapher.Models.Serialized; using System; +using System.CodeDom; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -101,41 +102,64 @@ namespace grapher public void UpdateActiveSettingsFromFields() { - Settings.UpdateActiveSettings( - AccelerationOptions.AccelerationIndex, - Rotation.Field.Data, - Sensitivity.Fields.X, - Sensitivity.Fields.Y, - Weight.Fields.X, - Weight.Fields.Y, - Cap.SensitivityCapX, - Cap.SensitivityCapY, - Offset.Field.Data, - Acceleration.Field.Data, - LimitOrExponent.Field.Data, - Midpoint.Field.Data, - Cap.VelocityGainCap); + Settings.UpdateActiveSettings(new DriverSettings + { + rotation = Rotation.Field.Data, + sensitivity = new Vec2<double> + { + x = Sensitivity.Fields.X, + y = Sensitivity.Fields.Y + }, + combineMagnitudes = true, + modes = new Vec2<AccelMode> + { + x = (AccelMode)AccelerationOptions.AccelerationIndex + }, + args = new Vec2<AccelArgs> + { + x = new AccelArgs + { + offset = Offset.Field.Data, + weight = Weight.Fields.X, + gainCap = Cap.VelocityGainCap, + scaleCap = Cap.SensitivityCapX, + accel = Acceleration.Field.Data, + rate = Acceleration.Field.Data, + powerScale = Acceleration.Field.Data, + limit = LimitOrExponent.Field.Data, + exponent = LimitOrExponent.Field.Data, + powerExponent = LimitOrExponent.Field.Data, + midpoint = Midpoint.Field.Data + } + }, + minimumTime = .4 + }); UpdateGraph(); } public void UpdateGraph() { - AccelCalculator.Calculate(AccelCharts.AccelData, Settings.ActiveAccel); + AccelCalculator.Calculate( + AccelCharts.AccelData, + Settings.ActiveAccel, + Settings.RawAccelSettings.AccelerationSettings); AccelCharts.Bind(); UpdateActiveValueLabels(); } public void UpdateActiveValueLabels() { - Sensitivity.SetActiveValues(Settings.ActiveAccel.SensitivityX, Settings.ActiveAccel.SensitivityY); - Rotation.SetActiveValue(Settings.ActiveAccel.Rotation); - AccelerationOptions.SetActiveValue(Settings.ActiveAccel.Type); - Offset.SetActiveValue(Settings.ActiveAccel.Offset); - Acceleration.SetActiveValue(Settings.ActiveAccel.Acceleration); - Cap.SetActiveValues(Settings.ActiveAccel.GainCap, Settings.ActiveAccel.CapX, Settings.ActiveAccel.CapY, Settings.ActiveAccel.GainCapEnabled); - Weight.SetActiveValues(Settings.ActiveAccel.WeightX, Settings.ActiveAccel.WeightY); - LimitOrExponent.SetActiveValue(Settings.ActiveAccel.LimitExp); - Midpoint.SetActiveValue(Settings.ActiveAccel.Midpoint); + var settings = Settings.RawAccelSettings.AccelerationSettings; + + Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y); + Rotation.SetActiveValue(settings.rotation); + AccelerationOptions.SetActiveValue((int)settings.modes.x); + Offset.SetActiveValue(settings.args.x.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 + Midpoint.SetActiveValue(settings.args.x.midpoint); + //Cap.SetActiveValues(Settings.ActiveAccel.GainCap, Settings.ActiveAccel.CapX, Settings.ActiveAccel.CapY, Settings.ActiveAccel.GainCapEnabled); } private void OnScaleMenuItemClick(object sender, EventArgs e) diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 63ed281..102de8d 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -46,15 +47,15 @@ namespace grapher.Models.Calculations private int Increment { get; set; } - public void Calculate(AccelData data, ManagedAccel accel) + public void Calculate(AccelData data, ManagedAccel accel, DriverSettings settings) { ScaleByMouseSettings(); data.Clear(); - Calculate(data.Combined, accel, accel.SensitivityX, MagnitudesCombined); - Calculate(data.X, accel, accel.SensitivityX, MagnitudesX); - Calculate(data.Y, accel, accel.SensitivityY, MagnitudesY); + Calculate(data.Combined, accel, settings.sensitivity.x, MagnitudesCombined); + Calculate(data.X, accel, settings.sensitivity.x, MagnitudesX); + Calculate(data.Y, accel, settings.sensitivity.y, MagnitudesY); } public static void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection<MagnitudeData> magnitudeData) diff --git a/grapher/Models/Options/AccelOptions.cs b/grapher/Models/Options/AccelOptions.cs index cd7c4e5..6b98274 100644 --- a/grapher/Models/Options/AccelOptions.cs +++ b/grapher/Models/Options/AccelOptions.cs @@ -16,7 +16,6 @@ namespace grapher public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase> { - new DefaultLayout(), new LinearLayout(), new ClassicLayout(), new NaturalLayout(), @@ -37,7 +36,7 @@ namespace grapher { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); - AccelDropdown.Items.AddRange(AccelerationTypes.Keys.Skip(1).ToArray()); + AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray()); AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); if (options.Length > PossibleOptionsCount) @@ -55,7 +54,7 @@ namespace grapher WriteButton = writeButton; ActiveValueLabel = activeValueLabel; - Layout("Default"); + Layout("Off"); } public Button WriteButton { get; } diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs new file mode 100644 index 0000000..91d7e9f --- /dev/null +++ b/grapher/Models/Serialized/DriverSettings.cs @@ -0,0 +1,87 @@ +using System; +using System.Runtime.InteropServices; + +namespace grapher.Models.Serialized +{ + public enum AccelMode + { + linear, classic, natural, logarithmic, sigmoid, naturalgain, sigmoidgain, power, noaccel + } + + [StructLayout(LayoutKind.Sequential)] + public struct AccelArgs + { + public double 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; + } + + [StructLayout(LayoutKind.Sequential)] + [Serializable] + public class DriverSettings + { + private static readonly IntPtr UnmanagedSettingsHandle = + Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>()); + + public double rotation; + public bool combineMagnitudes; + public Vec2<AccelMode> modes; + public Vec2<AccelArgs> args; + public Vec2<double> sensitivity; + public double minimumTime; + + public static DriverSettings GetActive() + { + DriverInterop.GetActiveSettings(UnmanagedSettingsHandle); + return Marshal.PtrToStructure<DriverSettings>(UnmanagedSettingsHandle); + } + + public static void SetActive(DriverSettings settings) + { + Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false); + DriverInterop.SetActiveSettings(UnmanagedSettingsHandle); + } + + public void SendToDriver() + { + SetActive(this); + } + + public void SendToDriverAndUpdate(ManagedAccel accel) + { + SendToDriver(); + accel.UpdateFromSettings(UnmanagedSettingsHandle); + } + + 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; + } + } +} diff --git a/grapher/Models/Serialized/ModifierArgs.cs b/grapher/Models/Serialized/ModifierArgs.cs deleted file mode 100644 index 206a3c9..0000000 --- a/grapher/Models/Serialized/ModifierArgs.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace grapher.Models.Serialized -{ - public enum accel_mode - { - linear=1, classic, natural, logarithmic, sigmoid, power, naturalgain, sigmoidgain, noaccel - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - [Serializable] - public struct vec2d - { - public double x; - public double y; - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - [Serializable] - public struct accel_args - { - public double offset; - public double accel; - public double limit; - public double exponent; - public double midpoint; - public double power_scale; - public double gain_cap; - public vec2d weight; - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - [Serializable] - public struct accel_fn_args - { - public accel_args acc_args; - public int accel_mode; - public double time_min; - public vec2d cap; - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - [Serializable] - public struct modifier_args - { - public double degrees; - public vec2d sens; - public accel_fn_args acc_fn_args; - - public modifier_args(ManagedAccel managedAccel) - { - degrees = managedAccel.Rotation; - sens.x = managedAccel.SensitivityX; - sens.y = managedAccel.SensitivityY; - acc_fn_args.accel_mode = managedAccel.Type; - acc_fn_args.time_min = managedAccel.MinimumTime; - acc_fn_args.cap.x = managedAccel.CapX; - acc_fn_args.cap.y = managedAccel.CapY; - acc_fn_args.acc_args.accel = managedAccel.Acceleration; - acc_fn_args.acc_args.exponent = managedAccel.LimitExp; - acc_fn_args.acc_args.gain_cap = managedAccel.GainCap; - acc_fn_args.acc_args.limit = managedAccel.LimitExp; - acc_fn_args.acc_args.midpoint = managedAccel.Midpoint; - acc_fn_args.acc_args.offset = managedAccel.Offset; - acc_fn_args.acc_args.power_scale = managedAccel.PowerScale; - acc_fn_args.acc_args.weight.x = managedAccel.WeightX; - acc_fn_args.acc_args.weight.y = managedAccel.WeightY; - } - } -} diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 21a7f0c..7aed917 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -24,17 +24,16 @@ namespace grapher.Models.Serialized public RawAccelSettings() { } public RawAccelSettings( - ManagedAccel managedAccel, + DriverSettings accelSettings, GUISettings guiSettings) { - AccelerationSettings = new modifier_args(managedAccel); + AccelerationSettings = accelSettings; GUISettings = guiSettings; } - public GUISettings GUISettings { get; set; } - public modifier_args AccelerationSettings { get; set; } + public DriverSettings AccelerationSettings { get; set; } public static RawAccelSettings Load() { @@ -42,23 +41,19 @@ namespace grapher.Models.Serialized } public static RawAccelSettings Load(string file) - { - if (!Exists(file)) + { + try { - throw new Exception($"Settings file does not exist at {file}"); + return JsonConvert.DeserializeObject<RawAccelSettings>(File.ReadAllText(file), SerializerSettings); } - - RawAccelSettings deserializedSettings; - try + catch (FileNotFoundException e) { - deserializedSettings = JsonConvert.DeserializeObject<RawAccelSettings>(File.ReadAllText(file), SerializerSettings); + throw new FileNotFoundException($"Settings file does not exist at {file}", e); } - catch(Exception e) + catch (JsonSerializationException e) { - throw new Exception($"Settings file at {file} does not contain valid Raw Accel Settings.", e); + throw new JsonSerializationException($"Settings file at {file} does not contain valid Raw Accel Settings.", e); } - - return deserializedSettings; } public static bool Exists() diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 848606d..fc58387 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using Newtonsoft.Json; +using System; using System.Windows.Forms; namespace grapher.Models.Serialized @@ -32,63 +28,38 @@ namespace grapher.Models.Serialized private ToolStripMenuItem AutoWriteMenuItem { get; set; } - public void UpdateActiveSettings( - int mode, - double degrees, - double sensitivityX, - double sensitivityY, - double weightX, - double weightY, - double capX, - double capY, - double offset, - double accel, - double limitOrExp, - double midpoint, - double gainCap) + public void UpdateActiveSettings(DriverSettings settings) { - ActiveAccel.UpdateAccel( - mode, - degrees, - sensitivityX, - sensitivityY, - weightX, - weightY, - capX, - capY, - offset, - accel, - limitOrExp, - midpoint, - gainCap); + try + { + settings.SendToDriverAndUpdate(ActiveAccel); - RawAccelSettings.AccelerationSettings = new modifier_args(ActiveAccel); - RawAccelSettings.GUISettings = new GUISettings + RawAccelSettings.AccelerationSettings = settings; + RawAccelSettings.GUISettings = new GUISettings { AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, DPI = (int)DpiField.Data, PollRate = (int)PollRateField.Data }; - RawAccelSettings.Save(); + RawAccelSettings.Save(); + } + catch (DriverWriteCDException) + { + Console.WriteLine("write on cooldown"); + } } - public void UpdateActiveAccelFromFileSettings() + public void UpdateActiveAccelFromFileSettings(DriverSettings settings) { - ActiveAccel.UpdateAccel( - RawAccelSettings.AccelerationSettings.acc_fn_args.accel_mode, - RawAccelSettings.AccelerationSettings.degrees, - RawAccelSettings.AccelerationSettings.sens.x, - RawAccelSettings.AccelerationSettings.sens.y, - RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.weight.x, - RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.weight.y, - RawAccelSettings.AccelerationSettings.acc_fn_args.cap.x, - RawAccelSettings.AccelerationSettings.acc_fn_args.cap.y, - RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.offset, - RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.accel, - RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.exponent, - RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.midpoint, - RawAccelSettings.AccelerationSettings.acc_fn_args.acc_args.gain_cap); + try + { + settings.SendToDriverAndUpdate(ActiveAccel); + } + catch (DriverWriteCDException) + { + Console.WriteLine("write on cd during file init"); + } DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; @@ -96,28 +67,32 @@ namespace grapher.Models.Serialized public void Startup() { - ActiveAccel.ReadFromDriver(); - - if(RawAccelSettings.Exists()) + if (RawAccelSettings.Exists()) { - RawAccelSettings = RawAccelSettings.Load(); - if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) + try { - UpdateActiveAccelFromFileSettings(); - } - } - else - { - RawAccelSettings = new RawAccelSettings( - ActiveAccel, - new GUISettings + RawAccelSettings = RawAccelSettings.Load(); + if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data - }); - RawAccelSettings.Save(); + UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); + } + return; + } + catch (JsonSerializationException e) + { + Console.WriteLine($"bad settings: {e}"); + } } + + RawAccelSettings = new RawAccelSettings( + DriverSettings.GetActive(), + new GUISettings + { + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data + }); + RawAccelSettings.Save(); } } } diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 6e03ae0..d34e678 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -13,24 +13,27 @@ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <Deterministic>true</Deterministic> </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <PlatformTarget>x64</PlatformTarget> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> + <OutputPath>bin\x64\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>x64</PlatformTarget> + <LangVersion>7.3</LangVersion> <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <PlatformTarget>x64</PlatformTarget> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + <OutputPath>bin\x64\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> + <Optimize>true</Optimize> + <DebugType>pdbonly</DebugType> + <PlatformTarget>x64</PlatformTarget> + <LangVersion>7.3</LangVersion> <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> </PropertyGroup> <ItemGroup> <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> @@ -85,7 +88,7 @@ <Compile Include="Models\Options\Option.cs" /> <Compile Include="Models\Options\OptionXY.cs" /> <Compile Include="Models\Serialized\GUISettings.cs" /> - <Compile Include="Models\Serialized\ModifierArgs.cs" /> + <Compile Include="Models\Serialized\DriverSettings.cs" /> <Compile Include="Models\Serialized\RawAccelSettings.cs" /> <Compile Include="Models\Serialized\SettingsManager.cs" /> <Compile Include="Program.cs" /> |