summaryrefslogtreecommitdiff
path: root/grapher/Models
diff options
context:
space:
mode:
Diffstat (limited to 'grapher/Models')
-rw-r--r--grapher/Models/AccelGUI.cs28
-rw-r--r--grapher/Models/Calculations/AccelCalculator.cs73
-rw-r--r--grapher/Models/Calculations/AccelChartData.cs22
-rw-r--r--grapher/Models/Charts/AccelCharts.cs5
-rw-r--r--grapher/Models/Charts/ChartState/ChartState.cs7
-rw-r--r--grapher/Models/Charts/ChartXY.cs21
-rw-r--r--grapher/Models/Fields/Field.cs10
-rw-r--r--grapher/Models/Mouse/MouseWatcher.cs8
-rw-r--r--grapher/Models/Options/Option.cs2
-rw-r--r--grapher/Models/Serialized/DriverSettings.cs117
-rw-r--r--grapher/Models/Serialized/SettingsManager.cs41
11 files changed, 163 insertions, 171 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs
index 95d0c25..cc86ff7 100644
--- a/grapher/Models/AccelGUI.cs
+++ b/grapher/Models/AccelGUI.cs
@@ -38,6 +38,7 @@ namespace grapher
WriteButton.Click += new System.EventHandler(OnWriteButtonClick);
ButtonTimer = SetupButtonTimer();
+ ChartRefresh = SetupChartTimer();
SetupWriteButton();
}
@@ -63,6 +64,8 @@ namespace grapher
public ToolStripMenuItem ScaleMenuItem { get; }
+ private Timer ChartRefresh { get; }
+
#endregion Properties
#region Methods
@@ -83,14 +86,8 @@ namespace grapher
minimumTime = .4
};
- Settings.UpdateActiveSettings(settings, () =>
- {
- AccelForm.Invoke((MethodInvoker)delegate
- {
- WriteButtonDelay();
- UpdateGraph();
- });
- });
+ WriteButtonDelay();
+ Settings.UpdateActiveSettings(settings);
RefreshOnRead();
}
@@ -116,6 +113,15 @@ namespace grapher
ApplyOptions.SetActiveValues(settings);
}
+ private Timer SetupChartTimer()
+ {
+ Timer chartTimer = new Timer();
+ chartTimer.Enabled = true;
+ chartTimer.Interval = 10;
+ chartTimer.Tick += new System.EventHandler(OnChartTimerTick);
+ return chartTimer;
+ }
+
private Timer SetupButtonTimer()
{
Timer buttonTimer = new Timer();
@@ -165,6 +171,12 @@ namespace grapher
ButtonTimer.Start();
}
+ private void OnChartTimerTick(object sender, EventArgs e)
+ {
+ AccelCharts.DrawLastMovement();
+ MouseWatcher.UpdateLastMove();
+ }
+
#endregion Methods
}
diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs
index f2a6c7c..e2f7bcc 100644
--- a/grapher/Models/Calculations/AccelCalculator.cs
+++ b/grapher/Models/Calculations/AccelCalculator.cs
@@ -67,9 +67,13 @@ namespace grapher.Models.Calculations
double maxSlope = 0.0;
double minSlope = Double.MaxValue;
+ double log = -2;
+ int index = 0;
+ int logIndex = 0;
+
foreach (var magnitudeDatum in magnitudeData)
{
- if (magnitudeDatum.magnitude <=0)
+ if (magnitudeDatum.magnitude <= 0)
{
continue;
}
@@ -77,7 +81,23 @@ namespace grapher.Models.Calculations
var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime);
var outMagnitude = Magnitude(output.Item1, output.Item2);
- var ratio = magnitudeDatum.magnitude > 0 ? outMagnitude / magnitudeDatum.magnitude : starter;
+ if (!data.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
+ {
+ data.VelocityPoints.Add(magnitudeDatum.magnitude, outMagnitude);
+ }
+ else
+ {
+ continue;
+ }
+
+ while (Math.Pow(10,log) < outMagnitude && logIndex < data.LogToIndex.Length)
+ {
+ data.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
+ }
+
+ var ratio = outMagnitude / magnitudeDatum.magnitude;
if (ratio > maxRatio)
{
@@ -108,11 +128,6 @@ namespace grapher.Models.Calculations
data.AccelPoints.Add(magnitudeDatum.magnitude, ratio);
}
- if (!data.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
- {
- data.VelocityPoints.Add(magnitudeDatum.magnitude, outMagnitude);
- }
-
if (!data.GainPoints.ContainsKey(magnitudeDatum.magnitude))
{
data.GainPoints.Add(magnitudeDatum.magnitude, slope);
@@ -120,9 +135,18 @@ namespace grapher.Models.Calculations
lastInputMagnitude = magnitudeDatum.magnitude;
lastOutputMagnitude = outMagnitude;
+ index += 1;
+ }
+
+ index--;
+
+ while (log <= 5.0)
+ {
+ data.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
}
- data.OrderedVelocityPointsList.AddRange(data.VelocityPoints.Values.ToList());
data.MaxAccel = maxRatio;
data.MinAccel = minRatio;
data.MaxGain = maxSlope;
@@ -143,18 +167,38 @@ namespace grapher.Models.Calculations
Sensitivity = GetSens(ref settings);
+ double log = -2;
+ int index = 0;
+ int logIndex = 0;
+
foreach (var magnitudeDatum in magnitudeData)
{
+ if (magnitudeDatum.magnitude <= 0)
+ {
+ continue;
+ }
+
var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime);
var outputWithoutSens = StripThisSens(output.Item1, output.Item2);
var magnitudeWithoutSens = Magnitude(outputWithoutSens.Item1, outputWithoutSens.Item2);
- var ratio = magnitudeDatum.magnitude > 0 ? magnitudeWithoutSens / magnitudeDatum.magnitude : 1;
+ var ratio = magnitudeWithoutSens / magnitudeDatum.magnitude;
if (!data.Combined.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
{
data.Combined.VelocityPoints.Add(magnitudeDatum.magnitude, magnitudeWithoutSens);
}
+ else
+ {
+ continue;
+ }
+
+ while (Math.Pow(10,log) < magnitudeWithoutSens && logIndex < data.Combined.LogToIndex.Length)
+ {
+ data.Combined.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
+ }
var xRatio = settings.sensitivity.x * ratio;
var yRatio = settings.sensitivity.y * ratio;
@@ -241,9 +285,18 @@ namespace grapher.Models.Calculations
lastInputMagnitude = magnitudeDatum.magnitude;
lastOutputMagnitudeX = xOut;
lastOutputMagnitudeY = yOut;
+ index += 1;
+ }
+
+ index--;
+
+ while (log <= 5.0)
+ {
+ data.Combined.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
}
- data.Combined.OrderedVelocityPointsList.AddRange(data.Combined.VelocityPoints.Values.ToList());
data.Combined.MaxAccel = maxRatio;
data.Combined.MinAccel = minRatio;
data.Combined.MaxGain = maxSlope;
diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs
index 54685a2..60d4c89 100644
--- a/grapher/Models/Calculations/AccelChartData.cs
+++ b/grapher/Models/Calculations/AccelChartData.cs
@@ -13,8 +13,8 @@ namespace grapher.Models.Calculations
AccelPoints = new SortedDictionary<double, double>();
VelocityPoints = new SortedDictionary<double, double>();
GainPoints = new SortedDictionary<double, double>();
- OrderedVelocityPointsList = new List<double>();
OutVelocityToPoints = new Dictionary<double, (double, double, double)>();
+ LogToIndex = new int[701];
}
#endregion Constructors
@@ -35,7 +35,7 @@ namespace grapher.Models.Calculations
public SortedDictionary<double, double> GainPoints { get; }
- public List<double> OrderedVelocityPointsList { get; }
+ public int[] LogToIndex { get; }
public Dictionary<double, (double, double, double)> OutVelocityToPoints { get; }
@@ -48,8 +48,8 @@ namespace grapher.Models.Calculations
AccelPoints.Clear();
VelocityPoints.Clear();
GainPoints.Clear();
- OrderedVelocityPointsList.Clear();
OutVelocityToPoints.Clear();
+ Array.Clear(LogToIndex, 0, LogToIndex.Length);
}
public (double, double, double) FindPointValuesFromOut(double outVelocityValue)
@@ -80,15 +80,19 @@ namespace grapher.Models.Calculations
public int GetVelocityIndex(double outVelocityValue)
{
- var velIdx = OrderedVelocityPointsList.BinarySearch(outVelocityValue);
-
- if (velIdx < 0)
+ var log = Math.Log10(outVelocityValue);
+ if (log < -2)
+ {
+ log = -2;
+ }
+ else if (log > 5)
{
- velIdx = ~velIdx;
+ log = 5;
}
- velIdx = Math.Min(velIdx, VelocityPoints.Count - 1);
- velIdx = Math.Max(velIdx, 0);
+ log = log * 100 + 200;
+
+ var velIdx = LogToIndex[(int)log];
return velIdx;
}
diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs
index a0e99c8..7484a3a 100644
--- a/grapher/Models/Charts/AccelCharts.cs
+++ b/grapher/Models/Charts/AccelCharts.cs
@@ -143,6 +143,11 @@ namespace grapher
AlignWriteButton();
}
+ public void Redraw()
+ {
+ ChartState.Redraw();
+ }
+
public void Calculate(ManagedAccel accel, DriverSettings settings)
{
ChartState.SetUpCalculate(settings);
diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs
index e1c7d01..1898e12 100644
--- a/grapher/Models/Charts/ChartState/ChartState.cs
+++ b/grapher/Models/Charts/ChartState/ChartState.cs
@@ -48,6 +48,13 @@ namespace grapher.Models.Charts.ChartState
public abstract void Calculate(ManagedAccel accel, DriverSettings settings);
+ public void Redraw()
+ {
+ SensitivityChart.Update();
+ VelocityChart.Update();
+ GainChart.Update();
+ }
+
public virtual void SetUpCalculate(DriverSettings settings)
{
Data.Clear();
diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs
index c30c993..d95c7ac 100644
--- a/grapher/Models/Charts/ChartXY.cs
+++ b/grapher/Models/Charts/ChartXY.cs
@@ -154,6 +154,15 @@ namespace grapher
*/
}
+ public void Update()
+ {
+ ChartX.Update();
+ if (ChartY.Visible)
+ {
+ ChartY.Update();
+ }
+ }
+
public void SetPointBinds(PointData combined, PointData x, PointData y)
{
CombinedPointData = combined;
@@ -213,8 +222,8 @@ namespace grapher
{
if (min < max)
{
- ChartX.ChartAreas[0].AxisY.Minimum = min;
- ChartX.ChartAreas[0].AxisY.Maximum = max;
+ ChartX.ChartAreas[0].AxisY.Minimum = min * 0.95;
+ ChartX.ChartAreas[0].AxisY.Maximum = max * 1.05;
}
}
@@ -222,14 +231,14 @@ namespace grapher
{
if (minX < maxX)
{
- ChartX.ChartAreas[0].AxisY.Minimum = minX;
- ChartX.ChartAreas[0].AxisY.Maximum = maxX;
+ ChartX.ChartAreas[0].AxisY.Minimum = minX * 0.95;
+ ChartX.ChartAreas[0].AxisY.Maximum = maxX * 1.05;
}
if (minY < maxY)
{
- ChartY.ChartAreas[0].AxisY.Minimum = minY;
- ChartY.ChartAreas[0].AxisY.Maximum = maxY;
+ ChartY.ChartAreas[0].AxisY.Minimum = minY * 0.95;
+ ChartY.ChartAreas[0].AxisY.Maximum = maxY * 1.05;
}
}
diff --git a/grapher/Models/Fields/Field.cs b/grapher/Models/Fields/Field.cs
index df73dd7..541bbe2 100644
--- a/grapher/Models/Fields/Field.cs
+++ b/grapher/Models/Fields/Field.cs
@@ -52,7 +52,7 @@ namespace grapher
public string FormatString { get; set; }
- public string DefaultText { get; }
+ public string DefaultText { get; set; }
public FieldState State { get; private set; }
@@ -120,7 +120,7 @@ namespace grapher
}
}
- private double DefaultData { get; }
+ private double DefaultData { get; set; }
#endregion Properties
@@ -138,6 +138,12 @@ namespace grapher
Box.Enabled = true;
}
+ public void SetNewDefault(double newDefault)
+ {
+ DefaultData = newDefault;
+ DefaultText = DecimalString(newDefault);
+ }
+
public void SetToDefault()
{
if (State != FieldState.Default)
diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs
index 86b1c2e..c6e85c1 100644
--- a/grapher/Models/Mouse/MouseWatcher.cs
+++ b/grapher/Models/Mouse/MouseWatcher.cs
@@ -716,10 +716,16 @@ namespace grapher.Models.Mouse
public void OnMouseMove(int x, int y, double timeInMs)
{
- Display.Text = $"Last (x, y): ({x}, {y})";
+ MouseData.Set(x,y);
AccelCharts.MakeDots(x, y, timeInMs);
}
+ public void UpdateLastMove()
+ {
+ MouseData.Get(out var x, out var y);
+ Display.Text = $"Last (x, y): ({x}, {y})";
+ }
+
public void ReadMouseMove(Message message)
{
RawInput rawInput = new RawInput();
diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs
index c0d339e..d5129d5 100644
--- a/grapher/Models/Options/Option.cs
+++ b/grapher/Models/Options/Option.cs
@@ -136,6 +136,8 @@ namespace grapher
public void SetActiveValue(double value)
{
ActiveValueLabel.SetValue(value);
+ Field.SetNewDefault(value);
+ Field.SetToDefault();
}
public override void Hide()
diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs
deleted file mode 100644
index 5f9307c..0000000
--- a/grapher/Models/Serialized/DriverSettings.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-namespace grapher.Models.Serialized
-{
- #region Enumerations
-
- public enum AccelMode
- {
- linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel
- }
-
- #endregion Enumerations
-
- #region Structs
-
- [StructLayout(LayoutKind.Sequential)]
- public struct AccelArgs
- {
- public double offset;
- public double legacy_offset;
- public double accel;
- public double limit;
- public double exponent;
- public double midpoint;
- public double powerScale;
- public double powerExponent;
- public double weight;
- public double rate;
- public double scaleCap;
- public double gainCap;
- };
-
- [StructLayout(LayoutKind.Sequential)]
- public struct Vec2 <T>
- {
- public T x;
- public T y;
- }
-
- #endregion Structs
-
- [StructLayout(LayoutKind.Sequential)]
- [Serializable]
- public class DriverSettings
- {
- #region Fields
-
- private static readonly IntPtr UnmanagedSettingsHandle =
- Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>());
- private static object UnmanagedSettingsLock = new object();
-
- public double rotation;
- public bool combineMagnitudes;
- public Vec2<AccelMode> modes;
- public Vec2<AccelArgs> args;
- public Vec2<double> sensitivity;
- public double minimumTime;
-
- #endregion Fields
-
- #region Methods
-
- public static DriverSettings GetActive()
- {
- DriverInterop.GetActiveSettings(UnmanagedSettingsHandle);
- return Marshal.PtrToStructure<DriverSettings>(UnmanagedSettingsHandle);
- }
-
- public static void SetActive(DriverSettings settings, Action<IntPtr> unmanagedActionBefore = null)
- {
- new Thread(() =>
- {
- lock (UnmanagedSettingsLock)
- {
- Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false);
- unmanagedActionBefore?.Invoke(UnmanagedSettingsHandle);
- DriverInterop.SetActiveSettings(UnmanagedSettingsHandle);
- }
- }).Start();
-
- }
-
- public void SendToDriver(Action<IntPtr> unmanagedActionBefore = null)
- {
- SetActive(this, unmanagedActionBefore);
- }
-
- public void SendToDriverAndUpdate(ManagedAccel accel, Action betweenAccelAndWrite = null)
- {
- SendToDriver(settingsHandle =>
- {
- accel.UpdateFromSettings(settingsHandle);
- betweenAccelAndWrite?.Invoke();
- });
- }
-
- public bool verify()
- {
- /*
- if (args.accel < 0 || args.rate < 0)
- bad_arg("accel can not be negative, use a negative weight to compensate");
- if (args.rate > 1) bad_arg("rate can not be greater than 1");
- if (args.exponent <= 1) bad_arg("exponent must be greater than 1");
- if (args.limit <= 1) bad_arg("limit must be greater than 1");
- if (args.power_scale <= 0) bad_arg("scale must be positive");
- if (args.power_exp <= 0) bad_arg("exponent must be positive");
- if (args.midpoint < 0) bad_arg("midpoint must not be negative");
- if (args.time_min <= 0) bad_arg("min time must be positive");
- */
- return true;
- }
-
- #endregion Methods
- }
-}
diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs
index cac2bd0..26160f5 100644
--- a/grapher/Models/Serialized/SettingsManager.cs
+++ b/grapher/Models/Serialized/SettingsManager.cs
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Windows.Forms;
+using System.Threading;
namespace grapher.Models.Serialized
{
@@ -46,29 +47,28 @@ namespace grapher.Models.Serialized
#region Methods
- public void UpdateActiveSettings(DriverSettings settings, Action afterAccelSettingsUpdate = null)
+ public void UpdateActiveSettings(DriverSettings settings)
{
- settings.SendToDriverAndUpdate(ActiveAccel, () =>
- {
- RawAccelSettings.AccelerationSettings = settings;
- RawAccelSettings.GUISettings = new GUISettings
- {
- AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked,
- DPI = (int)DpiField.Data,
- PollRate = (int)PollRateField.Data,
- ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked,
- ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked,
- };
+ ActiveAccel.UpdateFromSettings(settings);
+ SendToDriver(settings);
- RawAccelSettings.Save();
+ RawAccelSettings.AccelerationSettings = settings;
+ RawAccelSettings.GUISettings = new GUISettings
+ {
+ AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked,
+ DPI = (int)DpiField.Data,
+ PollRate = (int)PollRateField.Data,
+ ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked,
+ ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked,
+ };
- afterAccelSettingsUpdate?.Invoke();
- });
+ RawAccelSettings.Save();
}
public void UpdateActiveAccelFromFileSettings(DriverSettings settings)
- {
- settings.SendToDriverAndUpdate(ActiveAccel);
+ {
+ ActiveAccel.UpdateFromSettings(settings);
+ SendToDriver(settings);
DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI);
PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate);
@@ -77,6 +77,11 @@ namespace grapher.Models.Serialized
ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain;
}
+ public static void SendToDriver(DriverSettings settings)
+ {
+ new Thread(() => DriverInterop.SetActiveSettings(settings)).Start();
+ }
+
public void Startup()
{
if (RawAccelSettings.Exists())
@@ -97,7 +102,7 @@ namespace grapher.Models.Serialized
}
RawAccelSettings = new RawAccelSettings(
- DriverSettings.GetActive(),
+ DriverInterop.GetActiveSettings(),
new GUISettings
{
AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked,