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 /grapher/Models/Serialized | |
| parent | use callbacks for applying accel (diff) | |
| download | rawaccel-70382da847f2a9f4353ea2f981199f832c600ca4.tar.xz rawaccel-70382da847f2a9f4353ea2f981199f832c600ca4.zip | |
Add lookuptable json
Diffstat (limited to 'grapher/Models/Serialized')
| -rw-r--r-- | grapher/Models/Serialized/LookupTable.cs | 67 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 2 |
2 files changed, 68 insertions, 1 deletions
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) |