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.

printer_operation.cpp 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #include "../../../inc/MarlinConfigPre.h"
  23. #if HAS_TFT_LVGL_UI
  24. #include "draw_ui.h"
  25. #include <lv_conf.h>
  26. #include "../../../gcode/gcode.h"
  27. #include "../../../module/planner.h"
  28. #include "../../../module/motion.h"
  29. #include "../../../sd/cardreader.h"
  30. #include "../../../inc/MarlinConfig.h"
  31. #include "../../../MarlinCore.h"
  32. #include "../../../gcode/queue.h"
  33. #if ENABLED(POWER_LOSS_RECOVERY)
  34. #include "../../../feature/powerloss.h"
  35. #endif
  36. extern uint32_t To_pre_view;
  37. extern bool flash_preview_begin, default_preview_flg, gcode_preview_over;
  38. void printer_state_polling() {
  39. char str_1[16];
  40. if (uiCfg.print_state == PAUSING) {
  41. #if ENABLED(SDSUPPORT)
  42. if (!planner.has_blocks_queued() && card.getIndex() > MIN_FILE_PRINTED)
  43. uiCfg.waitEndMoves++;
  44. if (uiCfg.waitEndMoves > 20) {
  45. uiCfg.waitEndMoves = 0;
  46. planner.synchronize();
  47. gcode.process_subcommands_now_P(PSTR("M25"));
  48. //save the position
  49. uiCfg.current_x_position_bak = current_position.x;
  50. uiCfg.current_y_position_bak = current_position.y;
  51. uiCfg.current_z_position_bak = current_position.z;
  52. if (gCfgItems.pausePosZ != (float)-1) {
  53. sprintf_P(public_buf_l, PSTR("G91\nG1 Z%s\nG90"), dtostrf(gCfgItems.pausePosZ, 1, 1, str_1));
  54. gcode.process_subcommands_now(public_buf_l);
  55. }
  56. if (gCfgItems.pausePosX != (float)-1 && gCfgItems.pausePosY != (float)-1) {
  57. sprintf_P(public_buf_l, PSTR("G1 X%s Y%s"), dtostrf(gCfgItems.pausePosX, 1, 1, str_1), dtostrf(gCfgItems.pausePosY, 1, 1, str_1));
  58. gcode.process_subcommands_now(public_buf_l);
  59. }
  60. uiCfg.print_state = PAUSED;
  61. uiCfg.current_e_position_bak = current_position.e;
  62. gCfgItems.pause_reprint = true;
  63. update_spi_flash();
  64. }
  65. #endif
  66. }
  67. else
  68. uiCfg.waitEndMoves = 0;
  69. if (uiCfg.print_state == PAUSED) {
  70. }
  71. if (uiCfg.print_state == RESUMING) {
  72. if (IS_SD_PAUSED()) {
  73. if (gCfgItems.pausePosX != (float)-1 && gCfgItems.pausePosY != (float)-1) {
  74. sprintf_P(public_buf_m, PSTR("G1 X%s Y%s"), dtostrf(uiCfg.current_x_position_bak, 1, 1, str_1), dtostrf(uiCfg.current_y_position_bak, 1, 1, str_1));
  75. gcode.process_subcommands_now(public_buf_m);
  76. }
  77. if (gCfgItems.pausePosZ != (float)-1) {
  78. ZERO(public_buf_m);
  79. sprintf_P(public_buf_m, PSTR("G1 Z%s"), dtostrf(uiCfg.current_z_position_bak, 1, 1, str_1));
  80. gcode.process_subcommands_now(public_buf_m);
  81. }
  82. gcode.process_subcommands_now_P(M24_STR);
  83. uiCfg.print_state = WORKING;
  84. start_print_time();
  85. gCfgItems.pause_reprint = false;
  86. update_spi_flash();
  87. }
  88. }
  89. #if ENABLED(POWER_LOSS_RECOVERY)
  90. if (uiCfg.print_state == REPRINTED) {
  91. #if HAS_HOTEND
  92. HOTEND_LOOP() {
  93. const int16_t et = recovery.info.target_temperature[e];
  94. if (et) {
  95. #if HAS_MULTI_HOTEND
  96. sprintf_P(public_buf_m, PSTR("T%i"), e);
  97. gcode.process_subcommands_now(public_buf_m);
  98. #endif
  99. sprintf_P(public_buf_m, PSTR("M109 S%i"), et);
  100. gcode.process_subcommands_now(public_buf_m);
  101. }
  102. }
  103. #endif
  104. recovery.resume();
  105. #if 0
  106. // Move back to the saved XY
  107. char str_1[16], str_2[16];
  108. sprintf_P(public_buf_m, PSTR("G1 X%s Y%s F2000"),
  109. dtostrf(recovery.info.current_position.x, 1, 3, str_1),
  110. dtostrf(recovery.info.current_position.y, 1, 3, str_2)
  111. );
  112. gcode.process_subcommands_now(public_buf_m);
  113. if (gCfgItems.pause_reprint && gCfgItems.pausePosZ != -1.0f) {
  114. sprintf_P(public_buf_l, PSTR("G91\nG1 Z-%s\nG90"), dtostrf(gCfgItems.pausePosZ, 1, 1, str_2));
  115. gcode.process_subcommands_now(public_buf_l);
  116. }
  117. #endif
  118. uiCfg.print_state = WORKING;
  119. start_print_time();
  120. gCfgItems.pause_reprint = false;
  121. update_spi_flash();
  122. }
  123. #endif
  124. if (uiCfg.print_state == WORKING)
  125. filament_check();
  126. TERN_(MKS_WIFI_MODULE, wifi_looping());
  127. }
  128. void filament_pin_setup() {
  129. #if PIN_EXISTS(MT_DET_1)
  130. SET_INPUT_PULLUP(MT_DET_1_PIN);
  131. #endif
  132. #if PIN_EXISTS(MT_DET_2)
  133. SET_INPUT_PULLUP(MT_DET_2_PIN);
  134. #endif
  135. #if PIN_EXISTS(MT_DET_3)
  136. SET_INPUT_PULLUP(MT_DET_3_PIN);
  137. #endif
  138. }
  139. void filament_check() {
  140. #if ANY_PIN(MT_DET_1, MT_DET_2, MT_DET_3)
  141. const int FIL_DELAY = 20;
  142. #endif
  143. #if PIN_EXISTS(MT_DET_1)
  144. static int fil_det_count_1 = 0;
  145. if (READ(MT_DET_1_PIN) == MT_DET_PIN_INVERTING)
  146. fil_det_count_1++;
  147. else if (fil_det_count_1 > 0)
  148. fil_det_count_1--;
  149. #endif
  150. #if PIN_EXISTS(MT_DET_2)
  151. static int fil_det_count_2 = 0;
  152. if (READ(MT_DET_2_PIN) == MT_DET_PIN_INVERTING)
  153. fil_det_count_2++;
  154. else if (fil_det_count_2 > 0)
  155. fil_det_count_2--;
  156. #endif
  157. #if PIN_EXISTS(MT_DET_3)
  158. static int fil_det_count_3 = 0;
  159. if (READ(MT_DET_3_PIN) == MT_DET_PIN_INVERTING)
  160. fil_det_count_3++;
  161. else if (fil_det_count_3 > 0)
  162. fil_det_count_3--;
  163. #endif
  164. if (false
  165. #if PIN_EXISTS(MT_DET_1)
  166. || fil_det_count_1 >= FIL_DELAY
  167. #endif
  168. #if PIN_EXISTS(MT_DET_2)
  169. || fil_det_count_2 >= FIL_DELAY
  170. #endif
  171. #if PIN_EXISTS(MT_DET_3)
  172. || fil_det_count_3 >= FIL_DELAY
  173. #endif
  174. ) {
  175. clear_cur_ui();
  176. card.pauseSDPrint();
  177. stop_print_time();
  178. uiCfg.print_state = PAUSING;
  179. if (gCfgItems.from_flash_pic)
  180. flash_preview_begin = true;
  181. else
  182. default_preview_flg = true;
  183. lv_draw_printing();
  184. }
  185. }
  186. #endif // HAS_TFT_LVGL_UI