1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Added more basic stuff

This commit is contained in:
Darth Affe 2017-01-22 15:31:04 +01:00
parent 9638b52f83
commit 89194c4cb4
9 changed files with 175 additions and 40 deletions

View File

@ -11,15 +11,11 @@ namespace RGB.NET.Core
{
#region Properties & Fields
/// <summary>
/// Gets generic information about the <see cref="IRGBDevice"/>.
/// </summary>
public IRGBDeviceInfo DeviceInfo { get; }
/// <inheritdoc />
public abstract IRGBDeviceInfo DeviceInfo { get; }
/// <summary>
/// Gets the <see cref="Rectangle"/> representing the whole <see cref="IRGBDevice"/>.
/// </summary>
public Rectangle DeviceRectangle { get; }
/// <inheritdoc />
public abstract Rectangle DeviceRectangle { get; }
/// <summary>
/// Gets a dictionary containing all <see cref="Led"/> of the <see cref="IRGBDevice"/>.
@ -28,6 +24,7 @@ namespace RGB.NET.Core
#region Indexer
/// <inheritdoc />
Led IRGBDevice.this[ILedId ledId]
{
get
@ -37,8 +34,10 @@ namespace RGB.NET.Core
}
}
/// <inheritdoc />
Led IRGBDevice.this[Point location] => LedMapping.Values.FirstOrDefault(x => x.LedRectangle.Contains(location));
/// <inheritdoc />
IEnumerable<Led> 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()
/// <inheritdoc />
public virtual void Update(bool flushLeds = false)
{
throw new System.NotImplementedException();
// Device-specific updates
DeviceUpdate();
// Send LEDs to SDK
IEnumerable<Led> ledsToUpdate = flushLeds ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty);
foreach (Led ledToUpdate in ledsToUpdate)
ledToUpdate.Update();
}
public void Update(bool flushLeds = false)
/// <summary>
/// Performs device specific updates.
/// </summary>
protected virtual void DeviceUpdate()
{ }
/// <summary>
/// Initializes the <see cref="Led"/> with the specified id.
/// </summary>
/// <param name="ledId">The <see cref="ILedId"/> to initialize.</param>
/// <param name="ledRectangle">The <see cref="Rectangle"/> representing the position of the <see cref="Led"/> to initialize.</param>
/// <returns></returns>
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

View File

@ -0,0 +1,38 @@
namespace RGB.NET.Core
{
/// <summary>
/// Contains list of different types of device.
/// </summary>
public enum DeviceType
{
/// <summary>
/// Represents a device where the type is not known or not present in the list.
/// </summary>
Unknown = 0,
/// <summary>
/// Represents a keyboard.
/// </summary>
Keyboard = 1,
/// <summary>
/// Represents a mouse.
/// </summary>
Mouse = 2,
/// <summary>
/// Represents a headset.
/// </summary>
Headset = 3,
/// <summary>
/// Represents a mousmat.
/// </summary>
Mousemat = 4,
/// <summary>
/// Represents a LED-stipe.
/// </summary>
LedStripe
}
}

View File

@ -0,0 +1,46 @@
using System.Collections.Generic;
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic device provider.
/// </summary>
public interface IDeviceProvider
{
#region Properties & Fields
/// <summary>
/// Indicates if the used SDK is initialized and ready to use.
/// </summary>
bool IsInitialized { get; }
/// <summary>
/// Gets a list of <see cref="IRGBDevice"/> loaded by this <see cref="IDeviceProvider"/>.
/// </summary>
IEnumerable<IRGBDevice> Devices { get; }
/// <summary>
/// Gets whether the application has exclusive access to devices or not.
/// </summary>
bool HasExclusiveAccess { get; }
#endregion
#region Methods
/// <summary>
/// Initializes the <see cref="IDeviceProvider"/> if not already happened or reloads it if it is already initialized.
/// </summary>
/// <param name="exclusiveAccessIfPossible">Specifies whether the application should request exclusive access of possible or not.</param>
/// <param name="throwExceptions">Specifies whether exception during the initialization sequence should be thrown or not.</param>
/// <returns></returns>
bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false);
/// <summary>
/// Resets all handled <see cref="IRGBDevice"/> back top default.
/// </summary>
void ResetDevices();
#endregion
}
}

