Browse Source

🎨 Misc. cleanup, string optimization

Scott Lahteine 2 years ago
parent
commit
e2353be24f

+ 3
- 3
Marlin/Configuration.h View File

@@ -766,8 +766,8 @@
766 766
   #define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
767 767
                                   // is more than PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
768 768
 
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)
771 771
 #endif
772 772
 
773 773
 // @section extruder
@@ -1970,7 +1970,7 @@
1970 1970
  *   M502 - Revert settings to "factory" defaults. (Follow with M500 to init the EEPROM.)
1971 1971
  */
1972 1972
 //#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!
1974 1974
 #define EEPROM_CHITCHAT       // Give feedback on EEPROM commands. Disable to save PROGMEM.
1975 1975
 #define EEPROM_BOOT_SILENT    // Keep M503 quiet and only give errors during first load
1976 1976
 #if ENABLED(EEPROM_SETTINGS)

+ 6
- 2
Marlin/src/MarlinCore.cpp View File

@@ -412,7 +412,9 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
412 412
   if (do_reset_timeout) gcode.reset_stepper_timeout(ms);
413 413
 
414 414
   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);
416 418
     kill();
417 419
   }
418 420
 
@@ -473,7 +475,9 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
473 475
     // KILL the machine
474 476
     // ----------------------------------------------------------------
475 477
     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);
477 481
       kill();
478 482
     }
479 483
   #endif

+ 13
- 9
Marlin/src/core/language.h View File

@@ -199,16 +199,20 @@
199 199
 #define STR_FILAMENT_CHANGE_INSERT_M108     "Insert filament and send M108"
200 200
 #define STR_FILAMENT_CHANGE_WAIT_M108       "Send M108 to resume"
201 201
 
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"
206 209
 
207 210
 // 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"
212 216
 #define STR_BIAS                            " bias: "
213 217
 #define STR_D_COLON                         " d: "
214 218
 #define STR_T_MIN                           " min: "
@@ -219,7 +223,7 @@
219 223
 #define STR_KP                              " Kp: "
220 224
 #define STR_KI                              " Ki: "
221 225
 #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"
223 227
 #define STR_PID_DEBUG                       " PID_DEBUG "
224 228
 #define STR_PID_DEBUG_INPUT                 ": Input "
225 229
 #define STR_PID_DEBUG_OUTPUT                " Output "

+ 4
- 11
Marlin/src/feature/bltouch.cpp View File

@@ -111,11 +111,8 @@ bool BLTouch::deploy_proc() {
111 111
     // Last attempt to DEPLOY
112 112
     if (_deploy_query_alarm()) {
113 113
       // 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
119 116
       return true;                         // Tell our caller we goofed in case he cares to know
120 117
     }
121 118
   }
@@ -153,12 +150,8 @@ bool BLTouch::stow_proc() {
153 150
                                            // But one more STOW will catch that
154 151
     // Last attempt to STOW
155 152
     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
162 155
       return true;                         // Tell our caller we goofed in case he cares to know
163 156
     }
164 157
   }

+ 1
- 0
Marlin/src/gcode/temp/M303.cpp View File

@@ -71,6 +71,7 @@ void GcodeSuite::M303() {
71 71
       case H_CHAMBER: default_temp = PREHEAT_1_TEMP_CHAMBER; break;
72 72
     #endif
73 73
     default:
74
+      SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
74 75
       SERIAL_ECHOLNPGM(STR_PID_BAD_HEATER_ID);
75 76
       TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM));
76 77
       TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_BAD_EXTRUDER_NUM));

+ 4
- 8
Marlin/src/inc/SanityCheck.h View File

@@ -2960,10 +2960,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
2960 2960
 #if ENABLED(DWIN_CREALITY_LCD)
2961 2961
   #if DISABLED(SDSUPPORT)
2962 2962
     #error "DWIN_CREALITY_LCD requires SDSUPPORT to be enabled."
2963
-  #elif ENABLED(PID_EDIT_MENU)
2964
-    #error "DWIN_CREALITY_LCD does not support PID_EDIT_MENU."
2965
-  #elif ENABLED(PID_AUTOTUNE_MENU)
2966
-    #error "DWIN_CREALITY_LCD does not support PID_AUTOTUNE_MENU."
2963
+  #elif EITHER(PID_EDIT_MENU, PID_AUTOTUNE_MENU)
2964
+    #error "DWIN_CREALITY_LCD does not support PID_EDIT_MENU or PID_AUTOTUNE_MENU."
2967 2965
   #elif ENABLED(LEVEL_BED_CORNERS)
2968 2966
     #error "DWIN_CREALITY_LCD does not support LEVEL_BED_CORNERS."
2969 2967
   #elif BOTH(LCD_BED_LEVELING, PROBE_MANUALLY)
@@ -2972,10 +2970,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
2972 2970
 #elif ENABLED(DWIN_LCD_PROUI)
2973 2971
   #if DISABLED(SDSUPPORT)
2974 2972
     #error "DWIN_LCD_PROUI requires SDSUPPORT to be enabled."
