/// <summary> /// Pass 5: saving new random presets /// </summary> private static void TestCase5() { Console.WriteLine("#######################################"); Console.WriteLine("## Pass 5: saving new random presets ##"); Console.WriteLine("#######################################"); Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 5: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = new Blink1Preset(Convert.ToUInt16(1000 + (position * 10)), GetRandomRgbColor()); Console.WriteLine( "Pass 5: Position:{0,3}, Millisecond:{1,5}, Red:{2,4}, Green:{3,4}, Blue:{4,4}, Hex: #{2:X02}{3:X02}{4:X02}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); blink1.SavePreset(blink1Preset, position); } Console.WriteLine("Pass 5: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); }
/// <summary> /// Sets the led status (just set, no blink) /// </summary> /// <param name="pValue"></param> private void SetStatus(byte pValue) { try { Console.WriteLine(string.Format("Send arbitrary data {0:X2} and answer is ", pValue) + TricolorUsbSignal.SendRawBuffer(new byte[] { Constants.PACKET_ID, pValue })); if (mLastSendCharWasError) { DoLogLine("SUCCESS while sending data to Blink. Reconnected?"); this.mSystrayIcon.ShowBalloonTip(2000, "Tricolor USB Signal", "Connected to USB signal.", ToolTipIcon.Info); } mLastSendCharWasError = false; } catch (Exception ex) { if (!mLastSendCharWasError) { DoLogLine("ERROR while sending data to Blink. Disconnected?"); this.mSystrayIcon.ShowBalloonTip(2000, "Tricolor USB Signal", "Connection lost to USB signal!", ToolTipIcon.Error); try { TricolorUsbSignal.Close(); } catch (Exception ex2) { DoLogLine("ERROR while closing connection to Blink. Ignore and release."); Console.WriteLine("ERROR SendChar() - Close(): " + ex.Message); } finally { mTricolorUsbSignal.Dispose(); mTricolorUsbSignal = null; } } mLastSendCharWasError = true; Console.WriteLine("ERROR SendChar(): " + ex.Message); } }
/// <summary> /// Pass 3: reading the current presets /// </summary> private static void TestCase3() { Console.WriteLine("#########################################"); Console.WriteLine("## Pass 3: reading the current presets ##"); Console.WriteLine("#########################################"); // Note, any dealing with presets is done asynchronously. Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 3: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = blink1.ReadPreset(position); Console.WriteLine( "Pass 3: Position:{0,3}, Millisecond:{1,5}, Red:{2,4}, Green:{3,4}, Blue:{4,4}, Hex: #{2:X02}{3:X02}{4:X02}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); } Console.WriteLine("Pass 3: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); }
/// <summary> /// Pass 1: work on the first Blink(1) device found, synchronously /// </summary> private static void TestCase1() { Console.WriteLine("####################################################################"); Console.WriteLine("## Pass 1: work on the first Blink(1) device found, synchronously ##"); Console.WriteLine("####################################################################"); // Note, the first past goes so fast, Blink(1) does not have the time to, well, blink. Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 1: Opening the first Blink(1) found."); blink1.Open(); int versionNumber = blink1.GetVersion(); Console.WriteLine("Pass 1: Blink(1) device is at version: {0}.", versionNumber.ToString()); Console.WriteLine("Pass 1: Set Blink(1) to be RED."); blink1.SetColor(255, 0, 0); Console.WriteLine("Pass 1: Set Blink(1) to fade to BLUE over 10 seconds."); blink1.FadeToColor(10000, 0, 0, 255, false); Thread.Sleep(10000); Console.WriteLine("Pass 1: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); }
// /blink1/fadeToRGB -- Send fadeToRGB command to blink(1) with hex color & fade time static string Ublink1FadeToRGB(HttpRequest request, Blink1Server blink1Server) { // FIXME: stop pattern player //NameValueCollection query = request.Query; string rgbstr = request.Query.Get("rgb"); string timestr = request.Query.Get("time"); Log("rgb: " + rgbstr); if (rgbstr == null) { rgbstr = "#000000"; } if (timestr == null) { timestr = "0.1"; } Color colr = ColorTranslator.FromHtml(rgbstr); float secs = float.Parse(timestr, CultureInfo.InvariantCulture); blink1Server.fadeToRGB(secs, colr); Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("status", "fadeToRGB"); result.Add("rgb", Blink1.colorToHexCode(colr)); result.Add("time", secs.ToString("F2", CultureInfo.InvariantCulture)); return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings)); }
/// <summary> /// Pass 2: work on the last Blink(1) device found, asynchronously /// </summary> private static void TestCase2() { Console.WriteLine("####################################################################"); Console.WriteLine("## Pass 2: work on the last Blink(1) device found, asynchronously ##"); Console.WriteLine("####################################################################"); List <string> devicePaths = Blink1Info.GetDevicePath(); Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 2: Opening the last Blink(1) found via its HID path."); blink1.Open(devicePaths.Last()); Console.WriteLine("Pass 2: Set Blink(1) to blink 8 times PURPLE."); blink1.Blink(8, 500, 200, 128, 0, 128); Console.WriteLine("Pass 2: Set Blink(1) to be RED, using RGB(255, 0, 0)."); blink1.SetColor(new Rgb(255, 0, 0)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be GREEN, using CYMK(100, 0, 100, 0)."); blink1.SetColor(new Cmyk(100, 0, 100, 0)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be BLUE, using HSB(240, 100, 100)."); blink1.SetColor(new Hsb(240, 100, 100)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be YELLOW, using HSL(60, 100, 50)."); blink1.SetColor(new Hsl(60, 100, 50)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be CYAN, using HtmlHexadecimal(\"#00FFFF\")."); blink1.SetColor(new HtmlHexadecimal("#00FFFF")); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be MAGENTA, using HtmlColorName and HtmlHexadecimal."); blink1.SetColor(new HtmlHexadecimal(HtmlColorName.Magenta)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be BLACK."); blink1.SetColor(0, 0, 0); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to fade to ORANGE over 10 seconds."); blink1.FadeToColor(10000, 251, 61, 4, true); Console.WriteLine("Pass 2: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Sets the color. /// </summary> /// <param name="iR">The i r.</param> /// <param name="iG">The i g.</param> /// <param name="iB">The i b.</param> private static void SetColor(int iR, int iG, int iB) { using (Blink1 blink = new Blink1()) { blink.Open(); blink.SetColor(( ushort )iR, ( ushort )iG, ( ushort )iB); } }
/// <summary> /// Creates a new instance of the blink-control starting the first suitable device found. /// </summary> /// <param name="terminationRequested">Function indicating whether termination of all processing was requested.</param> /// <param name="botState">Contains information about the current state of the robot.</param> /// <param name="logger">The logger to output messages.</param> public BlinkControl(RobotState botState, Func <bool> terminationRequested, Action <string> logger) { // Populate color dictionaries _carryingPodColors = new Dictionary <bool, IColorProcessor>() { { false, new Hsb(0, 0, 0) }, { true, new Hsb(240, 100, 100) } }; _statusColors = new Dictionary <RobotStatus, IColorProcessor>() { { RobotStatus.Idle, new Hsb(0, 0, 0) }, { RobotStatus.Moving, new Hsb(120, 100, 100) }, { RobotStatus.MovingBackwards, new Hsb(120, 100, 100) }, { RobotStatus.Pickup, new Hsb(0, 100, 100) }, { RobotStatus.Setdown, new Hsb(50, 100, 100) }, { RobotStatus.GetItem, new Hsb(330, 100, 100) }, { RobotStatus.PutItem, new Hsb(282, 100, 100) }, { RobotStatus.Rest, new Hsb(240, 100, 100) }, }; _combinedColors = new MultiKeyDictionary <RobotStatus, bool, IColorProcessor>(); _combinedColors[RobotStatus.Idle, false] = new Hsb(0, 0, 0); _combinedColors[RobotStatus.Idle, true] = new Hsb(0, 0, 0); _combinedColors[RobotStatus.Moving, false] = new Hsb(120, 100, 100); _combinedColors[RobotStatus.Moving, true] = new Hsb(240, 100, 100); _combinedColors[RobotStatus.MovingBackwards, false] = new Hsb(120, 100, 100); _combinedColors[RobotStatus.MovingBackwards, true] = new Hsb(240, 100, 100); _combinedColors[RobotStatus.Pickup, false] = new Hsb(0, 100, 100); _combinedColors[RobotStatus.Pickup, true] = new Hsb(0, 100, 100); _combinedColors[RobotStatus.Setdown, false] = new Hsb(50, 100, 100); _combinedColors[RobotStatus.Setdown, true] = new Hsb(50, 100, 100); _combinedColors[RobotStatus.GetItem, false] = new Hsb(330, 100, 100); _combinedColors[RobotStatus.GetItem, true] = new Hsb(330, 100, 100); _combinedColors[RobotStatus.PutItem, false] = new Hsb(282, 100, 100); _combinedColors[RobotStatus.PutItem, true] = new Hsb(282, 100, 100); _combinedColors[RobotStatus.Rest, false] = new Hsb(240, 100, 100); _combinedColors[RobotStatus.Rest, true] = new Hsb(240, 100, 100); // Init and look for available devices _botState = botState; _terminationRequested = terminationRequested; _logger = logger; IEnumerable <HidDevice> availableBlink1s = HidDevices.Enumerate(Blink1Constant.VendorId, Blink1Constant.ProductId); _blink1 = new Blink1(); if (availableBlink1s.Any()) { // Initialize and start first blink(1) device found Log("Starting blink(1) device ..."); _blink1.Open(); } else { // Notify no blink(1) found Log("No blink(1) device found"); } // Start the color manager ThreadPool.QueueUserWorkItem(new WaitCallback(Run)); }
/// <summary> /// Offs the LED. /// </summary> public static void Off() { using (Blink1 blink = new Blink1()) { blink.Open(); blink.Close(); } }
public Blink1Controller() { var blink1 = Blink1Connector.Scan()?.FirstOrDefault(); if (blink1 == null) { throw new InvalidOperationException("No Blink(1) device connected."); } Blink1 = (Blink1)blink1; }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Shows the specified number of time. /// </summary> /// <param name="numberOfTime">The number of time.</param> /// <param name="numberOfMillisecondOn">The number of millisecond on.</param> /// <param name="numberOfMillisecondOff">The number of millisecond off.</param> /// <param name="c">The c.</param> public static void Show(ushort numberOfTime, ushort numberOfMillisecondOn, ushort numberOfMillisecondOff, Color c) { using (Blink1 blink = new Blink1()) { blink.Open(); blink.Blink(numberOfTime, numberOfMillisecondOn, numberOfMillisecondOff, c.R, c.G, c.B); blink.Close(); } }
// // direct blink(1) control url handling // // /blink1/id -- Display blink1_id and blink1 serial numbers (if any) static string Ublink1Id(HttpRequest request, Blink1Server blink1Server) { Blink1 blink1 = blink1Server.blink1; Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("blink1_id", blink1.blink1Id); List <string> serialnums = new List <string>(); for (int i = 0; i < blink1.getCachedCount(); i++) // FIXME: surely a smarter way to do this { serialnums.Add(blink1.getCachedSerial(i)); } result.Add("blink1_serialnums", serialnums); result.Add("status", "blink1 id"); return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings)); }
//public void StartupLights() //{ // blink1 = new Blink1(); // blink1.Open(); // blink1.SetColor(150, 0, 0); // Red // blink1.FadeToColor(500, 0, 150, 0, true); // green // blink1.FadeToColor(500, 0, 0, 150, true); // blue // blink1.FadeToColor(500, 150, 0, 0, true); // red // blink1.FadeToColor(500, 0, 150, 0, true); // green // blink1.FadeToColor(500, 0, 0, 150, true); // blue // blink1.SetColor(0, 30, 0); // blink1.Close(false); //} public void RunChecks() { _blink1 = new Blink1(); _blink1.Open(); Color color = new Color(); int numberOfFailedTests = CheckAllStatusCakeTestsOK(); if (numberOfFailedTests == 0) { // OK color = Color.FromArgb(0, 50, 0); Log("No failed tests"); // If there are no error conditions, then check SSL expirations: var numberOfSslFails = CheckSSLExpirations(_settings.CertificateExpirationDays); Log("SSL fails: " + numberOfSslFails); if (numberOfSslFails > 0) { color = ColorHelper.ChangeBrightness(Color.DarkOrange, -0.6F); } } else { // NOT ok Log("Test fails: " + numberOfFailedTests); int brightness = numberOfFailedTests * 50; if (brightness >= MAX_BRIGHTNESS) { brightness = MAX_BRIGHTNESS; } color = Color.FromArgb(brightness, 0, 0); } // Don't update LED unless color has changed. if (lastColor != color) { Log($"Changing LED color to: {color.R},{color.G},{color.B}"); _blink1.SetColor(color.R, color.G, color.B); } _blink1.Close(false); _blink1 = null; }
/// <summary> /// Pass 8: work with the inactivity mode /// </summary> private static void TestCase8() { Console.WriteLine("###########################################"); Console.WriteLine("## Pass 8: work with the inactivity mode ##"); Console.WriteLine("###########################################"); Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 8: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 8: Writing inactivity mode presets"); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Red)), 0); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 1); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.White)), 2); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 3); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Green)), 4); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 5); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Blue)), 6); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 7); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Magenta)), 8); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 9); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Cyan)), 10); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 11); Console.WriteLine("Pass 8: Activating the inactivity mode for 10 seconds of inactivity."); blink1.ActivateInactivityMode(5000); Console.WriteLine("Pass 8: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine("Pass 8: After the inactivity period, Blink(1) will play its presets."); Thread.Sleep(15000); Console.WriteLine("Pass 8: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 8: Deactivating the inactivity."); blink1.DeactivateInactivityMode(); Console.WriteLine("Pass 8: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Tests this instance. /// </summary> public static void Test() { using (Blink1 blink = new Blink1()) { blink.Open(); void SetColor(Color c) { blink.SetColor(c.R, c.G, c.B); Thread.Sleep(1000); } SetColor(Colors.Red); SetColor(Colors.Green); SetColor(Colors.Blue); blink.Close(); } }
private bool TryToConnect(out Blink1 blink1) { blink1 = new Blink1(); List <string> devicePaths = Blink1Info.GetDevicePath(); if (devicePaths.Count == 0) { MessageBox.Show("Connection not possible - no device found!", "Connection Error", MessageBoxButton.OK, MessageBoxImage.Error); blink1 = null; return(false); } blink1.Open(devicePaths.First()); if (!blink1.IsConnected) { blink1 = null; } return(blink1.IsConnected); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Fades the white to black. /// </summary> public static void FadeWhiteToBlack() { using (Blink1 blink = new Blink1()) { blink.Open(); void SetColor(int r, int g, int b) { blink.SetColor(( ushort )r, ( ushort )g, ( ushort )b); Thread.Sleep(20); } for (int iCounter = 255; iCounter > 0; iCounter--) { SetColor(iCounter, iCounter, iCounter); } blink.Close(); } }
/// <summary> /// Pass 7: playing the new random presets /// </summary> private static void TestCase7() { Console.WriteLine("############################################"); Console.WriteLine("## Pass 7: playing the new random presets ##"); Console.WriteLine("############################################"); Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 7: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 7: Playing the presets for 20 seconds..."); blink1.PlayPreset(0); Thread.Sleep(20000); Console.WriteLine("Pass 7: Stopping playing presets."); blink1.StopPlayingPreset(); Console.WriteLine("Pass 7: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); }
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(2000); Console.WriteLine("fading cyan"); blink1.fadeToRGB(1000, 0, 255, 255); Thread.Sleep(2000); Console.WriteLine("fading red"); blink1.fadeToRGB(1000, 255, 0, 0); Thread.Sleep(2000); Console.WriteLine("fading black"); blink1.fadeToRGB(1500, 0, 0, 0); Thread.Sleep(2000); Console.WriteLine("------------Blink1LibDemo End --------------"); Thread.Sleep(2000); }
/// <summary> /// The main program. /// </summary> /// <param name="args"> /// The arguments. /// </param> public static void Main(string[] args) { Console.WriteLine("####################################################################"); Console.WriteLine("## Pass 1: work on the first Blink(1) device found, synchronously ##"); Console.WriteLine("####################################################################"); // Note, the first past goes so fast, Blink(1) does not have the time to, well, blink. Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 1: Opening the first Blink(1) found."); blink1.Open(); int versionNumber = blink1.GetVersion(); Console.WriteLine("Pass 1: Blink(1) device is at version: {0}.", versionNumber.ToString()); Console.WriteLine("Pass 1: Set Blink(1) to be RED."); blink1.SetColor(255, 0, 0); Console.WriteLine("Pass 1: Set Blink(1) to fade to BLUE over 10 seconds."); blink1.FadeToColor(3000, 0, 0, 255, false); Console.WriteLine("Pass 1: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("####################################################################"); Console.WriteLine("## Pass 2: work on the last Blink(1) device found, asynchronously ##"); Console.WriteLine("####################################################################"); List<string> devicePaths = Blink1Info.GetDevicePath(); blink1 = new Blink1(); Console.WriteLine("Pass 2: Opening the last Blink(1) found via its HID path."); blink1.Open(devicePaths.Last()); Console.WriteLine("Pass 2: Set Blink(1) to blink 8 times PURPLE."); blink1.Blink(8, 500, 200, 128, 0, 128); Console.WriteLine("Pass 2: Set Blink(1) to be RED, using RGB(255, 0, 0)."); blink1.SetColor(new Rgb(255, 0, 0)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be GREEN, using CYMK(100, 0, 100, 0)."); blink1.SetColor(new Cmyk(100, 0, 100, 0)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be BLUE, using HSB(240, 100, 100)."); blink1.SetColor(new Hsb(240, 100, 100)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be YELLOW, using HSL(60, 100, 50)."); blink1.SetColor(new Hsl(60, 100, 50)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be CYAN, using HtmlHexadecimal(\"#00FFFF\")."); blink1.SetColor(new HtmlHexadecimal("#00FFFF")); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be MAGENTA, using HtmlColorName and HtmlHexadecimal."); blink1.SetColor(new HtmlHexadecimal(HtmlColorName.Magenta)); Thread.Sleep(1000); Console.WriteLine("Pass 1: Set Blink(1) to be BLACK."); blink1.SetColor(0, 0, 0); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to fade to ORANGE over 10 seconds."); blink1.FadeToColor(10000, 251, 61, 4, true); Console.WriteLine("Pass 2: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("#########################################"); Console.WriteLine("## Pass 3: reading the current presets ##"); Console.WriteLine("#########################################"); // Note, any dealing with presets is done asynchronously. blink1 = new Blink1(); Console.WriteLine("Pass 3: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = blink1.ReadPreset(position); Console.WriteLine( "Pass 3: Position:{0}, Millisecond:{1}, Red:{2}, Green:{3}, Blue:{4}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); } Console.WriteLine("Pass 3: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("#########################################"); Console.WriteLine("## Pass 4: playing the current presets ##"); Console.WriteLine("#########################################"); blink1 = new Blink1(); Console.WriteLine("Pass 4: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 4: Playing the presets for 20 seconds..."); blink1.PlayPreset(0); Thread.Sleep(20000); Console.WriteLine("Pass 4: Stopping playing presets."); blink1.StopPlayingPreset(); Console.WriteLine("Pass 4: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("#######################################"); Console.WriteLine("## Pass 5: saving new random presets ##"); Console.WriteLine("#######################################"); blink1 = new Blink1(); Console.WriteLine("Pass 5: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = new Blink1Preset(Convert.ToUInt16(1000 + (position * 10)), GetRandomRgbColor()); Console.WriteLine( "Pass 5: Position:{0}, Millisecond:{1}, Red:{2}, Green:{3}, Blue:{4}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); blink1.SavePreset(blink1Preset, position); } Console.WriteLine("Pass 5: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("############################################"); Console.WriteLine("## Pass 6: reading the new random presets ##"); Console.WriteLine("############################################"); blink1 = new Blink1(); Console.WriteLine("Pass 6: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = blink1.ReadPreset(position); Console.WriteLine( "Pass 6: Position:{0}, Millisecond:{1}, Red:{2}, Green:{3}, Blue:{4}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); } Console.WriteLine("Pass 6: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("############################################"); Console.WriteLine("## Pass 7: playing the new random presets ##"); Console.WriteLine("############################################"); blink1 = new Blink1(); Console.WriteLine("Pass 7: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 7: Playing the presets for 20 seconds..."); blink1.PlayPreset(0); Thread.Sleep(20000); Console.WriteLine("Pass 7: Stopping playing presets."); blink1.StopPlayingPreset(); Console.WriteLine("Pass 7: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("###########################################"); Console.WriteLine("## Pass 8: work with the inactivity mode ##"); Console.WriteLine("###########################################"); blink1 = new Blink1(); Console.WriteLine("Pass 8: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 8: Writing inactivity mode presets"); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Red)), 0); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 1); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.White)), 2); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 3); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Green)), 4); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 5); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Blue)), 6); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 7); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Magenta)), 8); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 9); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Cyan)), 10); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 11); Console.WriteLine("Pass 8: Activating the inactivity mode for 10 seconds of inactivity."); blink1.ActivateInactivityMode(5000); Console.WriteLine("Pass 8: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine("Pass 8: After the inactivity period, Blink(1) will play its presets."); Thread.Sleep(15000); Console.WriteLine("Pass 8: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 8: Deactivating the inactivity."); blink1.DeactivateInactivityMode(); Console.WriteLine("Pass 8: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("We're done with the demo, press any key to stop the program."); Console.ReadKey(); }
/// <summary> /// Pass 2: work on the last Blink(1) device found, asynchronously /// </summary> private static void TestCase2() { Console.WriteLine("####################################################################"); Console.WriteLine("## Pass 2: work on the last Blink(1) device found, asynchronously ##"); Console.WriteLine("####################################################################"); List<string> devicePaths = Blink1Info.GetDevicePath(); Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 2: Opening the last Blink(1) found via its HID path."); blink1.Open(devicePaths.Last()); Console.WriteLine("Pass 2: Set Blink(1) to blink 8 times PURPLE."); blink1.Blink(8, 500, 200, 128, 0, 128); Console.WriteLine("Pass 2: Set Blink(1) to be RED, using RGB(255, 0, 0)."); blink1.SetColor(new Rgb(255, 0, 0)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be GREEN, using CYMK(100, 0, 100, 0)."); blink1.SetColor(new Cmyk(100, 0, 100, 0)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be BLUE, using HSB(240, 100, 100)."); blink1.SetColor(new Hsb(240, 100, 100)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be YELLOW, using HSL(60, 100, 50)."); blink1.SetColor(new Hsl(60, 100, 50)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be CYAN, using HtmlHexadecimal(\"#00FFFF\")."); blink1.SetColor(new HtmlHexadecimal("#00FFFF")); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be MAGENTA, using HtmlColorName and HtmlHexadecimal."); blink1.SetColor(new HtmlHexadecimal(HtmlColorName.Magenta)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be BLACK."); blink1.SetColor(0, 0, 0); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to fade to ORANGE over 10 seconds."); blink1.FadeToColor(10000, 251, 61, 4, true); Console.WriteLine("Pass 2: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); }
public override void SetGreen() { Blink1.Fade(Color.Green, TimeSpan.FromSeconds(1)); }
/// <summary> /// Pass 6: reading the new random presets /// </summary> private static void TestCase6() { Console.WriteLine("############################################"); Console.WriteLine("## Pass 6: reading the new random presets ##"); Console.WriteLine("############################################"); Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 6: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = blink1.ReadPreset(position); Console.WriteLine( "Pass 6: Position:{0,3}, Millisecond:{1,5}, Red:{2,4}, Green:{3,4}, Blue:{4,4}, Hex: #{2:X02}{3:X02}{4:X02}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); } Console.WriteLine("Pass 6: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); }
public override void SetOrange() { Blink1.Fade(Color.Orange, TimeSpan.FromSeconds(1)); }
public override void SetRed() { Blink1.Fade(Color.Red, TimeSpan.FromSeconds(1)); }
/// <summary> /// The main program. /// </summary> /// <param name="args"> /// The arguments. /// </param> public static void Main(string[] args) { Console.WriteLine("####################################################################"); Console.WriteLine("## Pass 1: work on the first Blink(1) device found, synchronously ##"); Console.WriteLine("####################################################################"); // Note, the first past goes so fast, Blink(1) does not have the time to, well, blink. Blink1 blink1 = new Blink1(); Console.WriteLine("Pass 1: Opening the first Blink(1) found."); blink1.Open(); int versionNumber = blink1.GetVersion(); Console.WriteLine("Pass 1: Blink(1) device is at version: {0}.", versionNumber.ToString()); Console.WriteLine("Pass 1: Set Blink(1) to be RED."); blink1.SetColor(255, 0, 0); Console.WriteLine("Pass 1: Set Blink(1) to fade to BLUE over 10 seconds."); blink1.FadeToColor(3000, 0, 0, 255, false); Console.WriteLine("Pass 1: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("####################################################################"); Console.WriteLine("## Pass 2: work on the last Blink(1) device found, asynchronously ##"); Console.WriteLine("####################################################################"); List <string> devicePaths = Blink1Info.GetDevicePath(); blink1 = new Blink1(); Console.WriteLine("Pass 2: Opening the last Blink(1) found via its HID path."); blink1.Open(devicePaths.Last()); Console.WriteLine("Pass 2: Set Blink(1) to blink 8 times PURPLE."); blink1.Blink(8, 500, 200, 128, 0, 128); Console.WriteLine("Pass 2: Set Blink(1) to be RED, using RGB(255, 0, 0)."); blink1.SetColor(new Rgb(255, 0, 0)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be GREEN, using CYMK(100, 0, 100, 0)."); blink1.SetColor(new Cmyk(100, 0, 100, 0)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be BLUE, using HSB(240, 100, 100)."); blink1.SetColor(new Hsb(240, 100, 100)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be YELLOW, using HSL(60, 100, 50)."); blink1.SetColor(new Hsl(60, 100, 50)); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be CYAN, using HtmlHexadecimal(\"#00FFFF\")."); blink1.SetColor(new HtmlHexadecimal("#00FFFF")); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to be MAGENTA, using HtmlColorName and HtmlHexadecimal."); blink1.SetColor(new HtmlHexadecimal(HtmlColorName.Magenta)); Thread.Sleep(1000); Console.WriteLine("Pass 1: Set Blink(1) to be BLACK."); blink1.SetColor(0, 0, 0); Thread.Sleep(1000); Console.WriteLine("Pass 2: Set Blink(1) to fade to ORANGE over 10 seconds."); blink1.FadeToColor(10000, 251, 61, 4, true); Console.WriteLine("Pass 2: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("#########################################"); Console.WriteLine("## Pass 3: reading the current presets ##"); Console.WriteLine("#########################################"); // Note, any dealing with presets is done asynchronously. blink1 = new Blink1(); Console.WriteLine("Pass 3: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = blink1.ReadPreset(position); Console.WriteLine( "Pass 3: Position:{0}, Millisecond:{1}, Red:{2}, Green:{3}, Blue:{4}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); } Console.WriteLine("Pass 3: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("#########################################"); Console.WriteLine("## Pass 4: playing the current presets ##"); Console.WriteLine("#########################################"); blink1 = new Blink1(); Console.WriteLine("Pass 4: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 4: Playing the presets for 20 seconds..."); blink1.PlayPreset(0); Thread.Sleep(20000); Console.WriteLine("Pass 4: Stopping playing presets."); blink1.StopPlayingPreset(); Console.WriteLine("Pass 4: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("#######################################"); Console.WriteLine("## Pass 5: saving new random presets ##"); Console.WriteLine("#######################################"); blink1 = new Blink1(); Console.WriteLine("Pass 5: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = new Blink1Preset(Convert.ToUInt16(1000 + (position * 10)), GetRandomRgbColor()); Console.WriteLine( "Pass 5: Position:{0}, Millisecond:{1}, Red:{2}, Green:{3}, Blue:{4}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); blink1.SavePreset(blink1Preset, position); } Console.WriteLine("Pass 5: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("############################################"); Console.WriteLine("## Pass 6: reading the new random presets ##"); Console.WriteLine("############################################"); blink1 = new Blink1(); Console.WriteLine("Pass 6: Opening the first Blink(1) found."); blink1.Open(); for (ushort position = 0; position < Blink1Constant.NumberOfPreset; position++) { Blink1Preset blink1Preset = blink1.ReadPreset(position); Console.WriteLine( "Pass 6: Position:{0}, Millisecond:{1}, Red:{2}, Green:{3}, Blue:{4}", position, blink1Preset.Millisecond, blink1Preset.Rgb.Red, blink1Preset.Rgb.Green, blink1Preset.Rgb.Blue); } Console.WriteLine("Pass 6: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("############################################"); Console.WriteLine("## Pass 7: playing the new random presets ##"); Console.WriteLine("############################################"); blink1 = new Blink1(); Console.WriteLine("Pass 7: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 7: Playing the presets for 20 seconds..."); blink1.PlayPreset(0); Thread.Sleep(20000); Console.WriteLine("Pass 7: Stopping playing presets."); blink1.StopPlayingPreset(); Console.WriteLine("Pass 7: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("###########################################"); Console.WriteLine("## Pass 8: work with the inactivity mode ##"); Console.WriteLine("###########################################"); blink1 = new Blink1(); Console.WriteLine("Pass 8: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 8: Writing inactivity mode presets"); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Red)), 0); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 1); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.White)), 2); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 3); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Green)), 4); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 5); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Blue)), 6); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 7); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Magenta)), 8); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 9); blink1.SavePreset(new Blink1Preset(500, new HtmlHexadecimal(HtmlColorName.Cyan)), 10); blink1.SavePreset(new Blink1Preset(250, new HtmlHexadecimal(HtmlColorName.Black)), 11); Console.WriteLine("Pass 8: Activating the inactivity mode for 10 seconds of inactivity."); blink1.ActivateInactivityMode(5000); Console.WriteLine("Pass 8: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine("Pass 8: After the inactivity period, Blink(1) will play its presets."); Thread.Sleep(15000); Console.WriteLine("Pass 8: Opening the first Blink(1) found."); blink1.Open(); Console.WriteLine("Pass 8: Deactivating the inactivity."); blink1.DeactivateInactivityMode(); Console.WriteLine("Pass 8: Closing Blink(1) connection."); blink1.Close(); Console.WriteLine(Environment.NewLine); Console.WriteLine("We're done with the demo, press any key to stop the program."); Console.ReadKey(); }