private bool Animate(MCP41X1_Base.ADDRESS pot, AnimationDsl animationType, int wait, int count = 1)
        {
            var steps = new List<int>();

            if (animationType == AnimationDsl.FadeInFadeOut) { 

                Animate(pot, AnimationDsl.FadeIn, wait);
                Animate(pot, AnimationDsl.Pause, wait);
                Animate(pot, AnimationDsl.FadeOut, wait);
            }
            else if (animationType == AnimationDsl.FadeIn) { 

                steps = _stepsDefinition[pot];
            }
            else if (animationType == AnimationDsl.FadeOut) { 

                steps = new List<int>(_stepsDefinition[pot]);
                steps.Reverse();
            }
            else if (animationType == AnimationDsl.Pause) { 
                
                TimePeriod.Sleep(wait*2);
                return true;
            }
            else if (animationType == AnimationDsl.Off) { 

                this.Set(0, pot);
                return true;
            }
            else if (animationType == AnimationDsl.Max) { 

                steps = _stepsDefinition[pot];
                this.Set(steps[steps.Count-1], pot);
                return true;
            }
            else if (animationType == AnimationDsl.HalfMax) { 

                steps = _stepsDefinition[pot];
                this.Set(steps[steps.Count/2], pot);
                return true;
            }
            else if (animationType == AnimationDsl.Blink) { 

                MCP41X1_Base.ADDRESS Led1 = pot;
                MCP41X1_Base.ADDRESS Led2 = Led1 == Red ? Green : Red;

                for (var c = 0; c < count; c++) { 
                    Animate(Led1, AnimationDsl.Off, wait);
                    TimePeriod.Sleep(wait);
                    Animate(Led1, AnimationDsl.Max, wait);
                    TimePeriod.Sleep(wait);
                }
                return true;
            }
            else if (animationType == AnimationDsl.BlinkWithOtherColor) { 

                MCP41X1_Base.ADDRESS Led1 = pot;
                MCP41X1_Base.ADDRESS Led2 = Led1 == Red ? Green : Red;

                for (var c = 0; c < count; c++) { 
                    Animate(Led1, AnimationDsl.Off, wait);
                    Animate(Led2, AnimationDsl.Max, wait);
                    TimePeriod.Sleep(wait);
                    Animate(Led2, AnimationDsl.Off, wait);
                    Animate(Led1, AnimationDsl.Max, wait);
                    TimePeriod.Sleep(wait);
                }
                return true;
            }
            else throw new ArgumentException();

            foreach (var s in steps)
            {
                if (!this.Set(s, pot).Succeeded) 
                    Console.WriteLine("Communication error");
                TimePeriod.Sleep(wait);
            }
            return true;
        }
Esempio n. 2
0
        private bool Animate(MCP41X1_Base.ADDRESS pot, AnimationDsl animationType, int wait, int count = 1)
        {
            var steps = new List <int>();

            if (animationType == AnimationDsl.FadeInFadeOut)
            {
                Animate(pot, AnimationDsl.FadeIn, wait);
                Animate(pot, AnimationDsl.Pause, wait);
                Animate(pot, AnimationDsl.FadeOut, wait);
            }
            else if (animationType == AnimationDsl.FadeIn)
            {
                steps = _stepsDefinition[pot];
            }
            else if (animationType == AnimationDsl.FadeOut)
            {
                steps = new List <int>(_stepsDefinition[pot]);
                steps.Reverse();
            }
            else if (animationType == AnimationDsl.Pause)
            {
                TimePeriod.Sleep(wait * 2);
                return(true);
            }
            else if (animationType == AnimationDsl.Off)
            {
                this.Set(0, pot);
                return(true);
            }
            else if (animationType == AnimationDsl.Max)
            {
                steps = _stepsDefinition[pot];
                this.Set(steps[steps.Count - 1], pot);
                return(true);
            }
            else if (animationType == AnimationDsl.HalfMax)
            {
                steps = _stepsDefinition[pot];
                this.Set(steps[steps.Count / 2], pot);
                return(true);
            }
            else if (animationType == AnimationDsl.Blink)
            {
                MCP41X1_Base.ADDRESS Led1 = pot;
                MCP41X1_Base.ADDRESS Led2 = Led1 == Red ? Green : Red;

                for (var c = 0; c < count; c++)
                {
                    Animate(Led1, AnimationDsl.Off, wait);
                    TimePeriod.Sleep(wait);
                    Animate(Led1, AnimationDsl.Max, wait);
                    TimePeriod.Sleep(wait);
                }
                return(true);
            }
            else if (animationType == AnimationDsl.BlinkWithOtherColor)
            {
                MCP41X1_Base.ADDRESS Led1 = pot;
                MCP41X1_Base.ADDRESS Led2 = Led1 == Red ? Green : Red;

                for (var c = 0; c < count; c++)
                {
                    Animate(Led1, AnimationDsl.Off, wait);
                    Animate(Led2, AnimationDsl.Max, wait);
                    TimePeriod.Sleep(wait);
                    Animate(Led2, AnimationDsl.Off, wait);
                    Animate(Led1, AnimationDsl.Max, wait);
                    TimePeriod.Sleep(wait);
                }
                return(true);
            }
            else
            {
                throw new ArgumentException();
            }

            foreach (var s in steps)
            {
                if (!this.Set(s, pot).Succeeded)
                {
                    Console.WriteLine("Communication error");
                }
                TimePeriod.Sleep(wait);
            }
            return(true);
        }