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
 
356
 
357
 extern void calculate_volumetric_multipliers();
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
 #endif //MARLIN_H
364
 #endif //MARLIN_H

+ 63
- 10
Marlin/Marlin_main.cpp View File

977
       ) {
977
       ) {
978
         if (card_eof) {
978
         if (card_eof) {
979
           SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
979
           SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
980
-          print_job_stop_ms = millis();
980
+          print_job_stop(true);
981
           char time[30];
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
           int hours = t / 60 / 60, minutes = (t / 60) % 60;
983
           int hours = t / 60 / 60, minutes = (t / 60) % 60;
984
           sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
984
           sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
985
           SERIAL_ECHO_START;
985
           SERIAL_ECHO_START;
3454
    */
3454
    */
3455
   inline void gcode_M24() {
3455
   inline void gcode_M24() {
3456
     card.startFileprint();
3456
     card.startFileprint();
3457
-    print_job_start_ms = millis();
3457
+    print_job_start();
3458
   }
3458
   }
3459
 
3459
 
3460
   /**
3460
   /**
3510
  * M31: Get the time since the start of SD Print (or last M109)
3510
  * M31: Get the time since the start of SD Print (or last M109)
3511
  */
3511
  */
3512
 inline void gcode_M31() {
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
   int min = t / 60, sec = t % 60;
3514
   int min = t / 60, sec = t % 60;
3516
   char time[30];
3515
   char time[30];
3517
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
3516
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
3545
         card.setIndex(code_value_short());
3544
         card.setIndex(code_value_short());
3546
 
3545
 
3547
       card.startFileprint();
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
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
3884
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
3885
     #endif
3885
     #endif
3886
   }
3886
   }
3887
+
3888
+  print_job_stop();
3887
 }
3889
 }
3888
 
3890
 
3889
 #if HAS_TEMP_0 || HAS_TEMP_BED || ENABLED(HEATER_0_USES_MAX6675)
3891
 #if HAS_TEMP_0 || HAS_TEMP_BED || ENABLED(HEATER_0_USES_MAX6675)
4008
 inline void gcode_M109() {
4010
 inline void gcode_M109() {
4009
   bool no_wait_for_cooling = true;
4011
   bool no_wait_for_cooling = true;
4010
 
4012
 
4013
+  // Start hook must happen before setTargetHotend()
4014
+  print_job_start();
4015
+
4011
   if (setTargetedHotend(109)) return;
4016
   if (setTargetedHotend(109)) return;
4012
   if (marlin_debug_flags & DEBUG_DRYRUN) return;
4017
   if (marlin_debug_flags & DEBUG_DRYRUN) return;
4013
 
4018
 
4014
-  LCD_MESSAGEPGM(MSG_HEATING);
4015
-
4016
   no_wait_for_cooling = code_seen('S');
4019
   no_wait_for_cooling = code_seen('S');
4017
   if (no_wait_for_cooling || code_seen('R')) {
4020
   if (no_wait_for_cooling || code_seen('R')) {
4018
     float temp = code_value();
4021
     float temp = code_value();
4021
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
4024
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
4022
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4025
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4023
     #endif
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
   #if ENABLED(AUTOTEMP)
4033
   #if ENABLED(AUTOTEMP)
4027
     autotemp_enabled = code_seen('F');
4034
     autotemp_enabled = code_seen('F');
4028
     if (autotemp_enabled) autotemp_factor = code_value();
4035
     if (autotemp_enabled) autotemp_factor = code_value();
4082
   } // while(!cancel_heatup && TEMP_CONDITIONS)
4089
   } // while(!cancel_heatup && TEMP_CONDITIONS)
4083
 
4090
 
4084
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4091
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4085
-  print_job_start_ms = previous_cmd_ms;
4086
 }
4092
 }
4087
 
4093
 
4088
 #if HAS_TEMP_BED
4094
 #if HAS_TEMP_BED
7398
   for (int i = 0; i < EXTRUDERS; i++)