View File

@ -48,12 +48,7 @@ namespace RGB.NET.Core
#endregion
#region Methods
/// <summary>
/// Initializes the <see cref="IRGBDevice"/>.
/// </summary>
void Initialize();
/// <summary>
/// Perform an update for all dirty <see cref="Led"/>, or all <see cref="Led"/> if flushLeds is set to true.
/// </summary>

View File

@ -5,6 +5,27 @@
/// </summary>
public interface IRGBDeviceInfo
{
#region Properties & Fields
/// <summary>
/// Gets the <see cref="Core.DeviceType"/> of the <see cref="IRGBDevice"/>.
/// </summary>
DeviceType DeviceType { get; }
/// <summary>
/// Gets the manufacturer-name of the <see cref="IRGBDevice"/>.
/// </summary>
string Manufacturer { get; }
/// <summary>
/// Gets the model-name of the <see cref="IRGBDevice"/>.
/// </summary>
string Model { get; }
#endregion
#region Methods
#endregion
}
}

View File

@ -0,0 +1,23 @@
using System;
namespace RGB.NET.Core.Exceptions
{
/// <summary>
/// Represents an exception thrown by an <see cref="IRGBDevice"/>.
/// </summary>
public class RGBDeviceException : ApplicationException
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RGBDeviceException"/> class.
/// </summary>
/// <param name="message">The message which describes the reason of throwing this exception.</param>
/// <param name="innerException">Optional inner exception, which lead to this exception.</param>
public RGBDeviceException(string message, Exception innerException = null)
: base(message, innerException)
{ }
#endregion
}
}

View File

@ -1,5 +1,6 @@
using System.Diagnostics;
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable MemberCanBePrivate.Global
using System.Diagnostics;
namespace RGB.NET.Core
{

View File

@ -47,6 +47,8 @@
<Compile Include="Brushes\IBrush.cs" />
<Compile Include="ColorCorrection\IColorCorrection.cs" />
<Compile Include="Devices\AbstractRGBDevice.cs" />
<Compile Include="Devices\DeviceType.cs" />
<Compile Include="Devices\IDeviceProvider.cs" />
<Compile Include="Devices\IRGBDeviceInfo.cs" />
<Compile Include="Effects\IEffect.cs" />
<Compile Include="Effects\IEffectTarget.cs" />
@ -55,6 +57,7 @@
<Compile Include="Events\LedsUpdatingEventArgs.cs" />
<Compile Include="Events\UpdatedEventArgs.cs" />
<Compile Include="Events\UpdatingEventArgs.cs" />
<Compile Include="Exceptions\RGBDeviceException.cs" />
<Compile Include="Leds\ILedId.cs" />
<Compile Include="Surfaces\IRGBSurface.cs" />
<Compile Include="MVVM\AbstractBindable.cs" />

View File

@ -6,7 +6,7 @@ namespace RGB.NET.Core
/// <summary>
/// Represents a generic RGB-surface.
/// </summary>
public class RGBSurface
public class RGBSurface : IRGBSurface
{
#region Properties & Fields
@ -18,29 +18,19 @@ namespace RGB.NET.Core
// ReSharper disable EventNeverSubscribedTo.Global
/// <summary>
/// Occurs when a catched exception is thrown inside the <see cref="IRGBSurface"/>.
/// </summary>
/// <inheritdoc />
public event ExceptionEventHandler Exception;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> starts updating.
/// </summary>
/// <inheritdoc />
public event UpdatingEventHandler Updating;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> update is done.
/// </summary>
/// <inheritdoc />
public event UpdatedEventHandler Updated;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> starts to update the <see cref="Led"/>.
/// </summary>
/// <inheritdoc />
public event LedsUpdatingEventHandler LedsUpdating;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> updated the <see cref="Led"/>.
/// </summary>
/// <inheritdoc />
public event LedsUpdatedEventHandler LedsUpdated;
// ReSharper restore EventNeverSubscribedTo.Global