2975
-  #elif ENABLED(PID_EDIT_MENU)
2976
-    #error "DWIN_LCD_PROUI does not support PID_EDIT_MENU."
2977
-  #elif ENABLED(PID_AUTOTUNE_MENU)
2978
-    #error "DWIN_LCD_PROUI does not support PID_AUTOTUNE_MENU."
2973
+  #elif EITHER(PID_EDIT_MENU, PID_AUTOTUNE_MENU)
2974
+    #error "DWIN_LCD_PROUI does not support PID_EDIT_MENU or PID_AUTOTUNE_MENU."
2979 2975
   #elif ENABLED(LEVEL_BED_CORNERS)
2980 2976
     #error "DWIN_LCD_PROUI does not support LEVEL_BED_CORNERS."
2981 2977
   #elif BOTH(LCD_BED_LEVELING, PROBE_MANUALLY)

+ 2
- 1
Marlin/src/lcd/menu/menu_advanced.cpp View File

@@ -256,6 +256,7 @@ void menu_backlash();
256 256
   void menu_advanced_temperature() {
257 257
     START_MENU();
258 258
     BACK_ITEM(MSG_ADVANCED_SETTINGS);
259
+
259 260
     //
260 261
     // Autotemp, Min, Max, Fact
261 262
     //
@@ -325,7 +326,7 @@ void menu_backlash();
325 326
 
326 327
       HOTEND_PID_EDIT_MENU_ITEMS(0);
327 328
       #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);
329 330
       #endif
330 331
     #endif
331 332
 

+ 18
- 7
Marlin/src/module/probe.cpp View File

@@ -416,6 +416,21 @@ FORCE_INLINE void probe_specific_action(const bool deploy) {
416 416
 #endif
417 417
 
418 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
+
433
+/**
419 434
  * Attempt to deploy or stow the probe
420 435
  *
421 436
  * Return TRUE if the probe could not be deployed/stowed
@@ -443,8 +458,7 @@ bool Probe::set_deployed(const bool deploy) {
443 458
 
444 459
   #if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY)
445 460
     if (homing_needed_error(TERN_(Z_PROBE_SLED, _BV(X_AXIS)))) {
446
-      SERIAL_ERROR_MSG(STR_STOP_UNHOMED);
447
-      stop();
461
+      probe_error_stop();
448 462
       return true;
449 463
     }
450 464
   #endif
@@ -484,15 +498,12 @@ bool Probe::set_deployed(const bool deploy) {
484 498
 }
485 499
 
486 500
 /**
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.
488 503
  *
489 504
  * @param  z        Z destination
490 505
  * @param  fr_mm_s  Feedrate in mm/s
491 506
  * @return true to indicate an error
492
- */
493
-
494
-/**
495
- * @brief Move down until the probe triggers or the low limit is reached
496 507
  *
497 508
  * @details Used by run_z_probe to get each bed Z height measurement.
498 509
  *          Sets current_position.z to the height where the probe triggered

+ 2
- 0
Marlin/src/module/probe.h View File

@@ -78,6 +78,8 @@ public:
78 78
       static void preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp);
79 79
     #endif
80 80
 
81
+    static void probe_error_stop();
82
+
81 83
     static bool set_deployed(const bool deploy);
82 84
 
83 85
     #if IS_KINEMATIC

+ 20
- 16
Marlin/src/module/temperature.cpp View File

@@ -632,6 +632,7 @@ volatile bool Temperature::raw_temps_ready = false;
632 632
     TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(isbed ? PID_BED_START : PID_EXTR_START));
633 633
 
634 634
     if (target > GHV(CHAMBER_MAX_TARGET, BED_MAX_TARGET, temp_range[heater_id].maxtemp - (HOTEND_OVERSHOOT))) {
635
+      SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
635 636
       SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH);
636 637
       TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH));
637 638
       TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TEMP_TOO_HIGH));
@@ -639,6 +640,7 @@ volatile bool Temperature::raw_temps_ready = false;
639 640
       return;
640 641
     }
641 642
 
643
+    SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
642 644
     SERIAL_ECHOLNPGM(STR_PID_AUTOTUNE_START);
643 645
 
644 646
     disable_all_heaters();
@@ -654,10 +656,11 @@ volatile bool Temperature::raw_temps_ready = false;
654 656
 
655 657
     TERN_(NO_FAN_SLOWING_IN_PID_TUNING, adaptive_fan_slowing = false);
656 658
 
657
-    // PID Tuning loop
658
-    wait_for_heatup = true; // Can be interrupted with M108
659 659
     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
661 664
 
662 665
       const millis_t ms = millis();
663 666
 
@@ -723,6 +726,7 @@ volatile bool Temperature::raw_temps_ready = false;
723 726
         #define MAX_OVERSHOOT_PID_AUTOTUNE 30
724 727
       #endif
725 728
       if (current_temp > target + MAX_OVERSHOOT_PID_AUTOTUNE) {
729
+        SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
726 730
         SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH);
727 731
         TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH));
728 732
         TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TEMP_TOO_HIGH));
@@ -765,11 +769,13 @@ volatile bool Temperature::raw_temps_ready = false;
765 769
         TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TUNING_TIMEOUT));
766 770
         TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TUNING_TIMEOUT));
767 771
         TERN_(HOST_PROMPT_SUPPORT, hostui.notify(GET_TEXT_F(MSG_PID_TIMEOUT)));
772
+        SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
768 773
         SERIAL_ECHOLNPGM(STR_PID_TIMEOUT);
769 774
         break;
770 775
       }
771 776
 
772 777
       if (cycles > ncycles && cycles > 2) {
778
+        SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
773 779
         SERIAL_ECHOLNPGM(STR_PID_AUTOTUNE_FINISHED);
774 780
         TERN_(HOST_PROMPT_SUPPORT, hostui.notify(GET_TEXT_F(MSG_PID_AUTOTUNE_DONE)));
775 781
 
@@ -869,7 +875,6 @@ volatile bool Temperature::raw_temps_ready = false;
869 875
     MPC_t& constants = hotend.constants;
870 876
 
871 877
     // move to center of bed, just above bed height and cool with max fan
872
-    SERIAL_ECHOLNPGM("Moving to tuning position");
873 878
     TERN_(HAS_FAN, zero_fan_speeds());
874 879
     disable_all_heaters();
875 880
     TERN_(HAS_FAN, set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 255));
@@ -896,6 +901,7 @@ volatile bool Temperature::raw_temps_ready = false;
896 901
         next_test_ms += 10000UL;
897 902
       }
898 903
     }
904
+
899 905
     TERN_(HAS_FAN, set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 0));
900 906
     TERN_(HAS_FAN, planner.sync_fan_speeds(fan_speed));
901 907
 
@@ -903,8 +909,7 @@ volatile bool Temperature::raw_temps_ready = false;
903 909
 
904 910
     SERIAL_ECHOLNPGM("Heating to 200C");
905 911
     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;
908 913
     celsius_float_t temp_samples[16];
909 914
     uint8_t sample_count = 0;
910 915
     uint16_t sample_distance = 1;
@@ -935,7 +940,7 @@ volatile bool Temperature::raw_temps_ready = false;
935 940
     }
936 941
     hotend.soft_pwm_amount = 0;
937 942
 
938
-    // calculate physical constants from three equally spaced samples
943
+    // Calculate physical constants from three equally-spaced samples
939 944
     sample_count = (sample_count + 1) / 2 * 2 - 1;
940 945
     const float t1 = temp_samples[0],
941 946
                 t2 = temp_samples[(sample_count - 1) >> 1],
@@ -951,14 +956,13 @@ volatile bool Temperature::raw_temps_ready = false;
951 956
     hotend.modeled_block_temp = asymp_temp + (ambient_temp - asymp_temp) * exp(-block_responsiveness * (ms - heat_start_time) / 1000.0f);
952 957
     hotend.modeled_sensor_temp = current_temp;
953 958
 
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
955 960
     SERIAL_ECHOLNPGM("Measuring ambient heatloss at target ", hotend.modeled_block_temp);
956 961
     hotend.target = hotend.modeled_block_temp;
957 962
     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;
960 964
     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;
962 966
     float total_energy_fan0 = 0.0f;
963 967
     #if HAS_FAN
964 968
       bool fan0_done = false;
@@ -981,7 +985,7 @@ volatile bool Temperature::raw_temps_ready = false;
981 985
             set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 255);
982 986
             planner.sync_fan_speeds(fan_speed);
983 987
             settle_end_ms = ms + settle_time;
984
-            test_end_ms = settle_end_ms + test_length;
988
+            test_end_ms = settle_end_ms + test_duration;
985 989
             fan0_done = true;
986 990
           }
987 991
           else if (ELAPSED(ms, settle_end_ms) && !ELAPSED(ms, test_end_ms))
@@ -999,11 +1003,11 @@ volatile bool Temperature::raw_temps_ready = false;
999 1003
       }
1000 1004
     }
1001 1005
 
1002
-    const float power_fan0 = total_energy_fan0 * 1000 / test_length;
1006
+    const float power_fan0 = total_energy_fan0 * 1000 / test_duration;
1003 1007
     constants.ambient_xfer_coeff_fan0 = power_fan0 / (hotend.target - ambient_temp);
1004 1008
 
1005 1009
     #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,
1007 1011
                   ambient_xfer_coeff_fan255 = power_fan255 / (hotend.target - ambient_temp);
1008 1012
       constants.fan255_adjustment = ambient_xfer_coeff_fan255 - constants.ambient_xfer_coeff_fan0;
1009 1013
     #endif
@@ -1369,8 +1373,8 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
1369 1373
       #endif
1370 1374
 
1371 1375
     #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;
1374 1378
 
1375 1379
       // At startup, initialize modeled temperatures
1376 1380
       if (isnan(hotend.modeled_block_temp)) {

Loading…
Cancel
Save