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