Browse Source

Rework the print job timer to use the stopwatch class

João Brázio 8 years ago
parent
commit
eb61051556

+ 4
- 7
Marlin/Marlin.h View File

65
 
65
 
66
 #include "WString.h"
66
 #include "WString.h"
67
 
67
 
68
+#include "stopwatch.h"
69
+
68
 #ifdef USBCON
70
 #ifdef USBCON
69
   #if ENABLED(BLUETOOTH)
71
   #if ENABLED(BLUETOOTH)
70
     #define MYSERIAL bluetoothSerial
72
     #define MYSERIAL bluetoothSerial
357
   extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
359
   extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
358
 #endif
360
 #endif
359
 
361
 
360
-extern millis_t print_job_start_ms;
361
-extern millis_t print_job_stop_ms;
362
+// Print job timer
363
+extern stopwatch print_job_timer;
362
 
364
 
363
 // Handling multiple extruders pins
365
 // Handling multiple extruders pins
364
 extern uint8_t active_extruder;
366
 extern uint8_t active_extruder;
374
 
376
 
375
 extern void calculate_volumetric_multipliers();
377
 extern void calculate_volumetric_multipliers();
376
 
378
 
377
-// Print job timer related functions
378
-millis_t print_job_timer();
379
-bool print_job_start(millis_t t = 0);
380
-bool print_job_stop(bool force = false);
381
-
382
 #endif //MARLIN_H
379
 #endif //MARLIN_H

+ 37
- 63
Marlin/Marlin_main.cpp View File

298
 millis_t previous_cmd_ms = 0;
298
 millis_t previous_cmd_ms = 0;
299
 static millis_t max_inactive_time = 0;
299
 static millis_t max_inactive_time = 0;
300
 static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000L;
300
 static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000L;
301
-millis_t print_job_start_ms = 0; ///< Print job start time
302
-millis_t print_job_stop_ms = 0;  ///< Print job stop time
301
+stopwatch print_job_timer = stopwatch();
303
 static uint8_t target_extruder;
302
 static uint8_t target_extruder;
304
 
303
 
