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

Commit

Permalink
Support for more KrakenX effects, fix DCB param eval
Browse files Browse the repository at this point in the history
- Add Wings, CoveringMarquee, SpectrumWave effect support.
  • Loading branch information
Ari Madian committed Feb 27, 2019
1 parent 0e24d2a commit b9d66f9
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,6 @@ ASALocalRun/
.localhistory/

TestApp/
NZXTSharpTesterApp/
NZXTSharpTesterApp/
Scripts/
.vscode/
1 change: 0 additions & 1 deletion NZXTSharp/COM/USB/USBController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ internal class USBController
private NZXTDeviceType _Type;
private HIDDeviceID _ID;
private int CurrProductID;
private INZXTDevice _Parent;
private readonly HIDDeviceID _VendorID = HIDDeviceID.VendorID;
private HidReport _LastReport;
private bool _IsAttached = false;
Expand Down
11 changes: 10 additions & 1 deletion NZXTSharp/Core/Common/Effects/CoveringMarquee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using NZXTSharp;
using NZXTSharp.HuePlus;
using NZXTSharp.KrakenX;
using NZXTSharp.Exceptions;

namespace NZXTSharp
Expand Down Expand Up @@ -96,7 +97,15 @@ public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel) {

return outList;
case NZXTDeviceType.KrakenX:
// TODO
List<byte[]> KrakenOutList = new List<byte[]>();
DCB param = new DCB(Channel.ChannelByte, Param1.IsForward);
for (int colorIndex = 0; colorIndex < _Colors.Length; colorIndex++)
{
byte[] KrakenSettingsBytes = new byte[] {0x2, 0x4c, (byte)param.GetValue(), 0x04, new CISS(colorIndex, _Speed)};
byte[] KrakenFinal = KrakenSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(_Colors[colorIndex]));
KrakenOutList.Add(KrakenFinal);
}
return KrakenOutList;
default:
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion NZXTSharp/Core/Common/Effects/SpectrumWave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel) {
return new List<byte[]>() { final };
case NZXTDeviceType.KrakenX:
DCB param = new DCB(Channel.ChannelByte, Param1.IsForward);
byte[] KrakenSettingsBytes = new byte[] { 0x42, 0x4c, (byte)param.GetValue(), 0x02, (byte)speed };
byte[] KrakenSettingsBytes = new byte[] { 0x2, 0x4c, (byte)param.GetValue(), 0x02, (byte)speed };
byte[] KrakenFinal = KrakenSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(new Color(0, 0, 255)));
return new List<byte[]>() { KrakenFinal };
default:
Expand Down
40 changes: 22 additions & 18 deletions NZXTSharp/Core/Common/Effects/Wings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Wings : IEffect {
/// <summary>
/// The array of colors used by the effect.
/// </summary>
public Color[] Colors;
public Color Color;
private IChannel _Channel;
private CISS _Param2;
private int speed = 2;
Expand All @@ -41,42 +41,46 @@ public class Wings : IEffect {
/// <summary>
/// Constructs a <see cref="Wings"/> effect with the given <see cref="Color"/> array and speed.
/// </summary>
/// <param name="Colors"></param>
/// <param name="Color"></param>
/// <param name="Speed">Speed values must be 0-4 (inclusive). 0 being slowest, 2 being normal, and 4 being fastest. Defaults to 2.</param>
public Wings(Color[] Colors, int Speed = 2) {
this.Colors = Colors;
public Wings(Color Color, int Speed = 2) {
this.Color = Color;
this.speed = Speed;
ValidateParams();
}

private void ValidateParams() {
if (this.Colors.Length > 15) {
throw new TooManyColorsProvidedException();
}

if (speed > 4 || speed < 0) {
private void ValidateParams()
{
if (speed > 4 || speed < 0)
{
throw new InvalidEffectSpeedException();
}
}

/// <inheritdoc/>
public bool IsCompatibleWith(NZXTDeviceType Type) {
public bool IsCompatibleWith(NZXTDeviceType Type)
{
return CompatibleWith.Contains(Type) ? true : false;
}

/// <inheritdoc/>
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel) {
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel)
{
switch (Type) {
case NZXTDeviceType.HuePlus:
List<byte[]> outList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++) {
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel.ChannelByte, 0x0c, 0x03, new CISS(colorIndex, this.speed) };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Colors[colorIndex]));
outList.Add(final);
}
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel.ChannelByte, 0x0c, 0x03, new CISS(0, this.speed) };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Color));
outList.Add(final);

