Skip to content

Commit e22831f

Browse files
thinkyheadLCh-77
authored andcommitted
🎨 Misc. cleanup, string optimization
1 parent ce4ff6a commit e22831f

File tree

10 files changed

+73
-57
lines changed

10 files changed

+73
-57
lines changed

Marlin/Configuration.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@
766766
#define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
767767
// is more than PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
768768

769-
//#define PID_EDIT_MENU // Add PID editing to the "Advanced Settings" menu. (~700 bytes of PROGMEM)
770-
//#define PID_AUTOTUNE_MENU // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of PROGMEM)
769+
//#define PID_EDIT_MENU // Add PID editing to the "Advanced Settings" menu. (~700 bytes of flash)
770+
//#define PID_AUTOTUNE_MENU // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of flash)
771771
#endif
772772

773773
// @section extruder
@@ -1970,7 +1970,7 @@
19701970
* M502 - Revert settings to "factory" defaults. (Follow with M500 to init the EEPROM.)
19711971
*/
19721972
//#define EEPROM_SETTINGS // Persistent storage with M500 and M501
1973-
//#define DISABLE_M503 // Saves ~2700 bytes of PROGMEM. Disable for release!
1973+
//#define DISABLE_M503 // Saves ~2700 bytes of flash. Disable for release!
19741974
#define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save PROGMEM.
19751975
#define EEPROM_BOOT_SILENT // Keep M503 quiet and only give errors during first load
19761976
#if ENABLED(EEPROM_SETTINGS)

Marlin/src/MarlinCore.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
412412
if (do_reset_timeout) gcode.reset_stepper_timeout(ms);
413413

414414
if (gcode.stepper_max_timed_out(ms)) {
415-
SERIAL_ERROR_MSG(STR_KILL_INACTIVE_TIME, parser.command_ptr);
415+
SERIAL_ERROR_START();
416+
SERIAL_ECHOPGM(STR_KILL_PRE);
417+
SERIAL_ECHOLNPGM(STR_KILL_INACTIVE_TIME, parser.command_ptr);
416418
kill();
417419
}
418420

@@ -473,7 +475,9 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
473475
// KILL the machine
474476
// ----------------------------------------------------------------
475477
if (killCount >= KILL_DELAY) {
476-
SERIAL_ERROR_MSG(STR_KILL_BUTTON);
478+
SERIAL_ERROR_START();
479+
SERIAL_ECHOPGM(STR_KILL_PRE);
480+
SERIAL_ECHOLNPGM(STR_KILL_BUTTON);
477481
kill();
478482
}
479483
#endif

Marlin/src/core/language.h

+13-9
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,20 @@
199199
#define STR_FILAMENT_CHANGE_INSERT_M108 "Insert filament and send M108"
200200
#define STR_FILAMENT_CHANGE_WAIT_M108 "Send M108 to resume"
201201

202-
#define STR_STOP_BLTOUCH "!! STOP called because of BLTouch error - restart with M999"
203-
#define STR_STOP_UNHOMED "!! STOP called because of unhomed error - restart with M999"
204-
#define STR_KILL_INACTIVE_TIME "!! KILL caused by too much inactive time - current command: "
205-
#define STR_KILL_BUTTON "!! KILL caused by KILL button/pin"
202+
#define STR_STOP_PRE "!! STOP called because of "
203+
#define STR_STOP_POST " error - restart with M999"
204+
#define STR_STOP_BLTOUCH "BLTouch"
205+
#define STR_STOP_UNHOMED "unhomed"
206+
#define STR_KILL_PRE "!! KILL caused by "
207+
#define STR_KILL_INACTIVE_TIME "too much inactive time - current command: "
208+
#define STR_KILL_BUTTON "KILL button/pin"
206209

