Skip to content

Commit d0bdb9c

Browse files
committed
⚡️ Misc. optimizations
1 parent 821d796 commit d0bdb9c

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
@@ -518,8 +518,8 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
518518
if (ELAPSED(ms, next_cub_ms_##N)) { \
519519
next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \
520520
CODE; \
521-
queue.inject(F(BUTTON##N##_GCODE)); \
522-
TERN_(HAS_MARLINUI_MENU, ui.quick_feedback()); \
521+
queue.inject(F(BUTTON##N##_GCODE)); \
522+
TERN_(HAS_MARLINUI_MENU, ui.quick_feedback()); \
523523
} \
524524
} \
525525
}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
@@ -2857,7 +2857,7 @@ void Temperature::init() {
28572857
*
28582858
* TODO: Embed the last 3 parameters during init, if not less optimal
28592859
*/
2860-
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) {
2860+
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) {
28612861

28622862
#if HEATER_IDLE_HANDLER
28632863
// Convert the given heater_id_t to an idle array index
@@ -2919,21 +2919,26 @@ void Temperature::init() {
29192919
// While the temperature is stable watch for a bad temperature
29202920
case TRStable: {
29212921

2922+
const celsius_float_t rdiff = running_temp - current;
2923+
29222924
#if ENABLED(ADAPTIVE_FAN_SLOWING)
29232925
if (adaptive_fan_slowing && heater_id >= 0) {
2924-
const int fan_index = _MIN(heater_id, FAN_COUNT - 1);
2925-
if (fan_speed[fan_index] == 0 || current >= running_temp - (hysteresis_degc * 0.25f))
2926-
fan_speed_scaler[fan_index] = 128;
2927-
else if (current >= running_temp - (hysteresis_degc * 0.3335f))
2928-
fan_speed_scaler[fan_index] = 96;
2929-
else if (current >= running_temp - (hysteresis_degc * 0.5f))
2930-
fan_speed_scaler[fan_index] = 64;
2931-
else if (current >= running_temp - (hysteresis_degc * 0.8f))
2932-
fan_speed_scaler[fan_index] = 32;
2926+
const int_fast8_t fan_index = _MIN(heater_id, FAN_COUNT - 1);
2927+
uint8_t scale;
2928+
if (fan_speed[fan_index] == 0 || rdiff <= hysteresis_degc * 0.25f)
2929+
scale = 128;
2930+
else if (rdiff <= hysteresis_degc * 0.3335f)
2931+
scale = 96;
2932+
else if (rdiff <= hysteresis_degc * 0.5f)
2933+
scale = 64;
2934+
else if (rdiff <= hysteresis_degc * 0.8f)
2935+
scale = 32;
29332936
else
2934-
fan_speed_scaler[fan_index] = 0;
2937+
scale = 0;
2938+
2939+
fan_speed_scaler[fan_index] = scale;
29352940
}
2936-
#endif
2941+
#endif // ADAPTIVE_FAN_SLOWING
29372942

29382943
const millis_t now = millis();
29392944

@@ -2953,7 +2958,7 @@ void Temperature::init() {
29532958
}
29542959
#endif
29552960

2956-
if (current >= running_temp - hysteresis_degc) {
2961+
if (rdiff <= hysteresis_degc) {
29572962
timer = now + SEC_TO_MS(period_seconds);
29582963
break;
29592964
}

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,
@@ -1293,12 +1293,12 @@ class Temperature {
12931293
typedef struct {
12941294
millis_t timer = 0;
12951295
TRState state = TRInactive;
1296-
float running_temp;
1296+
celsius_float_t running_temp;
12971297
#if ENABLED(THERMAL_PROTECTION_VARIANCE_MONITOR)
12981298
millis_t variance_timer = 0;
12991299
celsius_float_t last_temp = 0.0, variance = 0.0;
13001300
#endif
1301-
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);
1301+
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);
13021302
} tr_state_machine_t;
13031303

13041304
static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY];

0 commit comments

Comments
 (0)