Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from akmadian/develop
Browse files Browse the repository at this point in the history
v1.0 PR
  • Loading branch information
Ari Madian authored Jan 30, 2019
2 parents cc4bda4 + 7cd2c50 commit ceeac53
Show file tree
Hide file tree
Showing 33 changed files with 2,302 additions and 216 deletions.
47 changes: 40 additions & 7 deletions NZXTSharp/COM/SerialCOMData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,53 @@ namespace NZXTSharp.COM {
/// </summary>
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;

/// <summary>
/// The <see cref="System.IO.Ports.Parity"/> setting of the <see cref="SerialCOMData"/> instance.
/// </summary>
public Parity Parity { get => _Parity; }

/// <summary>
/// The <see cref="System.IO.Ports.StopBits"/> setting of the <see cref="SerialCOMData"/> instance.
/// </summary>
public StopBits StopBits { get => _StopBits; }

/// <summary>
/// The write timeout setting of the <see cref="SerialCOMData"/> instance (ms).
/// </summary>
public int WriteTimeout { get => _WriteTimeout; }

/// <summary>
/// The read timeout setting of the <see cref="SerialCOMData"/> instance (ms).
/// </summary>
public int ReadTimeout { get => _ReadTimeout; }

/// <summary>
/// The baud setting of the <see cref="SerialCOMData"/> instance.
/// </summary>
public int Baud { get => _Baud; }

/// <summary>
/// The databits setting of the <see cref="SerialCOMData"/> instance.
/// </summary>
public int DataBits { get => _DataBits; }

/// <summary>
/// The custom name of the <see cref="SerialCOMData"/> instance.
/// </summary>
public string Name { get => _Name; }
#endregion


#region Methods
/// <summary>
/// Constructs a <see cref="SerialCOMData"/> object.
/// </summary>
Expand All @@ -36,6 +67,7 @@ internal class SerialCOMData {
/// <param name="ReadTimeout"> The ReadTimeout in ms.</param>
/// <param name="Baud"> The baud to use.</param>
/// <param name="DataBits"> The number of DataBits to use.</param>
/// <param name="Name">A custom name for the <see cref="SerialCOMData"/>.</param>
public SerialCOMData(Parity Parity, StopBits StopBits, int WriteTimeout, int ReadTimeout, int Baud, int DataBits, string Name = "") {
this._Parity = Parity;
this._StopBits = StopBits;
Expand All @@ -58,5 +90,6 @@ public override string ToString()
this.Name
);
}
#endregion
}
}
24 changes: 21 additions & 3 deletions NZXTSharp/COM/SerialController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
using System.IO.Ports;

