diff --git a/windows/Blink1Lib/Blink1Lib/Blink1.cs b/windows/Blink1Lib/Blink1Lib/Blink1.cs new file mode 100644 index 00000000..c6c19459 --- /dev/null +++ b/windows/Blink1Lib/Blink1Lib/Blink1.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace Blink1Lib +{ + public class Blink1 + { + static void Main(string[] args) + { + } + + /// + /// Library for communicating with blink(1) USB RGB LEDs. + /// On instantiation, enumerates the USB and records any plugged in blink(1) devices. + /// + public Blink1() + { + enumerate(); + } + + /// + /// Open blink(1) device for use. If multiple blink(1)s, opens the first device. + /// + /// true if device was opened, false if no device available. + public Boolean open() + { + dev = blink1_open(); + if (dev == null) return false; + return true; + } + + /// + /// Open a particular blink(1) device, if there are several + /// + /// integer id (0,1,2...) of device to open + /// true if device was opened, false otherwise + public Boolean openById(int i) + { + dev = blink1_openById(i); + if (dev == null) return false; + return true; + } + + /// + /// Close an open blink(1) device. + /// + public void close() + { + blink1_close(dev); + } + + /// + /// Set blink(1) to RGB color immediately. + /// + /// red component + /// green component + /// blue component + public void setRGB(int r, int g, int b) + { + blink1_setRGB(dev, r, g, b); + } + + /// + /// Fade to an RGB color over a period of milliseconds. + /// + /// milliseconds fade time + /// red component + /// green component + /// blue component + public void fadeToRGB(int millis, int r, int g, int b) + { + blink1_fadeToRGB(dev, millis, r, g, b); + } + + /// + /// FIXME: make more like Blink1.m enumerate + /// + /// + public int enumerate() + { + return blink1_enumerate(); + } + + public string getCachedSerial(int i) + { + //Marshal.PtrToStringAuto + IntPtr wcstr = blink1_getCachedSerial(i); + string result = Marshal.PtrToStringAuto(wcstr); + return result; + } + + // see: http://msdn.microsoft.com/en-us/magazine/cc164123.aspx#S7 + private const string DllName = "blink1-lib.dll"; + private System.IntPtr dev; + + [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] + public static extern System.IntPtr blink1_open(); + + [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] + public static extern System.IntPtr blink1_openById(int i); + + [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] + public static extern void blink1_close( System.IntPtr dev ); + + [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] + public static extern System.IntPtr blink1_setRGB(System.IntPtr dev, int r, int g, int b); + + [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] + public static extern System.IntPtr blink1_fadeToRGB(System.IntPtr dev, int millis, int r, int g, int b); + + [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] + public static extern int blink1_enumerate(); + + [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr blink1_getCachedSerial(int i); + + } +} diff --git a/windows/Blink1Lib/Blink1Lib/Blink1Lib.csproj b/windows/Blink1Lib/Blink1Lib/Blink1Lib.csproj new file mode 100644 index 00000000..3f9fcae4 --- /dev/null +++ b/windows/Blink1Lib/Blink1Lib/Blink1Lib.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {4FE2AE76-BA05-44BC-A04E-5CAF5D7A7D2F} + Library + Properties + Blink1 + Blink1 + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Always + + + + + \ No newline at end of file diff --git a/windows/Blink1Lib/Blink1Lib/Properties/AssemblyInfo.cs b/windows/Blink1Lib/Blink1Lib/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..44d35b63 --- /dev/null +++ b/windows/Blink1Lib/Blink1Lib/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Blink1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Blink1")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b714d0d3-f611-4ee9-8c75-c5adf344dd40")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/windows/Blink1Lib/Blink1Lib/blink1-lib.dll b/windows/Blink1Lib/Blink1Lib/blink1-lib.dll new file mode 100644 index 00000000..6fe0e569 Binary files /dev/null and b/windows/Blink1Lib/Blink1Lib/blink1-lib.dll differ diff --git a/windows/Blink1Lib/Blink1LibDemo.sln b/windows/Blink1Lib/Blink1LibDemo.sln new file mode 100644 index 00000000..72c85b2c --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2012 for Windows Desktop +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blink1LibDemo", "Blink1LibDemo\Blink1LibDemo.csproj", "{F47758A5-F3F8-4B24-AD5A-333E30E5D249}" + ProjectSection(ProjectDependencies) = postProject + {4FE2AE76-BA05-44BC-A04E-5CAF5D7A7D2F} = {4FE2AE76-BA05-44BC-A04E-5CAF5D7A7D2F} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blink1Lib", "Blink1Lib\Blink1Lib.csproj", "{4FE2AE76-BA05-44BC-A04E-5CAF5D7A7D2F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F47758A5-F3F8-4B24-AD5A-333E30E5D249}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F47758A5-F3F8-4B24-AD5A-333E30E5D249}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F47758A5-F3F8-4B24-AD5A-333E30E5D249}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F47758A5-F3F8-4B24-AD5A-333E30E5D249}.Release|Any CPU.Build.0 = Release|Any CPU + {4FE2AE76-BA05-44BC-A04E-5CAF5D7A7D2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4FE2AE76-BA05-44BC-A04E-5CAF5D7A7D2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4FE2AE76-BA05-44BC-A04E-5CAF5D7A7D2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4FE2AE76-BA05-44BC-A04E-5CAF5D7A7D2F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/windows/Blink1Lib/Blink1LibDemo/App.config b/windows/Blink1Lib/Blink1LibDemo/App.config new file mode 100644 index 00000000..fad249e4 --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/windows/Blink1Lib/Blink1LibDemo/Blink1LibDemo.csproj b/windows/Blink1Lib/Blink1LibDemo/Blink1LibDemo.csproj new file mode 100644 index 00000000..fd9e8c55 --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo/Blink1LibDemo.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {F47758A5-F3F8-4B24-AD5A-333E30E5D249} + Exe + Properties + Blink1LibDemo + Blink1LibDemo + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {4fe2ae76-ba05-44bc-a04e-5caf5d7a7d2f} + Blink1Lib + + + + + \ No newline at end of file diff --git a/windows/Blink1Lib/Blink1LibDemo/Program.cs b/windows/Blink1Lib/Blink1LibDemo/Program.cs new file mode 100644 index 00000000..0e83c455 --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo/Program.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Threading; + +using Blink1Lib; + +namespace Blink1LibDemo +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("------------Blink1LibDemo Begin-------------"); + Blink1 blink1 = new Blink1(); + + int count = blink1.enumerate(); + Console.WriteLine("detected " + count + " blink(1 devices"); + + if (count != 0) + { + string serialnum = blink1.getCachedSerial(0); + Console.WriteLine("blink(1) serial number: " + serialnum); + } + + blink1.open(); + + Console.WriteLine("setting white"); + blink1.setRGB(255, 255, 255); + Thread.Sleep(1000); + + Console.WriteLine("fading cyan"); + blink1.fadeToRGB(500, 0, 255, 255); + Thread.Sleep(1000); + + Console.WriteLine("fading red"); + blink1.fadeToRGB(500, 255, 0, 0); + Thread.Sleep(1000); + + Console.WriteLine("fading black"); + blink1.fadeToRGB(1000, 0, 0, 0); + + Console.WriteLine("------------Blink1LibDemo End --------------"); + Thread.Sleep(3000); + + } + + } +} diff --git a/windows/Blink1Lib/Blink1LibDemo/Properties/AssemblyInfo.cs b/windows/Blink1Lib/Blink1LibDemo/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..3b557fb8 --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleApplication1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ConsoleApplication1")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a8e2303d-c644-4399-8394-c3a7a85d6a3c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe new file mode 100644 index 00000000..8c845174 Binary files /dev/null and b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe differ diff --git a/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe.config b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe.config new file mode 100644 index 00000000..fad249e4 --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe.manifest b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe.manifest new file mode 100644 index 00000000..f96b1d6b --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/Blink1LibDemo.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.exe b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.exe new file mode 100644 index 00000000..6fe83a29 Binary files /dev/null and b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.exe differ diff --git a/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.vshost.exe.config b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.vshost.exe.config new file mode 100644 index 00000000..fad249e4 --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.vshost.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.vshost.exe.manifest b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.vshost.exe.manifest new file mode 100644 index 00000000..f96b1d6b --- /dev/null +++ b/windows/Blink1Lib/Blink1LibDemo/bin/Debug/ConsoleApplication1.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/windows/Blink1Lib/README.md b/windows/Blink1Lib/README.md new file mode 100644 index 00000000..57feca23 --- /dev/null +++ b/windows/Blink1Lib/README.md @@ -0,0 +1,5 @@ +Blink1Lib -- .NET C# library for blink(1) USB RGB LED +===================================================== + + +