Skip to content

Commit

Permalink
⚡️ Reduce calls to set fan PWM (#23149)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot authored and thinkyhead committed Dec 25, 2021
1 parent 2cc4a1b commit 281ed99
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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());

Expand Down

0 comments on commit 281ed99

Please sign in to comment.