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

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