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_motor_settings.cpp 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 "../../../../inc/MarlinConfig.h"
  27. extern lv_group_t * g;
  28. static lv_obj_t * scr;
  29. #define ID_MOTOR_RETURN 1
  30. #define ID_MOTOR_STEPS 2
  31. #define ID_MOTOR_STEPS_ARROW 3
  32. #define ID_MOTOR_TMC_CURRENT 4
  33. #define ID_MOTOR_TMC_CURRENT_ARROW 5
  34. #define ID_MOTOR_STEP_MODE 6
  35. #define ID_MOTOR_STEP_MODE_ARROW 7
  36. #define ID_HOME_SENSE 8
  37. #define ID_HOME_SENSE_ARROW 9
  38. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  39. switch (obj->mks_obj_id) {
  40. case ID_MOTOR_RETURN:
  41. if (event == LV_EVENT_CLICKED) {
  42. }
  43. else if (event == LV_EVENT_RELEASED) {
  44. lv_clear_motor_settings();
  45. draw_return_ui();
  46. }
  47. break;
  48. case ID_MOTOR_STEPS:
  49. if (event == LV_EVENT_CLICKED) {
  50. }
  51. else if (event == LV_EVENT_RELEASED) {
  52. lv_clear_motor_settings();
  53. lv_draw_step_settings();
  54. }
  55. break;
  56. case ID_MOTOR_STEPS_ARROW:
  57. if (event == LV_EVENT_CLICKED) {
  58. }
  59. else if (event == LV_EVENT_RELEASED) {
  60. lv_clear_motor_settings();
  61. lv_draw_step_settings();
  62. }
  63. break;
  64. #if USE_SENSORLESS
  65. case ID_HOME_SENSE:
  66. if (event == LV_EVENT_CLICKED) {
  67. }
  68. else if (event == LV_EVENT_RELEASED) {
  69. lv_clear_motor_settings();
  70. lv_draw_homing_sensitivity_settings();
  71. }
  72. break;
  73. case ID_HOME_SENSE_ARROW:
  74. if (event == LV_EVENT_CLICKED) {
  75. }
  76. else if (event == LV_EVENT_RELEASED) {
  77. lv_clear_motor_settings();
  78. lv_draw_homing_sensitivity_settings();
  79. }
  80. break;
  81. #endif
  82. #if HAS_TRINAMIC_CONFIG
  83. case ID_MOTOR_TMC_CURRENT:
  84. if (event == LV_EVENT_CLICKED) {
  85. }
  86. else if (event == LV_EVENT_RELEASED) {
  87. lv_clear_motor_settings();
  88. lv_draw_tmc_current_settings();
  89. }
  90. break;
  91. case ID_MOTOR_TMC_CURRENT_ARROW:
  92. if (event == LV_EVENT_CLICKED) {
  93. }
  94. else if (event == LV_EVENT_RELEASED) {
  95. lv_clear_motor_settings();
  96. lv_draw_tmc_current_settings();
  97. }
  98. break;
  99. #if HAS_STEALTHCHOP
  100. case ID_MOTOR_STEP_MODE:
  101. if (event == LV_EVENT_CLICKED) {
  102. }
  103. else if (event == LV_EVENT_RELEASED) {
  104. lv_clear_motor_settings();
  105. lv_draw_tmc_step_mode_settings();
  106. }
  107. break;
  108. case ID_MOTOR_STEP_MODE_ARROW:
  109. if (event == LV_EVENT_CLICKED) {
  110. }
  111. else if (event == LV_EVENT_RELEASED) {
  112. lv_clear_motor_settings();
  113. lv_draw_tmc_step_mode_settings();
  114. }
  115. break;
  116. #endif
  117. #endif
  118. }
  119. }
  120. void lv_draw_motor_settings(void) {
  121. lv_obj_t *buttonBack, *label_Back;
  122. lv_obj_t *buttonSteps, *labelSteps, *buttonStepsNarrow;
  123. lv_obj_t * line1;
  124. #if USE_SENSORLESS
  125. lv_obj_t *buttonSensitivity, *labelSensitivity, *buttonSensitivityNarrow;
  126. lv_obj_t * line2;
  127. #endif
  128. #if HAS_TRINAMIC_CONFIG
  129. #if USE_SENSORLESS
  130. lv_obj_t * line3;
  131. #else
  132. lv_obj_t * line2;
  133. #endif
  134. lv_obj_t *buttonTMCcurrent, *labelTMCcurrent, *buttonTMCcurrentNarrow;
  135. #if HAS_STEALTHCHOP
  136. #if USE_SENSORLESS
  137. lv_obj_t * line4;
  138. #else
  139. lv_obj_t * line3;
  140. #endif
  141. lv_obj_t *buttonStepMode, *labelStepMode, *buttonStepModeNarrow;
  142. #endif
  143. #endif
  144. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MOTOR_SETTINGS_UI) {
  145. disp_state_stack._disp_index++;
  146. disp_state_stack._disp_state[disp_state_stack._disp_index] = MOTOR_SETTINGS_UI;
  147. }
  148. disp_state = MOTOR_SETTINGS_UI;
  149. scr = lv_obj_create(NULL, NULL);
  150. lv_obj_set_style(scr, &tft_style_scr);
  151. lv_scr_load(scr);
  152. lv_obj_clean(scr);
  153. lv_obj_t * title = lv_label_create(scr, NULL);
  154. lv_obj_set_style(title, &tft_style_label_rel);
  155. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  156. lv_label_set_text(title, machine_menu.MotorConfTitle);
  157. lv_refr_now(lv_refr_get_disp_refreshing());
  158. buttonSteps = lv_btn_create(scr, NULL); /*Add a button the current screen*/
  159. lv_obj_set_pos(buttonSteps, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/
  160. lv_obj_set_size(buttonSteps, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/
  161. //lv_obj_set_event_cb(buttonMachine, event_handler);
  162. lv_obj_set_event_cb_mks(buttonSteps, event_handler, ID_MOTOR_STEPS, NULL, 0);
  163. lv_btn_set_style(buttonSteps, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/
  164. lv_btn_set_style(buttonSteps, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/
  165. lv_btn_set_layout(buttonSteps, LV_LAYOUT_OFF);
  166. labelSteps = lv_label_create(buttonSteps, NULL); /*Add a label to the button*/
  167. #if HAS_ROTARY_ENCODER
  168. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonSteps);
  169. #endif
  170. buttonStepsNarrow = lv_imgbtn_create(scr, NULL);
  171. lv_obj_set_pos(buttonStepsNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V);
  172. lv_obj_set_event_cb_mks(buttonStepsNarrow, event_handler, ID_MOTOR_STEPS_ARROW, NULL, 0);
  173. lv_imgbtn_set_src(buttonStepsNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  174. lv_imgbtn_set_src(buttonStepsNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  175. lv_imgbtn_set_style(buttonStepsNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  176. lv_imgbtn_set_style(buttonStepsNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  177. lv_btn_set_layout(buttonStepsNarrow, LV_LAYOUT_OFF);
  178. line1 = lv_line_create(scr, NULL);
  179. lv_ex_line(line1, line_points[0]);
  180. #if USE_SENSORLESS
  181. buttonSensitivity = lv_btn_create(scr, NULL); /*Add a button the current screen*/
  182. lv_obj_set_pos(buttonSensitivity, PARA_UI_POS_X, PARA_UI_POS_Y * 2); /*Set its position*/
  183. lv_obj_set_size(buttonSensitivity, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/
  184. //lv_obj_set_event_cb(buttonMachine, event_handler);
  185. lv_obj_set_event_cb_mks(buttonSensitivity, event_handler, ID_HOME_SENSE, NULL, 0);
  186. lv_btn_set_style(buttonSensitivity, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/
  187. lv_btn_set_style(buttonSensitivity, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/
  188. lv_btn_set_layout(buttonSensitivity, LV_LAYOUT_OFF);
  189. labelSensitivity = lv_label_create(buttonSensitivity, NULL); /*Add a label to the button*/
  190. #if HAS_ROTARY_ENCODER
  191. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonSensitivity);
  192. #endif
  193. buttonSensitivityNarrow = lv_imgbtn_create(scr, NULL);
  194. lv_obj_set_pos(buttonSensitivityNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V);
  195. lv_obj_set_event_cb_mks(buttonSensitivityNarrow, event_handler, ID_HOME_SENSE_ARROW, NULL, 0);
  196. lv_imgbtn_set_src(buttonSensitivityNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  197. lv_imgbtn_set_src(buttonSensitivityNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  198. lv_imgbtn_set_style(buttonSensitivityNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  199. lv_imgbtn_set_style(buttonSensitivityNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  200. lv_btn_set_layout(buttonSensitivityNarrow, LV_LAYOUT_OFF);
  201. line2 = lv_line_create(scr, NULL);
  202. lv_ex_line(line2, line_points[1]);
  203. #endif
  204. #if HAS_TRINAMIC_CONFIG
  205. buttonTMCcurrent = lv_btn_create(scr, NULL); /*Add a button the current screen*/
  206. lv_obj_set_pos(buttonTMCcurrent, PARA_UI_POS_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 3, PARA_UI_POS_Y * 2));
  207. lv_obj_set_size(buttonTMCcurrent, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/
  208. //lv_obj_set_event_cb(buttonMachine, event_handler);
  209. lv_obj_set_event_cb_mks(buttonTMCcurrent, event_handler, ID_MOTOR_TMC_CURRENT, NULL, 0);
  210. lv_btn_set_style(buttonTMCcurrent, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/
  211. lv_btn_set_style(buttonTMCcurrent, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/
  212. lv_btn_set_layout(buttonTMCcurrent, LV_LAYOUT_OFF);
  213. labelTMCcurrent = lv_label_create(buttonTMCcurrent, NULL); /*Add a label to the button*/
  214. #if HAS_ROTARY_ENCODER
  215. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonTMCcurrent);
  216. #endif
  217. buttonTMCcurrentNarrow = lv_imgbtn_create(scr, NULL);
  218. lv_obj_set_pos(buttonTMCcurrentNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 3, PARA_UI_POS_Y * 2) + PARA_UI_ARROW_V);
  219. lv_obj_set_event_cb_mks(buttonTMCcurrentNarrow, event_handler, ID_MOTOR_TMC_CURRENT_ARROW, NULL, 0);
  220. lv_imgbtn_set_src(buttonTMCcurrentNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  221. lv_imgbtn_set_src(buttonTMCcurrentNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  222. lv_imgbtn_set_style(buttonTMCcurrentNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  223. lv_imgbtn_set_style(buttonTMCcurrentNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  224. lv_btn_set_layout(buttonTMCcurrentNarrow, LV_LAYOUT_OFF);
  225. #if USE_SENSORLESS
  226. line3 = lv_line_create(scr, NULL);
  227. lv_ex_line(line3, line_points[2]);
  228. #else
  229. line2 = lv_line_create(scr, NULL);
  230. lv_ex_line(line2, line_points[1]);
  231. #endif
  232. #if HAS_STEALTHCHOP
  233. buttonStepMode = lv_btn_create(scr, NULL); /*Add a button the current screen*/
  234. lv_obj_set_pos(buttonStepMode, PARA_UI_POS_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 4, PARA_UI_POS_Y * 3));
  235. lv_obj_set_size(buttonStepMode, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/
  236. lv_obj_set_event_cb_mks(buttonStepMode, event_handler, ID_MOTOR_STEP_MODE, NULL, 0);
  237. lv_btn_set_style(buttonStepMode, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/
  238. lv_btn_set_style(buttonStepMode, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/
  239. lv_btn_set_layout(buttonStepMode, LV_LAYOUT_OFF);
  240. labelStepMode = lv_label_create(buttonStepMode, NULL); /*Add a label to the button*/
  241. #if HAS_ROTARY_ENCODER
  242. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonStepMode);
  243. #endif
  244. buttonStepModeNarrow = lv_imgbtn_create(scr, NULL);
  245. lv_obj_set_pos(buttonStepModeNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 4, PARA_UI_POS_Y * 3) + PARA_UI_ARROW_V);
  246. lv_obj_set_event_cb_mks(buttonStepModeNarrow, event_handler, ID_MOTOR_STEP_MODE_ARROW, NULL, 0);
  247. lv_imgbtn_set_src(buttonStepModeNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  248. lv_imgbtn_set_src(buttonStepModeNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  249. lv_imgbtn_set_style(buttonStepModeNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  250. lv_imgbtn_set_style(buttonStepModeNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  251. lv_btn_set_layout(buttonStepModeNarrow, LV_LAYOUT_OFF);
  252. #if USE_SENSORLESS
  253. line4 = lv_line_create(scr, NULL);
  254. lv_ex_line(line4, line_points[3]);
  255. #else
  256. line3 = lv_line_create(scr, NULL);
  257. lv_ex_line(line3, line_points[2]);
  258. #endif
  259. #endif // HAS_STEALTHCHOP
  260. #endif // HAS_TRINAMIC_CONFIG
  261. buttonBack = lv_imgbtn_create(scr, NULL);
  262. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_MOTOR_RETURN, NULL, 0);
  263. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin");
  264. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin");
  265. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  266. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  267. lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y);
  268. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  269. label_Back = lv_label_create(buttonBack, NULL);
  270. #if HAS_ROTARY_ENCODER
  271. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack);
  272. #endif
  273. if (gCfgItems.multiple_language) {
  274. lv_label_set_text(label_Back, common_menu.text_back);
  275. lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0);
  276. lv_label_set_text(labelSteps, machine_menu.StepsConf);
  277. lv_obj_align(labelSteps, buttonSteps, LV_ALIGN_IN_LEFT_MID, 0, 0);
  278. #if USE_SENSORLESS
  279. lv_label_set_text(labelSensitivity, machine_menu.HomingSensitivityConf);
  280. lv_obj_align(labelSensitivity, buttonSensitivity, LV_ALIGN_IN_LEFT_MID, 0, 0);
  281. #endif
  282. #if HAS_TRINAMIC_CONFIG
  283. lv_label_set_text(labelTMCcurrent, machine_menu.TMCcurrentConf);
  284. lv_obj_align(labelTMCcurrent, buttonTMCcurrent, LV_ALIGN_IN_LEFT_MID, 0, 0);
  285. #if HAS_STEALTHCHOP
  286. lv_label_set_text(labelStepMode, machine_menu.TMCStepModeConf);
  287. lv_obj_align(labelStepMode, buttonStepMode, LV_ALIGN_IN_LEFT_MID, 0, 0);
  288. #endif
  289. #endif
  290. }
  291. }
  292. void lv_clear_motor_settings() {
  293. #if HAS_ROTARY_ENCODER
  294. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  295. #endif
  296. lv_obj_del(scr);
  297. }
  298. #endif // HAS_TFT_LVGL_UI