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.

menu_filament.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // Filament Change Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if BOTH(HAS_MARLINUI_MENU, ADVANCED_PAUSE_FEATURE)
  27. #include "menu_item.h"
  28. #include "../../module/temperature.h"
  29. #include "../../feature/pause.h"
  30. #include "../../gcode/queue.h"
  31. #if HAS_FILAMENT_SENSOR
  32. #include "../../feature/runout.h"
  33. #endif
  34. //
  35. // Change Filament > Change/Unload/Load Filament
  36. //
  37. static PauseMode _change_filament_mode; // = PAUSE_MODE_PAUSE_PRINT
  38. static int8_t _change_filament_extruder; // = 0
  39. inline PGM_P _change_filament_command() {
  40. switch (_change_filament_mode) {
  41. case PAUSE_MODE_LOAD_FILAMENT: return PSTR("M701 T%d");
  42. case PAUSE_MODE_UNLOAD_FILAMENT: return _change_filament_extruder >= 0
  43. ? PSTR("M702 T%d") : PSTR("M702 ;%d");
  44. case PAUSE_MODE_CHANGE_FILAMENT:
  45. case PAUSE_MODE_PAUSE_PRINT:
  46. default: break;
  47. }
  48. return PSTR("M600 B0 T%d");
  49. }
  50. // Initiate Filament Load/Unload/Change at the specified temperature
  51. static void _change_filament_with_temp(const uint16_t celsius) {
  52. char cmd[11];
  53. sprintf_P(cmd, _change_filament_command(), _change_filament_extruder);
  54. thermalManager.setTargetHotend(celsius, _change_filament_extruder);
  55. queue.inject(cmd);
  56. }
  57. static void _change_filament_with_preset() {
  58. _change_filament_with_temp(ui.material_preset[MenuItemBase::itemIndex].hotend_temp);
  59. }
  60. static void _change_filament_with_custom() {
  61. _change_filament_with_temp(thermalManager.degTargetHotend(MenuItemBase::itemIndex));
  62. }
  63. //
  64. // Menu to choose the temperature and start Filament Change
  65. //
  66. inline PGM_P change_filament_header(const PauseMode mode) {
  67. switch (mode) {
  68. case PAUSE_MODE_LOAD_FILAMENT: return GET_TEXT(MSG_FILAMENTLOAD);
  69. case PAUSE_MODE_UNLOAD_FILAMENT: return GET_TEXT(MSG_FILAMENTUNLOAD);
  70. default: break;
  71. }
  72. return GET_TEXT(MSG_FILAMENTCHANGE);
  73. }
  74. void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
  75. _change_filament_mode = mode;
  76. _change_filament_extruder = extruder;
  77. const int8_t old_index = MenuItemBase::itemIndex;
  78. START_MENU();
  79. if (LCD_HEIGHT >= 4) STATIC_ITEM_P(change_filament_header(mode), SS_DEFAULT|SS_INVERT);
  80. BACK_ITEM(MSG_BACK);
  81. #if HAS_PREHEAT
  82. LOOP_L_N(m, PREHEAT_COUNT)
  83. ACTION_ITEM_N_S(m, ui.get_preheat_label(m), MSG_PREHEAT_M, _change_filament_with_preset);
  84. #endif
  85. EDIT_ITEM_FAST_N(int3, extruder, MSG_PREHEAT_CUSTOM, &thermalManager.temp_hotend[extruder].target,
  86. EXTRUDE_MINTEMP, thermalManager.hotend_max_target(extruder),
  87. _change_filament_with_custom
  88. );
  89. END_MENU();
  90. MenuItemBase::itemIndex = old_index;
  91. }
  92. /**
  93. * "Change Filament" submenu
  94. */
  95. #if E_STEPPERS > 1 || ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  96. bool printingIsPaused();
  97. #endif
  98. void menu_change_filament() {
  99. #if E_STEPPERS > 1 || ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  100. // Say "filament change" when no print is active
  101. editable.int8 = printingIsPaused() ? PAUSE_MODE_PAUSE_PRINT : PAUSE_MODE_CHANGE_FILAMENT;
  102. #if E_STEPPERS > 1 && ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  103. bool too_cold = false;
  104. for (uint8_t s = 0; !too_cold && s < E_STEPPERS; s++)
  105. too_cold = thermalManager.targetTooColdToExtrude(s);
  106. #endif
  107. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  108. const bool is_busy = printer_busy();
  109. #endif
  110. START_MENU();
  111. BACK_ITEM(MSG_MAIN);
  112. // Change filament
  113. #if E_STEPPERS == 1
  114. PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE);
  115. if (thermalManager.targetTooColdToExtrude(active_extruder))
  116. SUBMENU_P(msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); });
  117. else
  118. GCODES_ITEM_P(msg, PSTR("M600 B0"));
  119. #else
  120. PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE_E);
  121. LOOP_L_N(s, E_STEPPERS) {
  122. if (thermalManager.targetTooColdToExtrude(s))
  123. SUBMENU_N_P(s, msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, MenuItemBase::itemIndex); });
  124. else {
  125. ACTION_ITEM_N_P(s, msg, []{
  126. PGM_P const cmdpstr = PSTR("M600 B0 T%i");
  127. char cmd[strlen_P(cmdpstr) + 3 + 1];
  128. sprintf_P(cmd, cmdpstr, int(MenuItemBase::itemIndex));
  129. queue.inject(cmd);
  130. });
  131. }
  132. }
  133. #endif
  134. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  135. if (!is_busy) {
  136. // Load filament
  137. #if E_STEPPERS == 1
  138. PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD);
  139. if (thermalManager.targetTooColdToExtrude(active_extruder))
  140. SUBMENU_P(msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, 0); });
  141. else
  142. GCODES_ITEM_P(msg_load, PSTR("M701"));
  143. #else
  144. PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD_E);
  145. LOOP_L_N(s, E_STEPPERS) {
  146. if (thermalManager.targetTooColdToExtrude(s))
  147. SUBMENU_N_P(s, msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, MenuItemBase::itemIndex); });
  148. else {
  149. ACTION_ITEM_N_P(s, msg_load, []{
  150. char cmd[12];
  151. sprintf_P(cmd, PSTR("M701 T%i"), int(MenuItemBase::itemIndex));
  152. queue.inject(cmd);
  153. });
  154. }
  155. }
  156. #endif
  157. // Unload filament
  158. #if E_STEPPERS == 1
  159. PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD);
  160. if (thermalManager.targetTooColdToExtrude(active_extruder))
  161. SUBMENU_P(msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, 0); });
  162. else
  163. GCODES_ITEM_P(msg_unload, PSTR("M702"));
  164. #else
  165. #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  166. if (too_cold)
  167. SUBMENU(MSG_FILAMENTUNLOAD_ALL, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, -1); });
  168. else
  169. GCODES_ITEM(MSG_FILAMENTUNLOAD_ALL, PSTR("M702"));
  170. #endif
  171. PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD_E);
  172. LOOP_L_N(s, E_STEPPERS) {
  173. if (thermalManager.targetTooColdToExtrude(s))
  174. SUBMENU_N_P(s, msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, MenuItemBase::itemIndex); });
  175. else {
  176. ACTION_ITEM_N_P(s, msg_unload, []{
  177. char cmd[12];
  178. sprintf_P(cmd, PSTR("M702 T%i"), int(MenuItemBase::itemIndex));
  179. queue.inject(cmd);
  180. });
  181. }
  182. }
  183. #endif
  184. } // !printer_busy
  185. #endif
  186. END_MENU();
  187. #else
  188. if (thermalManager.targetHotEnoughToExtrude(active_extruder))
  189. queue.inject(F("M600B0"));
  190. else
  191. ui.goto_screen([]{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); });
  192. #endif
  193. }
  194. static uint8_t hotend_status_extruder = 0;
  195. static PGM_P pause_header() {
  196. switch (pause_mode) {
  197. case PAUSE_MODE_CHANGE_FILAMENT: return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER);
  198. case PAUSE_MODE_LOAD_FILAMENT: return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_LOAD);
  199. case PAUSE_MODE_UNLOAD_FILAMENT: return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_UNLOAD);
  200. default: break;
  201. }
  202. return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_PAUSE);
  203. }
  204. // Portions from STATIC_ITEM...
  205. #define HOTEND_STATUS_ITEM() do { \
  206. if (_menuLineNr == _thisItemNr) { \
  207. if (ui.should_draw()) { \
  208. IF_DISABLED(HAS_GRAPHICAL_TFT, MenuItem_static::draw(_lcdLineNr, GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE), SS_INVERT)); \
  209. ui.draw_hotend_status(_lcdLineNr, hotend_status_extruder); \
  210. } \
  211. if (_skipStatic && encoderLine <= _thisItemNr) { \
  212. ui.encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  213. ++encoderLine; \
  214. } \
  215. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT); \
  216. } \
  217. ++_thisItemNr; \
  218. }while(0)
  219. void menu_pause_option() {
  220. START_MENU();
  221. #if LCD_HEIGHT > 2
  222. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER);
  223. #endif
  224. ACTION_ITEM(MSG_FILAMENT_CHANGE_OPTION_PURGE, []{ pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; });
  225. #if HAS_FILAMENT_SENSOR
  226. const bool still_out = runout.filament_ran_out;
  227. if (still_out)
  228. EDIT_ITEM(bool, MSG_RUNOUT_SENSOR, &runout.enabled, runout.reset);
  229. #else
  230. constexpr bool still_out = false;
  231. #endif
  232. if (!still_out)
  233. ACTION_ITEM(MSG_FILAMENT_CHANGE_OPTION_RESUME, []{ pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; });
  234. END_MENU();
  235. }
  236. //
  237. // ADVANCED_PAUSE_FEATURE message screens
  238. //
  239. // Warning: msg must have three null bytes to delimit lines!
  240. //
  241. void _lcd_pause_message(PGM_P const msg) {
  242. PGM_P const msg1 = msg;
  243. PGM_P const msg2 = msg1 + strlen_P(msg1) + 1;
  244. PGM_P const msg3 = msg2 + strlen_P(msg2) + 1;
  245. const bool has2 = msg2[0], has3 = msg3[0],
  246. skip1 = !has2 && (LCD_HEIGHT) >= 5;
  247. START_SCREEN();
  248. STATIC_ITEM_P(pause_header(), SS_DEFAULT|SS_INVERT); // 1: Header
  249. if (skip1) SKIP_ITEM(); // Move a single-line message down
  250. STATIC_ITEM_P(msg1); // 2: Message Line 1
  251. if (has2) STATIC_ITEM_P(msg2); // 3: Message Line 2
  252. if (has3 && (LCD_HEIGHT) >= 5) STATIC_ITEM_P(msg3); // 4: Message Line 3 (if LCD has 5 lines)
  253. if (skip1 + 1 + has2 + has3 < (LCD_HEIGHT) - 2) SKIP_ITEM(); // Push Hotend Status down, if needed
  254. HOTEND_STATUS_ITEM(); // 5: Hotend Status
  255. END_SCREEN();
  256. }
  257. void lcd_pause_parking_message() { _lcd_pause_message(GET_TEXT(MSG_PAUSE_PRINT_PARKING)); }
  258. void lcd_pause_changing_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_INIT)); }
  259. void lcd_pause_unload_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_UNLOAD)); }
  260. void lcd_pause_heating_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_HEATING)); }
  261. void lcd_pause_heat_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_HEAT)); }
  262. void lcd_pause_insert_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_INSERT)); }
  263. void lcd_pause_load_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_LOAD)); }
  264. void lcd_pause_waiting_message() { _lcd_pause_message(GET_TEXT(MSG_ADVANCED_PAUSE_WAITING)); }
  265. void lcd_pause_resume_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_RESUME)); }
  266. void lcd_pause_purge_message() {
  267. #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE)
  268. _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_CONT_PURGE));
  269. #else
  270. _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_PURGE));
  271. #endif
  272. }
  273. FORCE_INLINE screenFunc_t ap_message_screen(const PauseMessage message) {
  274. switch (message) {
  275. case PAUSE_MESSAGE_PARKING: return lcd_pause_parking_message;
  276. case PAUSE_MESSAGE_CHANGING: return lcd_pause_changing_message;
  277. case PAUSE_MESSAGE_UNLOAD: return lcd_pause_unload_message;
  278. case PAUSE_MESSAGE_WAITING: return lcd_pause_waiting_message;
  279. case PAUSE_MESSAGE_INSERT: return lcd_pause_insert_message;
  280. case PAUSE_MESSAGE_LOAD: return lcd_pause_load_message;
  281. case PAUSE_MESSAGE_PURGE: return lcd_pause_purge_message;
  282. case PAUSE_MESSAGE_RESUME: return lcd_pause_resume_message;
  283. case PAUSE_MESSAGE_HEAT: return lcd_pause_heat_message;
  284. case PAUSE_MESSAGE_HEATING: return lcd_pause_heating_message;
  285. case PAUSE_MESSAGE_OPTION: pause_menu_response = PAUSE_RESPONSE_WAIT_FOR;
  286. return menu_pause_option;
  287. case PAUSE_MESSAGE_STATUS:
  288. default: break;
  289. }
  290. return nullptr;
  291. }
  292. void MarlinUI::pause_show_message(
  293. const PauseMessage message,
  294. const PauseMode mode/*=PAUSE_MODE_SAME*/,
  295. const uint8_t extruder/*=active_extruder*/
  296. ) {
  297. if (mode != PAUSE_MODE_SAME) pause_mode = mode;
  298. hotend_status_extruder = extruder;
  299. const screenFunc_t next_screen = ap_message_screen(message);
  300. if (next_screen) {
  301. ui.defer_status_screen();
  302. ui.goto_screen(next_screen);
  303. }
  304. else
  305. ui.return_to_status();
  306. }
  307. #endif // HAS_MARLINUI_MENU && ADVANCED_PAUSE_FEATURE