Browse Source

Synchronize retractions

pull/1/head
Thomas Moore 7 years ago
committed by Scott Lahteine
parent
commit
ae2173cd52
  1. 32
      Marlin/src/feature/fwretract.cpp
  2. 23
      Marlin/src/feature/fwretract.h
  3. 1
      Marlin/src/gcode/feature/fwretract/G10_G11.cpp
  4. 3
      Marlin/src/gcode/feature/fwretract/M207-M209.cpp
  5. 2
      Marlin/src/lcd/ultralcd.cpp
  6. 4
      Marlin/src/module/configuration_store.cpp

32
Marlin/src/feature/fwretract.cpp

@ -30,13 +30,22 @@
#include "fwretract.h"
FWRetract fwretract; // Single instance
FWRetract fwretract; // Single instance - this calls the constructor
#include "../module/motion.h"
#include "../module/planner.h"
#include "../module/stepper.h"
// private:
#if EXTRUDERS > 1
bool FWRetract::retracted_swap[EXTRUDERS]; // Which extruders are swap-retracted
#endif
// public:
bool FWRetract::autoretract_enabled, // M209 S - Autoretract switch
FWRetract::retracted[EXTRUDERS] = { false }; // Which extruders are currently retracted
FWRetract::retracted[EXTRUDERS]; // Which extruders are currently retracted
float FWRetract::retract_length, // M207 S - G10 Retract length
FWRetract::retract_feedrate_mm_s, // M207 F - G10 Retract feedrate
FWRetract::retract_zlift, // M207 Z - G10 Retract hop size
@ -45,9 +54,6 @@ float FWRetract::retract_length, // M207 S - G10 Retract len
FWRetract::swap_retract_length, // M207 W - G10 Swap Retract length
FWRetract::swap_retract_recover_length, // M208 W - G11 Swap Recover length
FWRetract::swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
#if EXTRUDERS > 1
bool FWRetract::retracted_swap[EXTRUDERS] = { false }; // Which extruders are swap-retracted
#endif
void FWRetract::reset() {
autoretract_enabled = false;
@ -59,6 +65,13 @@ void FWRetract::reset() {
swap_retract_length = RETRACT_LENGTH_SWAP;
swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP;
swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
for (uint8_t i = 0; i < EXTRUDERS; ++i) {
retracted[i] = false;
#if EXTRUDERS > 1
retracted_swap[i] = false;
#endif
}
}
/**
@ -87,10 +100,11 @@ void FWRetract::retract(const bool retracting
// Simply never allow two retracts or recovers in a row
if (retracted[active_extruder] == retracting) return;
#if EXTRUDERS < 2
bool swapping = false;
#if EXTRUDERS > 1
if (!retracting) swapping = retracted_swap[active_extruder];
#else
const bool swapping = false;
#endif
if (!retracting) swapping = retracted_swap[active_extruder];
/* // debugging
SERIAL_ECHOLNPAIR("retracting ", retracting);
@ -117,6 +131,8 @@ void FWRetract::retract(const bool retracting
// The current position will be the destination for E and Z moves
set_destination_to_current();
stepper.synchronize(); // Wait for buffered moves to complete
if (retracting) {
// Remember the Z height since G-code may include its own Z-hop
// For best results turn off Z hop if G-code already includes it

23
Marlin/src/feature/fwretract.h

@ -30,6 +30,11 @@
#include "../inc/MarlinConfig.h"
class FWRetract {
private:
#if EXTRUDERS > 1
static bool retracted_swap[EXTRUDERS]; // Which extruders are swap-retracted
#endif
public:
static bool autoretract_enabled, // M209 S - Autoretract switch
retracted[EXTRUDERS]; // Which extruders are currently retracted
@ -42,22 +47,24 @@ public:
swap_retract_recover_length, // M208 W - G11 Swap Recover length
swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
#if EXTRUDERS > 1
static bool retracted_swap[EXTRUDERS]; // Which extruders are swap-retracted
#else
static bool constexpr retracted_swap[1] = { false };
#endif
FWRetract() {}
FWRetract() { reset(); }
static void reset();
static void refresh_autoretract() {
for (uint8_t i = 0; i < EXTRUDERS; i++) retracted[i] = false;
}
static void enable_autoretract(const bool enable) {
autoretract_enabled = enable;
refresh_autoretract();
}
static void retract(const bool retracting
#if EXTRUDERS > 1
, bool swapping = false
#endif
);
};
extern FWRetract fwretract;

1
Marlin/src/gcode/feature/fwretract/G10_G11.cpp

@ -34,7 +34,6 @@
void GcodeSuite::G10() {
#if EXTRUDERS > 1
const bool rs = parser.boolval('S');
fwretract.retracted_swap[active_extruder] = rs; // Use 'S' for swap, default to false
#endif
fwretract.retract(true
#if EXTRUDERS > 1

3
Marlin/src/gcode/feature/fwretract/M207-M209.cpp

@ -65,8 +65,7 @@ void GcodeSuite::M208() {
void GcodeSuite::M209() {
if (MIN_AUTORETRACT <= MAX_AUTORETRACT) {
if (parser.seen('S')) {
fwretract.autoretract_enabled = parser.value_bool();
for (uint8_t i = 0; i < EXTRUDERS; i++) fwretract.retracted[i] = false;
fwretract.enable_autoretract(parser.value_bool());
}
}
}

2
Marlin/src/lcd/ultralcd.cpp

@ -3557,7 +3557,7 @@ void kill_screen(const char* lcd_msg) {
void lcd_control_retract_menu() {
START_MENU();
MENU_BACK(MSG_CONTROL);
MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled);
MENU_ITEM_EDIT_CALLBACK(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled, fwretract.refresh_autoretract);
MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100);
#if EXTRUDERS > 1
MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100);

4
Marlin/src/module/configuration_store.cpp

@ -247,6 +247,10 @@ void MarlinSettings::postprocess() {
#if HAS_MOTOR_CURRENT_PWM
stepper.refresh_motor_power();
#endif
#if ENABLED(FWRETRACT)
fwretract.refresh_autoretract();
#endif
}
#if ENABLED(EEPROM_SETTINGS)

Loading…
Cancel
Save