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.9KB

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