207210
// temperature.cpp strings
208-
#define STR_PID_AUTOTUNE_START "PID Autotune start"
209-
#define STR_PID_BAD_HEATER_ID "PID Autotune failed! Bad heater id"
210-
#define STR_PID_TEMP_TOO_HIGH "PID Autotune failed! Temperature too high"
211-
#define STR_PID_TIMEOUT "PID Autotune failed! timeout"
211+
#define STR_PID_AUTOTUNE "PID Autotune"
212+
#define STR_PID_AUTOTUNE_START " start"
213+
#define STR_PID_BAD_HEATER_ID " failed! Bad heater id"
214+
#define STR_PID_TEMP_TOO_HIGH " failed! Temperature too high"
215+
#define STR_PID_TIMEOUT " failed! timeout"
212216
#define STR_BIAS " bias: "
213217
#define STR_D_COLON " d: "
214218
#define STR_T_MIN " min: "
@@ -219,7 +223,7 @@
219223
#define STR_KP " Kp: "
220224
#define STR_KI " Ki: "
221225
#define STR_KD " Kd: "
222-
#define STR_PID_AUTOTUNE_FINISHED "PID Autotune finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
226+
#define STR_PID_AUTOTUNE_FINISHED " finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
223227
#define STR_PID_DEBUG " PID_DEBUG "
224228
#define STR_PID_DEBUG_INPUT ": Input "
225229
#define STR_PID_DEBUG_OUTPUT " Output "

Marlin/src/feature/bltouch.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,8 @@ bool BLTouch::deploy_proc() {
111111
// Last attempt to DEPLOY
112112
if (_deploy_query_alarm()) {
113113
// The deploy might have failed or the probe is actually triggered (nozzle too low?) again
114-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Recovery Failed");
115-
116-
SERIAL_ERROR_MSG(STR_STOP_BLTOUCH); // Tell the user something is wrong, needs action
117-
stop(); // but it's not too bad, no need to kill, allow restart
118-
114+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Deploy Failed");
115+
probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
119116
return true; // Tell our caller we goofed in case he cares to know
120117
}
121118
}
@@ -153,12 +150,8 @@ bool BLTouch::stow_proc() {
153150
// But one more STOW will catch that
154151
// Last attempt to STOW
155152
if (_stow_query_alarm()) { // so if there is now STILL an ALARM condition:
156-
157-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Recovery Failed");
158-
159-
SERIAL_ERROR_MSG(STR_STOP_BLTOUCH); // Tell the user something is wrong, needs action
160-
stop(); // but it's not too bad, no need to kill, allow restart
161-
153+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Stow Failed");
154+
probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
162155
return true; // Tell our caller we goofed in case he cares to know
163156
}
164157
}

Marlin/src/gcode/temp/M303.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void GcodeSuite::M303() {
7171
case H_CHAMBER: default_temp = PREHEAT_1_TEMP_CHAMBER; break;
7272
#endif
7373
default:
74+
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
7475
SERIAL_ECHOLNPGM(STR_PID_BAD_HEATER_ID);
7576
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM));
7677
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_BAD_EXTRUDER_NUM));

