Skip to content

Commit

Permalink
⚡️ Misc. optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and ernisv committed Nov 23, 2023
1 parent f80070b commit 8ff7c7a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
if (ELAPSED(ms, next_cub_ms_##N)) { \
next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \
CODE; \
queue.inject(F(BUTTON##N##_GCODE)); \
TERN_(HAS_MARLINUI_MENU, ui.quick_feedback()); \
queue.inject(F(BUTTON##N##_GCODE)); \
TERN_(HAS_MARLINUI_MENU, ui.quick_feedback()); \
} \
} \
}while(0)
Expand Down
5 changes: 0 additions & 5 deletions Marlin/src/core/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ void serial_offset(const_float_t v, const uint8_t sp/*=0*/) {
SERIAL_DECIMAL(v);
}

void serial_ternary(const bool onoff, FSTR_P const pre, FSTR_P const on, FSTR_P const off, FSTR_P const post/*=nullptr*/) {
if (pre) serial_print(pre);
serial_print(onoff ? on : off);
if (post) serial_print(post);
}
void serialprint_onoff(const bool onoff) { serial_print(onoff ? F(STR_ON) : F(STR_OFF)); }
void serialprintln_onoff(const bool onoff) { serialprint_onoff(onoff); SERIAL_EOL(); }
void serialprint_truefalse(const bool tf) { serial_print(tf ? F("true") : F("false")); }
Expand Down
7 changes: 6 additions & 1 deletion Marlin/src/core/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,12 @@ inline void serial_echolnpair(FSTR_P const fstr, T v) { serial_echolnpair_P(FTOP

void serial_echo_start();
void serial_error_start();
void serial_ternary(const bool onoff, FSTR_P const pre, FSTR_P const on, FSTR_P const off, FSTR_P const post=nullptr);
inline void serial_ternary(const bool onoff, FSTR_P const pre, FSTR_P const on, FSTR_P const off, FSTR_P const post=nullptr) {
if (pre) serial_print(pre);
if (onoff && on) serial_print(on);
if (!onoff && off) serial_print(off);
if (post) serial_print(post);
}
void serialprint_onoff(const bool onoff);
void serialprintln_onoff(const bool onoff);
void serialprint_truefalse(const bool tf);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/ubl/ubl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void unified_bed_leveling::report_current_mesh() {

void unified_bed_leveling::report_state() {
echo_name();
SERIAL_ECHO_TERNARY(planner.leveling_active, " System v" UBL_VERSION " ", "", "in", "active\n");
serial_ternary(planner.leveling_active, " System v" UBL_VERSION " ", nullptr, "in", "active\n");
serial_delay(50);
}

Expand Down
31 changes: 18 additions & 13 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ void Temperature::init() {
*
* TODO: Embed the last 3 parameters during init, if not less optimal
*/
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) {
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) {

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

const celsius_float_t rdiff = running_temp - current;

#if ENABLED(ADAPTIVE_FAN_SLOWING)
if (adaptive_fan_slowing && heater_id >= 0) {
const int fan_index = _MIN(heater_id, FAN_COUNT - 1);
if (fan_speed[fan_index] == 0 || current >= running_temp - (hysteresis_degc * 0.25f))
fan_speed_scaler[fan_index] = 128;
else if (current >= running_temp - (hysteresis_degc * 0.3335f))
fan_speed_scaler[fan_index] = 96;
else if (current >= running_temp - (hysteresis_degc * 0.5f))
fan_speed_scaler[fan_index] = 64;
else if (current >= running_temp - (hysteresis_degc * 0.8f))
fan_speed_scaler[fan_index] = 32;
const int_fast8_t fan_index = _MIN(heater_id, FAN_COUNT - 1);
uint8_t scale;
if (fan_speed[fan_index] == 0 || rdiff <= hysteresis_degc * 0.25f)
scale = 128;
else if (rdiff <= hysteresis_degc * 0.3335f)
scale = 96;
else if (rdiff <= hysteresis_degc * 0.5f)
scale = 64;
else if (rdiff <= hysteresis_degc * 0.8f)
scale = 32;
else
fan_speed_scaler[fan_index] = 0;
scale = 0;

fan_speed_scaler[fan_index] = scale;
}
#endif
#endif // ADAPTIVE_FAN_SLOWING

const millis_t now = millis();

Expand All @@ -2953,7 +2958,7 @@ void Temperature::init() {
}
#endif

if (current >= running_temp - hysteresis_degc) {
if (rdiff <= hysteresis_degc) {
timer = now + SEC_TO_MS(period_seconds);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#define E_NAME TERN_(HAS_MULTI_HOTEND, e)

// Element identifiers. Positive values are hotends. Negative values are other heaters or coolers.
typedef enum : int8_t {
typedef enum : int_fast8_t {
H_REDUNDANT = HID_REDUNDANT,
H_COOLER = HID_COOLER,
H_PROBE = HID_PROBE,
Expand Down Expand Up @@ -1293,12 +1293,12 @@ class Temperature {
typedef struct {
millis_t timer = 0;
TRState state = TRInactive;
float running_temp;
celsius_float_t running_temp;
#if ENABLED(THERMAL_PROTECTION_VARIANCE_MONITOR)
millis_t variance_timer = 0;
celsius_float_t last_temp = 0.0, variance = 0.0;
#endif
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);
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);
} tr_state_machine_t;

static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY];
Expand Down

0 comments on commit 8ff7c7a

Please sign in to comment.