From d16d4085fccee1e4c88b232c84ee48c34a61182e Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 4 Jan 2024 20:02:29 +0100 Subject: [PATCH] Add output if AvatarId Changes Add output for last nil-Message Add output for Runtime Remove OSCQuery RefreshServices --- OSCCollar/ConsoleOutput.cs | 7 +++++-- OSCCollar/OSCCollar.cs | 16 +++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/OSCCollar/ConsoleOutput.cs b/OSCCollar/ConsoleOutput.cs index 4f6c165..1622195 100644 --- a/OSCCollar/ConsoleOutput.cs +++ b/OSCCollar/ConsoleOutput.cs @@ -9,11 +9,12 @@ public partial class OSCCollar { Layout layout = new Layout().SplitRows( new Layout("Top"), - new Layout("Bottom").SplitColumns( + new Layout("Middle").SplitColumns( new Layout("Config-Values"), new Layout("Variable-Values"), new Layout("Position") - )); + ), + new Layout("Bottom")); if(OperatingSystem.IsWindows()) Console.WindowWidth += 20; Table configTable = new Table(); @@ -36,6 +37,7 @@ public partial class OSCCollar layout["Config-Values"].Update(configTable); layout["Variable-Values"].Update(variableTable); layout["Position"].Update(new Panel(new Text(GetCoordinateSystem()))); + layout["Bottom"].Update(new Text($"{_lastNilMessageSent} AvatarId: {_avatarId} Runtime: {DateTime.Now.Subtract(_programStarted)}")); variableTable.AddRow("Status", ""); variableTable.AddRow("GPS 1", ""); @@ -61,6 +63,7 @@ public partial class OSCCollar variableTable.Rows.Update(7, 1, new Text($"{GetCalibrationValues().Item1}")); variableTable.Rows.Update(8, 1, new Text($"{GetCalibrationValues().Item2}")); layout["Position"].Update(new Panel(new Text(GetCoordinateSystem()))); + layout["Bottom"].Update(new Text($"{_lastNilMessageSent} AvatarId: {_avatarId} Runtime: {DateTime.Now.Subtract(_programStarted)}")); displayContext.Refresh(); await Task.Delay(100); } diff --git a/OSCCollar/OSCCollar.cs b/OSCCollar/OSCCollar.cs index a7c50aa..94a0780 100644 --- a/OSCCollar/OSCCollar.cs +++ b/OSCCollar/OSCCollar.cs @@ -38,6 +38,7 @@ public partial class OSCCollar private OscClient _client = null!; private Task _consoleOutputTask; + private string _avatarId = ""; private float _leashStretch; private readonly Vector _unitVectorLeash = new(1, 0); private Vector _movementVector = new(0, 0); @@ -106,6 +107,7 @@ public partial class OSCCollar { this._server = new OscServer(this._portReceive); this._client = new OscClient(this._config.Ip, this._config.PortSend); + this._server.TryAddMethod("/avatar/change", AvatarChangeHandle); this._server.TryAddMethod("/avatar/parameters/GPS1", GPS1Handle); this._server.TryAddMethod("/avatar/parameters/GPS2", GPS2Handle); this._server.TryAddMethod("/avatar/parameters/GPS3", GPS3Handle); @@ -131,16 +133,22 @@ public partial class OSCCollar .AdvertiseOSC() .AdvertiseOSCQuery() .Build(); + this.OscQueryService.AddEndpoint("/avatar/change", Attributes.AccessValues.WriteOnly); this.OscQueryService.AddEndpoint("/avatar/parameters/GPS1", Attributes.AccessValues.WriteOnly); this.OscQueryService.AddEndpoint("/avatar/parameters/GPS2", Attributes.AccessValues.WriteOnly); this.OscQueryService.AddEndpoint("/avatar/parameters/GPS3", Attributes.AccessValues.WriteOnly); this.OscQueryService.AddEndpoint("/avatar/parameters/Leash_Stretch", Attributes.AccessValues.WriteOnly); this.OscQueryService.AddEndpoint("/avatar/parameters/Leash_Toggle", Attributes.AccessValues.WriteOnly); - this.OscQueryService.RefreshServices(); } #endregion #region Handle OSC-Messages + + private void AvatarChangeHandle(OscMessageValues messageValues) + { + this._avatarId = messageValues.ReadStringElement(0); + } + private void AllowMovingHandle(OscMessageValues messageValues) { this._allowMoving = messageValues.ReadBooleanElement(0); @@ -209,12 +217,6 @@ public partial class OSCCollar this._client.Send("/input/Vertical", Convert.ToSingle(_movementVector.Y)); 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); }