Marlin/src/inc/SanityCheck.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -2964,10 +2964,8 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
29642964
#if ENABLED(DWIN_CREALITY_LCD)
29652965
#if DISABLED(SDSUPPORT)
29662966
#error "DWIN_CREALITY_LCD requires SDSUPPORT to be enabled."
2967-
#elif ENABLED(PID_EDIT_MENU)
2968-
#error "DWIN_CREALITY_LCD does not support PID_EDIT_MENU."
2969-
#elif ENABLED(PID_AUTOTUNE_MENU)
2970-
#error "DWIN_CREALITY_LCD does not support PID_AUTOTUNE_MENU."
2967+
#elif EITHER(PID_EDIT_MENU, PID_AUTOTUNE_MENU)
2968+
#error "DWIN_CREALITY_LCD does not support PID_EDIT_MENU or PID_AUTOTUNE_MENU."
29712969
#elif ENABLED(LEVEL_BED_CORNERS)
29722970
#error "DWIN_CREALITY_LCD does not support LEVEL_BED_CORNERS."
29732971
#elif BOTH(LCD_BED_LEVELING, PROBE_MANUALLY)
@@ -2976,10 +2974,8 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
29762974
#elif ENABLED(DWIN_LCD_PROUI)
29772975
#if DISABLED(SDSUPPORT)
29782976
#error "DWIN_LCD_PROUI requires SDSUPPORT to be enabled."
2979-
#elif ENABLED(PID_EDIT_MENU)
2980-
#error "DWIN_LCD_PROUI does not support PID_EDIT_MENU."
2981-
#elif ENABLED(PID_AUTOTUNE_MENU)
2982-
#error "DWIN_LCD_PROUI does not support PID_AUTOTUNE_MENU."
2977+
#elif EITHER(PID_EDIT_MENU, PID_AUTOTUNE_MENU)
2978+
#error "DWIN_LCD_PROUI does not support PID_EDIT_MENU or PID_AUTOTUNE_MENU."
29832979
#elif ENABLED(LEVEL_BED_CORNERS)
29842980
#error "DWIN_LCD_PROUI does not support LEVEL_BED_CORNERS."
29852981
#elif BOTH(LCD_BED_LEVELING, PROBE_MANUALLY)

