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

Commit

Permalink
1.0.1-beta Release: Refactoring, Added Some Features
Browse files Browse the repository at this point in the history
 - Add ChannelInfo.cs
 - Make some brackets on new line instead of same line
 - Add CoveringMarquee effect
 - HexColor.cs
    - Add empty constructor
    - Add hex color string constructor
    - Add AllOff method
 -  Channel.cs
    - Added constructor with ChannelInfo object
    - Added UpdateChannelInfo method
 - HuePlus.cs
    - Added LogHandler and DataRecieved delegates
    - Added Channels list field and property
    - Added ability to do a manual start
    - Updated baud
    - Improved exception handling
    - Added UnitLedOff and UnitLedOn methods
    - Added UpdateChannelInfo, UpdateChannel1Info, and UpdateChannel2Info
       methods.
    - Added License at top
    - Added ClearBuffers method
  - Marquee.cs
    - fixed protocol emulation
    - Added constructor with Parent param, now required.
 - SpectrumWave.cs
    - Fixed protocol emulation
  • Loading branch information
Ari Madian committed Jan 6, 2019
1 parent 06eef92 commit 20016f9
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 67 deletions.
43 changes: 43 additions & 0 deletions NZXTSharp/ChannelInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace NZXTSharp {
public class ChannelInfo {
private int _NumLeds;
private bool _IsFan;
private bool _IsStrip;
private int _NumSubDevices;
private bool _IsActive;
private Channel _Parent;

public int NumLeds { get; }
public int NumSubDevices { get; }
public bool IsFan { get; }
public bool IsStrip { get; }
public bool IsActive { get; }
private Channel Parent { get; }


public ChannelInfo(Channel Parent, byte[] data) {
ParseData(data);
}

public void Update() {
Parent.Parent.UpdateChannelInfo(Parent);
}

private void ParseData(byte[] data) {
if (data.Length == 5) {
this._IsActive = true;
this._NumSubDevices = data[4];

this._IsStrip = (data[3] == 0x00 ? true : false);
this._IsFan = (data[3] == 0x01 ? true : false);

if (this._IsFan)
this._NumLeds = _NumSubDevices * 8;
else
this._NumLeds = _NumSubDevices * 10;

} else
this._IsActive = false;
}
}
}
57 changes: 51 additions & 6 deletions NZXTSharp/Core/HexColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,75 @@
using System.Linq;

namespace NZXTSharp {
public class HexColor {

public class HexColor
{

private int R;
private int G;
private int B;

public HexColor(int R, int G, int B) {
public HexColor()
{

}

public HexColor(string hexColor)
{
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]);
}

public HexColor(int R, int G, int B)
{
this.R = R;
this.G = G;
this.B = B;
}

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

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

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

return outB.ToArray();
}

public byte[] Expanded()
{
List<int> outBytes = new List<int>();
for (int i = 0; i < 40; i++) {
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) {

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

return outB.ToArray();
}
}
}

26 changes: 21 additions & 5 deletions NZXTSharp/Devices/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
using System.Text;
using NZXTSharp.Devices.Hue;

using NZXTSharp.Devices;

namespace NZXTSharp {
public class Channel {

#region Fields

private int _ChannelByte;
private IEffect _Effect;
private IHueDevice _Parent;

#endregion
private bool _State = true;
private ChannelInfo _ChannelInfo;

#region Properties
public int ChannelByte { get; }
public IEffect Effect { get; set; }

public bool State { get; set; }
public ChannelInfo ChannelInfo { get; set; }
public IHueDevice Parent { get; }
#endregion

public Channel() {
Expand All @@ -32,17 +36,29 @@ public Channel(int _ChannelByte, IHueDevice Parent) {
this._Parent = Parent;
}

public Channel(int _ChannelByte, IHueDevice Parent, ChannelInfo Info) {
this.ChannelByte = _ChannelByte;
this._Parent = Parent;
this._ChannelInfo = Info;
}

public void On() {
this._State = false;
byte[] SettingsBytes = new byte[] { 0x4b, (byte)this, (byte)this.Effect.EffectByte, 0x03, 0x02 };
// TODO : TOFIX
//byte[] final = SettingsBytes.ConcatenateByteArr(this.Effect.Color.Expanded());
//_Parent.ApplyCustom(final);
}

public void Off() {
this._State = false;
_Parent.ApplyEffect(this, new Effects.Fixed(this, new HexColor(0, 0, 0)));
}

public void UpdateChannelInfo() {
Parent.UpdateChannelInfo(this);
}

public static explicit operator byte(Channel channel) {
return (byte)channel.ChannelByte;
}
Expand Down
Loading

0 comments on commit 20016f9

Please sign in to comment.