Skip to content

Commit

Permalink
fan_speed_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
studiodyne committed Jul 17, 2024
1 parent 6f04d8d commit a7fbdea
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
15 changes: 15 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,21 @@
*/
//#define EXTRA_FAN_SPEED

/**
* Fan speed offset
* Adds a constant value to fan_speed, to increase/decrease for the totality of your print.
* Can modify the fan speed permanently and proportionnaly , whatever the many fan speed changes
* Threshold must be used to target the normal fan speed with no effect, when full power or very low value.
* 'M106 C <%> : (-100/100) Set the additional speed
* 'M106 B <%> : (0/100) Min threshold of fan speed to be affected by(Any speed below this will not be modified)
* 'M106 D <%> : (0/100) Max threshold of fan speed addition (If set on 70%, all higher fan speeds called will not be modified, like full power, will remains full power)
*/
#define FAN_SPEED_OFFSET
#if ENABLED(FAN_SPEED_OFFSET)
#define FAN_SPEED_OFFSET_THR_MIN 20 // '%'
#define FAN_SPEED_OFFSET_THR_MAX 70 // '%'
#endif

// @section gcode

/**
Expand Down
17 changes: 17 additions & 0 deletions Marlin/src/gcode/temp/M106_M107.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
/**
* M106: Set Fan Speed
*
* B<int> Min threshold of constant addition
* D<int> Max threshold of constant addition
* C<int> Constant value for permanent modification during printing
* 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
Expand All @@ -63,6 +66,12 @@ void GcodeSuite::M106() {
if (pfan >= _CNT_P) return;
if (FAN_IS_REDUNDANT(pfan)) return;

#if ENABLED(FAN_SPEED_OFFSET)
if (parser.seen_test('B')) thermalManager.fan_speed_offset_thr_min[pfan] = parser.intval('B') * (255/100);
if (parser.seen_test('C')) thermalManager.fan_speed_offset[pfan] = parser.intval('C');
if (parser.seen_test('D')) thermalManager.fan_speed_offset_thr_max[pfan] = parser.intval('D') * (255/100);
#endif

#if ENABLED(EXTRA_FAN_SPEED)
const uint16_t t = parser.intval('T');
if (t > 0) return thermalManager.set_temp_fan_speed(pfan, t);
Expand All @@ -85,6 +94,14 @@ void GcodeSuite::M106() {

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

#if ENABLED(FAN_SPEED_OFFSET)
if ((speed > thermalManager.fan_speed_offset_thr_min[pfan])
&& (speed < thermalManager.fan_speed_offset_thr_max[pfan])
&& (thermalManager.fan_speed_offset_thr_min[pfan] < thermalManager.fan_speed_offset_thr_max[pfan])
)
speed += (thermalManager.fan_speed_offset[pfan] * 255/100);
#endif

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

Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ namespace LanguageNarrow_en {
LSTR MSG_STORED_FAN_N = _UxGT("Stored Fan ~");
LSTR MSG_EXTRA_FAN_SPEED = _UxGT("Extra Fan Speed");
LSTR MSG_EXTRA_FAN_SPEED_N = _UxGT("Extra Fan Speed ~");
LSTR MSG_OFFSET_FAN_SPEED = _UxGT("Fan speed offs ~");
LSTR MSG_OFFSET_MIN_FAN_SPEED = _UxGT("Fan offs min ~");
LSTR MSG_OFFSET_MAX_FAN_SPEED = _UxGT("Fan offs max ~");
LSTR MSG_OFFSET_FAN_SPEED_N = _UxGT("Fan speed offs ~");
LSTR MSG_OFFSET_MIN_FAN_SPEED_N = _UxGT("Fan offs min ~");
LSTR MSG_OFFSET_MAX_FAN_SPEED_N = _UxGT("Fan offs max ~");
LSTR MSG_CONTROLLER_FAN = _UxGT("Controller Fan");
LSTR MSG_CONTROLLER_FAN_IDLE_SPEED = _UxGT("Idle Speed");
LSTR MSG_CONTROLLER_FAN_AUTO_ON = _UxGT("Auto Mode");
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/lcd/language/language_fr_na.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ namespace LanguageNarrow_fr_na {
LSTR MSG_EXTRA_FAN_SPEED = _UxGT("Extra ventil. ");
LSTR MSG_EXTRA_FAN_SPEED_N = _UxGT("Extra ventil. ~");

LSTR MSG_OFFSET_FAN_SPEED = _UxGT("Ventil. sup ~");
LSTR MSG_OFFSET_MIN_FAN_SPEED = _UxGT("Seuil min ~");
LSTR MSG_OFFSET_MAX_FAN_SPEED = _UxGT("Seuil max ~");
LSTR MSG_OFFSET_FAN_SPEED_N = _UxGT("Ventil. sup ~");
LSTR MSG_OFFSET_MIN_FAN_SPEED_N = _UxGT("Seuil min ~");
LSTR MSG_OFFSET_MAX_FAN_SPEED_N = _UxGT("Seuil max ~");
LSTR MSG_FLOW = _UxGT("Flux");
LSTR MSG_FLOW_N = _UxGT("Flux ~");
LSTR MSG_CONTROL = _UxGT("Controler");
Expand Down
32 changes: 28 additions & 4 deletions Marlin/src/lcd/menu/menu_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,20 +578,44 @@ class MenuItem_bool : public MenuEditItemBase {
#define EDIT_EXTRA_FAN_SPEED(...)
#endif

#if ENABLED(FAN_SPEED_OFFSET)
#define EDIT_OFFSET_FAN_SPEED(V...) EDIT_ITEM_FAST_N(V)
#define EDIT_OFFSET_MIN_FAN_SPEED(V...) EDIT_ITEM_FAST_N(V)
#define EDIT_OFFSET_MAX_FAN_SPEED(V...) EDIT_ITEM_FAST_N(V)
#else
#define EDIT_OFFSET_FAN_SPEED(...)
#define EDIT_OFFSET_MIN_FAN_SPEED(...)
#define EDIT_OFFSET_MAX_FAN_SPEED(...)
#endif

#if FAN_COUNT == 1
#define MSG_FIRST_FAN_SPEED MSG_FAN_SPEED
#define MSG_EXTRA_FIRST_FAN_SPEED MSG_EXTRA_FAN_SPEED
#define MSG_FIRST_FAN_SPEED MSG_FAN_SPEED
#define MSG_EXTRA_FIRST_FAN_SPEED MSG_EXTRA_FAN_SPEED
#define MSG_OFFSET_FIRST_FAN_SPEED MSG_OFFSET_FAN_SPEED
#define MSG_OFFSET_MIN_FIRST_FAN_SPEED MSG_OFFSET_MIN_FAN_SPEED
#define MSG_OFFSET_MAX_FIRST_FAN_SPEED MSG_OFFSET_MAX_FAN_SPEED
#else
#define MSG_FIRST_FAN_SPEED MSG_FAN_SPEED_N
#define MSG_EXTRA_FIRST_FAN_SPEED MSG_EXTRA_FAN_SPEED_N
#define MSG_FIRST_FAN_SPEED MSG_FAN_SPEED_N
#define MSG_EXTRA_FIRST_FAN_SPEED MSG_EXTRA_FAN_SPEED_N
#define MSG_OFFSET_FIRST_FAN_SPEED MSG_OFFSET_FAN_SPEED_N
#define MSG_OFFSET_MIN_FIRST_FAN_SPEED MSG_OFFSET_MIN_FAN_SPEED_N
#define MSG_OFFSET_MAX_FIRST_FAN_SPEED MSG_OFFSET_MAX_FAN_SPEED_N
#endif

#define _FAN_EDIT_ITEMS(F,L) do{ \
editable.uint8 = thermalManager.fan_speed[F]; \
EDIT_ITEM_FAST_N(percent, F, MSG_##L, &editable.uint8, 0, 255, on_fan_update); \
EDIT_EXTRA_FAN_SPEED(percent, F, MSG_EXTRA_##L, &thermalManager.extra_fan_speed[F].speed, 3, 255); \
EDIT_OFFSET_FAN_SPEED(int3, F, MSG_OFFSET_##L, &thermalManager.fan_speed_offset[F], -100, 100); \
EDIT_OFFSET_MIN_FAN_SPEED(percent, F, MSG_OFFSET_MIN_##L, &thermalManager.fan_speed_offset_thr_min[F], 0, 255); \
EDIT_OFFSET_MAX_FAN_SPEED(percent, F, MSG_OFFSET_MAX_##L, &thermalManager.fan_speed_offset_thr_max[F], 0, 255); \
}while(0)

/*EDIT_TUNE_FAN_SPEED(percent, F, MSG_MODIFIER_##L, &thermalManager.fan_speed_offset[F], -255, 255); \
EDIT_MIN_TUNE_FAN_SPEED(percent, F, MSG_MODIFIER_MIN_##L, &thermalManager.fan_speed_offset_thr_min[F], 1, 255); \
EDIT_MAX_TUNE_FAN_SPEED(percent, F, MSG_MODIFIER_MAX_##L, &thermalManager.fan_speed_offset_thr_max[F], 1, 255); \
*/

#if FAN_COUNT > 1
#define FAN_EDIT_ITEMS(F) _FAN_EDIT_ITEMS(F, FAN_SPEED_N)
#endif
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,12 @@ class Temperature {
static void set_temp_fan_speed(const uint8_t fan, const uint16_t command_or_speed);
#endif

#if ENABLED(FAN_SPEED_OFFSET)
int16_t fan_speed_offset[FAN_COUNT] = {0};
uint8_t fan_speed_offset_thr_min[FAN_COUNT] = {uint8_t(FAN_SPEED_OFFSET_THR_MIN * 255/100)};
uint8_t fan_speed_offset_thr_max[FAN_COUNT] = {uint8_t(FAN_SPEED_OFFSET_THR_MAX * 255/100)};
#endif

#if ANY(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE)
void set_fans_paused(const bool p);
#endif
Expand Down

0 comments on commit a7fbdea

Please sign in to comment.