fixed the broken fade out when the watchdog kicks in

This commit is contained in:
2026-01-18 06:06:57 +01:00
parent a9957bc695
commit c1d7ba4b3d

View File

@@ -183,19 +183,22 @@ void loop() {
} }
} }
// -------- Slew-rate limiting (smooth 1-second transitions) -------- // -------- Slew-rate limiting (only when NOT in watchdog mode) --------
unsigned long now = millis(); if (millis() - lastPacketTime <= watchdogTimeout) {
float progress = (float)(now - slewStartTime) / (float)slewDuration;
if (progress > 1.0f) progress = 1.0f;
for (int ch = 0; ch < NUM_CHANNELS; ch++) { unsigned long now = millis();
float newDuty = slewStartDuty[ch] + (targetDuty[ch] - slewStartDuty[ch]) * progress; float progress = (float)(now - slewStartTime) / (float)slewDuration;
currentDuty[ch] = newDuty; if (progress > 1.0f) progress = 1.0f;
float calibratedDuty = applyCalibration(ch, newDuty); for (int ch = 0; ch < NUM_CHANNELS; ch++) {
int duty = (int)((calibratedDuty / 100.0f) * ((1 << pwmResolution) - 1)); float newDuty = slewStartDuty[ch] + (targetDuty[ch] - slewStartDuty[ch]) * progress;
currentDuty[ch] = newDuty;
ledcWrite(pwmPins[ch], duty); float calibratedDuty = applyCalibration(ch, newDuty);
int duty = (int)((calibratedDuty / 100.0f) * ((1 << pwmResolution) - 1));
ledcWrite(pwmPins[ch], duty);
}
} }
// -------- Watchdog fade-to-zero (UDP-based) -------- // -------- Watchdog fade-to-zero (UDP-based) --------