public void AddFadePlan(int brightnessPercent, int delay) { //if (this.fadePlan) // delete this.fadePlan; this.fadePlan = new FadeInfo(brightnessPercent, millis() + delay); Update(); }
public void Update() { if (fadePlan != null) { int delay = (int)(fadePlan.GetStartOnMillis() - millis()); if (delay <= 0) { Fade(fadePlan.GetBrightnessPercent(), delay); //delete fadePlan; fadePlan = null; } } if (!this.isFadingPlanned) { return; } long currentMillis = millis(); if (currentMillis >= millisStart) { this.isFading = true; long difference = currentMillis - millisStart; double timeLeftPercent = difference * 1.0 * 100 / this.milisCountForFullBrightness; if (timeLeftPercent - this.previousTimeLeftPercent > 0) { if (this.brightnessGoingUp) { this.currentBrightness += (int)Math.Round((timeLeftPercent - this.previousTimeLeftPercent) * MAX_LED_BRIGHTNESS / 100, 0); } else { this.currentBrightness -= (int)Math.Round((timeLeftPercent - this.previousTimeLeftPercent) * MAX_LED_BRIGHTNESS / 100, 0); } this.previousTimeLeftPercent = timeLeftPercent; if (timeLeftPercent >= 100 || (brightnessGoingUp && currentBrightness >= brightnessToSet) || (!brightnessGoingUp && currentBrightness <= brightnessToSet)) { this.currentBrightness = this.brightnessToSet; this.isFadingPlanned = this.isFading = false; this.millisStart = 0; } SetPWM(this.currentBrightness); } } }