Bläddra i källkod

Reduce size of heater state print code

Scott Lahteine 8 år sedan
förälder
incheckning
da8e946efb
1 ändrade filer med 56 tillägg och 46 borttagningar
  1. 56
    46
      Marlin/Marlin_main.cpp

+ 56
- 46
Marlin/Marlin_main.cpp Visa fil

@@ -5889,7 +5889,7 @@ inline void gcode_M17() {
5889 5889
   }
5890 5890
 
5891 5891
   static bool pause_print(const float &retract, const float &z_lift, const float &x_pos, const float &y_pos,
5892
-                          const float &unload_length = 0 , int8_t max_beep_count = 0, bool show_lcd = false
5892
+                          const float &unload_length = 0 , const int8_t max_beep_count = 0, const bool show_lcd = false
5893 5893
   ) {
5894 5894
     if (move_away_flag) return false; // already paused
5895 5895
 
@@ -5989,7 +5989,7 @@ inline void gcode_M17() {
5989 5989
     return true;
5990 5990
   }
5991 5991
 
5992
-  static void wait_for_filament_reload(int8_t max_beep_count = 0) {
5992
+  static void wait_for_filament_reload(const int8_t max_beep_count = 0) {
5993 5993
     bool nozzle_timed_out = false;
5994 5994
 
5995 5995
     // Wait for filament insert by user and press button
@@ -6014,7 +6014,7 @@ inline void gcode_M17() {
6014 6014
     KEEPALIVE_STATE(IN_HANDLER);
6015 6015
   }
6016 6016
 
6017
-  static void resume_print(const float &load_length = 0, const float &initial_extrude_length = 0, int8_t max_beep_count = 0) {
6017
+  static void resume_print(const float &load_length = 0, const float &initial_extrude_length = 0, const int8_t max_beep_count = 0) {
6018 6018
     bool nozzle_timed_out = false;
6019 6019
 
6020 6020
     if (!move_away_flag) return;
@@ -6974,39 +6974,57 @@ inline void gcode_M104() {
6974 6974
 
6975 6975
 #if HAS_TEMP_HOTEND || HAS_TEMP_BED
6976 6976
 
6977
+  void print_heater_state(const float &c, const float &t,
6978
+    #if ENABLED(SHOW_TEMP_ADC_VALUES)
6979
+      const float r,
6980
+    #endif
6981
+    const int8_t e=-2
6982
+  ) {
6983
+    SERIAL_PROTOCOLCHAR(' ');
6984
+    SERIAL_PROTOCOLCHAR(
6985
+      #if HAS_TEMP_BED && HAS_TEMP_HOTEND
6986
+        e == -1 ? 'B' : 'T'
6987
+      #elif HAS_TEMP_HOTEND
6988
+        'T'
6989
+      #else
6990
+        'B'
6991
+      #endif
6992
+    );
6993
+    #if HOTENDS > 1
6994
+      if (e >= 0) SERIAL_PROTOCOLCHAR('0' + e);
6995
+    #endif
6996
+    SERIAL_PROTOCOLCHAR(':');
6997
+    SERIAL_PROTOCOL(c);
6998
+    SERIAL_PROTOCOLPAIR(" /" , t);
6999
+    #if ENABLED(SHOW_TEMP_ADC_VALUES)
7000
+      SERIAL_PROTOCOLPAIR(" (", r / OVERSAMPLENR);
7001
+      SERIAL_PROTOCOLCHAR(')');
7002
+    #endif
7003
+  }
7004
+
6977 7005
   void print_heaterstates() {
6978 7006
     #if HAS_TEMP_HOTEND
6979
-      SERIAL_PROTOCOLPGM(" T:");
6980
-      SERIAL_PROTOCOL(thermalManager.degHotend(target_extruder));
6981
-      SERIAL_PROTOCOLPGM(" /");
6982
-      SERIAL_PROTOCOL(thermalManager.degTargetHotend(target_extruder));
6983
-      #if ENABLED(SHOW_TEMP_ADC_VALUES)
6984
-        SERIAL_PROTOCOLPAIR(" (", thermalManager.rawHotendTemp(target_extruder) / OVERSAMPLENR);
6985
-        SERIAL_PROTOCOLCHAR(')');
6986
-      #endif
7007
+      print_heater_state(thermalManager.degHotend(target_extruder), thermalManager.degTargetHotend(target_extruder)
7008
+        #if ENABLED(SHOW_TEMP_ADC_VALUES)
7009
+          , thermalManager.rawHotendTemp(target_extruder)
7010
+        #endif
7011
+      );
6987 7012
     #endif
6988 7013
     #if HAS_TEMP_BED
6989
-      SERIAL_PROTOCOLPGM(" B:");
6990
-      SERIAL_PROTOCOL(thermalManager.degBed());
6991
-      SERIAL_PROTOCOLPGM(" /");
6992
-      SERIAL_PROTOCOL(thermalManager.degTargetBed());
6993
-      #if ENABLED(SHOW_TEMP_ADC_VALUES)
6994
-        SERIAL_PROTOCOLPAIR(" (", thermalManager.rawBedTemp() / OVERSAMPLENR);
6995
-        SERIAL_PROTOCOLCHAR(')');
6996
-      #endif
7014
+      print_heater_state(thermalManager.degBed(), thermalManager.degTargetBed(),
7015
+        #if ENABLED(SHOW_TEMP_ADC_VALUES)
7016
+          thermalManager.rawBedTemp(),
7017
+        #endif
7018
+        -1 // BED
7019
+      );
6997 7020
     #endif
6998 7021
     #if HOTENDS > 1
6999
-      HOTEND_LOOP() {
7000
-        SERIAL_PROTOCOLPAIR(" T", e);
7001
-        SERIAL_PROTOCOLCHAR(':');
7002
-        SERIAL_PROTOCOL(thermalManager.degHotend(e));
7003
-        SERIAL_PROTOCOLPGM(" /");
7004
-        SERIAL_PROTOCOL(thermalManager.degTargetHotend(e));
7022
+      HOTEND_LOOP() print_heater_state(thermalManager.degHotend(e), thermalManager.degTargetHotend(e),
7005 7023
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
7006
-          SERIAL_PROTOCOLPAIR(" (", thermalManager.rawHotendTemp(e) / OVERSAMPLENR);
7007
-          SERIAL_PROTOCOLCHAR(')');
7024
+          thermalManager.rawHotendTemp(e),
7008 7025
         #endif
7009
-      }
7026
+        e
7027
+      );
7010 7028
     #endif
7011 7029
     SERIAL_PROTOCOLPGM(" @:");
7012 7030
     SERIAL_PROTOCOL(thermalManager.getHeaterPower(target_extruder));
@@ -7206,16 +7224,12 @@ inline void gcode_M109() {
7206 7224
       print_heaterstates();
7207 7225
       #if TEMP_RESIDENCY_TIME > 0
7208 7226
         SERIAL_PROTOCOLPGM(" W:");
7209
-        if (residency_start_ms) {
7210
-          long rem = (((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL;
7211
-          SERIAL_PROTOCOLLN(rem);
7212
-        }
7213
-        else {
7214
-          SERIAL_PROTOCOLLNPGM("?");
7215
-        }
7216
-      #else
7217
-        SERIAL_EOL();
7227
+        if (residency_start_ms)
7228
+          SERIAL_PROTOCOL(long((((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
7229
+        else
7230
+          SERIAL_PROTOCOLCHAR('?');
7218 7231
       #endif
7232
+      SERIAL_EOL();
7219 7233
     }
7220 7234
 
7221 7235
     idle();
@@ -7339,16 +7353,12 @@ inline void gcode_M109() {
7339 7353
         print_heaterstates();
7340 7354
         #if TEMP_BED_RESIDENCY_TIME > 0
7341 7355
           SERIAL_PROTOCOLPGM(" W:");
7342
-          if (residency_start_ms) {
7343
-            long rem = (((TEMP_BED_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL;
7344
-            SERIAL_PROTOCOLLN(rem);
7345
-          }
7346
-          else {
7347
-            SERIAL_PROTOCOLLNPGM("?");
7348
-          }
7349
-        #else
7350
-          SERIAL_EOL();
7356
+          if (residency_start_ms)
7357
+            SERIAL_PROTOCOL(long((((TEMP_BED_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
7358
+          else
7359
+            SERIAL_PROTOCOLCHAR('?');
7351 7360
         #endif
7361
+        SERIAL_EOL();
7352 7362
       }
7353 7363
 
7354 7364
       idle();

Laddar…
Avbryt
Spara