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 7.5KB

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