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_tmc_step_mode_settings.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 BOTH(HAS_TFT_LVGL_UI, HAS_STEALTHCHOP)
  24. #include "draw_ui.h"
  25. #include <lv_conf.h>
  26. #include "../../../module/stepper/indirection.h"
  27. #include "../../../feature/tmc_util.h"
  28. #include "../../../inc/MarlinConfig.h"
  29. #if ENABLED(EEPROM_SETTINGS)
  30. #include "../../../module/settings.h"
  31. #endif
  32. extern lv_group_t *g;
  33. static lv_obj_t *scr;
  34. enum {
  35. ID_TMC_MODE_RETURN = 1,
  36. ID_TMC_MODE_X,
  37. ID_TMC_MODE_Y,
  38. ID_TMC_MODE_Z,
  39. ID_TMC_MODE_E0,
  40. ID_TMC_MODE_E1,
  41. ID_TMC_MODE_DOWN,
  42. ID_TMC_MODE_UP
  43. };
  44. static lv_obj_t *buttonXState = nullptr, *buttonYState = nullptr, *buttonZState = nullptr, *buttonE0State = nullptr;
  45. static lv_obj_t *buttonE1State = nullptr;
  46. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  47. if (event != LV_EVENT_RELEASED) return;
  48. auto toggle_chop = [&](auto &stepper, auto &button) {
  49. const bool isena = stepper.toggle_stepping_mode();
  50. lv_screen_menu_item_onoff_update(button, isena);
  51. TERN_(EEPROM_SETTINGS, (void)settings.save());
  52. };
  53. switch (obj->mks_obj_id) {
  54. case ID_TMC_MODE_RETURN:
  55. uiCfg.para_ui_page = false;
  56. lv_clear_tmc_step_mode_settings();
  57. draw_return_ui();
  58. break;
  59. #if X_HAS_STEALTHCHOP
  60. case ID_TMC_MODE_X: toggle_chop(stepperX, buttonXState); break;
  61. #endif
  62. #if Y_HAS_STEALTHCHOP
  63. case ID_TMC_MODE_Y: toggle_chop(stepperY, buttonYState); break;
  64. #endif
  65. #if Z_HAS_STEALTHCHOP
  66. case ID_TMC_MODE_Z: toggle_chop(stepperZ, buttonZState); break;
  67. #endif
  68. #if E0_HAS_STEALTHCHOP
  69. case ID_TMC_MODE_E0: toggle_chop(stepperE0, buttonE0State); break;
  70. #endif
  71. #if E1_HAS_STEALTHCHOP
  72. case ID_TMC_MODE_E1: toggle_chop(stepperE1, buttonE1State); break;
  73. #endif
  74. case ID_TMC_MODE_UP:
  75. uiCfg.para_ui_page = false;
  76. lv_clear_tmc_step_mode_settings();
  77. lv_draw_tmc_step_mode_settings();
  78. break;
  79. case ID_TMC_MODE_DOWN:
  80. uiCfg.para_ui_page = true;
  81. lv_clear_tmc_step_mode_settings();
  82. lv_draw_tmc_step_mode_settings();
  83. break;
  84. }
  85. }
  86. void lv_draw_tmc_step_mode_settings() {
  87. buttonXState = buttonYState = buttonZState = buttonE0State = buttonE1State = nullptr;
  88. scr = lv_screen_create(TMC_MODE_UI, machine_menu.TmcStepModeConfTitle);
  89. bool stealth_X = false, stealth_Y = false, stealth_Z = false, stealth_E0 = false, stealth_E1 = false;
  90. TERN_(X_HAS_STEALTHCHOP, stealth_X = stepperX.get_stealthChop());
  91. TERN_(Y_HAS_STEALTHCHOP, stealth_Y = stepperY.get_stealthChop());
  92. TERN_(Z_HAS_STEALTHCHOP, stealth_Z = stepperZ.get_stealthChop());
  93. TERN_(E0_HAS_STEALTHCHOP, stealth_E0 = stepperE0.get_stealthChop());
  94. TERN_(E1_HAS_STEALTHCHOP, stealth_E1 = stepperE1.get_stealthChop());
  95. if (!uiCfg.para_ui_page) {
  96. buttonXState = lv_screen_menu_item_onoff(scr, machine_menu.X_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_MODE_X, 0, stealth_X);
  97. buttonYState = lv_screen_menu_item_onoff(scr, machine_menu.Y_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_TMC_MODE_Y, 1, stealth_Y);
  98. buttonZState = lv_screen_menu_item_onoff(scr, machine_menu.Z_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_TMC_MODE_Z, 2, stealth_Z);
  99. buttonE0State = lv_screen_menu_item_onoff(scr, machine_menu.E0_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_TMC_MODE_E0, 2, stealth_E0);
  100. lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_MODE_DOWN, true);
  101. }
  102. else {
  103. buttonE1State = lv_screen_menu_item_onoff(scr, machine_menu.E1_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_MODE_E1, 0, stealth_E1);
  104. lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_MODE_UP, true);
  105. }
  106. lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACK_POS_X, PARA_UI_BACK_POS_Y, event_handler, ID_TMC_MODE_RETURN, true);
  107. }
  108. void lv_clear_tmc_step_mode_settings() {
  109. #if HAS_ROTARY_ENCODER
  110. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  111. #endif
  112. lv_obj_del(scr);
  113. }
  114. #endif // HAS_TFT_LVGL_UI && HAS_STEALTHCHOP