mesh_bed_leveling.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "MarlinConfig.h"
  23. #if ENABLED(MESH_BED_LEVELING)
  24. #include "mesh_bed_leveling.h"
  25. #include "Marlin.h"
  26. #include "serial.h"
  27. mesh_bed_leveling mbl;
  28. float mesh_bed_leveling::z_offset,
  29. mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
  30. mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X],
  31. mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y];
  32. mesh_bed_leveling::mesh_bed_leveling() {
  33. for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i)
  34. index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
  35. for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i)
  36. index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
  37. reset();
  38. }
  39. void mesh_bed_leveling::reset() {
  40. z_offset = 0;
  41. ZERO(z_values);
  42. }
  43. void mesh_bed_leveling::report_mesh() {
  44. SERIAL_PROTOCOLLNPGM("Num X,Y: " STRINGIFY(GRID_MAX_POINTS_X) "," STRINGIFY(GRID_MAX_POINTS_Y));
  45. SERIAL_PROTOCOLPGM("Z offset: "); SERIAL_PROTOCOL_F(z_offset, 5);
  46. SERIAL_PROTOCOLLNPGM("\nMeasured points:");
  47. print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5,
  48. [](const uint8_t ix, const uint8_t iy) { return z_values[ix][iy]; }
  49. );
  50. }
  51. #endif // MESH_BED_LEVELING