Spectre Console

This commit is contained in:
Glax 2024-01-02 18:33:41 +01:00
parent f522950ef7
commit d10a4483ed
4 changed files with 838 additions and 73 deletions

718
OSCCollar/Alligator.flf Normal file
View File

@ -0,0 +1,718 @@
flf2a$ 7 7 26 32 3
Alligator by Simon Bradley <syb3@aber.ac.uk>
17th June, 1994
$ $@
$ $@
$ $@
$ $@
$ $@
$ $@
$ $@@
:::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
$ $ @
###$ @@
::: :::$@
:+: :+:$ @
$ $ @
$ $ @
$ $ @
$ $ @
$ $ @@
::: :::$ @
:+: :+:$ @
+:+:+:+:+:+:+:+$@
+#+ +:+$ @
+#+#+#+#+#+#+#+$ @
#+# #+#$ @
### ###$ @@
:::$ @
:+:+:+:+:$@
+:+ +:+$ @
+#++:++#+$ @
+#+ +#+$ @
#+#+#+#+#$ @
###$ @@
::: :::$ @
:+: :+:$ @
+:+$ @
+#+$ @
+#+$ @
#+# #+#$@
### ###$ @@
:::::::$ @
:+: :+:$ @
+:+ +:+$ @
+#++: ++#$@
+#+ +#+#+#$ @
#+# #+#+$ @
##########$ @@
:::$@
:+$ @
$$ @
$$ @
$$ @
$$ @
$$ @@
:::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
###$ @@
:::$@
:+:$@
+:+$@
+#+$ @
+#+$ @
#+#$ @
###$ @@
$ $ $ $@
:+: :+:$@
+:+ +:+$ @
+#++:++#++:++$ @
+#+ +#+$ @
#+# #+#$ @
$ $ $ $ @@
$ $ @
:+:$ @
+:+$ @
+#++:++#++:++$@
+#+$ @
#+#$ @
$ $ @@
$ $@
$ $ @
$ $ @
$ $ @
$ $ @
#+#$ @
##$ @@
$ $@
$ $ @
$ $ @
+#++:++#++:++$ @
$ $ @
$ $ @
$ $ @@
$ $@
$ $ @
$ $ @
$ $ @
$ $ @
#+#$ @
###$ @@
:::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
###$ @@
:::::::$@
:+: :+:$@
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
#######$ @@
:::$@
:+:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
#######$ @@
::::::::$@
:+: :+:$@
$ +:+$ @
$ +#+$ @
$ +#+$ @
#+#$ @
##########$ @@
::::::::$@
:+: :+:$@
$ +:+$ @
$ +#++:$ @
$ +#+$ @
#+# #+#$ @
########$ @@
:::$@
:+:$ @
+:+ +:+$@
+#+ +:+$ @
+#+#+#+#+#+$@
#+#$ @
###$ @@
::::::::::$@
:+: :+:$ @
+:+ $ @
+#++:++#+$ @
$ +#+$ @
#+# #+#$ @
########$ @@
::::::::$@
:+: :+:$@
+:+ $ @
+#++:++#+$ @
+#+ +#+$ @
#+# #+#$ @
########$ @@
:::::::::::$@
:+: :+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
###$ @@
::::::::$@
:+: :+:$@
+:+ +:+$ @
+#++:++#$ @
+#+ +#+$ @
#+# #+#$ @
########$ @@
::::::::$@
:+: :+:$@
+:+ +:+$ @
+#++:++#+$ @
$ +#+$ @
#+# #+#$ @
########$ @@
$ $@
:+:$@
$ $ @
$ $ @
$ $ @
#+#$ @
$ $ @@
$ $@
:+:$@
$ $ @
$ $ @
$ $ @
#+#$ @
##$ @@
:::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
###$ @@
$ $@
$ $ @
+:+:+:+:+:+:+$ @
$ $ @
+#+#+#+#+#+#+$ @
$ $ @
$ $ @@
:::$@
:+:$@
+:+$@
+#+$@
+#+$ @
#+#$ @
###$ @@
:::::::::$@
:+: :+:$@
+:+$ @
+#+$ @
+#+$ @
$ $ @
###$ @@
:::::::::::$ @
:+: :+:+:+:+:+:$@
+:+ +:+ +:+ +:+$@
+#+ +:+ +#+ +:+$ @
+#+ +#+ +#+ +#+$ @
#+# #+#+#+#+#+$ @
#####$ @@
:::$ @
:+: :+:$@
+:+ +:+$@
+#++:++#++:$@
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
:::::::::$@
:+: :+:$@
+:+ +:+$ @
+#++:++#+$ @
+#+ +#+$ @
#+# #+#$ @
#########$ @@
::::::::$@
:+: :+:$@
+:+ $ @
+#+ $ @
+#+ $ @
#+# #+#$ @
########$ @@
:::::::::$@
:+: :+:$@
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
#########$ @@
::::::::::$@
:+:$ @
+:+$ @
+#++:++#$ @
+#+$ @
#+#$ @
##########$ @@
::::::::::$@
:+:$ @
+:+$ @
:#::+::#$ @
+#+$ @
#+#$ @
###$ @@
::::::::$@
:+: :+:$@
+:+ $ @
:#: $ @
+#+ +#+#$ @
#+# #+#$ @
########$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#++:++#++$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
:::::::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
###########$ @@
:::::::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+# #+#$ @
#####$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#++:++$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
:::$ @
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
##########$@@
::: :::$@
:+:+: :+:+:$@
+:+ +:+:+ +:+$@
+#+ +:+ +#+$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
:::: :::$@
:+:+: :+:$ @
:+:+:+ +:+$ @
+#+ +:+ +#+$ @
+#+ +#+#+#$ @
#+# #+#+#$ @
### ####$ @@
::::::::$@
:+: :+:$@
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
########$ @@
:::::::::$@
:+: :+:$@
+:+ +:+$ @
+#++:++#+$ @
+#+$ @
#+#$ @
###$ @@
::::::::$@
:+: :+:$@
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
###########$ @@
:::::::::$@
:+: :+:$@
+:+ +:+$ @
+#++:++#:$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
::::::::$@
:+: :+:$@
+:+ $ @
+#++:++#++$ @
$ +#+$ @
#+# #+#$ @
########$ @@
:::::::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
###$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
########$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+#+#+#$ @
###$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#+ +:+ +#+$ @
+#+ +#+#+ +#+$ @
#+#+# #+#+#$ @
### ###$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#++:+$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#++:$ @
+#+$ @
#+#$ @
###$ @@
:::::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
#########$ @@
::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
######$ @@
:::$@
:+:$@
+:+$@
+#+$@
+#+$@
#+#$@
###$@@
::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
######$ @@
:::$ @
:+: :+:$ @
+:+ +:+$@
$ $ @
$ $ @
$ $ @
$ $ @@
$ $@
$ $ @
$ $ @
$ $ @
$ $ @
$ $ @
##########$ @@
:::$@
:+$ @
$$ @
$$ @
$$ @
$$ @
$$ @@
:::$ @
:+: :+:$@
+:+ +:+$@
+#++:++#++:$@
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
:::::::::$@
:+: :+:$@
+:+ +:+$ @
+#++:++#+$ @
+#+ +#+$ @
#+# #+#$ @
#########$ @@
::::::::$@
:+: :+:$@
+:+ $ @
+#+ $ @
+#+ $ @
#+# #+#$ @
########$ @@
:::::::::$@
:+: :+:$@
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
#########$ @@
::::::::::$@
:+:$ @
+:+$ @
+#++:++#$ @
+#+$ @
#+#$ @
##########$ @@
::::::::::$@
:+:$ @
+:+$ @
:#::+::#$ @
+#+$ @
#+#$ @
###$ @@
::::::::$@
:+: :+:$@
+:+ $ @
:#: $ @
+#+ +#+#$ @
#+# #+#$ @
########$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#++:++#++$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
:::::::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
###########$ @@
:::::::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+# #+#$ @
#####$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#++:++$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
:::$ @
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
##########$@@
::: :::$@
:+:+: :+:+:$@
+:+ +:+:+ +:+$@
+#+ +:+ +#+$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
:::: :::$@
:+:+: :+:$ @
:+:+:+ +:+$ @
+#+ +:+ +#+$ @
+#+ +#+#+#$ @
#+# #+#+#$ @
### ####$ @@
::::::::$@
:+: :+:$@
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
########$ @@
:::::::::$@
:+: :+:$@
+:+ +:+$ @
+#++:++#+$ @
+#+$ @
#+#$ @
###$ @@
::::::::$@
:+: :+:$@
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
###########$ @@
:::::::::$@
:+: :+:$@
+:+ +:+$ @
+#++:++#:$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
::::::::$@
:+: :+:$@
+:+ $ @
+#++:++#++$ @
$ +#+$ @
#+# #+#$ @
########$ @@
:::::::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
###$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+# #+#$ @
########$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#+ +:+$ @
+#+ +#+$ @
#+#+#+#$ @
###$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#+ +:+ +#+$ @
+#+ +#+#+ +#+$ @
#+#+# #+#+#$ @
### ###$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#++:+$ @
+#+ +#+$ @
#+# #+#$ @
### ###$ @@
::: :::$@
:+: :+:$ @
+:+ +:+$ @
+#++:$ @
+#+$ @
#+#$ @
###$ @@
:::::::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
#########$ @@
::::$@
:+:$ @
+:+$ @
+#+$ @
+#+$ @
#+#$ @
####$ @@
:::$@
:+:$ @
+:+$ @
$ $ @
+#+$ @
#+#$ @
###$ @@
::::$@
:+:$@
+:+$ @
+#+$@
+#+$ @
#+#$ @
####$ @@
::::: :::$@
:+: :+:+:$ @
$ $ @
$ $ @
$ $ @
$ $ @
$ $ @@
@
@
@
@
@
@
@@
@
@
@
@
@
@
@@
@
@
@
@
@
@
@@
@
@
@
@
@
@
@@
@
@
@
@
@
@
@@
@
@
@
@
@
@
@@
@
@
@
@
@
@
@@

