private void InitData() { var rnd = new Random(); for (int i = 0; i < 5; i++) { Command cmd = null; int cmdType = rnd.Next(3); int length = rnd.Next(1, 15); switch (cmdType) { case 0: cmd = new SetColor(RandColor(rnd)){Channel = 1}; break; case 1: cmd = new FadeColor(1, RandColor(rnd), RandColor(rnd), (short)length); break; case 2: cmd = new BlinkColor(RandColor(rnd), (short)length){Channel = 1}; break; } var frame = new LightPlayer.BL.Frame(TimeSpan.FromSeconds(_commonLength), TimeSpan.FromSeconds(length), cmd); _viewModel.Add(frame); _commonLength += length; } }
public void BlinkColorToBytes() { var expected = new byte[] { 0x7e, 1, (byte)CmdEnum.Blink, 0, 128, 0, 128, 0, 128, 0x00, 137.ToByte(), 0x7f }; var color = Color.FromRgb(128, 128, 128); var cmd = new BlinkColor(color, 137){Channel = 1}; var actual = cmd.GetBytes(); CollectionAssert.AreEqual(expected, actual); }
public Frame CreateFrameByCmdEnum(CmdEnum cmdEnum, TimeSpan startTime) { Frame result = null; Command cmd = null; switch (cmdEnum) { case CmdEnum.SetColor: cmd = new SetColor(Colors.Black){Channel = Command.DefaultChannel}; break; case CmdEnum.Fade: var length = (short)(DefaultLength.TotalSeconds * TicksPerSec); cmd = new FadeColor(Colors.Black, Colors.Black, length){Channel = Command.DefaultChannel}; break; case CmdEnum.Blink: cmd = new BlinkColor(Colors.Black, 50){Channel = Command.DefaultChannel}; break; } if(cmd != null) result = new Frame(startTime, DefaultLength) { Command = cmd }; return result; }