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 #11 from akmadian/develop
Browse files Browse the repository at this point in the history
1.0.3-beta release
  • Loading branch information
Ari Madian authored Jan 27, 2019
2 parents bacb4c2 + 98c2c3e commit cc4bda4
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 113 deletions.
2 changes: 1 addition & 1 deletion NZXTSharp/COM/SerialCOMData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NZXTSharp.COM {
/// <summary>
/// Contains information needed to open a COM port.
/// </summary>
class SerialCOMData {
internal class SerialCOMData {

private Parity _Parity;
private StopBits _StopBits;
Expand Down
2 changes: 1 addition & 1 deletion NZXTSharp/COM/SerialController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.IO.Ports;

namespace NZXTSharp.COM {
class SerialController : ICOMController {
internal class SerialController : ICOMController {

private SerialPort _Port;
private SerialCOMData _StartData;
Expand Down
92 changes: 90 additions & 2 deletions NZXTSharp/COM/USBController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,99 @@
using System.Collections.Generic;
using System.Text;


using NZXTSharp.Devices;
using NZXTSharp.Exceptions;

namespace NZXTSharp.COM {
public class USBController : ICOMController {
internal class USBController : ICOMController {

private NZXTDeviceType _Type;
private SerialDeviceID _ID;

public NZXTDeviceType Type { get => _Type; }
public SerialDeviceID ID { get => _ID; }

public USBController(NZXTDeviceType Type) {
this._Type = Type;
ResolveDeviceID();
}

public void Initialize()
{

}

public USBController(int DeivceID) {
public void Write()
{

}

private void ResolveDeviceID()
{
switch (_Type) // TODO: Find better way
{
// Kraken Devices
case NZXTDeviceType.KrakenM:
this._ID = SerialDeviceID.KrakenM;
break;
case NZXTDeviceType.KrakenM22:
this._ID = SerialDeviceID.KrakenM;
break;
case NZXTDeviceType.KrakenX:
this._ID = SerialDeviceID.KrakenX;
break;
case NZXTDeviceType.KrakenX42:
this._ID = SerialDeviceID.KrakenX;
break;
case NZXTDeviceType.KrakenX52:
this._ID = SerialDeviceID.KrakenX;
break;
case NZXTDeviceType.KrakenX62:
this._ID = SerialDeviceID.KrakenX;
break;
case NZXTDeviceType.KrakenX72:
this._ID = SerialDeviceID.KrakenX;
break;

// Hue Devices
case NZXTDeviceType.Hue2:
this._ID = SerialDeviceID.Hue2;
break;
case NZXTDeviceType.HueAmbient:
this._ID = SerialDeviceID.HueAmbient;
break;

// Grid Devices
case NZXTDeviceType.GridV3:
this._ID = SerialDeviceID.GridV3;
break;

// Motherboards
case NZXTDeviceType.N7:
this._ID = SerialDeviceID.N7;
break;
case NZXTDeviceType.N7_Z390:
this._ID = SerialDeviceID.N7_Z390;
break;

// Misc
case NZXTDeviceType.H7Lumi:
this._ID = SerialDeviceID.H7Lumi;
break;
case NZXTDeviceType.SmartDevice:
this._ID = SerialDeviceID.SmartDevice;
break;

default:
throw new IncompatibleDeviceTypeException();
}
}

public string[] ScanForDevices()
{
// TODO
return new[] { "" };
}
}
}
48 changes: 22 additions & 26 deletions NZXTSharp/Core/Color.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
Expand Down Expand Up @@ -56,39 +57,34 @@ public byte[] AllOff()

public byte[] Expanded()
{
List<int> outBytes = new List<int>();
List<byte> outBytes = new List<byte>();
for (int i = 0; i < 40; i++)
{
outBytes.Add(G);
outBytes.Add(R);
outBytes.Add(B);
}

List<byte> outB = new List<byte>();

foreach (int val in outBytes)
{
outB.Add(Convert.ToByte(val));
outBytes.Add(Convert.ToByte(G));
outBytes.Add(Convert.ToByte(R));
outBytes.Add(Convert.ToByte(B));
}

return outB.ToArray();
return outBytes.ToArray();
}

public byte[] Expanded(int NumLeds) {
List<int> outBytes = new List<int>();
for (int i = 0; i < NumLeds; i++) {
outBytes.Add(G);
outBytes.Add(R);
outBytes.Add(B);
}

List<byte> outB = new List<byte>();

foreach (int val in outBytes) {
outB.Add(Convert.ToByte(val));
/// <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>
/// <returns></returns>
public 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());
}

return outB.ToArray();
return outBytes.ToArray();
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions NZXTSharp/Core/Exceptions/IncompatibleDeviceTypeException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NZXTSharp.Exceptions
{
internal class IncompatibleDeviceTypeException : Exception
{

public IncompatibleDeviceTypeException()
: base("Invalid NZXTDeviceType given to USBController.")
{

}

public IncompatibleDeviceTypeException(string message)
: base(message)
{

}

public IncompatibleDeviceTypeException(string message, Exception innerException) : base(message, innerException)
{
}
}
}
2 changes: 1 addition & 1 deletion NZXTSharp/Core/Exceptions/IncompatibleEffectException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;

namespace NZXTSharp.Exceptions {
class IncompatibleEffectException : Exception {
internal class IncompatibleEffectException : Exception {

private static string baseString = "NXZTSharp.Exceptions.IncompatibleEffectException; ";

Expand Down
2 changes: 1 addition & 1 deletion NZXTSharp/Core/Exceptions/IncompatibleParamException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;

namespace NZXTSharp.Exceptions {
class IncompatibleParamException : Exception {
internal class IncompatibleParamException : Exception {
public IncompatibleParamException() {

}
Expand Down
2 changes: 1 addition & 1 deletion NZXTSharp/Core/Exceptions/InvalidEffectSpeedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;

namespace NZXTSharp.Exceptions {
class InvalidEffectSpeedException : Exception {
internal class InvalidEffectSpeedException : Exception {

public InvalidEffectSpeedException()
: base ("NZXTSharp.Exceptions.InvalidEffectSpeedException; Effect Speed Must Be Between 0 and 4 (Inclusive).") {
Expand Down
2 changes: 1 addition & 1 deletion NZXTSharp/Core/Exceptions/InvalidParamException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;

namespace NZXTSharp.Exceptions {
class InvalidParamException : Exception {
internal class InvalidParamException : Exception {

public InvalidParamException() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace NZXTSharp.Exceptions
{
class MaxHandshakeRetryExceededException : Exception
internal class MaxHandshakeRetryExceededException : Exception
{
public MaxHandshakeRetryExceededException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;

namespace NZXTSharp.Exceptions {
public class SubDeviceDoesNotExistException : Exception {
internal class SubDeviceDoesNotExistException : Exception {
public SubDeviceDoesNotExistException() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;

namespace NZXTSharp.Exceptions {
public class SubDeviceLEDDoesNotExistException : Exception {
internal class SubDeviceLEDDoesNotExistException : Exception {
public SubDeviceLEDDoesNotExistException() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;

namespace NZXTSharp.Exceptions {
public class TooManyColorsProvidedException : Exception {
internal class TooManyColorsProvidedException : Exception {

public TooManyColorsProvidedException()
: base("NZXTSharp.Exceptions.TooManyColorsProvidedException; CISS Param Can Handle Max Of 15 Colors.") {
Expand Down
23 changes: 20 additions & 3 deletions NZXTSharp/Core/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace NZXTSharp {

public static class IntExtensions {
internal static class IntExtensions {

public static int DecimalToByte(this int toConvert) {
return Convert.ToInt32(toConvert.ToString("X"));
}
}

public static class StringExtensions {
internal static class StringExtensions {

public static string[] SplitEveryN(this string toSplit, int n) {
List<string> returnArr = new List<string>();
Expand All @@ -31,7 +31,7 @@ public static string MultString(this string str, int n) {
}
}

public static class ByteArrExtensions {
internal static class ByteArrExtensions {

public static byte[] ConcatenateByteArr(this byte[] thisone, byte[] other) {
List<byte> l1 = new List<byte>(thisone);
Expand All @@ -48,5 +48,22 @@ public static string ToString(this byte[] thisone) {
}
return sb.ToString();
}

// TOFIX
public static string ColorArrToString(this byte[] thisone)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < thisone.Length; i++)
{
if (!(i % 12 == 0) || i == 0)
{
sb.Append(thisone[i] + " ");
} else
{
sb.Append("\n");
}
}
return sb.ToString();
}
}
}
Loading

0 comments on commit cc4bda4

Please sign in to comment.