Compare commits

...

4 Commits

Author SHA1 Message Date
b837dec116 Reduce refreshrate for console 2024-01-04 20:03:02 +01:00
fccb466bee Add output if AvatarId Changes
Add output for last nil-Message
Add output for Runtime
Remove OSCQuery RefreshServices
2024-01-04 20:02:51 +01:00
bf5d688fd3 Made config readonly 2024-01-04 20:02:37 +01:00
d16d4085fc Add output if AvatarId Changes
Add output for last nil-Message
Add output for Runtime
Remove OSCQuery RefreshServices
2024-01-04 20:02:29 +01:00
2 changed files with 17 additions and 12 deletions

View File

@ -9,11 +9,12 @@ public partial class OSCCollar
{ {
Layout layout = new Layout().SplitRows( Layout layout = new Layout().SplitRows(
new Layout("Top"), new Layout("Top"),
new Layout("Bottom").SplitColumns( new Layout("Middle").SplitColumns(
new Layout("Config-Values"), new Layout("Config-Values"),
new Layout("Variable-Values"), new Layout("Variable-Values"),
new Layout("Position") new Layout("Position")
)); ),
new Layout("Bottom"));
if(OperatingSystem.IsWindows()) if(OperatingSystem.IsWindows())
Console.WindowWidth += 20; Console.WindowWidth += 20;
Table configTable = new Table(); Table configTable = new Table();
@ -36,6 +37,7 @@ public partial class OSCCollar
layout["Config-Values"].Update(configTable); layout["Config-Values"].Update(configTable);
layout["Variable-Values"].Update(variableTable); layout["Variable-Values"].Update(variableTable);
layout["Position"].Update(new Panel(new Text(GetCoordinateSystem()))); 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("Status", "");
variableTable.AddRow("GPS 1", ""); variableTable.AddRow("GPS 1", "");
@ -61,8 +63,9 @@ public partial class OSCCollar
variableTable.Rows.Update(7, 1, new Text($"{GetCalibrationValues().Item1}")); variableTable.Rows.Update(7, 1, new Text($"{GetCalibrationValues().Item1}"));
variableTable.Rows.Update(8, 1, new Text($"{GetCalibrationValues().Item2}")); variableTable.Rows.Update(8, 1, new Text($"{GetCalibrationValues().Item2}"));
layout["Position"].Update(new Panel(new Text(GetCoordinateSystem()))); layout["Position"].Update(new Panel(new Text(GetCoordinateSystem())));
layout["Bottom"].Update(new Text($"{_lastNilMessageSent} AvatarId: {_avatarId} Runtime: {DateTime.Now.Subtract(_programStarted)}"));
displayContext.Refresh(); displayContext.Refresh();
await Task.Delay(100); await Task.Delay(500);
} }
}); });
} }

View File

@ -30,7 +30,7 @@ public partial class OSCCollar
} }
} }
private Config _config; private readonly Config _config;
private readonly int _portReceive; private readonly int _portReceive;
private OSCQueryService? OscQueryService { get; set; } private OSCQueryService? OscQueryService { get; set; }
@ -38,12 +38,13 @@ public partial class OSCCollar
private OscClient _client = null!; private OscClient _client = null!;
private Task _consoleOutputTask; private Task _consoleOutputTask;
private string _avatarId = "";
private float _leashStretch; private float _leashStretch;
private readonly Vector _unitVectorLeash = new(1, 0); private readonly Vector _unitVectorLeash = new(1, 0);
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 readonly DateTime _programStarted = 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!;
@ -106,6 +107,7 @@ public partial class OSCCollar
{ {
this._server = new OscServer(this._portReceive); this._server = new OscServer(this._portReceive);
this._client = new OscClient(this._config.Ip, this._config.PortSend); 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/GPS1", GPS1Handle);
this._server.TryAddMethod("/avatar/parameters/GPS2", GPS2Handle); this._server.TryAddMethod("/avatar/parameters/GPS2", GPS2Handle);
this._server.TryAddMethod("/avatar/parameters/GPS3", GPS3Handle); this._server.TryAddMethod("/avatar/parameters/GPS3", GPS3Handle);
@ -131,16 +133,22 @@ public partial class OSCCollar
.AdvertiseOSC() .AdvertiseOSC()
.AdvertiseOSCQuery() .AdvertiseOSCQuery()
.Build(); .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/GPS1", Attributes.AccessValues.WriteOnly);
this.OscQueryService.AddEndpoint<float>("/avatar/parameters/GPS2", 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/GPS3", Attributes.AccessValues.WriteOnly);
this.OscQueryService.AddEndpoint<float>("/avatar/parameters/Leash_Stretch", 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.AddEndpoint<bool>("/avatar/parameters/Leash_Toggle", Attributes.AccessValues.WriteOnly);
this.OscQueryService.RefreshServices();
} }
#endregion #endregion
#region Handle OSC-Messages #region Handle OSC-Messages
private void AvatarChangeHandle(OscMessageValues messageValues)
{
this._avatarId = messageValues.ReadStringElement(0);
}
private void AllowMovingHandle(OscMessageValues messageValues) private void AllowMovingHandle(OscMessageValues messageValues)
{ {
this._allowMoving = messageValues.ReadBooleanElement(0); this._allowMoving = messageValues.ReadBooleanElement(0);
@ -210,12 +218,6 @@ 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);
} }
} }