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.

M421.cpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * unified.cpp - Unified Bed Leveling
  24. */
  25. #include "../../../inc/MarlinConfig.h"
  26. #if ENABLED(AUTO_BED_LEVELING_UBL)
  27. #include "../../gcode.h"
  28. #include "../../../feature/bedlevel/bedlevel.h"
  29. /**
  30. * M421: Set a single Mesh Bed Leveling Z coordinate
  31. *
  32. * Usage:
  33. * M421 I<xindex> J<yindex> Z<linear>
  34. * M421 I<xindex> J<yindex> Q<offset>
  35. * M421 I<xindex> J<yindex> N
  36. * M421 C Z<linear>
  37. * M421 C Q<offset>
  38. */
  39. void GcodeSuite::M421() {
  40. int8_t ix = parser.intval('I', -1), iy = parser.intval('J', -1);
  41. const bool hasI = ix >= 0,
  42. hasJ = iy >= 0,
  43. hasC = parser.seen('C'),
  44. hasN = parser.seen('N'),
  45. hasZ = parser.seen('Z'),
  46. hasQ = !hasZ && parser.seen('Q');
  47. if (hasC) {
  48. const mesh_index_pair location = ubl.find_closest_mesh_point_of_type(REAL, current_position[X_AXIS], current_position[Y_AXIS], USE_NOZZLE_AS_REFERENCE, NULL);
  49. ix = location.x_index;
  50. iy = location.y_index;
  51. }
  52. if (int(hasC) + int(hasI && hasJ) != 1 || !(hasZ || hasQ || hasN))
  53. SERIAL_ERROR_MSG(MSG_ERR_M421_PARAMETERS);
  54. else if (!WITHIN(ix, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(iy, 0, GRID_MAX_POINTS_Y - 1))
  55. SERIAL_ERROR_MSG(MSG_ERR_MESH_XY);
  56. else {
  57. ubl.z_values[ix][iy] = hasN ? NAN : parser.value_linear_units() + (hasQ ? ubl.z_values[ix][iy] : 0);
  58. #if ENABLED(EXTENSIBLE_UI)
  59. ExtUI::onMeshUpdate(ix, iy, ubl.z_values[ix][iy]);
  60. #endif
  61. }
  62. }
  63. #endif // AUTO_BED_LEVELING_UBL