diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index c0a58de..125f0ef 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -11,15 +11,11 @@ namespace RGB.NET.Core { #region Properties & Fields - /// - /// Gets generic information about the . - /// - public IRGBDeviceInfo DeviceInfo { get; } + /// + public abstract IRGBDeviceInfo DeviceInfo { get; } - /// - /// Gets the representing the whole . - /// - public Rectangle DeviceRectangle { get; } + /// + public abstract Rectangle DeviceRectangle { get; } /// /// Gets a dictionary containing all of the . @@ -28,6 +24,7 @@ namespace RGB.NET.Core #region Indexer + /// Led IRGBDevice.this[ILedId ledId] { get @@ -37,8 +34,10 @@ namespace RGB.NET.Core } } + /// Led IRGBDevice.this[Point location] => LedMapping.Values.FirstOrDefault(x => x.LedRectangle.Contains(location)); + /// IEnumerable IRGBDevice.this[Rectangle referenceRect, float minOverlayPercentage] => LedMapping.Values.Where(x => referenceRect.CalculateIntersectPercentage(x.LedRectangle) >= minOverlayPercentage) ; @@ -47,20 +46,39 @@ namespace RGB.NET.Core #endregion - #region Constructors - - #endregion - #region Methods - public void Initialize() + /// + public virtual void Update(bool flushLeds = false) { - throw new System.NotImplementedException(); + // Device-specific updates + DeviceUpdate(); + + // Send LEDs to SDK + IEnumerable ledsToUpdate = flushLeds ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty); + foreach (Led ledToUpdate in ledsToUpdate) + ledToUpdate.Update(); } - public void Update(bool flushLeds = false) + /// + /// Performs device specific updates. + /// + protected virtual void DeviceUpdate() + { } + + /// + /// Initializes the with the specified id. + /// + /// The to initialize. + /// The representing the position of the to initialize. + /// + protected virtual Led InitializeLed(ILedId ledId, Rectangle ledRectangle) { - throw new System.NotImplementedException(); + if (LedMapping.ContainsKey(ledId)) return null; + + Led led = new Led(this, ledId, ledRectangle); + LedMapping.Add(ledId, led); + return led; } #region Enumerator diff --git a/RGB.NET.Core/Devices/DeviceType.cs b/RGB.NET.Core/Devices/DeviceType.cs new file mode 100644 index 0000000..83c376f --- /dev/null +++ b/RGB.NET.Core/Devices/DeviceType.cs @@ -0,0 +1,38 @@ +namespace RGB.NET.Core +{ + /// + /// Contains list of different types of device. + /// + public enum DeviceType + { + /// + /// Represents a device where the type is not known or not present in the list. + /// + Unknown = 0, + + /// + /// Represents a keyboard. + /// + Keyboard = 1, + + /// + /// Represents a mouse. + /// + Mouse = 2, + + /// + /// Represents a headset. + /// + Headset = 3, + + /// + /// Represents a mousmat. + /// + Mousemat = 4, + + /// + /// Represents a LED-stipe. + /// + LedStripe + } +} diff --git a/RGB.NET.Core/Devices/IDeviceProvider.cs b/RGB.NET.Core/Devices/IDeviceProvider.cs new file mode 100644 index 0000000..716f507 --- /dev/null +++ b/RGB.NET.Core/Devices/IDeviceProvider.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; + +namespace RGB.NET.Core +{ + /// + /// Represents a generic device provider. + /// + public interface IDeviceProvider + { + #region Properties & Fields + + /// + /// Indicates if the used SDK is initialized and ready to use. + /// + bool IsInitialized { get; } + + /// + /// Gets a list of loaded by this . + /// + IEnumerable Devices { get; } + + /// + /// Gets whether the application has exclusive access to devices or not. + /// + bool HasExclusiveAccess { get; } + + #endregion + + #region Methods + + /// + /// Initializes the if not already happened or reloads it if it is already initialized. + /// + /// Specifies whether the application should request exclusive access of possible or not. + /// Specifies whether exception during the initialization sequence should be thrown or not. + /// + bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false); + + /// + /// Resets all handled back top default. + /// + void ResetDevices(); + + #endregion + } +} diff --git a/RGB.NET.Core/Devices/IRGBDevice.cs b/RGB.NET.Core/Devices/IRGBDevice.cs index 1538ef7..10030da 100644 --- a/RGB.NET.Core/Devices/IRGBDevice.cs +++ b/RGB.NET.Core/Devices/IRGBDevice.cs @@ -48,12 +48,7 @@ namespace RGB.NET.Core #endregion #region Methods - - /// - /// Initializes the . - /// - void Initialize(); - + /// /// Perform an update for all dirty , or all if flushLeds is set to true. /// diff --git a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs index 4860dd8..20f952d 100644 --- a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs +++ b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs @@ -5,6 +5,27 @@ /// public interface IRGBDeviceInfo { + #region Properties & Fields + /// + /// Gets the of the . + /// + DeviceType DeviceType { get; } + + /// + /// Gets the manufacturer-name of the . + /// + string Manufacturer { get; } + + /// + /// Gets the model-name of the . + /// + string Model { get; } + + #endregion + + #region Methods + + #endregion } } diff --git a/RGB.NET.Core/Exceptions/RGBDeviceException.cs b/RGB.NET.Core/Exceptions/RGBDeviceException.cs new file mode 100644 index 0000000..1e222b3 --- /dev/null +++ b/RGB.NET.Core/Exceptions/RGBDeviceException.cs @@ -0,0 +1,23 @@ +using System; + +namespace RGB.NET.Core.Exceptions +{ + /// + /// Represents an exception thrown by an . + /// + public class RGBDeviceException : ApplicationException + { + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The message which describes the reason of throwing this exception. + /// Optional inner exception, which lead to this exception. + public RGBDeviceException(string message, Exception innerException = null) + : base(message, innerException) + { } + + #endregion + } +} diff --git a/RGB.NET.Core/Leds/Led.cs b/RGB.NET.Core/Leds/Led.cs index e13c937..b9efb55 100644 --- a/RGB.NET.Core/Leds/Led.cs +++ b/RGB.NET.Core/Leds/Led.cs @@ -1,5 +1,6 @@ -using System.Diagnostics; -// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable MemberCanBePrivate.Global + +using System.Diagnostics; namespace RGB.NET.Core { diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index 64fb4f6..6f069ce 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -47,6 +47,8 @@ + + @@ -55,6 +57,7 @@ + diff --git a/RGB.NET.Core/Surfaces/RGBSurface.cs b/RGB.NET.Core/Surfaces/RGBSurface.cs index 2d46d62..0b182f5 100644 --- a/RGB.NET.Core/Surfaces/RGBSurface.cs +++ b/RGB.NET.Core/Surfaces/RGBSurface.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Core /// /// Represents a generic RGB-surface. /// - public class RGBSurface + public class RGBSurface : IRGBSurface { #region Properties & Fields @@ -18,29 +18,19 @@ namespace RGB.NET.Core // ReSharper disable EventNeverSubscribedTo.Global - /// - /// Occurs when a catched exception is thrown inside the . - /// + /// public event ExceptionEventHandler Exception; - /// - /// Occurs when the starts updating. - /// + /// public event UpdatingEventHandler Updating; - /// - /// Occurs when the update is done. - /// + /// public event UpdatedEventHandler Updated; - /// - /// Occurs when the starts to update the . - /// + /// public event LedsUpdatingEventHandler LedsUpdating; - /// - /// Occurs when the updated the . - /// + /// public event LedsUpdatedEventHandler LedsUpdated; // ReSharper restore EventNeverSubscribedTo.Global