diff options
| author | a1xd <[email protected]> | 2021-07-05 23:33:41 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-07-05 23:33:41 -0400 |
| commit | 31efc792f5895d7ef3533390875de3c480add996 (patch) | |
| tree | 8db5b16a88f50448cb525ba8ae56801985294f63 /grapher/Models | |
| parent | Merge pull request #87 from matthewstrasiotto/streamer_mode (diff) | |
| parent | Handle power\exponent correctly in GUI (diff) | |
| download | rawaccel-31efc792f5895d7ef3533390875de3c480add996.tar.xz rawaccel-31efc792f5895d7ef3533390875de3c480add996.zip | |
merge lut2
Diffstat (limited to 'grapher/Models')
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 147 | ||||
| -rw-r--r-- | grapher/Models/AccelGUIFactory.cs | 73 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelCalculator.cs | 170 | ||||
| -rw-r--r-- | grapher/Models/Mouse/MouseWatcher.cs | 4 | ||||
| -rw-r--r-- | grapher/Models/Options/AccelOptionSet.cs | 12 | ||||
| -rw-r--r-- | grapher/Models/Options/AccelTypeOptions.cs | 265 | ||||
| -rw-r--r-- | grapher/Models/Options/ApplyOptions.cs | 61 | ||||
| -rw-r--r-- | grapher/Models/Options/CapOptions.cs | 225 | ||||
| -rw-r--r-- | grapher/Models/Options/CheckBoxOption.cs | 109 | ||||
| -rw-r--r-- | grapher/Models/Options/LUT/LUTPanelOptions.cs | 217 | ||||
| -rw-r--r-- | grapher/Models/Options/LUT/LUTPointOption.cs | 39 | ||||
| -rw-r--r-- | grapher/Models/Options/LUT/LutApplyOptions.cs | 183 | ||||
| -rw-r--r-- | grapher/Models/Options/OffsetOptions.cs | 5 | ||||
| -rw-r--r-- | grapher/Models/Options/TextOption.cs | 129 | ||||
| -rw-r--r-- | grapher/Models/Serialized/GUISettings.cs | 27 | ||||
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 141 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 139 |
17 files changed, 1250 insertions, 696 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 3a30a9b..9ca7fed 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -32,7 +32,7 @@ namespace grapher AccelCharts = accelCharts; ApplyOptions = applyOptions; WriteButton = writeButton; - ToggleButton = (CheckBox)toggleButton; + DisableButton = (CheckBox)toggleButton; ScaleMenuItem = scaleMenuItem; Settings = settings; DefaultButtonFont = WriteButton.Font; @@ -42,34 +42,17 @@ namespace grapher ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); WriteButton.Click += new System.EventHandler(OnWriteButtonClick); - ToggleButton.Click += new System.EventHandler(OnToggleButtonClick); + DisableButton.Click += new System.EventHandler(DisableDriverEventHandler); AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose); - ButtonTimerInterval = Convert.ToInt32(DriverInterop.WriteDelayMs); + ButtonTimerInterval = Convert.ToInt32(DriverSettings.WriteDelayMs); ButtonTimer = new Timer(); ButtonTimer.Tick += new System.EventHandler(OnButtonTimerTick); ChartRefresh = SetupChartTimer(); - bool settingsActive = Settings.Startup(); - SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent(); - - if (settingsActive) - { - LastToggleChecked = SettingsNotDefault; - ToggleButton.Enabled = LastToggleChecked; - RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); - } - else - { - DriverSettings active = DriverInterop.GetActiveSettings(); - bool activeNotDefault = !RawAccelSettings.IsDefaultEquivalent(active); - - LastToggleChecked = activeNotDefault; - ToggleButton.Enabled = SettingsNotDefault || activeNotDefault; - RefreshOnRead(active); - } - + RefreshUser(); + RefreshActive(); SetupButtons(); // TODO: The below removes an overlapping form from the anisotropy panel. @@ -94,7 +77,7 @@ namespace grapher public Button WriteButton { get; } - public CheckBox ToggleButton { get; } + public CheckBox DisableButton { get; } public Timer ButtonTimer { get; } @@ -104,8 +87,6 @@ namespace grapher public DeviceIDManager DeviceIDManager { get; } - public Action UpdateInputManagers { get; private set; } - private Timer ChartRefresh { get; } private Font SmallButtonFont { get; } @@ -125,47 +106,36 @@ namespace grapher private void SaveGUISettingsOnClose(Object sender, FormClosingEventArgs e) { var guiSettings = Settings.MakeGUISettingsFromFields(); - if (!Settings.RawAccelSettings.GUISettings.Equals(guiSettings)) + if (!Settings.GuiSettings.Equals(guiSettings)) { - Settings.RawAccelSettings.GUISettings = guiSettings; - Settings.RawAccelSettings.Save(); + guiSettings.Save(); } } public void UpdateActiveSettingsFromFields() { - var driverSettings = Settings.RawAccelSettings.AccelerationSettings; + var settings = new DriverSettings(); - var newArgs = ApplyOptions.GetArgs(); - newArgs.x.speedCap = driverSettings.args.x.speedCap; - newArgs.y.speedCap = driverSettings.args.y.speedCap; - - var settings = new DriverSettings + settings.rotation = ApplyOptions.Rotation.Field.Data; + settings.sensitivity = new Vec2<double> { - rotation = ApplyOptions.Rotation.Field.Data, - snap = driverSettings.snap, - sensitivity = new Vec2<double> - { - x = ApplyOptions.Sensitivity.Fields.X, - y = ApplyOptions.Sensitivity.Fields.Y - }, - combineMagnitudes = ApplyOptions.IsWhole, - modes = ApplyOptions.GetModes(), - args = newArgs, - minimumTime = driverSettings.minimumTime, - directionalMultipliers = driverSettings.directionalMultipliers, - domainArgs = ApplyOptions.Directionality.GetDomainArgs(), - rangeXY = ApplyOptions.Directionality.GetRangeXY(), - deviceID = DeviceIDManager.ID, + x = ApplyOptions.Sensitivity.Fields.X, + y = ApplyOptions.Sensitivity.Fields.Y }; + settings.combineMagnitudes = ApplyOptions.IsWhole; + ApplyOptions.SetArgs(ref settings.args); + settings.domainArgs = ApplyOptions.Directionality.GetDomainArgs(); + settings.rangeXY = ApplyOptions.Directionality.GetRangeXY(); + settings.deviceID = DeviceIDManager.ID; + + Settings.SetHiddenOptions(settings); ButtonDelay(WriteButton); - SettingsErrors errors = Settings.TryUpdateActiveSettings(settings); + + SettingsErrors errors = Settings.TryActivate(settings); if (errors.Empty()) { - SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent(); - LastToggleChecked = SettingsNotDefault; - RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); + RefreshActive(); } else { @@ -173,25 +143,29 @@ namespace grapher } } - public void RefreshOnRead(DriverSettings args) + public void UpdateInputManagers() { - UpdateShownActiveValues(args); - UpdateGraph(args); - - UpdateInputManagers = () => - { - MouseWatcher.UpdateHandles(args.deviceID); - DeviceIDManager.Update(args.deviceID); - }; + MouseWatcher.UpdateHandles(Settings.ActiveSettings.baseSettings.deviceID); + DeviceIDManager.Update(Settings.ActiveSettings.baseSettings.deviceID); + } + public void RefreshActive() + { + UpdateShownActiveValues(Settings.UserSettings); + UpdateGraph(); UpdateInputManagers(); } - public void UpdateGraph(DriverSettings args) + public void RefreshUser() + { + UpdateShownActiveValues(Settings.UserSettings); + } + + public void UpdateGraph() { AccelCharts.Calculate( Settings.ActiveAccel, - args); + Settings.ActiveSettings.baseSettings); AccelCharts.Bind(); } @@ -215,32 +189,31 @@ namespace grapher { WriteButton.Top = Constants.SensitivityChartAloneHeight - Constants.ButtonVerticalOffset; - ToggleButton.Appearance = Appearance.Button; - ToggleButton.FlatStyle = FlatStyle.System; - ToggleButton.TextAlign = ContentAlignment.MiddleCenter; - ToggleButton.Size = WriteButton.Size; - ToggleButton.Top = WriteButton.Top; + DisableButton.Appearance = Appearance.Button; + DisableButton.FlatStyle = FlatStyle.System; + DisableButton.TextAlign = ContentAlignment.MiddleCenter; + DisableButton.Size = WriteButton.Size; + DisableButton.Top = WriteButton.Top; SetButtonDefaults(); } private void SetButtonDefaults() { - ToggleButton.Checked = LastToggleChecked; - - ToggleButton.Font = DefaultButtonFont; - ToggleButton.Text = ToggleButton.Checked ? "Disable" : "Enable"; - ToggleButton.Update(); + DisableButton.Font = DefaultButtonFont; + DisableButton.Text = "Disable"; + DisableButton.Enabled = true; + DisableButton.Update(); WriteButton.Font = DefaultButtonFont; WriteButton.Text = Constants.WriteButtonDefaultText; - WriteButton.Enabled = ToggleButton.Checked || !ToggleButton.Enabled; + WriteButton.Enabled = true; WriteButton.Update(); } private void OnScaleMenuItemClick(object sender, EventArgs e) { - UpdateGraph(Settings.RawAccelSettings.AccelerationSettings); + UpdateGraph(); } private void OnWriteButtonClick(object sender, EventArgs e) @@ -248,24 +221,16 @@ namespace grapher UpdateActiveSettingsFromFields(); } - private void OnToggleButtonClick(object sender, EventArgs e) + private void DisableDriverEventHandler(object sender, EventArgs e) { - var settings = ToggleButton.Checked ? - Settings.RawAccelSettings.AccelerationSettings : - DriverInterop.DefaultSettings; - - LastToggleChecked = ToggleButton.Checked; - ButtonDelay(ToggleButton); - - SettingsManager.SendToDriver(settings); - Settings.ActiveAccel.UpdateFromSettings(settings); - RefreshOnRead(settings); + ButtonDelay(DisableButton); + Settings.DisableDriver(); + RefreshActive(); } private void OnButtonTimerTick(object sender, EventArgs e) { ButtonTimer.Stop(); - ToggleButton.Enabled = SettingsNotDefault; SetButtonDefaults(); } @@ -277,15 +242,13 @@ namespace grapher private void ButtonDelay(ButtonBase btn) { - ToggleButton.Checked = false; - - ToggleButton.Enabled = false; + DisableButton.Enabled = false; WriteButton.Enabled = false; btn.Font = SmallButtonFont; btn.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms"; - ToggleButton.Update(); + DisableButton.Update(); WriteButton.Update(); StartButtonTimer(); diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 305445a..7d33f0c 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -3,6 +3,7 @@ using grapher.Models.Devices; using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Options.Directionality; +using grapher.Models.Options.LUT; using grapher.Models.Serialized; using System; using System.Windows.Forms; @@ -25,15 +26,13 @@ namespace grapher.Models Chart gainChartY, ComboBox accelTypeDropX, ComboBox accelTypeDropY, + ComboBox lutApplyDropdownX, + ComboBox lutApplyDropdownY, Button writeButton, ButtonBase toggleButton, ToolStripMenuItem showVelocityGainToolStripMenuItem, ToolStripMenuItem showLastMouseMoveMenuItem, ToolStripMenuItem streamingModeToolStripMenuItem, - ToolStripMenuItem velocityGainCapToolStripMenuItem, - ToolStripMenuItem legacyCapToolStripMenuItem, - ToolStripMenuItem gainOffsetToolStripMenuItem, - ToolStripMenuItem legacyOffsetToolStripMenuItem, ToolStripMenuItem autoWriteMenuItem, ToolStripMenuItem useSpecificDeviceMenuItem, ToolStripMenuItem scaleMenuItem, @@ -69,6 +68,12 @@ namespace grapher.Models CheckBox fakeBox, CheckBox wholeCheckBox, CheckBox byComponentCheckBox, + CheckBox gainSwitchX, + CheckBox gainSwitchY, + RichTextBox xLutActiveValuesBox, + RichTextBox yLutActiveValuesBox, + RichTextBox xLutPointsBox, + RichTextBox yLutPointsBox, Label lockXYLabel, Label sensitivityLabel, Label rotationLabel, @@ -86,6 +91,8 @@ namespace grapher.Models Label limitLabelY, Label expLabelX, Label expLabelY, + Label lutTextLabelX, + Label lutTextLabelY, Label constantThreeLabelX, Label constantThreeLabelY, Label activeValueTitleX, @@ -111,6 +118,8 @@ namespace grapher.Models Label midpointActiveLabelY, Label accelTypeActiveLabelX, Label accelTypeActiveLabelY, + Label gainSwitchActiveLabelX, + Label gainSwitchActiveLabelY, Label optionSetXTitle, Label optionSetYTitle, Label mouseLabel, @@ -125,7 +134,11 @@ namespace grapher.Models Label domainActiveValueY, Label rangeLabel, Label rangeActiveValueX, - Label rangeActiveValueY) + Label rangeActiveValueY, + Label lutApplyLabelX, + Label lutApplyLabelY, + Label lutApplyActiveValueX, + Label lutApplyActiveValueY) { fakeBox.Checked = false; fakeBox.Hide(); @@ -224,16 +237,6 @@ namespace grapher.Models new ActiveValueLabel(offsetActiveLabelY, activeValueTitleY), "Offset"); - var offsetOptionsX = new OffsetOptions( - gainOffsetToolStripMenuItem, - legacyOffsetToolStripMenuItem, - offsetX); - - var offsetOptionsY = new OffsetOptions( - gainOffsetToolStripMenuItem, - legacyOffsetToolStripMenuItem, - offsetY); - var accelerationX = new Option( new Field(accelerationBoxX, form, 0), constantOneLabelX, @@ -324,39 +327,53 @@ namespace grapher.Models new ActiveValueLabel(rangeActiveValueY, direcionalityActiveValueTitle)), false); - var capOptionsX = new CapOptions( - velocityGainCapToolStripMenuItem, - legacyCapToolStripMenuItem, - capX); - var capOptionsY = new CapOptions( - velocityGainCapToolStripMenuItem, - legacyCapToolStripMenuItem, - capY); + var lutTextX = new TextOption(lutTextLabelX); + var lutTextY = new TextOption(lutTextLabelY); + var gainSwitchOptionX = new CheckBoxOption( + gainSwitchX, + new ActiveValueLabel(gainSwitchActiveLabelX, activeValueTitleX)); + var gainSwitchOptionY = new CheckBoxOption( + gainSwitchY, + new ActiveValueLabel(gainSwitchActiveLabelY, activeValueTitleY)); var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, + gainSwitchOptionX, accelerationX, scaleX, - capOptionsX, + capX, weightX, - offsetOptionsX, + offsetX, limitX, exponentX, midpointX, + lutTextX, + new LUTPanelOptions(xLutPointsBox, xLutActiveValuesBox), + new LutApplyOptions( + lutApplyLabelX, + lutApplyDropdownX, + new ActiveValueLabel(lutApplyActiveValueX, activeValueTitleX)), writeButton, new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX)); var accelerationOptionsY = new AccelTypeOptions( accelTypeDropY, + gainSwitchOptionY, accelerationY, scaleY, - capOptionsY, + capY, weightY, - offsetOptionsY, + offsetY, limitY, exponentY, midpointY, + lutTextY, + new LUTPanelOptions(yLutPointsBox, yLutActiveValuesBox), + new LutApplyOptions( + lutApplyLabelY, + lutApplyDropdownY, + new ActiveValueLabel(lutApplyActiveValueY, activeValueTitleY)), writeButton, new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY)); @@ -383,7 +400,7 @@ namespace grapher.Models range, wholeCheckBox, byComponentCheckBox, - 260); + Constants.DirectionalityVerticalOffset); var applyOptions = new ApplyOptions( byComponentXYLock, diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index d641873..574f55a 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -108,7 +108,7 @@ namespace grapher.Models.Calculations } var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); - var outMagnitude = Velocity(output.Item1, output.Item2, simulatedInputDatum.time); + var outMagnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time)); var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(outMagnitude - lastOutputMagnitude, 5); @@ -133,8 +133,8 @@ namespace grapher.Models.Calculations logIndex++; } - var ratio = outMagnitude / simulatedInputDatum.velocity; - var slope = inDiff > 0 ? outDiff / inDiff : starter; + var ratio = DecimalCheck(outMagnitude / simulatedInputDatum.velocity); + var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : starter); if (slope < lastSlope) { @@ -200,9 +200,6 @@ namespace grapher.Models.Calculations double maxSlope = 0.0; double minSlope = Double.MaxValue; - - Sensitivity = GetSens(ref settings); - int angleIndex = 0; foreach (var simulatedInputDataAngle in simulatedInputData) @@ -223,7 +220,7 @@ namespace grapher.Models.Calculations } var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); - var magnitude = Velocity(output.Item1, output.Item2, simulatedInputDatum.time); + var magnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time)); var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(magnitude - lastOutputMagnitude, 5); @@ -248,10 +245,15 @@ namespace grapher.Models.Calculations logIndex++; } - var ratio = magnitude / simulatedInputDatum.velocity; - var slope = inDiff > 0 ? outDiff / inDiff : settings.sensitivity.x; + var ratio = DecimalCheck(magnitude / simulatedInputDatum.velocity); + var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : settings.sensitivity.x); bool indexToMeasureExtrema = (angleIndex == 0) || (angleIndex == (Constants.AngleDivisions - 1)); + + if (angleIndex == 0 && double.IsNaN(ratio)) + { + Console.WriteLine("oops"); + } if (indexToMeasureExtrema && (ratio > maxRatio)) { @@ -322,10 +324,9 @@ namespace grapher.Models.Calculations mouseInputData.x = ceilX; mouseInputData.y = ceilY; mouseInputData.time = MeasurementTime*timeFactor; - mouseInputData.velocity = Velocity(ceilX, ceilY, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(ceilX, ceilY, mouseInputData.time)); mouseInputData.angle = Math.Atan2(ceilY, ceilX); magnitudes.Add(mouseInputData); - } for (double i = 5; i < MaxVelocity; i+=Increment) @@ -336,7 +337,7 @@ namespace grapher.Models.Calculations mouseInputData.x = ceil; mouseInputData.y = 0; mouseInputData.time = MeasurementTime * timeFactor; - mouseInputData.velocity = Velocity(ceil, 0, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(ceil, 0, mouseInputData.time)); mouseInputData.angle = Math.Atan2(ceil, 0); magnitudes.Add(mouseInputData); } @@ -371,7 +372,7 @@ namespace grapher.Models.Calculations mouseInputData.x = ceil; mouseInputData.y = 0; mouseInputData.time = MeasurementTime*timeFactor; - mouseInputData.velocity = Velocity(ceil, 0, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(ceil, 0, mouseInputData.time)); mouseInputData.angle = 0; magnitudes.Add(mouseInputData); } @@ -391,7 +392,7 @@ namespace grapher.Models.Calculations mouseInputData.x = 0; mouseInputData.y = ceil; mouseInputData.time = MeasurementTime*timeFactor; - mouseInputData.velocity = Velocity(0, ceil, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(0, ceil, mouseInputData.time)); mouseInputData.angle = 0; magnitudes.Add(mouseInputData); } @@ -404,7 +405,7 @@ namespace grapher.Models.Calculations mouseInputData.x = 0; mouseInputData.y = ceil; mouseInputData.time = MeasurementTime*timeFactor; - mouseInputData.velocity = Velocity(0, ceil, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(0, ceil, mouseInputData.time)); mouseInputData.angle = Math.PI / 2; magnitudes.Add(mouseInputData); } @@ -422,39 +423,12 @@ namespace grapher.Models.Calculations foreach (var slowMoveMagnitude in SlowMovements) { - var slowMoveX = Math.Round(slowMoveMagnitude * Math.Cos(angle), 4); - var slowMoveY = Math.Round(slowMoveMagnitude * Math.Sin(angle), 4); - var ceilX = (int)Math.Round(slowMoveX*90); - var ceilY = (int)Math.Round(slowMoveY*90); - var ceilMagnitude = Magnitude(ceilX, ceilY); - var timeFactor = ceilMagnitude / slowMoveMagnitude; - - SimulatedMouseInput mouseInputData; - mouseInputData.x = ceilX; - mouseInputData.y = ceilY; - mouseInputData.time = timeFactor; - mouseInputData.velocity = Velocity(ceilX, ceilY, timeFactor); - mouseInputData.angle = angle; - magnitudes.Add(mouseInputData); + magnitudes.Add(SimulateAngledInput(angle, slowMoveMagnitude)); } for (double magnitude = 5; magnitude < MaxVelocity; magnitude+=Increment) { - var slowMoveX = Math.Round(magnitude * Math.Cos(angle), 4); - var slowMoveY = Math.Round(magnitude * Math.Sin(angle), 4); - var ratio = slowMoveX > 0.0 ? slowMoveY / slowMoveX : 90; - var ceilX = (int)Math.Round(slowMoveX*90); - var ceilY = (int)Math.Round(slowMoveY*ratio); - var ceilMagnitude = Magnitude(ceilX, ceilY); - var timeFactor = ceilMagnitude / magnitude; - - SimulatedMouseInput mouseInputData; - mouseInputData.x = ceilX; - mouseInputData.y = ceilY; - mouseInputData.time = timeFactor; - mouseInputData.velocity = Velocity(ceilX, ceilY, mouseInputData.time); - mouseInputData.angle = angle; - magnitudes.Add(mouseInputData); + magnitudes.Add(SimulateAngledInput(angle, magnitude)); } magnitudesByAngle.Add(magnitudes.AsReadOnly()); @@ -465,11 +439,31 @@ namespace grapher.Models.Calculations public static double Magnitude(int x, int y) { + if (x == 0) + { + return Math.Abs(y); + } + + if (y == 0) + { + return Math.Abs(x); + } + return Math.Sqrt(x * x + y * y); } public static double Magnitude(double x, double y) { + if (x == 0) + { + return Math.Abs(y); + } + + if (y == 0) + { + return Math.Abs(x); + } + return Math.Sqrt(x * x + y * y); } @@ -519,6 +513,94 @@ namespace grapher.Models.Calculations SimulatedDirectionalInput = GetSimulatedDirectionalInput(); } + private static readonly double MinChartAllowedValue = Convert.ToDouble(Decimal.MinValue) / 10; + private static readonly double MaxChartAllowedValue = Convert.ToDouble(Decimal.MaxValue) / 10; + + private double DecimalCheck(double value) + { + if (value < MinChartAllowedValue) + { + return MinChartAllowedValue; + } + + if (value > MaxChartAllowedValue) + { + return MaxChartAllowedValue; + } + + return value; + } + + private SimulatedMouseInput SimulateAngledInput(double angle, double magnitude) + { + SimulatedMouseInput mouseInputData; + + var moveX = Math.Round(magnitude * Math.Cos(angle), 4); + var moveY = Math.Round(magnitude * Math.Sin(angle), 4); + + if (moveX == 0) + { + mouseInputData.x = 0; + mouseInputData.y = (int)Math.Ceiling(moveY); + mouseInputData.time = mouseInputData.y / moveY; + } + else if (moveY == 0) + { + mouseInputData.x = (int)Math.Ceiling(moveX); + mouseInputData.y = 0; + mouseInputData.time = mouseInputData.x / moveX; + } + else + { + var ratio = moveY / moveX; + int ceilX = 0; + int ceilY = 0; + double biggerX = 0; + double biggerY = 0; + double roundedBiggerX = 0; + double roundedBiggerY = 0; + double roundedRatio = -1; + double factor = 10; + + while (Math.Abs(roundedRatio - ratio) > 0.01 && + biggerX < 25000 && + biggerY < 25000) + { + roundedBiggerX = Math.Floor(biggerX); + roundedBiggerY = Math.Floor(biggerY); + ceilX = Convert.ToInt32(roundedBiggerX); + ceilY = Convert.ToInt32(roundedBiggerY); + roundedRatio = ceilX > 0 ? ceilY / ceilX : -1; + biggerX = moveX * factor; + biggerY = moveY * factor; + factor *= 10; + } + + var ceilMagnitude = Magnitude(ceilX, ceilY); + var timeFactor = ceilMagnitude / magnitude; + + mouseInputData.x = ceilX; + mouseInputData.y = ceilY; + mouseInputData.time = timeFactor; + + if (mouseInputData.x == 1 && mouseInputData.time == 1) + { + Console.WriteLine("Oops"); + } + + } + + mouseInputData.velocity = DecimalCheck(Velocity(mouseInputData.x, mouseInputData.y, mouseInputData.time)); + + if (double.IsNaN(mouseInputData.velocity)) + { + Console.WriteLine("oopsie"); + } + + mouseInputData.angle = angle; + return mouseInputData; + } + #endregion Methods } } diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 163829f..c5c2ae5 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -772,8 +772,8 @@ namespace grapher.Models.Mouse // strip negative directional multipliers, charts calculated from positive input - Vec2<double> dirMults = SettingsManager.RawAccelSettings - .AccelerationSettings.directionalMultipliers; + Vec2<double> dirMults = SettingsManager.ActiveSettings.baseSettings + .directionalMultipliers; if (dirMults.x > 0 && x < 0) { diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index 11a7f10..75eb017 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -46,8 +46,8 @@ namespace grapher.Models.Options { IsTitleMode = false; - HideTitle(); Options.ShowFull(); + HideTitle(); } } @@ -61,6 +61,7 @@ namespace grapher.Models.Options Options.ShowShortened(); DisplayTitle(); + Options.HandleLUTOptionsOnResize(); } } @@ -103,16 +104,11 @@ namespace grapher.Models.Options Options.SetArgs(ref args); } - public AccelArgs GenerateArgs() - { - return Options.GenerateArgs(); - } - - public void SetActiveValues(int mode, AccelArgs args) + public void SetActiveValues(ref AccelArgs args) { if (!Hidden) { - Options.SetActiveValues(mode, args); + Options.SetActiveValues(ref args); } } diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 8d3fecb..f97df2d 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -1,5 +1,6 @@ using grapher.Layouts; using grapher.Models.Options; +using grapher.Models.Options.LUT; using grapher.Models.Serialized; using System; using System.Collections.Generic; @@ -12,16 +13,15 @@ namespace grapher { #region Fields - public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase> - { - new LinearLayout(), - new ClassicLayout(), - new NaturalLayout(), - new NaturalGainLayout(), - new PowerLayout(), - new MotivityLayout(), - new OffLayout() - }.ToDictionary(k => k.Name); + public static readonly LayoutBase Linear = new LinearLayout(); + public static readonly LayoutBase Classic = new ClassicLayout(); + public static readonly LayoutBase Jump = new JumpLayout(); + public static readonly LayoutBase Natural = new NaturalLayout(); + public static readonly LayoutBase Motivity = new MotivityLayout(); + public static readonly LayoutBase Power = new PowerLayout(); + public static readonly LayoutBase LUT = new LUTLayout(); + public static readonly LayoutBase Off = new OffLayout(); + public static readonly LayoutBase Unsupported = new UnsupportedLayout(); #endregion Fields @@ -29,22 +29,39 @@ namespace grapher public AccelTypeOptions( ComboBox accelDropdown, + CheckBoxOption gainSwitch, Option acceleration, Option scale, - CapOptions cap, + Option cap, Option weight, - OffsetOptions offset, + Option offset, Option limit, Option exponent, Option midpoint, + TextOption lutText, + LUTPanelOptions lutPanelOptions, + LutApplyOptions lutApplyOptions, Button writeButton, ActiveValueLabel accelTypeActiveValue) { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); - AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray()); + AccelDropdown.Items.AddRange( + new LayoutBase[] + { + Linear, + Classic, + Jump, + Natural, + Motivity, + Power, + LUT, + Off + }); + AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); + GainSwitch = gainSwitch; Acceleration = acceleration; Scale = scale; Cap = cap; @@ -55,11 +72,21 @@ namespace grapher Midpoint = midpoint; WriteButton = writeButton; AccelTypeActiveValue = accelTypeActiveValue; + LutText = lutText; + LutPanel = lutPanelOptions; + LutApply = lutApplyOptions; AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width; AccelTypeActiveValue.Height = AccelDropdown.Height; + GainSwitch.Left = Acceleration.Field.Left; + + LutPanel.Left = AccelDropdown.Left; + LutPanel.Width = AccelDropdown.Width + AccelTypeActiveValue.Width; - Layout("Off"); + LutText.SetText(TextOption.LUTLayoutExpandedText, TextOption.LUTLayoutShortenedText); + + AccelerationType = Off; + Layout(); ShowingDefault = true; } @@ -72,27 +99,17 @@ namespace grapher public ComboBox AccelDropdown { get; } - public int AccelerationIndex - { - get - { - return AccelerationType.Index; - } - } - - public LayoutBase AccelerationType { get; private set; } - public ActiveValueLabel AccelTypeActiveValue { get; } public Option Acceleration { get; } public Option Scale { get; } - public CapOptions Cap { get; } + public Option Cap { get; } public Option Weight { get; } - public OffsetOptions Offset { get; } + public Option Offset { get; } public Option Limit { get; } @@ -100,6 +117,26 @@ namespace grapher public Option Midpoint { get; } + public TextOption LutText { get; } + + public CheckBoxOption GainSwitch { get; } + + public LUTPanelOptions LutPanel { get; } + + public LutApplyOptions LutApply { get; } + + public LayoutBase AccelerationType + { + get + { + return AccelDropdown.SelectedItem as LayoutBase; + } + private set + { + AccelDropdown.SelectedItem = value; + } + } + public override int Top { get @@ -131,6 +168,9 @@ namespace grapher set { AccelDropdown.Left = value; + LutText.Left = value; + LutPanel.Left = value; + LutApply.Left = value; } } @@ -143,6 +183,9 @@ namespace grapher set { AccelDropdown.Width = value; + LutText.Width = value; + LutPanel.Width = AccelTypeActiveValue.CenteringLabel.Right - AccelDropdown.Left; + LutApply.Width = value; } } @@ -165,6 +208,7 @@ namespace grapher AccelDropdown.Hide(); AccelTypeActiveValue.Hide(); + GainSwitch.Hide(); Acceleration.Hide(); Scale.Hide(); Cap.Hide(); @@ -173,13 +217,16 @@ namespace grapher Limit.Hide(); Exponent.Hide(); Midpoint.Hide(); + LutText.Hide(); + LutPanel.Hide(); + LutApply.Hide(); } public void Show() { AccelDropdown.Show(); AccelTypeActiveValue.Show(); - Layout(); + Layout(AccelDropdown.Bottom + Constants.OptionVerticalSeperation); } public override void Show(string name) @@ -187,20 +234,21 @@ namespace grapher Show(); } - public void SetActiveValues(int index, AccelArgs args) + public void SetActiveValues(ref AccelArgs args) { - AccelerationType = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value; - AccelTypeActiveValue.SetValue(AccelerationType.Name); - AccelDropdown.SelectedIndex = AccelerationType.Index; - + AccelerationType = AccelTypeFromSettings(ref args); + AccelTypeActiveValue.SetValue(AccelerationType.ActiveName); + GainSwitch.SetActiveValue(args.legacy); Weight.SetActiveValue(args.weight); - Cap.SetActiveValues(args.gainCap, args.scaleCap, args.gainCap > 0 || args.scaleCap <= 0); - Offset.SetActiveValue(args.offset, args.legacyOffset); - Acceleration.SetActiveValue(args.acceleration); + Cap.SetActiveValue(args.cap); + Offset.SetActiveValue(args.offset); + Acceleration.SetActiveValue(AccelerationParameterFromArgs(ref args)); Scale.SetActiveValue(args.scale); Limit.SetActiveValue(args.limit); - Exponent.SetActiveValue(args.exponent); + Exponent.SetActiveValue(ExponentParameterFromArgs(ref args)); Midpoint.SetActiveValue(args.midpoint); + LutPanel.SetActiveValues(args.tableData.points, args.tableData.length); + LutApply.SetActiveValue(args.tableData.velocity); } public void ShowFull() @@ -212,6 +260,9 @@ namespace grapher Left = Acceleration.Left + Constants.DropDownLeftSeparation; Width = Acceleration.Width - Constants.DropDownLeftSeparation; + + LutText.Expand(); + HandleLUTOptionsOnResize(); } public void ShowShortened() @@ -223,33 +274,66 @@ namespace grapher Left = Acceleration.Field.Left; Width = Acceleration.Field.Width; + + LutText.Shorten(); } public void SetArgs(ref AccelArgs args) { - AccelArgs defaults = DriverInterop.DefaultSettings.args.x; - args.acceleration = Acceleration.Visible ? Acceleration.Field.Data : defaults.acceleration; - args.scale = Scale.Visible ? Scale.Field.Data : defaults.scale; - args.gainCap = Cap.Visible ? Cap.VelocityGainCap : defaults.gainCap; - args.scaleCap = Cap.Visible ? Cap.SensitivityCap : defaults.scaleCap; - args.limit = Limit.Visible ? Limit.Field.Data : defaults.limit; - args.exponent = Exponent.Visible ? Exponent.Field.Data : defaults.exponent; - args.offset = Offset.Visible ? Offset.Offset : defaults.offset; - args.legacyOffset = Offset.IsLegacy; - args.midpoint = Midpoint.Visible ? Midpoint.Field.Data : defaults.midpoint; - args.weight = Weight.Visible ? Weight.Field.Data : defaults.weight; - } + if (AccelerationType == Unsupported) throw new NotImplementedException(); - public AccelArgs GenerateArgs() - { - AccelArgs args = new AccelArgs(); - SetArgs(ref args); - return args; + args.mode = AccelerationType.Mode; + + if (Acceleration.Visible) + { + if (args.mode == AccelMode.natural) + { + args.decayRate = Acceleration.Field.Data; + } + else if (args.mode == AccelMode.motivity) + { + args.growthRate = Acceleration.Field.Data; + } + else + { + args.accelClassic = Acceleration.Field.Data; + } + + args.smooth = Acceleration.Field.Data; + } + + args.legacy = !GainSwitch.CheckBox.Checked; + + if (Scale.Visible) args.scale = Scale.Field.Data; + if (Cap.Visible) args.cap = Cap.Field.Data; + if (Limit.Visible) args.limit = Limit.Field.Data; + if (Exponent.Visible) + { + if (args.mode == AccelMode.classic) + { + args.power = Exponent.Field.Data; + } + else + { + args.exponent = Exponent.Field.Data; + } + } + if (Offset.Visible) args.offset = Offset.Field.Data; + if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; + if (Weight.Visible) args.weight = Weight.Field.Data; + if (LutPanel.Visible) + { + (var points, var length) = LutPanel.GetPoints(); + args.tableData.points = points; + args.tableData.length = length; + } + if (LutApply.Visible) args.tableData.velocity = LutApply.ApplyType == LutApplyOptions.LutApplyType.Velocity; } public override void AlignActiveValues() { AccelTypeActiveValue.Align(); + GainSwitch.AlignActiveValues(); Acceleration.AlignActiveValues(); Scale.AlignActiveValues(); Cap.AlignActiveValues(); @@ -258,29 +342,33 @@ namespace grapher Limit.AlignActiveValues(); Exponent.AlignActiveValues(); Midpoint.AlignActiveValues(); + LutApply.AlignActiveValues(); } - private void OnIndexChanged(object sender, EventArgs e) + public void HandleLUTOptionsOnResize() { - var accelerationTypeString = AccelDropdown.SelectedItem.ToString(); - Layout(accelerationTypeString, Beneath); - ShowingDefault = false; + LutText.Left = AccelDropdown.Left; + LutPanel.Left = GainSwitch.Left - 100; + LutPanel.Width = Acceleration.ActiveValueLabel.CenteringLabel.Right - LutPanel.Left; + LutApply.Left = LutPanel.Left; + LutApply.Width = AccelDropdown.Right - LutPanel.Left; } - private void Layout(string type, int top = -1) + private void OnIndexChanged(object sender, EventArgs e) { - AccelerationType = AccelerationTypes[type]; - Layout(top); + Layout(Beneath); + ShowingDefault = false; } private void Layout(int top = -1) { if (top < 0) { - top = Acceleration.Top; + top = GainSwitch.Top; } AccelerationType.Layout( + GainSwitch, Acceleration, Scale, Cap, @@ -289,9 +377,64 @@ namespace grapher Limit, Exponent, Midpoint, + LutText, + LutPanel, + LutApply, top); } + private LayoutBase AccelTypeFromSettings(ref AccelArgs args) + { + if (args.spacedTableArgs.mode != SpacedTableMode.off) + { + if (!AccelDropdown.Items.Contains(Unsupported)) + { + AccelDropdown.Items.Add(Unsupported); + } + + return Unsupported; + } + + switch (args.mode) + { + case AccelMode.classic: return (args.power == 2) ? Linear : Classic; + case AccelMode.jump: return Jump; + case AccelMode.natural: return Natural; + case AccelMode.motivity: return Motivity; + case AccelMode.power: return Power; + case AccelMode.lut: return LUT; + default: return Off; + } + } + + private double AccelerationParameterFromArgs(ref AccelArgs args) + { + if (args.mode == AccelMode.motivity) + { + return args.growthRate; + } + else if (args.mode == AccelMode.natural) + { + return args.decayRate; + } + else + { + return args.accelClassic; + } + } + + private double ExponentParameterFromArgs(ref AccelArgs args) + { + if (args.mode == AccelMode.classic) + { + return args.power; + } + else + { + return args.exponent; + } + } + #endregion Methods } } diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index ffe430d..06854b8 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -81,59 +81,30 @@ namespace grapher.Models.Options #region Methods - public Vec2<AccelMode> GetModes() + public void SetArgs(ref Vec2<AccelArgs> args) { - var xMode = (AccelMode)OptionSetX.Options.AccelerationIndex; + OptionSetX.SetArgs(ref args.x); - return new Vec2<AccelMode> + if (ByComponentVectorXYLock.Checked) { - x = xMode, - y = ByComponentVectorXYLock.Checked ? xMode : (AccelMode)OptionSetY.Options.AccelerationIndex - }; - } - - public Vec2<AccelArgs> GetArgs() - { - var xArgs = OptionSetX.GenerateArgs(); - - return new Vec2<AccelArgs> + OptionSetX.SetArgs(ref args.y); + } + else { - x = xArgs, - y = ByComponentVectorXYLock.Checked ? xArgs : OptionSetY.GenerateArgs() - }; - - } - - public void SetActiveValues( - double xSens, - double ySens, - double rotation, - int xMode, - int yMode, - AccelArgs xArgs, - AccelArgs yArgs, - bool isWhole) - { - Sensitivity.SetActiveValues(xSens, ySens); - Rotation.SetActiveValue(rotation); - OptionSetX.SetActiveValues(xMode, xArgs); - WholeVectorCheckBox.Checked = isWhole; - ByComponentVectorCheckBox.Checked = !isWhole; - ByComponentVectorXYLock.Checked = xArgs.Equals(yArgs); - OptionSetY.SetActiveValues(yMode, yArgs); + OptionSetY.SetArgs(ref args.y); + } } public void SetActiveValues(DriverSettings settings) { - SetActiveValues( - settings.sensitivity.x, - settings.sensitivity.y, - settings.rotation, - (int)settings.modes.x, - (int)settings.modes.y, - settings.args.x, - settings.args.y, - settings.combineMagnitudes); + Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y); + Rotation.SetActiveValue(settings.rotation); + + WholeVectorCheckBox.Checked = settings.combineMagnitudes; + ByComponentVectorCheckBox.Checked = !settings.combineMagnitudes; + ByComponentVectorXYLock.Checked = settings.args.x.Equals(settings.args.y); + OptionSetX.SetActiveValues(ref settings.args.x); + OptionSetY.SetActiveValues(ref settings.args.y); Directionality.SetActiveValues(settings); diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs deleted file mode 100644 index c459c50..0000000 --- a/grapher/Models/Options/CapOptions.cs +++ /dev/null @@ -1,225 +0,0 @@ -using grapher.Models.Options; -using System; -using System.Windows.Forms; - -namespace grapher -{ - public class CapOptions : OptionBase - { - #region Constants - - - #endregion Constants - - #region Constructors - - public CapOptions( - ToolStripMenuItem velocityGainCapCheck, - ToolStripMenuItem legacyCapCheck, - Option capOption) - { - - VelocityGainCapCheck = velocityGainCapCheck; - LegacyCapCheck = legacyCapCheck; - CapOption = capOption; - - LegacyCapCheck.Click += new System.EventHandler(OnSensitivityCapCheckClick); - VelocityGainCapCheck.Click += new System.EventHandler(OnVelocityGainCapCheckClick); - - LegacyCapCheck.CheckedChanged += new System.EventHandler(OnSensitivityCapCheckedChange); - VelocityGainCapCheck.CheckedChanged += new System.EventHandler(OnVelocityGainCapCheckedChange); - - EnableVelocityGainCap(); - } - - #endregion Constructors - - #region Properties - - public ToolStripMenuItem LegacyCapCheck { get; } - - public ToolStripMenuItem VelocityGainCapCheck { get; } - - public Option CapOption { get; } - - public bool IsSensitivityGain { get; private set; } - - public double SensitivityCap { - get - { - if (IsSensitivityGain) - { - return CapOption.Field.Data; - } - else - { - return 0; - } - } - } - - public double VelocityGainCap { - get - { - if (IsSensitivityGain) - { - return 0; - } - else - { - return CapOption.Field.Data; - } - } - } - - public override int Top - { - get - { - return CapOption.Top; - } - set - { - CapOption.Top = value; - } - } - - public override int Height - { - get - { - return CapOption.Height; - } - } - - public override int Left - { - get - { - return CapOption.Left; - } - set - { - CapOption.Left = value; - } - } - - public override int Width - { - get - { - return CapOption.Width; - } - set - { - CapOption.Width = value; - } - } - - public override bool Visible - { - get - { - return CapOption.Visible; - } - } - - #endregion Properties - - #region Methods - - public override void Hide() - { - CapOption.Hide(); - } - - public void Show() - { - CapOption.Show(); - } - - public override void Show(string name) - { - CapOption.Show(name); - } - - public void SnapTo(Option option) - { - Top = option.Top + option.Height + Constants.OptionVerticalSeperation; - } - - - public void SetActiveValues(double gainCap, double sensCap, bool capGainEnabled) - { - if (capGainEnabled) - { - CapOption.ActiveValueLabel.FormatString = Constants.GainCapFormatString; - CapOption.ActiveValueLabel.Prefix = "Gain"; - CapOption.SetActiveValue(gainCap); - LegacyCapCheck.Checked = false; - VelocityGainCapCheck.Checked = true; - } - else - { - CapOption.ActiveValueLabel.FormatString = Constants.DefaultActiveValueFormatString; - CapOption.ActiveValueLabel.Prefix = string.Empty; - CapOption.SetActiveValue(sensCap); - LegacyCapCheck.Checked = true; - VelocityGainCapCheck.Checked = false; - } - } - - public override void AlignActiveValues() - { - CapOption.AlignActiveValues(); - } - - void OnSensitivityCapCheckClick(object sender, EventArgs e) - { - if (!LegacyCapCheck.Checked) - { - VelocityGainCapCheck.Checked = false; - LegacyCapCheck.Checked = true; - } - } - - void OnVelocityGainCapCheckClick(object sender, EventArgs e) - { - if (!VelocityGainCapCheck.Checked) - { - VelocityGainCapCheck.Checked = true; - LegacyCapCheck.Checked = false; - } - } - - void OnSensitivityCapCheckedChange(object sender, EventArgs e) - { - if (LegacyCapCheck.Checked) - { - EnableSensitivityCap(); - } - } - - void OnVelocityGainCapCheckedChange(object sender, EventArgs e) - { - if (VelocityGainCapCheck.Checked) - { - EnableVelocityGainCap(); - } - } - - void EnableSensitivityCap() - { - IsSensitivityGain = true; - CapOption.SetName("Sensitivity Cap"); - } - - void EnableVelocityGainCap() - { - IsSensitivityGain = false; - CapOption.SetName("Velocity Gain Cap"); - } - - #endregion Methods - } -} diff --git a/grapher/Models/Options/CheckBoxOption.cs b/grapher/Models/Options/CheckBoxOption.cs new file mode 100644 index 0000000..abf96d3 --- /dev/null +++ b/grapher/Models/Options/CheckBoxOption.cs @@ -0,0 +1,109 @@ +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class CheckBoxOption : OptionBase + { + public CheckBoxOption( + CheckBox checkBox, + ActiveValueLabel activeValueLabel) + { + CheckBox = checkBox; + ActiveValueLabel = activeValueLabel; + Show(string.Empty); + } + + public CheckBox CheckBox { get; } + + public ActiveValueLabel ActiveValueLabel { get; } + + public override bool Visible + { + get + { + return CheckBox.Visible || ShouldShow; + } + } + + public override int Left + { + get + { + return CheckBox.Left; + } + set + { + CheckBox.Left = value; + } + } + + public override int Height + { + get + { + return CheckBox.Height; + } + } + + public override int Top + { + get + { + return CheckBox.Top; + } + set + { + CheckBox.Top = value; + ActiveValueLabel.Top = value; + } + } + + public override int Width + { + get + { + return CheckBox.Width; + } + set + { + CheckBox.Width = value; + } + } + + /// <summary> + /// For some reason, setting CheckBox.Show() does not result in visible not being true on GUI startup. + /// This is inconsistent with the other options, which do. + /// Keep this bool for allowing Visible to still be the signal for option snapping. + /// </summary> + private bool ShouldShow { get; set; } + + public override void AlignActiveValues() + { + ActiveValueLabel.Align(); + } + + public override void Hide() + { + CheckBox.Hide(); + ShouldShow = false; + CheckBox.Enabled = false; + ActiveValueLabel.Hide(); + } + + public override void Show(string Name) + { + CheckBox.Show(); + ShouldShow = true; + CheckBox.Enabled = true; + CheckBox.Name = Name; + ActiveValueLabel.Show(); + } + + public void SetActiveValue(bool legacy) + { + CheckBox.Checked = !legacy; + var activeValueString = legacy ? "Legacy" : "Gain"; + ActiveValueLabel.SetValue(activeValueString); + } + } +} diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs new file mode 100644 index 0000000..6b13cdc --- /dev/null +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -0,0 +1,217 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LUTPanelOptions : OptionBase + { + public const int PanelPadding = 5; + public const int PanelHeight = 100; + + public LUTPanelOptions(RichTextBox pointsTextBox, RichTextBox activeValuesTextBox) + { + PointsTextBox = pointsTextBox; + PointsTextBox.Height = PanelHeight; + + ActiveValuesTextBox = activeValuesTextBox; + ActiveValuesTextBox.Height = PanelHeight; + ActiveValuesTextBox.ReadOnly = true; + } + + public RichTextBox PointsTextBox + { + get; + } + + public RichTextBox ActiveValuesTextBox + { + get; + } + + public override bool Visible + { + get + { + return PointsTextBox.Visible || ShouldShow; + } + } + + public override int Top + { + get + { + return PointsTextBox.Top; + } + set + { + PointsTextBox.Top = value; + ActiveValuesTextBox.Top = value; + } + } + + public override int Height + { + get + { + return PointsTextBox.Height; + } + } + + public override int Left + { + get + { + return PointsTextBox.Left; + } + set + { + PointsTextBox.Left = value; + AlignActivePanelToPointsTextBox(); + } + } + + public override int Width + { + get + { + return PointsTextBox.Width; + } + set + { + var panelWidth = value / 2 - PanelPadding; + PointsTextBox.Width = panelWidth; + ActiveValuesTextBox.Width = panelWidth; + AlignActivePanelToPointsTextBox(); + } + } + + private bool ShouldShow { get; set; } + + public override void Hide() + { + PointsTextBox.Hide(); + ActiveValuesTextBox.Hide(); + ShouldShow = false; + } + + public override void Show(string name) + { + PointsTextBox.Show(); + ActiveValuesTextBox.Show(); + ShouldShow = true; + } + + public override void AlignActiveValues() + { + // Nothing to do here. + } + + public void SetActiveValues(IEnumerable<Vec2<float>> activePoints, int length) + { + if (length > 0 && activePoints.First().x != 0) + { + ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints, length); + } + else + { + ActiveValuesTextBox.Text = string.Empty; + } + } + + public (Vec2<float>[], int length) GetPoints() + { + return UserTextToPoints(PointsTextBox.Text); + } + + private static (Vec2<float>[], int length) UserTextToPoints(string userText) + { + if (string.IsNullOrWhiteSpace(userText)) + { + throw new Exception("Text must be entered in text box to fill Look Up Table."); + } + + Vec2<float>[] points = new Vec2<float>[256]; + + var userTextSplit = userText.Trim().Trim(';').Split(';'); + int index = 0; + float lastX = 0; + + foreach(var pointEntry in userTextSplit) + { + var pointSplit = pointEntry.Trim().Split(','); + + if (pointSplit.Length != 2) + { + throw new Exception($"Point at index {index} is malformed. Expected format: x,y; Given: {pointEntry.Trim()}"); + } + + float x; + float y; + + try + { + x = float.Parse(pointSplit[0]); + } + catch (Exception ex) + { + throw new Exception($"X-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[0]}", ex); + } + + if (x <= 0) + { + throw new Exception($"X-value for point at index {index} is less than or equal to 0. Point (0,0) is implied and should not be specified in points text."); + } + + if (x <= lastX) + { + throw new Exception($"X-value for point at index {index} is less than or equal to previous x-value. Value: {x} Previous: {lastX}"); + } + + lastX = x; + + try + { + y = float.Parse(pointSplit[1]); + } + catch (Exception ex) + { + throw new Exception($"Y-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[1]}", ex); + } + + if (y <= 0) + { + throw new Exception($"Y-value for point at index {index} is less than or equal to 0. Value: {y}"); + } + + points[index] = new Vec2<float> { x = x, y = y }; + + index++; + } + + return (points, userTextSplit.Length); + } + + private void AlignActivePanelToPointsTextBox() + { + ActiveValuesTextBox.Left = PointsTextBox.Right + PanelPadding; + } + + private string PointsToActiveValuesText(IEnumerable<Vec2<float>> points, int length) + { + StringBuilder builder = new StringBuilder(); + + for(int i = 0; i < length; i++) + { + var point = points.ElementAt(i); + builder.AppendLine($"{point.x},{point.y};"); + } + + return builder.ToString(); + } + } +} diff --git a/grapher/Models/Options/LUT/LUTPointOption.cs b/grapher/Models/Options/LUT/LUTPointOption.cs new file mode 100644 index 0000000..6afee4f --- /dev/null +++ b/grapher/Models/Options/LUT/LUTPointOption.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LUTPointOption + { + public LUTPointOption(Form form) + { + FieldX = new Field(new System.Windows.Forms.TextBox(), form, 0); + FieldY = new Field(new System.Windows.Forms.TextBox(), form, 0); + } + + public double X { get => FieldX.Data; } + + public double Y { get => FieldY.Data; } + + public int Top + { + get + { + return FieldX.Top; + } + set + { + FieldX.Top = value; + FieldY.Top = value; + } + } + + private Field FieldX { get; } + + private Field FieldY { get; } + } +} diff --git a/grapher/Models/Options/LUT/LutApplyOptions.cs b/grapher/Models/Options/LUT/LutApplyOptions.cs new file mode 100644 index 0000000..7d8c737 --- /dev/null +++ b/grapher/Models/Options/LUT/LutApplyOptions.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LutApplyOptions : OptionBase + { + public const string LUTApplyOptionsLabelText = "Apply as:"; + public const int LUTApplyLabelDropdownSeparation = 4; + + public enum LutApplyType + { + Sensitivity, + Velocity + } + + public class LutApplyOption + { + public LutApplyType Type { get; set; } + + public string Name => Type.ToString(); + + public override string ToString() => Name; + } + + public static readonly LutApplyOption Sensitivity = new LutApplyOption + { + Type = LutApplyType.Sensitivity, + }; + + public static readonly LutApplyOption Velocity = new LutApplyOption + { + Type = LutApplyType.Velocity, + }; + + public LutApplyOptions( + Label label, + ComboBox applyOptionsDropdown, + ActiveValueLabel lutApplyActiveValue) + { + ApplyOptions = applyOptionsDropdown; + ApplyOptions.Items.Clear(); + ApplyOptions.Items.AddRange( + new LutApplyOption[] + { + Sensitivity, + Velocity, + }); + + Label = label; + Label.Text = LUTApplyOptionsLabelText; + Label.AutoSize = false; + Label.Width = 50; + + ActiveValueLabel = lutApplyActiveValue; + } + + public LutApplyType ApplyType { get => ApplyOption.Type; } + + public LutApplyOption ApplyOption { + get + { + return ApplyOptions.SelectedItem as LutApplyOption; + } + set + { + ApplyOptions.SelectedItem = value; + } + } + + public Label Label { get; } + + public ActiveValueLabel ActiveValueLabel { get; } + + public ComboBox ApplyOptions { get; } + + public override bool Visible + { + get + { + return Label.Visible || ShouldShow; + } + } + + public override int Left + { + get + { + return Label.Left; + } + set + { + Label.Left = value; + ApplyOptions.Left = Label.Left + Label.Width + LUTApplyLabelDropdownSeparation; + } + } + + public override int Height + { + get + { + return Label.Height; + } + } + + public override int Top + { + get + { + return Label.Top; + } + set + { + ApplyOptions.Top = value; + Label.Top = (ApplyOptions.Height - Label.Height) / 2 + ApplyOptions.Top; + ActiveValueLabel.Top = value; + } + } + + public override int Width + { + get + { + return Label.Width; + } + set + { + ApplyOptions.Width = value - Label.Width - Constants.OptionLabelBoxSeperation; + } + } + + private bool ShouldShow { get; set; } + + public override void Hide() + { + Label.Hide(); + ApplyOptions.Hide(); + ActiveValueLabel.Hide(); + ShouldShow = false; + } + + public override void Show(string labelText) + { + Label.Show(); + + if (!string.IsNullOrWhiteSpace(labelText)) + { + Label.Text = labelText; + } + + ApplyOptions.Show(); + ActiveValueLabel.Show(); + ShouldShow = true; + } + + public override void AlignActiveValues() + { + ActiveValueLabel.Align(); + } + + public void SetActiveValue(bool applyAsVelocity) + { + ApplyOption = ApplyOptionFromSettings(applyAsVelocity); + ActiveValueLabel.SetValue(ApplyOption.Name); + } + + public LutApplyOption ApplyOptionFromSettings(bool applyAsVelocity) + { + if (applyAsVelocity) + { + return Velocity; + } + else + { + return Sensitivity; + } + } + } +} diff --git a/grapher/Models/Options/OffsetOptions.cs b/grapher/Models/Options/OffsetOptions.cs index 6638ed7..42d2d92 100644 --- a/grapher/Models/Options/OffsetOptions.cs +++ b/grapher/Models/Options/OffsetOptions.cs @@ -106,12 +106,9 @@ namespace grapher.Models.Options OffsetOption.Show(name); } - public void SetActiveValue(double offset, bool legacy) + public void SetActiveValue(double offset) { OffsetOption.SetActiveValue(offset); - - VelocityGainOffsetCheck.Checked = !legacy; - LegacyOffsetCheck.Checked = legacy; } public override void AlignActiveValues() diff --git a/grapher/Models/Options/TextOption.cs b/grapher/Models/Options/TextOption.cs new file mode 100644 index 0000000..1f8034d --- /dev/null +++ b/grapher/Models/Options/TextOption.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class TextOption : OptionBase + { + #region Constants + + public const string LUTLayoutExpandedText = "This mode is for experts only. Format: x1,y1;x2,y2;...xn,yn;"; + public const string LUTLayoutShortenedText = "Experts only."; + + #endregion Constants + + #region Constructors + + public TextOption(Label label) + { + Label = label; + Label.AutoSize = true; + } + + #endregion Constructors + + #region Properties + + private Label Label { get; } + + private string ExpandedText { get; set; } + + private string ShortenedText { get; set; } + + public override bool Visible + { + get + { + return Label.Visible || ShouldShow; + } + } + + public override int Top + { + get + { + return Label.Top; + } + set + { + Label.Top = value; + } + } + + public override int Height + { + get + { + return Label.Height; + } + } + + public override int Width + { + get + { + return Label.Width; + } + set + { + Label.MaximumSize = new System.Drawing.Size(value, 0); + } + } + + public override int Left + { + get + { + return Label.Left; + } + set + { + Label.Left = value; + } + } + + private bool ShouldShow + { + get; set; + } + + public override void Hide() + { + Label.Hide(); + ShouldShow = false; + } + + public override void Show(string Name) + { + Label.Show(); + ShouldShow = true; + } + + public void Expand() + { + Label.Text = ExpandedText; + } + + public void Shorten() + { + Label.Text = ShortenedText; + } + + public void SetText(string expandedText, string shortenedText) + { + ExpandedText = expandedText; + ShortenedText = shortenedText; + } + + public override void AlignActiveValues() + { + // Nothing to do here + } + + #endregion Properties + } +} diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index a4eb627..e7b67ba 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.IO; namespace grapher.Models.Serialized { @@ -70,6 +71,32 @@ namespace grapher.Models.Serialized StreamingMode.GetHashCode(); } + public void Save() + { + File.WriteAllText(Constants.GuiConfigFileName, JsonConvert.SerializeObject(this)); + } + + public static GUISettings MaybeLoad() + { + GUISettings settings = null; + + try + { + settings = JsonConvert.DeserializeObject<GUISettings>( + File.ReadAllText(Constants.GuiConfigFileName)); + } + catch (Exception ex) + { + if (!(ex is JsonException || ex is FileNotFoundException)) + { + throw; + } + } + + return settings; + } + #endregion Methods + } } diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs deleted file mode 100644 index 17db910..0000000 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ /dev/null @@ -1,141 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.IO; -using System.Linq; - -namespace grapher.Models.Serialized -{ - [Serializable] - public class RawAccelSettings - { - #region Fields - - public static readonly string ExecutingDirectory = AppDomain.CurrentDomain.BaseDirectory; - public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, Constants.DefaultSettingsFileName); - public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings - { - MissingMemberHandling = MissingMemberHandling.Ignore, - }; - #endregion Fields - - #region Constructors - - public RawAccelSettings() { } - - public RawAccelSettings( - DriverSettings accelSettings, - GUISettings guiSettings) - { - AccelerationSettings = accelSettings; - GUISettings = guiSettings; - } - - #endregion Constructors - - #region Properties - [JsonProperty(Required = Required.Always)] - public GUISettings GUISettings { get; set; } - - [JsonProperty(DriverSettings.Key, Required = Required.Always)] - public DriverSettings AccelerationSettings { get; set; } - - #endregion Properties - - #region Methods - - public static RawAccelSettings Load(Func<GUISettings> DefaultGUISettingsSupplier) - { - return Load(DefaultSettingsFile, DefaultGUISettingsSupplier); - } - - public static RawAccelSettings Load(string file, Func<GUISettings> DefaultGUISettingsSupplier) - { - try - { - RawAccelSettings settings = null; - - JObject settingsJObject = JObject.Parse(File.ReadAllText(file)); - if (settingsJObject.ContainsKey(DriverSettings.Key)) - { - settings = settingsJObject.ToObject<RawAccelSettings>(JsonSerializer.Create(SerializerSettings)); - } - else - { - settings = new RawAccelSettings - { - AccelerationSettings = settingsJObject.ToObject<DriverSettings>(), - GUISettings = DefaultGUISettingsSupplier() - }; - } - - if (settings is null || settings.AccelerationSettings is null) - { - throw new JsonException($"{file} contains invalid JSON"); - } - - return settings; - } - catch (FileNotFoundException e) - { - throw new FileNotFoundException($"Settings file does not exist at {file}", e); - } - catch (JsonException e) - { - throw new JsonException($"Settings file at {file} does not contain valid Raw Accel Settings.", e); - } - } - - public static bool Exists() - { - return Exists(DefaultSettingsFile); - } - - public static bool Exists(string file) - { - return File.Exists(file); - } - - public void Save() - { - Save(DefaultSettingsFile); - } - - public void Save(string file) - { - JObject thisJO = JObject.FromObject(this); - AddComments(thisJO); - File.WriteAllText(file, thisJO.ToString(Formatting.Indented)); - } - - private void AddComments(JObject thisJO) - { - string modes = string.Join(" | ", Enum.GetNames(typeof(AccelMode))); - ((JObject)thisJO[DriverSettings.Key]) - .AddFirst(new JProperty("### Mode Types ###", modes)); - } - - public bool IsDefaultEquivalent() - { - return IsDefaultEquivalent(AccelerationSettings); - } - - public static bool IsDefaultEquivalent(DriverSettings accelSettings) - { - bool wholeOrNoY = accelSettings.combineMagnitudes || - accelSettings.modes.y == AccelMode.noaccel; - - return string.IsNullOrEmpty(accelSettings.deviceID) && - accelSettings.sensitivity.x == 1 && - accelSettings.sensitivity.y == 1 && - accelSettings.directionalMultipliers.x <= 0 && - accelSettings.directionalMultipliers.y <= 0 && - accelSettings.rotation == 0 && - accelSettings.snap == 0 && - accelSettings.modes.x == AccelMode.noaccel && - wholeOrNoY; - } - - #endregion Methods - } -} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index c867c0a..6bcfab8 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.IO; using System.Windows.Forms; using System.Threading; using System.Text; @@ -22,7 +23,6 @@ namespace grapher.Models.Serialized ToolStripMenuItem streamingMode, DeviceIDManager deviceIDManager) { - ActiveAccel = activeAccel; DpiField = dpiField; PollRateField = pollRateField; AutoWriteMenuItem = autoWrite; @@ -30,15 +30,35 @@ namespace grapher.Models.Serialized ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; StreamingModeMenuItem = streamingMode; DeviceIDManager = deviceIDManager; + + SetActiveFields(activeAccel); + + GuiSettings = GUISettings.MaybeLoad(); + + if (GuiSettings is null) + { + GuiSettings = MakeGUISettingsFromFields(); + GuiSettings.Save(); + } + else + { + UpdateFieldsFromGUISettings(); + } + + UserSettings = InitUserSettings(); } #endregion Constructors #region Properties - public ManagedAccel ActiveAccel { get; } + public GUISettings GuiSettings { get; private set; } + + public ManagedAccel ActiveAccel { get; private set; } + + public ExtendedSettings ActiveSettings { get; private set; } - public RawAccelSettings RawAccelSettings { get; private set; } + public DriverSettings UserSettings { get; private set; } public Field DpiField { get; private set; } @@ -55,47 +75,55 @@ namespace grapher.Models.Serialized #endregion Properties #region Methods - public SettingsErrors TryUpdateActiveSettings(DriverSettings settings) - { - var errors = TryUpdateAccel(settings); - - if (errors.Empty()) - { - RawAccelSettings.AccelerationSettings = settings; - RawAccelSettings.GUISettings = MakeGUISettingsFromFields(); - RawAccelSettings.Save(); - } - return errors; + public void DisableDriver() + { + var defaultSettings = new ExtendedSettings(); + ActiveSettings = defaultSettings; + ActiveAccel.Settings = defaultSettings; + new Thread(() => ActiveAccel.Activate()).Start(); } public void UpdateFieldsFromGUISettings() { - DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); - PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); - ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; - ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; - StreamingModeMenuItem.Checked = RawAccelSettings.GUISettings.StreamingMode; - AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; + DpiField.SetToEntered(GuiSettings.DPI); + PollRateField.SetToEntered(GuiSettings.PollRate); + ShowLastMouseMoveMenuItem.Checked = GuiSettings.ShowLastMouseMove; + ShowVelocityAndGainMoveMenuItem.Checked = GuiSettings.ShowVelocityAndGain; + StreamingModeMenuItem.Checked = GUISettings.StreamingMode; + AutoWriteMenuItem.Checked = GuiSettings.AutoWriteToDriverOnStartup; } - public SettingsErrors TryUpdateAccel(DriverSettings settings) + public SettingsErrors TryActivate(DriverSettings settings) { - var errors = SendToDriverSafe(settings); - if (errors.Empty()) ActiveAccel.UpdateFromSettings(settings); - return errors; - } + var errors = new SettingsErrors(settings); - public static void SendToDriver(DriverSettings settings) - { - new Thread(() => DriverInterop.Write(settings)).Start(); + if (errors.Empty()) + { + GuiSettings = MakeGUISettingsFromFields(); + GuiSettings.Save(); + + UserSettings = settings; + File.WriteAllText(Constants.DefaultSettingsFileName, RaConvert.Settings(settings)); + + ActiveSettings = new ExtendedSettings(settings); + ActiveAccel.Settings = ActiveSettings; + + new Thread(() => ActiveAccel.Activate()).Start(); + } + + return errors; } - public static SettingsErrors SendToDriverSafe(DriverSettings settings) + public void SetHiddenOptions(DriverSettings settings) { - var errors = DriverInterop.GetSettingsErrors(settings); - if (errors.Empty()) SendToDriver(settings); - return errors; + settings.snap = UserSettings.snap; + settings.maximumSpeed = UserSettings.maximumSpeed; + settings.minimumSpeed = UserSettings.minimumSpeed; + settings.minimumTime = UserSettings.minimumTime; + settings.maximumTime = UserSettings.maximumTime; + settings.ignore = UserSettings.ignore; + settings.directionalMultipliers = UserSettings.directionalMultipliers; } public GUISettings MakeGUISettingsFromFields() @@ -111,32 +139,51 @@ namespace grapher.Models.Serialized }; } - // Returns true when file settings are active - public bool Startup() + public bool TableActive() + { + return ActiveSettings.tables.x != null || ActiveSettings.tables.y != null; + } + + public void SetActiveFields(ManagedAccel activeAccel) { - if (RawAccelSettings.Exists()) + ActiveAccel = activeAccel; + ActiveSettings = activeAccel.Settings; + } + + private DriverSettings InitUserSettings() + { + var path = Constants.DefaultSettingsFileName; + if (File.Exists(path)) { try { - RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); - UpdateFieldsFromGUISettings(); - if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) + DriverSettings settings = RaConvert.Settings(File.ReadAllText(path)); + + if (!GuiSettings.AutoWriteToDriverOnStartup || + TableActive() || + TryActivate(settings).Empty()) { - TryUpdateAccel(RawAccelSettings.AccelerationSettings); + return settings; } - return RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; + } catch (JsonException e) { - Console.WriteLine($"bad settings: {e}"); + System.Diagnostics.Debug.WriteLine($"bad settings: {e}"); } } - RawAccelSettings = new RawAccelSettings( - DriverInterop.GetActiveSettings(), - MakeGUISettingsFromFields()); - RawAccelSettings.Save(); - return true; + if (!TableActive()) + { + File.WriteAllText(path, RaConvert.Settings(ActiveSettings.baseSettings)); + return ActiveSettings.baseSettings; + } + else + { + var defaultSettings = new DriverSettings(); + File.WriteAllText(path, RaConvert.Settings(defaultSettings)); + return defaultSettings; + } } #endregion Methods |