7404
   for (int i = 0; i < EXTRUDERS; i++)
7399
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
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
 
305
 
306
     u8g.setPrintPos(80,48);
306
     u8g.setPrintPos(80,48);
307
     if (print_job_start_ms != 0) {
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
       lcd_print(itostr2(time/60));
310
       lcd_print(itostr2(time/60));
310
       lcd_print(':');
311
       lcd_print(':');
311
       lcd_print(itostr2(time%60));
312
       lcd_print(itostr2(time%60));

+ 3
- 0
Marlin/temperature.cpp View File

1134
   for (int i = 0; i < EXTRUDERS; i++) setTargetHotend(0, i);
1134
   for (int i = 0; i < EXTRUDERS; i++) setTargetHotend(0, i);
1135
   setTargetBed(0);
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
   #define DISABLE_HEATER(NR) { \
1140
   #define DISABLE_HEATER(NR) { \
1138
     setTargetHotend(NR, 0); \
1141
     setTargetHotend(NR, 0); \
1139
     soft_pwm[NR] = 0; \
1142
     soft_pwm[NR] = 0; \

+ 6
- 5
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

136
   #define LCD_I2C_PIN_D5  5
136
   #define LCD_I2C_PIN_D5  5
137
   #define LCD_I2C_PIN_D6  6
137
   #define LCD_I2C_PIN_D6  6
138
   #define LCD_I2C_PIN_D7  7
138
   #define LCD_I2C_PIN_D7  7
139
-  
139
+
140
   #include <Wire.h>
140
   #include <Wire.h>
141
   #include <LCD.h>
141
   #include <LCD.h>
142
   #include <LiquidCrystal_I2C.h>
142
   #include <LiquidCrystal_I2C.h>
637
         else {
637
         else {
638
           if (!axis_homed[X_AXIS])
638
           if (!axis_homed[X_AXIS])
639
             lcd_printPGM(PSTR("?"));
639
             lcd_printPGM(PSTR("?"));
640
-          else 
640
+          else
641
             #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
641
             #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
642
               if (!axis_known_position[X_AXIS])
642
               if (!axis_known_position[X_AXIS])
643
                 lcd_printPGM(PSTR(" "));
643
                 lcd_printPGM(PSTR(" "));
654
         else {
654
         else {
655
           if (!axis_homed[Y_AXIS])
655
           if (!axis_homed[Y_AXIS])
656
             lcd_printPGM(PSTR("?"));
656
             lcd_printPGM(PSTR("?"));
657
-          else 
657
+          else
658
             #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
658
             #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
659
               if (!axis_known_position[Y_AXIS])
659
               if (!axis_known_position[Y_AXIS])
660
                 lcd_printPGM(PSTR(" "));
660
                 lcd_printPGM(PSTR(" "));
674
     else {
674
     else {
675
       if (!axis_homed[Z_AXIS])
675
       if (!axis_homed[Z_AXIS])
676
         lcd_printPGM(PSTR("?"));
676
         lcd_printPGM(PSTR("?"));
677
-      else 
677
+      else
678
         #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
678
         #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
679
           if (!axis_known_position[Z_AXIS])
679
           if (!axis_known_position[Z_AXIS])
680
             lcd_printPGM(PSTR(" "));
680
             lcd_printPGM(PSTR(" "));
712
     lcd.setCursor(LCD_WIDTH - 6, 2);
712
     lcd.setCursor(LCD_WIDTH - 6, 2);
713
     lcd.print(LCD_STR_CLOCK[0]);
713
     lcd.print(LCD_STR_CLOCK[0]);
714
     if (print_job_start_ms != 0) {
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
       lcd.print(itostr2(time / 60));
717
       lcd.print(itostr2(time / 60));
717
       lcd.print(':');
718
       lcd.print(':');
718
       lcd.print(itostr2(time % 60));
719
       lcd.print(itostr2(time % 60));

Loading…
Cancel
Save