refresh osc services every 10 seconds

This commit is contained in:
Glax 2024-01-03 20:49:39 +01:00
parent 950168e856
commit 0857a4763c

View File

@ -43,6 +43,7 @@ public partial class OSCCollar
private Vector _movementVector = new(0, 0); private Vector _movementVector = new(0, 0);
private bool _allowMoving = true; private bool _allowMoving = true;
private DateTime _lastNilMessageSent = DateTime.UnixEpoch; private DateTime _lastNilMessageSent = DateTime.UnixEpoch;
private DateTime _lastOSCRefresh = DateTime.Now;
private static readonly TimeSpan UpdateInterval = TimeSpan.FromMilliseconds(10); private static readonly TimeSpan UpdateInterval = TimeSpan.FromMilliseconds(10);
private static readonly TimeSpan MessageMinInterval = TimeSpan.FromMilliseconds(400); private static readonly TimeSpan MessageMinInterval = TimeSpan.FromMilliseconds(400);
private GPS _gps1 = null!, _gps2 = null!, _gps3 = null!; private GPS _gps1 = null!, _gps2 = null!, _gps3 = null!;
@ -209,6 +210,12 @@ public partial class OSCCollar
this._client.Send("/input/Horizontal", Convert.ToSingle(_movementVector.X)); this._client.Send("/input/Horizontal", Convert.ToSingle(_movementVector.X));
} }
if (_lastOSCRefresh.Add(TimeSpan.FromSeconds(10)) > DateTime.Now)
{
this.OscQueryService?.RefreshServices();
_lastOSCRefresh = DateTime.Now;
}
Thread.Sleep(UpdateInterval); Thread.Sleep(UpdateInterval);
} }
} }