2019-02-01 02:10:52 +01:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-02-01 02:10:52 +01:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-02-01 02:10:52 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(PRUSA_MMU2)
|
|
|
|
|
|
|
|
#include "mmu2.h"
|
2019-02-07 00:38:46 +01:00
|
|
|
#include "../../lcd/menu/menu_mmu2.h"
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
MMU2 mmu2;
|
|
|
|
|
|
|
|
#include "../../gcode/gcode.h"
|
|
|
|
#include "../../lcd/ultralcd.h"
|
|
|
|
#include "../../libs/buzzer.h"
|
|
|
|
#include "../../libs/nozzle.h"
|
|
|
|
#include "../../module/temperature.h"
|
|
|
|
#include "../../module/planner.h"
|
2019-09-01 02:44:45 +02:00
|
|
|
#include "../../module/stepper/indirection.h"
|
2020-01-03 02:01:38 +01:00
|
|
|
#include "../../MarlinCore.h"
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-02-12 22:55:47 +01:00
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
|
|
|
#include "../../feature/host_actions.h"
|
|
|
|
#endif
|
|
|
|
|
2019-08-19 04:03:26 +02:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
2020-03-13 22:29:29 +01:00
|
|
|
#include "../../lcd/extui/ui_api.h"
|
2019-08-19 04:03:26 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
#define DEBUG_OUT ENABLED(MMU2_DEBUG)
|
|
|
|
#include "../../core/debug_out.h"
|
|
|
|
|
2019-02-01 02:10:52 +01:00
|
|
|
#define MMU_TODELAY 100
|
|
|
|
#define MMU_TIMEOUT 10
|
2019-06-30 05:49:50 +02:00
|
|
|
#define MMU_CMD_TIMEOUT 60000ul // 5min timeout for mmu commands (except P0)
|
|
|
|
#define MMU_P0_TIMEOUT 3000ul // Timeout for P0 command: 3seconds
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#if ENABLED(MMU2_MODE_12V)
|
|
|
|
#define MMU_REQUIRED_FW_BUILDNR 132
|
|
|
|
#else
|
|
|
|
#define MMU_REQUIRED_FW_BUILDNR 126
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MMU2_NO_TOOL 99
|
|
|
|
#define MMU_BAUD 115200
|
|
|
|
|
|
|
|
#define mmuSerial MMU2_SERIAL
|
|
|
|
|
|
|
|
bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved;
|
|
|
|
uint8_t MMU2::cmd, MMU2::cmd_arg, MMU2::last_cmd, MMU2::extruder;
|
|
|
|
int8_t MMU2::state = 0;
|
|
|
|
volatile int8_t MMU2::finda = 1;
|
2019-04-09 00:56:40 +02:00
|
|
|
volatile bool MMU2::finda_runout_valid;
|
2019-02-01 02:10:52 +01:00
|
|
|
int16_t MMU2::version = -1, MMU2::buildnr = -1;
|
2019-02-06 03:56:22 +01:00
|
|
|
millis_t MMU2::last_request, MMU2::next_P0_request;
|
2019-10-24 19:28:41 +02:00
|
|
|
char MMU2::rx_buffer[MMU_RX_SIZE], MMU2::tx_buffer[MMU_TX_SIZE];
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
|
|
|
|
|
|
|
|
struct E_Step {
|
2019-09-26 08:28:09 +02:00
|
|
|
float extrude; //!< extrude distance in mm
|
|
|
|
feedRate_t feedRate; //!< feed rate in mm/s
|
2019-02-01 02:10:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr E_Step ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE };
|
2019-04-09 00:56:40 +02:00
|
|
|
static constexpr E_Step load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE };
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#endif // MMU2_MENUS
|
|
|
|
|
|
|
|
MMU2::MMU2() {
|
|
|
|
rx_buffer[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
void MMU2::init() {
|
2019-02-06 03:56:22 +01:00
|
|
|
|
|
|
|
set_runout_valid(false);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#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() {
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU <= reset");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#if PIN_EXISTS(MMU2_RST)
|
|
|
|
WRITE(MMU2_RST_PIN, LOW);
|
|
|
|
safe_delay(20);
|
|
|
|
WRITE(MMU2_RST_PIN, HIGH);
|
|
|
|
#else
|
|
|
|
tx_str_P(PSTR("X0\n")); // Send soft reset
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
uint8_t MMU2::get_current_tool() {
|
2019-02-01 02:10:52 +01:00
|
|
|
return extruder == MMU2_NO_TOOL ? -1 : extruder;
|
|
|
|
}
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::mmu_loop() {
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
|
|
|
case 0: break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
if (rx_start()) {
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU => 'start'");
|
|
|
|
DEBUG_ECHOLNPGM("MMU <= 'S1'");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
// send "read version" request
|
|
|
|
tx_str_P(PSTR("S1\n"));
|
|
|
|
|
|
|
|
state = -2;
|
|
|
|
}
|
|
|
|
else if (millis() > 3000000) {
|
|
|
|
SERIAL_ECHOLNPGM("MMU not responding - DISABLED");
|
|
|
|
state = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -2:
|
|
|
|
if (rx_ok()) {
|
|
|
|
sscanf(rx_buffer, "%uok\n", &version);
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPAIR("MMU => ", version, "\nMMU <= 'S2'");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
tx_str_P(PSTR("S2\n")); // read build number
|
|
|
|
state = -3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -3:
|
|
|
|
if (rx_ok()) {
|
|
|
|
sscanf(rx_buffer, "%uok\n", &buildnr);
|
2019-03-14 08:25:42 +01:00
|
|
|
|
|
|
|
DEBUG_ECHOLNPAIR("MMU => ", buildnr);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
check_version();
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#if ENABLED(MMU2_MODE_12V)
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU <= 'M1'");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
tx_str_P(PSTR("M1\n")); // switch to stealth mode
|
|
|
|
state = -5;
|
|
|
|
|
|
|
|
#else
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU <= 'P0'");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
tx_str_P(PSTR("P0\n")); // read finda
|
|
|
|
state = -4;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-05-08 04:02:08 +02:00
|
|
|
#if ENABLED(MMU2_MODE_12V)
|
2019-02-01 02:10:52 +01:00
|
|
|
case -5:
|
|
|
|
// response to M1
|
|
|
|
if (rx_ok()) {
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU => ok");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU <= 'P0'");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
tx_str_P(PSTR("P0\n")); // read finda
|
|
|
|
state = -4;
|
|
|
|
}
|
|
|
|
break;
|
2019-05-08 04:02:08 +02:00
|
|
|
#endif
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-02-04 06:00:57 +01:00
|
|
|
case -4:
|
2019-02-01 02:10:52 +01:00
|
|
|
if (rx_ok()) {
|
|
|
|
sscanf(rx_buffer, "%hhuok\n", &finda);
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPAIR("MMU => ", finda, "\nMMU - ENABLED");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
enabled = true;
|
|
|
|
state = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (cmd) {
|
|
|
|
if (WITHIN(cmd, MMU_CMD_T0, MMU_CMD_T4)) {
|
|
|
|
// tool change
|
|
|
|
int filament = cmd - MMU_CMD_T0;
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPAIR("MMU <= T", filament);
|
2019-02-01 02:10:52 +01:00
|
|
|
tx_printf_P(PSTR("T%d\n"), filament);
|
|
|
|
state = 3; // wait for response
|
|
|
|
}
|
|
|
|
else if (WITHIN(cmd, MMU_CMD_L0, MMU_CMD_L4)) {
|
|
|
|
// load
|
|
|
|
int filament = cmd - MMU_CMD_L0;
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPAIR("MMU <= L", filament);
|
2019-02-01 02:10:52 +01:00
|
|
|
tx_printf_P(PSTR("L%d\n"), filament);
|
|
|
|
state = 3; // wait for response
|
|
|
|
}
|
|
|
|
else if (cmd == MMU_CMD_C0) {
|
|
|
|
// continue loading
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU <= 'C0'");
|
2019-02-01 02:10:52 +01:00
|
|
|
tx_str_P(PSTR("C0\n"));
|
|
|
|
state = 3; // wait for response
|
|
|
|
}
|
|
|
|
else if (cmd == MMU_CMD_U0) {
|
|
|
|
// unload current
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU <= 'U0'");
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
tx_str_P(PSTR("U0\n"));
|
|
|
|
state = 3; // wait for response
|
|
|
|
}
|
|
|
|
else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E4)) {
|
|
|
|
// eject filament
|
|
|
|
int filament = cmd - MMU_CMD_E0;
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPAIR("MMU <= E", filament);
|
2019-02-01 02:10:52 +01:00
|
|
|
tx_printf_P(PSTR("E%d\n"), filament);
|
|
|
|
state = 3; // wait for response
|
|
|
|
}
|
|
|
|
else if (cmd == MMU_CMD_R0) {
|
|
|
|
// recover after eject
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU <= 'R0'");
|
2019-02-01 02:10:52 +01:00
|
|
|
tx_str_P(PSTR("R0\n"));
|
|
|
|
state = 3; // wait for response
|
|
|
|
}
|
|
|
|
else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F4)) {
|
|
|
|
// filament type
|
|
|
|
int filament = cmd - MMU_CMD_F0;
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOPAIR("MMU <= F", filament, " ");
|
|
|
|
DEBUG_ECHO_F(cmd_arg, DEC);
|
|
|
|
DEBUG_EOL();
|
2019-02-01 02:10:52 +01:00
|
|
|
tx_printf_P(PSTR("F%d %d\n"), filament, cmd_arg);
|
|
|
|
state = 3; // wait for response
|
|
|
|
}
|
|
|
|
|
|
|
|
last_cmd = cmd;
|
|
|
|
cmd = MMU_CMD_NONE;
|
|
|
|
}
|
2019-02-06 03:56:22 +01:00
|
|
|
else if (ELAPSED(millis(), next_P0_request)) {
|
2019-02-01 02:10:52 +01:00
|
|
|
// read FINDA
|
|
|
|
tx_str_P(PSTR("P0\n"));
|
|
|
|
state = 2; // wait for response
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // response to command P0
|
|
|
|
if (rx_ok()) {
|
|
|
|
sscanf(rx_buffer, "%hhuok\n", &finda);
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
// This is super annoying. Only activate if necessary
|
2019-04-09 00:56:40 +02:00
|
|
|
// if (finda_runout_valid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
state = 1;
|
|
|
|
|
|
|
|
if (cmd == 0) ready = true;
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
if (!finda && finda_runout_valid) filament_runout();
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
2019-05-08 04:02:08 +02:00
|
|
|
else if (ELAPSED(millis(), last_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
|
2019-02-01 02:10:52 +01:00
|
|
|
state = 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: // response to mmu commands
|
|
|
|
if (rx_ok()) {
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU => 'ok'");
|
2019-02-01 02:10:52 +01:00
|
|
|
ready = true;
|
|
|
|
state = 1;
|
|
|
|
last_cmd = MMU_CMD_NONE;
|
|
|
|
}
|
2019-02-06 03:56:22 +01:00
|
|
|
else if (ELAPSED(millis(), last_request + MMU_CMD_TIMEOUT)) {
|
2019-02-01 02:10:52 +01:00
|
|
|
// resend request after timeout
|
|
|
|
if (last_cmd) {
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("MMU retry");
|
2019-02-01 02:10:52 +01:00
|
|
|
cmd = last_cmd;
|
|
|
|
last_cmd = MMU_CMD_NONE;
|
|
|
|
}
|
|
|
|
state = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if MMU was started
|
|
|
|
*/
|
|
|
|
bool MMU2::rx_start() {
|
|
|
|
// check for start message
|
|
|
|
if (rx_str_P(PSTR("start\n"))) {
|
2019-02-06 03:56:22 +01:00
|
|
|
next_P0_request = millis() + 300;
|
2019-02-01 02:10:52 +01:00
|
|
|
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) {
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHOLNPGM("rx buffer overrun");
|
2019-02-01 02:10:52 +01:00
|
|
|
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);
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_L_N(i, len) mmuSerial.write(pgm_read_byte(str++));
|
2019-02-01 02:10:52 +01:00
|
|
|
rx_buffer[0] = '\0';
|
2019-02-06 03:56:22 +01:00
|
|
|
last_request = millis();
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
|
2019-02-01 02:10:52 +01:00
|
|
|
rx_buffer[0] = '\0';
|
2019-02-06 03:56:22 +01:00
|
|
|
last_request = millis();
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
|
2019-02-01 02:10:52 +01:00
|
|
|
rx_buffer[0] = '\0';
|
2019-02-06 03:56:22 +01:00
|
|
|
last_request = millis();
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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"))) {
|
2019-02-06 03:56:22 +01:00
|
|
|
next_P0_request = millis() + 300;
|
2019-02-01 02:10:52 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if MMU has compatible firmware
|
|
|
|
*/
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::check_version() {
|
2019-02-01 02:10:52 +01:00
|
|
|
if (buildnr < MMU_REQUIRED_FW_BUILDNR) {
|
2019-09-26 10:47:26 +02:00
|
|
|
SERIAL_ERROR_MSG("Invalid MMU2 firmware. Version >= " STRINGIFY(MMU_REQUIRED_FW_BUILDNR) " required.");
|
2019-10-10 02:46:10 +02:00
|
|
|
kill(GET_TEXT(MSG_MMU2_WRONG_FIRMWARE));
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle tool change
|
|
|
|
*/
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::tool_change(uint8_t index) {
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
if (!enabled) return;
|
|
|
|
|
2019-02-06 03:56:22 +01:00
|
|
|
set_runout_valid(false);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
if (index != extruder) {
|
|
|
|
|
2020-01-30 10:24:23 +01:00
|
|
|
DISABLE_AXIS_E0();
|
2019-10-10 02:46:10 +02:00
|
|
|
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
command(MMU_CMD_T0 + index);
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
manage_response(true, true);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
command(MMU_CMD_C0);
|
|
|
|
extruder = index; //filament change is finished
|
|
|
|
active_extruder = 0;
|
|
|
|
|
2020-01-30 10:24:23 +01:00
|
|
|
ENABLE_AXIS_E0();
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
SERIAL_ECHO_START();
|
2020-02-26 10:02:03 +01:00
|
|
|
SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
ui.reset_status();
|
|
|
|
}
|
|
|
|
|
2019-02-06 03:56:22 +01:00
|
|
|
set_runout_valid(true);
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::tool_change(const char* special) {
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
if (!enabled) return;
|
|
|
|
|
|
|
|
#if ENABLED(MMU2_MENUS)
|
|
|
|
|
2019-02-06 03:56:22 +01:00
|
|
|
set_runout_valid(false);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-02-12 23:25:49 +01:00
|
|
|
switch (*special) {
|
2019-02-01 02:10:52 +01:00
|
|
|
case '?': {
|
2019-04-09 00:56:40 +02:00
|
|
|
uint8_t index = mmu2_choose_filament();
|
2019-02-01 02:10:52 +01:00
|
|
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
|
2019-04-09 00:56:40 +02:00
|
|
|
load_filament_to_nozzle(index);
|
2019-02-01 02:10:52 +01:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case 'x': {
|
|
|
|
planner.synchronize();
|
2019-04-09 00:56:40 +02:00
|
|
|
uint8_t index = mmu2_choose_filament();
|
2020-01-30 10:24:23 +01:00
|
|
|
DISABLE_AXIS_E0();
|
2019-02-01 02:10:52 +01:00
|
|
|
command(MMU_CMD_T0 + index);
|
2019-04-09 00:56:40 +02:00
|
|
|
manage_response(true, true);
|
2019-02-01 02:10:52 +01:00
|
|
|
command(MMU_CMD_C0);
|
2019-04-09 00:56:40 +02:00
|
|
|
mmu_loop();
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2020-01-30 10:24:23 +01:00
|
|
|
ENABLE_AXIS_E0();
|
2019-02-01 02:10:52 +01:00
|
|
|
extruder = index;
|
|
|
|
active_extruder = 0;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 'c': {
|
|
|
|
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
|
2019-04-09 00:56:40 +02:00
|
|
|
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
|
2019-02-01 02:10:52 +01:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2019-02-06 03:56:22 +01:00
|
|
|
set_runout_valid(true);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set next command
|
|
|
|
*/
|
|
|
|
void MMU2::command(const uint8_t mmu_cmd) {
|
|
|
|
if (!enabled) return;
|
|
|
|
cmd = mmu_cmd;
|
|
|
|
ready = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait for response from MMU
|
|
|
|
*/
|
2019-09-17 03:31:08 +02:00
|
|
|
bool MMU2::get_response() {
|
2019-02-01 02:10:52 +01:00
|
|
|
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
|
|
|
|
*/
|
2019-06-30 05:49:50 +02:00
|
|
|
void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-09-29 11:25:39 +02:00
|
|
|
constexpr xyz_pos_t park_point = NOZZLE_PARK_POINT;
|
2019-02-01 02:10:52 +01:00
|
|
|
bool response = false;
|
|
|
|
mmu_print_saved = false;
|
2019-09-29 11:25:39 +02:00
|
|
|
xyz_pos_t resume_position;
|
2019-02-01 02:10:52 +01:00
|
|
|
int16_t resume_hotend_temp;
|
|
|
|
|
2019-06-30 05:49:50 +02:00
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
|
2019-02-01 02:10:52 +01:00
|
|
|
while (!response) {
|
|
|
|
|
2019-06-30 05:49:50 +02:00
|
|
|
response = get_response(); // wait for "ok" from mmu
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-06-30 05:49:50 +02:00
|
|
|
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.
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
planner.synchronize();
|
|
|
|
|
|
|
|
mmu_print_saved = true;
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM("MMU not responding");
|
|
|
|
|
|
|
|
resume_hotend_temp = thermalManager.degTargetHotend(active_extruder);
|
2019-09-29 11:25:39 +02:00
|
|
|
resume_position = current_position;
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
if (move_axes && all_axes_homed())
|
2019-07-17 10:41:04 +02:00
|
|
|
nozzle.park(2, park_point /*= NOZZLE_PARK_POINT*/);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
if (turn_off_nozzle) thermalManager.setTargetHotend(0, active_extruder);
|
|
|
|
|
|
|
|
LCD_MESSAGEPGM(MSG_MMU2_NOT_RESPONDING);
|
|
|
|
BUZZ(100, 659);
|
|
|
|
BUZZ(200, 698);
|
|
|
|
BUZZ(100, 659);
|
|
|
|
BUZZ(300, 440);
|
|
|
|
BUZZ(100, 659);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
BUZZ(200, 404);
|
|
|
|
BUZZ(200, 404);
|
|
|
|
|
|
|
|
// Move XY to starting position, then Z
|
2019-09-29 11:25:39 +02:00
|
|
|
do_blocking_move_to_xy(resume_position, feedRate_t(NOZZLE_PARK_XY_FEEDRATE));
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
// Move Z_AXIS to saved position
|
2019-09-29 11:25:39 +02:00
|
|
|
do_blocking_move_to_z(resume_position.z, feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BUZZ(200, 404);
|
|
|
|
BUZZ(200, 404);
|
|
|
|
LCD_MESSAGEPGM(MSG_MMU2_RESUMING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::set_filament_type(uint8_t index, uint8_t filamentType) {
|
2019-02-01 02:10:52 +01:00
|
|
|
if (!enabled) return;
|
|
|
|
|
|
|
|
cmd_arg = filamentType;
|
|
|
|
command(MMU_CMD_F0 + index);
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
manage_response(true, true);
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::filament_runout() {
|
2019-06-19 07:00:19 +02:00
|
|
|
queue.inject_P(PSTR(MMU2_FILAMENT_RUNOUT_SCRIPT));
|
2019-02-01 02:10:52 +01:00
|
|
|
planner.synchronize();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
|
|
|
|
|
|
|
|
// Load filament into MMU2
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::load_filament(uint8_t index) {
|
2019-02-01 02:10:52 +01:00
|
|
|
if (!enabled) return;
|
|
|
|
command(MMU_CMD_L0 + index);
|
2019-04-09 00:56:40 +02:00
|
|
|
manage_response(false, false);
|
2019-02-01 02:10:52 +01:00
|
|
|
BUZZ(200, 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Switch material and load to nozzle
|
|
|
|
*
|
|
|
|
*/
|
2019-04-09 00:56:40 +02:00
|
|
|
bool MMU2::load_filament_to_nozzle(uint8_t index) {
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
if (!enabled) return false;
|
|
|
|
|
|
|
|
if (thermalManager.tooColdToExtrude(active_extruder)) {
|
|
|
|
BUZZ(200, 404);
|
|
|
|
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
command(MMU_CMD_T0 + index);
|
2019-04-09 00:56:40 +02:00
|
|
|
manage_response(true, true);
|
2019-02-01 02:10:52 +01:00
|
|
|
command(MMU_CMD_C0);
|
2019-04-09 00:56:40 +02:00
|
|
|
mmu_loop();
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
extruder = index;
|
|
|
|
active_extruder = 0;
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
load_to_nozzle();
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
BUZZ(200, 404);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::load_to_nozzle() {
|
2019-02-01 02:10:52 +01:00
|
|
|
if (!enabled) return;
|
2019-04-09 00:56:40 +02:00
|
|
|
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
bool MMU2::eject_filament(uint8_t index, bool recover) {
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
if (!enabled) return false;
|
|
|
|
|
|
|
|
if (thermalManager.tooColdToExtrude(active_extruder)) {
|
|
|
|
BUZZ(200, 404);
|
|
|
|
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);
|
|
|
|
|
2020-01-30 10:24:23 +01:00
|
|
|
ENABLE_AXIS_E0();
|
2019-09-29 11:25:39 +02:00
|
|
|
current_position.e -= MMU2_FILAMENTCHANGE_EJECT_FEED;
|
|
|
|
line_to_current_position(2500 / 60);
|
2019-02-01 02:10:52 +01:00
|
|
|
planner.synchronize();
|
|
|
|
command(MMU_CMD_E0 + index);
|
2019-04-09 00:56:40 +02:00
|
|
|
manage_response(false, false);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
if (recover) {
|
|
|
|
LCD_MESSAGEPGM(MSG_MMU2_EJECT_RECOVER);
|
|
|
|
BUZZ(200, 404);
|
2019-02-12 22:55:47 +01:00
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
2019-11-29 11:45:07 +01:00
|
|
|
host_prompt_do(PROMPT_USER_CONTINUE, PSTR("MMU2 Eject Recover"), CONTINUE_STR);
|
2019-02-12 22:55:47 +01:00
|
|
|
#endif
|
2019-08-19 04:03:26 +02:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
2019-10-10 02:46:10 +02:00
|
|
|
ExtUI::onUserConfirmRequired_P(PSTR("MMU2 Eject Recover"));
|
2019-08-19 04:03:26 +02:00
|
|
|
#endif
|
2020-03-28 09:18:53 +01:00
|
|
|
wait_for_user_response();
|
2019-02-01 02:10:52 +01:00
|
|
|
BUZZ(200, 404);
|
|
|
|
BUZZ(200, 404);
|
|
|
|
|
|
|
|
command(MMU_CMD_R0);
|
2019-04-09 00:56:40 +02:00
|
|
|
manage_response(false, false);
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.reset_status();
|
|
|
|
|
|
|
|
// no active tool
|
|
|
|
extruder = MMU2_NO_TOOL;
|
2019-02-06 03:56:22 +01:00
|
|
|
|
|
|
|
set_runout_valid(false);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
BUZZ(200, 404);
|
|
|
|
|
2020-01-30 10:24:23 +01:00
|
|
|
DISABLE_AXIS_E0();
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* unload from hotend and retract to MMU
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool MMU2::unload() {
|
|
|
|
|
|
|
|
if (!enabled) return false;
|
|
|
|
|
|
|
|
if (thermalManager.tooColdToExtrude(active_extruder)) {
|
|
|
|
BUZZ(200, 404);
|
|
|
|
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
filament_ramming();
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
command(MMU_CMD_U0);
|
2019-04-09 00:56:40 +02:00
|
|
|
manage_response(false, true);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
BUZZ(200, 404);
|
|
|
|
|
|
|
|
// no active tool
|
|
|
|
extruder = MMU2_NO_TOOL;
|
2019-02-06 03:56:22 +01:00
|
|
|
|
|
|
|
set_runout_valid(false);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unload sequence to optimize shape of the tip of the unloaded filament
|
|
|
|
*/
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::filament_ramming() {
|
|
|
|
execute_extruder_sequence((const E_Step *)ramming_sequence, sizeof(ramming_sequence) / sizeof(E_Step));
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
2019-04-09 00:56:40 +02:00
|
|
|
void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
planner.synchronize();
|
2020-01-30 10:24:23 +01:00
|
|
|
ENABLE_AXIS_E0();
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
const E_Step* step = sequence;
|
|
|
|
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_L_N(i, steps) {
|
2019-09-26 08:28:09 +02:00
|
|
|
const float es = pgm_read_float(&(step->extrude));
|
|
|
|
const feedRate_t fr_mm_m = pgm_read_float(&(step->feedRate));
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHO_START();
|
2019-09-26 08:28:09 +02:00
|
|
|
DEBUG_ECHOLNPAIR("E step ", es, "/", fr_mm_m);
|
2019-02-01 02:10:52 +01:00
|
|
|
|
2019-09-29 11:25:39 +02:00
|
|
|
current_position.e += es;
|
2019-09-26 08:28:09 +02:00
|
|
|
line_to_current_position(MMM_TO_MMS(fr_mm_m));
|
2019-02-01 02:10:52 +01:00
|
|
|
planner.synchronize();
|
|
|
|
|
|
|
|
step++;
|
|
|
|
}
|
|
|
|
|
2020-01-30 10:24:23 +01:00
|
|
|
DISABLE_AXIS_E0();
|
2019-02-01 02:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAS_LCD_MENU && MMU2_MENUS
|
|
|
|
|
|
|
|
#endif // PRUSA_MMU2
|