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_change_speed.cpp 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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/planner.h"
  27. #include "../../../inc/MarlinConfig.h"
  28. extern lv_group_t *g;
  29. static lv_obj_t *scr;
  30. static lv_obj_t *labelStep, *buttonStep, *buttonMov, *buttonExt;
  31. static lv_obj_t *labelMov, *labelExt;
  32. static lv_obj_t *printSpeedText;
  33. enum {
  34. ID_C_ADD = 1,
  35. ID_C_DEC,
  36. ID_C_MOVE,
  37. ID_C_EXT,
  38. ID_C_STEP,
  39. ID_C_RETURN
  40. };
  41. static bool editingFlowrate;
  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_C_ADD:
  46. if (!editingFlowrate) {
  47. if (feedrate_percentage < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed)
  48. feedrate_percentage += uiCfg.stepPrintSpeed;
  49. else
  50. feedrate_percentage = MAX_EXT_SPEED_PERCENT;
  51. }
  52. else {
  53. if (planner.flow_percentage[0] < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed)
  54. planner.flow_percentage[0] += uiCfg.stepPrintSpeed;
  55. else
  56. planner.flow_percentage[0] = MAX_EXT_SPEED_PERCENT;
  57. planner.refresh_e_factor(0);
  58. #if HAS_MULTI_EXTRUDER
  59. planner.flow_percentage[1] = planner.flow_percentage[0];
  60. planner.refresh_e_factor(1);
  61. #endif
  62. }
  63. disp_print_speed();
  64. break;
  65. case ID_C_DEC:
  66. if (!editingFlowrate) {
  67. if (feedrate_percentage > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed)
  68. feedrate_percentage -= uiCfg.stepPrintSpeed;
  69. else
  70. feedrate_percentage = MIN_EXT_SPEED_PERCENT;
  71. }
  72. else {
  73. if (planner.flow_percentage[0] > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed)
  74. planner.flow_percentage[0] -= uiCfg.stepPrintSpeed;
  75. else
  76. planner.flow_percentage[0] = MIN_EXT_SPEED_PERCENT;
  77. planner.refresh_e_factor(0);
  78. #if HAS_MULTI_EXTRUDER
  79. planner.flow_percentage[1] = planner.flow_percentage[0];
  80. planner.refresh_e_factor(1);
  81. #endif
  82. }
  83. disp_print_speed();
  84. break;
  85. case ID_C_MOVE:
  86. editingFlowrate = false;
  87. disp_speed_type();
  88. disp_print_speed();
  89. break;
  90. case ID_C_EXT:
  91. editingFlowrate = true;
  92. disp_speed_type();
  93. disp_print_speed();
  94. break;
  95. case ID_C_STEP:
  96. if (uiCfg.stepPrintSpeed == 1)
  97. uiCfg.stepPrintSpeed = 5;
  98. else if (uiCfg.stepPrintSpeed == 5)
  99. uiCfg.stepPrintSpeed = 10;
  100. else
  101. uiCfg.stepPrintSpeed = 1;
  102. disp_speed_step();
  103. break;
  104. case ID_C_RETURN:
  105. goto_previous_ui();
  106. break;
  107. }
  108. }
  109. void lv_draw_change_speed() {
  110. scr = lv_screen_create(CHANGE_SPEED_UI);
  111. // Create an Image button
  112. lv_big_button_create(scr, "F:/bmp_Add.bin", speed_menu.add, INTERVAL_V, titleHeight, event_handler, ID_C_ADD);
  113. lv_big_button_create(scr, "F:/bmp_Dec.bin", speed_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_C_DEC);
  114. buttonMov = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_MOVE);
  115. buttonExt = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_EXT);
  116. buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_STEP);
  117. #if HAS_ROTARY_ENCODER
  118. if (gCfgItems.encoder_enable) {
  119. lv_group_add_obj(g, buttonMov);
  120. lv_group_add_obj(g, buttonExt);
  121. lv_group_add_obj(g, buttonStep);
  122. }
  123. #endif
  124. 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_C_RETURN);
  125. // Create labels on the image buttons
  126. labelMov = lv_label_create_empty(buttonMov);
  127. labelExt = lv_label_create_empty(buttonExt);
  128. labelStep = lv_label_create_empty(buttonStep);
  129. #if HAS_ROTARY_ENCODER
  130. if (gCfgItems.encoder_enable) {
  131. lv_group_add_obj(g, buttonMov);
  132. lv_group_add_obj(g, buttonExt);
  133. lv_group_add_obj(g, buttonStep);
  134. }
  135. #endif
  136. disp_speed_type();
  137. disp_speed_step();
  138. printSpeedText = lv_label_create_empty(scr);
  139. lv_obj_set_style(printSpeedText, &tft_style_label_rel);
  140. disp_print_speed();
  141. }
  142. void disp_speed_step() {
  143. if (uiCfg.stepPrintSpeed == 1)
  144. lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step1_percent.bin");
  145. else if (uiCfg.stepPrintSpeed == 5)
  146. lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step5_percent.bin");
  147. else if (uiCfg.stepPrintSpeed == 10)
  148. lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step10_percent.bin");
  149. if (gCfgItems.multiple_language) {
  150. if (uiCfg.stepPrintSpeed == 1) {
  151. lv_label_set_text(labelStep, speed_menu.step_1percent);
  152. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  153. }
  154. else if (uiCfg.stepPrintSpeed == 5) {
  155. lv_label_set_text(labelStep, speed_menu.step_5percent);
  156. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  157. }
  158. else if (uiCfg.stepPrintSpeed == 10) {
  159. lv_label_set_text(labelStep, speed_menu.step_10percent);
  160. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  161. }
  162. }
  163. }
  164. void disp_print_speed() {
  165. char buf[30] = { 0 };
  166. public_buf_l[0] = '\0';
  167. int16_t val;
  168. const char *lbl;
  169. if (editingFlowrate) {
  170. lbl = speed_menu.extrude_speed;
  171. val = planner.flow_percentage[0];
  172. }
  173. else {
  174. lbl = speed_menu.move_speed;
  175. val = feedrate_percentage;
  176. }
  177. strcpy(public_buf_l, lbl);
  178. strcat_P(public_buf_l, PSTR(": "));
  179. sprintf_P(buf, PSTR("%d%%"), val);
  180. strcat(public_buf_l, buf);
  181. lv_label_set_text(printSpeedText, public_buf_l);
  182. lv_obj_align(printSpeedText, nullptr, LV_ALIGN_CENTER, 0, -65);
  183. }
  184. void disp_speed_type() {
  185. lv_imgbtn_set_src_both(buttonMov, editingFlowrate ? "F:/bmp_mov_changeSpeed.bin" : "F:/bmp_mov_sel.bin");
  186. lv_imgbtn_set_src_both(buttonExt, editingFlowrate ? "F:/bmp_extruct_sel.bin" : "F:/bmp_speed_extruct.bin");
  187. lv_obj_refresh_ext_draw_pad(buttonExt);
  188. lv_obj_refresh_ext_draw_pad(buttonMov);
  189. if (gCfgItems.multiple_language) {
  190. lv_label_set_text(labelMov, speed_menu.move);
  191. lv_obj_align(labelMov, buttonMov, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  192. lv_label_set_text(labelExt, speed_menu.extrude);
  193. lv_obj_align(labelExt, buttonExt, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  194. }
  195. }
  196. void lv_clear_change_speed() {
  197. #if HAS_ROTARY_ENCODER
  198. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  199. #endif
  200. lv_obj_del(scr);
  201. }
  202. #endif // HAS_TFT_LVGL_UI