305
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
304
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
1012
       ) {
1011
       ) {
1013
         if (card_eof) {
1012
         if (card_eof) {
1014
           SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
1013
           SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
1015
-          print_job_stop(true);
1014
+          print_job_timer.stop();
1016
           char time[30];
1015
           char time[30];
1017
-          millis_t t = print_job_timer();
1016
+          millis_t t = print_job_timer.duration();
1018
           int hours = t / 60 / 60, minutes = (t / 60) % 60;
1017
           int hours = t / 60 / 60, minutes = (t / 60) % 60;
1019
           sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
1018
           sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
1020
           SERIAL_ECHO_START;
1019
           SERIAL_ECHO_START;
3624
    */
3623
    */
3625
   inline void gcode_M24() {
3624
   inline void gcode_M24() {
3626
     card.startFileprint();
3625
     card.startFileprint();
3627
-    print_job_start();
3626
+    print_job_timer.start();
3628
   }
3627
   }
3629
 
3628
 
3630
   /**
3629
   /**
3680
  * M31: Get the time since the start of SD Print (or last M109)
3679
  * M31: Get the time since the start of SD Print (or last M109)
3681
  */
3680
  */
3682
 inline void gcode_M31() {
3681
 inline void gcode_M31() {
3683
-  millis_t t = print_job_timer();
3682
+  millis_t t = print_job_timer.duration();
3684
   int min = t / 60, sec = t % 60;
3683
   int min = t / 60, sec = t % 60;
3685
   char time[30];
3684
   char time[30];
3686
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
3685
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
4090
   if (setTargetedHotend(104)) return;
4089
   if (setTargetedHotend(104)) return;
4091
   if (DEBUGGING(DRYRUN)) return;
4090
   if (DEBUGGING(DRYRUN)) return;
4092
 
4091
 
4093
-  // Start hook must happen before setTargetHotend()
4094
-  print_job_start();
4095
-
4096
   if (code_seen('S')) {
4092
   if (code_seen('S')) {
4097
     float temp = code_value();
4093
     float temp = code_value();
4098
     setTargetHotend(temp, target_extruder);
4094
     setTargetHotend(temp, target_extruder);
4101
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4097
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4102
     #endif
4098
     #endif
4103
 
4099
 
4100
+    /**
4101
+     * We use halve EXTRUDE_MINTEMP here to allow nozzles to be put into hot
4102
+     * stand by mode, for instance in a dual extruder setup, without affecting
4103
+     * the running print timer.
4104
+     */
4105
+    if (temp <= (EXTRUDE_MINTEMP/2)) {
4106
+      print_job_timer.stop();
4107
+      LCD_MESSAGEPGM(WELCOME_MSG);
4108
+    }
4109
+    /**
4110
+     * We do not check if the timer is already running because this check will
4111
+     * be done for us inside the stopwatch::start() method thus a running timer
4112
+     * will not restart.
4113
+     */
4114
+    else print_job_timer.start();
4115
+
4104
     if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4116
     if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4105
   }
4117
   }
4106
-
4107
-  if (print_job_stop()) LCD_MESSAGEPGM(WELCOME_MSG);
4108
 }
4118
 }
4109
 
4119
 
4110
 #if HAS_TEMP_HOTEND || HAS_TEMP_BED
4120
 #if HAS_TEMP_HOTEND || HAS_TEMP_BED
4232
   if (setTargetedHotend(109)) return;
4242
   if (setTargetedHotend(109)) return;
4233
   if (DEBUGGING(DRYRUN)) return;
4243
   if (DEBUGGING(DRYRUN)) return;
4234
 
4244
 
4235
-  // Start hook must happen before setTargetHotend()
4236
-  print_job_start();
4237
-
4238
   no_wait_for_cooling = code_seen('S');
4245
   no_wait_for_cooling = code_seen('S');
4239
   if (no_wait_for_cooling || code_seen('R')) {
4246
   if (no_wait_for_cooling || code_seen('R')) {
4240
     float temp = code_value();
4247
     float temp = code_value();
4244
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4251
         setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
4245
     #endif
4252
     #endif
4246
 
4253
 
4254
+    /**
4255
+     * We use halve EXTRUDE_MINTEMP here to allow nozzles to be put into hot
4256
+     * stand by mode, for instance in a dual extruder setup, without affecting
4257
+     * the running print timer.
4258
+     */
4259
+    if (temp <= (EXTRUDE_MINTEMP/2)) {
4260
+      print_job_timer.stop();
4261
+      LCD_MESSAGEPGM(WELCOME_MSG);
4262
+    }
4263
+    /**
4264
+     * We do not check if the timer is already running because this check will
4265
+     * be done for us inside the stopwatch::start() method thus a running timer
4266
+     * will not restart.
4267
+     */
4268
+    else print_job_timer.start();
4269
+
4247
     if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4270
     if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4248
   }
4271
   }
4249
 
4272
 
4250
-  if (print_job_stop()) LCD_MESSAGEPGM(WELCOME_MSG);
4251
-
4252
   #if ENABLED(AUTOTEMP)
4273
   #if ENABLED(AUTOTEMP)
4253
     autotemp_enabled = code_seen('F');
4274
     autotemp_enabled = code_seen('F');
4254
     if (autotemp_enabled) autotemp_factor = code_value();
4275
     if (autotemp_enabled) autotemp_factor = code_value();
7692
   for (int i = 0; i < EXTRUDERS; i++)
7713
   for (int i = 0; i < EXTRUDERS; i++)
7693
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
7714
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
7694
 }
7715
 }
7695
-
7696
-/**
7697
- * Start the print job timer
7698
- *
7699
- * The print job is only started if all extruders have their target temp at zero
7700
- * otherwise the print job timew would be reset everytime a M109 is received.
7701
- *
7702
- * @param t start timer timestamp
7703
- *
7704
- * @return true if the timer was started at function call
7705
- */
7706
-bool print_job_start(millis_t t /* = 0 */) {
7707
-  for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
7708
-  print_job_start_ms = (t) ? t : millis();
7709
-  print_job_stop_ms = 0;
7710
-  return true;
7711
-}
7712
-
7713
-/**
7714
- * Check if the running print job has finished and stop the timer
7715
- *
7716
- * When the target temperature for all extruders is zero then we assume that the
7717
- * print job has finished printing. There are some special conditions under which
7718
- * this assumption may not be valid: If during a print job for some reason the
7719
- * user decides to bring a nozzle temp down and only then heat the other afterwards.
7720
- *
7721
- * @param force stops the timer ignoring all pre-checks
7722
- *
7723
- * @return boolean true if the print job has finished printing
7724
- */
7725
-bool print_job_stop(bool force /* = false */) {
7726
-  if (!print_job_start_ms) return false;
7727
-  if (!force) for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
7728
-  print_job_stop_ms = millis();
7729
-  return true;
7730
-}
7731
-
7732
-/**
7733
- * Output the print job timer in seconds
7734
- *
7735
- * @return the number of seconds
7736
- */
7737
-millis_t print_job_timer() {
7738
-  if (!print_job_start_ms) return 0;
7739
-  return (((print_job_stop_ms > print_job_start_ms)
7740
-    ? print_job_stop_ms : millis()) - print_job_start_ms) / 1000;
7741
-}

+ 2
- 3
Marlin/dogm_lcd_implementation.h View File

334
     }
