switched back to ESP32 and UDP, but without OSC, because serial under windows is a bitch

This commit is contained in:
2026-01-18 05:41:51 +01:00
parent 2311647885
commit a9957bc695
6 changed files with 202 additions and 285 deletions

View File

@@ -9,15 +9,13 @@ public class Telemetry : IDisposable
private const int UpdateRateDefaultMs = 1000;
public int UpdateRateMs => UpdateRateDefaultMs;
private readonly SerialManager serial = new SerialManager();
private readonly UdpSender udp = new UdpSender();
private readonly Computer computer = new Computer();
// Cached hardware references
private IHardware? cpuHw;
private IHardware? gpuHw;
private IHardware? memHw;
// Cached sensors
private ISensor[] cpuLoadSensors = Array.Empty<ISensor>();
private ISensor? cpuTempSensor;
@@ -33,22 +31,11 @@ public class Telemetry : IDisposable
public void Initialize()
{
serial.DiscoverDevice();
// Enable only what we need
computer.IsCpuEnabled = true;
computer.IsGpuEnabled = true;
computer.IsMemoryEnabled = true;
computer.IsMotherboardEnabled = false;
computer.IsControllerEnabled = false;
computer.IsNetworkEnabled = false;
computer.IsStorageEnabled = false;
computer.IsBatteryEnabled = false;
computer.IsPsuEnabled = false;
computer.Open();
CacheHardwareAndSensors();
}
@@ -145,23 +132,8 @@ public class Telemetry : IDisposable
}
}
private static string F(float v) => v.ToString("0.###", CI);
public void UpdateAndSend()
{
if (!serial.IsConnected)
{
serial.DiscoverDevice();
return;
}
if (serial.WatchdogExpired)
{
serial.DiscoverDevice();
return;
}
// Update only the hardware we need
cpuHw?.Update();
gpuHw?.Update();
memHw?.Update();
@@ -173,14 +145,22 @@ public class Telemetry : IDisposable
float gpuTemp = GetGpuTemperaturePercent();
float vram = GetGpuVramPercent();
string cmd =
$"SETALL: {F(cpu)},{F(cpuTemp)},{F(mem)},{F(gpu3d)},{F(gpuTemp)},{F(vram)},0,0";
// Prepare 8 floats (futureproof)
float[] packet =
{
cpu,
cpuTemp,
mem,
gpu3d,
gpuTemp,
vram,
0f, // reserved for future use
0f // reserved for future use
};
serial.SendSetAll(cmd);
udp.SendFloats(packet);
}
// ---------------- METRICS ----------------
private float GetCpuLoadPercent()
{
if (cpuLoadSensors.Length == 0) return 0;
@@ -236,7 +216,7 @@ public class Telemetry : IDisposable
public void Dispose()
{
serial.Dispose();
udp.Dispose();
computer.Close();
}
}