You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1073 lines
28 KiB
1073 lines
28 KiB
6 years ago
|
/**
|
||
|
* Marlin 3D Printer Firmware
|
||
5 years ago
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||
6 years ago
|
*
|
||
|
* Based on Sprinter and grbl.
|
||
5 years ago
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||
6 years ago
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
4 years ago
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
6 years ago
|
*
|
||
|
*/
|
||
|
|
||
|
#include "../../inc/MarlinConfig.h"
|
||
|
|
||
4 years ago
|
#if HAS_PRUSA_MMU2
|
||
6 years ago
|
|
||
|
#include "mmu2.h"
|
||
6 years ago
|
#include "../../lcd/menu/menu_mmu2.h"
|
||
6 years ago
|
|
||
|
MMU2 mmu2;
|
||
|
|
||
|
#include "../../gcode/gcode.h"
|
||
4 years ago
|
#include "../../lcd/marlinui.h"
|
||
6 years ago
|
#include "../../libs/buzzer.h"
|
||
|
#include "../../libs/nozzle.h"
|
||
|
#include "../../module/temperature.h"
|
||
|
#include "../../module/planner.h"
|
||
5 years ago
|
#include "../../module/stepper/indirection.h"
|
||
5 years ago
|
#include "../../MarlinCore.h"
|
||
6 years ago
|
|
||
6 years ago
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
||
|
#include "../../feature/host_actions.h"
|
||
|
#endif
|
||
|
|
||
5 years ago
|
#if ENABLED(EXTENSIBLE_UI)
|
||
5 years ago
|
#include "../../lcd/extui/ui_api.h"
|
||
5 years ago
|
#endif
|
||
|
|
||
6 years ago
|
#define DEBUG_OUT ENABLED(MMU2_DEBUG)
|
||
|
#include "../../core/debug_out.h"
|
||
|
|
||
6 years ago
|
#define MMU_TODELAY 100
|
||
|
#define MMU_TIMEOUT 10
|
||
5 years ago
|
#define MMU_CMD_TIMEOUT 45000UL // 45s timeout for mmu commands (except P0)
|
||
|
#define MMU_P0_TIMEOUT 3000UL // Timeout for P0 command: 3seconds
|
||
|
|
||
4 years ago
|
#define MMU2_COMMAND(S) tx_str_P(PSTR(S "\n"))
|
||
|
|
||
5 years ago
|
#if ENABLED(MMU_EXTRUDER_SENSOR)
|
||
|
uint8_t mmu_idl_sens = 0;
|
||
|
static bool mmu_loading_flag = false;
|
||
|
#endif
|
||
6 years ago
|
|
||
|
#define MMU_CMD_NONE 0
|
||
|
#define MMU_CMD_T0 0x10
|
||
|
#define MMU_CMD_T1 0x11
|
||
|
#define MMU_CMD_T2 0x12
|
||
|
#define MMU_CMD_T3 0x13
|
||
|
#define MMU_CMD_T4 0x14
|
||
|
#define MMU_CMD_L0 0x20
|
||
|
#define MMU_CMD_L1 0x21
|
||
|
#define MMU_CMD_L2 0x22
|
||
|
#define MMU_CMD_L3 0x23
|
||
|
#define MMU_CMD_L4 0x24
|
||
|
#define MMU_CMD_C0 0x30
|
||
|
#define MMU_CMD_U0 0x40
|
||
|
#define MMU_CMD_E0 0x50
|
||
|
#define MMU_CMD_E1 0x51
|
||
|
#define MMU_CMD_E2 0x52
|
||
|
#define MMU_CMD_E3 0x53
|
||
|
#define MMU_CMD_E4 0x54
|
||
|
#define MMU_CMD_R0 0x60
|
||
|
#define MMU_CMD_F0 0x70
|
||
|
#define MMU_CMD_F1 0x71
|
||
|
#define MMU_CMD_F2 0x72
|
||
|
#define MMU_CMD_F3 0x73
|
||
|
#define MMU_CMD_F4 0x74
|
||
|
|
||
5 years ago
|
#define MMU_REQUIRED_FW_BUILDNR TERN(MMU2_MODE_12V, 132, 126)
|
||
6 years ago
|
|
||
|
#define MMU2_NO_TOOL 99
|
||
|
#define MMU_BAUD 115200
|
||
|
|
||
|
#define mmuSerial MMU2_SERIAL
|
||
|
|
||
|
bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved;
|
||
4 years ago
|
#if HAS_PRUSA_MMU2S
|
||
5 years ago
|
bool MMU2::mmu2s_triggered;
|
||
|
#endif
|
||
6 years ago
|
uint8_t MMU2::cmd, MMU2::cmd_arg, MMU2::last_cmd, MMU2::extruder;
|
||
|
int8_t MMU2::state = 0;
|
||
|
volatile int8_t MMU2::finda = 1;
|
||
6 years ago
|
volatile bool MMU2::finda_runout_valid;
|
||
6 years ago
|
int16_t MMU2::version = -1, MMU2::buildnr = -1;
|
||
5 years ago
|
millis_t MMU2::prev_request, MMU2::prev_P0_request;
|
||
5 years ago
|
char MMU2::rx_buffer[MMU_RX_SIZE], MMU2::tx_buffer[MMU_TX_SIZE];
|
||
6 years ago
|
|
||
4 years ago
|
struct E_Step {
|
||
|
float extrude; //!< extrude distance in mm
|
||
|
feedRate_t feedRate; //!< feed rate in mm/s
|
||
|
};
|
||
|
|
||
|
static constexpr E_Step
|
||
|
ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE }
|
||
|
, load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE }
|
||
|
#if HAS_PRUSA_MMU2S
|
||
|
, can_load_sequence[] PROGMEM = { MMU2_CAN_LOAD_SEQUENCE }
|
||
|
, can_load_increment_sequence[] PROGMEM = { MMU2_CAN_LOAD_INCREMENT_SEQUENCE }
|
||
|
#endif
|
||
|
;
|
||
6 years ago
|
|
||
|
MMU2::MMU2() {
|
||
|
rx_buffer[0] = '\0';
|
||
|
}
|
||
|
|
||
|
void MMU2::init() {
|
||
6 years ago
|
|
||
|
set_runout_valid(false);
|
||
6 years ago
|
|
||
|
#if PIN_EXISTS(MMU2_RST)
|
||
|
// TODO use macros for this
|
||
|
WRITE(MMU2_RST_PIN, HIGH);
|
||
|
SET_OUTPUT(MMU2_RST_PIN);
|
||
|
#endif
|
||
|
|
||
|
mmuSerial.begin(MMU_BAUD);
|
||
|
extruder = MMU2_NO_TOOL;
|
||
|
|
||
|
safe_delay(10);
|
||
|
reset();
|
||
|
rx_buffer[0] = '\0';
|
||
|
state = -1;
|
||
|
}
|
||
|
|
||
|
void MMU2::reset() {
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU <= reset");
|
||
6 years ago
|
|
||
|
#if PIN_EXISTS(MMU2_RST)
|
||
|
WRITE(MMU2_RST_PIN, LOW);
|
||
|
safe_delay(20);
|
||
|
WRITE(MMU2_RST_PIN, HIGH);
|
||
|
#else
|
||
4 years ago
|
MMU2_COMMAND("X0"); // Send soft reset
|
||
6 years ago
|
#endif
|
||
|
}
|
||
|
|
||
6 years ago
|
uint8_t MMU2::get_current_tool() {
|
||
6 years ago
|
return extruder == MMU2_NO_TOOL ? -1 : extruder;
|
||
|
}
|
||
|
|
||
4 years ago
|
#if EITHER(HAS_PRUSA_MMU2S, MMU_EXTRUDER_SENSOR)
|
||
4 years ago
|
#define FILAMENT_PRESENT() (READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE)
|
||
5 years ago
|
#endif
|
||
|
|
||
6 years ago
|
void MMU2::mmu_loop() {
|
||
6 years ago
|
|
||
|
switch (state) {
|
||
|
|
||
|
case 0: break;
|
||
|
|
||
|
case -1:
|
||
|
if (rx_start()) {
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU => 'start'");
|
||
|
DEBUG_ECHOLNPGM("MMU <= 'S1'");
|
||
6 years ago
|
|
||
4 years ago
|
MMU2_COMMAND("S1"); // Read Version
|
||
6 years ago
|
state = -2;
|
||
|
}
|
||
|
else if (millis() > 3000000) {
|
||
|
SERIAL_ECHOLNPGM("MMU not responding - DISABLED");
|
||
|
state = 0;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case -2:
|
||
|
if (rx_ok()) {
|
||
4 years ago
|
sscanf(rx_buffer, "%huok\n", &version);
|
||
6 years ago
|
|
||
6 years ago
|
DEBUG_ECHOLNPAIR("MMU => ", version, "\nMMU <= 'S2'");
|
||
6 years ago
|
|
||
4 years ago
|
MMU2_COMMAND("S2"); // Read Build Number
|
||
6 years ago
|
state = -3;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case -3:
|
||
|
if (rx_ok()) {
|
||
4 years ago
|
sscanf(rx_buffer, "%huok\n", &buildnr);
|
||
6 years ago
|
|
||
|
DEBUG_ECHOLNPAIR("MMU => ", buildnr);
|
||
6 years ago
|
|
||
6 years ago
|
check_version();
|
||
6 years ago
|
|
||
|
#if ENABLED(MMU2_MODE_12V)
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU <= 'M1'");
|
||
6 years ago
|
|
||
4 years ago
|
MMU2_COMMAND("M1"); // Stealth Mode
|
||
6 years ago
|
state = -5;
|
||
|
|
||
|
#else
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU <= 'P0'");
|
||
6 years ago
|
|
||
4 years ago
|
MMU2_COMMAND("P0"); // Read FINDA
|
||
6 years ago
|
state = -4;
|
||
|
#endif
|
||
|
}
|
||
|
break;
|
||
|
|
||
6 years ago
|
#if ENABLED(MMU2_MODE_12V)
|
||
6 years ago
|
case -5:
|
||
|
// response to M1
|
||
|
if (rx_ok()) {
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU => ok");
|
||
6 years ago
|
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU <= 'P0'");
|
||
6 years ago
|
|
||
4 years ago
|
MMU2_COMMAND("P0"); // Read FINDA
|
||
6 years ago
|
state = -4;
|
||
|
}
|
||
|
break;
|
||
6 years ago
|
#endif
|
||
6 years ago
|
|
||
6 years ago
|
case -4:
|
||
6 years ago
|
if (rx_ok()) {
|
||
|
sscanf(rx_buffer, "%hhuok\n", &finda);
|
||
|
|
||
6 years ago
|
DEBUG_ECHOLNPAIR("MMU => ", finda, "\nMMU - ENABLED");
|
||
6 years ago
|
|
||
|
enabled = true;
|
||
|
state = 1;
|
||
4 years ago
|
TERN_(HAS_PRUSA_MMU2S, mmu2s_triggered = false);
|
||
6 years ago
|
}
|
||
|
break;
|
||
|
|
||
|
case 1:
|
||
|
if (cmd) {
|
||
|
if (WITHIN(cmd, MMU_CMD_T0, MMU_CMD_T4)) {
|
||
|
// tool change
|
||
|
int filament = cmd - MMU_CMD_T0;
|
||
6 years ago
|
DEBUG_ECHOLNPAIR("MMU <= T", filament);
|
||
6 years ago
|
tx_printf_P(PSTR("T%d\n"), filament);
|
||
5 years ago
|
TERN_(MMU_EXTRUDER_SENSOR, mmu_idl_sens = 1); // enable idler sensor, if any
|
||
6 years ago
|
state = 3; // wait for response
|
||
|
}
|
||
|
else if (WITHIN(cmd, MMU_CMD_L0, MMU_CMD_L4)) {
|
||
|
// load
|
||
|
int filament = cmd - MMU_CMD_L0;
|
||
6 years ago
|
DEBUG_ECHOLNPAIR("MMU <= L", filament);
|
||
6 years ago
|
tx_printf_P(PSTR("L%d\n"), filament);
|
||
|
state = 3; // wait for response
|
||
|
}
|
||
|
else if (cmd == MMU_CMD_C0) {
|
||
|
// continue loading
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU <= 'C0'");
|
||
4 years ago
|
MMU2_COMMAND("C0");
|
||
6 years ago
|
state = 3; // wait for response
|
||
|
}
|
||
|
else if (cmd == MMU_CMD_U0) {
|
||
|
// unload current
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU <= 'U0'");
|
||
6 years ago
|
|
||
4 years ago
|
MMU2_COMMAND("U0");
|
||
6 years ago
|
state = 3; // wait for response
|
||
|
}
|
||
|
else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E4)) {
|
||
|
// eject filament
|
||
|
int filament = cmd - MMU_CMD_E0;
|
||
6 years ago
|
DEBUG_ECHOLNPAIR("MMU <= E", filament);
|
||
6 years ago
|
tx_printf_P(PSTR("E%d\n"), filament);
|
||
|
state = 3; // wait for response
|
||
|
}
|
||
|
else if (cmd == MMU_CMD_R0) {
|
||
|
// recover after eject
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU <= 'R0'");
|
||
4 years ago
|
MMU2_COMMAND("R0");
|
||
6 years ago
|
state = 3; // wait for response
|
||
|
}
|
||
|
else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F4)) {
|
||
|
// filament type
|
||
|
int filament = cmd - MMU_CMD_F0;
|
||
6 years ago
|
DEBUG_ECHOPAIR("MMU <= F", filament, " ");
|
||
|
DEBUG_ECHO_F(cmd_arg, DEC);
|
||
|
DEBUG_EOL();
|
||
6 years ago
|
tx_printf_P(PSTR("F%d %d\n"), filament, cmd_arg);
|
||
|
state = 3; // wait for response
|
||
|
}
|
||
|
|
||
|
last_cmd = cmd;
|
||
|
cmd = MMU_CMD_NONE;
|
||
|
}
|
||
5 years ago
|
else if (ELAPSED(millis(), prev_P0_request + 300)) {
|
||
4 years ago
|
MMU2_COMMAND("P0"); // Read FINDA
|
||
6 years ago
|
state = 2; // wait for response
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
TERN_(HAS_PRUSA_MMU2S, check_filament());
|
||
6 years ago
|
break;
|
||
|
|
||
|
case 2: // response to command P0
|
||
|
if (rx_ok()) {
|
||
|
sscanf(rx_buffer, "%hhuok\n", &finda);
|
||
|
|
||
6 years ago
|
// This is super annoying. Only activate if necessary
|
||
6 years ago
|
// if (finda_runout_valid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6);
|
||
6 years ago
|
|
||
6 years ago
|
if (!finda && finda_runout_valid) filament_runout();
|
||
5 years ago
|
if (cmd == 0) ready = true;
|
||
|
state = 1;
|
||
6 years ago
|
}
|
||
5 years ago
|
else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
|
||
6 years ago
|
state = 1;
|
||
|
|
||
4 years ago
|
TERN_(HAS_PRUSA_MMU2S, check_filament());
|
||
6 years ago
|
break;
|
||
|
|
||
|
case 3: // response to mmu commands
|
||
5 years ago
|
#if ENABLED(MMU_EXTRUDER_SENSOR)
|
||
|
if (mmu_idl_sens) {
|
||
|
if (FILAMENT_PRESENT() && mmu_loading_flag) {
|
||
4 years ago
|
DEBUG_ECHOLNPGM("MMU <= 'A'");
|
||
|
MMU2_COMMAND("A"); // send 'abort' request
|
||
5 years ago
|
mmu_idl_sens = 0;
|
||
4 years ago
|
DEBUG_ECHOLNPGM("MMU IDLER_SENSOR = 0 - ABORT");
|
||
5 years ago
|
}
|
||
|
}
|
||
|
#endif
|
||
|
|
||
6 years ago
|
if (rx_ok()) {
|
||
4 years ago
|
// Response to C0 mmu command in MMU2S model
|
||
4 years ago
|
bool can_reset = true;
|
||
4 years ago
|
#if HAS_PRUSA_MMU2S
|
||
4 years ago
|
if (!mmu2s_triggered && last_cmd == MMU_CMD_C0) {
|
||
4 years ago
|
can_reset = false;
|
||
|
// MMU ok received but filament sensor not triggered, retrying...
|
||
|
DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)");
|
||
|
DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
|
||
|
MMU2_COMMAND("C0");
|
||
|
}
|
||
4 years ago
|
#endif
|
||
4 years ago
|
if (can_reset) {
|
||
|
DEBUG_ECHOLNPGM("MMU => 'ok'");
|
||
|
ready = true;
|
||
|
state = 1;
|
||
|
last_cmd = MMU_CMD_NONE;
|
||
|
}
|
||
6 years ago
|
}
|
||
5 years ago
|
else if (ELAPSED(millis(), prev_request + MMU_CMD_TIMEOUT)) {
|
||
6 years ago
|
// resend request after timeout
|
||
|
if (last_cmd) {
|
||
6 years ago
|
DEBUG_ECHOLNPGM("MMU retry");
|
||
6 years ago
|
cmd = last_cmd;
|
||
|
last_cmd = MMU_CMD_NONE;
|
||
|
}
|
||
|
state = 1;
|
||
|
}
|
||
4 years ago
|
TERN_(HAS_PRUSA_MMU2S, check_filament());
|
||
6 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if MMU was started
|
||
|
*/
|
||
|
bool MMU2::rx_start() {
|
||
|
// check for start message
|
||
|
if (rx_str_P(PSTR("start\n"))) {
|
||
5 years ago
|
prev_P0_request = millis();
|
||
6 years ago
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if the data received ends with the given string.
|
||
|
*/
|
||
|
bool MMU2::rx_str_P(const char* str) {
|
||
|
uint8_t i = strlen(rx_buffer);
|
||
|
|
||
|
while (mmuSerial.available()) {
|
||
|
rx_buffer[i++] = mmuSerial.read();
|
||
|
rx_buffer[i] = '\0';
|
||
|
|
||
|
if (i == sizeof(rx_buffer) - 1) {
|
||
6 years ago
|
DEBUG_ECHOLNPGM("rx buffer overrun");
|
||
6 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
uint8_t len = strlen_P(str);
|
||
|
|
||
|
if (i < len) return false;
|
||
|
|
||
|
str += len;
|
||
|
|
||
|
while (len--) {
|
||
|
char c0 = pgm_read_byte(str--), c1 = rx_buffer[i--];
|
||
|
if (c0 == c1) continue;
|
||
|
if (c0 == '\r' && c1 == '\n') continue; // match cr as lf
|
||
|
if (c0 == '\n' && c1 == '\r') continue; // match lf as cr
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Transfer data to MMU, no argument
|
||
|
*/
|
||
|
void MMU2::tx_str_P(const char* str) {
|
||
|
clear_rx_buffer();
|
||
|
uint8_t len = strlen_P(str);
|
||
5 years ago
|
LOOP_L_N(i, len) mmuSerial.write(pgm_read_byte(str++));
|
||
6 years ago
|
rx_buffer[0] = '\0';
|
||
5 years ago
|
prev_request = millis();
|
||
6 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Transfer data to MMU, single argument
|
||
|
*/
|
||
|
void MMU2::tx_printf_P(const char* format, int argument = -1) {
|
||
|
clear_rx_buffer();
|
||
|
uint8_t len = sprintf_P(tx_buffer, format, argument);
|
||
5 years ago
|
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
|
||
6 years ago
|
rx_buffer[0] = '\0';
|
||
5 years ago
|
prev_request = millis();
|
||
6 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Transfer data to MMU, two arguments
|
||
|
*/
|
||
|
void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
|
||
|
clear_rx_buffer();
|
||
|
uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
|
||
5 years ago
|
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
|
||
6 years ago
|
rx_buffer[0] = '\0';
|
||
5 years ago
|
prev_request = millis();
|
||
6 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Empty the rx buffer
|
||
|
*/
|
||
|
void MMU2::clear_rx_buffer() {
|
||
|
while (mmuSerial.available()) mmuSerial.read();
|
||
|
rx_buffer[0] = '\0';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if we received 'ok' from MMU
|
||
|
*/
|
||
|
bool MMU2::rx_ok() {
|
||
|
if (rx_str_P(PSTR("ok\n"))) {
|
||
5 years ago
|
prev_P0_request = millis();
|
||
6 years ago
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if MMU has compatible firmware
|
||
|
*/
|
||
6 years ago
|
void MMU2::check_version() {
|
||
6 years ago
|
if (buildnr < MMU_REQUIRED_FW_BUILDNR) {
|
||
5 years ago
|
SERIAL_ERROR_MSG("Invalid MMU2 firmware. Version >= " STRINGIFY(MMU_REQUIRED_FW_BUILDNR) " required.");
|
||
5 years ago
|
kill(GET_TEXT(MSG_KILL_MMU2_FIRMWARE));
|
||
6 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
static void mmu2_not_responding() {
|
||
5 years ago
|
LCD_MESSAGEPGM(MSG_MMU2_NOT_RESPONDING);
|
||
|
BUZZ(100, 659);
|
||
|
BUZZ(200, 698);
|
||
|
BUZZ(100, 659);
|
||
|
BUZZ(300, 440);
|
||
|
BUZZ(100, 659);
|
||
|
}
|
||
|
|
||
4 years ago
|
#if HAS_PRUSA_MMU2S
|
||
5 years ago
|
|
||
|
bool MMU2::load_to_gears() {
|
||
|
command(MMU_CMD_C0);
|
||
|
manage_response(true, true);
|
||
|
LOOP_L_N(i, MMU2_C0_RETRY) { // Keep loading until filament reaches gears
|
||
|
if (mmu2s_triggered) break;
|
||
|
command(MMU_CMD_C0);
|
||
|
manage_response(true, true);
|
||
|
check_filament();
|
||
|
}
|
||
|
const bool success = mmu2s_triggered && can_load();
|
||
|
if (!success) mmu2_not_responding();
|
||
|
return success;
|
||
|
}
|
||
|
|
||
5 years ago
|
/**
|
||
|
* Handle tool change
|
||
|
*/
|
||
|
void MMU2::tool_change(const uint8_t index) {
|
||
|
|
||
|
if (!enabled) return;
|
||
|
|
||
|
set_runout_valid(false);
|
||
|
|
||
|
if (index != extruder) {
|
||
|
|
||
|
DISABLE_AXIS_E0();
|
||
|
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
|
||
|
|
||
|
command(MMU_CMD_T0 + index);
|
||
|
manage_response(true, true);
|
||
|
|
||
|
if (load_to_gears()) {
|
||
|
extruder = index; // filament change is finished
|
||
|
active_extruder = 0;
|
||
|
ENABLE_AXIS_E0();
|
||
|
SERIAL_ECHO_START();
|
||
|
SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));
|
||
|
}
|
||
|
ui.reset_status();
|
||
|
}
|
||
|
|
||
|
set_runout_valid(true);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Handle special T?/Tx/Tc commands
|
||
|
*
|
||
|
* T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically
|
||
|
* Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load.
|
||
|
* Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated.
|
||
|
*/
|
||
|
void MMU2::tool_change(const char* special) {
|
||
4 years ago
|
if (!enabled) return;
|
||
5 years ago
|
|
||
|
set_runout_valid(false);
|
||
|
|
||
|
switch (*special) {
|
||
|
case '?': {
|
||
4 years ago
|
#if ENABLED(MMU2_MENUS)
|
||
|
const uint8_t index = mmu2_choose_filament();
|
||
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
|
||
|
load_filament_to_nozzle(index);
|
||
|
#else
|
||
|
BUZZ(400, 40);
|
||
|
#endif
|
||
5 years ago
|
} break;
|
||
|
|
||
|
case 'x': {
|
||
4 years ago
|
#if ENABLED(MMU2_MENUS)
|
||
|
planner.synchronize();
|
||
|
const uint8_t index = mmu2_choose_filament();
|
||
|
DISABLE_AXIS_E0();
|
||
|
command(MMU_CMD_T0 + index);
|
||
|
manage_response(true, true);
|
||
|
|
||
|
if (load_to_gears()) {
|
||
|
mmu_loop();
|
||
|
ENABLE_AXIS_E0();
|
||
|
extruder = index;
|
||
|
active_extruder = 0;
|
||
|
}
|
||
|
#else
|
||
|
BUZZ(400, 40);
|
||
|
#endif
|
||
5 years ago
|
} break;
|
||
|
|
||
|
case 'c': {
|
||
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
|
||
|
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
|
||
|
} break;
|
||
|
}
|
||
|
|
||
|
set_runout_valid(true);
|
||
|
}
|
||
|
|
||
|
#elif ENABLED(MMU_EXTRUDER_SENSOR)
|
||
|
|
||
|
/**
|
||
|
* Handle tool change
|
||
|
*/
|
||
|
void MMU2::tool_change(const uint8_t index) {
|
||
|
if (!enabled) return;
|
||
|
|
||
|
set_runout_valid(false);
|
||
|
|
||
|
if (index != extruder) {
|
||
|
DISABLE_AXIS_E0();
|
||
|
if (FILAMENT_PRESENT()) {
|
||
|
DEBUG_ECHOLNPGM("Unloading\n");
|
||
|
mmu_loading_flag = false;
|
||
|
command(MMU_CMD_U0);
|
||
|
manage_response(true, true);
|
||
|
}
|
||
|
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
|
||
|
mmu_loading_flag = true;
|
||
|
command(MMU_CMD_T0 + index);
|
||
|
manage_response(true, true);
|
||
|
mmu_continue_loading();
|
||
|
command(MMU_CMD_C0);
|
||
|
extruder = index;
|
||
|
active_extruder = 0;
|
||
|
|
||
|
ENABLE_AXIS_E0();
|
||
|
SERIAL_ECHO_START();
|
||
|
SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));
|
||
|
|
||
|
ui.reset_status();
|
||
|
}
|
||
|
|
||
|
set_runout_valid(true);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Handle special T?/Tx/Tc commands
|
||
|
*
|
||
|
* T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically
|
||
|
* Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load.
|
||
|
* Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated.
|
||
|
*/
|
||
|
void MMU2::tool_change(const char* special) {
|
||
|
if (!enabled) return;
|
||
|
|
||
4 years ago
|
set_runout_valid(false);
|
||
5 years ago
|
|
||
4 years ago
|
switch (*special) {
|
||
|
case '?': {
|
||
|
DEBUG_ECHOLNPGM("case ?\n");
|
||
|
#if ENABLED(MMU2_MENUS)
|
||
5 years ago
|
uint8_t index = mmu2_choose_filament();
|
||
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
|
||
|
load_filament_to_nozzle(index);
|
||
4 years ago
|
#else
|
||
|
BUZZ(400, 40);
|
||
|
#endif
|
||
|
} break;
|
||
5 years ago
|
|
||
4 years ago
|
case 'x': {
|
||
|
DEBUG_ECHOLNPGM("case x\n");
|
||
|
#if ENABLED(MMU2_MENUS)
|
||
5 years ago
|
planner.synchronize();
|
||
|
uint8_t index = mmu2_choose_filament();
|
||
|
DISABLE_AXIS_E0();
|
||
|
command(MMU_CMD_T0 + index);
|
||
|
manage_response(true, true);
|
||
|
mmu_continue_loading();
|
||
|
command(MMU_CMD_C0);
|
||
|
mmu_loop();
|
||
|
|
||
|
ENABLE_AXIS_E0();
|
||
|
extruder = index;
|
||
|
active_extruder = 0;
|
||
4 years ago
|
#else
|
||
|
BUZZ(400, 40);
|
||
|
#endif
|
||
|
} break;
|
||
5 years ago
|
|
||
4 years ago
|
case 'c': {
|
||
|
DEBUG_ECHOLNPGM("case c\n");
|
||
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
|
||
|
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
|
||
|
} break;
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
set_runout_valid(true);
|
||
5 years ago
|
}
|
||
|
|
||
|
void MMU2::mmu_continue_loading() {
|
||
|
for (uint8_t i = 0; i < MMU_LOADING_ATTEMPTS_NR; i++) {
|
||
|
DEBUG_ECHOLNPAIR("Additional load attempt #", i);
|
||
|
if (FILAMENT_PRESENT()) break;
|
||
|
command(MMU_CMD_C0);
|
||
|
manage_response(true, true);
|
||
|
}
|
||
|
if (!FILAMENT_PRESENT()) {
|
||
|
DEBUG_ECHOLNPGM("Filament never reached sensor, runout");
|
||
|
filament_runout();
|
||
|
}
|
||
|
mmu_idl_sens = 0;
|
||
|
}
|
||
|
|
||
4 years ago
|
#else // !HAS_PRUSA_MMU2S && !MMU_EXTRUDER_SENSOR
|
||
5 years ago
|
|
||
4 years ago
|
/**
|
||
|
* Handle tool change
|
||
|
*/
|
||
|
void MMU2::tool_change(const uint8_t index) {
|
||
|
if (!enabled) return;
|
||
6 years ago
|
|
||
4 years ago
|
set_runout_valid(false);
|
||
6 years ago
|
|
||
4 years ago
|
if (index != extruder) {
|
||
|
DISABLE_AXIS_E0();
|
||
|
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
|
||
|
command(MMU_CMD_T0 + index);
|
||
|
manage_response(true, true);
|
||
|
command(MMU_CMD_C0);
|
||
|
extruder = index; //filament change is finished
|
||
|
active_extruder = 0;
|
||
|
ENABLE_AXIS_E0();
|
||
|
SERIAL_ECHO_START();
|
||
|
SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));
|
||
|
ui.reset_status();
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
set_runout_valid(true);
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
/**
|
||
|
* Handle special T?/Tx/Tc commands
|
||
|
*
|
||
|
* T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically
|
||
|
* Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load.
|
||
|
* Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated.
|
||
|
*/
|
||
|
void MMU2::tool_change(const char* special) {
|
||
|
if (!enabled) return;
|
||
6 years ago
|
|
||
6 years ago
|
set_runout_valid(false);
|
||
6 years ago
|
|
||
6 years ago
|
switch (*special) {
|
||
6 years ago
|
case '?': {
|
||
5 years ago
|
DEBUG_ECHOLNPGM("case ?\n");
|
||
4 years ago
|
#if ENABLED(MMU2_MENUS)
|
||
|
uint8_t index = mmu2_choose_filament();
|
||
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
|
||
|
load_filament_to_nozzle(index);
|
||
|
#else
|
||
|
BUZZ(400, 40);
|
||
|
#endif
|
||
6 years ago
|
} break;
|
||
|
|
||
|
case 'x': {
|
||
5 years ago
|
DEBUG_ECHOLNPGM("case x\n");
|
||
4 years ago
|
#if ENABLED(MMU2_MENUS)
|
||
|
planner.synchronize();
|
||
|
uint8_t index = mmu2_choose_filament();
|
||
|
DISABLE_AXIS_E0();
|
||
|
command(MMU_CMD_T0 + index);
|
||
|
manage_response(true, true);
|
||
|
command(MMU_CMD_C0);
|
||
|
mmu_loop();
|
||
6 years ago
|
|
||
4 years ago
|
ENABLE_AXIS_E0();
|
||
|
extruder = index;
|
||
|
active_extruder = 0;
|
||
|
#else
|
||
|
BUZZ(400, 40);
|
||
|
#endif
|
||
6 years ago
|
} break;
|
||
|
|
||
|
case 'c': {
|
||
5 years ago
|
DEBUG_ECHOLNPGM("case c\n");
|
||
6 years ago
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
|
||
6 years ago
|
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
|
||
6 years ago
|
} break;
|
||
|
}
|
||
|
|
||
6 years ago
|
set_runout_valid(true);
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
#endif // HAS_PRUSA_MMU2S
|
||
6 years ago
|
|
||
|
/**
|
||
|
* Set next command
|
||
|
*/
|
||
|
void MMU2::command(const uint8_t mmu_cmd) {
|
||
|
if (!enabled) return;
|
||
|
cmd = mmu_cmd;
|
||
|
ready = false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Wait for response from MMU
|
||
|
*/
|
||
5 years ago
|
bool MMU2::get_response() {
|
||
6 years ago
|
while (cmd != MMU_CMD_NONE) idle();
|
||
|
|
||
|
while (!ready) {
|
||
|
idle();
|
||
|
if (state != 3) break;
|
||
|
}
|
||
|
|
||
|
const bool ret = ready;
|
||
|
ready = false;
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Wait for response and deal with timeout if nexcessary
|
||
|
*/
|
||
5 years ago
|
void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
|
||
6 years ago
|
|
||
5 years ago
|
constexpr xyz_pos_t park_point = NOZZLE_PARK_POINT;
|
||
6 years ago
|
bool response = false;
|
||
|
mmu_print_saved = false;
|
||
5 years ago
|
xyz_pos_t resume_position;
|
||
5 years ago
|
int16_t resume_hotend_temp = thermalManager.degTargetHotend(active_extruder);
|
||
6 years ago
|
|
||
5 years ago
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
||
|
|
||
6 years ago
|
while (!response) {
|
||
|
|
||
5 years ago
|
response = get_response(); // wait for "ok" from mmu
|
||
6 years ago
|
|
||
5 years ago
|
if (!response) { // No "ok" was received in reserved time frame, user will fix the issue on mmu unit
|
||
|
if (!mmu_print_saved) { // First occurrence. Save current position, park print head, disable nozzle heater.
|
||
6 years ago
|
|
||
|
planner.synchronize();
|
||
|
|
||
|
mmu_print_saved = true;
|
||
|
|
||
|
SERIAL_ECHOLNPGM("MMU not responding");
|
||
|
|
||
|
resume_hotend_temp = thermalManager.degTargetHotend(active_extruder);
|
||
5 years ago
|
resume_position = current_position;
|
||
6 years ago
|
|
||
|
if (move_axes && all_axes_homed())
|
||
5 years ago
|
nozzle.park(0, park_point /*= NOZZLE_PARK_POINT*/);
|
||
6 years ago
|
|
||
|
if (turn_off_nozzle) thermalManager.setTargetHotend(0, active_extruder);
|
||
|
|
||
5 years ago
|
mmu2_not_responding();
|
||
6 years ago
|
}
|
||
|
}
|
||
|
else if (mmu_print_saved) {
|
||
|
SERIAL_ECHOLNPGM("MMU starts responding\n");
|
||
|
|
||
|
if (turn_off_nozzle && resume_hotend_temp) {
|
||
|
thermalManager.setTargetHotend(resume_hotend_temp, active_extruder);
|
||
|
LCD_MESSAGEPGM(MSG_HEATING);
|
||
|
BUZZ(200, 40);
|
||
|
|
||
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(1000);
|
||
|
}
|
||
|
|
||
|
if (move_axes && all_axes_homed()) {
|
||
|
LCD_MESSAGEPGM(MSG_MMU2_RESUMING);
|
||
4 years ago
|
BUZZ(198, 404); BUZZ(4, 0); BUZZ(198, 404);
|
||
6 years ago
|
|
||
|
// Move XY to starting position, then Z
|
||
5 years ago
|
do_blocking_move_to_xy(resume_position, feedRate_t(NOZZLE_PARK_XY_FEEDRATE));
|
||
6 years ago
|
|
||
|
// Move Z_AXIS to saved position
|
||
5 years ago
|
do_blocking_move_to_z(resume_position.z, feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
|
||
6 years ago
|
}
|
||
|
else {
|
||
4 years ago
|
BUZZ(198, 404); BUZZ(4, 0); BUZZ(198, 404);
|
||
6 years ago
|
LCD_MESSAGEPGM(MSG_MMU2_RESUMING);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
void MMU2::set_filament_type(const uint8_t index, const uint8_t filamentType) {
|
||
6 years ago
|
if (!enabled) return;
|
||
|
|
||
|
cmd_arg = filamentType;
|
||
|
command(MMU_CMD_F0 + index);
|
||
|
|
||
6 years ago
|
manage_response(true, true);
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
void MMU2::filament_runout() {
|
||
5 years ago
|
queue.inject_P(PSTR(MMU2_FILAMENT_RUNOUT_SCRIPT));
|
||
6 years ago
|
planner.synchronize();
|
||
|
}
|
||
|
|
||
4 years ago
|
#if HAS_PRUSA_MMU2S
|
||
5 years ago
|
|
||
5 years ago
|
void MMU2::check_filament() {
|
||
5 years ago
|
const bool present = FILAMENT_PRESENT();
|
||
4 years ago
|
if (cmd == MMU_CMD_NONE && last_cmd == MMU_CMD_C0) {
|
||
|
if (present && !mmu2s_triggered) {
|
||
|
DEBUG_ECHOLNPGM("MMU <= 'A'");
|
||
|
tx_str_P(PSTR("A\n"));
|
||
|
}
|
||
|
// Slowly spin the extruder during C0
|
||
|
else {
|
||
|
while (planner.movesplanned() < 3) {
|
||
|
current_position.e += 0.25;
|
||
|
line_to_current_position(MMM_TO_MMS(120));
|
||
|
}
|
||
|
}
|
||
5 years ago
|
}
|
||
5 years ago
|
mmu2s_triggered = present;
|
||
5 years ago
|
}
|
||
|
|
||
|
bool MMU2::can_load() {
|
||
|
execute_extruder_sequence((const E_Step *)can_load_sequence, COUNT(can_load_sequence));
|
||
5 years ago
|
|
||
5 years ago
|
int filament_detected_count = 0;
|
||
5 years ago
|
const int steps = (MMU2_CAN_LOAD_RETRACT) / (MMU2_CAN_LOAD_INCREMENT);
|
||
5 years ago
|
DEBUG_ECHOLNPGM("MMU can_load:");
|
||
|
LOOP_L_N(i, steps) {
|
||
|
execute_extruder_sequence((const E_Step *)can_load_increment_sequence, COUNT(can_load_increment_sequence));
|
||
|
check_filament(); // Don't trust the idle function
|
||
|
DEBUG_CHAR(mmu2s_triggered ? 'O' : 'o');
|
||
|
if (mmu2s_triggered) ++filament_detected_count;
|
||
|
}
|
||
|
|
||
5 years ago
|
if (filament_detected_count <= steps - (MMU2_CAN_LOAD_DEVIATION) / (MMU2_CAN_LOAD_INCREMENT)) {
|
||
5 years ago
|
DEBUG_ECHOLNPGM(" failed.");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
DEBUG_ECHOLNPGM(" succeeded.");
|
||
|
return true;
|
||
|
}
|
||
4 years ago
|
|
||
5 years ago
|
#endif
|
||
|
|
||
4 years ago
|
// Load filament into MMU2
|
||
|
void MMU2::load_filament(const uint8_t index) {
|
||
|
if (!enabled) return;
|
||
|
command(MMU_CMD_L0 + index);
|
||
|
manage_response(false, false);
|
||
|
BUZZ(200, 404);
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
/**
|
||
|
* Switch material and load to nozzle
|
||
|
*/
|
||
|
bool MMU2::load_filament_to_nozzle(const uint8_t index) {
|
||
|
|
||
|
if (!enabled) return false;
|
||
|
|
||
|
if (thermalManager.tooColdToExtrude(active_extruder)) {
|
||
6 years ago
|
BUZZ(200, 404);
|
||
4 years ago
|
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
|
||
|
return false;
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
command(MMU_CMD_T0 + index);
|
||
|
manage_response(true, true);
|
||
6 years ago
|
|
||
4 years ago
|
const bool success = load_to_gears();
|
||
|
if (success) {
|
||
|
mmu_loop();
|
||
|
extruder = index;
|
||
|
active_extruder = 0;
|
||
|
load_to_nozzle();
|
||
|
BUZZ(200, 404);
|
||
|
}
|
||
|
return success;
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
/**
|
||
|
* Load filament to nozzle of multimaterial printer
|
||
|
*
|
||
|
* This function is used only only after T? (user select filament) and M600 (change filament).
|
||
|
* It is not used after T0 .. T4 command (select filament), in such case, gcode is responsible for loading
|
||
|
* filament to nozzle.
|
||
|
*/
|
||
|
void MMU2::load_to_nozzle() {
|
||
|
if (!enabled) return;
|
||
|
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
bool MMU2::eject_filament(const uint8_t index, const bool recover) {
|
||
5 years ago
|
|
||
4 years ago
|
if (!enabled) return false;
|
||
6 years ago
|
|
||
4 years ago
|
if (thermalManager.tooColdToExtrude(active_extruder)) {
|
||
|
BUZZ(200, 404);
|
||
|
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
|
||
|
return false;
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);
|
||
6 years ago
|
|
||
4 years ago
|
ENABLE_AXIS_E0();
|
||
|
current_position.e -= MMU2_FILAMENTCHANGE_EJECT_FEED;
|
||
|
line_to_current_position(MMM_TO_MMS(2500));
|
||
|
planner.synchronize();
|
||
|
command(MMU_CMD_E0 + index);
|
||
|
manage_response(false, false);
|
||
6 years ago
|
|
||
4 years ago
|
if (recover) {
|
||
|
LCD_MESSAGEPGM(MSG_MMU2_EJECT_RECOVER);
|
||
|
BUZZ(200, 404);
|
||
|
TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("MMU2 Eject Recover"), CONTINUE_STR));
|
||
|
TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("MMU2 Eject Recover")));
|
||
|
wait_for_user_response();
|
||
|
BUZZ(200, 404);
|
||
|
BUZZ(200, 404);
|
||
6 years ago
|
|
||
4 years ago
|
command(MMU_CMD_R0);
|
||
6 years ago
|
manage_response(false, false);
|
||
4 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
ui.reset_status();
|
||
6 years ago
|
|
||
4 years ago
|
// no active tool
|
||
|
extruder = MMU2_NO_TOOL;
|
||
6 years ago
|
|
||
4 years ago
|
set_runout_valid(false);
|
||
6 years ago
|
|
||
4 years ago
|
BUZZ(200, 404);
|
||
6 years ago
|
|
||
4 years ago
|
DISABLE_AXIS_E0();
|
||
6 years ago
|
|
||
4 years ago
|
return true;
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
/**
|
||
|
* Unload from hotend and retract to MMU
|
||
|
*/
|
||
|
bool MMU2::unload() {
|
||
6 years ago
|
|
||
4 years ago
|
if (!enabled) return false;
|
||
6 years ago
|
|
||
4 years ago
|
if (thermalManager.tooColdToExtrude(active_extruder)) {
|
||
|
BUZZ(200, 404);
|
||
|
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
|
||
|
return false;
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
filament_ramming();
|
||
6 years ago
|
|
||
4 years ago
|
command(MMU_CMD_U0);
|
||
|
manage_response(false, true);
|
||
6 years ago
|
|
||
4 years ago
|
BUZZ(200, 404);
|
||
6 years ago
|
|
||
4 years ago
|
// no active tool
|
||
|
extruder = MMU2_NO_TOOL;
|
||
6 years ago
|
|
||
4 years ago
|
set_runout_valid(false);
|
||
6 years ago
|
|
||
4 years ago
|
return true;
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
/**
|
||
|
* Unload sequence to optimize shape of the tip of the unloaded filament
|
||
|
*/
|
||
|
void MMU2::filament_ramming() {
|
||
|
execute_extruder_sequence((const E_Step *)ramming_sequence, sizeof(ramming_sequence) / sizeof(E_Step));
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {
|
||
6 years ago
|
|
||
4 years ago
|
planner.synchronize();
|
||
|
ENABLE_AXIS_E0();
|
||
6 years ago
|
|
||
4 years ago
|
const E_Step* step = sequence;
|
||
6 years ago
|
|
||
4 years ago
|
LOOP_L_N(i, steps) {
|
||
|
const float es = pgm_read_float(&(step->extrude));
|
||
|
const feedRate_t fr_mm_m = pgm_read_float(&(step->feedRate));
|
||
6 years ago
|
|
||
4 years ago
|
DEBUG_ECHO_START();
|
||
|
DEBUG_ECHOLNPAIR("E step ", es, "/", fr_mm_m);
|
||
6 years ago
|
|
||
4 years ago
|
current_position.e += es;
|
||
|
line_to_current_position(MMM_TO_MMS(fr_mm_m));
|
||
|
planner.synchronize();
|
||
6 years ago
|
|
||
4 years ago
|
step++;
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
DISABLE_AXIS_E0();
|
||
|
}
|
||
6 years ago
|
|
||
4 years ago
|
#endif // HAS_PRUSA_MMU2
|