111
OSCCollar/ConsoleOutput.cs Normal file
View File

@ -0,0 +1,111 @@
using Spectre.Console;
namespace VRC_Console;
public partial class OSCCollar
{
private const byte CoordinateSystemSize = 16;
private void SetupConsoleOutput()
{
Layout layout = new Layout().SplitRows(
new Layout("Top"),
new Layout("Bottom").SplitColumns(
new Layout("Config-Values"),
new Layout("Variable-Values"),
new Layout("Position")
));
Table configTable = new Table();
configTable.AddColumn("ConVar");
configTable.AddColumn("Value");
configTable.AddRow("IP", this._config.Ip);
configTable.AddRow("Send-Osc-Port", this._config.PortSend.ToString());
configTable.AddRow("Receive-Osc-Port", _portReceive.ToString());
configTable.AddRow("HTTP-Port", this.OscQueryService?.TcpPort.ToString() ?? "");
Table variableTable = new Table();
variableTable.AddColumn("OscVar");
variableTable.AddColumn("Value");
layout["Top"].Update(new FigletText(FigletFont.Load("Alligator.flf"), "OSC Collar").LeftJustified());
layout["Config-Values"].Update(configTable);
layout["Variable-Values"].Update(variableTable);
layout["Position"].Update(new Panel(new Text(GetCoordinateSystem())));
variableTable.AddRow("Status", $"{(_allowMoving ? "enabled" : "disabled")}");
variableTable.AddRow("GPS 1", $"{_gps1.Distance:00.00000}");
variableTable.AddRow("GPS 2", $"{_gps2.Distance:00.00000}");
variableTable.AddRow("GPS 3", $"{_gps3.Distance:00.00000}");
variableTable.AddRow("Position Vector", $"{_unitVectorLeash}");
variableTable.AddRow("Leash Stretch", $"{_leashStretch:0.00000}");
variableTable.AddRow("Movement Vector", $"{_movementVector}");
AnsiConsole.Live(layout).StartAsync(async displayContext =>
{
while (true)
{
variableTable.Rows.Update(0, 1, new Text($"{(_allowMoving ? "enabled" : "disabled")}"));
variableTable.Rows.Update(1, 1, new Text($"{_gps1.Distance:00.00000}"));
variableTable.Rows.Update(2, 1, new Text($"{_gps2.Distance:00.00000}"));
variableTable.Rows.Update(3, 1, new Text($"{_gps3.Distance:00.00000}"));
variableTable.Rows.Update(4, 1, new Text($"{_unitVectorLeash}"));
variableTable.Rows.Update(5, 1, new Text($"{_leashStretch:0.00000}"));
variableTable.Rows.Update(6, 1, new Text($"{_movementVector}"));
layout["Position"].Update(new Panel(new Text(GetCoordinateSystem())));
displayContext.Refresh();
await Task.Delay(100);
}
});
}
private String GetCoordinateSystem()
{
string system = "";
byte width = CoordinateSystemSize;
byte height = CoordinateSystemSize / 2;
int positionX = Convert.ToInt32(Math.Floor(_unitVectorLeash.X * (width / 2.0))) + (width / 2);
int positionY = Convert.ToInt32(-Math.Floor(_unitVectorLeash.Y * (height / 2.0))) + (height / 2);
int movementX = Convert.ToInt32(Math.Floor(_movementVector.X * (width / 2.0))) + (width / 2);
int movementY = Convert.ToInt32(-Math.Floor(_movementVector.Y * (height / 2.0))) + (height / 2);
for (int y = 0; y <= height; y++)
{
for (int x = 0; x <= width; x++)
{
if (x == movementX && y == movementY)
{
system += "x";
continue;
}
if (x == positionX && y == positionY)
{
system += "x";
continue;
}
if (y == height / 2)
{
if (x == width / 2)
system += "+";
else
system += "-";
}
else
{
if (x == width / 2)
system += "|";
else
system += " ";
}
}
if (y != height)
system += "\n";
}
return system;
}
}

