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_filament_change.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 "../../../../MarlinCore.h"
  27. #include "../../../../module/temperature.h"
  28. #include "../../../../gcode/queue.h"
  29. #include "../../../../gcode/gcode.h"
  30. #include "../../../../module/motion.h"
  31. #include "../../../../module/planner.h"
  32. extern lv_group_t * g;
  33. static lv_obj_t * scr;
  34. static lv_obj_t *buttoType;
  35. static lv_obj_t *labelType;
  36. static lv_obj_t * tempText1;
  37. #define ID_FILAMNT_IN 1
  38. #define ID_FILAMNT_OUT 2
  39. #define ID_FILAMNT_TYPE 3
  40. #define ID_FILAMNT_RETURN 4
  41. extern feedRate_t feedrate_mm_s;
  42. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  43. switch (obj->mks_obj_id) {
  44. case ID_FILAMNT_IN:
  45. if (event == LV_EVENT_CLICKED) {
  46. // nothing to do
  47. }
  48. else if (event == LV_EVENT_RELEASED) {
  49. uiCfg.filament_load_heat_flg = 1;
  50. if ((abs(thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius) <= 1)
  51. || (gCfgItems.filament_limit_temper <= thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) {
  52. lv_clear_filament_change();
  53. lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED);
  54. }
  55. else {
  56. lv_clear_filament_change();
  57. lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_HEAT);
  58. if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) {
  59. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper;
  60. thermalManager.start_watching_hotend(uiCfg.curSprayerChoose);
  61. }
  62. }
  63. }
  64. break;
  65. case ID_FILAMNT_OUT:
  66. if (event == LV_EVENT_CLICKED) {
  67. // nothing to do
  68. }
  69. else if (event == LV_EVENT_RELEASED) {
  70. uiCfg.filament_unload_heat_flg=1;
  71. if ((thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > 0)
  72. && ((abs((int)((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) <= 1)
  73. || ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= gCfgItems.filament_limit_temper))
  74. ) {
  75. lv_clear_filament_change();
  76. lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED);
  77. }
  78. else {
  79. lv_clear_filament_change();
  80. lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_HEAT);
  81. if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) {
  82. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper;
  83. thermalManager.start_watching_hotend(uiCfg.curSprayerChoose);
  84. }
  85. filament_sprayer_temp();
  86. }
  87. }
  88. break;
  89. case ID_FILAMNT_TYPE:
  90. if (event == LV_EVENT_CLICKED) {
  91. // nothing to do
  92. }
  93. else if (event == LV_EVENT_RELEASED) {
  94. #if HAS_MULTI_EXTRUDER
  95. if (uiCfg.curSprayerChoose == 0)
  96. uiCfg.curSprayerChoose = 1;
  97. else if (uiCfg.curSprayerChoose == 1)
  98. uiCfg.curSprayerChoose = 0;
  99. #endif
  100. disp_filament_type();
  101. }
  102. break;
  103. case ID_FILAMNT_RETURN:
  104. if (event == LV_EVENT_CLICKED) {
  105. // nothing to do
  106. }
  107. else if (event == LV_EVENT_RELEASED) {
  108. #if HAS_MULTI_EXTRUDER
  109. if (uiCfg.print_state != IDLE && uiCfg.print_state != REPRINTED)
  110. gcode.process_subcommands_now_P(uiCfg.curSprayerChoose_bak == 1 ? PSTR("T1") : PSTR("T0"));
  111. #endif
  112. feedrate_mm_s = (float)uiCfg.moveSpeed_bak;
  113. if (uiCfg.print_state == PAUSED)
  114. planner.set_e_position_mm((destination.e = current_position.e = uiCfg.current_e_position_bak));
  115. //current_position.e = destination.e = uiCfg.current_e_position_bak;
  116. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak;
  117. clear_cur_ui();
  118. draw_return_ui();
  119. }
  120. break;
  121. }
  122. }
  123. void lv_draw_filament_change(void) {
  124. lv_obj_t *buttonIn, *buttonOut;
  125. lv_obj_t *buttonBack;
  126. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FILAMENTCHANGE_UI) {
  127. disp_state_stack._disp_index++;
  128. disp_state_stack._disp_state[disp_state_stack._disp_index] = FILAMENTCHANGE_UI;
  129. }
  130. disp_state = FILAMENTCHANGE_UI;
  131. scr = lv_obj_create(NULL, NULL);
  132. lv_obj_set_style(scr, &tft_style_scr);
  133. lv_scr_load(scr);
  134. lv_obj_clean(scr);
  135. lv_obj_t * title = lv_label_create(scr, NULL);
  136. lv_obj_set_style(title, &tft_style_label_rel);
  137. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  138. lv_label_set_text(title, creat_title_text());
  139. lv_refr_now(lv_refr_get_disp_refreshing());
  140. // Create an Image button
  141. buttonIn = lv_imgbtn_create(scr, NULL);
  142. buttonOut = lv_imgbtn_create(scr, NULL);
  143. buttoType = lv_imgbtn_create(scr, NULL);
  144. buttonBack = lv_imgbtn_create(scr, NULL);
  145. lv_obj_set_event_cb_mks(buttonIn, event_handler, ID_FILAMNT_IN, NULL, 0);
  146. lv_imgbtn_set_src(buttonIn, LV_BTN_STATE_REL, "F:/bmp_in.bin");
  147. lv_imgbtn_set_src(buttonIn, LV_BTN_STATE_PR, "F:/bmp_in.bin");
  148. lv_imgbtn_set_style(buttonIn, LV_BTN_STATE_PR, &tft_style_label_pre);
  149. lv_imgbtn_set_style(buttonIn, LV_BTN_STATE_REL, &tft_style_label_rel);
  150. lv_obj_clear_protect(buttonIn, LV_PROTECT_FOLLOW);
  151. lv_obj_set_event_cb_mks(buttonOut, event_handler, ID_FILAMNT_OUT, NULL, 0);
  152. lv_imgbtn_set_src(buttonOut, LV_BTN_STATE_REL, "F:/bmp_out.bin");
  153. lv_imgbtn_set_src(buttonOut, LV_BTN_STATE_PR, "F:/bmp_out.bin");
  154. lv_imgbtn_set_style(buttonOut, LV_BTN_STATE_PR, &tft_style_label_pre);
  155. lv_imgbtn_set_style(buttonOut, LV_BTN_STATE_REL, &tft_style_label_rel);
  156. lv_obj_set_event_cb_mks(buttoType, event_handler, ID_FILAMNT_TYPE, NULL, 0);
  157. lv_imgbtn_set_style(buttoType, LV_BTN_STATE_PR, &tft_style_label_pre);
  158. lv_imgbtn_set_style(buttoType, LV_BTN_STATE_REL, &tft_style_label_rel);
  159. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_FILAMNT_RETURN, NULL, 0);
  160. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  161. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  162. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  163. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  164. lv_obj_set_pos(buttonIn, INTERVAL_V, titleHeight);
  165. lv_obj_set_pos(buttonOut, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  166. lv_obj_set_pos(buttoType, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  167. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  168. // Create labels on the image buttons
  169. lv_btn_set_layout(buttonIn, LV_LAYOUT_OFF);
  170. lv_btn_set_layout(buttonOut, LV_LAYOUT_OFF);
  171. lv_btn_set_layout(buttoType, LV_LAYOUT_OFF);
  172. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  173. lv_obj_t *labelIn = lv_label_create(buttonIn, NULL);
  174. lv_obj_t *labelOut = lv_label_create(buttonOut, NULL);
  175. labelType = lv_label_create(buttoType, NULL);
  176. lv_obj_t *label_Back = lv_label_create(buttonBack, NULL);
  177. if (gCfgItems.multiple_language != 0) {
  178. lv_label_set_text(labelIn, filament_menu.in);
  179. lv_obj_align(labelIn, buttonIn, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  180. lv_label_set_text(labelOut, filament_menu.out);
  181. lv_obj_align(labelOut, buttonOut, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  182. lv_label_set_text(label_Back, common_menu.text_back);
  183. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  184. }
  185. #if HAS_ROTARY_ENCODER
  186. if (gCfgItems.encoder_enable) {
  187. lv_group_add_obj(g, buttonIn);
  188. lv_group_add_obj(g, buttonOut);
  189. lv_group_add_obj(g, buttoType);
  190. lv_group_add_obj(g, buttonBack);
  191. }
  192. #endif
  193. disp_filament_type();
  194. tempText1 = lv_label_create(scr, NULL);
  195. lv_obj_set_style(tempText1, &tft_style_label_rel);
  196. disp_filament_temp();
  197. }
  198. void disp_filament_type() {
  199. if (uiCfg.curSprayerChoose == 1) {
  200. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru2.bin");
  201. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru2.bin");
  202. if (gCfgItems.multiple_language != 0) {
  203. lv_label_set_text(labelType, preheat_menu.ext2);
  204. lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  205. }
  206. }
  207. else {
  208. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru1.bin");
  209. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru1.bin");
  210. if (gCfgItems.multiple_language != 0) {
  211. lv_label_set_text(labelType, preheat_menu.ext1);
  212. lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  213. }
  214. }
  215. }
  216. void disp_filament_temp() {
  217. char buf[20] = {0};
  218. public_buf_l[0] = '\0';
  219. if (uiCfg.curSprayerChoose < 1)
  220. strcat(public_buf_l, preheat_menu.ext1);
  221. else
  222. strcat(public_buf_l, preheat_menu.ext2);
  223. sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target);
  224. strcat_P(public_buf_l, PSTR(": "));
  225. strcat(public_buf_l, buf);
  226. lv_label_set_text(tempText1, public_buf_l);
  227. lv_obj_align(tempText1, NULL, LV_ALIGN_CENTER, 0, -50);
  228. }
  229. void lv_clear_filament_change() {
  230. #if HAS_ROTARY_ENCODER
  231. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  232. #endif
  233. lv_obj_del(scr);
  234. }
  235. #endif // HAS_TFT_LVGL_UI