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_move_motor.cpp 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 "../../../../gcode/queue.h"
  27. #include "../../../../module/motion.h"
  28. #include "../../../../inc/MarlinConfig.h"
  29. extern lv_group_t *g;
  30. static lv_obj_t *scr;
  31. static lv_obj_t *labelV, *buttonV, *labelP;
  32. static lv_task_t *updatePosTask;
  33. static char cur_label = 'Z';
  34. static float cur_pos = 0;
  35. void disp_cur_pos();
  36. enum {
  37. ID_M_X_P = 1,
  38. ID_M_X_N,
  39. ID_M_Y_P,
  40. ID_M_Y_N,
  41. ID_M_Z_P,
  42. ID_M_Z_N,
  43. ID_M_STEP,
  44. ID_M_RETURN
  45. };
  46. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  47. char str_1[16];
  48. if (event != LV_EVENT_RELEASED) return;
  49. if (!queue.ring_buffer.full(3)) {
  50. bool do_inject = true;
  51. float dist = uiCfg.move_dist;
  52. switch (obj->mks_obj_id) {
  53. case ID_M_X_N: dist *= -1; case ID_M_X_P: cur_label = 'X'; break;
  54. case ID_M_Y_N: dist *= -1; case ID_M_Y_P: cur_label = 'Y'; break;
  55. case ID_M_Z_N: dist *= -1; case ID_M_Z_P: cur_label = 'Z'; break;
  56. default: do_inject = false;
  57. }
  58. if (do_inject) {
  59. sprintf_P(public_buf_l, PSTR("G91\nG1 %c%s F%d\nG90"), cur_label, dtostrf(dist, 1, 3, str_1), uiCfg.moveSpeed);
  60. queue.inject(public_buf_l);
  61. }
  62. }
  63. switch (obj->mks_obj_id) {
  64. case ID_M_STEP:
  65. if (abs(10 * (int)uiCfg.move_dist) == 100)
  66. uiCfg.move_dist = 0.1;
  67. else
  68. uiCfg.move_dist *= 10.0f;
  69. disp_move_dist();
  70. break;
  71. case ID_M_RETURN:
  72. clear_cur_ui();
  73. draw_return_ui();
  74. return;
  75. }
  76. disp_cur_pos();
  77. }
  78. void refresh_pos(lv_task_t *) {
  79. switch (cur_label) {
  80. case 'X': cur_pos = current_position.x; break;
  81. case 'Y': cur_pos = current_position.y; break;
  82. case 'Z': cur_pos = current_position.z; break;
  83. default: return;
  84. }
  85. disp_cur_pos();
  86. }
  87. void lv_draw_move_motor() {
  88. scr = lv_screen_create(MOVE_MOTOR_UI);
  89. lv_obj_t *buttonXI = lv_big_button_create(scr, "F:/bmp_xAdd.bin", move_menu.x_add, INTERVAL_V, titleHeight, event_handler, ID_M_X_P);
  90. lv_obj_clear_protect(buttonXI, LV_PROTECT_FOLLOW);
  91. lv_big_button_create(scr, "F:/bmp_xDec.bin", move_menu.x_dec, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_X_N);
  92. lv_big_button_create(scr, "F:/bmp_yAdd.bin", move_menu.y_add, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_M_Y_P);
  93. lv_big_button_create(scr, "F:/bmp_yDec.bin", move_menu.y_dec, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Y_N);
  94. lv_big_button_create(scr, "F:/bmp_zAdd.bin", move_menu.z_add, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_M_Z_P);
  95. lv_big_button_create(scr, "F:/bmp_zDec.bin", move_menu.z_dec, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Z_N);
  96. // button with image and label changed dynamically by disp_move_dist
  97. buttonV = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_M_STEP);
  98. labelV = lv_label_create_empty(buttonV);
  99. #if HAS_ROTARY_ENCODER
  100. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonV);
  101. #endif
  102. 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_M_RETURN);
  103. // We need to patch the title to leave some space on the right for displaying the status
  104. lv_obj_t * title = lv_obj_get_child_back(scr, NULL);
  105. if (title != NULL) lv_obj_set_width(title, TFT_WIDTH - 101);
  106. labelP = lv_label_create(scr, TFT_WIDTH - 100, TITLE_YPOS, "Z:0.0mm");
  107. if (labelP != NULL)
  108. updatePosTask = lv_task_create(refresh_pos, 300, LV_TASK_PRIO_LOWEST, 0);
  109. disp_move_dist();
  110. disp_cur_pos();
  111. }
  112. void disp_cur_pos() {
  113. char str_1[16];
  114. sprintf_P(public_buf_l, PSTR("%c:%s mm"), cur_label, dtostrf(cur_pos, 1, 1, str_1));
  115. if (labelP) lv_label_set_text(labelP, public_buf_l);
  116. }
  117. void disp_move_dist() {
  118. if ((int)(10 * uiCfg.move_dist) == 1)
  119. lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move0_1.bin");
  120. else if ((int)(10 * uiCfg.move_dist) == 10)
  121. lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move1.bin");
  122. else if ((int)(10 * uiCfg.move_dist) == 100)
  123. lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move10.bin");
  124. if (gCfgItems.multiple_language) {
  125. if ((int)(10 * uiCfg.move_dist) == 1) {
  126. lv_label_set_text(labelV, move_menu.step_01mm);
  127. lv_obj_align(labelV, buttonV, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  128. }
  129. else if ((int)(10 * uiCfg.move_dist) == 10) {
  130. lv_label_set_text(labelV, move_menu.step_1mm);
  131. lv_obj_align(labelV, buttonV, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  132. }
  133. else if ((int)(10 * uiCfg.move_dist) == 100) {
  134. lv_label_set_text(labelV, move_menu.step_10mm);
  135. lv_obj_align(labelV, buttonV, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  136. }
  137. }
  138. }
  139. void lv_clear_move_motor() {
  140. #if HAS_ROTARY_ENCODER
  141. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  142. #endif
  143. lv_task_del(updatePosTask);
  144. lv_obj_del(scr);
  145. }
  146. #endif // HAS_TFT_LVGL_UI