Rework the print job timer to use the stopwatch class

This commit is contained in:
João Brázio 2016-04-06 04:34:03 +01:00
parent 399101fff3
commit eb61051556
5 changed files with 47 additions and 77 deletions

View file

@ -65,6 +65,8 @@ typedef unsigned long millis_t;
#include "WString.h"
#include "stopwatch.h"
#ifdef USBCON
#if ENABLED(BLUETOOTH)
#define MYSERIAL bluetoothSerial
@ -357,8 +359,8 @@ extern bool axis_homed[3]; // axis[n].is_homed
extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
#endif
extern millis_t print_job_start_ms;
extern millis_t print_job_stop_ms;
// Print job timer
extern stopwatch print_job_timer;
// Handling multiple extruders pins
extern uint8_t active_extruder;
@ -374,9 +376,4 @@ extern uint8_t active_extruder;
extern void calculate_volumetric_multipliers();
// Print job timer related functions
millis_t print_job_timer();
bool print_job_start(millis_t t = 0);
bool print_job_stop(bool force = false);
#endif //MARLIN_H

View file

@ -298,8 +298,7 @@ const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
millis_t previous_cmd_ms = 0;
static millis_t max_inactive_time = 0;
static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000L;
millis_t print_job_start_ms = 0; ///< Print job start time
millis_t print_job_stop_ms = 0; ///< Print job stop time
stopwatch print_job_timer = stopwatch();
static uint8_t target_extruder;
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
@ -1012,9 +1011,9 @@ inline void get_serial_commands() {
) {
if (card_eof) {
SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
print_job_stop(true);
print_job_timer.stop();
char time[30];
millis_t t = print_job_timer();
millis_t t = print_job_timer.duration();
int hours = t / 60 / 60, minutes = (t / 60) % 60;
sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
SERIAL_ECHO_START;
@ -3624,7 +3623,7 @@ inline void gcode_M17() {
*/
inline void gcode_M24() {
card.startFileprint();
print_job_start();
print_job_timer.start();
}
/**
@ -3680,7 +3679,7 @@ inline void gcode_M17() {
* M31: Get the time since the start of SD Print (or last M109)
*/
inline void gcode_M31() {
millis_t t = print_job_timer();
millis_t t = print_job_timer.duration();
int min = t / 60, sec = t % 60;
char time[30];
sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
@ -4090,9 +4089,6 @@ inline void gcode_M104() {
if (setTargetedHotend(104)) return;
if (DEBUGGING(DRYRUN)) return;
// Start hook must happen before setTargetHotend()
print_job_start();
if (code_seen('S')) {
float temp = code_value();
setTargetHotend(temp, target_extruder);
@ -4101,10 +4097,24 @@ inline void gcode_M104() {
setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
#endif
/**
* We use halve EXTRUDE_MINTEMP here to allow nozzles to be put into hot
* stand by mode, for instance in a dual extruder setup, without affecting
* the running print timer.
*/
if (temp <= (EXTRUDE_MINTEMP/2)) {
print_job_timer.stop();
LCD_MESSAGEPGM(WELCOME_MSG);
}
/**
* We do not check if the timer is already running because this check will
* be done for us inside the stopwatch::start() method thus a running timer
* will not restart.
*/
else print_job_timer.start();
if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
}
if (print_job_stop()) LCD_MESSAGEPGM(WELCOME_MSG);
}
#if HAS_TEMP_HOTEND || HAS_TEMP_BED
@ -4232,9 +4242,6 @@ inline void gcode_M109() {
if (setTargetedHotend(109)) return;
if (DEBUGGING(DRYRUN)) return;
// Start hook must happen before setTargetHotend()
print_job_start();
no_wait_for_cooling = code_seen('S');
if (no_wait_for_cooling || code_seen('R')) {
float temp = code_value();
@ -4244,11 +4251,25 @@ inline void gcode_M109() {
setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
#endif
/**
* We use halve EXTRUDE_MINTEMP here to allow nozzles to be put into hot
* stand by mode, for instance in a dual extruder setup, without affecting
* the running print timer.
*/
if (temp <= (EXTRUDE_MINTEMP/2)) {
print_job_timer.stop();
LCD_MESSAGEPGM(WELCOME_MSG);
}
/**
* We do not check if the timer is already running because this check will
* be done for us inside the stopwatch::start() method thus a running timer
* will not restart.
*/
else print_job_timer.start();
if (temp > degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
}
if (print_job_stop()) LCD_MESSAGEPGM(WELCOME_MSG);
#if ENABLED(AUTOTEMP)
autotemp_enabled = code_seen('F');
if (autotemp_enabled) autotemp_factor = code_value();
@ -7692,50 +7713,3 @@ void calculate_volumetric_multipliers() {
for (int i = 0; i < EXTRUDERS; i++)
volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
}
/**
* Start the print job timer
*
* The print job is only started if all extruders have their target temp at zero
* otherwise the print job timew would be reset everytime a M109 is received.
*
* @param t start timer timestamp
*
* @return true if the timer was started at function call
*/
bool print_job_start(millis_t t /* = 0 */) {
for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
print_job_start_ms = (t) ? t : millis();
print_job_stop_ms = 0;
return true;
}
/**
* Check if the running print job has finished and stop the timer
*
* When the target temperature for all extruders is zero then we assume that the
* print job has finished printing. There are some special conditions under which
* this assumption may not be valid: If during a print job for some reason the
* user decides to bring a nozzle temp down and only then heat the other afterwards.
*
* @param force stops the timer ignoring all pre-checks
*
* @return boolean true if the print job has finished printing
*/
bool print_job_stop(bool force /* = false */) {
if (!print_job_start_ms) return false;
if (!force) for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
print_job_stop_ms = millis();
return true;
}
/**
* Output the print job timer in seconds
*
* @return the number of seconds
*/
millis_t print_job_timer() {
if (!print_job_start_ms) return 0;
return (((print_job_stop_ms > print_job_start_ms)
? print_job_stop_ms : millis()) - print_job_start_ms) / 1000;
}

View file

@ -334,9 +334,8 @@ static void lcd_implementation_status_screen() {
}
u8g.setPrintPos(80,48);
if (print_job_start_ms != 0) {
uint16_t time = (((print_job_stop_ms > print_job_start_ms)
? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
uint16_t time = print_job_timer.duration() / 60;
if (time != 0) {
lcd_print(itostr2(time/60));
lcd_print(':');
lcd_print(itostr2(time%60));

View file

@ -1175,7 +1175,7 @@ void disable_all_heaters() {
setTargetBed(0);
// If all heaters go down then for sure our print job has stopped
print_job_stop(true);
print_job_timer.stop();
#define DISABLE_HEATER(NR) { \
setTargetHotend(NR, 0); \

View file

@ -739,9 +739,9 @@ static void lcd_implementation_status_screen() {
lcd.setCursor(LCD_WIDTH - 6, 2);
lcd.print(LCD_STR_CLOCK[0]);
if (print_job_start_ms != 0) {
uint16_t time = (((print_job_stop_ms > print_job_start_ms)
? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
uint16_t time = print_job_timer.duration() / 60;
if (time != 0) {
lcd.print(itostr2(time / 60));
lcd.print(':');
lcd.print(itostr2(time % 60));