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. ) {
  50. lv_clear_filament_change();
  51. lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED);
  52. }
  53. else {
  54. lv_clear_filament_change();
  55. lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_HEAT);
  56. if (thermalManager.degTargetHotend(uiCfg.extruderIndex) < gCfgItems.filament_limit_temp) {
  57. thermalManager.setTargetHotend(gCfgItems.filament_limit_temp, uiCfg.extruderIndex);
  58. thermalManager.start_watching_hotend(uiCfg.extruderIndex);
  59. }
  60. }
  61. break;
  62. case ID_FILAMNT_OUT:
  63. uiCfg.filament_unload_heat_flg = true;
  64. if (thermalManager.degTargetHotend(uiCfg.extruderIndex)
  65. && (ABS(thermalManager.degTargetHotend(uiCfg.extruderIndex) - thermalManager.wholeDegHotend(uiCfg.extruderIndex)) <= 1
  66. || thermalManager.wholeDegHotend(uiCfg.extruderIndex) >= gCfgItems.filament_limit_temp)
  67. ) {
  68. lv_clear_filament_change();
  69. lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED);
  70. }
  71. else {
  72. lv_clear_filament_change();
  73. lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_HEAT);
  74. if (thermalManager.degTargetHotend(uiCfg.extruderIndex) < gCfgItems.filament_limit_temp) {
  75. thermalManager.setTargetHotend(gCfgItems.filament_limit_temp, uiCfg.extruderIndex);
  76. thermalManager.start_watching_hotend(uiCfg.extruderIndex);
  77. }
  78. filament_sprayer_temp();
  79. }
  80. break;
  81. case ID_FILAMNT_TYPE:
  82. #if HAS_MULTI_EXTRUDER
  83. uiCfg.extruderIndex = !uiCfg.extruderIndex;
  84. #endif
  85. disp_filament_type();
  86. break;
  87. case ID_FILAMNT_RETURN:
  88. #if HAS_MULTI_EXTRUDER
  89. if (uiCfg.print_state != IDLE && uiCfg.print_state != REPRINTED)
  90. gcode.process_subcommands_now(uiCfg.extruderIndexBak == 1 ? F("T1") : F("T0"));
  91. #endif
  92. feedrate_mm_s = (float)uiCfg.moveSpeed_bak;
  93. if (uiCfg.print_state == PAUSED)
  94. planner.set_e_position_mm((destination.e = current_position.e = uiCfg.current_e_position_bak));
  95. thermalManager.setTargetHotend(uiCfg.hotendTargetTempBak, uiCfg.extruderIndex);
  96. goto_previous_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. #endif
  111. 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);
  112. // Create labels on the image buttons
  113. labelType = lv_label_create_empty(buttonType);
  114. disp_filament_type();
  115. tempText1 = lv_label_create_empty(scr);
  116. lv_obj_set_style(tempText1, &tft_style_label_rel);
  117. disp_filament_temp();
  118. }
  119. void disp_filament_type() {
  120. if (uiCfg.extruderIndex == 1) {
  121. lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru2.bin");
  122. if (gCfgItems.multiple_language) {
  123. lv_label_set_text(labelType, preheat_menu.ext2);
  124. lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  125. }
  126. }
  127. else {
  128. lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru1.bin");
  129. if (gCfgItems.multiple_language) {
  130. lv_label_set_text(labelType, preheat_menu.ext1);
  131. lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  132. }
  133. }
  134. }
  135. void disp_filament_temp() {
  136. char buf[20] = {0};
  137. public_buf_l[0] = '\0';
  138. strcat(public_buf_l, uiCfg.extruderIndex < 1 ? preheat_menu.ext1 : preheat_menu.ext2);
  139. sprintf(buf, preheat_menu.value_state, thermalManager.wholeDegHotend(uiCfg.extruderIndex), thermalManager.degTargetHotend(uiCfg.extruderIndex));
  140. strcat_P(public_buf_l, PSTR(": "));
  141. strcat(public_buf_l, buf);
  142. lv_label_set_text(tempText1, public_buf_l);
  143. lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50);
  144. }
  145. void lv_clear_filament_change() {
  146. #if HAS_ROTARY_ENCODER
  147. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  148. #endif
  149. lv_obj_del(scr);
  150. }
  151. #endif // HAS_TFT_LVGL_UI