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.

menu_bed_corners.cpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // Level Bed Corners menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if HAS_LCD_MENU && ENABLED(LEVEL_BED_CORNERS)
  27. #include "menu.h"
  28. #include "../../module/motion.h"
  29. #include "../../module/planner.h"
  30. #if HAS_LEVELING
  31. #include "../../feature/bedlevel/bedlevel.h"
  32. #endif
  33. #ifndef LEVEL_CORNERS_Z_HOP
  34. #define LEVEL_CORNERS_Z_HOP 4.0
  35. #endif
  36. #ifndef LEVEL_CORNERS_HEIGHT
  37. #define LEVEL_CORNERS_HEIGHT 0.0
  38. #endif
  39. static_assert(LEVEL_CORNERS_Z_HOP >= 0, "LEVEL_CORNERS_Z_HOP must be >= 0. Please update your configuration.");
  40. #if HAS_LEVELING
  41. static bool leveling_was_active = false;
  42. #endif
  43. /**
  44. * Level corners, starting in the front-left corner.
  45. */
  46. static int8_t bed_corner;
  47. static inline void _lcd_goto_next_corner() {
  48. line_to_z(LEVEL_CORNERS_Z_HOP);
  49. switch (bed_corner) {
  50. case 0:
  51. current_position[X_AXIS] = X_MIN_BED + LEVEL_CORNERS_INSET;
  52. current_position[Y_AXIS] = Y_MIN_BED + LEVEL_CORNERS_INSET;
  53. break;
  54. case 1:
  55. current_position[X_AXIS] = X_MAX_BED - (LEVEL_CORNERS_INSET);
  56. break;
  57. case 2:
  58. current_position[Y_AXIS] = Y_MAX_BED - (LEVEL_CORNERS_INSET);
  59. break;
  60. case 3:
  61. current_position[X_AXIS] = X_MIN_BED + LEVEL_CORNERS_INSET;
  62. break;
  63. #if ENABLED(LEVEL_CENTER_TOO)
  64. case 4:
  65. current_position[X_AXIS] = X_CENTER;
  66. current_position[Y_AXIS] = Y_CENTER;
  67. break;
  68. #endif
  69. }
  70. planner.buffer_line(current_position, MMM_TO_MMS(manual_feedrate_mm_m[X_AXIS]), active_extruder);
  71. line_to_z(LEVEL_CORNERS_HEIGHT);
  72. if (++bed_corner > 3
  73. #if ENABLED(LEVEL_CENTER_TOO)
  74. + 1
  75. #endif
  76. ) bed_corner = 0;
  77. }
  78. static inline void menu_level_bed_corners() {
  79. do_select_screen(
  80. PSTR(MSG_BUTTON_NEXT), PSTR(MSG_BUTTON_DONE),
  81. _lcd_goto_next_corner,
  82. []{
  83. #if HAS_LEVELING
  84. set_bed_leveling_enabled(leveling_was_active);
  85. #endif
  86. ui.goto_previous_screen_no_defer();
  87. },
  88. PSTR(
  89. #if ENABLED(LEVEL_CENTER_TOO)
  90. MSG_LEVEL_BED_NEXT_POINT
  91. #else
  92. MSG_NEXT_CORNER
  93. #endif
  94. ), nullptr, PSTR("?")
  95. );
  96. }
  97. static inline void _lcd_level_bed_corners_homing() {
  98. _lcd_draw_homing();
  99. if (all_axes_homed()) {
  100. bed_corner = 0;
  101. ui.goto_screen(menu_level_bed_corners);
  102. ui.set_selection(true);
  103. _lcd_goto_next_corner();
  104. }
  105. }
  106. void _lcd_level_bed_corners() {
  107. ui.defer_status_screen();
  108. if (!all_axes_known()) {
  109. set_all_unhomed();
  110. queue.inject_P(PSTR("G28"));
  111. }
  112. // Disable leveling so the planner won't mess with us
  113. #if HAS_LEVELING
  114. leveling_was_active = planner.leveling_active;
  115. set_bed_leveling_enabled(false);
  116. #endif
  117. ui.goto_screen(_lcd_level_bed_corners_homing);
  118. }
  119. #endif // HAS_LCD_MENU && LEVEL_BED_CORNERS