Skip to content

Limit fan speed menu #27820

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

Open
wants to merge 3 commits into
base: bugfix-2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3556,6 +3556,8 @@
// Set number of user-controlled fans. Disable to use all board-defined fans.
// :[1,2,3,4,5,6,7,8]
//#define NUM_M106_FANS 1
//#define MAX_FAN_SPEED 255 // (0..255) Set a Maximum Fan Speed for 'M106 S'
//#define EDITABLE_MAX_FAN_SPEED // Add 'M106 F' and menu item to modify Maximum Fan Speed

/**
* Use software PWM to drive the fan, as for the heaters. This uses a very low frequency
Expand Down
19 changes: 16 additions & 3 deletions Marlin/src/gcode/temp/M106_M107.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
* S<int> Speed between 0-255
* P<index> Fan index, if more than one fan
*
* With EDITABLE_MAX_FAN_SPEED enabled:
* F<int> Max fan speed (128-255)
*
* With EXTRA_FAN_SPEED enabled:
*
* T<int> Restore/Use/Set Temporary Speed:
Expand All @@ -63,12 +66,17 @@ void GcodeSuite::M106() {
if (pfan >= _CNT_P) return;
if (FAN_IS_REDUNDANT(pfan)) return;

#if ENABLED(EDITABLE_MAX_FAN_SPEED)
if (parser.seenval('F'))
thermalManager.max_fan_speed = _MAX(parser.value_byte(), 128);
#endif

#if ENABLED(EXTRA_FAN_SPEED)
const uint16_t t = parser.intval('T');
if (t > 0) return thermalManager.set_temp_fan_speed(pfan, t);
#endif

const uint16_t dspeed = parser.seen_test('A') ? thermalManager.fan_speed[active_extruder] : 255;
const uint16_t dspeed = parser.seen_test('A') ? thermalManager.fan_speed[active_extruder] : 255U;

uint16_t speed = dspeed;

Expand All @@ -83,9 +91,14 @@ void GcodeSuite::M106() {
if (!got_preset && parser.seenval('S'))
speed = parser.value_ushort();

TERN_(FOAMCUTTER_XYUV, speed *= 2.55f); // Get command in % of max heat
TERN_(FOAMCUTTER_XYUV, speed = (speed * 255U) / 100U); // Get command in % of max heat

#if ENABLED(EDITABLE_MAX_FAN_SPEED) || MAX_FAN_SPEED < 255
// Set speed, with constraint < max_fan_speed
NOMORE(speed, thermalManager.max_fan_speed);
#endif

// Set speed, with constraint
// Set speed, with constraint <= 255
thermalManager.set_fan_speed(pfan, speed);

TERN_(LASER_SYNCHRONOUS_M106_M107, planner.buffer_sync_block(BLOCK_BIT_SYNC_FANS));
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ namespace LanguageNarrow_en {
LSTR MSG_CUTTER = _UxGT("Cutter");
LSTR MSG_LASER = _UxGT("Laser");
LSTR MSG_FAN_SPEED = _UxGT("Fan Speed");
LSTR MSG_MAX_FAN_SPEED = _UxGT("Max Fan Speed");
LSTR MSG_FAN_SPEED_N = _UxGT("Fan Speed ~");
LSTR MSG_STORED_FAN_N = _UxGT("Stored Fan ~");
LSTR MSG_EXTRA_FAN_SPEED = _UxGT("Extra Fan Speed");
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/lcd/menu/menu_temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ void menu_temperature() {
singlenozzle_item(7);
#endif

#if ENABLED(EDITABLE_MAX_FAN_SPEED)
EDIT_ITEM_FAST(percent, MSG_MAX_FAN_SPEED, &thermalManager.max_fan_speed, 0, 255);
#endif
#endif // HAS_FAN

#if HAS_PREHEAT
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/lcd/menu/menu_tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ void menu_tune() {
singlenozzle_item(7);
#endif

#if ENABLED(EDITABLE_MAX_FAN_SPEED)
EDIT_ITEM_FAST(percent, MSG_MAX_FAN_SPEED, &thermalManager.max_fan_speed, 0, 255);
#endif
#endif // HAS_FAN

//
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
// HAS_FAN does not include CONTROLLER_FAN
#if HAS_FAN

#if ENABLED(EDITABLE_MAX_FAN_SPEED)
uint8_t Temperature::max_fan_speed = MAX_FAN_SPEED;
#else
constexpr uint8_t Temperature::max_fan_speed;
#endif

uint8_t Temperature::fan_speed[FAN_COUNT] = ARRAY_N_1(FAN_COUNT, FAN_OFF_PWM);

#if ENABLED(EXTRA_FAN_SPEED)
Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,15 @@ class Temperature {

#if HAS_FAN

#ifndef MAX_FAN_SPEED
#define MAX_FAN_SPEED 255
#endif
#if ENABLED(EDITABLE_MAX_FAN_SPEED)
static uint8_t max_fan_speed;
#else
static constexpr uint8_t max_fan_speed = MAX_FAN_SPEED;
#endif

static uint8_t fan_speed[FAN_COUNT];
#define FANS_LOOP(I) for (uint8_t I = 0; I < FAN_COUNT; ++I)

Expand Down