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.

M851.cpp 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "../../inc/MarlinConfig.h"
  23. #if HAS_BED_PROBE
  24. #include "../gcode.h"
  25. #include "../../feature/bedlevel/bedlevel.h"
  26. #include "../../module/probe.h"
  27. /**
  28. * M851: Set the nozzle-to-probe offsets in current units
  29. */
  30. void GcodeSuite::M851() {
  31. // Show usage with no parameters
  32. if (!parser.seen("XYZ")) {
  33. SERIAL_ECHOLNPAIR_P(
  34. #if HAS_PROBE_XY_OFFSET
  35. PSTR(STR_PROBE_OFFSET " X"), probe.offset_xy.x, SP_Y_STR, probe.offset_xy.y, SP_Z_STR
  36. #else
  37. PSTR(STR_PROBE_OFFSET " X0 Y0 Z")
  38. #endif
  39. , probe.offset.z
  40. );
  41. return;
  42. }
  43. // Start with current offsets and modify
  44. xyz_pos_t offs = probe.offset;
  45. // Assume no errors
  46. bool ok = true;
  47. if (parser.seenval('X')) {
  48. const float x = parser.value_float();
  49. #if HAS_PROBE_XY_OFFSET
  50. if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE))
  51. offs.x = x;
  52. else {
  53. SERIAL_ECHOLNPAIR("?X out of range (-", int(X_BED_SIZE), " to ", int(X_BED_SIZE), ")");
  54. ok = false;
  55. }
  56. #else
  57. if (x) SERIAL_ECHOLNPAIR("?X must be 0 (NOZZLE_AS_PROBE)."); // ...but let 'ok' stay true
  58. #endif
  59. }
  60. if (parser.seenval('Y')) {
  61. const float y = parser.value_float();
  62. #if HAS_PROBE_XY_OFFSET
  63. if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE))
  64. offs.y = y;
  65. else {
  66. SERIAL_ECHOLNPAIR("?Y out of range (-", int(Y_BED_SIZE), " to ", int(Y_BED_SIZE), ")");
  67. ok = false;
  68. }
  69. #else
  70. if (y) SERIAL_ECHOLNPAIR("?Y must be 0 (NOZZLE_AS_PROBE)."); // ...but let 'ok' stay true
  71. #endif
  72. }
  73. if (parser.seenval('Z')) {
  74. const float z = parser.value_float();
  75. if (WITHIN(z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX))
  76. offs.z = z;
  77. else {
  78. SERIAL_ECHOLNPAIR("?Z out of range (", int(Z_PROBE_OFFSET_RANGE_MIN), " to ", int(Z_PROBE_OFFSET_RANGE_MAX), ")");
  79. ok = false;
  80. }
  81. }
  82. // Save the new offsets
  83. if (ok) probe.offset = offs;
  84. }
  85. #endif // HAS_BED_PROBE