Marlin/src/lcd/menu/menu_advanced.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void menu_backlash();
256256
void menu_advanced_temperature() {
257257
START_MENU();
258258
BACK_ITEM(MSG_ADVANCED_SETTINGS);
259+
259260
//
260261
// Autotemp, Min, Max, Fact
261262
//
@@ -325,7 +326,7 @@ void menu_backlash();
325326

326327
HOTEND_PID_EDIT_MENU_ITEMS(0);
327328
#if ENABLED(PID_PARAMS_PER_HOTEND)
328-
REPEAT_S(1, HOTENDS, HOTEND_PID_EDIT_MENU_ITEMS)
329+
REPEAT_S(1, HOTENDS, HOTEND_PID_EDIT_MENU_ITEMS);
329330
#endif
330331
#endif
331332

Marlin/src/module/probe.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,21 @@ FORCE_INLINE void probe_specific_action(const bool deploy) {
415415

416416
#endif
417417

418+
/**
419+
* Print an error and stop()
420+
*/
421+
void Probe::probe_error_stop() {
422+
SERIAL_ERROR_START();
423+
SERIAL_ECHOPGM(STR_STOP_PRE);
424+
#if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY)
425+
SERIAL_ECHOPGM(STR_STOP_UNHOMED);
426+
#elif ENABLED(BLTOUCH)
427+
SERIAL_ECHOPGM(STR_STOP_BLTOUCH);
428+
#endif
429+
SERIAL_ECHOLNPGM(STR_STOP_POST);
430+
stop();
431+
}
432+
418433
/**
419434
* Attempt to deploy or stow the probe
420435
*
@@ -443,8 +458,7 @@ bool Probe::set_deployed(const bool deploy) {
443458

444459
#if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY)
445460
if (homing_needed_error(TERN_(Z_PROBE_SLED, _BV(X_AXIS)))) {
446-
SERIAL_ERROR_MSG(STR_STOP_UNHOMED);
447-
stop();
461+
probe_error_stop();
448462
return true;
449463
}
450464
#endif
@@ -484,15 +498,12 @@ bool Probe::set_deployed(const bool deploy) {
484498
}
485499

486500
/**
487-
* @brief Used by run_z_probe to do a single Z probe move.
501+
* @brief Move down until the probe triggers or the low limit is reached
502+
* Used by run_z_probe to do a single Z probe move.
488503
*
489504
* @param z Z destination
490505
* @param fr_mm_s Feedrate in mm/s
491506
* @return true to indicate an error
492-
*/
493-
494-
/**
495-
* @brief Move down until the probe triggers or the low limit is reached
496507
*
497508
* @details Used by run_z_probe to get each bed Z height measurement.
498509
* Sets current_position.z to the height where the probe triggered

Marlin/src/module/probe.h

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class Probe {
7878
static void preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp);
7979
#endif
8080

81+
static void probe_error_stop();
82+
8183
static bool set_deployed(const bool deploy);
8284

8385
#if IS_KINEMATIC

Marlin/src/module/temperature.cpp

+20-16
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,15 @@ volatile bool Temperature::raw_temps_ready = false;
632632
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(isbed ? PID_BED_START : PID_EXTR_START));
633633

634634
if (target > GHV(CHAMBER_MAX_TARGET, BED_MAX_TARGET, temp_range[heater_id].maxtemp - (HOTEND_OVERSHOOT))) {
635+
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
635636
SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH);
636637
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH));
637638
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TEMP_TOO_HIGH));
638639
TERN_(HOST_PROMPT_SUPPORT, hostui.notify(GET_TEXT_F(MSG_PID_TEMP_TOO_HIGH)));
639640
return;
640641
}
641642

643+
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
642644
SERIAL_ECHOLNPGM(STR_PID_AUTOTUNE_START);
643645

644646
disable_all_heaters();
@@ -654,10 +656,11 @@ volatile bool Temperature::raw_temps_ready = false;
654656

655657
TERN_(NO_FAN_SLOWING_IN_PID_TUNING, adaptive_fan_slowing = false);
656658

657-
// PID Tuning loop
658-
wait_for_heatup = true; // Can be interrupted with M108
659659
LCD_MESSAGE(MSG_HEATING);
660-
while (wait_for_heatup) {
660+
661+
// PID Tuning loop
662+
wait_for_heatup = true;
663+
while (wait_for_heatup) { // Can be interrupted with M108
661664

662665
const millis_t ms = millis();
663666

@@ -723,6 +726,7 @@ volatile bool Temperature::raw_temps_ready = false;
723726
#define MAX_OVERSHOOT_PID_AUTOTUNE 30
724727
#endif
725728
if (current_temp > target + MAX_OVERSHOOT_PID_AUTOTUNE) {
729+
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
726730
SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH);
727731
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH));
728732
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TEMP_TOO_HIGH));
@@ -765,11 +769,13 @@ volatile bool Temperature::raw_temps_ready = false;
765769
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TUNING_TIMEOUT));
766770
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TUNING_TIMEOUT));
767771
TERN_(HOST_PROMPT_SUPPORT, hostui.notify(GET_TEXT_F(MSG_PID_TIMEOUT)));
772+
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
768773
SERIAL_ECHOLNPGM(STR_PID_TIMEOUT);
769774
break;
770775
}
771776

772777
if (cycles > ncycles && cycles > 2) {
778+
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
773779
SERIAL_ECHOLNPGM(STR_PID_AUTOTUNE_FINISHED);
774780
TERN_(HOST_PROMPT_SUPPORT, hostui.notify(GET_TEXT_F(MSG_PID_AUTOTUNE_DONE)));
775781

@@ -869,7 +875,6 @@ volatile bool Temperature::raw_temps_ready = false;
869875
MPC_t& constants = hotend.constants;
870876

871877
// move to center of bed, just above bed height and cool with max fan
872-
SERIAL_ECHOLNPGM("Moving to tuning position");
873878
TERN_(HAS_FAN, zero_fan_speeds());
874879
disable_all_heaters();
875880
TERN_(HAS_FAN, set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 255));
@@ -896,15 +901,15 @@ volatile bool Temperature::raw_temps_ready = false;
896901
next_test_ms += 10000UL;
897902
}
898903
}
904+
899905
TERN_(HAS_FAN, set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 0));
900906
TERN_(HAS_FAN, planner.sync_fan_speeds(fan_speed));
901907

902908
hotend.modeled_ambient_temp = ambient_temp;
903909

904910
SERIAL_ECHOLNPGM("Heating to 200C");
905911
hotend.soft_pwm_amount = MPC_MAX >> 1;
906-
const millis_t heat_start_time = ms;
907-
next_test_ms = ms;
912+
const millis_t heat_start_time = next_test_ms = ms;
908913
celsius_float_t temp_samples[16];
909914
uint8_t sample_count = 0;
910915
uint16_t sample_distance = 1;
@@ -935,7 +940,7 @@ volatile bool Temperature::raw_temps_ready = false;
935940
}
936941
hotend.soft_pwm_amount = 0;
937942

938-
// calculate physical constants from three equally spaced samples
943+
// Calculate physical constants from three equally-spaced samples
939944
sample_count = (sample_count + 1) / 2 * 2 - 1;
940945
const float t1 = temp_samples[0],
941946
t2 = temp_samples[(sample_count - 1) >> 1],
@@ -951,14 +956,13 @@ volatile bool Temperature::raw_temps_ready = false;
951956
hotend.modeled_block_temp = asymp_temp + (ambient_temp - asymp_temp) * exp(-block_responsiveness * (ms - heat_start_time) / 1000.0f);
952957
hotend.modeled_sensor_temp = current_temp;
953958

954-
// let the system stabilise under MPC control then get a better measure of ambient loss without and with fan
959+
// Allow the system to stabilize under MPC, then get a better measure of ambient loss with and without fan
955960
SERIAL_ECHOLNPGM("Measuring ambient heatloss at target ", hotend.modeled_block_temp);
956961
hotend.target = hotend.modeled_block_temp;
957962
next_test_ms = ms + MPC_dT * 1000;
958-
constexpr millis_t settle_time = 20000UL,
959-
test_length = 20000UL;
963+
constexpr millis_t settle_time = 20000UL, test_duration = 20000UL;
960964
millis_t settle_end_ms = ms + settle_time,
961-
test_end_ms = settle_end_ms + test_length;
965+
test_end_ms = settle_end_ms + test_duration;
962966
float total_energy_fan0 = 0.0f;
963967
#if HAS_FAN
964968
bool fan0_done = false;
@@ -981,7 +985,7 @@ volatile bool Temperature::raw_temps_ready = false;
981985
set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 255);
982986
planner.sync_fan_speeds(fan_speed);
983987
settle_end_ms = ms + settle_time;
984-
test_end_ms = settle_end_ms + test_length;
988+
test_end_ms = settle_end_ms + test_duration;
985989
fan0_done = true;
986990
}
987991
else if (ELAPSED(ms, settle_end_ms) && !ELAPSED(ms, test_end_ms))
@@ -999,11 +1003,11 @@ volatile bool Temperature::raw_temps_ready = false;
9991003
}
10001004
}
10011005

1002-
const float power_fan0 = total_energy_fan0 * 1000 / test_length;
1006+
const float power_fan0 = total_energy_fan0 * 1000 / test_duration;
10031007
constants.ambient_xfer_coeff_fan0 = power_fan0 / (hotend.target - ambient_temp);
10041008

10051009
#if HAS_FAN
1006-
const float power_fan255 = total_energy_fan255 * 1000 / test_length,
1010+
const float power_fan255 = total_energy_fan255 * 1000 / test_duration,
10071011
ambient_xfer_coeff_fan255 = power_fan255 / (hotend.target - ambient_temp);
10081012
constants.fan255_adjustment = ambient_xfer_coeff_fan255 - constants.ambient_xfer_coeff_fan0;
10091013
#endif
@@ -1369,8 +1373,8 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
13691373
#endif
13701374

13711375
#elif ENABLED(MPCTEMP)
1372-
MPCHeaterInfo& hotend = temp_hotend[ee];
1373-
MPC_t& constants = hotend.constants;
1376+
MPCHeaterInfo &hotend = temp_hotend[ee];
1377+
MPC_t &constants = hotend.constants;
13741378

13751379
// At startup, initialize modeled temperatures
13761380
if (isnan(hotend.modeled_block_temp)) {

0 commit comments

Comments
 (0)