Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fan override and multiplier #27198

Open
wants to merge 9 commits into
base: bugfix-2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3894,6 +3894,16 @@

//#define REPORT_FAN_CHANGE // Report the new fan speed when changed by M106 (and others)

/**
* Adds UI and G-code (M106) options to control fan speed while printing.
*
* - Lock Fan Speed: To prevent G-code commands (i.e., M106) from altering the current fan speed.
* - Fan Speed Multiplier: Multiplies the fan speed set by G-code commands by a specified factor for fine-tuning.
*
* Note: Settings are not saved in EEPROM and will reset after a power cycle.
*/
//#define FAN_MULTIPLIER

/**
* Auto-report temperatures with M155 S<seconds>
*/
Expand Down
22 changes: 22 additions & 0 deletions Marlin/src/gcode/temp/M106_M107.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
* I<index> Material Preset index (if material presets are defined)
* S<int> Speed between 0-255
* P<index> Fan index, if more than one fan
* L Lock fan
* U Unlock fan
* M<float> Fan speed multiplier between 0.1 and 10
*
* With EXTRA_FAN_SPEED enabled:
*
Expand All @@ -59,6 +62,21 @@
* 3-255 = Set the speed for use with T2
*/
void GcodeSuite::M106() {
#if ENABLED(FAN_MULTIPLIER)
if (parser.seen('L')) {
thermalManager.lock_fan = true;
if (!parser.seenval('S')) return;
} if (parser.seen('U')) {
thermalManager.lock_fan = false;
return;
} else if (thermalManager.lock_fan) return;

if (parser.seenval('M')) {
thermalManager.set_fan_multiplier(parser.value_float());
if (!parser.seenval('S')) return;
}
#endif

const uint8_t pfan = parser.byteval('P', _ALT_P);
if (pfan >= _CNT_P) return;
if (FAN_IS_REDUNDANT(pfan)) return;
Expand Down Expand Up @@ -98,6 +116,10 @@ void GcodeSuite::M106() {
* M107: Fan Off
*/
void GcodeSuite::M107() {
#if ENABLED(FAN_MULTIPLIER)
if (thermalManager.lock_fan) return;
#endif

const uint8_t pfan = parser.byteval('P', _ALT_P);
if (pfan >= _CNT_P) return;
if (FAN_IS_REDUNDANT(pfan)) return;
Expand Down
6 changes: 4 additions & 2 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2748,8 +2748,10 @@
#ifndef FAN_MAX_PWM
#define FAN_MAX_PWM 255
#endif
#if FAN_MIN_PWM == 0 && FAN_MAX_PWM == 255
#define CALC_FAN_SPEED(f) (f ?: FAN_OFF_PWM)
dbuezas marked this conversation as resolved.
Show resolved Hide resolved
#if FAN_MIN_PWM == 0 && FAN_MAX_PWM == 255 && !defined(FAN_MULTIPLIER)
#define CALC_FAN_SPEED(f) (f ? f : FAN_OFF_PWM)
#elif defined(FAN_MULTIPLIER)
#define CALC_FAN_SPEED(f) (f ? map(thermalManager.compute_multiplied_fan(f), 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : FAN_OFF_PWM)
#else
#define CALC_FAN_SPEED(f) (f ? map(f, 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : FAN_OFF_PWM)
#endif
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ namespace LanguageNarrow_en {
LSTR MSG_SINGLENOZZLE_UNRETRACT_SPEED = _UxGT("Recover Speed");
LSTR MSG_SINGLENOZZLE_FAN_SPEED = _UxGT("Fan Speed");
LSTR MSG_SINGLENOZZLE_FAN_TIME = _UxGT("Fan Time");
LSTR MSG_LOCK_FAN = _UxGT("Lock Fan");
LSTR MSG_UNLOCK_FAN = _UxGT("Unlock Fan");
LSTR MSG_FAN_MULTIPLIER = _UxGT("Fan Multiplier");
LSTR MSG_TOOL_MIGRATION_ON = _UxGT("Auto ON");
LSTR MSG_TOOL_MIGRATION_OFF = _UxGT("Auto OFF");
LSTR MSG_TOOL_MIGRATION = _UxGT("Tool Migration");
Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/lcd/menu/menu_temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ void menu_temperature() {

#if FAN_IS_M106ABLE(0)
_FAN_EDIT_ITEMS(0, FIRST_FAN_SPEED);
#if ENABLED(FAN_MULTIPLIER)
if (thermalManager.lock_fan) {
ACTION_ITEM(MSG_UNLOCK_FAN, []{ thermalManager.lock_fan = false; ui.refresh(); });
} else {
ACTION_ITEM(MSG_LOCK_FAN, []{ thermalManager.lock_fan = true; ui.refresh(); });
}
editable.decimal = thermalManager.get_fan_multiplier();
EDIT_ITEM_FAST(float31, MSG_FAN_MULTIPLIER, &editable.decimal, 0.0f, 9.9f, []{ thermalManager.set_fan_multiplier(editable.decimal); }, true);
#endif
#endif
#if FAN_IS_M106ABLE(1)
FAN_EDIT_ITEMS(1);
Expand Down
15 changes: 15 additions & 0 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
* public:
*/

#if ALL(HAS_FAN, FAN_MULTIPLIER)
void Temperature::set_fan_multiplier(float m){
fan_multiplier = m;
planner.sync_fan_speeds(fan_speed);
}

uint8_t Temperature::compute_multiplied_fan(uint8_t speed){
return constrain(speed * fan_multiplier, 1, 255);
}

float Temperature::get_fan_multiplier(){
return fan_multiplier;
}
#endif

#if ENABLED(TEMP_TUNING_MAINTAIN_FAN)
bool Temperature::adaptive_fan_slowing = true;
#endif
Expand Down
10 changes: 9 additions & 1 deletion Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ typedef struct { raw_adc_t raw_min, raw_max; celsius_t mintemp, maxtemp; } temp_
class Temperature {

public:
#if ALL(HAS_FAN, FAN_MULTIPLIER)
bool lock_fan;
void set_fan_multiplier(float m);
uint8_t compute_multiplied_fan(uint8_t speed);
float get_fan_multiplier();
#endif

#if HAS_HOTEND
static hotend_info_t temp_hotend[HOTENDS];
Expand Down Expand Up @@ -1334,7 +1340,9 @@ class Temperature {
#endif

private:

#if ENABLED(FAN_MULTIPLIER)
float fan_multiplier = 1;
#endif
// Reading raw temperatures and converting to Celsius when ready
static volatile bool raw_temps_ready;
static void update_raw_temperatures();
Expand Down