Skip to content

Commit

Permalink
Prevent heating after Stop() is called
Browse files Browse the repository at this point in the history
Checks IsStopped() before heating

If M104, M109, M140 or M190 is called, we don't set temperature, and sends "Hotend/Bed temperature not set because Stop() has been called. Use M999 to reset and try again." over serial.

Removes menu items that cause heating if IsStopped():
Preheat
Print from SD
Load filament
Unload filament
Settings > Temperature
  • Loading branch information
Jefhope committed Aug 2, 2020
1 parent 45e1829 commit 3db242b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
45 changes: 31 additions & 14 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6232,7 +6232,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 @@ -6255,7 +6257,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 @@ -6392,19 +6399,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 @@ -6432,7 +6439,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 @@ -6452,18 +6462,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 @@ -6496,6 +6510,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 @@ -6848,14 +6848,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 @@ -6898,11 +6899,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 @@ -6942,6 +6945,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 @@ -6972,6 +6976,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 @@ -7282,6 +7287,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 @@ -7294,6 +7300,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

0 comments on commit 3db242b

Please sign in to comment.