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 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 *buttonType;
  34. static lv_obj_t *labelType;
  35. static lv_obj_t *tempText1;
  36. enum {
  37. ID_FILAMNT_IN = 1,
  38. ID_FILAMNT_OUT,
  39. ID_FILAMNT_TYPE,
  40. ID_FILAMNT_RETURN
  41. };
  42. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  43. if (event != LV_EVENT_RELEASED) return;
  44. switch (obj->mks_obj_id) {
  45. case ID_FILAMNT_IN:
  46. uiCfg.filament_load_heat_flg = true;
  47. if (abs(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.wholeDegHotend(uiCfg.extruderIndex)) <= 1
  48. || gCfgItems.filament_limit_temp <= thermalManager.wholeDegHotend(uiCfg.extruderIndex)) {
  49. lv_clear_filament_change();
  50. lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED);
  51. }
  52. else {
  53. lv_clear_filament_change();
  54. lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_HEAT);
  55. if (thermalManager.degTargetHotend(uiCfg.extruderIndex) < gCfgItems.filament_limit_temp) {
  56. thermalManager.setTargetHotend(gCfgItems.filament_limit_temp, uiCfg.extruderIndex);
  57. thermalManager.start_watching_hotend(uiCfg.extruderIndex);
  58. }
  59. }
  60. break;
  61. case ID_FILAMNT_OUT:
  62. uiCfg.filament_unload_heat_flg = true;
  63. if (thermalManager.degTargetHotend(uiCfg.extruderIndex)
  64. && (abs(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.wholeDegHotend(uiCfg.extruderIndex)) <= 1
  65. || thermalManager.wholeDegHotend(uiCfg.extruderIndex) >= gCfgItems.filament_limit_temp)
  66. ) {
  67. lv_clear_filament_change();
  68. lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED);
  69. }
  70. else {
  71. lv_clear_filament_change();
  72. lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_HEAT);
  73. if (thermalManager.degTargetHotend(uiCfg.extruderIndex) < gCfgItems.filament_limit_temp) {
  74. thermalManager.setTargetHotend(gCfgItems.filament_limit_temp, uiCfg.extruderIndex);
  75. thermalManager.start_watching_hotend(uiCfg.extruderIndex);
  76. }
  77. filament_sprayer_temp();
  78. }
  79. break;
  80. case ID_FILAMNT_TYPE:
  81. #if HAS_MULTI_EXTRUDER
  82. uiCfg.extruderIndex = !uiCfg.extruderIndex;
  83. #endif
  84. disp_filament_type();
  85. break;
  86. case ID_FILAMNT_RETURN:
  87. #if HAS_MULTI_EXTRUDER
  88. if (uiCfg.print_state != IDLE && uiCfg.print_state != REPRINTED)
  89. gcode.process_subcommands_now_P(uiCfg.extruderIndexBak == 1 ? PSTR("T1") : PSTR("T0"));
  90. #endif
  91. feedrate_mm_s = (float)uiCfg.moveSpeed_bak;
  92. if (uiCfg.print_state == PAUSED)
  93. planner.set_e_position_mm((destination.e = current_position.e = uiCfg.current_e_position_bak));
  94. thermalManager.setTargetHotend(uiCfg.hotendTargetTempBak, uiCfg.extruderIndex);
  95. clear_cur_ui();
  96. draw_return_ui();
  97. break;
  98. }
  99. }
  100. void lv_draw_filament_change() {
  101. scr = lv_screen_create(FILAMENTCHANGE_UI);
  102. // Create an Image button
  103. lv_obj_t *buttonIn = lv_big_button_create(scr, "F:/bmp_in.bin", filament_menu.in, INTERVAL_V, titleHeight, event_handler, ID_FILAMNT_IN);
  104. lv_obj_clear_protect(buttonIn, LV_PROTECT_FOLLOW);
  105. lv_big_button_create(scr, "F:/bmp_out.bin", filament_menu.out, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_FILAMNT_OUT);
  106. buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_TYPE);
  107. #if HAS_ROTARY_ENCODER
  108. if (gCfgItems.encoder_enable) {
  109. lv_group_add_obj(g, buttonType);
  110. }
  111. #endif
  112. lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_RETURN);
  113. // Create labels on the image buttons
  114. labelType = lv_label_create_empty(buttonType);
  115. disp_filament_type();
  116. tempText1 = lv_label_create_empty(scr);
  117. lv_obj_set_style(tempText1, &tft_style_label_rel);
  118. disp_filament_temp();
  119. }
  120. void disp_filament_type() {
  121. if (uiCfg.extruderIndex == 1) {
  122. lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru2.bin");
  123. if (gCfgItems.multiple_language) {
  124. lv_label_set_text(labelType, preheat_menu.ext2);
  125. lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  126. }
  127. }
  128. else {
  129. lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru1.bin");
  130. if (gCfgItems.multiple_language) {
  131. lv_label_set_text(labelType, preheat_menu.ext1);
  132. lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  133. }
  134. }
  135. }
  136. void disp_filament_temp() {
  137. char buf[20] = {0};
  138. public_buf_l[0] = '\0';
  139. strcat(public_buf_l, uiCfg.extruderIndex < 1 ? preheat_menu.ext1 : preheat_menu.ext2);
  140. sprintf(buf, preheat_menu.value_state, thermalManager.wholeDegHotend(uiCfg.extruderIndex), thermalManager.degTargetHotend(uiCfg.extruderIndex));
  141. strcat_P(public_buf_l, PSTR(": "));
  142. strcat(public_buf_l, buf);
  143. lv_label_set_text(tempText1, public_buf_l);
  144. lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50);
  145. }
  146. void lv_clear_filament_change() {
  147. #if HAS_ROTARY_ENCODER
  148. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  149. #endif
  150. lv_obj_del(scr);
  151. }
  152. #endif // HAS_TFT_LVGL_UI