diff --git a/converter/converter.cpp b/converter/converter.cpp index e282ca45..af2699b6 100644 --- a/converter/converter.cpp +++ b/converter/converter.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -44,12 +45,16 @@ static inline void trim(std::string& s) { rtrim(s); } -bool yes() { - for (;;) { - wchar_t c = _getwch(); - if (c == 'y') return true; - else if (c == 'n') return false; - } +bool ask(std::string_view question) { + std::cout << question << " (Y/N)" << std::endl; + wchar_t ch; + bool yes; + do + { + ch = towupper(_getwch()); + yes = ch == 'Y'; + } while (ch != 'N' && !yes); + return yes; } using ia_settings_t = std::vector>; @@ -128,10 +133,10 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) { double offset = get("Offset").value_or(0); ra::accel_args args; - - double accel_b = std::pow(accel * prescale, power - 1) / sens; - double accel_e = 1 / (power - 1); - args.accel = std::pow(accel_b, accel_e); + double powm1 = power - 1; + double rpowm1 = 1 / powm1; + double accel_b = std::pow(accel * prescale, powm1) / sens; + args.accel = std::pow(accel_b, rpowm1); args.exponent = power; args.legacy_offset = legacy; args.offset = offset; @@ -142,9 +147,7 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) { args.scale_cap = cap_converted; } else { - double b = (cap_converted - 1) / power; - double e = 1 / (power - 1); - args.gain_cap = offset + (1 / accel) * std::pow(b, e); + args.gain_cap = offset + std::pow(cap_converted - 1, rpowm1) / args.accel; } return args; @@ -165,16 +168,16 @@ bool try_convert(const ia_settings_t& ia_settings) { switch (static_cast(mode)) { case IA_QL: { - std::cout << "We recommend trying out our new cap and offset styles.\n" - "Use new cap and offset? (y|n)\n"; + bool legacy = !ask("We recommend trying out our new cap and offset styles.\n" + "Use new cap and offset?"); ra_settings.modes.x = ra::accel_mode::classic; - ra_settings.argsv.x = convert_quake(ia_settings, !yes()); + ra_settings.argsv.x = convert_quake(ia_settings, legacy); break; } case IA_NAT: { - std::cout << "Raw Accel offers a new mode that you might like more than Natural.\n" - "Wanna try it out now? (y|n)\n"; - ra_settings.modes.x = yes() ? ra::accel_mode::naturalgain : ra::accel_mode::natural; + bool nat_gain = ask("Raw Accel offers a new mode that you might like more than Natural.\n" + "Wanna try it out now?"); + ra_settings.modes.x = nat_gain ? ra::accel_mode::naturalgain : ra::accel_mode::natural; ra_settings.argsv.x = convert_natural(ia_settings); break; } @@ -223,29 +226,31 @@ int main() } if (opt_path) { - std::cout << "Found " << opt_path->filename() << - "\n\nConvert and send settings generated from " << - opt_path->filename() << "? (y|n)\n"; - if (!yes()) return 0; - try { - if (!try_convert(parse_ia_settings(opt_path.value()))) - std::cout << "Unable to convert settings.\n"; - } - catch (DriverNotInstalledException^) { - Console::WriteLine("\nDriver is not installed."); - } - catch (Exception^ e) { - Console::WriteLine("\nError: " + e->ToString()); - } - catch (const std::exception& e) { - std::cout << "Error: " << e.what() << '\n'; + std::string path = opt_path->filename().generic_string(); + std::stringstream ss; + ss << "Found " << path << + "\n\nConvert and send settings generated from " << path << '?'; + if (ask(ss.str())) { + try { + if (!try_convert(parse_ia_settings(opt_path.value()))) + std::cout << "Unable to convert settings.\n"; + } + catch (DriverNotInstalledException^) { + Console::WriteLine("\nDriver is not installed."); + } + catch (Exception^ e) { + Console::WriteLine("\nError: " + e->ToString()); + } + catch (const std::exception& e) { + std::cout << "Error: " << e.what() << '\n'; + } } } else { std::cout << "Drop your InterAccel settings/profile into this directory.\n" "Then run this program to generate the equivalent Raw Accel settings.\n"; } - - std::cout << "Press any key to close this window . . .\n"; + + std::cout << "Press any key to close this window . . ." << std::endl; _getwch(); } diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index e2f7bcc3..f864fad0 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -10,9 +10,10 @@ public class AccelCalculator { #region Structs - public struct MagnitudeData + public struct SimulatedMouseInput { - public double magnitude; + public double velocity; + public double time; public int x; public int y; } @@ -31,11 +32,11 @@ public AccelCalculator(Field dpi, Field pollRate) #region Properties - public ReadOnlyCollection MagnitudesCombined { get; private set; } + public ReadOnlyCollection SimulatedInputCombined { get; private set; } - public ReadOnlyCollection MagnitudesX { get; private set; } + public ReadOnlyCollection SimulatedInputX { get; private set; } - public ReadOnlyCollection MagnitudesY { get; private set; } + public ReadOnlyCollection SimulatedInputY { get; private set; } public Field DPI { get; private set; } @@ -57,7 +58,7 @@ public AccelCalculator(Field dpi, Field pollRate) #region Methods - public void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection magnitudeData) + public void Calculate(AccelChartData data, ManagedAccel accel, double starter, ICollection simulatedInputData) { double lastInputMagnitude = 0; double lastOutputMagnitude = 0; @@ -71,19 +72,19 @@ public void Calculate(AccelChartData data, ManagedAccel accel, double starter, I int index = 0; int logIndex = 0; - foreach (var magnitudeDatum in magnitudeData) + foreach (var simulatedInputDatum in simulatedInputData) { - if (magnitudeDatum.magnitude <= 0) + if (simulatedInputDatum.velocity <= 0) { continue; } - var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime); + var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); var outMagnitude = Magnitude(output.Item1, output.Item2); - if (!data.VelocityPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.VelocityPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.VelocityPoints.Add(magnitudeDatum.magnitude, outMagnitude); + data.VelocityPoints.Add(simulatedInputDatum.velocity, outMagnitude); } else { @@ -97,7 +98,7 @@ public void Calculate(AccelChartData data, ManagedAccel accel, double starter, I logIndex++; } - var ratio = outMagnitude / magnitudeDatum.magnitude; + var ratio = outMagnitude / simulatedInputDatum.velocity; if (ratio > maxRatio) { @@ -109,7 +110,7 @@ public void Calculate(AccelChartData data, ManagedAccel accel, double starter, I minRatio = ratio; } - var inDiff = magnitudeDatum.magnitude - lastInputMagnitude; + var inDiff = simulatedInputDatum.velocity - lastInputMagnitude; var outDiff = outMagnitude - lastOutputMagnitude; var slope = inDiff > 0 ? outDiff / inDiff : starter; @@ -123,17 +124,17 @@ public void Calculate(AccelChartData data, ManagedAccel accel, double starter, I minSlope = slope; } - if (!data.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.AccelPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.AccelPoints.Add(magnitudeDatum.magnitude, ratio); + data.AccelPoints.Add(simulatedInputDatum.velocity, ratio); } - if (!data.GainPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.GainPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.GainPoints.Add(magnitudeDatum.magnitude, slope); + data.GainPoints.Add(simulatedInputDatum.velocity, slope); } - lastInputMagnitude = magnitudeDatum.magnitude; + lastInputMagnitude = simulatedInputDatum.velocity; lastOutputMagnitude = outMagnitude; index += 1; } @@ -153,7 +154,7 @@ public void Calculate(AccelChartData data, ManagedAccel accel, double starter, I data.MinGain = minSlope; } - public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, DriverSettings settings, ICollection magnitudeData) + public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, DriverSettings settings, ICollection simulatedInputData) { double lastInputMagnitude = 0; double lastOutputMagnitudeX = 0; @@ -171,22 +172,22 @@ public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, Driver int index = 0; int logIndex = 0; - foreach (var magnitudeDatum in magnitudeData) + foreach (var simulatedInputDatum in simulatedInputData) { - if (magnitudeDatum.magnitude <= 0) + if (simulatedInputDatum.velocity <= 0) { continue; } - var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime); + var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); var outputWithoutSens = StripThisSens(output.Item1, output.Item2); var magnitudeWithoutSens = Magnitude(outputWithoutSens.Item1, outputWithoutSens.Item2); - var ratio = magnitudeWithoutSens / magnitudeDatum.magnitude; + var ratio = magnitudeWithoutSens / simulatedInputDatum.velocity; - if (!data.Combined.VelocityPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.Combined.VelocityPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.Combined.VelocityPoints.Add(magnitudeDatum.magnitude, magnitudeWithoutSens); + data.Combined.VelocityPoints.Add(simulatedInputDatum.velocity, magnitudeWithoutSens); } else { @@ -223,20 +224,20 @@ public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, Driver minRatio = yRatio; } - if (!data.X.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.X.AccelPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.X.AccelPoints.Add(magnitudeDatum.magnitude, xRatio); + data.X.AccelPoints.Add(simulatedInputDatum.velocity, xRatio); } - if (!data.Y.AccelPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.Y.AccelPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.Y.AccelPoints.Add(magnitudeDatum.magnitude, yRatio); + data.Y.AccelPoints.Add(simulatedInputDatum.velocity, yRatio); } - var xOut = xRatio * magnitudeDatum.magnitude; - var yOut = yRatio * magnitudeDatum.magnitude; + var xOut = xRatio * simulatedInputDatum.velocity; + var yOut = yRatio * simulatedInputDatum.velocity; - var inDiff = magnitudeDatum.magnitude - lastInputMagnitude; + var inDiff = simulatedInputDatum.velocity - lastInputMagnitude; var xOutDiff = xOut - lastOutputMagnitudeX; var yOutDiff = yOut - lastOutputMagnitudeY; var xSlope = inDiff > 0 ? xOutDiff / inDiff : settings.sensitivity.x; @@ -262,27 +263,27 @@ public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, Driver minSlope = ySlope; } - if (!data.X.VelocityPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.X.VelocityPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.X.VelocityPoints.Add(magnitudeDatum.magnitude, xOut); + data.X.VelocityPoints.Add(simulatedInputDatum.velocity, xOut); } - if (!data.Y.VelocityPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.Y.VelocityPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.Y.VelocityPoints.Add(magnitudeDatum.magnitude, yOut); + data.Y.VelocityPoints.Add(simulatedInputDatum.velocity, yOut); } - if (!data.X.GainPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.X.GainPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.X.GainPoints.Add(magnitudeDatum.magnitude, xSlope); + data.X.GainPoints.Add(simulatedInputDatum.velocity, xSlope); } - if (!data.Y.GainPoints.ContainsKey(magnitudeDatum.magnitude)) + if (!data.Y.GainPoints.ContainsKey(simulatedInputDatum.velocity)) { - data.Y.GainPoints.Add(magnitudeDatum.magnitude, ySlope); + data.Y.GainPoints.Add(simulatedInputDatum.velocity, ySlope); } - lastInputMagnitude = magnitudeDatum.magnitude; + lastInputMagnitude = simulatedInputDatum.velocity; lastOutputMagnitudeX = xOut; lastOutputMagnitudeY = yOut; index += 1; @@ -303,53 +304,56 @@ public void CalculateCombinedDiffSens(AccelData data, ManagedAccel accel, Driver data.Combined.MinGain = minSlope; } - public ReadOnlyCollection GetMagnitudes() + public ReadOnlyCollection GetSimulatedInput() { - var magnitudes = new List(); + var magnitudes = new List(); for (int i = 0; i < CombinedMaxVelocity; i+=Increment) { for (int j = 0; j <= i; j+=Increment) { - MagnitudeData magnitudeData; - magnitudeData.magnitude = Magnitude(i, j); - magnitudeData.x = i; - magnitudeData.y = j; - magnitudes.Add(magnitudeData); + SimulatedMouseInput mouseInputData; + mouseInputData.x = i; + mouseInputData.y = j; + mouseInputData.time = MeasurementTime; + mouseInputData.velocity = Velocity(i, j, mouseInputData.time); + magnitudes.Add(mouseInputData); } } - magnitudes.Sort((m1, m2) => m1.magnitude.CompareTo(m2.magnitude)); + magnitudes.Sort((m1, m2) => m1.velocity.CompareTo(m2.velocity)); return magnitudes.AsReadOnly(); } - public ReadOnlyCollection GetMagnitudesX() + public ReadOnlyCollection GetSimulatInputX() { - var magnitudes = new List(); + var magnitudes = new List(); for (int i = 0; i < XYMaxVelocity; i+=Increment) { - MagnitudeData magnitudeData; - magnitudeData.magnitude = i; - magnitudeData.x = i; - magnitudeData.y = 0; - magnitudes.Add(magnitudeData); + SimulatedMouseInput mouseInputData; + mouseInputData.x = i; + mouseInputData.y = 0; + mouseInputData.time = MeasurementTime; + mouseInputData.velocity = Velocity(i, 0, mouseInputData.time); + magnitudes.Add(mouseInputData); } return magnitudes.AsReadOnly(); } - public ReadOnlyCollection GetMagnitudesY() + public ReadOnlyCollection GetSimulatedInputY() { - var magnitudes = new List(); + var magnitudes = new List(); for (int i = 0; i < XYMaxVelocity; i+=Increment) { - MagnitudeData magnitudeData; - magnitudeData.magnitude = i; - magnitudeData.x = 0; - magnitudeData.y = i; - magnitudes.Add(magnitudeData); + SimulatedMouseInput mouseInputData; + mouseInputData.x = 0; + mouseInputData.y = i; + mouseInputData.time = MeasurementTime; + mouseInputData.velocity = Velocity(0, i, mouseInputData.time); + magnitudes.Add(mouseInputData); } return magnitudes.AsReadOnly(); @@ -407,9 +411,9 @@ public void ScaleByMouseSettings() Increment = ratio > 1 ? (int) Math.Floor(ratio) : 1; MeasurementTime = Increment == 1 ? 1 / ratio : 1; XYMaxVelocity = CombinedMaxVelocity * Constants.XYToCombinedRatio; - MagnitudesCombined = GetMagnitudes(); - MagnitudesX = GetMagnitudesX(); - MagnitudesY = GetMagnitudesY(); + SimulatedInputCombined = GetSimulatedInput(); + SimulatedInputX = GetSimulatInputX(); + SimulatedInputY = GetSimulatedInputY(); } #endregion Methods diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index 802c3925..aab8a38c 100644 --- a/grapher/Models/Charts/ChartState/CombinedState.cs +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -46,7 +46,7 @@ public override void Bind() public override void Calculate(ManagedAccel accel, DriverSettings settings) { - Calculator.Calculate(Data.Combined, accel, settings.sensitivity.x, Calculator.MagnitudesCombined); + Calculator.Calculate(Data.Combined, accel, settings.sensitivity.x, Calculator.SimulatedInputCombined); } } } diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index 6bfaac59..92c799fe 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -44,7 +44,7 @@ public override void Bind() public override void Calculate(ManagedAccel accel, DriverSettings settings) { - Calculator.CalculateCombinedDiffSens(Data, accel, settings, Calculator.MagnitudesCombined); + Calculator.CalculateCombinedDiffSens(Data, accel, settings, Calculator.SimulatedInputCombined); } } } diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index 017d3d1c..22181add 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -76,8 +76,8 @@ public override void Bind() public override void Calculate(ManagedAccel accel, DriverSettings settings) { - Calculator.Calculate(Data.X, accel, settings.sensitivity.x, Calculator.MagnitudesX); - Calculator.Calculate(Data.Y, accel, settings.sensitivity.y, Calculator.MagnitudesY); + Calculator.Calculate(Data.X, accel, settings.sensitivity.x, Calculator.SimulatedInputX); + Calculator.Calculate(Data.Y, accel, settings.sensitivity.y, Calculator.SimulatedInputY); } } } diff --git a/signed/driver/rawaccel.sys b/signed/driver/rawaccel.sys index 794158d4..94872fea 100644 Binary files a/signed/driver/rawaccel.sys and b/signed/driver/rawaccel.sys differ