public void Pull(ControlDevice controlDevice) { foreach (ControlDevice.LedUnit ledUnit in controlDevice.LEDs) { RGBNetLed slsLED = (RGBNetLed)ledUnit; Led rgbNetLed = RGBSurface.Instance.Leds.First(led => led.Id == (LedId)slsLED.LedId && led.Device.DeviceInfo.DeviceName == slsLED.DeviceName); slsLED.Color = new LEDColor((int)rgbNetLed.Color.R * 255, (int)rgbNetLed.Color.G * 255, (int)rgbNetLed.Color.B * 255); } }
public void Configure(DriverDetails driverDetails) { surface = RGBSurface.Instance; string deviceProvierDir = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? string.Empty, DEVICEPROVIDER_DIRECTORY); if (!Directory.Exists(deviceProvierDir)) { return; } foreach (string file in Directory.GetFiles(deviceProvierDir, "*.dll")) { try { Assembly assembly = Assembly.LoadFrom(file); foreach (Type loaderType in assembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && t.IsClass && typeof(IRGBDeviceProviderLoader).IsAssignableFrom(t))) { if (Activator.CreateInstance(loaderType) is IRGBDeviceProviderLoader deviceProviderLoader) { if (deviceProviderLoader.RequiresInitialization) { continue; } RGBSurface.Instance.LoadDevices(deviceProviderLoader, RGBDeviceType.All); } } } catch (Exception e) { Console.WriteLine(e.Message); } } surface.AlignDevices(); foreach (IRGBDevice device in surface.Devices) { device.UpdateMode = DeviceUpdateMode.Sync | DeviceUpdateMode.SyncBack; ControlDevice slsDevice = new ControlDevice(); slsDevice.Name = device.DeviceInfo.Manufacturer + "-" + device.DeviceInfo.DeviceName; slsDevice.DeviceType = DeviceTypeConverter.GetType(device.DeviceInfo.DeviceType); slsDevice.Driver = this; slsDevice.Has2DSupport = false; slsDevice.ProductImage = (Bitmap)System.Drawing.Image.FromStream(imageStream); List <ControlDevice.LedUnit> deviceLeds = new List <ControlDevice.LedUnit>(); int i = 0; foreach (Led led in device) { RGBNetLed newLed = new RGBNetLed(); newLed.Data = new ControlDevice.LEDData(); newLed.Data.LEDNumber = i; i++; newLed.LedId = (int)led.Id; newLed.DeviceName = led.Device.DeviceInfo.DeviceName; deviceLeds.Add(newLed); } slsDevice.LEDs = deviceLeds.ToArray(); DeviceAdded?.Invoke(slsDevice, new Events.DeviceChangeEventArgs(slsDevice)); } UpdateTrigger = new TimerUpdateTrigger { UpdateFrequency = 1.0 / 30 }; surface.RegisterUpdateTrigger(UpdateTrigger); UpdateTrigger.Start(); }