334
     }
335
 
335
 
336
     u8g.setPrintPos(80,48);
336
     u8g.setPrintPos(80,48);
337
-    if (print_job_start_ms != 0) {
338
-      uint16_t time = (((print_job_stop_ms > print_job_start_ms)
339
-                       ? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
337
+    uint16_t time = print_job_timer.duration() / 60;
338
+    if (time != 0) {
340
       lcd_print(itostr2(time/60));
339
       lcd_print(itostr2(time/60));
341
       lcd_print(':');
340
       lcd_print(':');
342
       lcd_print(itostr2(time%60));
341
       lcd_print(itostr2(time%60));

+ 1
- 1
Marlin/temperature.cpp View File

1175
   setTargetBed(0);
1175
   setTargetBed(0);
1176
 
1176
 
1177
   // If all heaters go down then for sure our print job has stopped
1177
   // If all heaters go down then for sure our print job has stopped
1178
-  print_job_stop(true);
1178
+  print_job_timer.stop();
1179
 
1179
 
1180
   #define DISABLE_HEATER(NR) { \
1180
   #define DISABLE_HEATER(NR) { \
1181
     setTargetHotend(NR, 0); \
1181
     setTargetHotend(NR, 0); \

+ 3
- 3
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

739
 
739
 
740
     lcd.setCursor(LCD_WIDTH - 6, 2);
740
     lcd.setCursor(LCD_WIDTH - 6, 2);
741
     lcd.print(LCD_STR_CLOCK[0]);
741
     lcd.print(LCD_STR_CLOCK[0]);
742
-    if (print_job_start_ms != 0) {
743
-      uint16_t time = (((print_job_stop_ms > print_job_start_ms)
744
-                       ? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
742
+
743
+    uint16_t time = print_job_timer.duration() / 60;
744
+    if (time != 0) {
745
       lcd.print(itostr2(time / 60));
745
       lcd.print(itostr2(time / 60));
746
       lcd.print(':');
746
       lcd.print(':');
747
       lcd.print(itostr2(time % 60));
747
       lcd.print(itostr2(time % 60));

Loading…
Cancel
Save