static bool AnimateOneLed(MCP4231 dp, MCP41X1_Base.ADDRESS pot0, MCP41X1_Base.ADDRESS?pot1, int wait) { int startStep = 38; int step = 4; for (var i = startStep; i <= dp.MaxDigitalValue; i += step) { if (!dp.Set(i, pot0).Succeeded) { Console.WriteLine("Communication error"); } if (pot1.HasValue) { if (!dp.Set(i, pot1.Value).Succeeded) { Console.WriteLine("Communication error"); } } if (DisplayPotentiometerInfoAndCheckForCancel(dp, exWaitTime:wait)) { return(true); // Quit } } for (var i = dp.MaxDigitalValue; i > startStep; i -= step) { if (!dp.Set(i, pot0).Succeeded) { Console.WriteLine("Communication error"); } if (pot1.HasValue) { if (!dp.Set(i, pot1.Value).Succeeded) { Console.WriteLine("Communication error"); } } if (DisplayPotentiometerInfoAndCheckForCancel(dp, exWaitTime:wait)) { return(true); // Quit } } return(false); }
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); }