コード例 #1
0
 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;
     }
 }
コード例 #2
0
        public void SetColorToBytes()
        {
            var expected = new byte[] {0x7e, 1, (byte)CmdEnum.SetColor, 0, 128, 0, 128, 0, 128, 0x7f};

            var color = Color.FromRgb(128, 128, 128);
            var cmd = new SetColor(color){Channel = 1};

            var actual = cmd.GetBytes();
            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #3
0
        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;
        }