namespace NZXTSharp.COM {

/// <summary>
/// Represents a <see cref="SerialPort"/> with some useful methods.
/// </summary>
internal class SerialController : ICOMController {


#region Properties and Fields
private SerialPort _Port;
private SerialCOMData _StartData;
private string[] _PossiblePorts;
Expand All @@ -24,25 +29,37 @@ internal class SerialController : ICOMController {
/// </summary>
public SerialCOMData StartData { get => _StartData; }

/// <summary>
/// Returns a bool telling whether or not the <see cref="SerialController"/>'s <see cref="Port"/> is open.
/// </summary>
public bool IsOpen { get => _Port.IsOpen; }
#endregion

#region Constructors
/// <summary>
///
/// Opens the SerialController on a specific COM port.
/// </summary>
/// <param name="COMPort"></param>
/// <param name="COMPort">The COM port to open in "COMx" format.</param>
public SerialController(string COMPort) {
this._PossiblePorts = new string[] { COMPort };

Initialize();
}

/// <summary>
/// Attempts to open each of the COM ports in <paramref name="PossiblePorts"/> with the provided <paramref name="Data"/>.
/// </summary>
/// <param name="PossiblePorts">An array of possible ports the device could be on.</param>
/// <param name="Data">The <see cref="SerialCOMData"/> to open the port with.</param>
public SerialController(string[] PossiblePorts, SerialCOMData Data) {
this._PossiblePorts = PossiblePorts;
this._StartData = Data;

Initialize();
}
#endregion

#region Methods
private void Initialize() {
try
{
Expand Down Expand Up @@ -129,5 +146,6 @@ public void Dispose()
{
_Port.Close();
}
#endregion
}
}
103 changes: 80 additions & 23 deletions NZXTSharp/Core/Color.cs
Original file line number Diff line number Diff line change
@@ -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 {

/// <summary>
/// Represents a color.
/// </summary>
public class Color
{
#region Properties and Fields
private readonly int _R;
private readonly int _G;
private readonly int _B;

/// <summary>
/// The R value of the color.
/// </summary>
public int R { get => _R; }

/// <summary>
/// The G value of the color.
/// </summary>
public int G { get => _G; }

private int R;
private int G;
private int B;
/// <summary>
/// The B value of the color.
/// </summary>
public int B { get => _B; }
#endregion

#region Constructors
/// <summary>
/// Constructs an empty <see cref="Color"/>.
/// </summary>
public Color()
{

}

/// <summary>
/// Creates a Color instance from a hex color code.
/// </summary>
/// <param name="hexColor">The color code. Supports codes with a leading #, and without.</param>
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);
}

/// <summary>
/// Creates a Color instance from R, G, B values.
/// </summary>
/// <param name="R">The color's R value. Must be 0-255 (inclusive).</param>
/// <param name="G">The color's G value. Must be 0-255 (inclusive).</param>
/// <param name="B">The color's B value. Must be 0-255 (inclusive).</param>
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
/// <summary>
/// Returns a list of 40 "#ffffff" color codes in G, R, B format.
/// </summary>
/// <returns></returns>
public byte[] AllOff()
{
List<int> outBytes = new List<int>();
Expand All @@ -55,14 +105,18 @@ public byte[] AllOff()
return outB.ToArray();
}

public byte[] Expanded()
/// <summary>
/// Expands the <see cref="Color"/> instance into a byte array.
/// </summary>
/// <returns></returns>
internal byte[] Expanded()
{
List<byte> outBytes = new List<byte>();
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();
Expand All @@ -71,21 +125,24 @@ public byte[] Expanded()
/// <summary>
/// Expands the <see cref="Color"/> instance into an array of byte arrays. Each sub array contains the RGB values for each LED.
/// </summary>
/// <param name="NumLeds"></param>
/// <param name="NumLeds">The number of LED triplets to create in the array.</param>
/// <returns></returns>
public byte[][] ExpandedChunks(int NumLeds)
internal byte[][] ExpandedChunks(int NumLeds)
{
List<byte[]> outBytes = new List<byte[]>();
for (int i = 0; i < NumLeds; i++)
{
List<byte> arr = new List<byte>();
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
}
}

56 changes: 56 additions & 0 deletions NZXTSharp/Devices/Enum/NZXTDeviceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,100 @@
using System.Text;

namespace NZXTSharp.Devices {

/// <summary>
/// Definitions of unique IDs for all NZXT devices.
/// </summary>
public enum NZXTDeviceType
{
/// <summary>
/// If device type is unknown.
/// </summary>
Unknown = 0,

/// <summary>
///
/// </summary>
NotActive = 1,


// SubDevices
/// <summary>
/// Any fan, RGB or otherwise.
/// </summary>
Fan = 2,

/// <summary>
/// An RGB strip.
/// </summary>
Strip = 3,

// Krakens
/// <summary>
/// A generic Kraken device.
/// </summary>
Kraken = 4,

/// <summary>
/// A generic KrakenX device.
/// </summary>
KrakenX = 5,

/// <summary>
/// A generic KrakenM device.
/// </summary>
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
/// <summary>
/// A generic Hue device.
/// </summary>
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
/// <summary>
/// A generic motherboard device.
/// </summary>
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
/// <summary>
/// A generic Grid device.
/// </summary>
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
}
}
Loading

0 comments on commit ceeac53

Please sign in to comment.