public Dictionary <string, string> Serialize() { return(new Dictionary <string, string> { { "IPAddress", IpAddress.ToString() }, { "LedNumber", LedNumber.ToString() } }); }
public Dictionary <string, string> Serialize() { return(new Dictionary <string, string> { { "PortName", PortName }, { "LedNumber", LedNumber.ToString(CultureInfo.InvariantCulture) }, { "BaudRate", BaudRate.ToString(CultureInfo.InvariantCulture) } }); }
/// <summary> /// Sends data to device /// </summary> /// <param name="ledValue">Bit-mask of LEDs to be set</param> /// <returns>Operation succeed?</returns> /// <exception cref="InvalidOperationException">Device could not be initialized</exception> public bool SetLed(LedNumber ledValue) { if (_wheel?.IsInitialized != true && !InitDevice()) { throw new InvalidOperationException("SRWheel not initialized."); } var payload = PayloadHelper.PreparePayload(ledValue); return(_wheel.Write(payload)); }
/// <summary> /// Returns complete byte array to write directly to device. /// </summary> /// <param name="ledValue">Bit-mask of LEDs to set</param> /// <returns>Byte array to write to device</returns> public static byte[] PreparePayload(LedNumber ledValue) { var ledBytes = BitConverter.GetBytes((short)ledValue); var payload = new byte[4]; Array.Copy(_commonPayload, payload, 4); payload[2] = ledBytes[0]; payload[3] = ledBytes[1]; return(payload); }
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"); }