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

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