From 696c163598adcc46efce3081316ebd8f095ea862 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 19 Sep 2014 16:31:04 +0100 Subject: [PATCH 01/50] Added link to API reference documentation --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index 939b40e..4b6819e 100644 --- a/README.rst +++ b/README.rst @@ -8,6 +8,11 @@ What is BlinkStick? It's smart USB LED pixel. More info about it here: http://www.blinkstick.com +API Reference +------------ + +http://arvydas.github.io/BlinkStickDotNet + Supported platforms ------------ From ebef09bef443e43b81d467638b0c94b369813ca9 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 16:44:39 +0100 Subject: [PATCH 02/50] Simplified code for feature transmission --- BlinkStick.Hid/BlinkstickHid.cs | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/BlinkStick.Hid/BlinkstickHid.cs b/BlinkStick.Hid/BlinkstickHid.cs index 20007c2..1e9a629 100644 --- a/BlinkStick.Hid/BlinkstickHid.cs +++ b/BlinkStick.Hid/BlinkstickHid.cs @@ -183,15 +183,7 @@ public void SetColor(byte channel, byte index, byte r, byte g, byte b) { if (connectedToDriver) { - byte [] data = new byte[6]; - data[0] = 5; - data[1] = channel; - data[2] = index; - data[3] = r; - data[4] = g; - data[5] = b; - - stream.SetFeature(data); + stream.SetFeature(new byte[6] {5, channel, index, r, g, b} ); } } @@ -222,10 +214,7 @@ public void SetMode(byte mode) { if (connectedToDriver) { - byte [] data = new byte[2]; - data[0] = 4; - data[1] = mode; - stream.SetFeature(data); + stream.SetFeature(new byte[2] {4, mode}); } } @@ -474,13 +463,8 @@ public void SetColor(byte r, byte g, byte b) { if (connectedToDriver) { - byte [] data = new byte[4]; - data[0] = 1; - data[1] = r; - data[2] = g; - data[3] = b; - stream.SetFeature(data); + stream.SetFeature(new byte[4] {1, r, g, b}); } } From 71b1a5f6dbb349436018a2217d040440c9c4bbf9 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 16:45:12 +0100 Subject: [PATCH 03/50] Implemented software color patch --- BlinkStick.Hid/BlinkstickHid.cs | 92 +++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/BlinkStick.Hid/BlinkstickHid.cs b/BlinkStick.Hid/BlinkstickHid.cs index 1e9a629..63e1827 100644 --- a/BlinkStick.Hid/BlinkstickHid.cs +++ b/BlinkStick.Hid/BlinkstickHid.cs @@ -41,6 +41,8 @@ public class BlinkstickHid : IDisposable protected bool connectedToDriver = false; + private bool _RequiresSoftwareColorPatch = false; + /// /// Gets a value indicating whether this is connected. /// @@ -61,6 +63,54 @@ public String Serial { } } + private int _VersionMajor = -1; + + /// + /// Gets the major version number from serial number. + /// + /// The major version number. + public int VersionMajor { + get { + if (_VersionMajor == -1) + { + try + { + _VersionMajor = Convert.ToInt32(this.Serial.Substring(this.Serial.Length - 1, 1)); + } + catch + { + _VersionMajor = 0; + } + } + + return _VersionMajor; + } + } + + private int _VersionMinor = -1; + + /// + /// Gets the minor version number from serial number. + /// + /// The version minor. + public int VersionMinor { + get { + if (_VersionMinor == -1) + { + try + { + _VersionMinor = Convert.ToInt32(this.Serial.Substring(this.Serial.Length - 3, 1)); + } + catch + { + _VersionMinor = 0; + } + } + + return _VersionMinor; + } + } + /// /// Gets the name of the manufacturer. /// @@ -334,13 +384,31 @@ public BlinkstickHid() /// True if a Blinkstick device is connected, False otherwise. public bool OpenDevice () { - if (this.device == null) { + bool result; + + this._VersionMajor = -1; + this._VersionMinor = -1; + + if (this.device == null) { HidDeviceLoader loader = new HidDeviceLoader(); HidDevice adevice = loader.GetDevices(VendorId, ProductId).FirstOrDefault(); - return OpenDevice (adevice); + result = OpenDevice (adevice); } else { - return OpenCurrentDevice(); + result = OpenCurrentDevice(); } + + CheckRequiresSoftwareColorPatch(); + + return result; + } + + /// + /// Checks if BlinkStick requires software color patch due to hardware bug. + /// + /// true, if requires software color patch, false otherwise. + private void CheckRequiresSoftwareColorPatch() + { + _RequiresSoftwareColorPatch = VersionMajor == 1 && VersionMinor >= 1 && VersionMinor <= 3; } /// @@ -463,6 +531,24 @@ public void SetColor(byte r, byte g, byte b) { if (connectedToDriver) { + if (_RequiresSoftwareColorPatch) + { + byte cr, cg, cb; + if (GetColor(out cr, out cg, out cb)) + { + if (r == cg && g == cr && b == cb) + { + if (cr > 0) + { + stream.SetFeature(new byte[4] { 1, (byte)(cr - 1), cg, cb }); + } + else if (cg > 0) + { + stream.SetFeature(new byte[4] { 1, cr, (byte)(cg - 1), cb }); + } + } + } + } stream.SetFeature(new byte[4] {1, r, g, b}); } From f772604f8fc0f4cd11eb49ce421c9d6ecb240bb4 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 17:25:50 +0100 Subject: [PATCH 04/50] Added support for named colors --- BlinkStick.Hid/RgbColor.cs | 250 +++++++++++++++++++++++++++++++------ 1 file changed, 213 insertions(+), 37 deletions(-) diff --git a/BlinkStick.Hid/RgbColor.cs b/BlinkStick.Hid/RgbColor.cs index efd60f6..83299ff 100644 --- a/BlinkStick.Hid/RgbColor.cs +++ b/BlinkStick.Hid/RgbColor.cs @@ -7,7 +7,7 @@ // it and/or modify it under the terms of the GNU General Public License as published // by the Free Software Foundation, either version 3 of the License, or (at your option) // any later version. -// +// // BlinkStick application is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -17,15 +17,170 @@ #endregion using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; namespace BlinkStick.Hid { - public class RgbColor - { + public class RgbColor + { + #region Colors + static Dictionary _NamesToHex = new Dictionary + { + {"aliceblue", "#f0f8ff"}, + {"antiquewhite", "#faebd7"}, + {"aqua", "#00ffff"}, + {"aquamarine", "#7fffd4"}, + {"azure", "#f0ffff"}, + {"beige", "#f5f5dc"}, + {"bisque", "#ffe4c4"}, + {"black", "#000000"}, + {"blanchedalmond", "#ffebcd"}, + {"blue", "#0000ff"}, + {"blueviolet", "#8a2be2"}, + {"brown", "#a52a2a"}, + {"burlywood", "#deb887"}, + {"cadetblue", "#5f9ea0"}, + {"chartreuse", "#7fff00"}, + {"chocolate", "#d2691e"}, + {"coral", "#ff7f50"}, + {"cornflowerblue", "#6495ed"}, + {"cornsilk", "#fff8dc"}, + {"crimson", "#dc143c"}, + {"cyan", "#00ffff"}, + {"darkblue", "#00008b"}, + {"darkcyan", "#008b8b"}, + {"darkgoldenrod", "#b8860b"}, + {"darkgray", "#a9a9a9"}, + {"darkgrey", "#a9a9a9"}, + {"darkgreen", "#006400"}, + {"darkkhaki", "#bdb76b"}, + {"darkmagenta", "#8b008b"}, + {"darkolivegreen", "#556b2f"}, + {"darkorange", "#ff8c00"}, + {"darkorchid", "#9932cc"}, + {"darkred", "#8b0000"}, + {"darksalmon", "#e9967a"}, + {"darkseagreen", "#8fbc8f"}, + {"darkslateblue", "#483d8b"}, + {"darkslategray", "#2f4f4f"}, + {"darkslategrey", "#2f4f4f"}, + {"darkturquoise", "#00ced1"}, + {"darkviolet", "#9400d3"}, + {"deeppink", "#ff1493"}, + {"deepskyblue", "#00bfff"}, + {"dimgray", "#696969"}, + {"dimgrey", "#696969"}, + {"dodgerblue", "#1e90ff"}, + {"firebrick", "#b22222"}, + {"floralwhite", "#fffaf0"}, + {"forestgreen", "#228b22"}, + {"fuchsia", "#ff00ff"}, + {"gainsboro", "#dcdcdc"}, + {"ghostwhite", "#f8f8ff"}, + {"gold", "#ffd700"}, + {"goldenrod", "#daa520"}, + {"gray", "#808080"}, + {"grey", "#808080"}, + {"green", "#008000"}, + {"greenyellow", "#adff2f"}, + {"honeydew", "#f0fff0"}, + {"hotpink", "#ff69b4"}, + {"indianred", "#cd5c5c"}, + {"indigo", "#4b0082"}, + {"ivory", "#fffff0"}, + {"khaki", "#f0e68c"}, + {"lavender", "#e6e6fa"}, + {"lavenderblush", "#fff0f5"}, + {"lawngreen", "#7cfc00"}, + {"lemonchiffon", "#fffacd"}, + {"lightblue", "#add8e6"}, + {"lightcoral", "#f08080"}, + {"lightcyan", "#e0ffff"}, + {"lightgoldenrodyellow", "#fafad2"}, + {"lightgray", "#d3d3d3"}, + {"lightgrey", "#d3d3d3"}, + {"lightgreen", "#90ee90"}, + {"lightpink", "#ffb6c1"}, + {"lightsalmon", "#ffa07a"}, + {"lightseagreen", "#20b2aa"}, + {"lightskyblue", "#87cefa"}, + {"lightslategray", "#778899"}, + {"lightslategrey", "#778899"}, + {"lightsteelblue", "#b0c4de"}, + {"lightyellow", "#ffffe0"}, + {"lime", "#00ff00"}, + {"limegreen", "#32cd32"}, + {"linen", "#faf0e6"}, + {"magenta", "#ff00ff"}, + {"maroon", "#800000"}, + {"mediumaquamarine", "#66cdaa"}, + {"mediumblue", "#0000cd"}, + {"mediumorchid", "#ba55d3"}, + {"mediumpurple", "#9370d8"}, + {"mediumseagreen", "#3cb371"}, + {"mediumslateblue", "#7b68ee"}, + {"mediumspringgreen", "#00fa9a"}, + {"mediumturquoise", "#48d1cc"}, + {"mediumvioletred", "#c71585"}, + {"midnightblue", "#191970"}, + {"mintcream", "#f5fffa"}, + {"mistyrose", "#ffe4e1"}, + {"moccasin", "#ffe4b5"}, + {"navajowhite", "#ffdead"}, + {"navy", "#000080"}, + {"oldlace", "#fdf5e6"}, + {"olive", "#808000"}, + {"olivedrab", "#6b8e23"}, + {"orange", "#ffa500"}, + {"orangered", "#ff4500"}, + {"orchid", "#da70d6"}, + {"palegoldenrod", "#eee8aa"}, + {"palegreen", "#98fb98"}, + {"paleturquoise", "#afeeee"}, + {"palevioletred", "#d87093"}, + {"papayawhip", "#ffefd5"}, + {"peachpuff", "#ffdab9"}, + {"peru", "#cd853f"}, + {"pink", "#ffc0cb"}, + {"plum", "#dda0dd"}, + {"powderblue", "#b0e0e6"}, + {"purple", "#800080"}, + {"red", "#ff0000"}, + {"rosybrown", "#bc8f8f"}, + {"royalblue", "#4169e1"}, + {"saddlebrown", "#8b4513"}, + {"salmon", "#fa8072"}, + {"sandybrown", "#f4a460"}, + {"seagreen", "#2e8b57"}, + {"seashell", "#fff5ee"}, + {"sienna", "#a0522d"}, + {"silver", "#c0c0c0"}, + {"skyblue", "#87ceeb"}, + {"slateblue", "#6a5acd"}, + {"slategray", "#708090"}, + {"slategrey", "#708090"}, + {"snow", "#fffafa"}, + {"springgreen", "#00ff7f"}, + {"steelblue", "#4682b4"}, + {"tan", "#d2b48c"}, + {"teal", "#008080"}, + {"thistle", "#d8bfd8"}, + {"tomato", "#ff6347"}, + {"turquoise", "#40e0d0"}, + {"violet", "#ee82ee"}, + {"wheat", "#f5deb3"}, + {"white", "#ffffff"}, + {"whitesmoke", "#f5f5f5"}, + {"yellow", "#ffff00"}, + {"yellowgreen", "#9acd32"} + }; + #endregion + /// /// The Red byte component. /// - public Byte R; + public Byte R; /// /// The Green byte component. @@ -37,9 +192,9 @@ public class RgbColor /// public Byte B; - public RgbColor () - { - } + public RgbColor () + { + } /// /// Froms the rgb value from int components. @@ -48,16 +203,16 @@ public RgbColor () /// The red component. /// The green component. /// The blue component. - public static RgbColor FromRgb(int r, int g, int b) - { - RgbColor color = new RgbColor(); - color.R = (byte)r; - color.G = (byte)g; - color.B = (byte)b; - - return color; - } - + public static RgbColor FromRgb(int r, int g, int b) + { + RgbColor color = new RgbColor(); + color.R = (byte)r; + color.G = (byte)g; + color.B = (byte)b; + + return color; + } + /// /// Froms the color of the GDK color. /// @@ -65,31 +220,42 @@ public static RgbColor FromRgb(int r, int g, int b) /// The red component. /// The green component. /// The blue component. - public static RgbColor FromGdkColor(ushort r, ushort g, ushort b) - { - RgbColor color = new RgbColor(); - - color.R = (byte)(r / 0x100); - color.G = (byte)(g / 0x100); - color.B = (byte)(b / 0x100); - - return color; - } + public static RgbColor FromGdkColor(ushort r, ushort g, ushort b) + { + RgbColor color = new RgbColor(); + + color.R = (byte)(r / 0x100); + color.G = (byte)(g / 0x100); + color.B = (byte)(b / 0x100); + + return color; + } /// - /// Converts HEX string to RGB color. For example #123456 + /// Converts HEX string or name of the RGB color. For example #123456, blue, red, orange /// /// The string. /// Color string. - public static RgbColor FromString (String colorStr) - { - RgbColor color = new RgbColor(); - color.R = Convert.ToByte(colorStr.Substring(1, 2), 16); - color.G = Convert.ToByte(colorStr.Substring(3, 2), 16); - color.B = Convert.ToByte(colorStr.Substring(5, 2), 16); + public static RgbColor FromString (String color) + { + RgbColor result = new RgbColor(); + + if (_NamesToHex.ContainsKey(color.ToLower())) + { + color = _NamesToHex[color.ToLower()]; + } + else + { + if (!IsValidColor(color)) + throw new Exception("Color value is invalid"); + } - return color; - } + result.R = Convert.ToByte(color.Substring(1, 2), 16); + result.G = Convert.ToByte(color.Substring(3, 2), 16); + result.B = Convert.ToByte(color.Substring(5, 2), 16); + + return result; + } /// /// Get black color. @@ -99,6 +265,16 @@ public static RgbColor Black () return RgbColor.FromRgb(0, 0, 0); } + /// + /// Determines if is valid color format of the specified string (#rrggbb). + /// + /// true if is valid color the specified color; otherwise, false. + /// Color. + public static Boolean IsValidColor (String color) + { + return Regex.IsMatch(color, "^#[A-Fa-f0-9]{6}$"); + } + /// /// Returns a string that represents the current object. /// @@ -108,6 +284,6 @@ public override string ToString() { return string.Format("{0:x2}{1:x2}{2:x2}", this.R, this.G, this.B); } - } + } } From 640439377d69153038ab599549e50f61f2a57143 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 17:27:21 +0100 Subject: [PATCH 05/50] Removed no longer needed methods, use RgbColor class to manipulate string colors --- BlinkStick.Hid/BlinkstickHid.cs | 47 +++++++++++++++------------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/BlinkStick.Hid/BlinkstickHid.cs b/BlinkStick.Hid/BlinkstickHid.cs index 63e1827..6c7e57b 100644 --- a/BlinkStick.Hid/BlinkstickHid.cs +++ b/BlinkStick.Hid/BlinkstickHid.cs @@ -21,7 +21,6 @@ using System.Linq; using System.Text; using System.Runtime.InteropServices; -using System.Text.RegularExpressions; using HidSharp; namespace BlinkStick.Hid @@ -212,13 +211,16 @@ private Boolean GetInfoBlock (byte id, out string data) /// Must be in #rrggbb format public void SetColor(String color) { - if (!IsValidColor(color)) - throw new Exception("Color value is invalid"); + SetColor(RgbColor.FromString(color)); + } - SetColor( - Convert.ToByte(color.Substring(1, 2), 16), - Convert.ToByte(color.Substring(3, 2), 16), - Convert.ToByte(color.Substring(5, 2), 16)); + /// + /// Sets the color of the led. + /// + /// Color as RgbColor class. + public void SetColor(RgbColor color) + { + SetColor(color.R, color.G, color.B); } /// @@ -242,18 +244,21 @@ public void SetColor(byte channel, byte index, byte r, byte g, byte b) /// /// Channel (0 - R, 1 - G, 2 - B) /// Index of the LED - /// Must be in #rrggbb format + /// Must be in #rrggbb format or named color ("red", "green", "blue") public void SetColor(byte channel, byte index, string color) { - if (!IsValidColor(color)) - throw new Exception("Color value is invalid"); + SetColor(channel, index, RgbColor.FromString(color)); + } - SetColor( - channel, - index, - Convert.ToByte(color.Substring(1, 2), 16), - Convert.ToByte(color.Substring(3, 2), 16), - Convert.ToByte(color.Substring(5, 2), 16)); + /// + /// Sets the color of the led. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// Color parameter as RgbColor class instance + public void SetColor(byte channel, byte index, RgbColor color) + { + SetColor(channel, index, color.R, color.B, color.G); } /// @@ -349,16 +354,6 @@ public void SetColors(byte channel, byte[] reportData) } } - /// - /// Determines if is valid color format of the specified string (#rrggbb). - /// - /// true if is valid color the specified color; otherwise, false. - /// Color. - public static Boolean IsValidColor (String color) - { - return Regex.IsMatch(color, "^#[A-Fa-f0-9]{6}$"); - } - /// /// Occurs when BlinkStick device is attached. /// From e0be9c25170d2e6ab8fcfa8c6a13891454d7ba2d Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 18:17:17 +0100 Subject: [PATCH 06/50] Restructured and documented code --- BlinkStick.Hid/BlinkstickHid.cs | 610 ++++++++++++++++---------------- 1 file changed, 304 insertions(+), 306 deletions(-) diff --git a/BlinkStick.Hid/BlinkstickHid.cs b/BlinkStick.Hid/BlinkstickHid.cs index 6c7e57b..3af01a1 100644 --- a/BlinkStick.Hid/BlinkstickHid.cs +++ b/BlinkStick.Hid/BlinkstickHid.cs @@ -30,6 +30,7 @@ namespace BlinkStick.Hid /// public class BlinkstickHid : IDisposable { + #region Private Properties protected const int VendorId = 0x20A0; protected const int ProductId = 0x41E5; @@ -41,7 +42,9 @@ public class BlinkstickHid : IDisposable protected bool connectedToDriver = false; private bool _RequiresSoftwareColorPatch = false; + #endregion + #region Device Properties /// /// Gets a value indicating whether this is connected. /// @@ -53,7 +56,14 @@ public Boolean Connected { } /// - /// Gets the serial number of BlinkStick. + /// Returns the serial number of BlinkStick. + /// BSnnnnnn-1.0 + /// || | | |- Software minor version + /// || | |--- Software major version + /// || |-------- Denotes sequential number + /// ||----------- Denotes BlinkStick device + /// + /// Software version defines the capabilities of the device /// /// The serial. public String Serial { @@ -173,7 +183,119 @@ public String InfoBlock2 { } } } + #endregion + + #region Constructor/Destructor + /// + /// Initializes a new instance of the BlinkstickHid class. + /// + public BlinkstickHid() + { + } + + /// + /// Closes the connection to the device. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Closes any connected devices. + /// + /// + private void Dispose(bool disposing) + { + if(!this.disposed) + { + if(disposing) + { + CloseDevice(); + } + + disposed = true; + } + } + + /// + /// Destroys instance and frees device resources (if not freed already) + /// + ~BlinkstickHid() + { + Dispose(false); + } + #endregion + + #region Device Open/Close functions + /// + /// Attempts to connect to a BlinkStick device. + /// + /// After a successful connection, a DeviceAttached event will normally be sent. + /// + /// True if a Blinkstick device is connected, False otherwise. + public bool OpenDevice () + { + bool result; + + this._VersionMajor = -1; + this._VersionMinor = -1; + + if (this.device == null) { + HidDeviceLoader loader = new HidDeviceLoader(); + HidDevice adevice = loader.GetDevices(VendorId, ProductId).FirstOrDefault(); + result = OpenDevice (adevice); + } else { + result = OpenCurrentDevice(); + } + + CheckRequiresSoftwareColorPatch(); + + return result; + } + + /// + /// Opens the device. + /// + /// true, if device was opened, false otherwise. + /// Pass the parameter of HidDevice to open it directly + public bool OpenDevice(HidDevice adevice) + { + if (adevice != null) + { + this.device = adevice; + + return OpenCurrentDevice(); + } + + return false; + } + + /// + /// Opens the current device. + /// + /// true, if current device was opened, false otherwise. + private bool OpenCurrentDevice() + { + connectedToDriver = true; + device.TryOpen(out stream); + + return true; + } + + /// + /// Closes the connection to the device. + /// + public void CloseDevice() + { + stream.Close(); + device = null; + connectedToDriver = false; + } + #endregion + #region Helper functions for InfoBlocks /// /// Sets the info block. /// @@ -205,6 +327,71 @@ private Boolean GetInfoBlock (byte id, out string data) return result; } + protected void SetInfoBlock (byte id, byte[] data) + { + if (id == 2 || id == 3) { + if (data.Length > 32) + { + Array.Resize(ref data, 32); + } + else if (data.Length < 32) + { + int size = data.Length; + + Array.Resize(ref data, 32); + + //pad with zeros + for (int i = size; i < 32; i++) + { + data[i] = 0; + } + } + + Array.Resize(ref data, 33); + + + for (int i = 32; i >0; i--) + { + data[i] = data[i-1]; + } + + data[0] = id; + + stream.SetFeature(data); + } else { + throw new Exception("Invalid info block id"); + } + } + + /// + /// Gets the info block. + /// + /// true, if info block was received, false otherwise. + /// Identifier. + /// Data. + public Boolean GetInfoBlock (byte id, out byte[] data) + { + if (id == 2 || id == 3) { + data = new byte[33]; + data[0] = id; + + if (connectedToDriver) + { + stream.GetFeature(data, 0, data.Length); + return true; + } + else + { + data = new byte[0]; + return false; + } + } else { + throw new Exception("Invalid info block id"); + } + } + #endregion + + #region Color manipulation functions /// /// Sets the color of the led. /// @@ -223,6 +410,78 @@ public void SetColor(RgbColor color) SetColor(color.R, color.G, color.B); } + /// + /// Sets the color of the led. + /// + /// The red component. + /// The green component. + /// The blue component. + public void SetColor(byte r, byte g, byte b) + { + if (connectedToDriver) + { + if (_RequiresSoftwareColorPatch) + { + byte cr, cg, cb; + if (GetColor(out cr, out cg, out cb)) + { + if (r == cg && g == cr && b == cb) + { + if (cr > 0) + { + stream.SetFeature(new byte[4] { 1, (byte)(cr - 1), cg, cb }); + } + else if (cg > 0) + { + stream.SetFeature(new byte[4] { 1, cr, (byte)(cg - 1), cb }); + } + } + } + } + + stream.SetFeature(new byte[4] {1, r, g, b}); + } + } + + /// + /// Gets the color of the led. + /// + /// true, if led color was received, false otherwise. + /// The red component. + /// The green component. + /// The blue component. + public Boolean GetColor (out byte r, out byte g, out byte b) + { + byte[] report = new byte[33]; + report[0] = 1; + + if (connectedToDriver) { + stream.GetFeature(report, 0, 33); + + r = report [1]; + g = report [2]; + b = report [3]; + + return true; + } else { + r = 0; + g = 0; + b = 0; + + return false; + } + } + + /// + /// Turn BlinkStick off. + /// + public void TurnOff() + { + SetColor(0, 0, 0); + } + #endregion + + #region Color manipulation functions for BlinkStick Pro /// /// Sets the color of the led. /// @@ -261,58 +520,38 @@ public void SetColor(byte channel, byte index, RgbColor color) SetColor(channel, index, color.R, color.B, color.G); } - /// - /// Sets the mode for BlinkStick Pro. - /// - /// 0 - Normal, 1 - Inverse, 2 - WS2812 - public void SetMode(byte mode) - { - if (connectedToDriver) - { - stream.SetFeature(new byte[2] {4, mode}); - } - } - - /// - /// Turn BlinkStick off. - /// - public void TurnOff() - { - SetColor(0, 0, 0); - } - /// /// Send a packet of data to LEDs /// /// Channel (0 - R, 1 - G, 2 - B) /// Report data must be a byte array in the following format: [g0, r0, b0, g1, r1, b1, g2, r2, b2 ...] - public void SetColors(byte channel, byte[] reportData) + public void SetColors(byte channel, byte[] colorData) { int max_leds = 64; byte reportId = 9; //Automatically determine the correct report id to send the data to - if (reportData.Length <= 8 * 3) + if (colorData.Length <= 8 * 3) { max_leds = 8; reportId = 6; } - else if (reportData.Length <= 16 * 3) + else if (colorData.Length <= 16 * 3) { max_leds = 16; reportId = 7; } - else if (reportData.Length <= 32 * 3) + else if (colorData.Length <= 32 * 3) { max_leds = 32; reportId = 8; } - else if (reportData.Length <= 64 * 3) + else if (colorData.Length <= 64 * 3) { max_leds = 64; reportId = 9; } - else if (reportData.Length <= 128 * 3) + else if (colorData.Length <= 128 * 3) { max_leds = 64; reportId = 10; @@ -322,12 +561,12 @@ public void SetColors(byte channel, byte[] reportData) data[0] = reportId; data[1] = channel; // chanel index - for (int i = 0; i < Math.Min(reportData.Length, data.Length - 2); i++) + for (int i = 0; i < Math.Min(colorData.Length, data.Length - 2); i++) { - data[i + 2] = reportData[i]; + data[i + 2] = colorData[i]; } - for (int i = reportData.Length + 2; i < data.Length; i++) + for (int i = colorData.Length + 2; i < data.Length; i++) { data[i] = 0; } @@ -336,14 +575,12 @@ public void SetColors(byte channel, byte[] reportData) if (reportId == 10) { - //System.Threading.Thread.Sleep(1); - - for (int i = 0; i < Math.Min(data.Length - 2, reportData.Length - 64 * 3); i++) + for (int i = 0; i < Math.Min(data.Length - 2, colorData.Length - 64 * 3); i++) { - data[i + 2] = reportData[64 * 3 + i]; + data[i + 2] = colorData[64 * 3 + i]; } - for (int i = reportData.Length + 2 - 64 * 3; i < data.Length; i++) + for (int i = colorData.Length + 2 - 64 * 3; i < data.Length; i++) { data[i] = 0; } @@ -355,89 +592,44 @@ public void SetColors(byte channel, byte[] reportData) } /// - /// Occurs when BlinkStick device is attached. - /// - public event EventHandler DeviceAttached; - - /// - /// Occurs when a BlinkStick device is removed. - /// - public event EventHandler DeviceRemoved; - - /// - /// Initializes a new instance of the BlinkstickHid class. + /// Gets led data. /// - public BlinkstickHid() + /// true, if led data was received, false otherwise. + /// LED data as an array of colors [G0, R0, B0, G1, R1, B1 ...] + public Boolean GetColors (out byte[] colorData) { - } - - /// - /// Attempts to connect to a BlinkStick device. - /// - /// After a successful connection, a DeviceAttached event will normally be sent. - /// - /// True if a Blinkstick device is connected, False otherwise. - public bool OpenDevice () - { - bool result; - - this._VersionMajor = -1; - this._VersionMinor = -1; - - if (this.device == null) { - HidDeviceLoader loader = new HidDeviceLoader(); - HidDevice adevice = loader.GetDevices(VendorId, ProductId).FirstOrDefault(); - result = OpenDevice (adevice); - } else { - result = OpenCurrentDevice(); - } - - CheckRequiresSoftwareColorPatch(); + if (connectedToDriver) + { + colorData = new byte[3 * 8 * 8 + 1]; + colorData[0] = 9; + stream.GetFeature(colorData, 0, colorData.Length); + return true; + } + else + { + colorData = new byte[0]; + return false; + } - return result; } - /// - /// Checks if BlinkStick requires software color patch due to hardware bug. - /// - /// true, if requires software color patch, false otherwise. - private void CheckRequiresSoftwareColorPatch() - { - _RequiresSoftwareColorPatch = VersionMajor == 1 && VersionMinor >= 1 && VersionMinor <= 3; - } + #endregion + #region BlinkStick Pro mode selection /// - /// Opens the device. + /// Sets the mode for BlinkStick Pro. /// - /// true, if device was opened, false otherwise. - /// Pass the parameter of HidDevice to open it directly - public bool OpenDevice(HidDevice adevice) + /// 0 - Normal, 1 - Inverse, 2 - WS2812 + public void SetMode(byte mode) { - if (adevice != null) + if (connectedToDriver) { - this.device = adevice; - - return OpenCurrentDevice(); + stream.SetFeature(new byte[2] {4, mode}); } - - return false; } + #endregion - /// - /// Opens the current device. - /// - /// true, if current device was opened, false otherwise. - private bool OpenCurrentDevice() - { - connectedToDriver = true; - device.TryOpen(out stream); - - //!!!device.Inserted += DeviceAttachedHandler; - //!!!device.Removed += DeviceRemovedHandler; - - return true; - } - + #region Static Functions to initialize BlinkSticks /// /// Find all BlinkStick devices. /// @@ -483,212 +675,18 @@ public static BlinkstickHid FindBySerial(String serial) return null; } + #endregion - - /// - /// Closes the connection to the device. - /// - public void CloseDevice() - { - stream.Close(); - device = null; - connectedToDriver = false; - } - - /// - /// Closes the connection to the device. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void DeviceAttachedHandler() - { - if (DeviceAttached != null) - DeviceAttached(this, EventArgs.Empty); - } - - private void DeviceRemovedHandler() - { - if (DeviceRemoved != null) - DeviceRemoved(this, EventArgs.Empty); - } - + #region Misc helper functions /// - /// Sets the color of the led. - /// - /// The red component. - /// The green component. - /// The blue component. - public void SetColor(byte r, byte g, byte b) - { - if (connectedToDriver) - { - if (_RequiresSoftwareColorPatch) - { - byte cr, cg, cb; - if (GetColor(out cr, out cg, out cb)) - { - if (r == cg && g == cr && b == cb) - { - if (cr > 0) - { - stream.SetFeature(new byte[4] { 1, (byte)(cr - 1), cg, cb }); - } - else if (cg > 0) - { - stream.SetFeature(new byte[4] { 1, cr, (byte)(cg - 1), cb }); - } - } - } - } - - stream.SetFeature(new byte[4] {1, r, g, b}); - } - } - - /// - /// Gets the color of the led. - /// - /// true, if led color was gotten, false otherwise. - /// The red component. - /// The green component. - /// The blue component. - public Boolean GetColor (out byte r, out byte g, out byte b) - { - byte[] report = new byte[33]; - report[0] = 1; - - if (connectedToDriver) { - stream.GetFeature(report, 0, 33); - - r = report [1]; - g = report [2]; - b = report [3]; - - return true; - } else { - r = 0; - g = 0; - b = 0; - - return false; - } - } - - /// - /// Gets the led data. - /// - /// true, if led data was gotten, false otherwise. - /// Data. - public Boolean GetData (out byte[] data) - { - if (connectedToDriver) - { - data = new byte[3 * 8 * 8 + 1]; - data[0] = 9; - stream.GetFeature(data, 0, data.Length); - return true; - } - else - { - data = new byte[0]; - return false; - } - - } - - protected void SetInfoBlock (byte id, byte[] data) - { - if (id == 2 || id == 3) { - if (data.Length > 32) - { - Array.Resize(ref data, 32); - } - else if (data.Length < 32) - { - int size = data.Length; - - Array.Resize(ref data, 32); - - //pad with zeros - for (int i = size; i < 32; i++) - { - data[i] = 0; - } - } - - Array.Resize(ref data, 33); - - - for (int i = 32; i >0; i--) - { - data[i] = data[i-1]; - } - - data[0] = id; - - stream.SetFeature(data); - } else { - throw new Exception("Invalid info block id"); - } - } - - /// - /// Gets the info block. - /// - /// true, if info block was gotten, false otherwise. - /// Identifier. - /// Data. - public Boolean GetInfoBlock (byte id, out byte[] data) - { - if (id == 2 || id == 3) { - data = new byte[33]; - data[0] = id; - - if (connectedToDriver) - { - stream.GetFeature(data, 0, data.Length); - return true; - } - else - { - data = new byte[0]; - return false; - } - } else { - throw new Exception("Invalid info block id"); - } - } - - - /// - /// Closes any connected devices. - /// - /// - private void Dispose(bool disposing) - { - if(!this.disposed) - { - if(disposing) - { - CloseDevice(); - } - - disposed = true; - } - } - - /// - /// Destroys instance and frees device resources (if not freed already) + /// Checks if BlinkStick requires software color patch due to hardware bug. /// - ~BlinkstickHid() + /// true, if requires software color patch, false otherwise. + private void CheckRequiresSoftwareColorPatch() { - Dispose(false); + _RequiresSoftwareColorPatch = VersionMajor == 1 && VersionMinor >= 1 && VersionMinor <= 3; } - + #endregion } } From 40023d79639cabe419ed3c1a34a68a0bd98f9cc1 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 18:52:54 +0100 Subject: [PATCH 07/50] Renamed assembly to BlinkStickDotNet and main class to BlinkStick --- BlinkStick.Hid/BlinkStick.Hid.sln | 20 ----------------- BlinkStickDotNet.sln | 2 +- .../AssemblyInfo.cs | 0 .../BlinkStick.cs | 22 +++++++++---------- .../BlinkStickDotNet.csproj | 6 ++--- .../HSLColor.cs | 2 +- .../RgbColor.cs | 2 +- .../UsbMonitor.cs | 2 +- .../WinUsbDeviceMonitor.cs | 2 +- 9 files changed, 19 insertions(+), 39 deletions(-) delete mode 100644 BlinkStick.Hid/BlinkStick.Hid.sln rename {BlinkStick.Hid => BlinkStickDotNet}/AssemblyInfo.cs (100%) rename BlinkStick.Hid/BlinkstickHid.cs => BlinkStickDotNet/BlinkStick.cs (97%) rename BlinkStick.Hid/BlinkStick.Hid.csproj => BlinkStickDotNet/BlinkStickDotNet.csproj (95%) rename {BlinkStick.Hid => BlinkStickDotNet}/HSLColor.cs (99%) rename {BlinkStick.Hid => BlinkStickDotNet}/RgbColor.cs (99%) rename {BlinkStick.Hid => BlinkStickDotNet}/UsbMonitor.cs (99%) rename {BlinkStick.Hid => BlinkStickDotNet}/WinUsbDeviceMonitor.cs (98%) diff --git a/BlinkStick.Hid/BlinkStick.Hid.sln b/BlinkStick.Hid/BlinkStick.Hid.sln deleted file mode 100644 index 9991f59..0000000 --- a/BlinkStick.Hid/BlinkStick.Hid.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlinkStick.Hid", "BlinkStick.Hid.csproj", "{7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = BlinkStick.Hid.csproj - EndGlobalSection -EndGlobal diff --git a/BlinkStickDotNet.sln b/BlinkStickDotNet.sln index 4b7b833..ff3f7c2 100644 --- a/BlinkStickDotNet.sln +++ b/BlinkStickDotNet.sln @@ -5,7 +5,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibUsbDotNet", "Components\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HidSharp", "Components\HidSharp\HidSharp.csproj", "{0DB86674-2A7B-4BDC-93C1-3F7DC771426C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlinkStick.Hid", "BlinkStick.Hid\BlinkStick.Hid.csproj", "{7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlinkStickDotNet", "BlinkStickDotNet\BlinkStickDotNet.csproj", "{7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/BlinkStick.Hid/AssemblyInfo.cs b/BlinkStickDotNet/AssemblyInfo.cs similarity index 100% rename from BlinkStick.Hid/AssemblyInfo.cs rename to BlinkStickDotNet/AssemblyInfo.cs diff --git a/BlinkStick.Hid/BlinkstickHid.cs b/BlinkStickDotNet/BlinkStick.cs similarity index 97% rename from BlinkStick.Hid/BlinkstickHid.cs rename to BlinkStickDotNet/BlinkStick.cs index 3af01a1..79b6700 100644 --- a/BlinkStick.Hid/BlinkstickHid.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -23,12 +23,12 @@ using System.Runtime.InteropServices; using HidSharp; -namespace BlinkStick.Hid +namespace BlinkStickDotNet { /// /// Main class to access Blinkstick HID devices. /// - public class BlinkstickHid : IDisposable + public class BlinkStick : IDisposable { #region Private Properties protected const int VendorId = 0x20A0; @@ -189,7 +189,7 @@ public String InfoBlock2 { /// /// Initializes a new instance of the BlinkstickHid class. /// - public BlinkstickHid() + public BlinkStick() { } @@ -222,7 +222,7 @@ private void Dispose(bool disposing) /// /// Destroys instance and frees device resources (if not freed already) /// - ~BlinkstickHid() + ~BlinkStick() { Dispose(false); } @@ -634,14 +634,14 @@ public void SetMode(byte mode) /// Find all BlinkStick devices. /// /// The devices. - public static BlinkstickHid[] AllDevices () + public static BlinkStick[] AllDevices () { - List result = new List(); + List result = new List(); HidDeviceLoader loader = new HidDeviceLoader(); foreach (HidDevice adevice in loader.GetDevices(VendorId, ProductId).ToArray()) { - BlinkstickHid hid = new BlinkstickHid(); + BlinkStick hid = new BlinkStick(); hid.device = adevice; result.Add(hid); } @@ -653,9 +653,9 @@ public static BlinkstickHid[] AllDevices () /// Find first BlinkStick. /// /// BlinkStickHid device if found, otherwise null if no devices found - public static BlinkstickHid FirstDevice() + public static BlinkStick FirstDevice() { - BlinkstickHid[] devices = AllDevices(); + BlinkStick[] devices = AllDevices(); return devices.Length > 0 ? devices[0] : null; } @@ -665,9 +665,9 @@ public static BlinkstickHid FirstDevice() /// /// BlinkStickHid device if found, otherwise null if no devices found /// Serial number to search for - public static BlinkstickHid FindBySerial(String serial) + public static BlinkStick FindBySerial(String serial) { - foreach (BlinkstickHid device in AllDevices()) + foreach (BlinkStick device in AllDevices()) { if (device.Serial == serial) return device; diff --git a/BlinkStick.Hid/BlinkStick.Hid.csproj b/BlinkStickDotNet/BlinkStickDotNet.csproj similarity index 95% rename from BlinkStick.Hid/BlinkStick.Hid.csproj rename to BlinkStickDotNet/BlinkStickDotNet.csproj index 06b745f..2c29fc7 100644 --- a/BlinkStick.Hid/BlinkStick.Hid.csproj +++ b/BlinkStickDotNet/BlinkStickDotNet.csproj @@ -5,8 +5,8 @@ AnyCPU {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} Library - BlinkStick.Hid - BlinkStick.Hid + BlinkStickDotNet + BlinkStickDotNet true @@ -38,7 +38,7 @@ - + diff --git a/BlinkStick.Hid/HSLColor.cs b/BlinkStickDotNet/HSLColor.cs similarity index 99% rename from BlinkStick.Hid/HSLColor.cs rename to BlinkStickDotNet/HSLColor.cs index 4278aed..1ed78d0 100644 --- a/BlinkStick.Hid/HSLColor.cs +++ b/BlinkStickDotNet/HSLColor.cs @@ -20,7 +20,7 @@ using System.Collections.Generic; using System.Text; -namespace BlinkStick.Hid +namespace BlinkStickDotNet { public struct HSLColor { diff --git a/BlinkStick.Hid/RgbColor.cs b/BlinkStickDotNet/RgbColor.cs similarity index 99% rename from BlinkStick.Hid/RgbColor.cs rename to BlinkStickDotNet/RgbColor.cs index 83299ff..e73a422 100644 --- a/BlinkStick.Hid/RgbColor.cs +++ b/BlinkStickDotNet/RgbColor.cs @@ -20,7 +20,7 @@ using System.Collections.Generic; using System.Text.RegularExpressions; -namespace BlinkStick.Hid +namespace BlinkStickDotNet { public class RgbColor { diff --git a/BlinkStick.Hid/UsbMonitor.cs b/BlinkStickDotNet/UsbMonitor.cs similarity index 99% rename from BlinkStick.Hid/UsbMonitor.cs rename to BlinkStickDotNet/UsbMonitor.cs index 25c9df9..b180308 100644 --- a/BlinkStick.Hid/UsbMonitor.cs +++ b/BlinkStickDotNet/UsbMonitor.cs @@ -19,7 +19,7 @@ using System; using LibUsbDotNet.DeviceNotify; -namespace BlinkStick.Hid +namespace BlinkStickDotNet { public class UsbMonitor { diff --git a/BlinkStick.Hid/WinUsbDeviceMonitor.cs b/BlinkStickDotNet/WinUsbDeviceMonitor.cs similarity index 98% rename from BlinkStick.Hid/WinUsbDeviceMonitor.cs rename to BlinkStickDotNet/WinUsbDeviceMonitor.cs index bef4763..f969552 100644 --- a/BlinkStick.Hid/WinUsbDeviceMonitor.cs +++ b/BlinkStickDotNet/WinUsbDeviceMonitor.cs @@ -21,7 +21,7 @@ using System.Security.Permissions; using System.Windows.Forms; -namespace BlinkStick.Hid +namespace BlinkStickDotNet { public class WinUsbDeviceMonitor { From 5d53fb8f511690727bbb2527b6dcd19a5483a2fa Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 21:03:57 +0100 Subject: [PATCH 08/50] Added blink, morph and pulse functions for BlinkStick --- BlinkStickDotNet/BlinkStick.cs | 319 ++++++++++++++++++++++++++++++++- 1 file changed, 314 insertions(+), 5 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 79b6700..32b257d 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -21,6 +21,7 @@ using System.Linq; using System.Text; using System.Runtime.InteropServices; +using System.Threading; using HidSharp; namespace BlinkStickDotNet @@ -494,7 +495,7 @@ public void SetColor(byte channel, byte index, byte r, byte g, byte b) { if (connectedToDriver) { - stream.SetFeature(new byte[6] {5, channel, index, r, g, b} ); + stream.SetFeature(new byte[6] { 5, channel, index, r, g, b }); } } @@ -595,14 +596,18 @@ public void SetColors(byte channel, byte[] colorData) /// Gets led data. /// /// true, if led data was received, false otherwise. - /// LED data as an array of colors [G0, R0, B0, G1, R1, B1 ...] + /// LED data as an array of colors [g0, r0, b0, g1, r1, b1 ...] public Boolean GetColors (out byte[] colorData) { if (connectedToDriver) { - colorData = new byte[3 * 8 * 8 + 1]; - colorData[0] = 9; - stream.GetFeature(colorData, 0, colorData.Length); + byte[] data = new byte[3 * 8 * 8 + 2]; + data[0] = 9; + stream.GetFeature(data, 0, data.Length); + + colorData = new byte[3 * 8 * 8]; + Array.Copy(data, 2, colorData, 0, colorData.Length); + return true; } else @@ -613,6 +618,41 @@ public Boolean GetColors (out byte[] colorData) } + + /// + /// Gets the color of the led. + /// + /// true, if led color was received, false otherwise. + /// The red component. + /// The green component. + /// The blue component. + public Boolean GetColor (byte index, out byte r, out byte g, out byte b) + { + if (index == 0) + { + return this.GetColor(out r, out g, out b); + } + + byte[] colors; + this.GetColors(out colors); + + if (colors.Length >= (index + 1) * 3) + { + r = colors[index * 3 + 1]; + g = colors[index * 3]; + b = colors[index * 3 + 2]; + + return true; + } + else + { + r = 0; + g = 0; + b = 0; + + return false; + } + } #endregion #region BlinkStick Pro mode selection @@ -629,6 +669,263 @@ public void SetMode(byte mode) } #endregion + #region Blink Animation + /// + /// Blink the LED on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// The red component. + /// The green component. + /// The blue component. + /// How many times to repeat (default 1) + /// Delay delay between on/off sequences (default 500) + public void Blink(byte channel, byte index, byte r, byte g, byte b, int repeats=1, int delay=500) + { + for (int i = 0; i < repeats; i++) + { + this.InternalSetColor(channel, index, r, g, b); + Thread.Sleep(delay); + this.InternalSetColor(channel, index, 0, 0, 0); + Thread.Sleep(delay); + } + } + + /// + /// Blink the LED on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// Color parameter as RgbColor class instance + /// How many times to repeat (default 1) + /// Delay delay between on/off sequences (default 500) + public void Blink(byte channel, byte index, RgbColor color, int repeats=1, int delay=500) + { + this.Blink(channel, index, color.R, color.G, color.B, repeats, delay); + } + + /// + /// Blink the LED on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How many times to repeat (default 1) + /// Delay delay between on/off sequences (default 500) + public void Blink(byte channel, byte index, string color, int repeats=1, int delay=500) + { + this.Blink(channel, index, RgbColor.FromString(color), repeats, delay); + } + + /// + /// Blink the LED. + /// + /// The red component. + /// The green component. + /// The blue component. + /// How many times to repeat (default 1) + /// Delay delay between on/off sequences (default 500) + public void Blink(byte r, byte g, byte b, int repeats=1, int delay=500) + { + this.Blink(0, 0, r, g, b, repeats, delay); + } + + /// + /// Blink the LED. + /// + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How many times to repeat (default 1) + /// Delay delay between on/off sequences (default 500) + public void Blink(RgbColor color, int repeats=1, int delay=500) + { + this.Blink(0, 0, color, repeats, delay); + } + + /// + /// Blink the LED. + /// + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How many times to repeat (default 1) + /// Delay delay between on/off sequences (default 500) + public void Blink(string color, int repeats=1, int delay=500) + { + this.Blink(0, 0, color, repeats, delay); + } + #endregion + + #region Morph Animation + /// + /// Morph from current color to new color on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// The red component. + /// The green component. + /// The blue component. + /// How long should the morph last + /// How many steps for color changes + public void Morph(byte channel, byte index, byte r, byte g, byte b, int duration=1000, int steps=50) + { + byte cr, cg, cb; + GetColor(index, out cr, out cg, out cb); + + for (int i = 0; i < steps; i++) + { + this.InternalSetColor(channel, index, + (byte)(1.0 * cr + (r - cr) / 1.0 / steps * i), + (byte)(1.0 * cg + (g - cg) / 1.0 / steps * i), + (byte)(1.0 * cb + (b - cb) / 1.0 / steps * i)); + + Thread.Sleep(duration / steps); + } + } + + /// + /// Morph from current color to new color on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// Color parameter as RgbColor class instance + /// How long should the morph last + /// How many steps for color changes + public void Morph(byte channel, byte index, RgbColor color, int duration=1000, int steps=50) + { + this.Morph(channel, index, color.R, color.G, color.B, duration, steps); + } + + /// + /// Morph from current color to new color on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How long should the morph last + /// How many steps for color changes + public void Morph(byte channel, byte index, string color, int duration=1000, int steps=50) + { + this.Morph(channel, index, RgbColor.FromString(color), duration, steps); + } + + /// + /// Morph from current color to new color. + /// + /// The red component. + /// The green component. + /// The blue component. + /// How long should the morph last + /// How many steps for color changes + public void Morph(byte r, byte g, byte b, int duration=1000, int steps=50) + { + this.Morph(0, 0, r, g, b, duration, steps); + } + + /// + /// Morph from current color to new color. + /// + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How long should the morph last + /// How many steps for color changes + public void Morph(RgbColor color, int duration=1000, int steps=50) + { + this.Morph(0, 0, color, duration, steps); + } + + /// + /// Morph from current color to new color. + /// + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How long should the morph last + /// How many steps for color changes + public void Morph(string color, int duration=1000, int steps=50) + { + this.Morph(0, 0, color, duration, steps); + } + #endregion + + #region Pulse Animation + /// + /// Pulse specified color on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// The red component. + /// The green component. + /// The blue component. + /// How long should the morph last + /// How many steps for color changes + public void Pulse(byte channel, byte index, byte r, byte g, byte b, int repeats=1, int duration=1000, int steps=50) + { + this.InternalSetColor(channel, index, 0, 0, 0); + + for (int i = 0; i < repeats; i++) + { + this.Morph(channel, index, r, g, b, duration, steps); + this.Morph(channel, index, 0, 0, 0, duration, steps); + } + } + + /// + /// Pulse specified color on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// Color parameter as RgbColor class instance + /// How long should the morph last + /// How many steps for color changes + public void Pulse(byte channel, byte index, RgbColor color, int repeats=1, int duration=1000, int steps=50) + { + this.Pulse(channel, index, color.R, color.G, color.B, repeats, duration, steps); + } + + /// + /// Pulse specified color on BlinkStick Pro. + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How long should the morph last + /// How many steps for color changes + public void Pulse(byte channel, byte index, string color, int repeats=1, int duration=1000, int steps=50) + { + this.Pulse(channel, index, RgbColor.FromString(color), repeats, duration, steps); + } + + /// + /// Pulse specified color. + /// + /// The red component. + /// The green component. + /// The blue component. + /// How long should the morph last + /// How many steps for color changes + public void Pulse(byte r, byte g, byte b, int repeats=1, int duration=1000, int steps=50) + { + this.Pulse(0, 0, r, g, b, repeats, duration, steps); + } + + /// + /// Pulse specified color. + /// + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How long should the morph last + /// How many steps for color changes + public void Pulse(RgbColor color, int repeats=1, int duration=1000, int steps=50) + { + this.Pulse(0, 0, color, repeats, duration, steps); + } + + /// + /// Pulse specified color. + /// + /// Must be in #rrggbb format or named color ("red", "green", "blue") + /// How long should the morph last + /// How many steps for color changes + public void Pulse(string color, int repeats=1, int duration=1000, int steps=50) + { + this.Pulse(0, 0, color, repeats, duration, steps); + } + #endregion + #region Static Functions to initialize BlinkSticks /// /// Find all BlinkStick devices. @@ -686,6 +983,18 @@ private void CheckRequiresSoftwareColorPatch() { _RequiresSoftwareColorPatch = VersionMajor == 1 && VersionMinor >= 1 && VersionMinor <= 3; } + + private void InternalSetColor(byte channel, byte index, byte r, byte g, byte b) + { + if (channel == 0 && index == 0) + { + this.SetColor(r, g, b); + } + else + { + this.SetColor(channel, index, r, g, b); + } + } #endregion } } From b713224ea89f73ad0c991130a0ad3b56a512c070 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 22:00:13 +0100 Subject: [PATCH 09/50] Renamed static functions to comply with other API implementations --- BlinkStickDotNet/BlinkStick.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 32b257d..e8fa371 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -931,7 +931,7 @@ public void Pulse(string color, int repeats=1, int duration=1000, int steps=50) /// Find all BlinkStick devices. /// /// The devices. - public static BlinkStick[] AllDevices () + public static BlinkStick[] FindAll () { List result = new List(); @@ -950,9 +950,9 @@ public static BlinkStick[] AllDevices () /// Find first BlinkStick. /// /// BlinkStickHid device if found, otherwise null if no devices found - public static BlinkStick FirstDevice() + public static BlinkStick FirstFirst() { - BlinkStick[] devices = AllDevices(); + BlinkStick[] devices = FindAll(); return devices.Length > 0 ? devices[0] : null; } @@ -964,7 +964,7 @@ public static BlinkStick FirstDevice() /// Serial number to search for public static BlinkStick FindBySerial(String serial) { - foreach (BlinkStick device in AllDevices()) + foreach (BlinkStick device in FindAll()) { if (device.Serial == serial) return device; From c576cb2f6bcae9db9675551d623859b9847f4273 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 25 Sep 2014 22:00:29 +0100 Subject: [PATCH 10/50] Improved documentation --- BlinkStickDotNet/BlinkStick.cs | 42 ++++++++++++++++++++++------------ BlinkStickDotNet/RgbColor.cs | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index e8fa371..d3346f9 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -27,7 +27,9 @@ namespace BlinkStickDotNet { /// - /// Main class to access Blinkstick HID devices. + /// BlinkStick class is designed to control regular BlinkStick devices. + /// Code examples on how you can use this class are available + /// wiki. /// public class BlinkStick : IDisposable { @@ -47,7 +49,7 @@ public class BlinkStick : IDisposable #region Device Properties /// - /// Gets a value indicating whether this is connected. + /// Gets a value indicating whether this is connected. /// /// true if connected; otherwise, false. public Boolean Connected { @@ -57,16 +59,18 @@ public Boolean Connected { } /// - /// Returns the serial number of BlinkStick. + /// Returns the serial number of BlinkStick. + ///
         /// BSnnnnnn-1.0
         /// ||  |    | |- Software minor version
         /// ||  |    |--- Software major version
         /// ||  |-------- Denotes sequential number
         /// ||----------- Denotes BlinkStick device
