2019-01-31 19:10:52 -06:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-01-31 19:10:52 -06:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-01-31 19:10:52 -06: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfig.h"
|
|
|
|
|
2019-02-12 20:08:34 -06:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2019-02-05 20:56:22 -06:00
|
|
|
#include "../runout.h"
|
|
|
|
#endif
|
|
|
|
|
2019-10-24 12:28:41 -05:00
|
|
|
#if SERIAL_USB
|
|
|
|
#define MMU_RX_SIZE 256
|
|
|
|
#define MMU_TX_SIZE 256
|
|
|
|
#else
|
|
|
|
#define MMU_RX_SIZE 16
|
|
|
|
#define MMU_TX_SIZE 16
|
|
|
|
#endif
|
|
|
|
|
2019-01-31 19:10:52 -06:00
|
|
|
struct E_Step;
|
|
|
|
|
|
|
|
class MMU2 {
|
|
|
|
public:
|
|
|
|
MMU2();
|
|
|
|
|
|
|
|
static void init();
|
|
|
|
static void reset();
|
2019-04-08 17:56:40 -05:00
|
|
|
static void mmu_loop();
|
|
|
|
static void tool_change(uint8_t index);
|
|
|
|
static void tool_change(const char* special);
|
|
|
|
static uint8_t get_current_tool();
|
|
|
|
static void set_filament_type(uint8_t index, uint8_t type);
|
2019-01-31 19:10:52 -06:00
|
|
|
|
2020-04-23 21:42:38 -05:00
|
|
|
#if BOTH(HAS_LCD_MENU, MMU2_MENUS)
|
2019-01-31 19:10:52 -06:00
|
|
|
static bool unload();
|
2019-04-08 17:56:40 -05:00
|
|
|
static void load_filament(uint8_t);
|
|
|
|
static void load_all();
|
|
|
|
static bool load_filament_to_nozzle(uint8_t index);
|
|
|
|
static bool eject_filament(uint8_t index, bool recover);
|
2019-01-31 19:10:52 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool rx_str_P(const char* str);
|
|
|
|
static void tx_str_P(const char* str);
|
|
|
|
static void tx_printf_P(const char* format, int argument);
|
|
|
|
static void tx_printf_P(const char* format, int argument1, int argument2);
|
|
|
|
static void clear_rx_buffer();
|
|
|
|
|
|
|
|
static bool rx_ok();
|
|
|
|
static bool rx_start();
|
2019-04-08 17:56:40 -05:00
|
|
|
static void check_version();
|
2019-01-31 19:10:52 -06:00
|
|
|
|
|
|
|
static void command(const uint8_t cmd);
|
2019-09-16 20:31:08 -05:00
|
|
|
static bool get_response();
|
2019-06-29 22:49:50 -05:00
|
|
|
static void manage_response(const bool move_axes, const bool turn_off_nozzle);
|
2019-01-31 19:10:52 -06:00
|
|
|
|
2020-04-23 21:42:38 -05:00
|
|
|
#if BOTH(HAS_LCD_MENU, MMU2_MENUS)
|
2019-04-08 17:56:40 -05:00
|
|
|
static void load_to_nozzle();
|
|
|
|
static void filament_ramming();
|
|
|
|
static void execute_extruder_sequence(const E_Step * sequence, int steps);
|
2019-01-31 19:10:52 -06:00
|
|
|
#endif
|
|
|
|
|
2019-04-08 17:56:40 -05:00
|
|
|
static void filament_runout();
|
2019-01-31 19:10:52 -06:00
|
|
|
|
2020-04-25 21:07:21 -05:00
|
|
|
#if ENABLED(PRUSA_MMU2_S_MODE)
|
|
|
|
static bool mmu2s_triggered;
|
|
|
|
static void check_filament();
|
|
|
|
static bool can_load();
|
|
|
|
static bool load_to_gears();
|
|
|
|
#else
|
|
|
|
FORCE_INLINE static bool load_to_gears() { return true; }
|
|
|
|
#endif
|
|
|
|
|
2019-01-31 19:10:52 -06:00
|
|
|
static bool enabled, ready, mmu_print_saved;
|
2020-04-25 21:07:21 -05:00
|
|
|
|
2019-01-31 19:10:52 -06:00
|
|
|
static uint8_t cmd, cmd_arg, last_cmd, extruder;
|
|
|
|
static int8_t state;
|
|
|
|
static volatile int8_t finda;
|
2019-04-08 17:56:40 -05:00
|
|
|
static volatile bool finda_runout_valid;
|
2019-01-31 19:10:52 -06:00
|
|
|
static int16_t version, buildnr;
|
2019-02-05 20:56:22 -06:00
|
|
|
static millis_t last_request, next_P0_request;
|
2019-10-24 12:28:41 -05:00
|
|
|
static char rx_buffer[MMU_RX_SIZE], tx_buffer[MMU_TX_SIZE];
|
2019-02-05 20:56:22 -06:00
|
|
|
|
|
|
|
static inline void set_runout_valid(const bool valid) {
|
2019-04-08 17:56:40 -05:00
|
|
|
finda_runout_valid = valid;
|
2019-02-12 20:08:34 -06:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2019-02-05 20:56:22 -06:00
|
|
|
if (valid) runout.reset();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-01-31 19:10:52 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
extern MMU2 mmu2;
|