Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop print timer with M105/M109 #3113

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3833,6 +3833,19 @@ inline void gcode_M104() {
setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
#endif
}

// Detect if a print job has finished.
// When the target temperature for all extruders is zero then we must have
// finished printing.
if (print_job_start_ms) {
bool all_extruders_cooling = true;
for (int i = 0; i < EXTRUDERS; i++) if( degTargetHotend(i) > 0 ) {
all_extruders_cooling = false;
break;
}

if( all_extruders_cooling ) print_job_stop_ms = millis();
}
}

#if HAS_TEMP_0 || HAS_TEMP_BED || ENABLED(HEATER_0_USES_MAX6675)
Expand Down Expand Up @@ -3949,8 +3962,6 @@ inline void gcode_M109() {
if (setTargetedHotend(109)) return;
if (marlin_debug_flags & DEBUG_DRYRUN) return;

LCD_MESSAGEPGM(MSG_HEATING);

no_wait_for_cooling = code_seen('S');
if (no_wait_for_cooling || code_seen('R')) {
float temp = code_value();
Expand All @@ -3959,6 +3970,9 @@ inline void gcode_M109() {
if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && target_extruder == 0)
setTargetHotend1(temp == 0.0 ? 0.0 : temp + duplicate_extruder_temp_offset);
#endif

// Only makes sense to show the heating message if we're in fact heating.
if (temp > 0) LCD_MESSAGEPGM(MSG_HEATING);
}

#if ENABLED(AUTOTEMP)
Expand All @@ -3968,6 +3982,22 @@ inline void gcode_M109() {
if (code_seen('B')) autotemp_max = code_value();
#endif

// Detect if a print job has finished.
// When the target temperature for all extruders is zero then we must have
// finished printing.
if( print_job_start_ms != 0 ) {
bool all_extruders_cooling = true;
for (int i = 0; i < EXTRUDERS; i++) if( degTargetHotend(i) > 0 ) {
all_extruders_cooling = false;
break;
}

if( all_extruders_cooling ) {
print_job_stop_ms = millis();
LCD_MESSAGEPGM(WELCOME_MSG);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this code repeating we might as well make a function and call it in both places:

bool finish_print_job() {
  if (print_job_start_ms) {
    for (int i = 0; i < EXTRUDERS; i++) if (degTargetHotend(i) > 0) return false;
    print_job_stop_ms = millis();
    return true;
  }
  return false;
}

In gcode_M104:

  finish_print_job();

In gcode_M109:

  if (finish_print_job()) LCD_MESSAGEPGM(WELCOME_MSG);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I'll take the opportunity to rework the overall code a bit a implement a start_print_job() function also.


// Exit if the temperature is above target and not waiting for cooling
if (no_wait_for_cooling && !isHeatingHotend(target_extruder)) return;

Expand Down
3 changes: 2 additions & 1 deletion Marlin/dogm_lcd_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ static void lcd_implementation_status_screen() {

u8g.setPrintPos(80,48);
if (print_job_start_ms != 0) {
uint16_t time = (millis() - print_job_start_ms) / 60000;
uint16_t time = (((print_job_stop_ms > print_job_start_ms)
? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
lcd_print(itostr2(time/60));
lcd_print(':');
lcd_print(itostr2(time%60));
Expand Down
3 changes: 3 additions & 0 deletions Marlin/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,9 @@ void disable_all_heaters() {
for (int i = 0; i < EXTRUDERS; i++) setTargetHotend(0, i);
setTargetBed(0);

// If all heaters go down then for sure our print job has stopped
if( print_job_start_ms != 0 ) print_job_stop_ms = millis();

#define DISABLE_HEATER(NR) { \
target_temperature[NR] = 0; \
soft_pwm[NR] = 0; \
Expand Down
11 changes: 6 additions & 5 deletions Marlin/ultralcd_implementation_hitachi_HD44780.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ extern volatile uint8_t buttons; //an extended version of the last checked butt
#define LCD_I2C_PIN_D5 5
#define LCD_I2C_PIN_D6 6
#define LCD_I2C_PIN_D7 7

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
Expand Down Expand Up @@ -632,7 +632,7 @@ static void lcd_implementation_status_screen() {
else {
if (!axis_homed[X_AXIS])
lcd_printPGM(PSTR("?"));
else
else
#if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
if (!axis_known_position[X_AXIS])
lcd_printPGM(PSTR(" "));
Expand All @@ -649,7 +649,7 @@ static void lcd_implementation_status_screen() {
else {
if (!axis_homed[Y_AXIS])
lcd_printPGM(PSTR("?"));
else
else
#if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
if (!axis_known_position[Y_AXIS])
lcd_printPGM(PSTR(" "));
Expand All @@ -669,7 +669,7 @@ static void lcd_implementation_status_screen() {
else {
if (!axis_homed[Z_AXIS])
lcd_printPGM(PSTR("?"));
else
else
#if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
if (!axis_known_position[Z_AXIS])
lcd_printPGM(PSTR(" "));
Expand Down Expand Up @@ -707,7 +707,8 @@ 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 = millis() / 60000 - print_job_start_ms / 60000;
uint16_t time = (((print_job_stop_ms > print_job_start_ms)
? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
lcd.print(itostr2(time / 60));
lcd.print(':');
lcd.print(itostr2(time % 60));
Expand Down