Add output if AvatarId Changes

Add output for last nil-Message
Add output for Runtime
Remove OSCQuery RefreshServices
This commit is contained in:
Glax 2024-01-04 20:02:29 +01:00
parent 0857a4763c
commit d16d4085fc
2 changed files with 14 additions and 9 deletions

View File

@ -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);
}

View File

@ -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<string>("/avatar/change", Attributes.AccessValues.WriteOnly);
this.OscQueryService.AddEndpoint<float>("/avatar/parameters/GPS1", Attributes.AccessValues.WriteOnly);
this.OscQueryService.AddEndpoint<float>("/avatar/parameters/GPS2", Attributes.AccessValues.WriteOnly);
this.OscQueryService.AddEndpoint<float>("/avatar/parameters/GPS3", Attributes.AccessValues.WriteOnly);
this.OscQueryService.AddEndpoint<float>("/avatar/parameters/Leash_Stretch", Attributes.AccessValues.WriteOnly);
this.OscQueryService.AddEndpoint<bool>("/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);
}