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_tramming.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. //
  23. // Bed Tramming Wizard
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if BOTH(HAS_MARLINUI_MENU, ASSISTED_TRAMMING_WIZARD)
  27. #include "menu_item.h"
  28. #include "../../feature/tramming.h"
  29. #include "../../module/motion.h"
  30. #include "../../module/probe.h"
  31. #include "../../gcode/queue.h"
  32. #if ENABLED(BLTOUCH)
  33. #include "../../feature/bltouch.h"
  34. #endif
  35. //#define DEBUG_OUT 1
  36. #include "../../core/debug_out.h"
  37. static float z_measured[G35_PROBE_COUNT];
  38. static Flags<G35_PROBE_COUNT> z_isvalid;
  39. static uint8_t tram_index = 0;
  40. static int8_t reference_index; // = 0
  41. #if HAS_LEVELING
  42. #include "../../feature/bedlevel/bedlevel.h"
  43. #endif
  44. static bool probe_single_point() {
  45. do_blocking_move_to_z(TERN(BLTOUCH, Z_CLEARANCE_DEPLOY_PROBE, Z_CLEARANCE_BETWEEN_PROBES));
  46. // Stow after each point with BLTouch "HIGH SPEED" mode for push-pin safety
  47. const float z_probed_height = probe.probe_at_point(tramming_points[tram_index], TERN0(BLTOUCH, bltouch.high_speed_mode) ? PROBE_PT_STOW : PROBE_PT_RAISE, 0, true);
  48. z_measured[tram_index] = z_probed_height;
  49. if (reference_index < 0) reference_index = tram_index;
  50. move_to_tramming_wait_pos();
  51. DEBUG_ECHOLNPGM("probe_single_point(", tram_index, ") = ", z_probed_height, "mm");
  52. const bool v = !isnan(z_probed_height);
  53. z_isvalid.set(tram_index, v);
  54. return v;
  55. }
  56. static void _menu_single_probe() {
  57. DEBUG_ECHOLNPGM("Screen: single probe screen Arg:", tram_index);
  58. START_MENU();
  59. STATIC_ITEM(MSG_BED_TRAMMING, SS_LEFT);
  60. STATIC_ITEM(MSG_LAST_VALUE_SP, SS_LEFT, z_isvalid[tram_index] ? ftostr42_52(z_measured[reference_index] - z_measured[tram_index]) : "---");
  61. ACTION_ITEM(MSG_UBL_BC_INSERT2, []{ if (probe_single_point()) ui.refresh(); });
  62. ACTION_ITEM(MSG_BUTTON_DONE, ui.goto_previous_screen);
  63. END_MENU();
  64. }
  65. static void tramming_wizard_menu() {
  66. START_MENU();
  67. STATIC_ITEM(MSG_SELECT_ORIGIN);
  68. // Draw a menu item for each tramming point
  69. for (tram_index = 0; tram_index < G35_PROBE_COUNT; tram_index++)
  70. SUBMENU_F(FPSTR(pgm_read_ptr(&tramming_point_name[tram_index])), _menu_single_probe);
  71. ACTION_ITEM(MSG_BUTTON_DONE, []{
  72. probe.stow(); // Stow before exiting Tramming Wizard
  73. ui.goto_previous_screen_no_defer();
  74. });
  75. END_MENU();
  76. }
  77. // Init the wizard and enter the submenu
  78. void goto_tramming_wizard() {
  79. DEBUG_ECHOLNPGM("Screen: goto_tramming_wizard", 1);
  80. ui.defer_status_screen();
  81. // Initialize measured point flags
  82. z_isvalid.reset();
  83. reference_index = -1;
  84. // Inject G28, wait for homing to complete,
  85. set_all_unhomed();
  86. queue.inject(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR)));
  87. ui.goto_screen([]{
  88. _lcd_draw_homing();
  89. if (all_axes_homed())
  90. ui.goto_screen(tramming_wizard_menu);
  91. });
  92. }
  93. #endif // HAS_MARLINUI_MENU && ASSISTED_TRAMMING_WIZARD