Darth Affe
Dynamic Lighting API in non UWP applications
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()));
}
}
2 replies