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

M600: reduce stack usage #4419

Merged
merged 1 commit into from
Nov 24, 2023
Merged
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
4 changes: 2 additions & 2 deletions Firmware/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ void gcode_M701(float fastLoadLength, uint8_t mmuSlotIndex);

void M600_load_filament();
void M600_load_filament_movements();
void M600_wait_for_user(float HotendTempBckp);
void M600_check_state(float nozzle_temp);
void M600_wait_for_user();
void M600_check_state();
void load_filament_final_feed();
void marlin_wait_for_click();
float raise_z(float delta);
Expand Down
43 changes: 16 additions & 27 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3385,7 +3385,7 @@ static void mmu_M600_unload_filament() {

/// @brief load filament for mmu v2
/// @par nozzle_temp nozzle temperature to load filament
static void mmu_M600_load_filament(bool automatic, float nozzle_temp) {
static void mmu_M600_load_filament(bool automatic) {
uint8_t slot;
if (automatic) {
slot = SpoolJoin::spooljoin.nextSlot();
Expand All @@ -3394,7 +3394,7 @@ static void mmu_M600_load_filament(bool automatic, float nozzle_temp) {
slot = choose_menu_P(_T(MSG_SELECT_FILAMENT), _T(MSG_FILAMENT));
}

setTargetHotend(nozzle_temp);
setTargetHotend(saved_extruder_temperature);

MMU2::mmu2.load_filament_to_nozzle(slot);

Expand All @@ -3404,7 +3404,6 @@ static void mmu_M600_load_filament(bool automatic, float nozzle_temp) {

static void gcode_M600(const bool automatic, const float x_position, const float y_position, const float z_shift, const float e_shift, const float e_shift_late) {
st_synchronize();
float lastpos[4];

// When using an MMU, save the currently use slot number
// so the firmware can know which slot to eject after the filament
Expand All @@ -3413,13 +3412,6 @@ static void gcode_M600(const bool automatic, const float x_position, const float

prusa_statistics(22);

//First backup current position and settings
int feedmultiplyBckp = feedmultiply;
float HotendTempBckp = saved_extruder_temperature;
uint8_t fanSpeedBckp = fanSpeed;

memcpy(lastpos, current_position, sizeof(lastpos));

// Turn off the fan
fanSpeed = 0;

Expand Down Expand Up @@ -3450,7 +3442,7 @@ static void gcode_M600(const bool automatic, const float x_position, const float
mmu_M600_unload_filament();
} else {
// Beep, manage nozzle heater and wait for user to start unload filament
M600_wait_for_user(HotendTempBckp);
M600_wait_for_user();
unload_filament(e_shift_late);
}
st_synchronize(); // finish moves
Expand All @@ -3475,15 +3467,15 @@ static void gcode_M600(const bool automatic, const float x_position, const float
else // MMU is enabled
{
if (!automatic) mmu_M600_filament_change_screen(eject_slot);
mmu_M600_load_filament(automatic, HotendTempBckp);
mmu_M600_load_filament(automatic);
}
if (!automatic)
M600_check_state(HotendTempBckp);
M600_check_state();

lcd_update_enable(true);

// Not let's go back to print
fanSpeed = fanSpeedBckp;
fanSpeed = saved_fan_speed;

// Feed a little of filament to stabilize pressure
if (!automatic) {
Expand All @@ -3506,22 +3498,22 @@ static void gcode_M600(const bool automatic, const float x_position, const float
}

// Move XY back
plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_XYFEED);
plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_XYFEED);
st_synchronize();

// Move Z back
plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_ZFEED);
plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_ZFEED);
st_synchronize();

// Set E position to original
plan_set_e_position(lastpos[E_AXIS]);
plan_set_e_position(saved_pos[E_AXIS]);

memcpy(current_position, lastpos, sizeof(lastpos));
memcpy(current_position, saved_pos, sizeof(saved_pos));
set_destination_to_current();

// Recover feed rate
feedmultiply = feedmultiplyBckp;
enquecommandf_P(MSG_M220, feedmultiplyBckp);
feedmultiply = saved_feedmultiply2;
enquecommandf_P(MSG_M220, saved_feedmultiply2);
}
if (isPrintPaused) lcd_setstatuspgm(_T(MSG_PRINT_PAUSED));
else lcd_setstatuspgm(MSG_WELCOME);
Expand Down Expand Up @@ -10832,8 +10824,7 @@ void load_filament_final_feed()
}

//! @brief Wait for user to check the state
//! @par nozzle_temp nozzle temperature to load filament
void M600_check_state(float nozzle_temp)
void M600_check_state()
{
uint8_t lcd_change_filament_state = 0;
while (lcd_change_filament_state != 1)
Expand All @@ -10855,7 +10846,7 @@ void M600_check_state(float nozzle_temp)
mmu_M600_filament_change_screen(eject_slot);

// After user clicks knob, MMU will load the filament
mmu_M600_load_filament(false, nozzle_temp);
mmu_M600_load_filament(false);
} else {
M600_load_filament_movements();
}
Expand All @@ -10881,9 +10872,7 @@ void M600_check_state(float nozzle_temp)
//!
//! Beep, manage nozzle heater and wait for user to start unload filament
//! If times out, active extruder temperature is set to 0.
//!
//! @param HotendTempBckp Temperature to be restored for active extruder, after user resolves MMU problem.
void M600_wait_for_user(float HotendTempBckp) {
void M600_wait_for_user() {

KEEPALIVE_STATE(PAUSED_FOR_USER);

Expand Down Expand Up @@ -10912,7 +10901,7 @@ void M600_wait_for_user(float HotendTempBckp) {
delay_keep_alive(4);

if (lcd_clicked()) {
setTargetHotend(HotendTempBckp);
setTargetHotend(saved_extruder_temperature);
lcd_wait_for_heater();
wait_for_user_state = 2;
}
Expand Down
Loading