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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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 "lv_conf.h"
  25. #include "draw_ui.h"
  26. //#include "../lvgl/src/lv_objx/lv_imgbtn.h"
  27. //#include "../lvgl/src/lv_objx/lv_img.h"
  28. //#include "../lvgl/src/lv_core/lv_disp.h"
  29. //#include "../lvgl/src/lv_core/lv_refr.h"
  30. #include "../../../../MarlinCore.h"
  31. #include "../../../../module/temperature.h"
  32. #include "../../../../module/motion.h"
  33. #include "../../../../sd/cardreader.h"
  34. #include "../../../../gcode/queue.h"
  35. #include "../../../../gcode/gcode.h"
  36. #if ENABLED(POWER_LOSS_RECOVERY)
  37. #include "../../../../feature/powerloss.h"
  38. #endif
  39. #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
  40. #include "../../../ultralcd.h"
  41. #endif
  42. extern lv_group_t * g;
  43. static lv_obj_t * scr;
  44. static lv_obj_t *labelExt1, * labelFan, * labelZpos, * labelTime;
  45. TERN_(HAS_MULTI_EXTRUDER, static lv_obj_t *labelExt2;)
  46. static lv_obj_t *labelPause, * labelStop, * labelOperat;
  47. static lv_obj_t * bar1, *bar1ValueText;
  48. static lv_obj_t * buttonPause, *buttonOperat, *buttonStop;
  49. #if HAS_HEATED_BED
  50. static lv_obj_t* labelBed;
  51. #endif
  52. #define ID_PAUSE 1
  53. #define ID_STOP 2
  54. #define ID_OPTION 3
  55. uint8_t once_flag = 0;
  56. extern uint32_t To_pre_view;
  57. extern uint8_t flash_preview_begin;
  58. extern uint8_t default_preview_flg;
  59. extern uint8_t gcode_preview_over;
  60. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  61. switch (obj->mks_obj_id) {
  62. case ID_PAUSE:
  63. if (event == LV_EVENT_CLICKED) {
  64. // nothing to do
  65. }
  66. else if (event == LV_EVENT_RELEASED) {
  67. if (gcode_preview_over != 1) {
  68. if (uiCfg.print_state == WORKING) {
  69. // #if ENABLED(PARK_HEAD_ON_PAUSE)
  70. // queue.inject_P(PSTR("M25 P\nM24"));
  71. #if ENABLED(SDSUPPORT)
  72. // queue.inject_P(PSTR("M25\nG91\nG1 Z10\nG90"));
  73. card.pauseSDPrint();
  74. stop_print_time();
  75. uiCfg.print_state = PAUSING;
  76. #endif
  77. lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_REL, "F:/bmp_resume.bin");
  78. lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_PR, "F:/bmp_resume.bin");
  79. lv_label_set_text(labelPause, printing_menu.resume);
  80. lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0);
  81. }
  82. else if (uiCfg.print_state == PAUSED) {
  83. uiCfg.print_state = RESUMING;
  84. lv_imgbtn_set_src(obj, LV_BTN_STATE_REL, "F:/bmp_pause.bin");
  85. lv_imgbtn_set_src(obj, LV_BTN_STATE_PR, "F:/bmp_pause.bin");
  86. lv_label_set_text(labelPause, printing_menu.pause);
  87. lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0);
  88. }
  89. #if ENABLED(POWER_LOSS_RECOVERY)
  90. else if (uiCfg.print_state == REPRINTING) {
  91. uiCfg.print_state = REPRINTED;
  92. lv_imgbtn_set_src(obj, LV_BTN_STATE_REL, "F:/bmp_pause.bin");
  93. lv_imgbtn_set_src(obj, LV_BTN_STATE_PR, "F:/bmp_pause.bin");
  94. lv_label_set_text(labelPause, printing_menu.pause);
  95. lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0);
  96. // recovery.resume();
  97. print_time.minutes = recovery.info.print_job_elapsed / 60;
  98. print_time.seconds = recovery.info.print_job_elapsed % 60;
  99. print_time.hours = print_time.minutes / 60;
  100. }
  101. #endif
  102. }
  103. }
  104. break;
  105. case ID_STOP:
  106. if (event == LV_EVENT_CLICKED) {
  107. // nothing to do
  108. }
  109. else if (event == LV_EVENT_RELEASED) {
  110. if (gcode_preview_over != 1) {
  111. lv_clear_printing();
  112. lv_draw_dialog(DIALOG_TYPE_STOP);
  113. }
  114. }
  115. break;
  116. case ID_OPTION:
  117. if (event == LV_EVENT_CLICKED) {
  118. // nothing to do
  119. }
  120. else if (event == LV_EVENT_RELEASED) {
  121. if (gcode_preview_over != 1) {
  122. lv_clear_printing();
  123. lv_draw_operation();
  124. }
  125. }
  126. break;
  127. }
  128. }
  129. void lv_draw_printing(void) {
  130. disp_state_stack._disp_index = 0;
  131. ZERO(disp_state_stack._disp_state);
  132. disp_state_stack._disp_state[disp_state_stack._disp_index] = PRINTING_UI;
  133. disp_state = PRINTING_UI;
  134. scr = lv_obj_create(NULL, NULL);
  135. // static lv_style_t tool_style;
  136. lv_obj_set_style(scr, &tft_style_scr);
  137. lv_scr_load(scr);
  138. lv_obj_clean(scr);
  139. lv_obj_t * title = lv_label_create(scr, NULL);
  140. lv_obj_set_style(title, &tft_style_label_rel);
  141. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  142. lv_label_set_text(title, creat_title_text());
  143. lv_refr_now(lv_refr_get_disp_refreshing());
  144. // Create image buttons
  145. lv_obj_t *buttonExt1 = lv_img_create(scr, NULL);
  146. #if HAS_MULTI_EXTRUDER
  147. lv_obj_t *buttonExt2 = lv_img_create(scr, NULL);
  148. #endif
  149. #if HAS_HEATED_BED
  150. lv_obj_t *buttonBedstate = lv_img_create(scr, NULL);
  151. #endif
  152. lv_obj_t *buttonFanstate = lv_img_create(scr, NULL);
  153. lv_obj_t *buttonTime = lv_img_create(scr, NULL);
  154. lv_obj_t *buttonZpos = lv_img_create(scr, NULL);
  155. buttonPause = lv_imgbtn_create(scr, NULL);
  156. buttonStop = lv_imgbtn_create(scr, NULL);
  157. buttonOperat = lv_imgbtn_create(scr, NULL);
  158. lv_img_set_src(buttonExt1, "F:/bmp_ext1_state.bin");
  159. #if 1
  160. #if HAS_MULTI_EXTRUDER
  161. lv_img_set_src(buttonExt2, "F:/bmp_ext2_state.bin");
  162. #endif
  163. #if HAS_HEATED_BED
  164. lv_img_set_src(buttonBedstate, "F:/bmp_bed_state.bin");
  165. #endif
  166. lv_img_set_src(buttonFanstate, "F:/bmp_fan_state.bin");
  167. lv_img_set_src(buttonTime, "F:/bmp_time_state.bin");
  168. lv_img_set_src(buttonZpos, "F:/bmp_zpos_state.bin");
  169. if (uiCfg.print_state == WORKING) {
  170. lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_REL, "F:/bmp_pause.bin");
  171. lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_PR, "F:/bmp_pause.bin");
  172. }
  173. else {
  174. lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_REL, "F:/bmp_resume.bin");
  175. lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_PR, "F:/bmp_resume.bin");
  176. }
  177. lv_obj_set_event_cb_mks(buttonPause, event_handler, ID_PAUSE, NULL, 0);
  178. lv_imgbtn_set_style(buttonPause, LV_BTN_STATE_PR, &tft_style_label_pre);
  179. lv_imgbtn_set_style(buttonPause, LV_BTN_STATE_REL, &tft_style_label_rel);
  180. lv_obj_set_event_cb_mks(buttonStop, event_handler, ID_STOP, NULL, 0);
  181. lv_imgbtn_set_src(buttonStop, LV_BTN_STATE_REL, "F:/bmp_stop.bin");
  182. lv_imgbtn_set_src(buttonStop, LV_BTN_STATE_PR, "F:/bmp_stop.bin");
  183. lv_imgbtn_set_style(buttonStop, LV_BTN_STATE_PR, &tft_style_label_pre);
  184. lv_imgbtn_set_style(buttonStop, LV_BTN_STATE_REL, &tft_style_label_rel);
  185. lv_obj_set_event_cb_mks(buttonOperat, event_handler, ID_OPTION, NULL, 0);
  186. lv_imgbtn_set_src(buttonOperat, LV_BTN_STATE_REL, "F:/bmp_operate.bin");
  187. lv_imgbtn_set_src(buttonOperat, LV_BTN_STATE_PR, "F:/bmp_operate.bin");
  188. lv_imgbtn_set_style(buttonOperat, LV_BTN_STATE_PR, &tft_style_label_pre);
  189. lv_imgbtn_set_style(buttonOperat, LV_BTN_STATE_REL, &tft_style_label_rel);
  190. #endif // if 1
  191. #if HAS_ROTARY_ENCODER
  192. if (gCfgItems.encoder_enable) {
  193. lv_group_add_obj(g, buttonPause);
  194. lv_group_add_obj(g, buttonStop);
  195. lv_group_add_obj(g, buttonOperat);
  196. }
  197. #endif
  198. lv_obj_set_pos(buttonExt1, 205, 136);
  199. #if HAS_MULTI_EXTRUDER
  200. lv_obj_set_pos(buttonExt2, 350, 136);
  201. #endif
  202. #if HAS_HEATED_BED
  203. lv_obj_set_pos(buttonBedstate, 205, 186);
  204. #endif
  205. lv_obj_set_pos(buttonFanstate, 350, 186);
  206. lv_obj_set_pos(buttonTime, 205, 86);
  207. lv_obj_set_pos(buttonZpos, 350, 86);
  208. lv_obj_set_pos(buttonPause, 5, 240);
  209. lv_obj_set_pos(buttonStop, 165, 240);
  210. lv_obj_set_pos(buttonOperat, 325, 240);
  211. // Create labels on the image buttons
  212. //lv_btn_set_layout(buttonExt1, LV_LAYOUT_OFF);
  213. //#if HAS_MULTI_EXTRUDER
  214. //lv_btn_set_layout(buttonExt2, LV_LAYOUT_OFF);
  215. //#endif
  216. //#if HAS_HEATED_BED
  217. //lv_btn_set_layout(buttonBedstate, LV_LAYOUT_OFF);
  218. //#endif
  219. //lv_btn_set_layout(buttonFanstate, LV_LAYOUT_OFF);
  220. //lv_btn_set_layout(buttonTime, LV_LAYOUT_OFF);
  221. //lv_btn_set_layout(buttonZpos, LV_LAYOUT_OFF);
  222. lv_btn_set_layout(buttonPause, LV_LAYOUT_OFF);
  223. lv_btn_set_layout(buttonStop, LV_LAYOUT_OFF);
  224. lv_btn_set_layout(buttonOperat, LV_LAYOUT_OFF);
  225. labelExt1 = lv_label_create(scr, NULL);
  226. lv_obj_set_style(labelExt1, &tft_style_label_rel);
  227. lv_obj_set_pos(labelExt1, 250, 146);
  228. #if HAS_MULTI_EXTRUDER
  229. labelExt2 = lv_label_create(scr, NULL);
  230. lv_obj_set_style(labelExt2, &tft_style_label_rel);
  231. lv_obj_set_pos(labelExt2, 395, 146);
  232. #endif
  233. #if HAS_HEATED_BED
  234. labelBed = lv_label_create(scr, NULL);
  235. lv_obj_set_style(labelBed, &tft_style_label_rel);
  236. lv_obj_set_pos(labelBed, 250, 196);
  237. #endif
  238. labelFan = lv_label_create(scr, NULL);
  239. lv_obj_set_style(labelFan, &tft_style_label_rel);
  240. lv_obj_set_pos(labelFan, 395, 196);
  241. labelTime = lv_label_create(scr, NULL);
  242. lv_obj_set_style(labelTime, &tft_style_label_rel);
  243. lv_obj_set_pos(labelTime, 250, 96);
  244. labelZpos = lv_label_create(scr, NULL);
  245. lv_obj_set_style(labelZpos, &tft_style_label_rel);
  246. lv_obj_set_pos(labelZpos, 395, 96);
  247. labelPause = lv_label_create(buttonPause, NULL);
  248. labelStop = lv_label_create(buttonStop, NULL);
  249. labelOperat = lv_label_create(buttonOperat, NULL);
  250. if (gCfgItems.multiple_language != 0) {
  251. lv_label_set_text(labelPause, uiCfg.print_state == WORKING ? printing_menu.pause : printing_menu.resume);
  252. lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 20, 0);
  253. lv_label_set_text(labelStop, printing_menu.stop);
  254. lv_obj_align(labelStop, buttonStop, LV_ALIGN_CENTER, 20, 0);
  255. lv_label_set_text(labelOperat, printing_menu.option);
  256. lv_obj_align(labelOperat, buttonOperat, LV_ALIGN_CENTER, 20, 0);
  257. }
  258. bar1 = lv_bar_create(scr, NULL);
  259. lv_obj_set_pos(bar1, 205, 36);
  260. lv_obj_set_size(bar1, 270, 40);
  261. lv_bar_set_style(bar1, LV_BAR_STYLE_INDIC, &lv_bar_style_indic);
  262. lv_bar_set_anim_time(bar1, 1000);
  263. lv_bar_set_value(bar1, 0, LV_ANIM_ON);
  264. bar1ValueText = lv_label_create(bar1, NULL);
  265. lv_label_set_text(bar1ValueText,"0%");
  266. lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0);
  267. disp_ext_temp();
  268. disp_bed_temp();
  269. disp_fan_speed();
  270. disp_print_time();
  271. disp_fan_Zpos();
  272. }
  273. void disp_ext_temp() {
  274. ZERO(public_buf_l);
  275. sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.temp_hotend[0].celsius, (int)thermalManager.temp_hotend[0].target);
  276. lv_label_set_text(labelExt1, public_buf_l);
  277. #if HAS_MULTI_EXTRUDER
  278. ZERO(public_buf_l);
  279. sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.temp_hotend[1].celsius, (int)thermalManager.temp_hotend[1].target);
  280. lv_label_set_text(labelExt2, public_buf_l);
  281. #endif
  282. }
  283. void disp_bed_temp() {
  284. #if HAS_HEATED_BED
  285. ZERO(public_buf_l);
  286. sprintf(public_buf_l, printing_menu.bed_temp, (int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target);
  287. lv_label_set_text(labelBed, public_buf_l);
  288. #endif
  289. }
  290. void disp_fan_speed() {
  291. ZERO(public_buf_l);
  292. sprintf_P(public_buf_l, PSTR("%3d"), thermalManager.fan_speed[0]);
  293. lv_label_set_text(labelFan, public_buf_l);
  294. }
  295. void disp_print_time() {
  296. ZERO(public_buf_l);
  297. #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
  298. const uint32_t r = ui.get_remaining_time();
  299. sprintf_P(public_buf_l, PSTR("%02d:%02d R"), r / 3600, (r % 3600) / 60);
  300. #else
  301. 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);
  302. #endif
  303. lv_label_set_text(labelTime, public_buf_l);
  304. }
  305. void disp_fan_Zpos() {
  306. ZERO(public_buf_l);
  307. sprintf_P(public_buf_l, PSTR("%.3f"), current_position[Z_AXIS]);
  308. lv_label_set_text(labelZpos, public_buf_l);
  309. }
  310. void reset_print_time() {
  311. // print_time.days = 0;
  312. print_time.hours = 0;
  313. print_time.minutes = 0;
  314. print_time.seconds = 0;
  315. print_time.ms_10 = 0;
  316. // print_time.start = 1;
  317. }
  318. void start_print_time() { print_time.start = 1; }
  319. void stop_print_time() { print_time.start = 0; }
  320. void setProBarRate() {
  321. int rate;
  322. volatile long long rate_tmp_r;
  323. if (gCfgItems.from_flash_pic != 1) {
  324. #if ENABLED(SDSUPPORT)
  325. rate_tmp_r = (long long)card.getIndex() * 100;
  326. #endif
  327. rate = rate_tmp_r / gCfgItems.curFilesize;
  328. }
  329. else {
  330. #if ENABLED(SDSUPPORT)
  331. rate_tmp_r = (long long)card.getIndex();
  332. #endif
  333. rate = (rate_tmp_r - (PREVIEW_SIZE + To_pre_view)) * 100 / (gCfgItems.curFilesize - (PREVIEW_SIZE + To_pre_view));
  334. }
  335. // gCurFileState.totalSend = rate;
  336. if (rate <= 0) return;
  337. if (disp_state == PRINTING_UI) {
  338. lv_bar_set_value(bar1, rate, LV_ANIM_ON);
  339. ZERO(public_buf_l);
  340. sprintf_P(public_buf_l, "%d%%", rate);
  341. lv_label_set_text(bar1ValueText,public_buf_l);
  342. lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0);
  343. if (marlin_state == MF_SD_COMPLETE) {
  344. if (once_flag == 0) {
  345. stop_print_time();
  346. flash_preview_begin = 0;
  347. default_preview_flg = 0;
  348. lv_clear_printing();
  349. lv_draw_dialog(DIALOG_TYPE_FINISH_PRINT);
  350. once_flag = 1;
  351. #if HAS_SUICIDE
  352. if (gCfgItems.finish_power_off == 1) {
  353. gcode.process_subcommands_now_P(PSTR("M1001"));
  354. queue.inject_P(PSTR("M81"));
  355. marlin_state = MF_RUNNING;
  356. }
  357. #endif
  358. }
  359. }
  360. }
  361. }
  362. void lv_clear_printing() {
  363. #if HAS_ROTARY_ENCODER
  364. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  365. #endif
  366. lv_obj_del(scr);
  367. }
  368. #endif // HAS_TFT_LVGL_UI