return outList;
case NZXTDeviceType.KrakenX:
// TODO
List<byte[]> KrakenXOutBytes = new List<byte[]>();
byte[] KrakenXSettingsBytes = new byte[] { 0x02, 0x4c, (byte)Channel.ChannelByte, 0x0c, (byte)speed };
byte[] KrakenXFinal = KrakenXSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Color));
KrakenXOutBytes.Add(KrakenXFinal);

return KrakenXOutBytes;
default:
return null;
}
Expand Down
10 changes: 8 additions & 2 deletions NZXTSharp/Core/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,20 @@ public static byte[] PadColorArr(this byte[] thisone)
}

// TOFIX
public static string ColorArrToString(this byte[] thisone)
public static string ColorArrToString(this byte[] thisone, bool asHex = true)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < thisone.Length; i++)
{
if (!(i % 12 == 0) || i == 0)
{
sb.Append(thisone[i] + " ");
if (asHex)
{
sb.Append(thisone[i].ToString("X2") + " ");
} else
{
sb.Append(thisone[i].ToString("X2") + " ");
}
} else
{
sb.Append("\n");
Expand Down
2 changes: 1 addition & 1 deletion NZXTSharp/HuePlus/HuePlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private void SendLogEvent(string Message)
private void SendDataRecvd(string Message)
{
var baseString = "NZXTSharp HuePlus " + (this.CustomName ?? "") + " - ";
OnDataReceived?.Invoke(baseString + Message);
//OnDataReceived?.Invoke(baseString + Message);
}

/// <summary>
Expand Down
15 changes: 12 additions & 3 deletions NZXTSharp/KrakenX/KrakenX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private void InitializeChannels()
_Both = new KrakenXChannel(0x00, this);
_Logo = new KrakenXChannel(0x01, this);
_Ring = new KrakenXChannel(0x02, this);
Console.WriteLine("Channels Initialized");
}

private void InitializeDeviceInfo()
Expand Down Expand Up @@ -180,6 +179,7 @@ public void StopOverrideThread(OverrideThread Thread, ThreadStopType StopType =
/// <param name="Effect">An <see cref="IEffect"/>.</param>
public void ApplyEffect(IEffect Effect)
{
System.Console.WriteLine("Type - " + Effect.GetType());
ApplyEffect(this.Both, Effect);
}

Expand All @@ -195,6 +195,7 @@ public void ApplyEffect(KrakenXChannel Channel, IEffect Effect, bool ApplyToChan
{

Console.WriteLine("Applying Effect");
System.Console.WriteLine("Type - " + Effect.GetType());
Console.WriteLine(Channel.ChannelByte);
if (!Effect.IsCompatibleWith(Type))
throw new IncompatibleEffectException("KrakenX", Effect.EffectName);
Expand All @@ -218,9 +219,17 @@ public void ApplyEffect(KrakenXChannel Channel, IEffect Effect, bool ApplyToChan
}

List<byte[]> CommandQueue = Effect.BuildBytes(Type, Channel);
//_COMController.SimulWrite(CommandQueue.ToArray());
foreach (byte[] Command in CommandQueue)
if (CommandQueue == null)
throw new NullReferenceException("CommandQueue for ApplyEffect returned null.");

Console.WriteLine("CQ Len - " + CommandQueue.Count);
foreach (byte[] Command in CommandQueue)
{
System.Console.WriteLine(" Command Len - " + Command.Length.ToString("X2"));
System.Console.WriteLine(Command.ColorArrToString());
System.Console.WriteLine("\n");
_COMController.Write(Command);
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion NZXTSharp/KrakenX/Params/DCB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public int GetValue()
{
string Dir = _IsForward ? "0" : "1";
string CB = Channel != null ? Channel.ChannelByte.ToString() : ChannelByte.ToString();
return Convert.ToInt32(Dir + CB);
return int.Parse(Dir + CB, System.Globalization.NumberStyles.HexNumber);
}

/// <summary>
Expand Down
13 changes: 4 additions & 9 deletions NZXTSharp/NZXTSharp.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b9d66f9

Please sign in to comment.