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.

draw_printing.cpp 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 "../../../../MarlinCore.h" // for marlin_state
  27. #include "../../../../module/temperature.h"
  28. #include "../../../../module/motion.h"
  29. #include "../../../../sd/cardreader.h"
  30. #include "../../../../gcode/queue.h"
  31. #include "../../../../gcode/gcode.h"
  32. #include "../../../../inc/MarlinConfig.h"
  33. #if ENABLED(POWER_LOSS_RECOVERY)
  34. #include "../../../../feature/powerloss.h"
  35. #endif
  36. #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
  37. #include "../../../marlinui.h"
  38. #endif
  39. extern lv_group_t *g;
  40. static lv_obj_t *scr;
  41. static lv_obj_t *labelExt1, *labelFan, *labelZpos, *labelTime;
  42. static lv_obj_t *labelPause, *labelStop, *labelOperat;
  43. static lv_obj_t *bar1, *bar1ValueText;
  44. static lv_obj_t *buttonPause, *buttonOperat, *buttonStop;
  45. TERN_(HAS_MULTI_EXTRUDER, static lv_obj_t *labelExt2);
  46. #if HAS_HEATED_BED
  47. static lv_obj_t* labelBed;
  48. #endif
  49. enum {
  50. ID_PAUSE = 1,
  51. ID_STOP,
  52. ID_OPTION
  53. };
  54. bool once_flag; // = false
  55. extern bool flash_preview_begin, default_preview_flg, gcode_preview_over;
  56. extern uint32_t To_pre_view;
  57. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  58. if (event != LV_EVENT_RELEASED) return;
  59. if (gcode_preview_over) return;
  60. switch (obj->mks_obj_id) {
  61. case ID_PAUSE:
  62. if (uiCfg.print_state == WORKING) {
  63. #if ENABLED(SDSUPPORT)
  64. card.pauseSDPrint();
  65. stop_print_time();
  66. uiCfg.print_state = PAUSING;
  67. #endif
  68. lv_imgbtn_set_src_both(buttonPause, "F:/bmp_resume.bin");
  69. lv_label_set_text(labelPause, printing_menu.resume);
  70. lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0);
  71. }
  72. else if (uiCfg.print_state == PAUSED) {
  73. uiCfg.print_state = RESUMING;
  74. lv_imgbtn_set_src_both(obj, "F:/bmp_pause.bin");
  75. lv_label_set_text(labelPause, printing_menu.pause);
  76. lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0);
  77. }
  78. #if ENABLED(POWER_LOSS_RECOVERY)
  79. else if (uiCfg.print_state == REPRINTING) {
  80. uiCfg.print_state = REPRINTED;
  81. lv_imgbtn_set_src_both(obj, "F:/bmp_pause.bin");
  82. lv_label_set_text(labelPause, printing_menu.pause);
  83. lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0);
  84. print_time.minutes = recovery.info.print_job_elapsed / 60;
  85. print_time.seconds = recovery.info.print_job_elapsed % 60;
  86. print_time.hours = print_time.minutes / 60;
  87. }
  88. #endif
  89. break;
  90. case ID_STOP:
  91. lv_clear_printing();
  92. lv_draw_dialog(DIALOG_TYPE_STOP);
  93. break;
  94. case ID_OPTION:
  95. lv_clear_printing();
  96. lv_draw_operation();
  97. break;
  98. }
  99. }
  100. void lv_draw_printing() {
  101. disp_state_stack._disp_index = 0;
  102. ZERO(disp_state_stack._disp_state);
  103. scr = lv_screen_create(PRINTING_UI);
  104. // Create image buttons
  105. lv_obj_t *buttonExt1 = lv_img_create(scr, nullptr);
  106. lv_img_set_src(buttonExt1, "F:/bmp_ext1_state.bin");
  107. lv_obj_set_pos(buttonExt1, 205, 136);
  108. #if HAS_MULTI_EXTRUDER
  109. lv_obj_t *buttonExt2 = lv_img_create(scr, nullptr);
  110. lv_img_set_src(buttonExt2, "F:/bmp_ext2_state.bin");
  111. lv_obj_set_pos(buttonExt2, 350, 136);
  112. #endif
  113. #if HAS_HEATED_BED
  114. lv_obj_t *buttonBedstate = lv_img_create(scr, nullptr);
  115. lv_img_set_src(buttonBedstate, "F:/bmp_bed_state.bin");
  116. lv_obj_set_pos(buttonBedstate, 205, 186);
  117. #endif
  118. lv_obj_t *buttonFanstate = lv_img_create(scr, nullptr);
  119. lv_img_set_src(buttonFanstate, "F:/bmp_fan_state.bin");
  120. lv_obj_set_pos(buttonFanstate, 350, 186);
  121. lv_obj_t *buttonTime = lv_img_create(scr, nullptr);
  122. lv_img_set_src(buttonTime, "F:/bmp_time_state.bin");
  123. lv_obj_set_pos(buttonTime, 205, 86);
  124. lv_obj_t *buttonZpos = lv_img_create(scr, nullptr);
  125. lv_img_set_src(buttonZpos, "F:/bmp_zpos_state.bin");
  126. lv_obj_set_pos(buttonZpos, 350, 86);
  127. buttonPause = lv_imgbtn_create(scr, uiCfg.print_state == WORKING ? "F:/bmp_pause.bin" : "F:/bmp_resume.bin", 5, 240, event_handler, ID_PAUSE);
  128. buttonStop = lv_imgbtn_create(scr, "F:/bmp_stop.bin", 165, 240, event_handler, ID_STOP);
  129. buttonOperat = lv_imgbtn_create(scr, "F:/bmp_operate.bin", 325, 240, event_handler, ID_OPTION);
  130. #if HAS_ROTARY_ENCODER
  131. if (gCfgItems.encoder_enable) {
  132. lv_group_add_obj(g, buttonPause);
  133. lv_group_add_obj(g, buttonStop);
  134. lv_group_add_obj(g, buttonOperat);
  135. }
  136. #endif
  137. labelExt1 = lv_label_create(scr, 250, 146, nullptr);
  138. #if HAS_MULTI_EXTRUDER
  139. labelExt2 = lv_label_create(scr, 395, 146, nullptr);
  140. #endif
  141. #if HAS_HEATED_BED
  142. labelBed = lv_label_create(scr, 250, 196, nullptr);
  143. #endif
  144. labelFan = lv_label_create(scr, 395, 196, nullptr);
  145. labelTime = lv_label_create(scr, 250, 96, nullptr);
  146. labelZpos = lv_label_create(scr, 395, 96, nullptr);
  147. labelPause = lv_label_create_empty(buttonPause);
  148. labelStop = lv_label_create_empty(buttonStop);
  149. labelOperat = lv_label_create_empty(buttonOperat);
  150. if (gCfgItems.multiple_language) {
  151. lv_label_set_text(labelPause, uiCfg.print_state == WORKING ? printing_menu.pause : printing_menu.resume);
  152. lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 20, 0);
  153. lv_label_set_text(labelStop, printing_menu.stop);
  154. lv_obj_align(labelStop, buttonStop, LV_ALIGN_CENTER, 20, 0);
  155. lv_label_set_text(labelOperat, printing_menu.option);
  156. lv_obj_align(labelOperat, buttonOperat, LV_ALIGN_CENTER, 20, 0);
  157. }
  158. bar1 = lv_bar_create(scr, nullptr);
  159. lv_obj_set_pos(bar1, 205, 36);
  160. lv_obj_set_size(bar1, 270, 40);
  161. lv_bar_set_style(bar1, LV_BAR_STYLE_INDIC, &lv_bar_style_indic);
  162. lv_bar_set_anim_time(bar1, 1000);
  163. lv_bar_set_value(bar1, 0, LV_ANIM_ON);
  164. bar1ValueText = lv_label_create_empty(bar1);
  165. lv_label_set_text(bar1ValueText,"0%");
  166. lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0);
  167. disp_ext_temp();
  168. disp_bed_temp();
  169. disp_fan_speed();
  170. disp_print_time();
  171. disp_fan_Zpos();
  172. }
  173. void disp_ext_temp() {
  174. sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.temp_hotend[0].celsius, (int)thermalManager.temp_hotend[0].target);
  175. lv_label_set_text(labelExt1, public_buf_l);
  176. #if HAS_MULTI_EXTRUDER
  177. sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.temp_hotend[1].celsius, (int)thermalManager.temp_hotend[1].target);
  178. lv_label_set_text(labelExt2, public_buf_l);
  179. #endif
  180. }
  181. void disp_bed_temp() {
  182. #if HAS_HEATED_BED
  183. sprintf(public_buf_l, printing_menu.bed_temp, (int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target);
  184. lv_label_set_text(labelBed, public_buf_l);
  185. #endif
  186. }
  187. void disp_fan_speed() {
  188. sprintf_P(public_buf_l, PSTR("%3d"), thermalManager.fan_speed[0]);
  189. lv_label_set_text(labelFan, public_buf_l);
  190. }
  191. void disp_print_time() {
  192. #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
  193. const uint32_t r = ui.get_remaining_time();
  194. sprintf_P(public_buf_l, PSTR("%02d:%02d R"), r / 3600, (r % 3600) / 60);
  195. #else
  196. sprintf_P(public_buf_l, PSTR("%d%d:%d%d:%d%d"), print_time.hours / 10, print_time.hours % 10, print_time.minutes / 10, print_time.minutes % 10, print_time.seconds / 10, print_time.seconds % 10);
  197. #endif
  198. lv_label_set_text(labelTime, public_buf_l);
  199. }
  200. void disp_fan_Zpos() {
  201. sprintf_P(public_buf_l, PSTR("%.3f"), current_position[Z_AXIS]);
  202. lv_label_set_text(labelZpos, public_buf_l);
  203. }
  204. void reset_print_time() {
  205. print_time.hours = 0;
  206. print_time.minutes = 0;
  207. print_time.seconds = 0;
  208. print_time.ms_10 = 0;
  209. }
  210. void start_print_time() { print_time.start = 1; }
  211. void stop_print_time() { print_time.start = 0; }
  212. void setProBarRate() {
  213. int rate;
  214. volatile long long rate_tmp_r;
  215. if (!gCfgItems.from_flash_pic) {
  216. #if ENABLED(SDSUPPORT)
  217. rate_tmp_r = (long long)card.getIndex() * 100;
  218. #endif
  219. rate = rate_tmp_r / gCfgItems.curFilesize;
  220. }
  221. else {
  222. #if ENABLED(SDSUPPORT)
  223. rate_tmp_r = (long long)card.getIndex();
  224. #endif
  225. rate = (rate_tmp_r - (PREVIEW_SIZE + To_pre_view)) * 100 / (gCfgItems.curFilesize - (PREVIEW_SIZE + To_pre_view));
  226. }
  227. if (rate <= 0) return;
  228. if (disp_state == PRINTING_UI) {
  229. lv_bar_set_value(bar1, rate, LV_ANIM_ON);
  230. sprintf_P(public_buf_l, "%d%%", rate);
  231. lv_label_set_text(bar1ValueText,public_buf_l);
  232. lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0);
  233. if (marlin_state == MF_SD_COMPLETE) {
  234. if (once_flag == 0) {
  235. stop_print_time();
  236. flash_preview_begin = false;
  237. default_preview_flg = false;
  238. lv_clear_printing();
  239. lv_draw_dialog(DIALOG_TYPE_FINISH_PRINT);
  240. once_flag = true;
  241. #if HAS_SUICIDE
  242. if (gCfgItems.finish_power_off) {
  243. gcode.process_subcommands_now_P(PSTR("M1001"));
  244. queue.inject_P(PSTR("M81"));
  245. marlin_state = MF_RUNNING;
  246. }
  247. #endif
  248. }
  249. }
  250. }
  251. }
  252. void lv_clear_printing() {
  253. #if HAS_ROTARY_ENCODER
  254. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  255. #endif
  256. lv_obj_del(scr);
  257. }
  258. #endif // HAS_TFT_LVGL_UI