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

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