Skip to content

Commit

Permalink
Merge pull request MarlinFirmware#4166 from gudnimg/gudnimg-patch-1
Browse files Browse the repository at this point in the history
M701/M702: Set default Z value to 0
  • Loading branch information
3d-gussner authored May 5, 2023
2 parents 12d9070 + fc15f5a commit bf6c091
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
16 changes: 10 additions & 6 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3566,8 +3566,10 @@ void gcode_M701(float fastLoadLength, uint8_t mmuSlotIndex){

prusa_statistics(22);

if (MMU2::mmu2.Enabled() && mmuSlotIndex < MMU_FILAMENT_COUNT) {
MMU2::mmu2.load_filament_to_nozzle(mmuSlotIndex);
if (MMU2::mmu2.Enabled()) {
if (mmuSlotIndex < MMU_FILAMENT_COUNT) {
MMU2::mmu2.load_filament_to_nozzle(mmuSlotIndex);
} // else do nothing
} else {
custom_message_type = CustomMsg::FilamentLoading;
lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT));
Expand Down Expand Up @@ -8390,13 +8392,13 @@ SERIAL_PROTOCOLPGM("\n\n");
- `P` - n index of MMU slot (zero based, so 0-4 like T0 and T4)
- `T` - Alias of `P`. Used for compatibility with Marlin
- `L` - Extrude distance for insertion (positive value)(manual reload)
- `Z` - Move the Z axis by this distance. Default value MIN_Z_FOR_LOAD
- `Z` - Move the Z axis by this distance. Default value is 0 to maintain backwards compatibility with older gcodes.
*/
case 701:
{
uint8_t mmuSlotIndex = 0xffU;
float fastLoadLength = FILAMENTCHANGE_FIRSTFEED; // Only used without MMU
float z_target = MIN_Z_FOR_LOAD;
float z_target = 0;
if( MMU2::mmu2.Enabled() )
{
if( code_seen('P') || code_seen('T') ) {
Expand All @@ -8408,6 +8410,7 @@ SERIAL_PROTOCOLPGM("\n\n");

// Z lift. For safety only allow positive values
if (code_seen('Z')) z_target = fabs(code_value());
else raise_z_above(MIN_Z_FOR_LOAD); // backwards compatibility for 3.12 and older FW

// Raise the Z axis
float delta = raise_z(z_target);
Expand All @@ -8428,16 +8431,17 @@ SERIAL_PROTOCOLPGM("\n\n");
#### Parameters
- `U` - Retract distance for removal (manual reload). Default value is 0.
- `Z` - Move the Z axis by this distance. Default value MIN_Z_FOR_UNLOAD.
- `Z` - Move the Z axis by this distance. Default value is 0 to maintain backwards compatibility with older gcodes.
*/
case 702:
{
float z_target = MIN_Z_FOR_UNLOAD;
float z_target = 0;
float unloadLength = FILAMENTCHANGE_FINALRETRACT;
if (code_seen('U')) unloadLength = code_value();

// For safety only allow positive values
if (code_seen('Z')) z_target = fabs(code_value());
else raise_z_above(MIN_Z_FOR_UNLOAD); // backwards compatibility for 3.12 and older FW

// Raise the Z axis
float delta = raise_z(z_target);
Expand Down
4 changes: 2 additions & 2 deletions Firmware/first_lay_cal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool lay1cal_load_filament(uint8_t filament)
return false;
} else if( currentTool != (uint8_t)MMU2::FILAMENT_UNKNOWN){
// some other slot is loaded, perform an unload first
enquecommand_P(MSG_M702_NO_LIFT);
enquecommand_P(MSG_M702);
}
// perform a toolchange
enquecommandf_P(PSTR("T%d"), filament);
Expand Down Expand Up @@ -245,6 +245,6 @@ void lay1cal_finish(bool mmu_enabled)

lay1cal_common_enqueue_loop(cmd_cal_finish, (sizeof(cmd_cal_finish)/sizeof(cmd_cal_finish[0])));

if (mmu_enabled) enquecommand_P(MSG_M702_NO_LIFT); //unload from nozzle
if (mmu_enabled) enquecommand_P(MSG_M702); //unload from nozzle
enquecommand_P(MSG_M84);// disable motors
}
4 changes: 2 additions & 2 deletions Firmware/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,5 @@ const char MSG_M107[] PROGMEM_N1 = "M107";
const char MSG_M220[] PROGMEM_N1 = "M220 S%d";
const char MSG_M500[] PROGMEM_N1 = "M500";
const char MSG_M600[] PROGMEM_N1 = "M600";
const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0";
const char MSG_M702_NO_LIFT[] PROGMEM_N1 = "M702 Z0";
const char MSG_M701[] PROGMEM_N1 = "M701";
const char MSG_M702[] PROGMEM_N1 = "M702";
4 changes: 2 additions & 2 deletions Firmware/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ extern const char MSG_M107[];
extern const char MSG_M220[];
extern const char MSG_M500[];
extern const char MSG_M600[];
extern const char MSG_M701_NO_LIFT[];
extern const char MSG_M702_NO_LIFT[];
extern const char MSG_M701[];
extern const char MSG_M702[];

#if defined(__cplusplus)
}
Expand Down
13 changes: 7 additions & 6 deletions Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,10 +1800,10 @@ switch(eFilamentAction)
// FALLTHRU
case FilamentAction::Load:
loading_flag=true;
enquecommand_P(MSG_M701_NO_LIFT); // load filament
enquecommand_P(MSG_M701); // load filament
break;
case FilamentAction::UnLoad:
enquecommand_P(MSG_M702_NO_LIFT); // unload filament
enquecommand_P(MSG_M702); // unload filament
break;
case FilamentAction::MmuLoad:
case FilamentAction::MmuLoadingTest:
Expand Down Expand Up @@ -1863,11 +1863,11 @@ void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad))
{
loading_flag = true;
enquecommand_P(MSG_M701_NO_LIFT); // load filament
enquecommand_P(MSG_M701); // load filament
if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
}
if (eFilamentAction == FilamentAction::UnLoad)
enquecommand_P(MSG_M702_NO_LIFT); // unload filament
enquecommand_P(MSG_M702); // unload filament
}
break;
case FilamentAction::MmuLoad:
Expand Down Expand Up @@ -3704,8 +3704,9 @@ static void lcd_wizard_load() {
lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
loading_flag = true;
}
gcode_M701(FILAMENTCHANGE_FIRSTFEED, 0);
//enquecommand_P(MSG_M701_NO_LIFT); // is enqueuecommand_P safe here?

// When MMU is disabled P parameter is ignored
enquecommand_P(PSTR("M701 P0"));
}

static void wizard_lay1cal_message(bool cold)
Expand Down

0 comments on commit bf6c091

Please sign in to comment.