예제 #1
0
        /// <summary>
        /// Sets the light a custom pattern.
        /// Use an array of Color objects to assign a list of colors the light will cycle through.
        /// </summary>
        /// <param name="colors"> The array of colors that the light will cycle through. </param>
        /// <param name="transition"> The transition type (Gradual, Strobe, Jump). </param>
        /// <param name="speed"> How quick the light will cycle through the pattern, from 0 to 100. </param>
        public async Task SetCustomPatternAsync(Color[] colors, TransitionType transition, byte speed)
        {
            List <byte> data      = new List <byte>();
            bool        firstbyte = true;

            for (int i = 0; i < colors.Length; i++)
            {
                if (firstbyte == true)
                {
                    data.Add(0x51);
                    firstbyte = false;
                }
                else
                {
                    data.Add(0);
                }

                data.AddRange(new byte[] { colors[i].Red, colors[i].Green, colors[i].Blue });
            }

            for (int i = 0; i < 16 - colors.Length; i++)
            {
                data.AddRange(new byte[] { 0, 1, 2, 3 });
            }

            data.AddRange(new byte[] { 0x00, Utilis.SpeedToDelay(speed), Convert.ToByte(transition), 0xff, 0x0f });

            byte[] dataReady = data.ToArray();
            await SendDataAsync(dataReady);

            //Populate field.
            Mode = LightMode.Custom;
        }
예제 #2
0
        /* TODO.
         * /// <summary> Sets the brightness of the light. </summary>
         * /// <param name="brightness"> The level of brightness, from 0 to 100. </param>
         * public async Task SetBrightnessAsync(byte brightness)
         * {
         *  if (brightness > 100) throw new MagicHomeException("Brightness value cannot be more than 100");
         *  if (Mode == LightMode.Color)
         *      await SetColorAsync(
         *          Convert.ToByte(Color.Red * (brightness / Brightness)),
         *          Convert.ToByte(Color.Green * (brightness / Brightness)),
         *          Convert.ToByte(Color.Blue * (brightness / Brightness))
         *          );
         *  else if (Mode == LightMode.WarmWhite)
         *      await SetWarmWhiteAsync(Convert.ToByte(WarmWhite * brightness / Brightness));
         *  UpdateBrightness();
         * }*/

        /// <summary> Sets a preset pattern. </summary>
        /// <param name="speed"> The speed of the pattern from 0 to 100. </param>
        public async Task SetPresetPatternAsync(PresetPattern pattern, byte speed)
        {
            byte delay = Utilis.SpeedToDelay(speed);

            await SendDataAsync(new byte[] { 0x61, Convert.ToByte(pattern), delay, 0x0f });

            //Populate field.
            Mode = LightMode.Preset;
        }