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.

M420.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_LEVELING
  24. #include "../gcode.h"
  25. #include "../../feature/bedlevel/bedlevel.h"
  26. #include "../../module/planner.h"
  27. #if ENABLED(EEPROM_SETTINGS)
  28. #include "../../module/configuration_store.h"
  29. #endif
  30. /**
  31. * M420: Enable/Disable Bed Leveling and/or set the Z fade height.
  32. *
  33. * S[bool] Turns leveling on or off
  34. * Z[height] Sets the Z fade height (0 or none to disable)
  35. * V[bool] Verbose - Print the leveling grid
  36. *
  37. * With AUTO_BED_LEVELING_UBL only:
  38. *
  39. * L[index] Load UBL mesh from index (0 is default)
  40. */
  41. void GcodeSuite::M420() {
  42. #if ENABLED(AUTO_BED_LEVELING_UBL)
  43. // L to load a mesh from the EEPROM
  44. if (parser.seen('L')) {
  45. #if ENABLED(EEPROM_SETTINGS)
  46. const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.state.storage_slot;
  47. const int16_t a = settings.calc_num_meshes();
  48. if (!a) {
  49. SERIAL_PROTOCOLLNPGM("?EEPROM storage not available.");
  50. return;
  51. }
  52. if (!WITHIN(storage_slot, 0, a - 1)) {
  53. SERIAL_PROTOCOLLNPGM("?Invalid storage slot.");
  54. SERIAL_PROTOCOLLNPAIR("?Use 0 to ", a - 1);
  55. return;
  56. }
  57. settings.load_mesh(storage_slot);
  58. ubl.state.storage_slot = storage_slot;
  59. #else
  60. SERIAL_PROTOCOLLNPGM("?EEPROM storage not available.");
  61. return;
  62. #endif
  63. }
  64. // L or V display the map info
  65. if (parser.seen('L') || parser.seen('V')) {
  66. ubl.display_map(0); // Currently only supports one map type
  67. SERIAL_ECHOLNPAIR("ubl.mesh_is_valid = ", ubl.mesh_is_valid());
  68. SERIAL_ECHOLNPAIR("ubl.state.storage_slot = ", ubl.state.storage_slot);
  69. }
  70. #endif // AUTO_BED_LEVELING_UBL
  71. // V to print the matrix or mesh
  72. if (parser.seen('V')) {
  73. #if ABL_PLANAR
  74. planner.bed_level_matrix.debug(PSTR("Bed Level Correction Matrix:"));
  75. #else
  76. if (leveling_is_valid()) {
  77. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  78. print_bilinear_leveling_grid();
  79. #if ENABLED(ABL_BILINEAR_SUBDIVISION)
  80. print_bilinear_leveling_grid_virt();
  81. #endif
  82. #elif ENABLED(MESH_BED_LEVELING)
  83. SERIAL_ECHOLNPGM("Mesh Bed Level data:");
  84. mbl_mesh_report();
  85. #endif
  86. }
  87. #endif
  88. }
  89. const bool to_enable = parser.boolval('S');
  90. if (parser.seen('S'))
  91. set_bed_leveling_enabled(to_enable);
  92. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  93. if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
  94. #endif
  95. const bool new_status = leveling_is_active();
  96. if (to_enable && !new_status) {
  97. SERIAL_ERROR_START();
  98. SERIAL_ERRORLNPGM(MSG_ERR_M420_FAILED);
  99. }
  100. SERIAL_ECHO_START();
  101. SERIAL_ECHOLNPAIR("Bed Leveling ", new_status ? MSG_ON : MSG_OFF);
  102. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  103. SERIAL_ECHO_START();
  104. SERIAL_ECHOPGM("Fade Height ");
  105. if (planner.z_fade_height > 0.0)
  106. SERIAL_ECHOLN(planner.z_fade_height);
  107. else
  108. SERIAL_ECHOLNPGM(MSG_OFF);
  109. #endif
  110. }
  111. #endif // HAS_LEVELING