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

Prevent heating after Stop() is called #2788

Open
wants to merge 2 commits into
base: MK3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
45 changes: 31 additions & 14 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6348,7 +6348,9 @@ SERIAL_PROTOCOLPGM("\n\n");
}
if (code_seen('S'))
{
setTargetHotendSafe(code_value(), extruder);
if (!setTargetHotendSafe(code_value(), extruder)){ // Set the hotend temperature, unless we are stopped, in which case send an error (setTargetHotendSafe() returns true if it let the printer start heating, false otherwise)
SERIAL_PROTOCOLLNPGM("Hotend temperature not set because Stop() has been called. Use M999 to reset and try again.");
}
}
break;
}
Expand All @@ -6371,7 +6373,12 @@ SERIAL_PROTOCOLPGM("\n\n");
- `S` - Target temperature
*/
case 140:
if (code_seen('S')) setTargetBed(code_value());

if (code_seen('S')) {
if (!setTargetBed(code_value())) {
SERIAL_PROTOCOLLNPGM("Bed temperature not set because Stop() has been called. Use M999 to reset and try again.");
}
}
break;

/*!
Expand Down Expand Up @@ -6454,19 +6461,19 @@ SERIAL_PROTOCOLPGM("\n\n");
if(setTargetedHotend(109, extruder)){
break;
}
bool set_heater_success = true; // Set to true by default to allow the program to continue if S or R are not sent
if (code_seen('S')) {
set_heater_success = setTargetHotendSafe(code_value(), extruder);
} else if (code_seen('R')) {
set_heater_success = setTargetHotendSafe(code_value(), extruder);
}
if (set_heater_success){
LCD_MESSAGERPGM(_T(MSG_HEATING));
heating_status = 1;
if (farm_mode) { prusa_statistics(1); };

#ifdef AUTOTEMP
autotemp_enabled=false;
#endif
if (code_seen('S')) {
setTargetHotendSafe(code_value(), extruder);
} else if (code_seen('R')) {
setTargetHotendSafe(code_value(), extruder);
}
#ifdef AUTOTEMP
if (code_seen('S')) autotemp_min=code_value();
if (code_seen('B')) autotemp_max=code_value();
if (code_seen('F'))
Expand Down Expand Up @@ -6494,7 +6501,10 @@ SERIAL_PROTOCOLPGM("\n\n");

//starttime=_millis();
previous_millis_cmd = _millis();
} else { // Stopped is therefore true, send a message over serial.
SERIAL_PROTOCOLLNPGM("Hotend temperature not set because Stop() has been called. Use M999 to reset and try again.");
}
}
break;

/*!
Expand All @@ -6514,18 +6524,22 @@ SERIAL_PROTOCOLPGM("\n\n");
#if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
{
bool CooldownNoWait = false;
LCD_MESSAGERPGM(_T(MSG_BED_HEATING));
heating_status = 3;
if (farm_mode) { prusa_statistics(1); };
bool set_heater_success = true; // Set to true by default to allow the program to continue if S or R are not sent
if (code_seen('S'))
{
setTargetBed(code_value());
set_heater_success = setTargetBed(code_value());
CooldownNoWait = true;
}
else if (code_seen('R'))
{
setTargetBed(code_value());
set_heater_success = setTargetBed(code_value());
}
if (set_heater_success){

LCD_MESSAGERPGM(_T(MSG_BED_HEATING));
heating_status = 3;
if (farm_mode) { prusa_statistics(1); };

codenum = _millis();

cancel_heatup = false;
Expand Down Expand Up @@ -6558,6 +6572,9 @@ SERIAL_PROTOCOLPGM("\n\n");
heating_status = 4;

previous_millis_cmd = _millis();
} else {
SERIAL_PROTOCOLLNPGM("Bed temperature not set because Stop() has been called. Use M999 to reset and try again.");
}
}
#endif
break;
Expand Down
26 changes: 17 additions & 9 deletions Firmware/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,22 @@ FORCE_INLINE float degTargetBed() {

// Doesn't save FLASH when FORCE_INLINE removed.
FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
target_temperature[extruder] = celsius;
resetPID(extruder);
if (!IsStopped()){
target_temperature[extruder] = celsius;
resetPID(extruder);
}
};

// Doesn't save FLASH when not inlined.
static inline void setTargetHotendSafe(const float &celsius, uint8_t extruder)
static inline bool setTargetHotendSafe(const float &celsius, uint8_t extruder)
{
if (extruder<EXTRUDERS) {
target_temperature[extruder] = celsius;
resetPID(extruder);
}
if (!IsStopped()){
if (extruder<EXTRUDERS) {
target_temperature[extruder] = celsius;
resetPID(extruder);
}
return true;
} else return false;
}

// Doesn't save FLASH when not inlined.
Expand All @@ -178,8 +183,11 @@ static inline void setAllTargetHotends(const float &celsius)
for(int i=0;i<EXTRUDERS;i++) setTargetHotend(celsius,i);
}

FORCE_INLINE void setTargetBed(const float &celsius) {
target_temperature_bed = celsius;
FORCE_INLINE bool setTargetBed(const float &celsius) {
if (!IsStopped()){
target_temperature_bed = celsius;
return true;
} else return false;
};

FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
Expand Down
9 changes: 8 additions & 1 deletion Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6891,14 +6891,15 @@ static void lcd_main_menu()
MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
}


if (!IsStopped()) {
if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal))
{
MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE
} else
{
MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT
}
}


if(isPrintPaused && saved_printing_type == PRINTING_TYPE_USB)
Expand Down Expand Up @@ -6941,11 +6942,13 @@ static void lcd_main_menu()
{
if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal))
{
if (!IsStopped()) {
//if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
/*else*/ {
bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
}
}
}
#if SDCARDDETECT < 1
MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD
Expand Down Expand Up @@ -6985,6 +6988,7 @@ static void lcd_main_menu()
}
else
{
if (!IsStopped()){
if (mmu_enabled)
{
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
Expand Down Expand Up @@ -7015,6 +7019,7 @@ static void lcd_main_menu()
bFilamentFirstRun=true;
MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
}
}
MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);

Expand Down Expand Up @@ -7325,6 +7330,7 @@ static void lcd_control_temperature_menu()

MENU_BEGIN();
MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
if (!IsStopped()) {
#if TEMP_SENSOR_0 != 0
MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
#endif
Expand All @@ -7337,6 +7343,7 @@ static void lcd_control_temperature_menu()
#if TEMP_SENSOR_BED != 0
MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
#endif
}
MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
#if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
//MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
Expand Down