Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey004 committed Nov 23, 2024
1 parent 8f41301 commit b04a71d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Quest2-VRC.Core/Services/RGBController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public static void SendRGBRawData(int R, int G, int B)

for (int i = 0; i < devices.Length; i++)
{
var leds = Enumerable.Range(0, devices[i].Colors.Length)
var leds = Enumerable.Range(0, devices[i].Colors.Length)
.Select(_ => new Color(R_Byte,G_Byte,B_Byte))
.ToArray();
client.UpdateLeds(i, leds);
client.UpdateLeds(i, leds);
}
}

Expand Down
48 changes: 31 additions & 17 deletions Quest2-VRC.Core/Services/Receiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Quest2_VRC.Services;
using System;
using System.Collections.Concurrent;
using System.Timers;
using System.IO;
using System.Linq;
using System.Net;
Expand All @@ -23,9 +24,15 @@ public class Receiver
private static readonly string B = "/avatar/parameters/B";
private static readonly ConcurrentDictionary<string, int> rgbBuffer = new();
private static readonly string[] rgbAddresses = { "/avatar/parameters/R", "/avatar/parameters/G", "/avatar/parameters/B" };
private static readonly Timer processTimer = new(230);
public static async void Run()
{
RGBController.SendRGBRawData(0, 195, 255); // Init OpenRGB
{
processTimer.Elapsed += ProcessBufferedData;
processTimer.AutoReset = true;
processTimer.Start();

RGBController.SendRGBRawData(255,255,255); // Init OpenRGB
await Task.Delay(20);
RGBController.SendRGBRawData(0, 0, 0); // Set to Black
var tcpPort = Extensions.GetAvailableTcpPort();
var udpPort = Extensions.GetAvailableUdpPort();
Expand Down Expand Up @@ -58,29 +65,34 @@ public static async void Run()
await Task.Delay(3000);
}

private static void oscServer_MessageReceived(object sender, OscMessageReceivedEventArgs e)
private static void ProcessBufferedData(object sender, ElapsedEventArgs e)
{
OscMessage message = e.Message;

if (rgbAddresses.Contains(message.Address) && message.Data[0] is int intValue)
{

rgbBuffer[message.Address] = intValue;
if (rgbBuffer.Count == 0) return;


int r = rgbBuffer.ContainsKey("/avatar/parameters/R") ? rgbBuffer["/avatar/parameters/R"] : 0;
int g = rgbBuffer.ContainsKey("/avatar/parameters/G") ? rgbBuffer["/avatar/parameters/G"] : 0;
int b = rgbBuffer.ContainsKey("/avatar/parameters/B") ? rgbBuffer["/avatar/parameters/B"] : 0;

if (rgbBuffer.Count == rgbAddresses.Length)
{
Console.WriteLine($"Processing RGB: R={r}, G={g}, B={b}");

int r = rgbBuffer["/avatar/parameters/R"];
int g = rgbBuffer["/avatar/parameters/G"];
int b = rgbBuffer["/avatar/parameters/B"];

ProcessRGB(r, g, b);


rgbBuffer.Clear();
}

ProcessRGB(r, g, b);
private static void oscServer_MessageReceived(object sender, OscMessageReceivedEventArgs e)
{
OscMessage message = e.Message;

if (rgbAddresses.Contains(message.Address) && message.Data[0] is int intValue)
{

rgbBuffer[message.Address] = intValue;

rgbBuffer.Clear();
}
Console.WriteLine($"Received {message.Address}: {intValue}");
}
else
{
Expand All @@ -90,8 +102,10 @@ private static void oscServer_MessageReceived(object sender, OscMessageReceivedE

private static void ProcessRGB(int r, int g, int b)
{

Console.WriteLine($"Received RGB: R={r}, G={g}, B={b}");
RGBController.SendRGBRawData(r, g, b);

}
}

Expand Down

0 comments on commit b04a71d

Please sign in to comment.