C
C#4mo ago
Darth Affe

Dynamic Lighting API in non UWP applications

I'm trying to control the leds on devices through the Dynamic Lighting API using the WinRT-Wrappers. The code below compiles, runs and detects all relevant devices using net8.0-windows10.0.17763.0 as the TargetFramework, but the SetColor-method does not work. (No exception, it's just doing nothing at all.) Inside a UWP-app this works and sets the color. I didn't find anything in the docs explaining this behavior and I'm also not really familiar with the usage of WinRT. Is there anything obvious I'm missing or does someone know a way to get this to work?
1 Reply
Darth Affe
Darth AffeOP4mo ago
Test-Code:
using Windows.Devices.Enumeration;
using Windows.Devices.Lights;
using Windows.System;
using Windows.UI;

namespace DynamicLightingTestNonUWP;

internal record LampArrayInfo(string Id, string DisplayName, LampArray LampArray);

public class Program
{
public static void Main()
{
List<LampArrayInfo> lampArrays = [];
ManualResetEventSlim waitEvent = new(false);

DeviceWatcher? watcher = DeviceInformation.CreateWatcher(LampArray.GetDeviceSelector());
watcher.EnumerationCompleted += OnEnumerationCompleted;
watcher.Added += OnDeviceAdded;
watcher.Start();

waitEvent.Wait();

watcher.Stop();
watcher.EnumerationCompleted -= OnEnumerationCompleted;
watcher.Added -= OnDeviceAdded;

foreach (LampArrayInfo lampArrayInfo in lampArrays)
{
Console.WriteLine("################################");
Console.WriteLine($"Id: {lampArrayInfo.Id}, Name: {lampArrayInfo.DisplayName}, LampCount: {lampArrayInfo.LampArray.LampCount}");
Console.WriteLine(lampArrayInfo.LampArray.IsConnected);
Console.WriteLine(lampArrayInfo.LampArray.IsEnabled);
Console.WriteLine($"[{string.Join(",", lampArrayInfo.LampArray.GetIndicesForKey(VirtualKey.Number1))}]");

lampArrayInfo.LampArray.SetColor(Color.FromArgb(255, 255, 0, 0));
}

Console.WriteLine("Press any key to exit ...");
Console.ReadKey();

void OnEnumerationCompleted(DeviceWatcher sender, object o) => waitEvent.Set();
void OnDeviceAdded(DeviceWatcher sender, DeviceInformation args) => lampArrays.Add(new LampArrayInfo(args.Id, args.Name, LampArray.FromIdAsync(args.Id).GetAwaiter().GetResult()));
}
}
using Windows.Devices.Enumeration;
using Windows.Devices.Lights;
using Windows.System;
using Windows.UI;

namespace DynamicLightingTestNonUWP;

internal record LampArrayInfo(string Id, string DisplayName, LampArray LampArray);

public class Program
{
public static void Main()
{
List<LampArrayInfo> lampArrays = [];
ManualResetEventSlim waitEvent = new(false);

DeviceWatcher? watcher = DeviceInformation.CreateWatcher(LampArray.GetDeviceSelector());
watcher.EnumerationCompleted += OnEnumerationCompleted;
watcher.Added += OnDeviceAdded;
watcher.Start();

waitEvent.Wait();

watcher.Stop();
watcher.EnumerationCompleted -= OnEnumerationCompleted;
watcher.Added -= OnDeviceAdded;

foreach (LampArrayInfo lampArrayInfo in lampArrays)
{
Console.WriteLine("################################");
Console.WriteLine($"Id: {lampArrayInfo.Id}, Name: {lampArrayInfo.DisplayName}, LampCount: {lampArrayInfo.LampArray.LampCount}");
Console.WriteLine(lampArrayInfo.LampArray.IsConnected);
Console.WriteLine(lampArrayInfo.LampArray.IsEnabled);
Console.WriteLine($"[{string.Join(",", lampArrayInfo.LampArray.GetIndicesForKey(VirtualKey.Number1))}]");

lampArrayInfo.LampArray.SetColor(Color.FromArgb(255, 255, 0, 0));
}

Console.WriteLine("Press any key to exit ...");
Console.ReadKey();

void OnEnumerationCompleted(DeviceWatcher sender, object o) => waitEvent.Set();
void OnDeviceAdded(DeviceWatcher sender, DeviceInformation args) => lampArrays.Add(new LampArrayInfo(args.Id, args.Name, LampArray.FromIdAsync(args.Id).GetAwaiter().GetResult()));
}
}
Want results from more Discord servers?
Add your server