diff options
| author | Jacob Palecki <[email protected]> | 2021-04-01 21:01:41 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2021-04-01 21:01:41 -0700 |
| commit | 70382da847f2a9f4353ea2f981199f832c600ca4 (patch) | |
| tree | 76f4244d9e892f1f49aaa37c83a1c4b2e1711aae | |
| parent | use callbacks for applying accel (diff) | |
| download | rawaccel-70382da847f2a9f4353ea2f981199f832c600ca4.tar.xz rawaccel-70382da847f2a9f4353ea2f981199f832c600ca4.zip | |
Add lookuptable json
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 4 | ||||
| -rw-r--r-- | grapher/Models/Serialized/LookupTable.cs | 67 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 2 |
3 files changed, 70 insertions, 3 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 3a30a9b..4c4b598 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -45,7 +45,7 @@ namespace grapher ToggleButton.Click += new System.EventHandler(OnToggleButtonClick); AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose); - ButtonTimerInterval = Convert.ToInt32(DriverInterop.WriteDelayMs); + ButtonTimerInterval = Convert.ToInt32(DriverSettings.WriteDelayMs); ButtonTimer = new Timer(); ButtonTimer.Tick += new System.EventHandler(OnButtonTimerTick); @@ -62,7 +62,7 @@ namespace grapher } else { - DriverSettings active = DriverInterop.GetActiveSettings(); + DriverSettings active = ManagedAccel.GetActive().Settings; bool activeNotDefault = !RawAccelSettings.IsDefaultEquivalent(active); LastToggleChecked = activeNotDefault; diff --git a/grapher/Models/Serialized/LookupTable.cs b/grapher/Models/Serialized/LookupTable.cs new file mode 100644 index 0000000..578c5bf --- /dev/null +++ b/grapher/Models/Serialized/LookupTable.cs @@ -0,0 +1,67 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Serialized +{ + [Serializable] + public class LookupTable + { + [Serializable] + public class Point + { + public Point(double x, double y) + { + X = x; + Y = y; + } + + double X { get; set; } + + double Y { get; set; } + } + + public LookupTable(Point[] points) + { + Points = points; + } + + public Point[] Points { get; } + + public bool InSensGraph { get; } + + public static LookupTable Deserialize(string lutFile) + { + if (!File.Exists(lutFile)) + { + throw new Exception($"LUT file does not exist at {lutFile}."); + } + + JObject lutJObject = JObject.Parse(File.ReadAllText(lutFile)); + + var lut = lutJObject.ToObject<LookupTable>(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); + + if (lut is null || lut.Points is null) + { + throw new Exception($"{lutFile} does not contain valid lookuptable json."); + } + + lut.Verify(); + + return lut; + } + + private void Verify() + { + if (Points.Length >= short.MaxValue) + { + throw new Exception($"LUT file with {Points.Length} points is too long. Max points: {short.MaxValue}"); + } + } + } +} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 40652dd..3773a9e 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -85,7 +85,7 @@ namespace grapher.Models.Serialized public static void SendToDriver(DriverSettings settings) { - new Thread(() => DriverInterop.Write(settings)).Start(); + new Thread(() => settings.ToFile()).Start(); } public static SettingsErrors SendToDriverSafe(DriverSettings settings) |