/// <summary> /// Sends data to device /// </summary> /// <param name="section">Bit-mask of LED sections to be set</param> /// <returns>Operation succeed?</returns> /// <exception cref="InvalidOperationException">Device could not be initialized</exception> public bool SetSection(LedSection section) { return(SetLed((LedNumber)section)); }
private static void TestSequence() { // TEST #1 WriteLine("Test sequence #1 - light up each single LED"); var allLeds = Enum.GetValues(typeof(LedNumber)).Cast <LedNumber>().ToArray(); foreach (var led in allLeds) { _controller.SetLed(led); WaitShort(); } WaitLong(); _controller.Reset(); WaitLong(); // TEST #2 WriteLine("Test sequence #2 - light up all consecutive LEDs"); LedNumber sum = 0; foreach (var led in allLeds) { sum |= led; _controller.SetLed(sum); WaitShort(); } WaitLong(); _controller.Reset(); WaitLong(); // TEST #3 WriteLine("Test sequence #3 - light up each LED section"); var sections = new [] { LedSection.Red, LedSection.Green, LedSection.Blue }; foreach (var section in sections) { _controller.SetSection(section); WaitLong(); } WaitLong(); _controller.Reset(); WaitLong(); // TEST #4 WriteLine("Test sequence #4 - light up each LED section consecutively"); LedSection cumulativeSections = 0; foreach (var section in sections) { cumulativeSections |= section; _controller.SetSection(cumulativeSections); WaitLong(); } WaitLong(); _controller.Reset(); WaitLong(); // TEST #5 WriteLine("Test sequence #5 - blink all LEDs"); for (int i = 0; i < 10; i++) { _controller.SetSection(LedSection.All); WaitShort(); _controller.Reset(); WaitShort(); } WaitLong(); _controller.Reset(); WaitLong(); // TEST #6 WriteLine("Test sequence #6 - blink all LEDs randomly for 5s"); var stopwatch = Stopwatch.StartNew(); while (stopwatch.ElapsedMilliseconds < 5_000) { var b = new byte[2]; _random.NextBytes(b); var leds = (LedNumber)BitConverter.ToInt16(b, 0); _controller.SetLed(leds); WaitVeryShort(); } _controller.Reset(); WriteLine("All test sequences completed"); }