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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // Level Bed Corners menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if BOTH(HAS_LCD_MENU, 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. constexpr float lfrb[4] = LEVEL_CORNERS_INSET_LFRB;
  49. constexpr xy_pos_t lf { (X_MIN_BED) + lfrb[0], (Y_MIN_BED) + lfrb[1] },
  50. rb { (X_MAX_BED) - lfrb[2], (Y_MAX_BED) - lfrb[3] };
  51. line_to_z(LEVEL_CORNERS_Z_HOP);
  52. switch (bed_corner) {
  53. case 0: current_position = lf; break; // copy xy
  54. case 1: current_position.x = rb.x; break;
  55. case 2: current_position.y = rb.y; break;
  56. case 3: current_position.x = lf.x; break;
  57. #if ENABLED(LEVEL_CENTER_TOO)
  58. case 4: current_position.set(X_CENTER, Y_CENTER); break;
  59. #endif
  60. }
  61. line_to_current_position(manual_feedrate_mm_s.x);
  62. line_to_z(LEVEL_CORNERS_HEIGHT);
  63. if (++bed_corner > 3 + ENABLED(LEVEL_CENTER_TOO)) bed_corner = 0;
  64. }
  65. static inline void _lcd_level_bed_corners_homing() {
  66. _lcd_draw_homing();
  67. if (all_axes_homed()) {
  68. bed_corner = 0;
  69. ui.goto_screen([]{
  70. MenuItem_confirm::select_screen(
  71. GET_TEXT(MSG_BUTTON_NEXT), GET_TEXT(MSG_BUTTON_DONE),
  72. _lcd_goto_next_corner,
  73. []{
  74. TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
  75. ui.goto_previous_screen_no_defer();
  76. },
  77. GET_TEXT(
  78. #if ENABLED(LEVEL_CENTER_TOO)
  79. MSG_LEVEL_BED_NEXT_POINT
  80. #else
  81. MSG_NEXT_CORNER
  82. #endif
  83. ), (PGM_P)nullptr, PSTR("?")
  84. );
  85. });
  86. ui.set_selection(true);
  87. _lcd_goto_next_corner();
  88. }
  89. }
  90. void _lcd_level_bed_corners() {
  91. ui.defer_status_screen();
  92. if (!all_axes_known()) {
  93. set_all_unhomed();
  94. queue.inject_P(G28_STR);
  95. }
  96. // Disable leveling so the planner won't mess with us
  97. #if HAS_LEVELING
  98. leveling_was_active = planner.leveling_active;
  99. set_bed_leveling_enabled(false);
  100. #endif
  101. ui.goto_screen(_lcd_level_bed_corners_homing);
  102. }
  103. #endif // HAS_LCD_MENU && LEVEL_BED_CORNERS