From 281ed99868e2ad67be39858aac5ba6a6b46c6fd0 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 20 Nov 2021 02:44:53 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Reduce=20calls=20to=20set?= =?UTF-8?q?=20fan=20PWM=20(#23149)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/module/planner.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index e19684a7b5..28364d4be0 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -1311,7 +1311,8 @@ void Planner::check_axes_activity() { #endif #if HAS_TAIL_FAN_SPEED - uint8_t tail_fan_speed[FAN_COUNT]; + static uint8_t tail_fan_speed[FAN_COUNT]; + bool fans_need_update = false; #endif #if ENABLED(BARICUDA) @@ -1330,7 +1331,13 @@ void Planner::check_axes_activity() { #endif #if HAS_TAIL_FAN_SPEED - FANS_LOOP(i) tail_fan_speed[i] = thermalManager.scaledFanSpeed(i, block->fan_speed[i]); + FANS_LOOP(i) { + const uint8_t spd = thermalManager.scaledFanSpeed(i, block->fan_speed[i]); + if (tail_fan_speed[i] != spd) { + fans_need_update = true; + tail_fan_speed[i] = spd; + } + } #endif #if ENABLED(BARICUDA) @@ -1358,7 +1365,13 @@ void Planner::check_axes_activity() { TERN_(HAS_CUTTER, cutter.refresh()); #if HAS_TAIL_FAN_SPEED - FANS_LOOP(i) tail_fan_speed[i] = thermalManager.scaledFanSpeed(i); + FANS_LOOP(i) { + const uint8_t spd = thermalManager.scaledFanSpeed(i); + if (tail_fan_speed[i] != spd) { + fans_need_update = true; + tail_fan_speed[i] = spd; + } + } #endif #if ENABLED(BARICUDA) @@ -1384,7 +1397,7 @@ void Planner::check_axes_activity() { // Update Fan speeds // Only if synchronous M106/M107 is disabled // - TERN_(HAS_TAIL_FAN_SPEED, sync_fan_speeds(tail_fan_speed)); + TERN_(HAS_TAIL_FAN_SPEED, if (fans_need_update) sync_fan_speeds(tail_fan_speed)); TERN_(AUTOTEMP, autotemp_task());