Skip to content

Commit e6ac9ff

Browse files
committed
⚡️ Misc. optimizations
1 parent 283d093 commit e6ac9ff

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed

Marlin/src/MarlinCore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
520520
if (ELAPSED(ms, next_cub_ms_##N)) { \
521521
next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \
522522
CODE; \
523-
queue.inject(F(BUTTON##N##_GCODE)); \
524-
TERN_(HAS_MARLINUI_MENU, ui.quick_feedback()); \
523+
queue.inject(F(BUTTON##N##_GCODE)); \
524+
TERN_(HAS_MARLINUI_MENU, ui.quick_feedback()); \
525525
} \
526526
} \
527527
}while(0)

Marlin/src/core/serial.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ void serial_offset(const_float_t v, const uint8_t sp/*=0*/) {
8585
SERIAL_DECIMAL(v);
8686
}
8787

88-
void serial_ternary(const bool onoff, FSTR_P const pre, FSTR_P const on, FSTR_P const off, FSTR_P const post/*=nullptr*/) {
89-
if (pre) serial_print(pre);
90-
serial_print(onoff ? on : off);
91-
if (post) serial_print(post);
92-
}
9388
void serialprint_onoff(const bool onoff) { serial_print(onoff ? F(STR_ON) : F(STR_OFF)); }
9489
void serialprintln_onoff(const bool onoff) { serialprint_onoff(onoff); SERIAL_EOL(); }
9590
void serialprint_truefalse(const bool tf) { serial_print(tf ? F("true") : F("false")); }

Marlin/src/core/serial.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,12 @@ inline void serial_echolnpair(FSTR_P const fstr, T v) { serial_echolnpair_P(FTOP
327327

328328
void serial_echo_start();
329329
void serial_error_start();
330-
void serial_ternary(const bool onoff, FSTR_P const pre, FSTR_P const on, FSTR_P const off, FSTR_P const post=nullptr);
330+
inline void serial_ternary(const bool onoff, FSTR_P const pre, FSTR_P const on, FSTR_P const off, FSTR_P const post=nullptr) {
331+
if (pre) serial_print(pre);
332+
if (onoff && on) serial_print(on);
333+
if (!onoff && off) serial_print(off);
334+
if (post) serial_print(post);
335+
}
331336
void serialprint_onoff(const bool onoff);
332337
void serialprintln_onoff(const bool onoff);
333338
void serialprint_truefalse(const bool tf);

Marlin/src/feature/bedlevel/ubl/ubl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void unified_bed_leveling::report_current_mesh() {
5959

6060
void unified_bed_leveling::report_state() {
6161
echo_name();
62-
SERIAL_ECHO_TERNARY(planner.leveling_active, " System v" UBL_VERSION " ", "", "in", "active\n");
62+
serial_ternary(planner.leveling_active, " System v" UBL_VERSION " ", nullptr, "in", "active\n");
6363
serial_delay(50);
6464
}
6565

Marlin/src/module/temperature.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,7 +2890,7 @@ void Temperature::init() {
28902890
*
28912891
* TODO: Embed the last 3 parameters during init, if not less optimal
28922892
*/
2893-
void Temperature::tr_state_machine_t::run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc) {
2893+
void Temperature::tr_state_machine_t::run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_float_t hysteresis_degc) {
28942894

28952895
#if HEATER_IDLE_HANDLER
28962896
// Convert the given heater_id_t to an idle array index
@@ -2959,21 +2959,26 @@ void Temperature::init() {
29592959
// While the temperature is stable watch for a bad temperature
29602960
case TRStable: {
29612961

2962+
const celsius_float_t rdiff = running_temp - current;
2963+
29622964
#if ENABLED(ADAPTIVE_FAN_SLOWING)
29632965
if (adaptive_fan_slowing && heater_id >= 0) {
2964-
const int fan_index = _MIN(heater_id, FAN_COUNT - 1);
2965-
if (fan_speed[fan_index] == 0 || current >= running_temp - (hysteresis_degc * 0.25f))
2966-
fan_speed_scaler[fan_index] = 128;
2967-
else if (current >= running_temp - (hysteresis_degc * 0.3335f))
2968-
fan_speed_scaler[fan_index] = 96;
2969-
else if (current >= running_temp - (hysteresis_degc * 0.5f))
2970-
fan_speed_scaler[fan_index] = 64;
2971-
else if (current >= running_temp - (hysteresis_degc * 0.8f))
2972-
fan_speed_scaler[fan_index] = 32;
2966+
const int_fast8_t fan_index = _MIN(heater_id, FAN_COUNT - 1);
2967+
uint8_t scale;
2968+
if (fan_speed[fan_index] == 0 || rdiff <= hysteresis_degc * 0.25f)
2969+
scale = 128;
2970+
else if (rdiff <= hysteresis_degc * 0.3335f)
2971+
scale = 96;
2972+
else if (rdiff <= hysteresis_degc * 0.5f)
2973+
scale = 64;
2974+
else if (rdiff <= hysteresis_degc * 0.8f)
2975+
scale = 32;
29732976
else
2974-
fan_speed_scaler[fan_index] = 0;
2977+
scale = 0;
2978+
2979+
fan_speed_scaler[fan_index] = scale;
29752980
}
2976-
#endif
2981+
#endif // ADAPTIVE_FAN_SLOWING
29772982

29782983
const millis_t now = millis();
29792984

@@ -2993,7 +2998,7 @@ void Temperature::init() {
29932998
}
29942999
#endif
29953000

2996-
if (current >= running_temp - hysteresis_degc) {
3001+
if (rdiff <= hysteresis_degc) {
29973002
timer = now + SEC_TO_MS(period_seconds);
29983003
break;
29993004
}

Marlin/src/module/temperature.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#define E_NAME TERN_(HAS_MULTI_HOTEND, e)
5050

5151
// Element identifiers. Positive values are hotends. Negative values are other heaters or coolers.
52-
typedef enum : int8_t {
52+
typedef enum : int_fast8_t {
5353
H_REDUNDANT = HID_REDUNDANT,
5454
H_COOLER = HID_COOLER,
5555
H_PROBE = HID_PROBE,
@@ -1319,12 +1319,12 @@ class Temperature {
13191319
typedef struct {
13201320
millis_t timer = 0;
13211321
TRState state = TRInactive;
1322-
float running_temp;
1322+
celsius_float_t running_temp;
13231323
#if ENABLED(THERMAL_PROTECTION_VARIANCE_MONITOR)
13241324
millis_t variance_timer = 0;
13251325
celsius_float_t last_temp = 0.0, variance = 0.0;
13261326
#endif
1327-
void run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc);
1327+
void run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_float_t hysteresis_degc);
13281328
} tr_state_machine_t;
13291329

13301330
static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY];

0 commit comments

Comments
 (0)