My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

draw_printing.cpp 10KB

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