My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

menu_probe_offset.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. // Calibrate Probe offset menu.
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if ENABLED(PROBE_OFFSET_WIZARD)
  27. #ifndef PROBE_OFFSET_START
  28. #error "PROBE_OFFSET_WIZARD requires a PROBE_OFFSET_START with a negative value."
  29. #else
  30. static_assert(PROBE_OFFSET_START < 0, "PROBE_OFFSET_START must be < 0. Please update your configuration.");
  31. #endif
  32. #include "menu_item.h"
  33. #include "menu_addon.h"
  34. #include "../../module/motion.h"
  35. #include "../../module/planner.h"
  36. #include "../../module/probe.h"
  37. #if HAS_LEVELING
  38. #include "../../feature/bedlevel/bedlevel.h"
  39. #endif
  40. // Global storage
  41. float z_offset_backup, calculated_z_offset;
  42. TERN_(HAS_LEVELING, bool leveling_was_active);
  43. void prepare_for_calibration() {
  44. z_offset_backup = probe.offset.z;
  45. // Disable soft endstops for free Z movement
  46. SET_SOFT_ENDSTOP_LOOSE(true);
  47. // Disable leveling for raw planner motion
  48. #if HAS_LEVELING
  49. leveling_was_active = planner.leveling_active;
  50. set_bed_leveling_enabled(false);
  51. #endif
  52. }
  53. void set_offset_and_go_back(const float &z) {
  54. probe.offset.z = z;
  55. SET_SOFT_ENDSTOP_LOOSE(false);
  56. TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
  57. ui.goto_previous_screen_no_defer();
  58. }
  59. void _goto_manual_move_z(const float scale) {
  60. ui.manual_move.menu_scale = scale;
  61. ui.goto_screen(lcd_move_z);
  62. }
  63. void probe_offset_wizard_menu() {
  64. START_MENU();
  65. calculated_z_offset = probe.offset.z + current_position.z;
  66. if (LCD_HEIGHT >= 4)
  67. STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
  68. STATIC_ITEM_P(PSTR("Z="), SS_CENTER, ftostr42_52(current_position.z));
  69. STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
  70. SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move_z( 1); });
  71. SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move_z( 0.1f); });
  72. if ((SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
  73. extern const char NUL_STR[];
  74. SUBMENU_P(NUL_STR, []{ _goto_manual_move_z(float(SHORT_MANUAL_Z_MOVE)); });
  75. MENU_ITEM_ADDON_START(0 + ENABLED(HAS_MARLINUI_HD44780));
  76. char tmp[20], numstr[10];
  77. // Determine digits needed right of decimal
  78. const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 :
  79. !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 100 - int((SHORT_MANUAL_Z_MOVE) * 100)) ? 3 : 2;
  80. sprintf_P(tmp, GET_TEXT(MSG_MOVE_Z_DIST), dtostrf(SHORT_MANUAL_Z_MOVE, 1, digs, numstr));
  81. lcd_put_u8str(tmp);
  82. MENU_ITEM_ADDON_END();
  83. }
  84. ACTION_ITEM(MSG_BUTTON_DONE, []{
  85. set_offset_and_go_back(calculated_z_offset);
  86. do_z_clearance(20.0
  87. #ifdef Z_AFTER_HOMING
  88. - 20.0 + Z_AFTER_HOMING
  89. #endif
  90. );
  91. });
  92. ACTION_ITEM(MSG_BUTTON_CANCEL, []{
  93. set_offset_and_go_back(z_offset_backup);
  94. });
  95. END_MENU();
  96. }
  97. void goto_probe_offset_wizard() {
  98. ui.defer_status_screen();
  99. prepare_for_calibration();
  100. probe.offset.z = PROBE_OFFSET_START;
  101. set_all_unhomed();
  102. queue.inject_P(G28_STR);
  103. ui.goto_screen([]{
  104. _lcd_draw_homing();
  105. if (all_axes_homed()) {
  106. ui.goto_screen(probe_offset_wizard_menu);
  107. ui.defer_status_screen();
  108. }
  109. });
  110. }
  111. #endif // PROBE_OFFSET_WIZARD