View File

@ -6,7 +6,7 @@ using Extensions = VRC.OSCQuery.Extensions;
namespace VRC_Console;
public class OSCCollar
public partial class OSCCollar
{
private static readonly string ConfigFilePath = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
@ -41,15 +41,11 @@ public class OSCCollar
private readonly Vector _unitVectorLeash = new(1, 0);
private Vector _movementVector = new(0, 0);
private bool _allowMoving = true;
private uint _nilSentCount;
private DateTime _lastNilMessageSent = DateTime.UnixEpoch;
private DateTime _lastConsoleOutput = DateTime.UnixEpoch;
private static readonly TimeSpan ConsoleUpdateInterval = TimeSpan.FromMilliseconds(500);
private static readonly TimeSpan UpdateInterval = TimeSpan.FromMilliseconds(10);
private static readonly TimeSpan MessageMinInterval = TimeSpan.FromMilliseconds(400);
private GPS _gps1 = null!, _gps2 = null!, _gps3 = null!;
private readonly Queue<ValueTuple<double, double>> _calibrationAverage = new();
private string _debugValue = "";
private double _constantA, _constantB, _constantC, _constantD, _constantE;
private OSCCollar(Config config, bool skipSetup = true)
@ -57,6 +53,7 @@ public class OSCCollar
this._config = config;
File.WriteAllText(ConfigFilePath, JsonConvert.SerializeObject(this._config));
this.SetupGPSVars();
if (!skipSetup)
{
@ -71,6 +68,7 @@ public class OSCCollar
this._portReceive = Extensions.GetAvailableUdpPort();
this.SetupOSCServer();
this.SetupOSCQuery();
this.SetupConsoleOutput();
}
private OSCCollar(string ip = "127.0.0.1", int portSend = 9000, double radius = 100, double calibrationX = 0,
@ -89,67 +87,6 @@ public class OSCCollar
}
private void PrintOutput()
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"OSC Collar - Status: {(_allowMoving ? "enabled" : "disabled")} IP: {this._config.Ip} Send-OSC: {this._config.PortSend} Receive-OSC: {_portReceive} OSC-HTTP: {this.OscQueryService?.TcpPort}");
Console.WriteLine("==============================");
Console.WriteLine($"GPS 1:................{_gps1.Distance:00.00000}");
Console.WriteLine($"GPS 2:................{_gps2.Distance:00.00000}");
Console.WriteLine($"GPS 3:................{_gps3.Distance:00.00000}");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"Position Vector:......{_unitVectorLeash}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"Stretch:..............{_leashStretch:0.00000}");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Movement Vector:......{_movementVector}");
Console.ForegroundColor = ConsoleColor.Gray;
ValueTuple<double, double> calibrationValues = GetCalibrationValues();
Console.WriteLine($"Calibration (x y): ...({calibrationValues.Item1:' '00.0000;'-'00.0000} {calibrationValues.Item2:' '00.0000;'-'00.0000})");
Console.ForegroundColor = ConsoleColor.White;
string nilString = $"/input nil {_nilSentCount}";
Console.SetCursorPosition(Console.WindowWidth - nilString.Length - 1, 0);
Console.Write(nilString);
Console.ForegroundColor = ConsoleColor.DarkGray;
if (Console.WindowHeight < 13)
return;
Console.SetCursorPosition(43, 5);
Console.WriteLine("----------+----------");
for (int i = 1; i < 10; i++)
{
if(i == 5)
continue;
Console.SetCursorPosition(53,i);
Console.Write("|");
}
const int centerX = 53;
const int centerY = 5;
int positionX = Convert.ToInt32(Math.Floor(_unitVectorLeash.X * 10));
int positionY = Convert.ToInt32(-Math.Floor(_unitVectorLeash.Y * 4));
double positionPrecision = (_unitVectorLeash.Y * 10) % 10;
char positionPrecisionChar = positionPrecision < 3 ? '.' : positionPrecision > 7 ? '\'' : 'x';
Console.SetCursorPosition(centerX + positionX, centerY + positionY);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(positionPrecisionChar);
int movementX = Convert.ToInt32(Math.Floor(_movementVector.X * 10));
int movementY = Convert.ToInt32(-Math.Floor(_movementVector.Y * 4));
double movementPrecision = (_movementVector.Y * 10) % 10;
char movementPrecisionChar = movementPrecision < 3 ? '.' : movementPrecision > 7 ? '\'' : 'x';
Console.SetCursorPosition(centerX + movementX, centerY + movementY);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(movementPrecisionChar);
Console.SetCursorPosition(Console.WindowWidth - _debugValue.Length - 1, Console.WindowHeight - 2);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(_debugValue);
}
#region Setup
private void SetupGPSVars()
{
@ -265,18 +202,11 @@ public class OSCCollar
this._client.Send("/input/Vertical", 0f);
this._client.Send("/input/Horizontal", 0f);
this._lastNilMessageSent = DateTime.Now;
_nilSentCount++;
}else if (_allowMoving)
{
this._client.Send("/input/Vertical", Convert.ToSingle(_movementVector.Y));
this._client.Send("/input/Horizontal", Convert.ToSingle(_movementVector.X));
}
if (_lastConsoleOutput.Add(ConsoleUpdateInterval) < DateTime.Now)
{
PrintOutput();
_lastConsoleOutput = DateTime.Now;
}
Thread.Sleep(UpdateInterval);
}

View File

@ -22,4 +22,10 @@
</Reference>
</ItemGroup>
<ItemGroup>
<None Update="Alligator.flf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>