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.

M206_M428.cpp 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. #include "../../inc/MarlinConfig.h"
  23. #if HAS_M206_COMMAND
  24. #include "../gcode.h"
  25. #include "../../module/motion.h"
  26. #include "../../lcd/ultralcd.h"
  27. #include "../../libs/buzzer.h"
  28. #include "../../Marlin.h" // for axis_homed
  29. /**
  30. * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
  31. *
  32. * *** @thinkyhead: I recommend deprecating M206 for SCARA in favor of M665.
  33. * *** M206 for SCARA will remain enabled in 1.1.x for compatibility.
  34. * *** In the 2.0 release, it will simply be disabled by default.
  35. */
  36. void GcodeSuite::M206() {
  37. LOOP_XYZ(i)
  38. if (parser.seen(axis_codes[i]))
  39. set_home_offset((AxisEnum)i, parser.value_linear_units());
  40. #if ENABLED(MORGAN_SCARA)
  41. if (parser.seen('T')) set_home_offset(A_AXIS, parser.value_float()); // Theta
  42. if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_float()); // Psi
  43. #endif
  44. report_current_position();
  45. }
  46. /**
  47. * M428: Set home_offset based on the distance between the
  48. * current_position and the nearest "reference point."
  49. * If an axis is past center its endstop position
  50. * is the reference-point. Otherwise it uses 0. This allows
  51. * the Z offset to be set near the bed when using a max endstop.
  52. *
  53. * M428 can't be used more than 2cm away from 0 or an endstop.
  54. *
  55. * Use M206 to set these values directly.
  56. */
  57. void GcodeSuite::M428() {
  58. if (axis_unhomed_error()) return;
  59. float diff[XYZ];
  60. LOOP_XYZ(i) {
  61. diff[i] = base_home_pos((AxisEnum)i) - current_position[i];
  62. if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0)
  63. diff[i] = -current_position[i];
  64. if (!WITHIN(diff[i], -20, 20)) {
  65. SERIAL_ERROR_START();
  66. SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
  67. LCD_ALERTMESSAGEPGM("Err: Too far!");
  68. BUZZ(200, 40);
  69. return;
  70. }
  71. }
  72. LOOP_XYZ(i) set_home_offset((AxisEnum)i, diff[i]);
  73. report_current_position();
  74. LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
  75. BUZZ(100, 659);
  76. BUZZ(100, 698);
  77. }
  78. #endif // HAS_M206_COMMAND