Browse Source

Merge pull request #3113 from jbrazio/bugfix/3061-stop-print-time-counter

Stop print timer with M105/M109
Scott Lahteine 8 years ago
parent
commit
06332f20be

+ 5
- 0
Marlin/Marlin.h View File

@@ -356,4 +356,9 @@ extern uint8_t active_extruder;
356 356
 
357 357
 extern void calculate_volumetric_multipliers();
358 358
 
359
+// Print job timer related functions
360
+millis_t print_job_timer();
361
+bool print_job_start(millis_t t = 0);
362
+bool print_job_stop(bool force = false);
363
+
359 364
 #endif //MARLIN_H

+ 63
- 10
Marlin/Marlin_main.cpp View File

@@ -977,9 +977,9 @@ void get_command() {
977 977
       ) {
978 978
         if (card_eof) {
979 979
           SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
980
-          print_job_stop_ms = millis();
980
+          print_job_stop(true);
981 981
           char time[30];
982
-          millis_t t = (print_job_stop_ms - print_job_start_ms) / 1000;
982
+          millis_t t = print_job_timer();
983 983
           int hours = t / 60 / 60, minutes = (t / 60) % 60;
984 984
           sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
985 985
           SERIAL_ECHO_START;
@@ -3454,7 +3454,7 @@ inline void gcode_M17() {
3454 3454
    */
3455 3455
   inline void gcode_M24() {
3456 3456
     card.startFileprint();
3457
-    print_job_start_ms = millis();
3457
+    print_job_start();
3458 3458
   }
3459 3459
 
3460 3460
   /**
@@ -3510,8 +3510,7 @@ inline void gcode_M17() {
3510 3510
  * M31: Get the time since the start of SD Print (or last M109)
3511 3511
  */
3512 3512
 inline void gcode_M31() {
3513
-  print_job_stop_ms = millis();
3514
-  millis_t t = (print_job_stop_ms - print_job_start_ms) / 1000;
3513
+  millis_t t = print_job_timer();
3515 3514
   int min = t / 60, sec = t % 60;
3516 3515
   char time[30];
3517 3516
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
@@ -3545,8 +3544,9 @@ inline void gcode_M31() {
3545 3544
         card.setIndex(code_value_short());
3546 3545
 
3547 3546
       card.startFileprint();
3548
-      if (!call_procedure)
3549
-        print_job_start_ms = millis(); //procedure calls count as normal print time.
3547
+
3548
+      // Procedure calls count as normal print time.
3549
+      if (!call_procedure) print_job_start();
3550 3550
     }
3551 3551
   }
3552 3552
 
@@ -3884,6 +3884,8 @@ inline void gcode_M104() {
3884 3884
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
3885 3885
     #endif
3886 3886
   }
3887
+
3888
+  print_job_stop();
3887 3889
 }
3888 3890
 
3889 3891
 #if HAS_TEMP_0 || HAS_TEMP_BED || ENABLED(HEATER_0_USES_MAX6675)
@@ -4008,11 +4010,12 @@ inline void gcode_M105() {
4008 4010
 inline void gcode_M109() {
4009 4011
   bool no_wait_for_cooling = true;
4010 4012
 
4013
+  // Start hook must happen before setTargetHotend()
4014
+  print_job_start();
4015
+
4011 4016
   if (setTargetedHotend(109)) return;
4012 4017
   if (marlin_debug_flags & DEBUG_DRYRUN) return;
4013 4018
 
4014
-  LCD_MESSAGEPGM(MSG_HEATING);
4015
-
4016 4019
   no_wait_for_cooling = code_seen('S');
4017 4020
   if (no_wait_for_cooling || code_seen('R')) {
4018 4021
     float temp = code_value();
@@ -4021,8 +4024,12 @@ inline void gcode_M109() {
4021 4024
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
4022 4025
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4023 4026
     #endif
4027
+
4028
+    if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4024 4029
   }
4025 4030
 
4031
+  if (print_job_stop()) LCD_MESSAGEPGM(WELCOME_MSG);
4032
+
4026 4033
   #if ENABLED(AUTOTEMP)
4027 4034
     autotemp_enabled = code_seen('F');
4028 4035
     if (autotemp_enabled) autotemp_factor = code_value();
@@ -4082,7 +4089,6 @@ inline void gcode_M109() {
4082 4089
   } // while(!cancel_heatup && TEMP_CONDITIONS)
4083 4090
 
4084 4091
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4085
-  print_job_start_ms = previous_cmd_ms;
4086 4092
 }
4087 4093
 
4088 4094
 #if HAS_TEMP_BED
@@ -7398,3 +7404,50 @@ void calculate_volumetric_multipliers() {
7398 7404
   for (int i = 0; i < EXTRUDERS; i++)
7399 7405
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
7400 7406
 }
7407
+
7408
+/**
7409
+ * Start the print job timer
7410
+ *
7411
+ * The print job is only started if all extruders have their target temp at zero
7412
+ * otherwise the print job timew would be reset everytime a M109 is received.
7413
+ *
7414
+ * @param t start timer timestamp
7415
+ *
7416
+ * @return true if the timer was started at function call
7417
+ */
7418
+bool print_job_start(millis_t t /* = 0 */) {
7419
+  for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
7420
+  print_job_start_ms = (t) ? t : millis();
7421
+  print_job_stop_ms = 0;
7422
+  return true;
7423
+}
7424
+
7425
+/**
7426
+ * Output the print job timer in seconds
7427
+ *
7428
+ * @return the number of seconds
7429
+ */
7430
+millis_t print_job_timer() {
7431
+  if (!print_job_start_ms) return 0;
7432
+  return (((print_job_stop_ms > print_job_start_ms)
7433
+    ? print_job_stop_ms : millis()) - print_job_start_ms) / 1000;
7434
+}
7435
+
7436
+/**
7437
+ * Check if the running print job has finished and stop the timer
7438
+ *
7439
+ * When the target temperature for all extruders is zero then we assume that the
7440
+ * print job has finished printing. There are some special conditions under which
7441
+ * this assumption may not be valid: If during a print job for some reason the
7442
+ * user decides to bring a nozzle temp down and only then heat the other afterwards.
7443
+ *
7444
+ * @param force stops the timer ignoring all pre-checks
7445
+ *
7446
+ * @return boolean true if the print job has finished printing
7447
+ */
7448
+bool print_job_stop(bool force /* = false */) {
7449
+  if (!print_job_start_ms) return false;
7450
+  if (!force) for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
7451
+  print_job_stop_ms = millis();
7452
+  return true;
7453
+}

+ 2
- 1
Marlin/dogm_lcd_implementation.h View File

@@ -305,7 +305,8 @@ static void lcd_implementation_status_screen() {
305 305
 
306 306
     u8g.setPrintPos(80,48);
307 307
     if (print_job_start_ms != 0) {
308
-      uint16_t time = (millis() - print_job_start_ms) / 60000;
308
+      uint16_t time = (((print_job_stop_ms > print_job_start_ms)
309
+                       ? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
309 310
       lcd_print(itostr2(time/60));
310 311
       lcd_print(':');
311 312
       lcd_print(itostr2(time%60));

+ 3
- 0
Marlin/temperature.cpp View File

@@ -1134,6 +1134,9 @@ void disable_all_heaters() {
1134 1134
   for (int i = 0; i < EXTRUDERS; i++) setTargetHotend(0, i);
1135 1135
   setTargetBed(0);
1136 1136
 
1137
+  // If all heaters go down then for sure our print job has stopped
1138
+  print_job_stop(true);
1139
+
1137 1140
   #define DISABLE_HEATER(NR) { \
1138 1141
     setTargetHotend(NR, 0); \
1139 1142
     soft_pwm[NR] = 0; \

+ 6
- 5
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

@@ -136,7 +136,7 @@ extern volatile uint8_t buttons;  //an extended version of the last checked butt
136 136
   #define LCD_I2C_PIN_D5  5
137 137
   #define LCD_I2C_PIN_D6  6
138 138
   #define LCD_I2C_PIN_D7  7
139
-  
139
+
140 140
   #include <Wire.h>
141 141
   #include <LCD.h>
142 142
   #include <LiquidCrystal_I2C.h>
@@ -637,7 +637,7 @@ static void lcd_implementation_status_screen() {
637 637
         else {
638 638
           if (!axis_homed[X_AXIS])
639 639
             lcd_printPGM(PSTR("?"));
640
-          else 
640
+          else
641 641
             #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
642 642
               if (!axis_known_position[X_AXIS])
643 643
                 lcd_printPGM(PSTR(" "));
@@ -654,7 +654,7 @@ static void lcd_implementation_status_screen() {
654 654
         else {
655 655
           if (!axis_homed[Y_AXIS])
656 656
             lcd_printPGM(PSTR("?"));
657
-          else 
657
+          else
658 658
             #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
659 659
               if (!axis_known_position[Y_AXIS])
660 660
                 lcd_printPGM(PSTR(" "));
@@ -674,7 +674,7 @@ static void lcd_implementation_status_screen() {
674 674
     else {
675 675
       if (!axis_homed[Z_AXIS])
676 676
         lcd_printPGM(PSTR("?"));
677
-      else 
677
+      else
678 678
         #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
679 679
           if (!axis_known_position[Z_AXIS])
680 680
             lcd_printPGM(PSTR(" "));
@@ -712,7 +712,8 @@ static void lcd_implementation_status_screen() {
712 712
     lcd.setCursor(LCD_WIDTH - 6, 2);
713 713
     lcd.print(LCD_STR_CLOCK[0]);
714 714
     if (print_job_start_ms != 0) {
715
-      uint16_t time = millis() / 60000 - print_job_start_ms / 60000;
715
+      uint16_t time = (((print_job_stop_ms > print_job_start_ms)
716
+                       ? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
716 717
       lcd.print(itostr2(time / 60));
717 718
       lcd.print(':');
718 719
       lcd.print(itostr2(time % 60));

Loading…
Cancel
Save