diff --git a/NZXTSharp/COM/SerialCOMData.cs b/NZXTSharp/COM/SerialCOMData.cs index 2f4e39e..42ffb01 100644 --- a/NZXTSharp/COM/SerialCOMData.cs +++ b/NZXTSharp/COM/SerialCOMData.cs @@ -11,22 +11,53 @@ namespace NZXTSharp.COM { /// internal class SerialCOMData { - private Parity _Parity; - private StopBits _StopBits; - private int _WriteTimeout; - private int _ReadTimeout; - private int _Baud; - private int _DataBits; - private string _Name; + #region Properties and Fields + private readonly Parity _Parity; + private readonly StopBits _StopBits; + private readonly int _WriteTimeout; + private readonly int _ReadTimeout; + private readonly int _Baud; + private readonly int _DataBits; + private readonly string _Name; + /// + /// The setting of the instance. + /// public Parity Parity { get => _Parity; } + + /// + /// The setting of the instance. + /// public StopBits StopBits { get => _StopBits; } + + /// + /// The write timeout setting of the instance (ms). + /// public int WriteTimeout { get => _WriteTimeout; } + + /// + /// The read timeout setting of the instance (ms). + /// public int ReadTimeout { get => _ReadTimeout; } + + /// + /// The baud setting of the instance. + /// public int Baud { get => _Baud; } + + /// + /// The databits setting of the instance. + /// public int DataBits { get => _DataBits; } + + /// + /// The custom name of the instance. + /// public string Name { get => _Name; } + #endregion + + #region Methods /// /// Constructs a object. /// @@ -36,6 +67,7 @@ internal class SerialCOMData { /// The ReadTimeout in ms. /// The baud to use. /// The number of DataBits to use. + /// A custom name for the . public SerialCOMData(Parity Parity, StopBits StopBits, int WriteTimeout, int ReadTimeout, int Baud, int DataBits, string Name = "") { this._Parity = Parity; this._StopBits = StopBits; @@ -58,5 +90,6 @@ public override string ToString() this.Name ); } + #endregion } } diff --git a/NZXTSharp/COM/SerialController.cs b/NZXTSharp/COM/SerialController.cs index 7d49909..cb2b9b6 100644 --- a/NZXTSharp/COM/SerialController.cs +++ b/NZXTSharp/COM/SerialController.cs @@ -7,8 +7,13 @@ using System.IO.Ports; namespace NZXTSharp.COM { + + /// + /// Represents a with some useful methods. + /// internal class SerialController : ICOMController { - + + #region Properties and Fields private SerialPort _Port; private SerialCOMData _StartData; private string[] _PossiblePorts; @@ -24,25 +29,37 @@ internal class SerialController : ICOMController { /// public SerialCOMData StartData { get => _StartData; } + /// + /// Returns a bool telling whether or not the 's is open. + /// public bool IsOpen { get => _Port.IsOpen; } + #endregion + #region Constructors /// - /// + /// Opens the SerialController on a specific COM port. /// - /// + /// The COM port to open in "COMx" format. public SerialController(string COMPort) { this._PossiblePorts = new string[] { COMPort }; Initialize(); } + /// + /// Attempts to open each of the COM ports in with the provided . + /// + /// An array of possible ports the device could be on. + /// The to open the port with. public SerialController(string[] PossiblePorts, SerialCOMData Data) { this._PossiblePorts = PossiblePorts; this._StartData = Data; Initialize(); } + #endregion + #region Methods private void Initialize() { try { @@ -129,5 +146,6 @@ public void Dispose() { _Port.Close(); } + #endregion } } diff --git a/NZXTSharp/Core/Color.cs b/NZXTSharp/Core/Color.cs index 3f4cf79..e175768 100644 --- a/NZXTSharp/Core/Color.cs +++ b/NZXTSharp/Core/Color.cs @@ -1,40 +1,90 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Text; -using System.Linq; +using System.Text.RegularExpressions; + +using NZXTSharp.Exceptions; namespace NZXTSharp { + + /// + /// Represents a color. + /// public class Color { + #region Properties and Fields + private readonly int _R; + private readonly int _G; + private readonly int _B; + + /// + /// The R value of the color. + /// + public int R { get => _R; } + + /// + /// The G value of the color. + /// + public int G { get => _G; } - private int R; - private int G; - private int B; + /// + /// The B value of the color. + /// + public int B { get => _B; } + #endregion + #region Constructors + /// + /// Constructs an empty . + /// public Color() { } + /// + /// Creates a Color instance from a hex color code. + /// + /// The color code. Supports codes with a leading #, and without. public Color(string hexColor) { + if (!Regex.IsMatch(hexColor, "#?([a-f]|[A-F]|[0-9]){6}")) // Validate input + { + throw new InvalidParamException("Invalid color format. The color must be of the form #FFFFFF or FFFFFF"); + } + if (hexColor.StartsWith("#")) // Strip leading # if it exists hexColor = hexColor.Substring(1); + string[] splitHex = hexColor.SplitEveryN(2); - this.R = Convert.ToInt32(splitHex[0]); - this.G = Convert.ToInt32(splitHex[1]); - this.B = Convert.ToInt32(splitHex[2]); + + this._R = int.Parse(splitHex[0], System.Globalization.NumberStyles.HexNumber); + this._G = int.Parse(splitHex[1], System.Globalization.NumberStyles.HexNumber); + this._B = int.Parse(splitHex[2], System.Globalization.NumberStyles.HexNumber); } + /// + /// Creates a Color instance from R, G, B values. + /// + /// The color's R value. Must be 0-255 (inclusive). + /// The color's G value. Must be 0-255 (inclusive). + /// The color's B value. Must be 0-255 (inclusive). public Color(int R, int G, int B) { - this.R = R; - this.G = G; - this.B = B; + if ((_R > 255 || _R < 0) || (_G > 255 || _G < 0) || (_B > 255 || _B < 0)) + throw new InvalidParamException("RGB Values must be between 0-255 (inclusive)."); + + this._R = R; + this._G = G; + this._B = B; } + #endregion + #region Methods + /// + /// Returns a list of 40 "#ffffff" color codes in G, R, B format. + /// + /// public byte[] AllOff() { List outBytes = new List(); @@ -55,14 +105,18 @@ public byte[] AllOff() return outB.ToArray(); } - public byte[] Expanded() + /// + /// Expands the instance into a byte array. + /// + /// + internal byte[] Expanded() { List outBytes = new List(); for (int i = 0; i < 40; i++) { - outBytes.Add(Convert.ToByte(G)); - outBytes.Add(Convert.ToByte(R)); - outBytes.Add(Convert.ToByte(B)); + outBytes.Add(Convert.ToByte(_G)); + outBytes.Add(Convert.ToByte(_R)); + outBytes.Add(Convert.ToByte(_B)); } return outBytes.ToArray(); @@ -71,21 +125,24 @@ public byte[] Expanded() /// /// Expands the instance into an array of byte arrays. Each sub array contains the RGB values for each LED. /// - /// + /// The number of LED triplets to create in the array. /// - public byte[][] ExpandedChunks(int NumLeds) + internal byte[][] ExpandedChunks(int NumLeds) { List outBytes = new List(); for (int i = 0; i < NumLeds; i++) { - List arr = new List(); - arr.Add(Convert.ToByte(G)); - arr.Add(Convert.ToByte(R)); - arr.Add(Convert.ToByte(B)); - outBytes.Add(arr.ToArray()); + byte[] arr = new byte[3] + { + Convert.ToByte(_G), + Convert.ToByte(_R), + Convert.ToByte(_B) + }; + outBytes.Add(arr); } return outBytes.ToArray(); } + #endregion } } diff --git a/NZXTSharp/Devices/Enum/NZXTDeviceType.cs b/NZXTSharp/Devices/Enum/NZXTDeviceType.cs index 1ccfd85..1db5b5c 100644 --- a/NZXTSharp/Devices/Enum/NZXTDeviceType.cs +++ b/NZXTSharp/Devices/Enum/NZXTDeviceType.cs @@ -3,44 +3,100 @@ using System.Text; namespace NZXTSharp.Devices { + + /// + /// Definitions of unique IDs for all NZXT devices. + /// public enum NZXTDeviceType { + /// + /// If device type is unknown. + /// Unknown = 0, + + /// + /// + /// NotActive = 1, + // SubDevices + /// + /// Any fan, RGB or otherwise. + /// Fan = 2, + + /// + /// An RGB strip. + /// Strip = 3, // Krakens + /// + /// A generic Kraken device. + /// Kraken = 4, + + /// + /// A generic KrakenX device. + /// KrakenX = 5, + + /// + /// A generic KrakenM device. + /// KrakenM = 6, + + #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member KrakenM22 = 7, KrakenX42 = 8, KrakenX52 = 9, KrakenX62 = 10, KrakenX72 = 11, + #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + // Hues + /// + /// A generic Hue device. + /// Hue = 12, + + #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member HuePlus = 13, Hue2 = 14, HueAmbient = 15, + #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + // N7s + /// + /// A generic motherboard device. + /// Motherboard = 16, + + #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member N7 = 17, N7_Z390 = 18, + #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + // Grids + /// + /// A generic Grid device. + /// Grid = 19, + + #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member GridPlus = 20, GridV2 = 21, GridV3 = 22, + #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member // Misc + #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member H7Lumi = 23, SmartDevice = 24, + #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } } diff --git a/NZXTSharp/Devices/Enum/SerialDeviceID.cs b/NZXTSharp/Devices/Enum/SerialDeviceID.cs index 84cc5d1..133728b 100644 --- a/NZXTSharp/Devices/Enum/SerialDeviceID.cs +++ b/NZXTSharp/Devices/Enum/SerialDeviceID.cs @@ -5,8 +5,15 @@ using NZXTSharp.Devices; namespace NZXTSharp.Devices { + + /// + /// Contains the Manufacturer and Product IDs of NZXT devices. + /// internal enum SerialDeviceID { + /// + /// An unknown ID. + /// Unknown = -1, ManufacturerID = 0x1e71, diff --git a/NZXTSharp/Devices/Channel.cs b/NZXTSharp/Devices/Hue/Channel.cs similarity index 54% rename from NZXTSharp/Devices/Channel.cs rename to NZXTSharp/Devices/Hue/Channel.cs index 40af1fa..2ffeeb7 100644 --- a/NZXTSharp/Devices/Channel.cs +++ b/NZXTSharp/Devices/Hue/Channel.cs @@ -7,6 +7,10 @@ using NZXTSharp.Effects; namespace NZXTSharp.Devices { + + /// + /// Represents a channel on an NZXT device. + /// public class Channel { private readonly int _ChannelByte; @@ -19,29 +23,66 @@ public class Channel { #pragma warning restore IDE0044 // Add readonly modifier #region Properties + /// + /// The channelbyte of the . + /// public int ChannelByte { get; } + + /// + /// The currently applied to the . + /// public IEffect Effect { get => _Effect; } + + /// + /// Whether or not the current is active (on). + /// public bool State { get => _State; } + + /// + /// The 's object. + /// public ChannelInfo ChannelInfo { get => _ChannelInfo; } + + /// + /// The device that owns the . + /// public IHueDevice Parent { get => _Parent; } + + /// + /// A list of s owned by the . + /// public List SubDevices { get => _SubDevices; } #endregion - - public Channel() { - - } - - public Channel(int _ChannelByte) { - this._ChannelByte = _ChannelByte; + + /// + /// Constructs a object with a given . + /// + /// The ChannelByte to construct the channel from. + public Channel(int ChannelByte) { + this._ChannelByte = ChannelByte; } - public Channel(int _ChannelByte, IHueDevice Parent) { - this.ChannelByte = _ChannelByte; + /// + /// Constructs a object with a given , + /// owned by a given . + /// + /// The ChannelByte to construct the channel from. + /// The that will own the + public Channel(int ChannelByte, IHueDevice Parent) { + this.ChannelByte = ChannelByte; this._Parent = Parent; } - public Channel(int _ChannelByte, IHueDevice Parent, ChannelInfo Info) { - this.ChannelByte = _ChannelByte; + /// + /// Constructs a object with a given , + /// owned by a given , + /// with a given . + /// + /// The ChannelByte to construct the channel from. + /// The that owns the + /// The owned by the . + public Channel(int ChannelByte, IHueDevice Parent, ChannelInfo Info) { + this.ChannelByte = ChannelByte; this._Parent = Parent; this._ChannelInfo = Info; } @@ -64,17 +105,25 @@ internal void UpdateEffect(IEffect newOne) this._Effect = newOne; } - + /// + /// Refreshes all s in the 's list. + /// public void RefreshSubDevices() { BuildSubDevices(); } + /// + /// Turns the on. + /// public void On() { this._State = true; _Parent.ApplyEffect(this, _Effect); } + /// + /// Turns the off. + /// public void Off() { this._State = false; _Parent.ApplyEffect(this, new Fixed(this, new Color(0, 0, 0)), false); @@ -114,14 +163,25 @@ internal byte[] BuildColorBytes(Color color) { return outList.ToArray(); } + /// + /// Updates the 's . + /// public void UpdateChannelInfo() { Parent.UpdateChannelInfo(this); } + /// + /// Sets the 's to the given . + /// + /// public void SetChannelInfo(ChannelInfo info) { this._ChannelInfo = info; } + /// + /// Returns the 's ChannelByte. + /// + /// public static explicit operator byte(Channel channel) { return (byte)channel.ChannelByte; } diff --git a/NZXTSharp/Devices/ChannelInfo.cs b/NZXTSharp/Devices/Hue/ChannelInfo.cs similarity index 58% rename from NZXTSharp/Devices/ChannelInfo.cs rename to NZXTSharp/Devices/Hue/ChannelInfo.cs index d4f2f05..23c962c 100644 --- a/NZXTSharp/Devices/ChannelInfo.cs +++ b/NZXTSharp/Devices/Hue/ChannelInfo.cs @@ -1,4 +1,8 @@ namespace NZXTSharp.Devices { + + /// + /// Represents information about a . + /// public class ChannelInfo { #pragma warning disable IDE0044 // Add readonly modifier private int _NumLeds; @@ -8,21 +12,47 @@ public class ChannelInfo { private Channel _Parent; #pragma warning restore IDE0044 // Add readonly modifier + /// + /// Represents the total number of LEDs available on a . + /// public int NumLeds { get => _NumLeds; } + + /// + /// The number of SubDevices available on a . + /// public int NumSubDevices { get => _NumSubDevices; } + + /// + /// Type of s available on a . + /// public NZXTDeviceType Type { get => _Type; } + + /// + /// + /// public bool IsActive { get => _IsActive; } private Channel Parent { get; } - + /// + /// Constructs a with a given as its parent, from some given channel handshake . + /// + /// + /// public ChannelInfo(Channel Parent, byte[] data) { ParseData(data); } + /// + /// Constructs a object from some given channel handshake . + /// + /// public ChannelInfo(byte[] data) { ParseData(data); } + /// + /// Updates the parent 's . + /// public void Update() { Parent.Parent.UpdateChannelInfo(Parent); } @@ -50,6 +80,10 @@ private void ParseData(byte[] data) { } + /// + /// + /// + /// public override string ToString() { return string.Format("Type: {0}, NumSubDevices: {1}, NumLeds: {2}, IsActive: {3}", Type, NumSubDevices, NumLeds, IsActive); } diff --git a/NZXTSharp/Devices/Hue/HuePlus.cs b/NZXTSharp/Devices/Hue/HuePlus.cs index 09aed8a..759ed60 100644 --- a/NZXTSharp/Devices/Hue/HuePlus.cs +++ b/NZXTSharp/Devices/Hue/HuePlus.cs @@ -34,8 +34,14 @@ You should have received a copy of the GNU General Public License namespace NZXTSharp.Devices { + /// + /// Triggers when a generic log message is sent. + /// public delegate void LogHandler(string message); + /// + /// Triggers when data is received from the COM port. + /// public delegate void DataRecieved(string message); /// @@ -44,9 +50,9 @@ namespace NZXTSharp.Devices public class HuePlus : IHueDevice { #region Fields - private string _Name = "HuePlus"; - private string _CustomName = null; - private int _MaxHandshakeRetry = 5; + private readonly string _Name = "HuePlus"; + private readonly string _CustomName = null; + private readonly int _MaxHandshakeRetry = 5; private SerialController _COMController; @@ -57,17 +63,51 @@ public class HuePlus : IHueDevice #endregion #region Properties + /// + /// The device's product name. + /// public string Name { get; } + + /// + /// A object representing both channels on the . + /// public Channel Both { get => _Both; } + + /// + /// A object representing the Channel 1 of the device. + /// public Channel Channel1 { get => _Channel1; } + + /// + /// A object representing the Channel 2 of the device. + /// public Channel Channel2 { get => _Channel2; } + + /// + /// A containing all objects owned by the device. + /// public List Channels { get => _Channels; } + + /// + /// A custom name for the instance. + /// public string CustomName { get; set; } + + /// + /// The of the object. + /// public NZXTDeviceType Type { get => NZXTDeviceType.HuePlus; } #endregion + + /// + /// Triggers when a generic log message is sent. + /// public event LogHandler OnLogMessage; + /// + /// Triggers when data is received from the COM port. + /// public event DataRecieved OnDataReceived; /// @@ -78,21 +118,18 @@ public HuePlus() Initialize(); } - public HuePlus(int MaxHandshakeRetry) + /// + /// Constructs a instance with a custom count, + /// and a custom name . + /// + /// + /// A custom name for the instance. + public HuePlus(int MaxHandshakeRetry = 5, string CustomName = null) { if (MaxHandshakeRetry <= 0) throw new InvalidParamException("Invalid MaxHandshakeRetry may not be less than or equal to 0."); this._MaxHandshakeRetry = MaxHandshakeRetry; - Initialize(); - } - - /// - /// Constructs a instance with a custom name . - /// - /// - public HuePlus(string CustomName = null) - { this._CustomName = CustomName; Initialize(); } @@ -165,14 +202,12 @@ private void InitializeChannelInfo() /// /// Disposes of and reconnects to the device's . /// - /// - public bool Reconnect() + public void Reconnect() { _COMController.Dispose(); Initialize(); InitializeChannels(); - return true; } /// @@ -189,71 +224,31 @@ public void Dispose() /// /// The to apply the effect to. /// The to apply. - public void ApplyEffect(Channel channel, IEffect effect) + /// Whether or not to save the given effect to the given channel. + public void ApplyEffect(Channel channel, IEffect effect, bool SaveToChannel = true) { - if (!effect.IsCompatibleWith(_Name)) + if (!effect.IsCompatibleWith(Type)) throw new IncompatibleEffectException(_Name, effect.EffectName); - SendLogEvent("Applying Effect: " + effect.EffectName); - - List commandBytes = new List(); - - if (channel == this._Both) // If both channels, build and send bytes for both individually - { - foreach (byte[] arr in effect.BuildBytes(this._Channel1)) { - commandBytes.Add(arr); - } - - foreach (byte[] arr in effect.BuildBytes(this._Channel2)) { - commandBytes.Add(arr); - } - - _Channel1.UpdateEffect(effect); - _Channel2.UpdateEffect(effect); - } - else // Otherwise, just build for the selected channel - { - commandBytes = effect.BuildBytes(channel); - } - - - channel.UpdateEffect(effect); - effect.Channel = channel; - - foreach (byte[] command in commandBytes) // Send command buffer - { - _COMController.WriteNoReponse(command); - Thread.Sleep(10); - } - } - /// - /// Applies the given to the given . - /// - /// The to apply the effect to. - /// The to apply. - public void ApplyEffect(Channel channel, IEffect effect, bool ApplyToChannel) - { - if (!effect.IsCompatibleWith(_Name)) - throw new IncompatibleEffectException(_Name, effect.EffectName); - SendLogEvent("Applying Effect: " + effect.EffectName); - List commandBytes = new List(); + List commandQueue = new List(); + // TODO : Improve this, not elegant. if (channel == this._Both) // If both channels, build and send bytes for both individually { foreach (byte[] arr in effect.BuildBytes(this._Channel1)) { - commandBytes.Add(arr); + commandQueue.Add(arr); } foreach (byte[] arr in effect.BuildBytes(this._Channel2)) { - commandBytes.Add(arr); + commandQueue.Add(arr); } - if (ApplyToChannel) + if (SaveToChannel) { _Channel1.UpdateEffect(effect); _Channel2.UpdateEffect(effect); @@ -261,14 +256,14 @@ public void ApplyEffect(Channel channel, IEffect effect, bool ApplyToChannel) } else // Otherwise, just build for the selected channel { - commandBytes = effect.BuildBytes(channel); + commandQueue = effect.BuildBytes(channel); } - if (ApplyToChannel) { channel.UpdateEffect(effect); } + if (SaveToChannel) { channel.UpdateEffect(effect); } effect.Channel = channel; - foreach (byte[] command in commandBytes) // Send command buffer + foreach (byte[] command in commandQueue) // Send command buffer { _COMController.WriteNoReponse(command); Thread.Sleep(10); @@ -278,7 +273,7 @@ public void ApplyEffect(Channel channel, IEffect effect, bool ApplyToChannel) /// /// Writes a custom to the device's . /// - /// + /// The buffer to write to the device. public void ApplyCustom(byte[] Buffer) { _COMController.WriteNoReponse(Buffer); @@ -305,7 +300,7 @@ public void UnitLedOff() /// /// Sets the device's unit led state. true: on, false: off. /// - /// + /// Which state to set the LED to; true: on, false: off. public void SetUnitLed(bool State) { if (State) @@ -333,14 +328,12 @@ private void SendDataRecvd(string Message) /// Updates the given 's . /// /// - // TOTEST public void UpdateChannelInfo(Channel Channel) { UpdateChannelInfoOp(this._Channel1); UpdateChannelInfoOp(this._Channel2); } - // TOTEST private void UpdateChannelInfoOp(Channel channel) { _COMController.Port.DiscardInBuffer(); //This will have to be removed later diff --git a/NZXTSharp/Devices/Hue/IHueDevice.cs b/NZXTSharp/Devices/Hue/IHueDevice.cs index 54f9093..9894ca8 100644 --- a/NZXTSharp/Devices/Hue/IHueDevice.cs +++ b/NZXTSharp/Devices/Hue/IHueDevice.cs @@ -5,19 +5,50 @@ using NZXTSharp.Effects; namespace NZXTSharp.Devices { - public interface IHueDevice : INZXTDevice { - void ApplyEffect(Channel channel, IEffect effect); + /// + /// Represents a generic NZXT Hue device. + /// + public interface IHueDevice : INZXTDevice { - void ApplyEffect(Channel channel, IEffect effect, bool ApplyToChannel); + /// + /// Applies a given to the given . + /// + /// + /// + /// + void ApplyEffect(Channel channel, IEffect effect, bool ApplyToChannel = true); - void ApplyCustom(byte[] Bytes); + /// + /// Sends a given to the 's . + /// + /// The buffer to send. + void ApplyCustom(byte[] Buffer); + /// + /// Updates the object owned by the given . + /// + /// void UpdateChannelInfo(Channel Channel); + /// + /// Represents both channels owned by a Hue device. + /// Channel Both { get; } + + /// + /// Represents Channel 1 of a Hue device. + /// Channel Channel1 { get; } + + /// + /// Represents Channel 2 of a hue device. + /// Channel Channel2 { get; } + + /// + /// A list of all s owned by a hue device. + /// List Channels { get; } } } diff --git a/NZXTSharp/Devices/SubDevices/Fan.cs b/NZXTSharp/Devices/SubDevices/Fan.cs index 4161e81..b2bbfcf 100644 --- a/NZXTSharp/Devices/SubDevices/Fan.cs +++ b/NZXTSharp/Devices/SubDevices/Fan.cs @@ -2,7 +2,13 @@ using System.Collections.Generic; using System.Text; +using NZXTSharp.Exceptions; + namespace NZXTSharp.Devices { + + /// + /// Represents a fan. + /// public class Fan : ISubDevice { private bool _IsActive = true; @@ -13,50 +19,100 @@ public class Fan : ISubDevice { true, true, true, true }; + /// + /// Whether or not the current instance is active (on). + /// public bool IsActive { get => _IsActive; } + /// + /// Returns the of the fan. + /// public NZXTDeviceType Type { get => NZXTDeviceType.Fan; } + /// + /// Returns the number of LEDs available on the . + /// public int NumLeds { get => 8; } + /// + /// A list containing the power states of the 's LEDs. + /// public List Leds { get => _Leds; } + /// + /// Constructs a instance. + /// public Fan() { } + /// + /// Toggles the 's state. + /// public void ToggleState() { this._IsActive = (this._IsActive ? false : true); } + /// + public void SetState(bool State) + { + this._IsActive = State; + } + + /// + /// Toggles a specific LED owned by the device. + /// + /// The index in the 's list to toggle. public void ToggleLed(int Index) { + if (Index > 7 || Index < 0) { throw new SubDeviceLEDDoesNotExistException(); } this._Leds[Index] = (this._Leds[Index] ? false : true); } + /// + /// Toggles all LEDs between a given and index. + /// + /// The index in the 's list to start at. + /// The index in the 's list to end at. public void ToggleLedRange(int Start, int End) { for (int Index = Start; Index <= End; Index++) { _Leds[Index] = (this._Leds[Index] ? false : true); } } + /// + /// Sets all LEDs between a given index and an index to a given . + /// + /// The index in the 's list to start at. + /// The index in the 's list to end at. + /// The value to set each LED to. public void SetLedRange(int Start, int End, bool Value) { for (int Index = Start; Index <= End; Index++) { _Leds[Index] = Value; } } + /// + /// Sets all LEDs in the 's list to true. + /// public void AllLedOn() { for (int index = 0; index < 8; index++) { _Leds[index] = true; } } + /// + /// Sets all LEDs in the 's list to false. + /// public void AllLedOff() { for (int index = 0; index < 8; index++) { _Leds[index] = false; } } + /// + /// Returns a string with all LED states. + /// + /// public string LedsToString() { StringBuilder sb = new StringBuilder(); _Leds.ForEach(c => sb.Append(c + " ")); diff --git a/NZXTSharp/Devices/SubDevices/ISubDevice.cs b/NZXTSharp/Devices/SubDevices/ISubDevice.cs index 4d870d8..71b3b0e 100644 --- a/NZXTSharp/Devices/SubDevices/ISubDevice.cs +++ b/NZXTSharp/Devices/SubDevices/ISubDevice.cs @@ -3,28 +3,79 @@ using System.Text; namespace NZXTSharp.Devices { + + /// + /// Represents a sub device. + /// public interface ISubDevice { + /// + /// The 's . + /// NZXTDeviceType Type { get; } + /// + /// Whether or not the current instance is active (on). + /// bool IsActive { get; } + /// + /// Returns the number of LEDs available on the . + /// int NumLeds { get; } + /// + /// A list containing the power states of the 's LEDs. + /// + // TODO : Change to array? List Leds { get; } + /// + /// Toggles the 's state. + /// void ToggleState(); + /// + /// Sets the 's state. + /// + /// The state to set the to. true: on, false: off. + void SetState(bool State); + + /// + /// Toggles a specific LED owned by the . + /// + /// The index in the 's list to toggle. void ToggleLed(int Index); + /// + /// Toggles all LEDs between a given and index. + /// + /// The index in the 's list to start at. + /// The index in the 's list to end at. void ToggleLedRange(int Start, int End); + /// + /// Sets all LEDs between a given index and an index to a given . + /// + /// The index in the 's list to start at. + /// The index in the 's list to end at. + /// The value to set each LED to. void SetLedRange(int Start, int End, bool Value); + /// + /// Sets all LEDs in the 's list to true. + /// void AllLedOn(); + /// + /// Sets all LEDs in the 's list to false. + /// void AllLedOff(); + /// + /// Returns a string with all LED states. + /// + /// string LedsToString(); } } diff --git a/NZXTSharp/Devices/SubDevices/Strip.cs b/NZXTSharp/Devices/SubDevices/Strip.cs index 78604a7..06dda78 100644 --- a/NZXTSharp/Devices/SubDevices/Strip.cs +++ b/NZXTSharp/Devices/SubDevices/Strip.cs @@ -2,9 +2,14 @@ using System.Collections.Generic; using System.Text; +using NZXTSharp.Exceptions; using System.Linq; namespace NZXTSharp.Devices { + + /// + /// Represents an RGB Strip subdevice. + /// public class Strip : ISubDevice { private bool _IsActive = true; @@ -15,51 +20,100 @@ public class Strip : ISubDevice { true, true, true, true, true }; + /// + /// Whether or not the current instance is active (on). + /// public bool IsActive { get => _IsActive; } + /// + /// Returns the of the fan. + /// public NZXTDeviceType Type { get => NZXTDeviceType.Fan; } + /// + /// Returns the number of LEDs available on the . + /// public int NumLeds { get => 10; } + /// + /// A list containing the power states of the 's LEDs. + /// public List Leds { get => _Leds; } - + /// + /// Constructs a instance. + /// public Strip() { } + /// + /// Toggles the 's state. + /// public void ToggleState() { this._IsActive = (this._IsActive ? false : true); } + /// + public void SetState(bool State) + { + this._IsActive = State; + } + + /// + /// Toggles a specific LED owned by the device. + /// + /// The index in the 's list to toggle. public void ToggleLed(int Index) { + if (Index > 7 || Index < 0) { throw new SubDeviceLEDDoesNotExistException(); } this._Leds[Index] = (this._Leds[Index] ? false : true); } + /// + /// Toggles all LEDs between a given and index. + /// + /// The index in the 's list to start at. + /// The index in the 's list to end at. public void ToggleLedRange(int Start, int End) { for (int Index = Start; Index <= End; Index++) { _Leds[Index] = (this._Leds[Index] ? false : true); } } + /// + /// Sets all LEDs between a given index and an index to a given . + /// + /// The index in the 's list to start at. + /// The index in the 's list to end at. + /// The value to set each LED to. public void SetLedRange(int Start, int End, bool Value) { for (int Index = Start; Index <= End; Index++) { _Leds[Index] = Value; } } + /// + /// Sets all LEDs in the 's list to true. + /// public void AllLedOn() { for (int index = 0; index < 10; index++) { _Leds[index] = true; } } + /// + /// Sets all LEDs in the 's list to false. + /// public void AllLedOff() { for (int index = 0; index < 10; index++) { _Leds[index] = false; } } + /// + /// Returns a string with all LED states. + /// + /// public string LedsToString() { StringBuilder sb = new StringBuilder(); _Leds.ForEach(c => sb.Append(c + " ")); diff --git a/NZXTSharp/Effects/Alternating.cs b/NZXTSharp/Effects/Alternating.cs index eaf0d20..0051044 100644 --- a/NZXTSharp/Effects/Alternating.cs +++ b/NZXTSharp/Effects/Alternating.cs @@ -8,12 +8,19 @@ // TOTEST namespace NZXTSharp.Effects { + + /// + /// Represents an RGB alternating effect. + /// public class Alternating : IEffect { #pragma warning disable IDE0044 // Add readonly modifier private int _EffectByte = 0x05; private string _EffectName = "Alternating"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; + + /// public Color[] Colors; private Channel _Channel; private Direction _Param1 = new Direction(true, false); @@ -21,16 +28,30 @@ public class Alternating : IEffect { private int speed = 2; #pragma warning restore IDE0044 // Add readonly modifier + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } + + /// public string EffectName { get; } + /// + /// Creates an effect with the given . + /// + /// The s to display. Must be of length (2). public Alternating(Color[] Colors) { this.Colors = Colors; ValidateParams(); } - // Speed Optional, Direction Provided + /// + /// Constructs an effect. + /// + /// The to display. + /// The the effect will move in. + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. public Alternating(Color[] Colors, Direction Direction, int speed = 2) { this.Colors = Colors; this._Param1 = Direction; @@ -38,7 +59,14 @@ public Alternating(Color[] Colors, Direction Direction, int speed = 2) { ValidateParams(); } - public Alternating(Color Color1, Color Color2, Direction Direction, int speed) { + /// + /// Constructs an effect. + /// + /// The first to display. + /// The second to display. + /// The the effect will move in. + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public Alternating(Color Color1, Color Color2, Direction Direction, int speed = 2) { this.Colors = new Color[] { Color1, Color2 }; this._Param1 = Direction; this.speed = speed; @@ -50,10 +78,13 @@ private void ValidateParams() { } } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { List outList = new List(); for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++) { diff --git a/NZXTSharp/Effects/Breathing.cs b/NZXTSharp/Effects/Breathing.cs index 3355bc5..3e70197 100644 --- a/NZXTSharp/Effects/Breathing.cs +++ b/NZXTSharp/Effects/Breathing.cs @@ -8,29 +8,50 @@ // TOTEST namespace NZXTSharp.Effects { + + /// + /// Represents an RGB breathing effect. + /// public class Breathing : IEffect { // Per Effect Fields private int _EffectByte = 0x07; private string _EffectName = "Breathing"; - public readonly List CompatibleWith = new List() { "HuePlus" }; - + + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; + + /// public Color[] Colors; private Channel _Channel; private _03Param _Param1; private CISS _Param2; private int speed = 2; - + + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } + + /// public string EffectName { get; } + /// + /// Constructs a effect. + /// + /// A array of colors to display. public Breathing(Color[] Colors) { this.Colors = Colors; ValidateParams(); } - public Breathing(Color[] Colors, int Speed) { + /// + /// Constructs a effect. + /// + /// A array of colors to display. + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public Breathing(Color[] Colors, int Speed = 2) { this.Colors = Colors; this.speed = Speed; ValidateParams(); @@ -46,10 +67,13 @@ private void ValidateParams() { } } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { List outList = new List(); for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++) { diff --git a/NZXTSharp/Effects/CandleLight.cs b/NZXTSharp/Effects/CandleLight.cs index 9c375fc..b3a0580 100644 --- a/NZXTSharp/Effects/CandleLight.cs +++ b/NZXTSharp/Effects/CandleLight.cs @@ -6,28 +6,47 @@ using NZXTSharp.Params; namespace NZXTSharp.Effects { + + /// + /// Represents an RGB Candle Light effect. + /// public class CandleLight : IEffect { private int _EffectByte = 0x09; private string _EffectName = "CandleLight"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; + + /// public Color Color; private Channel _Channel; private _03Param _Param1; private _02Param _Param2; + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } + + /// public string EffectName { get; } + /// + /// Constructs a effect with a given . + /// + /// The to display. public CandleLight(Color Color) { this.Color = Color; } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel, 0x09, _Param1, _Param2 }; byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Color)); diff --git a/NZXTSharp/Effects/CoveringMarquee.cs b/NZXTSharp/Effects/CoveringMarquee.cs index 7f0440f..2faaead 100644 --- a/NZXTSharp/Effects/CoveringMarquee.cs +++ b/NZXTSharp/Effects/CoveringMarquee.cs @@ -6,35 +6,55 @@ using NZXTSharp.Params; using NZXTSharp.Exceptions; -// TOTEST namespace NZXTSharp.Effects { + + /// + /// Represents an RGB CoveringMarquee effect. + /// public class CoveringMarquee : IEffect { private int _EffectByte = 0x04; private string _EffectName = "CoveringMarquee"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; private Color[] _Colors; private Direction Param1; private CISS Param2; private Channel _Channel; - private IHueDevice Parent; private int _Speed; - + + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } + + /// public string EffectName { get; } - public CoveringMarquee(IHueDevice Parent, Color Color1, Color Color2, Direction Direction, int speed = 2) { - this.Parent = Parent; + /// + /// Constructs a effect. + /// + /// The first in the effect. + /// The second in the effect. + /// The the effect will go in. + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public CoveringMarquee(Color Color1, Color Color2, Direction Direction, int speed = 2) { this._Colors = new Color[] { Color1, Color2 }; this.Param1 = Direction; this._Speed = speed; ValidateParams(); } - public CoveringMarquee(IHueDevice Parent, Color[] Colors, Direction Direction, int speed = 2) { - this.Parent = Parent; + /// + /// Constructs a effect. + /// + /// + /// The the effect will go in. + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public CoveringMarquee(Color[] Colors, Direction Direction, int speed = 2) { this._Colors = Colors; this.Param1 = Direction; this._Speed = speed; @@ -51,10 +71,13 @@ private void ValidateParams() { } } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { List outList = new List(); for (int colorIndex = 0; colorIndex < _Colors.Length; colorIndex++) diff --git a/NZXTSharp/Effects/Fading.cs b/NZXTSharp/Effects/Fading.cs index 985455e..cfde4f0 100644 --- a/NZXTSharp/Effects/Fading.cs +++ b/NZXTSharp/Effects/Fading.cs @@ -8,26 +8,40 @@ // TOTEST namespace NZXTSharp.Effects { + + /// + /// Represents an RGB Fading effect. + /// public class Fading : IEffect { private int _EffectByte = 0x01; private string _EffectName = "Fading"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; + + /// + /// The array of colors used by the effect. + /// public Color[] Colors; private _03Param Param1 = new _03Param(); private CISS Param2; private Channel _Channel; private int _Speed = 2; + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } - public string EffectName { get; } - public Fading(Color[] Colors) { - this.Colors = Colors; - ValidateParams(); - } + /// + public string EffectName { get; } + /// + /// Constructs a effect. + /// + /// The s to display. + /// /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. public Fading(Color[] Colors, int speed = 2) { this.Colors = Colors; this._Speed = speed; @@ -40,10 +54,13 @@ private void ValidateParams() { } } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { List outList = new List(); for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++) { diff --git a/NZXTSharp/Effects/Fixed.cs b/NZXTSharp/Effects/Fixed.cs index 43487a1..7de7aed 100644 --- a/NZXTSharp/Effects/Fixed.cs +++ b/NZXTSharp/Effects/Fixed.cs @@ -6,37 +6,61 @@ using NZXTSharp.Params; namespace NZXTSharp.Effects { + + /// + /// Represents an RGB fixed effect. + /// public class Fixed : IEffect { private int _EffectByte = 0x00; private string _EffectName = "Fixed"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; private Color _Color; private _03Param _Param1 = new _03Param(); private _02Param _Param2 = new _02Param(); private Channel _Channel; + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } + + /// public string EffectName { get; } - + /// + /// Constructs an RGB Fixed effect. + /// + /// The to display. public Fixed(Color color) { this._Color = color; } - public Fixed(Channel Channel, Color color) { + /// + /// Constructs an RGB Fixed effect. + /// + /// The the effect will be applied to. + /// The to display. + public Fixed(Channel Channel, Color color) + { this._Channel = Channel; this._Color = color; } - public bool IsCompatibleWith(string name) { - return CompatibleWith.Contains(name) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { - byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel, 0x00, 0x02, 0x03 }; - byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(_Color)); + this._Channel = Channel; + byte[] SettingsBytes = new byte[] { 0x4b, (byte)_Channel, 0x00, 0x02, 0x03 }; + byte[] final = SettingsBytes.ConcatenateByteArr(_Channel.BuildColorBytes(_Color)); return new List() { final }; } } diff --git a/NZXTSharp/Effects/IEffect.cs b/NZXTSharp/Effects/IEffect.cs index b1c0135..230e4e0 100644 --- a/NZXTSharp/Effects/IEffect.cs +++ b/NZXTSharp/Effects/IEffect.cs @@ -5,17 +5,40 @@ using NZXTSharp.Devices; namespace NZXTSharp.Effects { + + /// + /// Represents a generic RGB effect. + /// public interface IEffect { + /// + /// The 's EffectByte. + /// int EffectByte { get; } + /// + /// The name of the . + /// string EffectName { get; } + /// + /// The to set the on. + /// Channel Channel { get; set; } + /// + /// Builds and returns the buffer queue needed to set the . + /// + /// + /// List BuildBytes(Channel Channel); - bool IsCompatibleWith(string Device); + /// + /// Checks to see if the is compatible with a given . + /// + /// + /// + bool IsCompatibleWith(NZXTDeviceType Type); } } diff --git a/NZXTSharp/Effects/Marquee.cs b/NZXTSharp/Effects/Marquee.cs index 3588738..0875707 100644 --- a/NZXTSharp/Effects/Marquee.cs +++ b/NZXTSharp/Effects/Marquee.cs @@ -8,35 +8,53 @@ // TOTEST namespace NZXTSharp.Effects { + + /// + /// Represents an RGB marquee effect. + /// public class Marquee : IEffect { private int _EffectByte = 0x03; private string _EffectName = "Marquee"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; private Color _Color; private Direction Param1; private LSS Param2; private Channel _Channel; - private IHueDevice Parent; #region Properties + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } + + /// public string EffectName { get; } #endregion - public Marquee(IHueDevice Parent, Color Color, Direction Direction, LSS LSS) { - this.Parent = Parent; + /// + /// Constructs a effect. + /// + /// The of the effect. + /// The of the effect. + /// The param to apply. + public Marquee(Color Color, Direction Direction, LSS LSS) { this._Color = Color; this.Param1 = Direction; this.Param2 = LSS; } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { List outList = new List(); byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel, 0x03, Param1, Param2 }; diff --git a/NZXTSharp/Effects/Pulse.cs b/NZXTSharp/Effects/Pulse.cs index 0cb73a0..0b762f4 100644 --- a/NZXTSharp/Effects/Pulse.cs +++ b/NZXTSharp/Effects/Pulse.cs @@ -8,30 +8,44 @@ // TOTEST namespace NZXTSharp.Effects { + + /// + /// Represents an RGB pulse effect. + /// public class Pulse : IEffect { #pragma warning disable IDE0044 // Add readonly modifier private int _EffectByte = 0x06; private string _EffectName = "Pulse"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; + + /// + /// The array of colors used by the effect. + /// public Color[] Colors; private Channel _Channel; private CISS _Param2; private int speed = 2; #pragma warning restore IDE0044 // Add readonly modifier + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } - public string EffectName { get; } - public Pulse(Color[] Colors) { - this.Colors = Colors; - ValidateParams(); - } + /// + public string EffectName { get; } - public Pulse(Color[] Colors, int speed) { + /// + /// Constructs a effect with the given array and speed. + /// + /// + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public Pulse(Color[] Colors, int Speed = 2) { this.Colors = Colors; - this.speed = speed; + this.speed = Speed; ValidateParams(); } @@ -41,10 +55,13 @@ private void ValidateParams() { } } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { List outList = new List(); for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++) { diff --git a/NZXTSharp/Effects/SpectrumWave.cs b/NZXTSharp/Effects/SpectrumWave.cs index 3d12d9c..db03587 100644 --- a/NZXTSharp/Effects/SpectrumWave.cs +++ b/NZXTSharp/Effects/SpectrumWave.cs @@ -7,29 +7,48 @@ // TOTEST namespace NZXTSharp.Effects { + + /// + /// Represents an RGB Spectrum Wave effect. + /// public class SpectrumWave : IEffect { private int _EffectByte = 0x02; private string _EffectName = "SpectrumWave"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; private int speed; private Direction Param1; private CISS Param2; private Channel _Channel; + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } + + /// public string EffectName { get; } - public SpectrumWave(Direction Direction, int speed = 2) { + /// + /// Constructs a effect with the given . + /// + /// + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public SpectrumWave(Direction Direction, int Speed = 2) { this.Param1 = Direction; - this.Param2 = new CISS(0, speed); + this.Param2 = new CISS(0, Speed); } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) + { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel, 0x02, Param1, Param2 }; byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(new Color(0, 0, 255))); diff --git a/NZXTSharp/Effects/Wings.cs b/NZXTSharp/Effects/Wings.cs index c64bd82..c502822 100644 --- a/NZXTSharp/Effects/Wings.cs +++ b/NZXTSharp/Effects/Wings.cs @@ -7,27 +7,41 @@ using NZXTSharp.Devices; namespace NZXTSharp.Effects { + + /// + /// Represents an RGB wings effect. + /// public class Wings : IEffect { private int _EffectByte = 0x0c; private string _EffectName = "Wings"; - public readonly List CompatibleWith = new List() { "HuePlus" }; + /// + public readonly List CompatibleWith = new List() { NZXTDeviceType.HuePlus }; + + /// + /// The array of colors used by the effect. + /// public Color[] Colors; private Channel _Channel; private _03Param _Param1; private CISS _Param2; private int speed = 2; + /// public int EffectByte { get; } + + /// public Channel Channel { get; set; } - public string EffectName { get; } - public Wings(Color[] Colors) { - this.Colors = Colors; - ValidateParams(); - } + /// + public string EffectName { get; } - public Wings(Color[] Colors, int Speed) { + /// + /// Constructs a effect with the given array and speed. + /// + /// + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public Wings(Color[] Colors, int Speed = 2) { this.Colors = Colors; this.speed = Speed; ValidateParams(); @@ -43,10 +57,12 @@ private void ValidateParams() { } } - public bool IsCompatibleWith(string Device) { - return CompatibleWith.Contains(Device) ? true : false; + /// + public bool IsCompatibleWith(NZXTDeviceType Type) { + return CompatibleWith.Contains(Type) ? true : false; } + /// public List BuildBytes(Channel Channel) { List outList = new List(); for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++) { diff --git a/NZXTSharp/INZXTDevice.cs b/NZXTSharp/INZXTDevice.cs index fd6046f..50f5583 100644 --- a/NZXTSharp/INZXTDevice.cs +++ b/NZXTSharp/INZXTDevice.cs @@ -3,8 +3,15 @@ using System.Text; namespace NZXTSharp { + + /// + /// Represents a generic NZXT device. + /// public interface INZXTDevice { + /// + /// The of the . + /// Devices.NZXTDeviceType Type { get; } } diff --git a/NZXTSharp/NZXTSharp.csproj b/NZXTSharp/NZXTSharp.csproj index 73d3ad2..5bb6c57 100644 --- a/NZXTSharp/NZXTSharp.csproj +++ b/NZXTSharp/NZXTSharp.csproj @@ -40,6 +40,7 @@ Most effects still not working. 1701;1702;0414;0169;0649 + D:\Programming\1.GitHub_Repos\NZXTSharp\NZXTSharp\NZXTSharp.xml diff --git a/NZXTSharp/NZXTSharp.xml b/NZXTSharp/NZXTSharp.xml new file mode 100644 index 0000000..e14573c --- /dev/null +++ b/NZXTSharp/NZXTSharp.xml @@ -0,0 +1,1314 @@ + + + + NZXTSharp + + + + + Contains information needed to open a COM port. + + + + + The setting of the instance. + + + + + The setting of the instance. + + + + + The write timeout setting of the instance (ms). + + + + + The read timeout setting of the instance (ms). + + + + + The baud setting of the instance. + + + + + The databits setting of the instance. + + + + + The custom name of the instance. + + + + + Constructs a object. + + The type to use. + The number of to use. + The WriteTimeout in ms. + The ReadTimeout in ms. + The baud to use. + The number of DataBits to use. + A custom name for the . + + + + Represents a with some useful methods. + + + + + The SerialPort instance owned by the Controller. + + + + + The the used to start. + + + + + Returns a bool telling whether or not the 's is open. + + + + + Opens the SerialController on a specific COM port. + + The COM port to open in "COMx" format. + + + + Attempts to open each of the COM ports in with the provided . + + An array of possible ports the device could be on. + The to open the port with. + + + + Writes the bytes in the , and returns the device's response. + + The bytes to write to the port. + The expected length of the response buffer (bytes). + + + + + Writes the given to the connected device. + + The bytes to write. + + + + Disposes of and reinitializes the instance. + + + + + Disposes of the instance. + + + + + Represents a color. + + + + + The R value of the color. + + + + + The G value of the color. + + + + + The B value of the color. + + + + + Constructs an empty . + + + + + Creates a Color instance from a hex color code. + + The color code. Supports codes with a leading #, and without. + + + + Creates a Color instance from R, G, B values. + + The color's R value. Must be 0-255 (inclusive). + The color's G value. Must be 0-255 (inclusive). + The color's B value. Must be 0-255 (inclusive). + + + + Returns a list of 40 "#ffffff" color codes in G, R, B format. + + + + + + Expands the instance into a byte array. + + + + + + Expands the instance into an array of byte arrays. Each sub array contains the RGB values for each LED. + + The number of LED triplets to create in the array. + + + + + Definitions of unique IDs for all NZXT devices. + + + + + If device type is unknown. + + + + + + + + + + Any fan, RGB or otherwise. + + + + + An RGB strip. + + + + + A generic Kraken device. + + + + + A generic KrakenX device. + + + + + A generic KrakenM device. + + + + + A generic Hue device. + + + + + A generic motherboard device. + + + + + A generic Grid device. + + + + + Contains the Manufacturer and Product IDs of NZXT devices. + + + + + An unknown ID. + + + + + Represents a channel on an NZXT device. + + + + + The channelbyte of the . + + + + + The currently applied to the . + + + + + Whether or not the current is active (on). + + + + + The 's object. + + + + + The device that owns the . + + + + + A list of s owned by the . + + + + + Constructs a object with a given . + + The ChannelByte to construct the channel from. + + + + Constructs a object with a given , + owned by a given . + + The ChannelByte to construct the channel from. + The that will own the + + + + Constructs a object with a given , + owned by a given , + with a given . + + The ChannelByte to construct the channel from. + The that owns the + The owned by the . + + + + Refreshes all s in the 's list. + + + + + Turns the on. + + + + + Turns the off. + + + + + Updates the 's . + + + + + Sets the 's to the given . + + + + + + Returns the 's ChannelByte. + + + + + + Represents information about a . + + + + + Represents the total number of LEDs available on a . + + + + + The number of SubDevices available on a . + + + + + Type of s available on a . + + + + + + + + + + Constructs a with a given as its parent, from some given channel handshake . + + + + + + + Constructs a object from some given channel handshake . + + + + + + Updates the parent 's . + + + + + + + + + + + Triggers when a generic log message is sent. + + + + + Triggers when data is received from the COM port. + + + + + Represents an NZXT Hue+ lighting controller. + + + + + The device's product name. + + + + + A object representing both channels on the . + + + + + A object representing the Channel 1 of the device. + + + + + A object representing the Channel 2 of the device. + + + + + A containing all objects owned by the device. + + + + + A custom name for the instance. + + + + + The of the object. + + + + + Triggers when a generic log message is sent. + + + + + Triggers when data is received from the COM port. + + + + + Constructs a instance. + + + + + Constructs a instance with a custom count, + and a custom name . + + + A custom name for the instance. + + + + Disposes of and reconnects to the device's . + + + + + Disposes of the device's . + + + + + Applies the given to the given . + + The to apply the effect to. + The to apply. + Whether or not to save the given effect to the given channel. + + + + Writes a custom to the device's . + + The buffer to write to the device. + + + + Turns the device's unit led on. + + + + + Turns the device's unit led off. + + + + + Sets the device's unit led state. true: on, false: off. + + Which state to set the LED to; true: on, false: off. + + + + Updates the given 's . + + + + + + Represents a generic NZXT Hue device. + + + + + Applies a given to the given . + + + + + + + + Sends a given to the 's . + + The buffer to send. + + + + Updates the object owned by the given . + + + + + + Represents both channels owned by a Hue device. + + + + + Represents Channel 1 of a Hue device. + + + + + Represents Channel 2 of a hue device. + + + + + A list of all s owned by a hue device. + + + + + Represents a fan. + + + + + Whether or not the current instance is active (on). + + + + + Returns the of the fan. + + + + + Returns the number of LEDs available on the . + + + + + A list containing the power states of the 's LEDs. + + + + + Constructs a instance. + + + + + Toggles the 's state. + + + + + + + + Toggles a specific LED owned by the device. + + The index in the 's list to toggle. + + + + Toggles all LEDs between a given and index. + + The index in the 's list to start at. + The index in the 's list to end at. + + + + Sets all LEDs between a given index and an index to a given . + + The index in the 's list to start at. + The index in the 's list to end at. + The value to set each LED to. + + + + Sets all LEDs in the 's list to true. + + + + + Sets all LEDs in the 's list to false. + + + + + Returns a string with all LED states. + + + + + + Represents a sub device. + + + + + The 's . + + + + + Whether or not the current instance is active (on). + + + + + Returns the number of LEDs available on the . + + + + + A list containing the power states of the 's LEDs. + + + + + Toggles the 's state. + + + + + Sets the 's state. + + The state to set the to. true: on, false: off. + + + + Toggles a specific LED owned by the . + + The index in the 's list to toggle. + + + + Toggles all LEDs between a given and index. + + The index in the 's list to start at. + The index in the 's list to end at. + + + + Sets all LEDs between a given index and an index to a given . + + The index in the 's list to start at. + The index in the 's list to end at. + The value to set each LED to. + + + + Sets all LEDs in the 's list to true. + + + + + Sets all LEDs in the 's list to false. + + + + + Returns a string with all LED states. + + + + + + Represents an RGB Strip subdevice. + + + + + Whether or not the current instance is active (on). + + + + + Returns the of the fan. + + + + + Returns the number of LEDs available on the . + + + + + A list containing the power states of the 's LEDs. + + + + + Constructs a instance. + + + + + Toggles the 's state. + + + + + + + + Toggles a specific LED owned by the device. + + The index in the 's list to toggle. + + + + Toggles all LEDs between a given and index. + + The index in the 's list to start at. + The index in the 's list to end at. + + + + Sets all LEDs between a given index and an index to a given . + + The index in the 's list to start at. + The index in the 's list to end at. + The value to set each LED to. + + + + Sets all LEDs in the 's list to true. + + + + + Sets all LEDs in the 's list to false. + + + + + Returns a string with all LED states. + + + + + + Represents an RGB alternating effect. + + + + + + + + + + + + + + + + + + + + Creates an effect with the given . + + The s to display. Must be of length (2). + + + + Constructs an effect. + + The to display. + The the effect will move in. + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + Constructs an effect. + + The first to display. + The second to display. + The the effect will move in. + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + + + + + + + Represents an RGB breathing effect. + + + + + + + + + + + + + + + + + + + + Constructs a effect. + + A array of colors to display. + + + + Constructs a effect. + + A array of colors to display. + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + + + + + + + Represents an RGB Candle Light effect. + + + + + + + + + + + + + + + + + + + + Constructs a effect with a given . + + The to display. + + + + + + + + + + Represents an RGB CoveringMarquee effect. + + + + + + + + + + + + + + + + + Constructs a effect. + + The first in the effect. + The second in the effect. + The the effect will go in. + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + Constructs a effect. + + + The the effect will go in. + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + + + + + + + Represents an RGB Fading effect. + + + + + + + + The array of colors used by the effect. + + + + + + + + + + + + + + Constructs a effect. + + The s to display. + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + + + + + + + Represents an RGB fixed effect. + + + + + + + + + + + + + + + + + Constructs an RGB Fixed effect. + + The to display. + + + + Constructs an RGB Fixed effect. + + The the effect will be applied to. + The to display. + + + + + + + + + + Represents a generic RGB effect. + + + + + The 's EffectByte. + + + + + The name of the . + + + + + The to set the on. + + + + + Builds and returns the buffer queue needed to set the . + + + + + + + Checks to see if the is compatible with a given . + + + + + + + Represents an RGB marquee effect. + + + + + + + + + + + + + + + + + Constructs a effect. + + The of the effect. + The of the effect. + The param to apply. + + + + + + + + + + Represents an RGB pulse effect. + + + + + + + + The array of colors used by the effect. + + + + + + + + + + + + + + Constructs a effect with the given array and speed. + + + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + + + + + + + Represents an RGB Spectrum Wave effect. + + + + + + + + + + + + + + + + + Constructs a effect with the given . + + + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + + + + + + + Represents an RGB wings effect. + + + + + + + + The array of colors used by the effect. + + + + + + + + + + + + + + Constructs a effect with the given array and speed. + + + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + + + + + + + Represents a generic NZXT device. + + + + + The of the . + + + + + Represents an 02 effect Param + + + + + + + + + + + + + + + + + Represents an 03 effect param. + + + + + + + + + + + + + + + + + Represents a CISS effect param. + + + + + + + + Constructs a instance. + + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + Constructs a instance. + + The index of the color in the list. + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + + + + + + + + + + + + + Represents a effect param. + + + + + Whether or not the effect will move. + + + + + Whether or not the effect will move forward or backward. + + + + + + + + Constructs a param. + + Whether or not the param moves forward or backward. + Whether or not the effect will move smoothly. + + + + + + + + + + + + + An effect parameter. + + + + + The int representation of the effect's byte value. + + + + + Gets the int representation of the effect's byte value. + + + + + + Represents an LSS param. + + + + + + + + + + + Constructs an param. + + Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + The LED group size, LEDSizes must be between 3-6 (inclusive). + + + + + + + + + + + + diff --git a/NZXTSharp/Params/02Param.cs b/NZXTSharp/Params/02Param.cs index 12c7f5b..87b3ac5 100644 --- a/NZXTSharp/Params/02Param.cs +++ b/NZXTSharp/Params/02Param.cs @@ -3,17 +3,25 @@ using System.Text; namespace NZXTSharp.Params { + + /// + /// Represents an 02 effect Param + /// internal class _02Param : IParam { - private int _Value = 0x02; - private List _CompatibleWith = new List() { "HuePlus" }; + private readonly int _Value = 0x02; + /// public int Value { get => GetValue(); } - public List CompatibleWith { get; } + /// public int GetValue() { return 0x02; } + /// + /// + /// + /// public static implicit operator byte(_02Param param) { return (byte)0x02; } diff --git a/NZXTSharp/Params/03Param.cs b/NZXTSharp/Params/03Param.cs index ee80daf..e52f6d0 100644 --- a/NZXTSharp/Params/03Param.cs +++ b/NZXTSharp/Params/03Param.cs @@ -5,17 +5,26 @@ using NZXTSharp; namespace NZXTSharp.Params { + + /// + /// Represents an 03 effect param. + /// internal class _03Param : IParam { private int _Value = 0x03; private List _CompatibleWith = new List() { "HuePlus" }; + /// public int Value { get => GetValue(); } - public List CompatibleWith { get; } + /// public int GetValue() { return 0x03; } + /// + /// + /// + /// public static implicit operator byte(_03Param param) { return (byte)0x03; } diff --git a/NZXTSharp/Params/CISS.cs b/NZXTSharp/Params/CISS.cs index 04755e2..02f2f0f 100644 --- a/NZXTSharp/Params/CISS.cs +++ b/NZXTSharp/Params/CISS.cs @@ -5,22 +5,34 @@ using NZXTSharp.Exceptions; namespace NZXTSharp.Params { + + /// + /// Represents a CISS effect param. + /// internal class CISS : IParam { - private int colorIndex; + private readonly int colorIndex; private int speed; private int evaluatedIndex; - private int _Value; - private List _CompatibleWith = new List() { "HuePlus" }; + private readonly int _Value; + /// public int Value { get => GetValue(); } - public List CompatibleWith { get; } - public CISS(int speed) { + /// + /// Constructs a instance. + /// + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public CISS(int speed = 2) { this.speed = speed; ValidateInput(); } - public CISS(int colorIndex, int speed) { + /// + /// Constructs a instance. + /// + /// The index of the color in the list. + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + public CISS(int colorIndex, int speed = 2) { this.colorIndex = colorIndex; this.speed = speed; @@ -37,11 +49,16 @@ private void ValidateInput() { throw new InvalidParamException("Invalid Param; ColorIndex Value Must Be Between 7 and 0 (inclusive). (Zero-Indexed)"); } + /// public int GetValue() { string concatenated = evaluatedIndex.ToString("X") + speed.ToString(); return int.Parse(concatenated, System.Globalization.NumberStyles.HexNumber); } + /// + /// + /// + /// public static implicit operator byte(CISS param) { return (byte)param.GetValue(); } diff --git a/NZXTSharp/Params/Direction.cs b/NZXTSharp/Params/Direction.cs index d8f5cd7..093da7d 100644 --- a/NZXTSharp/Params/Direction.cs +++ b/NZXTSharp/Params/Direction.cs @@ -3,22 +3,40 @@ using System.Text; namespace NZXTSharp.Params { + + /// + /// Represents a effect param. + /// public class Direction : IParam { private bool _withMovement; private bool _isForward; private int _Value; private List _CompatibleWith = new List() { "HuePlus" }; + /// + /// Whether or not the effect will move. + /// public bool WithMovement { get; } + + /// + /// Whether or not the effect will move forward or backward. + /// public bool IsForward { get; } + + /// public int Value { get => GetValue(); } - public List CompatibleWith { get; } - public Direction(bool isForward, bool withMovement) { + /// + /// Constructs a param. + /// + /// Whether or not the param moves forward or backward. + /// Whether or not the effect will move smoothly. + public Direction(bool isForward = true, bool withMovement = true) { this._withMovement = withMovement; this._isForward = isForward; } + /// public int GetValue() { if (IsForward) if (WithMovement) @@ -32,6 +50,10 @@ public int GetValue() { return 0x13; // Backward W/O movement } + /// + /// + /// + /// public static implicit operator byte(Direction param) { return (byte)param.GetValue(); } diff --git a/NZXTSharp/Params/IParam.cs b/NZXTSharp/Params/IParam.cs index b02198e..4ea561f 100644 --- a/NZXTSharp/Params/IParam.cs +++ b/NZXTSharp/Params/IParam.cs @@ -2,13 +2,24 @@ using System.Collections.Generic; using System.Text; +using NZXTSharp.Devices; + namespace NZXTSharp.Params { + + /// + /// An effect parameter. + /// public interface IParam { + /// + /// The int representation of the effect's byte value. + /// int Value { get; } - List CompatibleWith { get; } - + /// + /// Gets the int representation of the effect's byte value. + /// + /// int GetValue(); diff --git a/NZXTSharp/Params/LSS.cs b/NZXTSharp/Params/LSS.cs index ac52c4d..6074f4a 100644 --- a/NZXTSharp/Params/LSS.cs +++ b/NZXTSharp/Params/LSS.cs @@ -5,23 +5,34 @@ using NZXTSharp.Exceptions; namespace NZXTSharp.Params { + + /// + /// Represents an LSS param. + /// public class LSS : IParam { - private List> LSSTable = new List>() { + private readonly List> LSSTable = new List>() { new List() {0x00, 0x08, 0x10, 0x18}, new List() {0x01, 0x09, 0x11, 0x19}, new List() {0x02, 0x0a, 0x12, 0x1a}, new List() {0x03, 0x0b, 0x13, 0x1b}, new List() {0x04, 0x0c, 0x14, 0x1c} }; - private int _speed; - private int _LEDSize; - private int _Value; - private List _CompatibleWith = new List() { "HuePlus" }; + private readonly int _speed; + private readonly int _LEDSize; + private readonly int _Value; + + /// + private readonly List _CompatibleWith = new List() { Devices.NZXTDeviceType.HuePlus }; + /// public int Value { get => GetValue(); } - public List CompatibleWith { get; } - public LSS(int speed, int LEDSize) { + /// + /// Constructs an param. + /// + /// Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2. + /// The LED group size, LEDSizes must be between 3-6 (inclusive). + public LSS(int speed = 2, int LEDSize = 4) { this._speed = speed; this._LEDSize = LEDSize; ValidateParams(); @@ -35,10 +46,15 @@ private void ValidateParams() { throw new InvalidParamException("Invalid Param; LEDSize Must Be Between 3 and 6 (inclusive)."); } + /// public int GetValue() { return LSSTable[_speed][this._LEDSize - 3]; } + /// + /// + /// + /// public static implicit operator byte(LSS param) { return (byte)param.GetValue(); } diff --git a/README.md b/README.md index 4d39aaa..5aae9e7 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ NZXTSharp is a C# package that allows interaction with NZXT's Hue+. Support for other devices will be coming. -Find NZXTSharp on NuGet [here][0]. If you are adding through Visual Studio, please be sure to check `Include Prereleases`. +You can find NZXTSharp on NuGet [here][0]. If you are adding through Visual Studio, please be sure to check `Include Prereleases`. -**Please keep in mind that NZXTSharp is in heavy development, and will have breaking changes in the future.** +**Please keep in mind that NZXTSharp is in development, and will have breaking changes in the future.** -Documentation is still a work in progress, and can be found at [NZXTSharp's readthedocs.io page][3]. Docs are built from [the docs branch][4]. +Documentation can be found at [NZXTSharp's readthedocs.io page][3]. Docs are built from [the docs branch][4]. ### Syntax NZXTSharp's syntax is lightweight, only taking a few lines to get started.