Skip to content

Feature Discussion - Device Addition and Removal #360

@diogotr7

Description

@diogotr7

I'm making this issue mostly because of OpenRGB's hotplug support. It will listen for changes and detect devices as they are plugged in. This is useful for some wireless devices that will be turned on and off whislt OpenRGB is expected to stay running.

The OpenRGB SDK implements this by sending a device update packet through the socket:

    private async Task ReadLoop()
    {
        while (!_cancellationTokenSource.IsCancellationRequested && Connected)
        {
            try
            {
                //todo: handle zero
                await _socket.ReceiveAsync(_headerBuffer, SocketFlags.None, _cancellationTokenSource.Token);

                var dataLength = ParseHeader();
                if (dataLength.Command == CommandId.DeviceListUpdated)
                {
                    //TODO: is this the best way to do this?
                    DeviceListUpdated?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    var dataBuffer = new byte[dataLength.DataLength];
                    await _socket.ReceiveAsync(dataBuffer, SocketFlags.None, _cancellationTokenSource.Token);
                    _pendingRequests[dataLength.Command].Add(dataBuffer);
                }
            }
            catch (TaskCanceledException)
            {
                //ignore
            }
        }
    }

My question is: does any other device provider implement something like this? Do we even want to handle this on the RGB.NET level? I could have artemis start up a new OpenRGB SDK connection and restart the plugin when one of these events is received if that's better. Opinions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions