Browse Source

All print timer related activity now uses print_job_start(), print_job_timer() or print_job_stop()

jbrazio 9 years ago
parent
commit
a645860431
3 changed files with 67 additions and 39 deletions
  1. 5
    0
      Marlin/Marlin.h
  2. 61
    38
      Marlin/Marlin_main.cpp
  3. 1
    1
      Marlin/temperature.cpp

+ 5
- 0
Marlin/Marlin.h View File

@@ -351,4 +351,9 @@ extern uint8_t active_extruder;
351 351
 
352 352
 extern void calculate_volumetric_multipliers();
353 353
 
354
+// Print job timer related functions
355
+millis_t print_job_timer();
356
+bool print_job_start(millis_t t = 0);
357
+bool print_job_stop(bool force = false);
358
+
354 359
 #endif //MARLIN_H

+ 61
- 38
Marlin/Marlin_main.cpp View File

@@ -943,9 +943,9 @@ void get_command() {
943 943
       ) {
944 944
         if (card.eof()) {
945 945
           SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
946
-          print_job_stop_ms = millis();
946
+          print_job_stop(true);
947 947
           char time[30];
948
-          millis_t t = (print_job_stop_ms - print_job_start_ms) / 1000;
948
+          millis_t t = print_job_timer();
949 949
           int hours = t / 60 / 60, minutes = (t / 60) % 60;
950 950
           sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
951 951
           SERIAL_ECHO_START;
@@ -3411,7 +3411,7 @@ inline void gcode_M17() {
3411 3411
    */
3412 3412
   inline void gcode_M24() {
3413 3413
     card.startFileprint();
3414
-    print_job_start_ms = millis();
3414
+    print_job_start();
3415 3415
   }
3416 3416
 
3417 3417
   /**
@@ -3467,8 +3467,7 @@ inline void gcode_M17() {
3467 3467
  * M31: Get the time since the start of SD Print (or last M109)
3468 3468
  */
3469 3469
 inline void gcode_M31() {
3470
-  print_job_stop_ms = millis();
3471
-  millis_t t = (print_job_stop_ms - print_job_start_ms) / 1000;
3470
+  millis_t t = print_job_timer();
3472 3471
   int min = t / 60, sec = t % 60;
3473 3472
   char time[30];
3474 3473
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
@@ -3502,8 +3501,9 @@ inline void gcode_M31() {
3502 3501
         card.setIndex(code_value_short());
3503 3502
 
3504 3503
       card.startFileprint();
3505
-      if (!call_procedure)
3506
-        print_job_start_ms = millis(); //procedure calls count as normal print time.
3504
+
3505
+      // Procedure calls count as normal print time.
3506
+      if (!call_procedure) print_job_start();
3507 3507
     }
3508 3508
   }
3509 3509
 
@@ -3834,18 +3834,7 @@ inline void gcode_M104() {
3834 3834
     #endif
3835 3835
   }
3836 3836
 
3837
-  // Detect if a print job has finished.
3838
-  // When the target temperature for all extruders is zero then we must have
3839
-  // finished printing.
3840
-  if (print_job_start_ms) {
3841
-    bool all_extruders_cooling = true;
3842
-    for (int i = 0; i < EXTRUDERS; i++) if( degTargetHotend(i) > 0 ) {
3843
-      all_extruders_cooling = false;
3844
-      break;
3845
-    }
3846
-
3847
-    if( all_extruders_cooling ) print_job_stop_ms = millis();
3848
-  }
3837
+  print_job_stop();
3849 3838
 }
3850 3839
 
3851 3840
 #if HAS_TEMP_0 || HAS_TEMP_BED || ENABLED(HEATER_0_USES_MAX6675)
@@ -3959,6 +3948,9 @@ inline void gcode_M105() {
3959 3948
 inline void gcode_M109() {
3960 3949
   bool no_wait_for_cooling = true;
3961 3950
 
3951
+  // Start hook must happen before setTargetHotend()
3952
+  print_job_start();
3953
+
3962 3954
   if (setTargetedHotend(109)) return;
3963 3955
   if (marlin_debug_flags & DEBUG_DRYRUN) return;
3964 3956
 
@@ -3971,10 +3963,11 @@ inline void gcode_M109() {
3971 3963
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
3972 3964
     #endif
3973 3965
 
3974
-    // Only makes sense to show the heating message if we're in fact heating.
3975
-    if (temp > 0) LCD_MESSAGEPGM(MSG_HEATING);
3966
+    if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
3976 3967
   }
3977 3968
 
3969
+  if (print_job_stop()) LCD_MESSAGEPGM(WELCOME_MSG);
3970
+
3978 3971
   #if ENABLED(AUTOTEMP)
3979 3972
     autotemp_enabled = code_seen('F');
3980 3973
     if (autotemp_enabled) autotemp_factor = code_value();
@@ -3982,22 +3975,6 @@ inline void gcode_M109() {
3982 3975
     if (code_seen('B')) autotemp_max = code_value();
3983 3976
   #endif
3984 3977
 
3985
-  // Detect if a print job has finished.
3986
-  // When the target temperature for all extruders is zero then we must have
3987
-  // finished printing.
3988
-  if( print_job_start_ms != 0 ) {
3989
-    bool all_extruders_cooling = true;
3990
-    for (int i = 0; i < EXTRUDERS; i++) if( degTargetHotend(i) > 0 ) {
3991
-      all_extruders_cooling = false;
3992
-      break;
3993
-    }
3994
-
3995
-    if( all_extruders_cooling ) {
3996
-      print_job_stop_ms = millis();
3997
-      LCD_MESSAGEPGM(WELCOME_MSG);
3998
-    }
3999
-  }
4000
-
4001 3978
   // Exit if the temperature is above target and not waiting for cooling
4002 3979
   if (no_wait_for_cooling && !isHeatingHotend(target_extruder)) return;
4003 3980
 
@@ -4046,7 +4023,6 @@ inline void gcode_M109() {
4046 4023
   } // while(!cancel_heatup && TEMP_CONDITIONS)
4047 4024
 
4048 4025
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4049
-  print_job_start_ms = previous_cmd_ms;
4050 4026
 }
4051 4027
 
4052 4028
 #if HAS_TEMP_BED
@@ -7336,3 +7312,50 @@ void calculate_volumetric_multipliers() {
7336 7312
   for (int i = 0; i < EXTRUDERS; i++)
7337 7313
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
7338 7314
 }
7315
+
7316
+/**
7317
+ * Start the print job timer
7318
+ *
7319
+ * The print job is only started if all extruders have their target temp at zero
7320
+ * otherwise the print job timew would be reset everytime a M109 is received.
7321
+ *
7322
+ * @param t start timer timestamp
7323
+ *
7324
+ * @return true if the timer was started at function call
7325
+ */
7326
+bool print_job_start(millis_t t /* = 0 */) {
7327
+  for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
7328
+  print_job_start_ms = (t) ? t : millis();
7329
+  print_job_stop_ms = 0;
7330
+  return true;
7331
+}
7332
+
7333
+/**
7334
+ * Output the print job timer in seconds
7335
+ *
7336
+ * @return the number of seconds
7337
+ */
7338
+millis_t print_job_timer() {
7339
+  if (!print_job_start_ms) return 0;
7340
+  return (((print_job_stop_ms > print_job_start_ms)
7341
+    ? print_job_stop_ms : millis()) - print_job_start_ms) / 1000;
7342
+}
7343
+
7344
+/**
7345
+ * Check if the running print job has finished and stop the timer
7346
+ *
7347
+ * When the target temperature for all extruders is zero then we assume that the
7348
+ * print job has finished printing. There are some special conditions under which
7349
+ * this assumption may not be valid: If during a print job for some reason the
7350
+ * user decides to bring a nozzle temp down and only then heat the other afterwards.
7351
+ *
7352
+ * @param force stops the timer ignoring all pre-checks
7353
+ *
7354
+ * @return boolean true if the print job has finished printing
7355
+ */
7356
+bool print_job_stop(bool force /* = false */) {
7357
+  if (!print_job_start_ms) return false;
7358
+  if (!force) for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
7359
+  print_job_stop_ms = millis();
7360
+  return true;
7361
+}

+ 1
- 1
Marlin/temperature.cpp View File

@@ -1112,7 +1112,7 @@ void disable_all_heaters() {
1112 1112
   setTargetBed(0);
1113 1113
 
1114 1114
   // If all heaters go down then for sure our print job has stopped
1115
-  if( print_job_start_ms != 0 ) print_job_stop_ms = millis();
1115
+  print_job_stop(true);
1116 1116
 
1117 1117
   #define DISABLE_HEATER(NR) { \
1118 1118
     target_temperature[NR] = 0; \

Loading…
Cancel
Save