コード例 #1
0
        // HACK/TODO: this is the signature I want, but it's broken until 4.4. (https://github.com/NETMF/netmf-interpreter/issues/87)
        // using arraylist for now
        //public void StartRunningColors(Color[] colors, int[] durations, bool loop)
        /// <summary>
        /// Animates through the listed colors for the specified durations. To use the same duration for all colors,
        /// pass in an array with a length of 1 for `durations`.
        /// </summary>
        /// <param name="colors"></param>
        /// <param name="durations"></param>
        /// <param name="loop"></param>
        ///
        public void StartRunningColors(ArrayList colors, int[] durations, bool loop = true)
        {
            _runningColorConfig = new RunningColorsConfig()
            {
                Colors    = colors,
                Durations = durations,
                Loop      = loop
            };

            if (_isRunning)
            {
                Stop();
                return;
            }

            if (durations.Length != 1 && colors.Count != durations.Length)
            {
                throw new Exception("durations must either have a count of 1, if they're all the same, or colors and durations arrays must be same length.");
            }

            int count = 0;

            if (_animationThread != null)
            {
                while (_animationThread.IsAlive && count < 10)
                {
                    Thread.Sleep(100);
                    count++;
                }
            }

            if (count == 10)
            {
                return;
            }

            _animationThread = new Thread(() =>
            {
                while (_runningColorConfig != null)
                {
                    var nextColors      = _runningColorConfig.Colors;
                    var nextDurations   = _runningColorConfig.Durations;
                    var nextLoop        = _runningColorConfig.Loop;
                    _runningColorConfig = null;

                    _isRunning = true;
                    AnimateColors(nextColors, nextDurations, nextLoop);
                }
            });
            _animationThread.Start();
        }
コード例 #2
0
        /// <summary>
        /// Sets the current color of the LED.
        /// </summary>
        ///
        public void SetColor(Color color, int duration = 0)
        {
            if (duration <= 0)
            {
                _runningColorConfig = null;
                Stop();

                UpdateColor(color);
            }
            else
            {
                StartRunningColors(GetFadeConfig(_color, color, duration));
            }
        }
コード例 #3
0
 private void StartRunningColors(RunningColorsConfig config)
 {
     StartRunningColors(config.Colors, config.Durations, config.Loop);
 }