using System; using System.Collections.Generic; using RGB.NET.Core; namespace RGB.NET.Devices.Novation; /// /// /// Represents a Novation launchpad. /// public sealed class NovationLaunchpadRGBDevice : NovationRGBDevice, ILedMatrix { #region Constructors /// /// /// Initializes a new instance of the class. /// /// The specific information provided by Novation for the launchpad /// The update trigger used to update this device. internal NovationLaunchpadRGBDevice(NovationLaunchpadRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger) : base(info, updateTrigger) { InitializeLayout(); } #endregion #region Methods private void InitializeLayout() { Dictionary mapping = GetDeviceMapping(); const int BUTTON_SIZE = 20; foreach (LedId ledId in mapping.Keys) { (_, _, int x, int y) = mapping[ledId]; AddLed(ledId, new Point(BUTTON_SIZE * x, BUTTON_SIZE * y), new Size(BUTTON_SIZE)); } } /// // ReSharper disable RedundantCast protected override object GetLedCustomData(LedId ledId) => GetDeviceMapping().TryGetValue(ledId, out (byte mode, byte id, int _, int __) data) ? (data.mode, data.id) : ((byte)0x00, (byte)0x00); // ReSharper restore RedundantCast /// /// Gets the mapping used to access the LEDs of the device based on . /// /// The mapping of the device. /// Thrown if the value of is not known. private Dictionary GetDeviceMapping() => DeviceInfo.LedMapping switch { LedIdMappings.Current => LaunchpadIdMapping.CURRENT, LedIdMappings.Legacy => LaunchpadIdMapping.LEGACY, LedIdMappings.Pro => LaunchpadIdMapping.PRO, _ => throw new ArgumentOutOfRangeException() }; #endregion }