Add basic exception handling

and make MLCore.Add a little bit more flexible
This commit is contained in:
X9VoiD 2020-10-07 03:56:40 +08:00
parent 8a4fc76635
commit bb16d036d5
No known key found for this signature in database
GPG key ID: 3AC5DBB8A2717CFF
3 changed files with 27 additions and 3 deletions

View file

@ -14,7 +14,12 @@ namespace OTDPlugins.MeL.Core
public void Add(Vector2 point)
{
if (AddTimeSeriesPoint(point, TimeNow))
Add(point, TimeNow);
}
public void Add(Vector2 point, DateTime time)
{
if (AddTimeSeriesPoint(point, time))
{
IsReady = true;
var timeMatrix = ConstructTimeDesignMatrix();

View file

@ -1,5 +1,6 @@
using System;
using System.Numerics;
using OpenTabletDriver.Plugin;
using OpenTabletDriver.Plugin.Attributes;
using OpenTabletDriver.Plugin.Tablet;
using OTDPlugins.MeL.Core;
@ -12,8 +13,16 @@ namespace OTDPlugins.MeL
public Vector2 Filter(Vector2 point)
{
Core.Add(point);
try
{
return Core.IsReady ? Core.Predict(DateTime.UtcNow, Offset) : point;
}
catch
{
Log.Write("MeLFilter", "Unknown error in MeLCore", LogLevel.Error);
return point;
}
}
public FilterStage FilterStage => FilterStage.PostTranspose;

View file

@ -1,6 +1,7 @@
#if false
using System.Numerics;
using OpenTabletDriver.Plugin;
using OpenTabletDriver.Plugin.Attributes;
using OpenTabletDriver.Plugin.Tablet.Interpolator;
using OTDPlugins.MeL.Core;
@ -18,8 +19,17 @@ namespace OTDPlugins.MeL
public override void Interpolate(InterpolatorArgs output)
{
if (Core.IsReady)
{
try
{
output.Position = Core.Predict(Core.TimeNow, 0);
}
catch
{
Log.Write("MeLInterp", "Unknown error in MeLCore");
}
}
}
[Property("Samples")]
public int Samples { set => Core.Samples = value; }