My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

mmu2.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../../inc/MarlinConfig.h"
  24. #if HAS_FILAMENT_SENSOR
  25. #include "../runout.h"
  26. #endif
  27. #if SERIAL_USB
  28. #define MMU_RX_SIZE 256
  29. #define MMU_TX_SIZE 256
  30. #else
  31. #define MMU_RX_SIZE 16
  32. #define MMU_TX_SIZE 16
  33. #endif
  34. struct E_Step;
  35. class MMU2 {
  36. public:
  37. MMU2();
  38. static void init();
  39. static void reset();
  40. static void mmu_loop();
  41. static void tool_change(uint8_t index);
  42. static void tool_change(const char* special);
  43. static uint8_t get_current_tool();
  44. static void set_filament_type(uint8_t index, uint8_t type);
  45. #if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
  46. static bool unload();
  47. static void load_filament(uint8_t);
  48. static void load_all();
  49. static bool load_filament_to_nozzle(uint8_t index);
  50. static bool eject_filament(uint8_t index, bool recover);
  51. #endif
  52. private:
  53. static bool rx_str_P(const char* str);
  54. static void tx_str_P(const char* str);
  55. static void tx_printf_P(const char* format, int argument);
  56. static void tx_printf_P(const char* format, int argument1, int argument2);
  57. static void clear_rx_buffer();
  58. static bool rx_ok();
  59. static bool rx_start();
  60. static void check_version();
  61. static void command(const uint8_t cmd);
  62. static bool get_response();
  63. static void manage_response(const bool move_axes, const bool turn_off_nozzle);
  64. #if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
  65. static void load_to_nozzle();
  66. static void filament_ramming();
  67. static void execute_extruder_sequence(const E_Step * sequence, int steps);
  68. #endif
  69. static void filament_runout();
  70. static bool enabled, ready, mmu_print_saved;
  71. static uint8_t cmd, cmd_arg, last_cmd, extruder;
  72. static int8_t state;
  73. static volatile int8_t finda;
  74. static volatile bool finda_runout_valid;
  75. static int16_t version, buildnr;
  76. static millis_t last_request, next_P0_request;
  77. static char rx_buffer[MMU_RX_SIZE], tx_buffer[MMU_TX_SIZE];
  78. static inline void set_runout_valid(const bool valid) {
  79. finda_runout_valid = valid;
  80. #if HAS_FILAMENT_SENSOR
  81. if (valid) runout.reset();
  82. #endif
  83. }
  84. };
  85. extern MMU2 mmu2;