OpenMacroBoard / OpenMacroBoard.SDK

MIT License
20 stars 10 forks source link

A Discovery-Methode is missing #3

Closed patrick-dmxc closed 2 years ago

patrick-dmxc commented 5 years ago

At the moment i have to discover every diferent Macroboard by my selve

Whats missing is a static Methode which returns all Availlable IMacroBoards

wischi-chr commented 5 years ago

Yea that's true. I'm aready working on that (as described here)

wischi-chr commented 2 years ago

Hi. If you are still interested in a better way of discovering new devices you can check out v4.0.0-preview.

You can now create a DeviceContext which basically collects events from "device listeners" (IObservable<DeviceStateReport>) to generate a collection of known devices.

// ## create a new device context and register some listeners
using var deviceDiscoveryContext = DeviceContext.Create()
    .AddListener<StreamDeckListener>()
    .AddListener(new SocketIOBoardListener(IPAddress.Loopback));

// ## A few options to open a device:

// Get it from the KnownDevices list
using var device1 = deviceDiscoveryContext.KnownDevices[0].Open();

// Wait for a device with a custom condition
using var device2 = await deviceDiscoveryContext.OpenAsync(r => r.Keys.Count == 15, default);

// Subscribe to device events to do other custom stuff
using var sub = deviceDiscoveryContext.DeviceStateReports.Subscribe(YourEventHandler);

static void YourEventHandler(DeviceStateReport report)
{
    // ...
}

Note that v4 is a breaking change but it should be straightforward to migrate