My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

menu_filament.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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_LCD_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.temp_hotend[MenuItemBase::itemIndex].target);
  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. START_MENU();
  78. if (LCD_HEIGHT >= 4) STATIC_ITEM_P(change_filament_header(mode), SS_DEFAULT|SS_INVERT);
  79. BACK_ITEM(MSG_BACK);
  80. #if PREHEAT_COUNT
  81. LOOP_L_N(m, PREHEAT_COUNT)
  82. ACTION_ITEM_N_S(m, ui.get_preheat_label(m), MSG_PREHEAT_M, _change_filament_with_preset);
  83. #endif
  84. EDIT_ITEM_FAST_N(int3, extruder, MSG_PREHEAT_CUSTOM, &thermalManager.temp_hotend[extruder].target,
  85. EXTRUDE_MINTEMP, thermalManager.heater_maxtemp[extruder] - HOTEND_OVERSHOOT,
  86. _change_filament_with_custom
  87. );
  88. END_MENU();
  89. }
  90. /**
  91. *
  92. * "Change Filament" submenu
  93. *
  94. */
  95. #if E_STEPPERS > 1 || ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  96. void menu_change_filament() {
  97. // Say "filament change" when no print is active
  98. editable.int8 = printingIsPaused() ? PAUSE_MODE_PAUSE_PRINT : PAUSE_MODE_CHANGE_FILAMENT;
  99. #if E_STEPPERS > 1 && ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  100. bool too_cold = false;
  101. for (uint8_t s = 0; !too_cold && s < E_STEPPERS; s++)
  102. too_cold = thermalManager.targetTooColdToExtrude(s);
  103. #endif
  104. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  105. const bool is_busy = printer_busy();
  106. #endif
  107. START_MENU();
  108. BACK_ITEM(MSG_MAIN);
  109. // Change filament
  110. #if E_STEPPERS == 1
  111. PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE);
  112. if (thermalManager.targetTooColdToExtrude(active_extruder))
  113. SUBMENU_P(msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); });
  114. else
  115. GCODES_ITEM_P(msg, PSTR("M600 B0"));
  116. #else
  117. PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE_E);
  118. LOOP_L_N(s, E_STEPPERS) {
  119. if (thermalManager.targetTooColdToExtrude(s))
  120. SUBMENU_N_P(s, msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, MenuItemBase::itemIndex); });
  121. else {
  122. ACTION_ITEM_N_P(s, msg, []{
  123. PGM_P const cmdpstr = PSTR("M600 B0 T%i");
  124. char cmd[strlen_P(cmdpstr) + 3 + 1];
  125. sprintf_P(cmd, cmdpstr, int(MenuItemBase::itemIndex));
  126. queue.inject(cmd);
  127. });
  128. }
  129. }
  130. #endif
  131. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  132. if (!is_busy) {
  133. // Load filament
  134. #if E_STEPPERS == 1
  135. PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD);
  136. if (thermalManager.targetTooColdToExtrude(active_extruder))
  137. SUBMENU_P(msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, 0); });
  138. else
  139. GCODES_ITEM_P(msg_load, PSTR("M701"));
  140. #else
  141. PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD_E);
  142. LOOP_L_N(s, E_STEPPERS) {
  143. if (thermalManager.targetTooColdToExtrude(s))
  144. SUBMENU_N_P(s, msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, MenuItemBase::itemIndex); });
  145. else {
  146. ACTION_ITEM_N_P(s, msg_load, []{
  147. char cmd[12];
  148. sprintf_P(cmd, PSTR("M701 T%i"), int(MenuItemBase::itemIndex));
  149. queue.inject(cmd);
  150. });
  151. }
  152. }
  153. #endif
  154. // Unload filament
  155. #if E_STEPPERS == 1
  156. PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD);
  157. if (thermalManager.targetTooColdToExtrude(active_extruder))
  158. SUBMENU_P(msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, 0); });
  159. else
  160. GCODES_ITEM_P(msg_unload, PSTR("M702"));
  161. #else
  162. #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  163. if (too_cold)
  164. SUBMENU(MSG_FILAMENTUNLOAD_ALL, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, -1); });
  165. else
  166. GCODES_ITEM(MSG_FILAMENTUNLOAD_ALL, PSTR("M702"));
  167. #endif
  168. PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD_E);
  169. LOOP_L_N(s, E_STEPPERS) {
  170. if (thermalManager.targetTooColdToExtrude(s))
  171. SUBMENU_N_P(s, msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, MenuItemBase::itemIndex); });
  172. else {
  173. ACTION_ITEM_N_P(s, msg_unload, []{
  174. char cmd[12];
  175. sprintf_P(cmd, PSTR("M702 T%i"), int(MenuItemBase::itemIndex));
  176. queue.inject(cmd);
  177. });
  178. }
  179. }
  180. #endif
  181. } // !printer_busy
  182. #endif
  183. END_MENU();
  184. }
  185. #endif
  186. static uint8_t hotend_status_extruder = 0;
  187. static PGM_P pause_header() {
  188. switch (pause_mode) {
  189. case PAUSE_MODE_CHANGE_FILAMENT: return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER);
  190. case PAUSE_MODE_LOAD_FILAMENT: return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_LOAD);
  191. case PAUSE_MODE_UNLOAD_FILAMENT: return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_UNLOAD);
  192. default: break;
  193. }
  194. return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_PAUSE);
  195. }
  196. // Portions from STATIC_ITEM...
  197. #define HOTEND_STATUS_ITEM() do { \
  198. if (_menuLineNr == _thisItemNr) { \
  199. if (ui.should_draw()) { \
  200. TERN(HAS_GRAPHICAL_TFT,, MenuItem_static::draw(_lcdLineNr, GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE), SS_INVERT)); \
  201. ui.draw_hotend_status(_lcdLineNr, hotend_status_extruder); \
  202. } \
  203. if (_skipStatic && encoderLine <= _thisItemNr) { \
  204. ui.encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  205. ++encoderLine; \
  206. } \
  207. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT); \
  208. } \
  209. ++_thisItemNr; \
  210. }while(0)
  211. void menu_pause_option() {
  212. START_MENU();
  213. #if LCD_HEIGHT > 2
  214. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER);
  215. #endif
  216. ACTION_ITEM(MSG_FILAMENT_CHANGE_OPTION_PURGE, []{ pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; });
  217. #if HAS_FILAMENT_SENSOR
  218. const bool still_out = runout.filament_ran_out;
  219. if (still_out)
  220. EDIT_ITEM(bool, MSG_RUNOUT_SENSOR, &runout.enabled, runout.reset);
  221. #else
  222. constexpr bool still_out = false;
  223. #endif
  224. if (!still_out)
  225. ACTION_ITEM(MSG_FILAMENT_CHANGE_OPTION_RESUME, []{ pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; });
  226. END_MENU();
  227. }
  228. //
  229. // ADVANCED_PAUSE_FEATURE message screens
  230. //
  231. // Warning: msg must have three null bytes to delimit lines!
  232. //
  233. void _lcd_pause_message(PGM_P const msg) {
  234. PGM_P const msg1 = msg;
  235. PGM_P const msg2 = msg1 + strlen_P(msg1) + 1;
  236. PGM_P const msg3 = msg2 + strlen_P(msg2) + 1;
  237. const bool has2 = msg2[0], has3 = msg3[0],
  238. skip1 = !has2 && (LCD_HEIGHT) >= 5;
  239. START_SCREEN();
  240. STATIC_ITEM_P(pause_header(), SS_DEFAULT|SS_INVERT); // 1: Header
  241. if (skip1) SKIP_ITEM(); // Move a single-line message down
  242. STATIC_ITEM_P(msg1); // 2: Message Line 1
  243. if (has2) STATIC_ITEM_P(msg2); // 3: Message Line 2
  244. if (has3 && (LCD_HEIGHT) >= 5) STATIC_ITEM_P(msg3); // 4: Message Line 3 (if LCD has 5 lines)
  245. if (skip1 + 1 + has2 + has3 < (LCD_HEIGHT) - 2) SKIP_ITEM(); // Push Hotend Status down, if needed
  246. HOTEND_STATUS_ITEM(); // 5: Hotend Status
  247. END_SCREEN();
  248. }
  249. void lcd_pause_parking_message() { _lcd_pause_message(GET_TEXT(MSG_PAUSE_PRINT_PARKING)); }
  250. void lcd_pause_changing_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_INIT)); }
  251. void lcd_pause_unload_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_UNLOAD)); }
  252. void lcd_pause_heating_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_HEATING)); }
  253. void lcd_pause_heat_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_HEAT)); }
  254. void lcd_pause_insert_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_INSERT)); }
  255. void lcd_pause_load_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_LOAD)); }
  256. void lcd_pause_waiting_message() { _lcd_pause_message(GET_TEXT(MSG_ADVANCED_PAUSE_WAITING)); }
  257. void lcd_pause_resume_message() { _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_RESUME)); }
  258. void lcd_pause_purge_message() {
  259. #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE)
  260. _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_CONT_PURGE));
  261. #else
  262. _lcd_pause_message(GET_TEXT(MSG_FILAMENT_CHANGE_PURGE));
  263. #endif
  264. }
  265. FORCE_INLINE screenFunc_t ap_message_screen(const PauseMessage message) {
  266. switch (message) {
  267. case PAUSE_MESSAGE_PARKING: return lcd_pause_parking_message;
  268. case PAUSE_MESSAGE_CHANGING: return lcd_pause_changing_message;
  269. case PAUSE_MESSAGE_UNLOAD: return lcd_pause_unload_message;
  270. case PAUSE_MESSAGE_WAITING: return lcd_pause_waiting_message;
  271. case PAUSE_MESSAGE_INSERT: return lcd_pause_insert_message;
  272. case PAUSE_MESSAGE_LOAD: return lcd_pause_load_message;
  273. case PAUSE_MESSAGE_PURGE: return lcd_pause_purge_message;
  274. case PAUSE_MESSAGE_RESUME: return lcd_pause_resume_message;
  275. case PAUSE_MESSAGE_HEAT: return lcd_pause_heat_message;
  276. case PAUSE_MESSAGE_HEATING: return lcd_pause_heating_message;
  277. case PAUSE_MESSAGE_OPTION: pause_menu_response = PAUSE_RESPONSE_WAIT_FOR;
  278. return menu_pause_option;
  279. case PAUSE_MESSAGE_STATUS:
  280. default: break;
  281. }
  282. return nullptr;
  283. }
  284. void lcd_pause_show_message(
  285. const PauseMessage message,
  286. const PauseMode mode/*=PAUSE_MODE_SAME*/,
  287. const uint8_t extruder/*=active_extruder*/
  288. ) {
  289. if (mode != PAUSE_MODE_SAME) pause_mode = mode;
  290. hotend_status_extruder = extruder;
  291. const screenFunc_t next_screen = ap_message_screen(message);
  292. if (next_screen) {
  293. ui.defer_status_screen();
  294. ui.goto_screen(next_screen);
  295. }
  296. else
  297. ui.return_to_status();
  298. }
  299. #endif // HAS_LCD_MENU && ADVANCED_PAUSE_FEATURE