+        /// 
/// /// Software version defines the capabilities of the device ///
- /// The serial. + /// Returns the serial. public String Serial { get { return device.SerialNumber; @@ -78,7 +82,7 @@ public String Serial { /// /// Gets the major version number from serial number. /// - /// The major version number. + /// Returns the major version number. public int VersionMajor { get { if (_VersionMajor == -1) @@ -102,7 +106,7 @@ public int VersionMajor { /// /// Gets the minor version number from serial number. /// - /// The version minor. + /// Returns the version minor. public int VersionMinor { get { if (_VersionMinor == -1) @@ -124,7 +128,7 @@ public int VersionMinor { /// /// Gets the name of the manufacturer. /// - /// The name of the manufacturer. + /// Returns the name of the manufacturer. public String ManufacturerName { get { return device.Manufacturer; @@ -134,7 +138,7 @@ public String ManufacturerName { /// /// Gets the product name of the device. /// - /// The name of the product. + /// Returns the name of the product. public String ProductName { get { return device.ProductName; @@ -145,7 +149,7 @@ public String ProductName { /// /// Gets or sets the name of the device (InfoBlock1). /// - /// The name. + /// String value of InfoBlock1 public String InfoBlock1 { get { if (_InfoBlock1 == null) { @@ -167,7 +171,7 @@ public String InfoBlock1 { /// /// Gets or sets the data of the device (InfoBlock2). /// - /// The data. + /// String value of InfoBlock2 public String InfoBlock2 { get { if (_InfoBlock2 == null) { @@ -188,14 +192,14 @@ public String InfoBlock2 { #region Constructor/Destructor /// - /// Initializes a new instance of the BlinkstickHid class. + /// Initializes a new instance of the BlinkStick class. /// public BlinkStick() { } /// - /// Closes the connection to the device. + /// Disposes of the device and closes the connection. /// public void Dispose() { @@ -930,7 +934,7 @@ public void Pulse(string color, int repeats=1, int duration=1000, int steps=50) /// /// Find all BlinkStick devices. /// - /// The devices. + /// An array of BlinkStick devices public static BlinkStick[] FindAll () { List result = new List(); @@ -949,7 +953,7 @@ public static BlinkStick[] FindAll () /// /// Find first BlinkStick. /// - /// BlinkStickHid device if found, otherwise null if no devices found + /// BlinkStick device if found, otherwise null if no devices found public static BlinkStick FirstFirst() { BlinkStick[] devices = FindAll(); @@ -960,7 +964,7 @@ public static BlinkStick FirstFirst() /// /// Finds BlinkStick by serial number. /// - /// BlinkStickHid device if found, otherwise null if no devices found + /// BlinkStick device if found, otherwise null if no devices found /// Serial number to search for public static BlinkStick FindBySerial(String serial) { @@ -984,6 +988,14 @@ private void CheckRequiresSoftwareColorPatch() _RequiresSoftwareColorPatch = VersionMajor == 1 && VersionMinor >= 1 && VersionMinor <= 3; } + /// + /// Automatically sets the color of the device using either BlinkStick or BlinkStick Pro API + /// + /// Channel (0 - R, 1 - G, 2 - B) + /// Index of the LED + /// The red component. + /// The green component. + /// The blue component. private void InternalSetColor(byte channel, byte index, byte r, byte g, byte b) { if (channel == 0 && index == 0) diff --git a/BlinkStickDotNet/RgbColor.cs b/BlinkStickDotNet/RgbColor.cs index e73a422..6c38b75 100644 --- a/BlinkStickDotNet/RgbColor.cs +++ b/BlinkStickDotNet/RgbColor.cs @@ -235,7 +235,7 @@ public static RgbColor FromGdkColor(ushort r, ushort g, ushort b) /// Converts HEX string or name of the RGB color. For example #123456, blue, red, orange /// /// The string. - /// Color string. + /// Color string. public static RgbColor FromString (String color) { RgbColor result = new RgbColor(); From 99da80fcdb136c225210663153714ac4aa4e3730 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 11:33:56 +0100 Subject: [PATCH 11/50] Added examples --- Examples.sln | 105 ++++++++++++++++++ .../BlinkStick/BlinkTest/BlinkTest.csproj | 46 ++++++++ Examples/BlinkStick/BlinkTest/Program.cs | 23 ++++ .../BlinkTest/Properties/AssemblyInfo.cs | 27 +++++ .../FindBySerial/FindBySerial.csproj | 45 ++++++++ Examples/BlinkStick/FindBySerial/Program.cs | 24 ++++ .../FindBySerial/Properties/AssemblyInfo.cs | 27 +++++ Examples/BlinkStick/GetInfo/GetInfo.csproj | 45 ++++++++ Examples/BlinkStick/GetInfo/Program.cs | 46 ++++++++ .../GetInfo/Properties/AssemblyInfo.cs | 27 +++++ .../BlinkStick/MorphTest/MorphTest.csproj | 46 ++++++++ Examples/BlinkStick/MorphTest/Program.cs | 20 ++++ .../MorphTest/Properties/AssemblyInfo.cs | 27 +++++ Examples/BlinkStick/PulseTest/Program.cs | 20 ++++ .../PulseTest/Properties/AssemblyInfo.cs | 27 +++++ .../BlinkStick/PulseTest/PulseTest.csproj | 46 ++++++++ Examples/BlinkStick/SetRandomColor/Program.cs | 36 ++++++ .../SetRandomColor/Properties/AssemblyInfo.cs | 27 +++++ .../SetRandomColor/SetRandomColor.csproj | 45 ++++++++ Examples/BlinkStick/TurnOff/Program.cs | 26 +++++ .../TurnOff/Properties/AssemblyInfo.cs | 27 +++++ Examples/BlinkStick/TurnOff/TurnOff.csproj | 45 ++++++++ .../IndexedColorFrame.csproj | 45 ++++++++ .../IndexedColorFrame/Program.cs | 44 ++++++++ .../Properties/AssemblyInfo.cs | 27 +++++ .../IndexedColors/IndexedColors.csproj | 45 ++++++++ .../BlinkStickPro/IndexedColors/Program.cs | 39 +++++++ .../IndexedColors/Properties/AssemblyInfo.cs | 27 +++++ 28 files changed, 1034 insertions(+) create mode 100644 Examples.sln create mode 100644 Examples/BlinkStick/BlinkTest/BlinkTest.csproj create mode 100644 Examples/BlinkStick/BlinkTest/Program.cs create mode 100644 Examples/BlinkStick/BlinkTest/Properties/AssemblyInfo.cs create mode 100644 Examples/BlinkStick/FindBySerial/FindBySerial.csproj create mode 100644 Examples/BlinkStick/FindBySerial/Program.cs create mode 100644 Examples/BlinkStick/FindBySerial/Properties/AssemblyInfo.cs create mode 100644 Examples/BlinkStick/GetInfo/GetInfo.csproj create mode 100644 Examples/BlinkStick/GetInfo/Program.cs create mode 100644 Examples/BlinkStick/GetInfo/Properties/AssemblyInfo.cs create mode 100644 Examples/BlinkStick/MorphTest/MorphTest.csproj create mode 100644 Examples/BlinkStick/MorphTest/Program.cs create mode 100644 Examples/BlinkStick/MorphTest/Properties/AssemblyInfo.cs create mode 100644 Examples/BlinkStick/PulseTest/Program.cs create mode 100644 Examples/BlinkStick/PulseTest/Properties/AssemblyInfo.cs create mode 100644 Examples/BlinkStick/PulseTest/PulseTest.csproj create mode 100644 Examples/BlinkStick/SetRandomColor/Program.cs create mode 100644 Examples/BlinkStick/SetRandomColor/Properties/AssemblyInfo.cs create mode 100644 Examples/BlinkStick/SetRandomColor/SetRandomColor.csproj create mode 100644 Examples/BlinkStick/TurnOff/Program.cs create mode 100644 Examples/BlinkStick/TurnOff/Properties/AssemblyInfo.cs create mode 100644 Examples/BlinkStick/TurnOff/TurnOff.csproj create mode 100644 Examples/BlinkStickPro/IndexedColorFrame/IndexedColorFrame.csproj create mode 100644 Examples/BlinkStickPro/IndexedColorFrame/Program.cs create mode 100644 Examples/BlinkStickPro/IndexedColorFrame/Properties/AssemblyInfo.cs create mode 100644 Examples/BlinkStickPro/IndexedColors/IndexedColors.csproj create mode 100644 Examples/BlinkStickPro/IndexedColors/Program.cs create mode 100644 Examples/BlinkStickPro/IndexedColors/Properties/AssemblyInfo.cs diff --git a/Examples.sln b/Examples.sln new file mode 100644 index 0000000..cfdceec --- /dev/null +++ b/Examples.sln @@ -0,0 +1,105 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibUsbDotNet", "Components\LibWinUsb\LibUsbDotNet.csproj", "{0A78F6FF-5586-4052-8104-E23FF83A7CE1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HidSharp", "Components\HidSharp\HidSharp.csproj", "{0DB86674-2A7B-4BDC-93C1-3F7DC771426C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlinkStickDotNet", "BlinkStickDotNet\BlinkStickDotNet.csproj", "{7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{E9CD0471-DE68-4F37-91A5-9ECD760F01AE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BlinkStick", "BlinkStick", "{17C84E65-0D70-4312-8033-D055F86146A3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlinkTest", "Examples\BlinkStick\BlinkTest\BlinkTest.csproj", "{84F24818-696F-4739-8D43-15CEDCCB517E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FindBySerial", "Examples\BlinkStick\FindBySerial\FindBySerial.csproj", "{850D0A4D-5DDF-46BB-A8B8-3C74E94875EA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetInfo", "Examples\BlinkStick\GetInfo\GetInfo.csproj", "{BE6C3C99-3ECE-4D21-A673-151867345B74}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorphTest", "Examples\BlinkStick\MorphTest\MorphTest.csproj", "{9E974C01-06CC-4AE9-9341-5B3A42EB6F78}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PulseTest", "Examples\BlinkStick\PulseTest\PulseTest.csproj", "{F570009D-7E5A-48F3-90E9-33AB8E512447}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetRandomColor", "Examples\BlinkStick\SetRandomColor\SetRandomColor.csproj", "{8187B197-5226-4A0D-8716-CE60DBE439BF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TurnOff", "Examples\BlinkStick\TurnOff\TurnOff.csproj", "{E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BlinkStickPro", "BlinkStickPro", "{1C9FD0B2-C8A2-4B6A-9288-5B6D2E00DED4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IndexedColorFrame", "Examples\BlinkStickPro\IndexedColorFrame\IndexedColorFrame.csproj", "{61527D2E-C94F-4EA5-8725-02EA6247EB8B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IndexedColors", "Examples\BlinkStickPro\IndexedColors\IndexedColors.csproj", "{725BBC2C-A4D3-4F67-ACC8-C65D92A3ECFE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0A78F6FF-5586-4052-8104-E23FF83A7CE1}.Debug|x86.ActiveCfg = Debug|x86 + {0A78F6FF-5586-4052-8104-E23FF83A7CE1}.Debug|x86.Build.0 = Debug|x86 + {0A78F6FF-5586-4052-8104-E23FF83A7CE1}.Release|x86.ActiveCfg = Release|x86 + {0A78F6FF-5586-4052-8104-E23FF83A7CE1}.Release|x86.Build.0 = Release|x86 + {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Debug|x86.ActiveCfg = Debug|Any CPU + {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Debug|x86.Build.0 = Debug|Any CPU + {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Release|x86.ActiveCfg = Release|Any CPU + {0DB86674-2A7B-4BDC-93C1-3F7DC771426C}.Release|x86.Build.0 = Release|Any CPU + {61527D2E-C94F-4EA5-8725-02EA6247EB8B}.Debug|x86.ActiveCfg = Debug|x86 + {61527D2E-C94F-4EA5-8725-02EA6247EB8B}.Debug|x86.Build.0 = Debug|x86 + {61527D2E-C94F-4EA5-8725-02EA6247EB8B}.Release|x86.ActiveCfg = Release|x86 + {61527D2E-C94F-4EA5-8725-02EA6247EB8B}.Release|x86.Build.0 = Release|x86 + {725BBC2C-A4D3-4F67-ACC8-C65D92A3ECFE}.Debug|x86.ActiveCfg = Debug|x86 + {725BBC2C-A4D3-4F67-ACC8-C65D92A3ECFE}.Debug|x86.Build.0 = Debug|x86 + {725BBC2C-A4D3-4F67-ACC8-C65D92A3ECFE}.Release|x86.ActiveCfg = Release|x86 + {725BBC2C-A4D3-4F67-ACC8-C65D92A3ECFE}.Release|x86.Build.0 = Release|x86 + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}.Debug|x86.ActiveCfg = Debug|Any CPU + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}.Debug|x86.Build.0 = Debug|Any CPU + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}.Release|x86.ActiveCfg = Release|Any CPU + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757}.Release|x86.Build.0 = Release|Any CPU + {8187B197-5226-4A0D-8716-CE60DBE439BF}.Debug|x86.ActiveCfg = Debug|x86 + {8187B197-5226-4A0D-8716-CE60DBE439BF}.Debug|x86.Build.0 = Debug|x86 + {8187B197-5226-4A0D-8716-CE60DBE439BF}.Release|x86.ActiveCfg = Release|x86 + {8187B197-5226-4A0D-8716-CE60DBE439BF}.Release|x86.Build.0 = Release|x86 + {84F24818-696F-4739-8D43-15CEDCCB517E}.Debug|x86.ActiveCfg = Debug|x86 + {84F24818-696F-4739-8D43-15CEDCCB517E}.Debug|x86.Build.0 = Debug|x86 + {84F24818-696F-4739-8D43-15CEDCCB517E}.Release|x86.ActiveCfg = Release|x86 + {84F24818-696F-4739-8D43-15CEDCCB517E}.Release|x86.Build.0 = Release|x86 + {850D0A4D-5DDF-46BB-A8B8-3C74E94875EA}.Debug|x86.ActiveCfg = Debug|x86 + {850D0A4D-5DDF-46BB-A8B8-3C74E94875EA}.Debug|x86.Build.0 = Debug|x86 + {850D0A4D-5DDF-46BB-A8B8-3C74E94875EA}.Release|x86.ActiveCfg = Release|x86 + {850D0A4D-5DDF-46BB-A8B8-3C74E94875EA}.Release|x86.Build.0 = Release|x86 + {9E974C01-06CC-4AE9-9341-5B3A42EB6F78}.Debug|x86.ActiveCfg = Debug|x86 + {9E974C01-06CC-4AE9-9341-5B3A42EB6F78}.Debug|x86.Build.0 = Debug|x86 + {9E974C01-06CC-4AE9-9341-5B3A42EB6F78}.Release|x86.ActiveCfg = Release|x86 + {9E974C01-06CC-4AE9-9341-5B3A42EB6F78}.Release|x86.Build.0 = Release|x86 + {BE6C3C99-3ECE-4D21-A673-151867345B74}.Debug|x86.ActiveCfg = Debug|x86 + {BE6C3C99-3ECE-4D21-A673-151867345B74}.Debug|x86.Build.0 = Debug|x86 + {BE6C3C99-3ECE-4D21-A673-151867345B74}.Release|x86.ActiveCfg = Release|x86 + {BE6C3C99-3ECE-4D21-A673-151867345B74}.Release|x86.Build.0 = Release|x86 + {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}.Debug|x86.ActiveCfg = Debug|x86 + {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}.Debug|x86.Build.0 = Debug|x86 + {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}.Release|x86.ActiveCfg = Release|x86 + {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}.Release|x86.Build.0 = Release|x86 + {F570009D-7E5A-48F3-90E9-33AB8E512447}.Debug|x86.ActiveCfg = Debug|x86 + {F570009D-7E5A-48F3-90E9-33AB8E512447}.Debug|x86.Build.0 = Debug|x86 + {F570009D-7E5A-48F3-90E9-33AB8E512447}.Release|x86.ActiveCfg = Release|x86 + {F570009D-7E5A-48F3-90E9-33AB8E512447}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {17C84E65-0D70-4312-8033-D055F86146A3} = {E9CD0471-DE68-4F37-91A5-9ECD760F01AE} + {1C9FD0B2-C8A2-4B6A-9288-5B6D2E00DED4} = {E9CD0471-DE68-4F37-91A5-9ECD760F01AE} + {84F24818-696F-4739-8D43-15CEDCCB517E} = {17C84E65-0D70-4312-8033-D055F86146A3} + {850D0A4D-5DDF-46BB-A8B8-3C74E94875EA} = {17C84E65-0D70-4312-8033-D055F86146A3} + {BE6C3C99-3ECE-4D21-A673-151867345B74} = {17C84E65-0D70-4312-8033-D055F86146A3} + {9E974C01-06CC-4AE9-9341-5B3A42EB6F78} = {17C84E65-0D70-4312-8033-D055F86146A3} + {F570009D-7E5A-48F3-90E9-33AB8E512447} = {17C84E65-0D70-4312-8033-D055F86146A3} + {8187B197-5226-4A0D-8716-CE60DBE439BF} = {17C84E65-0D70-4312-8033-D055F86146A3} + {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5} = {17C84E65-0D70-4312-8033-D055F86146A3} + {61527D2E-C94F-4EA5-8725-02EA6247EB8B} = {1C9FD0B2-C8A2-4B6A-9288-5B6D2E00DED4} + {725BBC2C-A4D3-4F67-ACC8-C65D92A3ECFE} = {1C9FD0B2-C8A2-4B6A-9288-5B6D2E00DED4} + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Examples\BlinkStick\TurnOff\TurnOff.csproj + EndGlobalSection +EndGlobal diff --git a/Examples/BlinkStick/BlinkTest/BlinkTest.csproj b/Examples/BlinkStick/BlinkTest/BlinkTest.csproj new file mode 100644 index 0000000..6b707bb --- /dev/null +++ b/Examples/BlinkStick/BlinkTest/BlinkTest.csproj @@ -0,0 +1,46 @@ + + + + Debug + x86 + {84F24818-696F-4739-8D43-15CEDCCB517E} + Exe + BlinkTest + BlinkTest + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStick/BlinkTest/Program.cs b/Examples/BlinkStick/BlinkTest/Program.cs new file mode 100644 index 0000000..bb403e3 --- /dev/null +++ b/Examples/BlinkStick/BlinkTest/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading; +using BlinkStickDotNet; + +namespace BlinkTest +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Blink test for BlinkStick.\r\n"); + + BlinkStick device = BlinkStick.FirstFirst (); + if (device != null && device.OpenDevice ()) { + foreach (string color in new string[] {"red", "green", "blue"}) + { + Console.WriteLine (color); + device.Blink(color); + } + } + } + } +} diff --git a/Examples/BlinkStick/BlinkTest/Properties/AssemblyInfo.cs b/Examples/BlinkStick/BlinkTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..17988f2 --- /dev/null +++ b/Examples/BlinkStick/BlinkTest/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("BlinkTest")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Examples/BlinkStick/FindBySerial/FindBySerial.csproj b/Examples/BlinkStick/FindBySerial/FindBySerial.csproj new file mode 100644 index 0000000..7cd9876 --- /dev/null +++ b/Examples/BlinkStick/FindBySerial/FindBySerial.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {850D0A4D-5DDF-46BB-A8B8-3C74E94875EA} + Exe + FindBySerial + FindBySerial + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStick/FindBySerial/Program.cs b/Examples/BlinkStick/FindBySerial/Program.cs new file mode 100644 index 0000000..ef42e41 --- /dev/null +++ b/Examples/BlinkStick/FindBySerial/Program.cs @@ -0,0 +1,24 @@ +using System; +using BlinkStickDotNet; + +namespace FindBySerial +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Find by serial.\r\n"); + + String serial = "BS010000-1.1"; + + if (BlinkStick.FindBySerial (serial) != null) { + Console.WriteLine ("BlinkStick found!"); + } else { + Console.WriteLine ("BlinkStick not found"); + } + + Console.WriteLine ("\r\nPress Enter to exit..."); + Console.ReadLine (); + } + } +} diff --git a/Examples/BlinkStick/FindBySerial/Properties/AssemblyInfo.cs b/Examples/BlinkStick/FindBySerial/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c26abef --- /dev/null +++ b/Examples/BlinkStick/FindBySerial/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("FindBySerial")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Examples/BlinkStick/GetInfo/GetInfo.csproj b/Examples/BlinkStick/GetInfo/GetInfo.csproj new file mode 100644 index 0000000..81397dc --- /dev/null +++ b/Examples/BlinkStick/GetInfo/GetInfo.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {BE6C3C99-3ECE-4D21-A673-151867345B74} + Exe + GetInfo + GetInfo + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStick/GetInfo/Program.cs b/Examples/BlinkStick/GetInfo/Program.cs new file mode 100644 index 0000000..ef4efdc --- /dev/null +++ b/Examples/BlinkStick/GetInfo/Program.cs @@ -0,0 +1,46 @@ +using System; +using BlinkStickDotNet; +using System.Collections.Generic; + +namespace GetInfo +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Information about BlinkSticks.\r\n"); + + BlinkStick[] devices = BlinkStick.FindAll(); + + if (devices.Length == 0) { + Console.WriteLine ("Could not find any BlinkStick devices..."); + return; + } + + //Iterate through all of them + foreach (BlinkStick device in devices) + { + //Open the device + if (device.OpenDevice ()) + { + Console.WriteLine (String.Format ("Device {0} opened successfully", device.Serial)); + + byte cr; + byte cg; + byte cb; + + device.GetColor(out cr, out cg, out cb); + + Console.WriteLine (String.Format (" Device color: #{0:X2}{1:X2}{2:X2}", cr, cg, cb)); + Console.WriteLine (" Serial: " + device.Serial); + Console.WriteLine (" Manufacturer: " + device.ManufacturerName); + Console.WriteLine (" Product Name: " + device.ProductName); + Console.WriteLine (" InfoBlock1: " + device.InfoBlock1); + Console.WriteLine (" InfoBlock2: " + device.InfoBlock2); } + } + + Console.WriteLine ("\r\nPress Enter to exit..."); + Console.ReadLine (); + } + } +} diff --git a/Examples/BlinkStick/GetInfo/Properties/AssemblyInfo.cs b/Examples/BlinkStick/GetInfo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ef3636f --- /dev/null +++ b/Examples/BlinkStick/GetInfo/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("GetInfo")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Examples/BlinkStick/MorphTest/MorphTest.csproj b/Examples/BlinkStick/MorphTest/MorphTest.csproj new file mode 100644 index 0000000..0038d98 --- /dev/null +++ b/Examples/BlinkStick/MorphTest/MorphTest.csproj @@ -0,0 +1,46 @@ + + + + Debug + x86 + {9E974C01-06CC-4AE9-9341-5B3A42EB6F78} + Exe + MorphTest + MorphTest + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStick/MorphTest/Program.cs b/Examples/BlinkStick/MorphTest/Program.cs new file mode 100644 index 0000000..e2761b6 --- /dev/null +++ b/Examples/BlinkStick/MorphTest/Program.cs @@ -0,0 +1,20 @@ +using System; +using BlinkStickDotNet; + +namespace MorphTest +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Morph test for BlinkStick.\r\n"); + + BlinkStick device = BlinkStick.FirstFirst (); + if (device != null && device.OpenDevice ()) { + device.Morph ("red"); + device.Morph ("green"); + device.Morph ("blue"); + } + } + } +} diff --git a/Examples/BlinkStick/MorphTest/Properties/AssemblyInfo.cs b/Examples/BlinkStick/MorphTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4cfecd3 --- /dev/null +++ b/Examples/BlinkStick/MorphTest/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("MorphTest")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Examples/BlinkStick/PulseTest/Program.cs b/Examples/BlinkStick/PulseTest/Program.cs new file mode 100644 index 0000000..0bc8bb0 --- /dev/null +++ b/Examples/BlinkStick/PulseTest/Program.cs @@ -0,0 +1,20 @@ +using System; +using BlinkStickDotNet; + +namespace PulseTest +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Pulse test for BlinkStick.\r\n"); + + BlinkStick device = BlinkStick.FirstFirst (); + if (device != null && device.OpenDevice ()) { + device.Pulse ("red"); + device.Pulse ("green"); + device.Pulse ("blue"); + } + } + } +} diff --git a/Examples/BlinkStick/PulseTest/Properties/AssemblyInfo.cs b/Examples/BlinkStick/PulseTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..da83b90 --- /dev/null +++ b/Examples/BlinkStick/PulseTest/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("PulseTest")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Examples/BlinkStick/PulseTest/PulseTest.csproj b/Examples/BlinkStick/PulseTest/PulseTest.csproj new file mode 100644 index 0000000..0c8eddf --- /dev/null +++ b/Examples/BlinkStick/PulseTest/PulseTest.csproj @@ -0,0 +1,46 @@ + + + + Debug + x86 + {F570009D-7E5A-48F3-90E9-33AB8E512447} + Exe + PulseTest + PulseTest + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStick/SetRandomColor/Program.cs b/Examples/BlinkStick/SetRandomColor/Program.cs new file mode 100644 index 0000000..5110f05 --- /dev/null +++ b/Examples/BlinkStick/SetRandomColor/Program.cs @@ -0,0 +1,36 @@ +using System; +using BlinkStickDotNet; +using System.Collections.Generic; + +namespace SetRandomColor +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Set random color.\r\n"); + + BlinkStick[] devices = BlinkStick.FindAll(); + + if (devices.Length == 0) { + Console.WriteLine ("Could not find any BlinkStick devices..."); + return; + } + + //Iterate through all of them + foreach (BlinkStick device in devices) + { + //Open the device + if (device.OpenDevice ()) + { + Console.WriteLine (String.Format ("Device {0} opened successfully", device.Serial)); + Random r = new Random (); + device.SetColor ((byte)r.Next(), (byte)r.Next(), (byte)r.Next()); + } + } + + Console.WriteLine ("\r\nPress Enter to exit..."); + Console.ReadLine (); + } + } +} diff --git a/Examples/BlinkStick/SetRandomColor/Properties/AssemblyInfo.cs b/Examples/BlinkStick/SetRandomColor/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..df9b046 --- /dev/null +++ b/Examples/BlinkStick/SetRandomColor/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("SetRandomColor")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Examples/BlinkStick/SetRandomColor/SetRandomColor.csproj b/Examples/BlinkStick/SetRandomColor/SetRandomColor.csproj new file mode 100644 index 0000000..6f75c60 --- /dev/null +++ b/Examples/BlinkStick/SetRandomColor/SetRandomColor.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {8187B197-5226-4A0D-8716-CE60DBE439BF} + Exe + SetRandomColor + SetRandomColor + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStick/TurnOff/Program.cs b/Examples/BlinkStick/TurnOff/Program.cs new file mode 100644 index 0000000..5f815a8 --- /dev/null +++ b/Examples/BlinkStick/TurnOff/Program.cs @@ -0,0 +1,26 @@ +using System; +using BlinkStickDotNet; + +namespace TurnOff +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Turn Off.\r\n"); + + BlinkStick device = BlinkStick.FirstFirst (); + + if (device != null) { + if (device.OpenDevice ()) { + device.TurnOff (); + Console.WriteLine ("BlinkStick was turned off"); + } else { + Console.WriteLine ("Could not open the device"); + } + } else { + Console.WriteLine ("BlinkStick not found"); + } + } + } +} diff --git a/Examples/BlinkStick/TurnOff/Properties/AssemblyInfo.cs b/Examples/BlinkStick/TurnOff/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4e4aed3 --- /dev/null +++ b/Examples/BlinkStick/TurnOff/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("TurnOff")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Examples/BlinkStick/TurnOff/TurnOff.csproj b/Examples/BlinkStick/TurnOff/TurnOff.csproj new file mode 100644 index 0000000..7f9412c --- /dev/null +++ b/Examples/BlinkStick/TurnOff/TurnOff.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5} + Exe + TurnOff + TurnOff + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStickPro/IndexedColorFrame/IndexedColorFrame.csproj b/Examples/BlinkStickPro/IndexedColorFrame/IndexedColorFrame.csproj new file mode 100644 index 0000000..da3cd7b --- /dev/null +++ b/Examples/BlinkStickPro/IndexedColorFrame/IndexedColorFrame.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {61527D2E-C94F-4EA5-8725-02EA6247EB8B} + Exe + IndexedColorFrame + IndexedColorFrame + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStickPro/IndexedColorFrame/Program.cs b/Examples/BlinkStickPro/IndexedColorFrame/Program.cs new file mode 100644 index 0000000..c254131 --- /dev/null +++ b/Examples/BlinkStickPro/IndexedColorFrame/Program.cs @@ -0,0 +1,44 @@ +using System; +using BlinkStickDotNet; + +namespace IndexedColorFrame +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Set indexed color frame. \r\nThis example requires BlinkStick Pro with 8 smart pixels connected to R channel.\r\n"); + + BlinkStick device = BlinkStick.FirstFirst (); + + //Set mode to WS2812. Read more about modes here: + //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes + + device.SetMode (2); + + if (device != null) { + if (device.OpenDevice ()) { + + byte[] data = new byte[3*8] + {0, 0, 255, //GRB for led0 + 0, 128, 0, //GRB for led1 + 128, 0, 0, //... + 128, 255, 0, + 0, 255, 128, + 128, 0, 128, + 0, 128, 255, + 128, 0, 0 //GRB for led7 + }; + + + device.SetColors (0, data); + + } else { + Console.WriteLine ("Could not open the device"); + } + } else { + Console.WriteLine ("BlinkStick not found"); + } + } + } +} diff --git a/Examples/BlinkStickPro/IndexedColorFrame/Properties/AssemblyInfo.cs b/Examples/BlinkStickPro/IndexedColorFrame/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7de3d64 --- /dev/null +++ b/Examples/BlinkStickPro/IndexedColorFrame/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("IndexedColorFrame")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Examples/BlinkStickPro/IndexedColors/IndexedColors.csproj b/Examples/BlinkStickPro/IndexedColors/IndexedColors.csproj new file mode 100644 index 0000000..ed1426d --- /dev/null +++ b/Examples/BlinkStickPro/IndexedColors/IndexedColors.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {725BBC2C-A4D3-4F67-ACC8-C65D92A3ECFE} + Exe + IndexedColors + IndexedColors + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStickPro/IndexedColors/Program.cs b/Examples/BlinkStickPro/IndexedColors/Program.cs new file mode 100644 index 0000000..82c2a9c --- /dev/null +++ b/Examples/BlinkStickPro/IndexedColors/Program.cs @@ -0,0 +1,39 @@ +using System; +using BlinkStickDotNet; +using System.Threading; + +namespace IndexedColors +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Set indexed color. \r\nThis example requires BlinkStick Pro with 8 smart pixels connected to R channel.\r\n"); + + BlinkStick device = BlinkStick.FirstFirst (); + + //Set mode to WS2812. Read more about modes here: + //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes + + device.SetMode (2); + + if (device != null) { + if (device.OpenDevice ()) { + + int numberOfLeds = 8; + + for (byte i = 0; i < numberOfLeds; i++) { + device.SetColor (0, i, "#ff0000"); + + Thread.Sleep (500); + } + + } else { + Console.WriteLine ("Could not open the device"); + } + } else { + Console.WriteLine ("BlinkStick not found"); + } + } + } +} diff --git a/Examples/BlinkStickPro/IndexedColors/Properties/AssemblyInfo.cs b/Examples/BlinkStickPro/IndexedColors/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..051acaf --- /dev/null +++ b/Examples/BlinkStickPro/IndexedColors/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("IndexedColors")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + From 52a913c4087430163949297ab1af3c598cec9b23 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 11:56:17 +0100 Subject: [PATCH 12/50] Removed unused parameter --- BlinkStickDotNet/UsbMonitor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlinkStickDotNet/UsbMonitor.cs b/BlinkStickDotNet/UsbMonitor.cs index b180308..541cea2 100644 --- a/BlinkStickDotNet/UsbMonitor.cs +++ b/BlinkStickDotNet/UsbMonitor.cs @@ -47,7 +47,7 @@ public Boolean Monitoring { private set; } - public UsbMonitor (IntPtr mainWindowHandle) + public UsbMonitor () { switch (HidSharp.PlatformDetector.RunningPlatform()) { From 3afcaec4754ed7e22cf0a49794f43d6a5994f6de Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 11:56:44 +0100 Subject: [PATCH 13/50] Move main form off the screen before showing and hiding it --- BlinkStickDotNet/WinUsbDeviceMonitor.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BlinkStickDotNet/WinUsbDeviceMonitor.cs b/BlinkStickDotNet/WinUsbDeviceMonitor.cs index f969552..c43e926 100644 --- a/BlinkStickDotNet/WinUsbDeviceMonitor.cs +++ b/BlinkStickDotNet/WinUsbDeviceMonitor.cs @@ -77,6 +77,13 @@ public WinUsbDeviceMonitor () { form = new MyForm(); form.Monitor = this; + + //Move main form off the screen + form.StartPosition = FormStartPosition.Manual; + form.Width = 10; + form.Height = 10; + form.Left = -200; + form.Visible = true; form.Visible = false; } From bb71dac45fda0074cfb8d6aa161d20e283c69a83 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 11:57:41 +0100 Subject: [PATCH 14/50] Don't show USB device monitor form in taskbar --- BlinkStickDotNet/WinUsbDeviceMonitor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/BlinkStickDotNet/WinUsbDeviceMonitor.cs b/BlinkStickDotNet/WinUsbDeviceMonitor.cs index c43e926..97863cd 100644 --- a/BlinkStickDotNet/WinUsbDeviceMonitor.cs +++ b/BlinkStickDotNet/WinUsbDeviceMonitor.cs @@ -83,6 +83,7 @@ public WinUsbDeviceMonitor () form.Width = 10; form.Height = 10; form.Left = -200; + form.ShowInTaskbar = false; form.Visible = true; form.Visible = false; From daad4caaf1c558ce8eb6f864f4a8bf623304d8a7 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 12:41:50 +0100 Subject: [PATCH 15/50] Track connected and disconnected BlinkStick devices in USBMonitor. Expose events. --- BlinkStickDotNet/UsbMonitor.cs | 106 ++++++++++++++++++++++++++++----- 1 file changed, 91 insertions(+), 15 deletions(-) diff --git a/BlinkStickDotNet/UsbMonitor.cs b/BlinkStickDotNet/UsbMonitor.cs index 541cea2..93054a1 100644 --- a/BlinkStickDotNet/UsbMonitor.cs +++ b/BlinkStickDotNet/UsbMonitor.cs @@ -17,28 +17,82 @@ #endregion using System; +using System.Collections.Generic; using LibUsbDotNet.DeviceNotify; namespace BlinkStickDotNet { public class UsbMonitor { + public event EventHandler BlinkStickConnected; + + protected void OnBlinkStickConnected(BlinkStick device) + { + if (BlinkStickConnected != null) + { + BlinkStickConnected(this, new DeviceModifiedArgs(device)); + } + } + + public event EventHandler BlinkStickDisconnected; + + protected void OnBlinkStickDisconnected(BlinkStick device) + { + if (BlinkStickDisconnected != null) + { + BlinkStickDisconnected(this, new DeviceModifiedArgs(device)); + } + } + /// - /// Occurs when usb device added. + /// Occurs when usb devices change. /// - public event EventHandler UsbDeviceAdded; + public event EventHandler UsbDevicesChanged; /// - /// Raises the usb device added event. + /// Raises the usb device changed event. /// - protected void OnUsbDeviceAdded() + protected void OnUsbDevicesChanged() { - if (UsbDeviceAdded != null) + if (UsbDevicesChanged != null) { - UsbDeviceAdded(this, new EventArgs()); + UsbDevicesChanged(this, new EventArgs()); } + + List newDevices = new List(); + + List scannedDevices = new List(BlinkStick.FindAll()); + + foreach (BlinkStick newDevice in scannedDevices) + { + Boolean found = false; + + for (int i = devices.Count - 1; i >= 0; i--) + { + if (devices[i].Serial == newDevice.Serial) + { + devices.RemoveAt(i); + found = true; + break; + } + } + + if (!found) + { + OnBlinkStickConnected(newDevice); + } + } + + foreach (BlinkStick device in devices) + { + OnBlinkStickDisconnected(device); + } + + devices = scannedDevices; } + List devices; + private WinUsbDeviceMonitor winUsbDeviceMonitor; public IDeviceNotifier UsbDeviceNotifier; @@ -64,17 +118,30 @@ public UsbMonitor () private void HandleDeviceListChanged (object sender, EventArgs e) { - OnUsbDeviceAdded(); + OnUsbDevicesChanged(); } + private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e) + { + OnUsbDevicesChanged(); + } + /// /// Start monitoring for added/removed BlinkStick devices. /// public void Start () { - if (UsbDeviceNotifier != null) { - UsbDeviceNotifier.Enabled = true; - } + //Get the list of already connected BlinkSticks + devices = new List(BlinkStick.FindAll()); + + if (UsbDeviceNotifier != null) + { + UsbDeviceNotifier.Enabled = true; + } + else if (winUsbDeviceMonitor != null) + { + winUsbDeviceMonitor.Enabled = true; + } Monitoring = true; } @@ -89,18 +156,27 @@ public void Stop () UsbDeviceNotifier.OnDeviceNotify -= OnDeviceNotifyEvent; } + else if (winUsbDeviceMonitor != null) + { + winUsbDeviceMonitor.Enabled = false; + } Monitoring = false; } - private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e) - { - OnUsbDeviceAdded(); - } - ~UsbMonitor () { } } + + public class DeviceModifiedArgs : EventArgs + { + public BlinkStick Device; + + public DeviceModifiedArgs(BlinkStick device) + { + this.Device = device; + } + } } From 5bc81ded06cd2b1feec56a455fc872c3df64265b Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 12:42:21 +0100 Subject: [PATCH 16/50] Control monitoring in Windows --- BlinkStickDotNet/WinUsbDeviceMonitor.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/BlinkStickDotNet/WinUsbDeviceMonitor.cs b/BlinkStickDotNet/WinUsbDeviceMonitor.cs index 97863cd..816b5a7 100644 --- a/BlinkStickDotNet/WinUsbDeviceMonitor.cs +++ b/BlinkStickDotNet/WinUsbDeviceMonitor.cs @@ -41,6 +41,8 @@ protected void OnDeviceListChanged() } } + public Boolean Enabled { get; set; } + /// /// Private property to keep reference to Windows form for getting /// notification from the OS about changes to USB devices @@ -65,7 +67,8 @@ protected override void WndProc(ref Message m) || m.WParam.ToInt32() == DBT_DEVICEREMOVECOMPLETE || m.WParam.ToInt32() == DBT_DEVNODES_CHANGED)) { - Monitor.OnDeviceListChanged(); + if (this.Enabled) + Monitor.OnDeviceListChanged(); } base.WndProc(ref m); @@ -75,7 +78,9 @@ protected override void WndProc(ref Message m) public WinUsbDeviceMonitor () { - form = new MyForm(); + this.Enabled = false; + + form = new MyForm(); form.Monitor = this; //Move main form off the screen From 82d24c670872f1498f2133fd1327a74bda420f5d Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 12:42:40 +0100 Subject: [PATCH 17/50] Added USB device monitor example --- Examples.sln | 9 +++- .../BlinkStick/MonitorTest/MonitorTest.csproj | 47 ++++++++++++++++ Examples/BlinkStick/MonitorTest/Program.cs | 54 +++++++++++++++++++ .../MonitorTest/Properties/AssemblyInfo.cs | 27 ++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 Examples/BlinkStick/MonitorTest/MonitorTest.csproj create mode 100644 Examples/BlinkStick/MonitorTest/Program.cs create mode 100644 Examples/BlinkStick/MonitorTest/Properties/AssemblyInfo.cs diff --git a/Examples.sln b/Examples.sln index cfdceec..ff8d4b5 100644 --- a/Examples.sln +++ b/Examples.sln @@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetRandomColor", "Examples\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TurnOff", "Examples\BlinkStick\TurnOff\TurnOff.csproj", "{E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonitorTest", "Examples\BlinkStick\MonitorTest\MonitorTest.csproj", "{F48BE451-412A-4AF9-8A47-CFECC578C54A}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BlinkStickPro", "BlinkStickPro", "{1C9FD0B2-C8A2-4B6A-9288-5B6D2E00DED4}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IndexedColorFrame", "Examples\BlinkStickPro\IndexedColorFrame\IndexedColorFrame.csproj", "{61527D2E-C94F-4EA5-8725-02EA6247EB8B}" @@ -81,6 +83,10 @@ Global {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}.Debug|x86.Build.0 = Debug|x86 {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}.Release|x86.ActiveCfg = Release|x86 {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5}.Release|x86.Build.0 = Release|x86 + {F48BE451-412A-4AF9-8A47-CFECC578C54A}.Debug|x86.ActiveCfg = Debug|x86 + {F48BE451-412A-4AF9-8A47-CFECC578C54A}.Debug|x86.Build.0 = Debug|x86 + {F48BE451-412A-4AF9-8A47-CFECC578C54A}.Release|x86.ActiveCfg = Release|x86 + {F48BE451-412A-4AF9-8A47-CFECC578C54A}.Release|x86.Build.0 = Release|x86 {F570009D-7E5A-48F3-90E9-33AB8E512447}.Debug|x86.ActiveCfg = Debug|x86 {F570009D-7E5A-48F3-90E9-33AB8E512447}.Debug|x86.Build.0 = Debug|x86 {F570009D-7E5A-48F3-90E9-33AB8E512447}.Release|x86.ActiveCfg = Release|x86 @@ -96,10 +102,11 @@ Global {F570009D-7E5A-48F3-90E9-33AB8E512447} = {17C84E65-0D70-4312-8033-D055F86146A3} {8187B197-5226-4A0D-8716-CE60DBE439BF} = {17C84E65-0D70-4312-8033-D055F86146A3} {E1C6B2F8-45E3-490D-B3D1-750ACBAD76F5} = {17C84E65-0D70-4312-8033-D055F86146A3} + {F48BE451-412A-4AF9-8A47-CFECC578C54A} = {17C84E65-0D70-4312-8033-D055F86146A3} {61527D2E-C94F-4EA5-8725-02EA6247EB8B} = {1C9FD0B2-C8A2-4B6A-9288-5B6D2E00DED4} {725BBC2C-A4D3-4F67-ACC8-C65D92A3ECFE} = {1C9FD0B2-C8A2-4B6A-9288-5B6D2E00DED4} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = Examples\BlinkStick\TurnOff\TurnOff.csproj + StartupItem = Examples\BlinkStick\MonitorTest\MonitorTest.csproj EndGlobalSection EndGlobal diff --git a/Examples/BlinkStick/MonitorTest/MonitorTest.csproj b/Examples/BlinkStick/MonitorTest/MonitorTest.csproj new file mode 100644 index 0000000..e61ae91 --- /dev/null +++ b/Examples/BlinkStick/MonitorTest/MonitorTest.csproj @@ -0,0 +1,47 @@ + + + + Debug + x86 + {F48BE451-412A-4AF9-8A47-CFECC578C54A} + Exe + MonitorTest + MonitorTest + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + true + + + full + true + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + + {7AAEBEBE-E38D-47B1-A04C-A055DCEB0757} + BlinkStickDotNet + + + \ No newline at end of file diff --git a/Examples/BlinkStick/MonitorTest/Program.cs b/Examples/BlinkStick/MonitorTest/Program.cs new file mode 100644 index 0000000..27bd00d --- /dev/null +++ b/Examples/BlinkStick/MonitorTest/Program.cs @@ -0,0 +1,54 @@ +using System; +using BlinkStickDotNet; +using System.Windows.Forms; +using System.Collections.Generic; + +namespace MonitorTest +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Monitor BlinkSticks inserted and removed"); + + UsbMonitor monitor = new UsbMonitor(); + + //Attach to connected event + monitor.BlinkStickConnected += (object sender, DeviceModifiedArgs e) => { + Console.WriteLine("BlinkStick " + e.Device.Serial + " connected!"); + }; + + //Attach to disconnected event + monitor.BlinkStickDisconnected += (object sender, DeviceModifiedArgs e) => { + Console.WriteLine("BlinkStick " + e.Device.Serial + " disconnected..."); + }; + + List devices = new List (BlinkStick.FindAll()); + + //List BlinkSticks already connected + foreach (BlinkStick device in devices) + { + Console.WriteLine("BlinkStick " + device.Serial + " already connected"); + } + + //Start monitoring + monitor.Start (); + + Console.WriteLine ("Monitoring for BlinkStick devices... Press any key to exit."); + + //Start application event loop. Alternatively you can run main form: + // Application.Run ([Your form]); + while (true) { + //Process messages + Application.DoEvents (); + + //Exit if key is pressed + if (Console.KeyAvailable) + break; + } + + //Stop monitoring + monitor.Stop (); + } + } +} diff --git a/Examples/BlinkStick/MonitorTest/Properties/AssemblyInfo.cs b/Examples/BlinkStick/MonitorTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..45ff53a --- /dev/null +++ b/Examples/BlinkStick/MonitorTest/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("MonitorTest")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Agile Innovative Ltd")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(c) Agile Innovative Ltd")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + From 9b3e1d5e21f7e7a6d58aea46b33a065ce2f339ab Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 12:57:05 +0100 Subject: [PATCH 18/50] Improved documentation --- BlinkStickDotNet/UsbMonitor.cs | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/BlinkStickDotNet/UsbMonitor.cs b/BlinkStickDotNet/UsbMonitor.cs index 93054a1..2991df2 100644 --- a/BlinkStickDotNet/UsbMonitor.cs +++ b/BlinkStickDotNet/UsbMonitor.cs @@ -24,8 +24,15 @@ namespace BlinkStickDotNet { public class UsbMonitor { + /// + /// Occurs when BlinkStick is connected. + /// public event EventHandler BlinkStickConnected; + /// + /// Raises the BlinkStick connected event. + /// + /// Device which has been connected. protected void OnBlinkStickConnected(BlinkStick device) { if (BlinkStickConnected != null) @@ -34,8 +41,15 @@ protected void OnBlinkStickConnected(BlinkStick device) } } + /// + /// Occurs when BlinkStick disconnected. + /// public event EventHandler BlinkStickDisconnected; + /// + /// Raises the BlinkStick disconnected event. + /// + /// Device which has been disconnected. protected void OnBlinkStickDisconnected(BlinkStick device) { if (BlinkStickDisconnected != null) @@ -91,11 +105,25 @@ protected void OnUsbDevicesChanged() devices = scannedDevices; } + /// + /// Internal list of tracked devices. + /// List devices; + /// + /// USB device monitor for Windows. + /// private WinUsbDeviceMonitor winUsbDeviceMonitor; + + /// + /// USB device monitor for Linux/Mac. + /// public IDeviceNotifier UsbDeviceNotifier; + /// + /// Gets a value indicating whether this is monitoring. + /// + /// true if monitoring; otherwise, false. public Boolean Monitoring { get; private set; @@ -116,11 +144,21 @@ public UsbMonitor () } } + /// + /// Handles the device list change on Windows. + /// + /// Sender object + /// Event args private void HandleDeviceListChanged (object sender, EventArgs e) { OnUsbDevicesChanged(); } + /// + /// Handles device list change on Linux/Mac. + /// + /// Sender. + /// E. private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e) { OnUsbDevicesChanged(); @@ -164,15 +202,29 @@ public void Stop () Monitoring = false; } + /// + /// Releases unmanaged resources and performs other cleanup operations before the + /// is reclaimed by garbage collection. + /// ~UsbMonitor () { } } + /// + /// Device modified arguments. + /// public class DeviceModifiedArgs : EventArgs { + /// + /// The device which has been modified. + /// public BlinkStick Device; + /// + /// Initializes a new instance of the class. + /// + /// Device passed as an argument public DeviceModifiedArgs(BlinkStick device) { this.Device = device; From 8db2c8921411ebb4c39658e4450a9561c0bf823c Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 26 Sep 2014 14:01:22 +0100 Subject: [PATCH 19/50] Major and minor version mixup --- BlinkStickDotNet/BlinkStick.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index d3346f9..7ee1748 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -89,7 +89,7 @@ public int VersionMajor { { try { - _VersionMajor = Convert.ToInt32(this.Serial.Substring(this.Serial.Length - 1, 1)); + _VersionMajor = Convert.ToInt32(this.Serial.Substring(this.Serial.Length - 3, 1)); } catch { @@ -113,7 +113,7 @@ public int VersionMinor { { try { - _VersionMinor = Convert.ToInt32(this.Serial.Substring(this.Serial.Length - 3, 1)); + _VersionMinor = Convert.ToInt32(this.Serial.Substring(this.Serial.Length - 1, 1)); } catch { From 1efd3c9ab9018e92142ea7456b564f993fe88648 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Tue, 30 Sep 2014 15:05:41 +0100 Subject: [PATCH 20/50] Update README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 4b6819e..606aa19 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ -BlinkStickDotNet -================= +.. image:: http://www.blinkstick.com/images/logos/blinkstick-dotnet.png + :alt: BlinkStickDotNet This is BlinkStick .NET interface to control devices connected to the computer. The library is written in Mono/.NET 4.0 C#. From a4072eb943c641b6d27d1763c6824988802e94aa Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 3 Oct 2014 21:46:44 +0100 Subject: [PATCH 21/50] FirstFirst renamed to FindFirst --- BlinkStickDotNet/BlinkStick.cs | 2 +- Examples/BlinkStick/BlinkTest/Program.cs | 2 +- Examples/BlinkStick/MorphTest/Program.cs | 2 +- Examples/BlinkStick/PulseTest/Program.cs | 2 +- Examples/BlinkStick/TurnOff/Program.cs | 2 +- Examples/BlinkStickPro/IndexedColorFrame/Program.cs | 2 +- Examples/BlinkStickPro/IndexedColors/Program.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 7ee1748..1fc40a7 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -954,7 +954,7 @@ public static BlinkStick[] FindAll () /// Find first BlinkStick. /// /// BlinkStick device if found, otherwise null if no devices found - public static BlinkStick FirstFirst() + public static BlinkStick FindFirst() { BlinkStick[] devices = FindAll(); diff --git a/Examples/BlinkStick/BlinkTest/Program.cs b/Examples/BlinkStick/BlinkTest/Program.cs index bb403e3..d837db4 100644 --- a/Examples/BlinkStick/BlinkTest/Program.cs +++ b/Examples/BlinkStick/BlinkTest/Program.cs @@ -10,7 +10,7 @@ public static void Main (string[] args) { Console.WriteLine ("Blink test for BlinkStick.\r\n"); - BlinkStick device = BlinkStick.FirstFirst (); + BlinkStick device = BlinkStick.FindFirst (); if (device != null && device.OpenDevice ()) { foreach (string color in new string[] {"red", "green", "blue"}) { diff --git a/Examples/BlinkStick/MorphTest/Program.cs b/Examples/BlinkStick/MorphTest/Program.cs index e2761b6..ecfd6ca 100644 --- a/Examples/BlinkStick/MorphTest/Program.cs +++ b/Examples/BlinkStick/MorphTest/Program.cs @@ -9,7 +9,7 @@ public static void Main (string[] args) { Console.WriteLine ("Morph test for BlinkStick.\r\n"); - BlinkStick device = BlinkStick.FirstFirst (); + BlinkStick device = BlinkStick.FindFirst (); if (device != null && device.OpenDevice ()) { device.Morph ("red"); device.Morph ("green"); diff --git a/Examples/BlinkStick/PulseTest/Program.cs b/Examples/BlinkStick/PulseTest/Program.cs index 0bc8bb0..e02626a 100644 --- a/Examples/BlinkStick/PulseTest/Program.cs +++ b/Examples/BlinkStick/PulseTest/Program.cs @@ -9,7 +9,7 @@ public static void Main (string[] args) { Console.WriteLine ("Pulse test for BlinkStick.\r\n"); - BlinkStick device = BlinkStick.FirstFirst (); + BlinkStick device = BlinkStick.FindFirst (); if (device != null && device.OpenDevice ()) { device.Pulse ("red"); device.Pulse ("green"); diff --git a/Examples/BlinkStick/TurnOff/Program.cs b/Examples/BlinkStick/TurnOff/Program.cs index 5f815a8..3bc22d0 100644 --- a/Examples/BlinkStick/TurnOff/Program.cs +++ b/Examples/BlinkStick/TurnOff/Program.cs @@ -9,7 +9,7 @@ public static void Main (string[] args) { Console.WriteLine ("Turn Off.\r\n"); - BlinkStick device = BlinkStick.FirstFirst (); + BlinkStick device = BlinkStick.FindFirst (); if (device != null) { if (device.OpenDevice ()) { diff --git a/Examples/BlinkStickPro/IndexedColorFrame/Program.cs b/Examples/BlinkStickPro/IndexedColorFrame/Program.cs index c254131..1bb184b 100644 --- a/Examples/BlinkStickPro/IndexedColorFrame/Program.cs +++ b/Examples/BlinkStickPro/IndexedColorFrame/Program.cs @@ -9,7 +9,7 @@ public static void Main (string[] args) { Console.WriteLine ("Set indexed color frame. \r\nThis example requires BlinkStick Pro with 8 smart pixels connected to R channel.\r\n"); - BlinkStick device = BlinkStick.FirstFirst (); + BlinkStick device = BlinkStick.FindFirst (); //Set mode to WS2812. Read more about modes here: //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes diff --git a/Examples/BlinkStickPro/IndexedColors/Program.cs b/Examples/BlinkStickPro/IndexedColors/Program.cs index 82c2a9c..80ef7da 100644 --- a/Examples/BlinkStickPro/IndexedColors/Program.cs +++ b/Examples/BlinkStickPro/IndexedColors/Program.cs @@ -10,7 +10,7 @@ public static void Main (string[] args) { Console.WriteLine ("Set indexed color. \r\nThis example requires BlinkStick Pro with 8 smart pixels connected to R channel.\r\n"); - BlinkStick device = BlinkStick.FirstFirst (); + BlinkStick device = BlinkStick.FindFirst (); //Set mode to WS2812. Read more about modes here: //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes From 76cba18c2638fdd9ed6edb3f4202a7643ce59ef1 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Sat, 4 Oct 2014 12:28:06 +0100 Subject: [PATCH 22/50] Xamarin studio project file update --- BlinkStickDotNet/BlinkStickDotNet.csproj | 2 ++ Components/HidSharp/HidSharp.csproj | 2 ++ Components/LibWinUsb/LibUsbDotNet.csproj | 2 ++ 3 files changed, 6 insertions(+) diff --git a/BlinkStickDotNet/BlinkStickDotNet.csproj b/BlinkStickDotNet/BlinkStickDotNet.csproj index 2c29fc7..3e53050 100644 --- a/BlinkStickDotNet/BlinkStickDotNet.csproj +++ b/BlinkStickDotNet/BlinkStickDotNet.csproj @@ -7,6 +7,8 @@ Library BlinkStickDotNet BlinkStickDotNet + 8.0.30703 + 2.0
true diff --git a/Components/HidSharp/HidSharp.csproj b/Components/HidSharp/HidSharp.csproj index e80993d..15e3d38 100644 --- a/Components/HidSharp/HidSharp.csproj +++ b/Components/HidSharp/HidSharp.csproj @@ -14,6 +14,8 @@ 3.5 + 8.0.30703 + 2.0 true diff --git a/Components/LibWinUsb/LibUsbDotNet.csproj b/Components/LibWinUsb/LibUsbDotNet.csproj index 6daf845..c7c1ec0 100644 --- a/Components/LibWinUsb/LibUsbDotNet.csproj +++ b/Components/LibWinUsb/LibUsbDotNet.csproj @@ -15,6 +15,8 @@ false LibUsbDotNet.snk + 8.0.30703 + 2.0 true From 284ade0445193c746da65e1f27fc49f02827b56f Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Wed, 8 Oct 2014 23:44:34 +0100 Subject: [PATCH 23/50] Added events to intercept data sent during SetColor and received during GetColor --- BlinkStickDotNet/BlinkStick.cs | 82 ++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 1fc40a7..98d7305 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -47,6 +47,41 @@ public class BlinkStick : IDisposable private bool _RequiresSoftwareColorPatch = false; #endregion + #region Events + public event SendColorEventHandler SendColor; + + public Boolean OnSendColor(byte channel, byte index, byte r, byte g, byte b) + { + if (SendColor != null) + { + SendColorEventArgs args = new SendColorEventArgs(channel, index, r, g, b); + SendColor(this, args); + return args.SendToDevice; + } + + return true; + } + + public event ReceiveColorEventHandler ReceiveColor; + + public Boolean OnReceiveColor(byte index, out byte r, out byte g, out byte b) + { + if (ReceiveColor != null) + { + ReceiveColorEventArgs args = new ReceiveColorEventArgs(index); + ReceiveColor(this, args); + r = args.R; + g = args.G; + b = args.B; + return true; + } + r = 0; + g = 0; + b = 0; + return false; + } + #endregion + #region Device Properties /// /// Gets a value indicating whether this is connected. @@ -423,6 +458,9 @@ public void SetColor(RgbColor color) /// The blue component. public void SetColor(byte r, byte g, byte b) { + if (!OnSendColor(0, 0, r, g, b)) + return; + if (connectedToDriver) { if (_RequiresSoftwareColorPatch) @@ -457,6 +495,9 @@ public void SetColor(byte r, byte g, byte b) /// The blue component. public Boolean GetColor (out byte r, out byte g, out byte b) { + if (OnReceiveColor(0, out r, out g, out b)) + return true; + byte[] report = new byte[33]; report[0] = 1; @@ -497,6 +538,9 @@ public void TurnOff() /// The blue component. public void SetColor(byte channel, byte index, byte r, byte g, byte b) { + if (!OnSendColor(channel, index, r, g, b)) + return; + if (connectedToDriver) { stream.SetFeature(new byte[6] { 5, channel, index, r, g, b }); @@ -632,6 +676,9 @@ public Boolean GetColors (out byte[] colorData) /// The blue component. public Boolean GetColor (byte index, out byte r, out byte g, out byte b) { + if (OnReceiveColor(index, out r, out g, out b)) + return true; + if (index == 0) { return this.GetColor(out r, out g, out b); @@ -1009,5 +1056,40 @@ private void InternalSetColor(byte channel, byte index, byte r, byte g, byte b) } #endregion } + + public delegate void SendColorEventHandler(object sender, SendColorEventArgs e); + + public delegate void ReceiveColorEventHandler(object sender, ReceiveColorEventArgs e); + + public class SendColorEventArgs: EventArgs { + public byte Channel; + public byte Index; + public byte R; + public byte G; + public byte B; + public Boolean SendToDevice; + + public SendColorEventArgs(byte channel, byte index, byte r, byte g, byte b) + { + this.Channel = channel; + this.Index = index; + this.R = r; + this.G = g; + this.B = b; + this.SendToDevice = true; + } + } + + public class ReceiveColorEventArgs: EventArgs { + public byte Index; + public byte R; + public byte G; + public byte B; + + public ReceiveColorEventArgs(byte index) + { + this.Index = index; + } + } } From 44364fc7cd6587a3279e34c2e2d1ebac422c47b2 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 9 Oct 2014 09:27:41 +0100 Subject: [PATCH 24/50] Ability to stop animations --- BlinkStickDotNet/BlinkStick.cs | 37 +++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 98d7305..2082b04 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -42,6 +42,8 @@ public class BlinkStick : IDisposable private bool disposed = false; + private bool stopped = false; + protected bool connectedToDriver = false; private bool _RequiresSoftwareColorPatch = false; @@ -720,6 +722,13 @@ public void SetMode(byte mode) } #endregion + #region Animation Control + public void Stop() + { + this.stopped = true; + } + #endregion + #region Blink Animation /// /// Blink the LED on BlinkStick Pro. @@ -736,9 +745,14 @@ public void Blink(byte channel, byte index, byte r, byte g, byte b, int repeats= for (int i = 0; i < repeats; i++) { this.InternalSetColor(channel, index, r, g, b); - Thread.Sleep(delay); + + if (!WaitThread(delay)) + return; + this.InternalSetColor(channel, index, 0, 0, 0); - Thread.Sleep(delay); + + if (!WaitThread(delay)) + return; } } @@ -827,7 +841,8 @@ public void Morph(byte channel, byte index, byte r, byte g, byte b, int duration (byte)(1.0 * cg + (g - cg) / 1.0 / steps * i), (byte)(1.0 * cb + (b - cb) / 1.0 / steps * i)); - Thread.Sleep(duration / steps); + if (!WaitThread(duration / steps)) + return; } } @@ -1054,6 +1069,22 @@ private void InternalSetColor(byte channel, byte index, byte r, byte g, byte b) this.SetColor(channel, index, r, g, b); } } + + public Boolean WaitThread(long milliseconds) + { + DateTime nextRetry = DateTime.Now + new TimeSpan(TimeSpan.TicksPerMillisecond * milliseconds); + + while (nextRetry > DateTime.Now) + { + if (this.stopped) + return false; + + Thread.Sleep(20); + } + + return true; + } + #endregion } From 8332153683ea59dd38cf200d4c701466cad66d88 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 9 Oct 2014 16:42:55 +0100 Subject: [PATCH 25/50] Added missing methods to avoid compiler warnings --- BlinkStickDotNet/HSLColor.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BlinkStickDotNet/HSLColor.cs b/BlinkStickDotNet/HSLColor.cs index 1ed78d0..6593d12 100644 --- a/BlinkStickDotNet/HSLColor.cs +++ b/BlinkStickDotNet/HSLColor.cs @@ -177,5 +177,15 @@ public override string ToString() s += string.Format ("RGB({0:x2}{1:x2}{2:x2})", Color.R, Color.G, Color.B); return s; } + + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } } From beac400a2f4e008ad99c3ed2c5c7b8413d3e6471 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 9 Oct 2014 16:43:22 +0100 Subject: [PATCH 26/50] Disable XML documentation generator, because assembly lacks proper documentation --- Components/HidSharp/HidSharp.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/Components/HidSharp/HidSharp.csproj b/Components/HidSharp/HidSharp.csproj index 15e3d38..010042f 100644 --- a/Components/HidSharp/HidSharp.csproj +++ b/Components/HidSharp/HidSharp.csproj @@ -27,11 +27,9 @@ 4 true false - ..\bin\HidSharp.XML x86 - pdbonly true ..\bin\ TRACE @@ -39,7 +37,6 @@ 4 true false - ..\bin\HidSharp.XML From 72552343ccad0597a9c0506deed3c9bf4fadc44b Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Sun, 16 Nov 2014 21:19:03 +0000 Subject: [PATCH 27/50] Fix for incorrect color element assignment --- BlinkStickDotNet/BlinkStick.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 2082b04..de458d7 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -568,7 +568,7 @@ public void SetColor(byte channel, byte index, string color) /// Color parameter as RgbColor class instance public void SetColor(byte channel, byte index, RgbColor color) { - SetColor(channel, index, color.R, color.B, color.G); + SetColor(channel, index, color.R, color.G, color.B); } /// From 8796b7d8c3adc93a90481bde8ff50ebfafb99e87 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Tue, 25 Nov 2014 12:44:00 +0000 Subject: [PATCH 28/50] API to set mode --- BlinkStickDotNet/BlinkStick.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index de458d7..d8fa39c 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -720,6 +720,23 @@ public void SetMode(byte mode) stream.SetFeature(new byte[2] {4, mode}); } } + + /// + /// Gets the mode on BlinkStick Pro. + /// + /// 0 - Normal, 1 - Inverse, 2 - WS2812, 3 - WS2812 mirror + public int GetMode() + { + if (connectedToDriver) + { + byte[] data = new byte[2]; + data[0] = 4; + stream.GetFeature(data, 0, data.Length); + return data[1]; + } + + return -1; + } #endregion #region Animation Control From 115900008d0769dd26610c4b0f3fe3f94598036d Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 11 Dec 2014 10:57:52 +0000 Subject: [PATCH 29/50] Set mode after device is opened --- .../IndexedColorFrame/Program.cs | 89 ++++++++++--------- .../BlinkStickPro/IndexedColors/Program.cs | 81 +++++++++-------- 2 files changed, 87 insertions(+), 83 deletions(-) diff --git a/Examples/BlinkStickPro/IndexedColorFrame/Program.cs b/Examples/BlinkStickPro/IndexedColorFrame/Program.cs index 1bb184b..61d4f97 100644 --- a/Examples/BlinkStickPro/IndexedColorFrame/Program.cs +++ b/Examples/BlinkStickPro/IndexedColorFrame/Program.cs @@ -1,44 +1,45 @@ -using System; -using BlinkStickDotNet; - -namespace IndexedColorFrame -{ - class MainClass - { - public static void Main (string[] args) - { - Console.WriteLine ("Set indexed color frame. \r\nThis example requires BlinkStick Pro with 8 smart pixels connected to R channel.\r\n"); - - BlinkStick device = BlinkStick.FindFirst (); - - //Set mode to WS2812. Read more about modes here: - //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes - - device.SetMode (2); - - if (device != null) { - if (device.OpenDevice ()) { - - byte[] data = new byte[3*8] - {0, 0, 255, //GRB for led0 - 0, 128, 0, //GRB for led1 - 128, 0, 0, //... - 128, 255, 0, - 0, 255, 128, - 128, 0, 128, - 0, 128, 255, - 128, 0, 0 //GRB for led7 - }; - - - device.SetColors (0, data); - - } else { - Console.WriteLine ("Could not open the device"); - } - } else { - Console.WriteLine ("BlinkStick not found"); - } - } - } -} +using System; +using BlinkStickDotNet; +using System.Threading; + +namespace IndexedColorFrame +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Set indexed color frame. \r\nThis example requires BlinkStick Pro with 8 smart pixels connected to R channel.\r\n"); + + BlinkStick device = BlinkStick.FindFirst (); + + if (device != null) { + if (device.OpenDevice ()) { + //Set mode to WS2812. Read more about modes here: + //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes + + device.SetMode (2); + Thread.Sleep (100); + + byte[] data = new byte[3*8] + {0, 0, 255, //GRB for led0 + 0, 128, 0, //GRB for led1 + 128, 0, 0, //... + 128, 255, 0, + 0, 255, 128, + 128, 0, 128, + 0, 128, 255, + 128, 0, 0 //GRB for led7 + }; + + + device.SetColors (0, data); + + } else { + Console.WriteLine ("Could not open the device"); + } + } else { + Console.WriteLine ("BlinkStick not found"); + } + } + } +} diff --git a/Examples/BlinkStickPro/IndexedColors/Program.cs b/Examples/BlinkStickPro/IndexedColors/Program.cs index 80ef7da..dd18c0b 100644 --- a/Examples/BlinkStickPro/IndexedColors/Program.cs +++ b/Examples/BlinkStickPro/IndexedColors/Program.cs @@ -1,39 +1,42 @@ -using System; -using BlinkStickDotNet; -using System.Threading; - -namespace IndexedColors -{ - class MainClass - { - public static void Main (string[] args) - { - Console.WriteLine ("Set indexed color. \r\nThis example requires BlinkStick Pro with 8 smart pixels connected to R channel.\r\n"); - - BlinkStick device = BlinkStick.FindFirst (); - - //Set mode to WS2812. Read more about modes here: - //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes - - device.SetMode (2); - - if (device != null) { - if (device.OpenDevice ()) { - - int numberOfLeds = 8; - - for (byte i = 0; i < numberOfLeds; i++) { - device.SetColor (0, i, "#ff0000"); - - Thread.Sleep (500); - } - - } else { - Console.WriteLine ("Could not open the device"); - } - } else { - Console.WriteLine ("BlinkStick not found"); - } - } - } -} +using System; +using BlinkStickDotNet; +using System.Threading; + +namespace IndexedColors +{ + class MainClass + { + public static void Main (string[] args) + { + Console.WriteLine ("Set indexed color. \r\nThis example requires BlinkStick Pro with 8 smart pixels connected to R channel.\r\n"); + + BlinkStick device = BlinkStick.FindFirst (); + + //Set mode to WS2812. Read more about modes here: + //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes + + if (device != null) { + if (device.OpenDevice ()) { + //Set mode to WS2812. Read more about modes here: + //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes + + device.SetMode (2); + Thread.Sleep (100); + + int numberOfLeds = 8; + + for (byte i = 0; i < numberOfLeds; i++) { + device.SetColor (0, i, "#ff0000"); + + Thread.Sleep (500); + } + + } else { + Console.WriteLine ("Could not open the device"); + } + } else { + Console.WriteLine ("BlinkStick not found"); + } + } + } +} From dc21f5e99c5f5f8174fca1be714899a7fc1356cb Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 11 Dec 2014 11:04:50 +0000 Subject: [PATCH 30/50] Removed duplicate comment --- Examples/BlinkStickPro/IndexedColors/Program.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Examples/BlinkStickPro/IndexedColors/Program.cs b/Examples/BlinkStickPro/IndexedColors/Program.cs index dd18c0b..bacdd20 100644 --- a/Examples/BlinkStickPro/IndexedColors/Program.cs +++ b/Examples/BlinkStickPro/IndexedColors/Program.cs @@ -12,9 +12,6 @@ public static void Main (string[] args) BlinkStick device = BlinkStick.FindFirst (); - //Set mode to WS2812. Read more about modes here: - //http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes - if (device != null) { if (device.OpenDevice ()) { //Set mode to WS2812. Read more about modes here: From 0fc6d998d6e16c4586086515ebdd12b55bad4002 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 12 Dec 2014 18:40:02 +0000 Subject: [PATCH 31/50] Correctly calculate morphing to finish at selected color --- BlinkStickDotNet/BlinkStick.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index d8fa39c..d62b632 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -851,7 +851,7 @@ public void Morph(byte channel, byte index, byte r, byte g, byte b, int duration byte cr, cg, cb; GetColor(index, out cr, out cg, out cb); - for (int i = 0; i < steps; i++) + for (int i = 1; i <= steps; i++) { this.InternalSetColor(channel, index, (byte)(1.0 * cr + (r - cr) / 1.0 / steps * i), From 2c942034919ecda6d1aee52be472cc223966f296 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 12 Dec 2014 18:40:21 +0000 Subject: [PATCH 32/50] Attempt multiple times to get color before failing --- BlinkStickDotNet/BlinkStick.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index d62b632..d2dfe03 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -503,8 +503,25 @@ public Boolean GetColor (out byte r, out byte g, out byte b) byte[] report = new byte[33]; report[0] = 1; - if (connectedToDriver) { - stream.GetFeature(report, 0, 33); + if (connectedToDriver) { + int attempt = 0; + while (attempt < 5) + { + attempt++; + try + { + stream.GetFeature(report, 0, 33); + break; + } + catch + { + if (attempt == 5) + throw; + + Thread.Sleep(1); + } + } + r = report [1]; g = report [2]; From c2a0eeae0bca9b0d9a468c17928db10e8f4942bd Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 12 Dec 2014 18:49:59 +0000 Subject: [PATCH 33/50] Ignore Win32 exceptions with native code 0 for SetFeature --- BlinkStickDotNet/BlinkStick.cs | 36 ++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index d2dfe03..958c740 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -399,7 +399,7 @@ protected void SetInfoBlock (byte id, byte[] data) data[0] = id; - stream.SetFeature(data); + SetFeature(data); } else { throw new Exception("Invalid info block id"); } @@ -474,17 +474,17 @@ public void SetColor(byte r, byte g, byte b) { if (cr > 0) { - stream.SetFeature(new byte[4] { 1, (byte)(cr - 1), cg, cb }); + SetFeature(new byte[4] { 1, (byte)(cr - 1), cg, cb }); } else if (cg > 0) { - stream.SetFeature(new byte[4] { 1, cr, (byte)(cg - 1), cb }); + SetFeature(new byte[4] { 1, cr, (byte)(cg - 1), cb }); } } } } - stream.SetFeature(new byte[4] {1, r, g, b}); + SetFeature(new byte[4] {1, r, g, b}); } } @@ -562,7 +562,7 @@ public void SetColor(byte channel, byte index, byte r, byte g, byte b) if (connectedToDriver) { - stream.SetFeature(new byte[6] { 5, channel, index, r, g, b }); + SetFeature(new byte[6] { 5, channel, index, r, g, b }); } } @@ -639,7 +639,7 @@ public void SetColors(byte channel, byte[] colorData) data[i] = 0; } - stream.SetFeature(data); + SetFeature(data); if (reportId == 10) { @@ -655,7 +655,7 @@ public void SetColors(byte channel, byte[] colorData) data[0] = (byte)(reportId + 1); - stream.SetFeature(data); + SetFeature(data); } } @@ -734,7 +734,7 @@ public void SetMode(byte mode) { if (connectedToDriver) { - stream.SetFeature(new byte[2] {4, mode}); + SetFeature(new byte[2] {4, mode}); } } @@ -1102,6 +1102,26 @@ private void InternalSetColor(byte channel, byte index, byte r, byte g, byte b) { this.SetColor(channel, index, r, g, b); } + } + + private void SetFeature(byte[] buffer) + { + try + { + stream.SetFeature(buffer); + } + catch (System.IO.IOException e) + { + if (e.InnerException is System.ComponentModel.Win32Exception) + { + System.ComponentModel.Win32Exception win32Exception = e.InnerException as System.ComponentModel.Win32Exception; + + if (win32Exception != null && win32Exception.NativeErrorCode == 0) + return; + } + + throw; + } } public Boolean WaitThread(long milliseconds) From e0625128bddb43ab14a38a49c9ab7300716e4201 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 12 Dec 2014 21:51:29 +0000 Subject: [PATCH 34/50] Do not start or continue Morph animation if stopped --- BlinkStickDotNet/BlinkStick.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 958c740..2dd157b 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -864,7 +864,10 @@ public void Blink(string color, int repeats=1, int delay=500) /// How long should the morph last /// How many steps for color changes public void Morph(byte channel, byte index, byte r, byte g, byte b, int duration=1000, int steps=50) - { + { + if (stopped) + return; + byte cr, cg, cb; GetColor(index, out cr, out cg, out cb); @@ -958,8 +961,15 @@ public void Pulse(byte channel, byte index, byte r, byte g, byte b, int repeats= this.InternalSetColor(channel, index, 0, 0, 0); for (int i = 0; i < repeats; i++) - { + { + if (this.stopped) + break; + this.Morph(channel, index, r, g, b, duration, steps); + + if (this.stopped) + break; + this.Morph(channel, index, 0, 0, 0, duration, steps); } } From 87fc0b42bb80f288a0c2f96c51ef6d6ff1ebe677 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 12 Dec 2014 21:51:46 +0000 Subject: [PATCH 35/50] Allow to resume animations --- BlinkStickDotNet/BlinkStick.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 2dd157b..28e18cd 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -761,6 +761,11 @@ public void Stop() { this.stopped = true; } + + public void Enable() + { + this.stopped = false; + } #endregion #region Blink Animation From b78bcc342f73dd3bcbd5c5f714bd4e588f78dc33 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Sat, 13 Dec 2014 11:53:51 +0000 Subject: [PATCH 36/50] Use WaitThread to reattempt getting the current color --- BlinkStickDotNet/BlinkStick.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 28e18cd..6a00ed0 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -518,7 +518,8 @@ public Boolean GetColor (out byte r, out byte g, out byte b) if (attempt == 5) throw; - Thread.Sleep(1); + if (!WaitThread(20)) + return false; } } From 4b4a862a6556abb087bdb996fad4513390f817c5 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Sun, 14 Dec 2014 11:23:26 +0000 Subject: [PATCH 37/50] Attempt multiple times to send feature before failing --- BlinkStickDotNet/BlinkStick.cs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 6a00ed0..b9d48b9 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -1122,21 +1122,31 @@ private void InternalSetColor(byte channel, byte index, byte r, byte g, byte b) private void SetFeature(byte[] buffer) { - try + int attempt = 0; + while (attempt < 5) { - stream.SetFeature(buffer); - } - catch (System.IO.IOException e) - { - if (e.InnerException is System.ComponentModel.Win32Exception) + attempt++; + try + { + stream.SetFeature(buffer); + break; + } + catch (System.IO.IOException e) { - System.ComponentModel.Win32Exception win32Exception = e.InnerException as System.ComponentModel.Win32Exception; + if (e.InnerException is System.ComponentModel.Win32Exception) + { + System.ComponentModel.Win32Exception win32Exception = e.InnerException as System.ComponentModel.Win32Exception; + + if (win32Exception != null && win32Exception.NativeErrorCode == 0) + return; + } - if (win32Exception != null && win32Exception.NativeErrorCode == 0) + if (attempt == 5) + throw; + + if (!WaitThread(20)) return; } - - throw; } } From 2378f7bc80f92364fdaf73bf8f968967f4ae1080 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Sun, 14 Dec 2014 22:27:20 +0000 Subject: [PATCH 38/50] Add ability to set delay for initial black in pulse animation --- BlinkStickDotNet/BlinkStick.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index b9d48b9..72307c7 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -224,7 +224,9 @@ public String InfoBlock2 { SetInfoBlock(3, _InfoBlock2); } } - } + } + + public int SetColorDelay { get; set; } #endregion #region Constructor/Destructor @@ -232,7 +234,8 @@ public String InfoBlock2 { /// Initializes a new instance of the BlinkStick class. /// public BlinkStick() - { + { + SetColorDelay = 0; } /// @@ -965,6 +968,12 @@ public void Morph(string color, int duration=1000, int steps=50) public void Pulse(byte channel, byte index, byte r, byte g, byte b, int repeats=1, int duration=1000, int steps=50) { this.InternalSetColor(channel, index, 0, 0, 0); + + if (this.SetColorDelay > 0) + { + if (!WaitThread(this.SetColorDelay)) + return; + } for (int i = 0; i < repeats; i++) { @@ -1117,7 +1126,7 @@ private void InternalSetColor(byte channel, byte index, byte r, byte g, byte b) else { this.SetColor(channel, index, r, g, b); - } + } } private void SetFeature(byte[] buffer) From 45ff6c5e4a451514934d36391b690edc7be58e38 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 18 Dec 2014 17:52:45 +0000 Subject: [PATCH 39/50] Detect BlinkStick device type --- BlinkStickDotNet/BlinkStick.cs | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 72307c7..4f7572a 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -160,6 +160,38 @@ public int VersionMinor { return _VersionMinor; } + } + + /// + /// Gets the device type + /// + /// Returns the device type. + public BlinkStickDeviceEnum BlinkStickDevice + { + get + { + if (VersionMajor == 1) + { + return BlinkStickDeviceEnum.BlinkStick; + } + else if (VersionMajor == 2) + { + return BlinkStickDeviceEnum.BlinkStickPro; + } + else if (VersionMajor == 3) + { + if (device.ProductVersion == 0x0200) + { + return BlinkStickDeviceEnum.BlinkStickSquare; + } + else if (device.ProductVersion == 0x0201) + { + return BlinkStickDeviceEnum.BlinkStickStrip; + } + } + + return BlinkStickDeviceEnum.Unknown; + } } /// @@ -1210,6 +1242,15 @@ public ReceiveColorEventArgs(byte index) { this.Index = index; } + } + + public enum BlinkStickDeviceEnum + { + Unknown, + BlinkStick, + BlinkStickPro, + BlinkStickStrip, + BlinkStickSquare } } From e7f6be2c5b68dd4edd0d40717a9258c087a07e33 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Wed, 7 Jan 2015 12:40:29 +0000 Subject: [PATCH 40/50] Support Any CPU builds --- BlinkStickDotNet/BlinkStickDotNet.csproj | 1 - Components/HidSharp/HidSharp.csproj | 1 - 2 files changed, 2 deletions(-) diff --git a/BlinkStickDotNet/BlinkStickDotNet.csproj b/BlinkStickDotNet/BlinkStickDotNet.csproj index 3e53050..c13d4ca 100644 --- a/BlinkStickDotNet/BlinkStickDotNet.csproj +++ b/BlinkStickDotNet/BlinkStickDotNet.csproj @@ -19,7 +19,6 @@ prompt 4 false - x86 none diff --git a/Components/HidSharp/HidSharp.csproj b/Components/HidSharp/HidSharp.csproj index 010042f..83edbdf 100644 --- a/Components/HidSharp/HidSharp.csproj +++ b/Components/HidSharp/HidSharp.csproj @@ -27,7 +27,6 @@ 4 true false - x86 true From 5a60c348e6a77494eaece915097d265703265e59 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 9 Jan 2015 14:13:20 +0000 Subject: [PATCH 41/50] Sign assemblies --- BlinkStickDotNet/BlinkStickDotNet.csproj | 4 ++-- BlinkStickDotNet/BlinkStickDotNet.snk | Bin 0 -> 596 bytes Components/HidSharp/HidSharp.csproj | 4 ++-- Components/HidSharp/HidSharp.snk | Bin 0 -> 596 bytes Components/LibWinUsb/LibUsbDotNet.csproj | 7 ++++--- 5 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 BlinkStickDotNet/BlinkStickDotNet.snk create mode 100644 Components/HidSharp/HidSharp.snk diff --git a/BlinkStickDotNet/BlinkStickDotNet.csproj b/BlinkStickDotNet/BlinkStickDotNet.csproj index c13d4ca..4e05fde 100644 --- a/BlinkStickDotNet/BlinkStickDotNet.csproj +++ b/BlinkStickDotNet/BlinkStickDotNet.csproj @@ -7,8 +7,8 @@ Library BlinkStickDotNet BlinkStickDotNet - 8.0.30703 - 2.0 + true + BlinkStickDotNet.snk true diff --git a/BlinkStickDotNet/BlinkStickDotNet.snk b/BlinkStickDotNet/BlinkStickDotNet.snk new file mode 100644 index 0000000000000000000000000000000000000000..cb720e75a45db8dc359c669e9b6e01279d0ae362 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098^S2Eas6MRVpB)8A8%1mCS-mH+o?{Bpm zPr|O;&NCeiJ>B=#4ezx(v7L?yY`rjJzu!1@I%L>FZs7_^=z#qf{SEV6Xn0>atT@?4UKMt_q`Se+e>{OkeFX)f2}ZP~a4P>URcs!n*WYINk)R3~wG2v5 zHQ+k^I4a6mT`yw!1Q;V|qy<(laF)XV)8YS(7ko4<7OHNG`Sb=DPNwgaf6Q(IH1Gp- zgw|Zb@BJCEwwps*MAwGuTT_S>^6I`zAeb12;#E5xn}{Oq+2I2g4l_TqoM+R7s^vCi zof@-fIQ`^8Kw|POXjZ~hNnegdZtW)k7Rze(j?Lu7nG}`w!zphhX`f51_!D_k;T1y` z59g;V-~FC{g|%pv>^0R#jtRkiJx%T=tn@9Bm2to~c=lJfhi))RS4oIcn z1~F|Tl 3.5 - 8.0.30703 - 2.0 + true + HidSharp.snk true diff --git a/Components/HidSharp/HidSharp.snk b/Components/HidSharp/HidSharp.snk new file mode 100644 index 0000000000000000000000000000000000000000..c0589c9fd438285b416a19e5b8cc4a503979d293 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098k8xhndVIOoFfQ-x`8)J2N2uU=LKvIRH zbVo+j249Ahj(aAtuHg|YC?wf<6p4fdWY!iYxOK6WJhAR0d^_Mk$gql^)C;8}l?XWZ zf|Y?iPXKmr)j`d_e(DOFXHjeKPmvP&ygVz z#1Vd3dfbv)!|ghRdi!c`lx&%wBm~R-@Eiw6Q7>sug!+(qDx2lT$4RPn-f+Dd()VUs z*0v=in(qcY`KmTBN4ilWlgr&yE^y9ab_hSba$kdRRcc?-i=};`A z?BzQ0zq?V&U+-hJv^nf10wh|EL!ZOs#l|<395Yc_8$gJa$QHGe4f9H4zpEpd$ zT(>VmCVUQL;b0aXW%Q*j>&tGQ)!2(FN_1JRDqjcE`)1DGEV`a`9!On?J9JeFH32.0 - false LibUsbDotNet.snk - 8.0.30703 - 2.0 true @@ -27,6 +24,7 @@ prompt 4 false + true pdbonly @@ -38,6 +36,7 @@ ..\bin\Release\LibUsbDotNet.xml Auto false + true true @@ -49,6 +48,7 @@ prompt 4 false + false bin\x86\Release\ @@ -59,6 +59,7 @@ x86 prompt 4 + false From 2906bc5068a0080c9b507842f1de061a35f4dc48 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Mon, 2 Feb 2015 11:08:32 +0000 Subject: [PATCH 42/50] Improved GetFeature function to ignore successful transfers --- BlinkStickDotNet/BlinkStick.cs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 4f7572a..8beb501 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -784,7 +784,7 @@ public int GetMode() { byte[] data = new byte[2]; data[0] = 4; - stream.GetFeature(data, 0, data.Length); + GetFeature(data); return data[1]; } @@ -1191,6 +1191,36 @@ private void SetFeature(byte[] buffer) } } + private void GetFeature(byte[] buffer) + { + int attempt = 0; + while (attempt < 5) + { + attempt++; + try + { + stream.GetFeature(buffer); + break; + } + catch (System.IO.IOException e) + { + if (e.InnerException is System.ComponentModel.Win32Exception) + { + System.ComponentModel.Win32Exception win32Exception = e.InnerException as System.ComponentModel.Win32Exception; + + if (win32Exception != null && win32Exception.NativeErrorCode == 0) + return; + } + + if (attempt == 5) + throw; + + if (!WaitThread(20)) + return; + } + } + } + public Boolean WaitThread(long milliseconds) { DateTime nextRetry = DateTime.Now + new TimeSpan(TimeSpan.TicksPerMillisecond * milliseconds); From 974bbc47038d4a6d36a7a236bf6e6faaf44c163c Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 20 Mar 2015 12:24:17 +0000 Subject: [PATCH 43/50] Sign LibUsbDotNet --- Components/LibWinUsb/LibUsbDotNet.csproj | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Components/LibWinUsb/LibUsbDotNet.csproj b/Components/LibWinUsb/LibUsbDotNet.csproj index 0c21d13..00567fb 100644 --- a/Components/LibWinUsb/LibUsbDotNet.csproj +++ b/Components/LibWinUsb/LibUsbDotNet.csproj @@ -14,6 +14,9 @@ LibUsbDotNet.snk + 8.0.30703 + 2.0 + true true @@ -24,7 +27,6 @@ prompt 4 false - true pdbonly @@ -36,7 +38,6 @@ ..\bin\Release\LibUsbDotNet.xml Auto false - true true @@ -48,7 +49,6 @@ prompt 4 false - false bin\x86\Release\ @@ -59,7 +59,6 @@ x86 prompt 4 - false From 08792a8158022101f098de3bc99f25e0e7061854 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 20 Mar 2015 12:24:32 +0000 Subject: [PATCH 44/50] IDE upgrades --- BlinkStickDotNet/BlinkStickDotNet.csproj | 2 ++ Components/HidSharp/HidSharp.csproj | 2 ++ 2 files changed, 4 insertions(+) diff --git a/BlinkStickDotNet/BlinkStickDotNet.csproj b/BlinkStickDotNet/BlinkStickDotNet.csproj index 4e05fde..ff4760e 100644 --- a/BlinkStickDotNet/BlinkStickDotNet.csproj +++ b/BlinkStickDotNet/BlinkStickDotNet.csproj @@ -9,6 +9,8 @@ BlinkStickDotNet true BlinkStickDotNet.snk + 8.0.30703 + 2.0 true diff --git a/Components/HidSharp/HidSharp.csproj b/Components/HidSharp/HidSharp.csproj index 1e93579..d4e7b29 100644 --- a/Components/HidSharp/HidSharp.csproj +++ b/Components/HidSharp/HidSharp.csproj @@ -16,6 +16,8 @@ 3.5 true HidSharp.snk + 8.0.30703 + 2.0 true From db8f5a96ad44f14bc6fcef667d881ba1bf504a36 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 20 Mar 2015 12:24:49 +0000 Subject: [PATCH 45/50] Get device type from serial as static function --- BlinkStickDotNet/BlinkStick.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 8beb501..f4796a8 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -169,7 +169,7 @@ public int VersionMinor { public BlinkStickDeviceEnum BlinkStickDevice { get - { + { if (VersionMajor == 1) { return BlinkStickDeviceEnum.BlinkStick; @@ -194,6 +194,26 @@ public BlinkStickDeviceEnum BlinkStickDevice } } + public static BlinkStickDeviceEnum BlinkStickDeviceFromSerial(string serial) + { + int versionMajor = Convert.ToInt32(serial.Substring(serial.Length - 3, 1)); + + if (versionMajor == 1) + { + return BlinkStickDeviceEnum.BlinkStick; + } + else if (versionMajor == 2) + { + return BlinkStickDeviceEnum.BlinkStickPro; + } + else if (versionMajor == 3) + { + return BlinkStickDeviceEnum.BlinkStickSquare; + } + + return BlinkStickDeviceEnum.Unknown; + } + /// /// Gets the name of the manufacturer. /// From c8bf348538dfbbf323094f111b745efc2c0ef8f4 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Fri, 20 Mar 2015 14:50:44 +0000 Subject: [PATCH 46/50] Mode of the device as property --- BlinkStickDotNet/BlinkStick.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index f4796a8..b999a8f 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -279,6 +279,33 @@ public String InfoBlock2 { } public int SetColorDelay { get; set; } + + private int _Mode = -1; + + /// + /// Gets or sets the mode of BlinkStick device. + /// + /// The mode to set or get. + public int Mode + { + get + { + if (_Mode == -1) + { + _Mode = GetMode(); + } + + return _Mode; + } + set + { + if (_Mode != value) + { + _Mode = value; + SetMode((byte)_Mode); + } + } + } #endregion #region Constructor/Destructor From 85314b3419d95e9e0de31261468d30e5317c9927 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 10 Dec 2015 17:51:50 +0000 Subject: [PATCH 47/50] Detect Nano and Flex devices --- BlinkStickDotNet/BlinkStick.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index b999a8f..33b25b9 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -188,6 +188,14 @@ public BlinkStickDeviceEnum BlinkStickDevice { return BlinkStickDeviceEnum.BlinkStickStrip; } + else if (device.ProductVersion == 0x0202) + { + return BlinkStickDeviceEnum.BlinkStickNano; + } + else if (device.ProductVersion == 0x0203) + { + return BlinkStickDeviceEnum.BlinkStickFlex; + } } return BlinkStickDeviceEnum.Unknown; @@ -1327,7 +1335,9 @@ public enum BlinkStickDeviceEnum BlinkStick, BlinkStickPro, BlinkStickStrip, - BlinkStickSquare + BlinkStickSquare, + BlinkStickNano, + BlinkStickFlex } } From 908499ee16501d034f24d4fca1b546b95ab0c305 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Thu, 7 Jan 2016 12:54:23 +0000 Subject: [PATCH 48/50] Ignore Windows API errors when no error code is reported and retry to read the info blocks of the device before failing --- BlinkStickDotNet/BlinkStick.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 33b25b9..45e145a 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -509,7 +509,33 @@ public Boolean GetInfoBlock (byte id, out byte[] data) if (connectedToDriver) { - stream.GetFeature(data, 0, data.Length); + int attempt = 0; + while (attempt < 5) + { + attempt++; + try + { + stream.GetFeature(data, 0, data.Length); + break; + } + catch (System.IO.IOException e) + { + if (e.InnerException is System.ComponentModel.Win32Exception) + { + System.ComponentModel.Win32Exception win32Exception = e.InnerException as System.ComponentModel.Win32Exception; + + if (win32Exception != null && win32Exception.NativeErrorCode == 0) + return true; + } + + if (attempt == 5) + throw; + + if (!WaitThread(20)) + return false; + } + } + return true; } else From ffc55c8d7d1b892481bc8823605fb67d7183fe6a Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Wed, 27 Jan 2016 18:45:30 +0000 Subject: [PATCH 49/50] Automatic versioning of assemblies --- BlinkStickDotNet/AssemblyInfo.cs | 2 +- Components/HidSharp/Properties/AssemblyInfo.cs | 3 +-- Components/LibWinUsb/Properties/AssemblyInfo.cs | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/BlinkStickDotNet/AssemblyInfo.cs b/BlinkStickDotNet/AssemblyInfo.cs index aaa106c..8aa7ebf 100644 --- a/BlinkStickDotNet/AssemblyInfo.cs +++ b/BlinkStickDotNet/AssemblyInfo.cs @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("1.0.3.*")] +[assembly: AssemblyVersion("1.0.*")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. diff --git a/Components/HidSharp/Properties/AssemblyInfo.cs b/Components/HidSharp/Properties/AssemblyInfo.cs index 7362613..97d5072 100644 --- a/Components/HidSharp/Properties/AssemblyInfo.cs +++ b/Components/HidSharp/Properties/AssemblyInfo.cs @@ -7,8 +7,7 @@ [assembly: AssemblyDescription("C# HID wrappers")] [assembly: AssemblyProduct("HidSharp")] [assembly: AssemblyTitle("HidSharp")] -[assembly: AssemblyFileVersion("1.5.1.0")] -[assembly: AssemblyVersion("1.5.1.0")] +[assembly: AssemblyVersion("1.5.*")] [assembly: ComVisible(false)] [assembly: Guid("1b874372-4c6c-4acb-9f4a-906f6738cff9")] diff --git a/Components/LibWinUsb/Properties/AssemblyInfo.cs b/Components/LibWinUsb/Properties/AssemblyInfo.cs index 7aa4bb7..8d430b5 100644 --- a/Components/LibWinUsb/Properties/AssemblyInfo.cs +++ b/Components/LibWinUsb/Properties/AssemblyInfo.cs @@ -57,7 +57,6 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("2.2.8.104")] -[assembly: AssemblyFileVersion("2.2.8.104")] +[assembly: AssemblyVersion("2.2.*")] [assembly: CLSCompliant(true)] [assembly: NeutralResourcesLanguage("en-US")] \ No newline at end of file From a3aa0fba4ecc5fb3ce81a48c625d00ee53853e23 Mon Sep 17 00:00:00 2001 From: Arvydas Juskevicius Date: Sat, 13 Feb 2016 15:41:12 +0000 Subject: [PATCH 50/50] Get and set LED count for Flex --- BlinkStickDotNet/BlinkStick.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/BlinkStickDotNet/BlinkStick.cs b/BlinkStickDotNet/BlinkStick.cs index 45e145a..09c16dd 100644 --- a/BlinkStickDotNet/BlinkStick.cs +++ b/BlinkStickDotNet/BlinkStick.cs @@ -873,6 +873,28 @@ public int GetMode() } #endregion + #region BlinkStick Flex features + public void SetLedCount(byte count) + { + if (connectedToDriver) + { + SetFeature(new byte[2] {0x81, count}); + } + } + + public int GetLedCount() + { + if (connectedToDriver) + { + byte[] data = new byte[2]; + data[0] = 0x81; + stream.GetFeature(data, 0, data.Length); + return data[1]; + } + return -1; + } + #endregion + #region Animation Control public void Stop() {