diff options
| author | JacobPalecki <[email protected]> | 2020-08-31 23:03:46 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-31 23:03:46 -0700 |
| commit | 471fe599bab6ba0632ddd1dacd20c7fc42db0eee (patch) | |
| tree | 90a82ee14dbb112621657efbd2523ed35f59d154 /grapher/Models/Serialized/DriverSettings.cs | |
| parent | Merge pull request #16 from JacobPalecki/Misc (diff) | |
| parent | add independent xy accel to driver (diff) | |
| download | rawaccel-471fe599bab6ba0632ddd1dacd20c7fc42db0eee.tar.xz rawaccel-471fe599bab6ba0632ddd1dacd20c7fc42db0eee.zip | |
Merge pull request #17 from a1xd/indep
Indep
Diffstat (limited to 'grapher/Models/Serialized/DriverSettings.cs')
| -rw-r--r-- | grapher/Models/Serialized/DriverSettings.cs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs new file mode 100644 index 0000000..91d7e9f --- /dev/null +++ b/grapher/Models/Serialized/DriverSettings.cs @@ -0,0 +1,87 @@ +using System; +using System.Runtime.InteropServices; + +namespace grapher.Models.Serialized +{ + public enum AccelMode + { + linear, classic, natural, logarithmic, sigmoid, naturalgain, sigmoidgain, power, noaccel + } + + [StructLayout(LayoutKind.Sequential)] + public struct AccelArgs + { + public double offset; + public double accel; + public double limit; + public double exponent; + public double midpoint; + public double powerScale; + public double powerExponent; + public double weight; + public double rate; + public double scaleCap; + public double gainCap; + }; + + [StructLayout(LayoutKind.Sequential)] + public struct Vec2 <T> + { + public T x; + public T y; + } + + [StructLayout(LayoutKind.Sequential)] + [Serializable] + public class DriverSettings + { + private static readonly IntPtr UnmanagedSettingsHandle = + Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>()); + + public double rotation; + public bool combineMagnitudes; + public Vec2<AccelMode> modes; + public Vec2<AccelArgs> args; + public Vec2<double> sensitivity; + public double minimumTime; + + public static DriverSettings GetActive() + { + DriverInterop.GetActiveSettings(UnmanagedSettingsHandle); + return Marshal.PtrToStructure<DriverSettings>(UnmanagedSettingsHandle); + } + + public static void SetActive(DriverSettings settings) + { + Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false); + DriverInterop.SetActiveSettings(UnmanagedSettingsHandle); + } + + public void SendToDriver() + { + SetActive(this); + } + + public void SendToDriverAndUpdate(ManagedAccel accel) + { + SendToDriver(); + accel.UpdateFromSettings(UnmanagedSettingsHandle); + } + + public bool verify() + { + /* + if (args.accel < 0 || args.rate < 0) + bad_arg("accel can not be negative, use a negative weight to compensate"); + if (args.rate > 1) bad_arg("rate can not be greater than 1"); + if (args.exponent <= 1) bad_arg("exponent must be greater than 1"); + if (args.limit <= 1) bad_arg("limit must be greater than 1"); + if (args.power_scale <= 0) bad_arg("scale must be positive"); + if (args.power_exp <= 0) bad_arg("exponent must be positive"); + if (args.midpoint < 0) bad_arg("midpoint must not be negative"); + if (args.time_min <= 0) bad_arg("min time must be positive"); + */ + return true; + } + } +} |