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_homing_sensitivity_settings.cpp 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/MarlinConfig.h"
  23. #if HAS_TFT_LVGL_UI && USE_SENSORLESS
  24. #include "draw_ui.h"
  25. #include <lv_conf.h>
  26. #include "../../../../module/planner.h"
  27. #include "../../../../module/probe.h"
  28. #include "../../../../module/stepper/indirection.h"
  29. #include "../../../../feature/tmc_util.h"
  30. extern lv_group_t * g;
  31. static lv_obj_t * scr;
  32. #define ID_SENSITIVITY_RETURN 1
  33. #define ID_SENSITIVITY_X 2
  34. #define ID_SENSITIVITY_Y 3
  35. #define ID_SENSITIVITY_Z 4
  36. #define ID_SENSITIVITY_Z2 5
  37. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  38. switch (obj->mks_obj_id) {
  39. case ID_SENSITIVITY_RETURN:
  40. if (event == LV_EVENT_CLICKED) {
  41. }
  42. else if (event == LV_EVENT_RELEASED) {
  43. lv_clear_homing_sensitivity_settings();
  44. draw_return_ui();
  45. }
  46. break;
  47. case ID_SENSITIVITY_X:
  48. if (event == LV_EVENT_CLICKED) {
  49. }
  50. else if (event == LV_EVENT_RELEASED) {
  51. value = x_sensitivity;
  52. lv_clear_homing_sensitivity_settings();
  53. lv_draw_number_key();
  54. }
  55. break;
  56. case ID_SENSITIVITY_Y:
  57. if (event == LV_EVENT_CLICKED) {
  58. }
  59. else if (event == LV_EVENT_RELEASED) {
  60. value = y_sensitivity;
  61. lv_clear_homing_sensitivity_settings();
  62. lv_draw_number_key();
  63. }
  64. break;
  65. case ID_SENSITIVITY_Z:
  66. if (event == LV_EVENT_CLICKED) {
  67. }
  68. else if (event == LV_EVENT_RELEASED) {
  69. value = z_sensitivity;
  70. lv_clear_homing_sensitivity_settings();
  71. lv_draw_number_key();
  72. }
  73. break;
  74. #if Z2_SENSORLESS
  75. case ID_SENSITIVITY_Z2:
  76. if (event == LV_EVENT_CLICKED) {
  77. }
  78. else if (event == LV_EVENT_RELEASED) {
  79. value = z2_sensitivity;
  80. lv_clear_homing_sensitivity_settings();
  81. lv_draw_number_key();
  82. }
  83. break;
  84. #endif
  85. }
  86. }
  87. void lv_draw_homing_sensitivity_settings(void) {
  88. lv_obj_t *buttonBack = NULL, *label_Back = NULL;
  89. lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL;
  90. lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL;
  91. lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL;
  92. lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL;
  93. #if Z2_SENSORLESS
  94. lv_obj_t *labelZ2Text = NULL, *buttonZ2Value = NULL, *labelZ2Value = NULL;
  95. lv_obj_t * line4 = NULL;
  96. #endif
  97. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != HOMING_SENSITIVITY_UI) {
  98. disp_state_stack._disp_index++;
  99. disp_state_stack._disp_state[disp_state_stack._disp_index] = HOMING_SENSITIVITY_UI;
  100. }
  101. disp_state = HOMING_SENSITIVITY_UI;
  102. scr = lv_obj_create(NULL, NULL);
  103. lv_obj_set_style(scr, &tft_style_scr);
  104. lv_scr_load(scr);
  105. lv_obj_clean(scr);
  106. lv_obj_t * title = lv_label_create(scr, NULL);
  107. lv_obj_set_style(title, &tft_style_label_rel);
  108. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  109. lv_label_set_text(title, machine_menu.HomingSensitivityConfTitle);
  110. lv_refr_now(lv_refr_get_disp_refreshing());
  111. labelXText = lv_label_create(scr, NULL);
  112. lv_obj_set_style(labelXText, &tft_style_label_rel);
  113. lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10);
  114. lv_label_set_text(labelXText, machine_menu.X_Sensitivity);
  115. buttonXValue = lv_btn_create(scr, NULL);
  116. lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2);
  117. lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  118. lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_SENSITIVITY_X, NULL, 0);
  119. lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value);
  120. lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value);
  121. labelXValue = lv_label_create(buttonXValue, NULL);
  122. #if HAS_ROTARY_ENCODER
  123. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonXValue);
  124. #endif
  125. line1 = lv_line_create(scr, NULL);
  126. lv_ex_line(line1, line_points[0]);
  127. labelYText = lv_label_create(scr, NULL);
  128. lv_obj_set_style(labelYText, &tft_style_label_rel);
  129. lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10);
  130. lv_label_set_text(labelYText, machine_menu.Y_Sensitivity);
  131. buttonYValue = lv_btn_create(scr, NULL);
  132. lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2);
  133. lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  134. lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_SENSITIVITY_Y, NULL, 0);
  135. lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value);
  136. lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value);
  137. labelYValue = lv_label_create(buttonYValue, NULL);
  138. #if HAS_ROTARY_ENCODER
  139. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonYValue);
  140. #endif
  141. line2 = lv_line_create(scr, NULL);
  142. lv_ex_line(line2, line_points[1]);
  143. labelZText = lv_label_create(scr, NULL);
  144. lv_obj_set_style(labelZText, &tft_style_label_rel);
  145. lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10);
  146. lv_label_set_text(labelZText, machine_menu.Z_Sensitivity);
  147. buttonZValue = lv_btn_create(scr, NULL);
  148. lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2);
  149. lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  150. lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_SENSITIVITY_Z, NULL, 0);
  151. lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value);
  152. lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value);
  153. labelZValue = lv_label_create(buttonZValue, NULL);
  154. #if HAS_ROTARY_ENCODER
  155. if (gCfgItems.encoder_enable == true) lv_group_add_obj(g, buttonZValue);
  156. #endif
  157. line3 = lv_line_create(scr, NULL);
  158. lv_ex_line(line3, line_points[2]);
  159. #if Z2_SENSORLESS
  160. labelZ2Text = lv_label_create(scr, NULL);
  161. lv_obj_set_style(labelZ2Text, &tft_style_label_rel);
  162. lv_obj_set_pos(labelZ2Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10);
  163. lv_label_set_text(labelZ2Text, machine_menu.Z2_Sensitivity);
  164. buttonZ2Value = lv_btn_create(scr, NULL);
  165. lv_obj_set_pos(buttonZ2Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2);
  166. lv_obj_set_size(buttonZ2Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE);
  167. lv_obj_set_event_cb_mks(buttonZ2Value, event_handler, ID_SENSITIVITY_Z2, NULL, 0);
  168. lv_btn_set_style(buttonZ2Value, LV_BTN_STYLE_REL, &style_para_value);
  169. lv_btn_set_style(buttonZ2Value, LV_BTN_STYLE_PR, &style_para_value);
  170. labelZ2Value = lv_label_create(buttonZ2Value, NULL);
  171. #if HAS_ROTARY_ENCODER
  172. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonZ2Value);
  173. #endif
  174. line4 = lv_line_create(scr, NULL);
  175. lv_ex_line(line4, line_points[3]);
  176. #endif
  177. buttonBack = lv_btn_create(scr, NULL);
  178. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_SENSITIVITY_RETURN, NULL, 0);
  179. lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back);
  180. lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back);
  181. lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y);
  182. lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE);
  183. label_Back = lv_label_create(buttonBack, NULL);
  184. #if HAS_ROTARY_ENCODER
  185. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack);
  186. #endif
  187. if (gCfgItems.multiple_language) {
  188. ZERO(public_buf_l);
  189. sprintf_P(public_buf_l, PSTR("%d"), TERN(X_SENSORLESS, stepperX.homing_threshold(), 0));
  190. lv_label_set_text(labelXValue, public_buf_l);
  191. lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0);
  192. ZERO(public_buf_l);
  193. sprintf_P(public_buf_l, PSTR("%d"), TERN(Y_SENSORLESS, stepperY.homing_threshold(), 0));
  194. lv_label_set_text(labelYValue, public_buf_l);
  195. lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0);
  196. ZERO(public_buf_l);
  197. sprintf_P(public_buf_l, PSTR("%d"), TERN(Z_SENSORLESS, stepperZ.homing_threshold(), 0));
  198. lv_label_set_text(labelZValue, public_buf_l);
  199. lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0);
  200. #if Z2_SENSORLESS
  201. ZERO(public_buf_l);
  202. sprintf_P(public_buf_l, PSTR("%d"), TERN(Z2_SENSORLESS, stepperZ2.homing_threshold(), 0));
  203. lv_label_set_text(labelZ2Value, public_buf_l);
  204. lv_obj_align(labelZ2Value, buttonZ2Value, LV_ALIGN_CENTER, 0, 0);
  205. #endif
  206. lv_label_set_text(label_Back, common_menu.text_back);
  207. lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0);
  208. }
  209. }
  210. void lv_clear_homing_sensitivity_settings() {
  211. #if HAS_ROTARY_ENCODER
  212. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  213. #endif
  214. lv_obj_del(scr);
  215. }
  216. #endif // HAS_TFT_LVGL_UI && USE_SENSORLESS