My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

meshviewer.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * DWIN Mesh Viewer
  3. * Author: Miguel A. Risco-Castillo
  4. * version: 2.5
  5. * Date: 2021/09/27
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include "../../../inc/MarlinConfigPre.h"
  22. #if BOTH(DWIN_CREALITY_LCD_ENHANCED, HAS_MESH)
  23. #include "meshviewer.h"
  24. #include "../../../core/types.h"
  25. #include "../../marlinui.h"
  26. #include "dwin_lcd.h"
  27. #include "dwinui.h"
  28. #include "dwin.h"
  29. #include "../../../feature/bedlevel/bedlevel.h"
  30. MeshViewerClass MeshViewer;
  31. void MeshViewerClass::Draw() {
  32. const int8_t mx = 30, my = 30; // Margins
  33. const int16_t stx = (DWIN_WIDTH - 2 * mx) / (GRID_MAX_POINTS_X - 1), // Steps
  34. sty = (DWIN_WIDTH - 2 * my) / (GRID_MAX_POINTS_Y - 1);
  35. int8_t zmesh[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], maxz =-127, minz = 127;
  36. #define px(xp) (mx + (xp) * stx)
  37. #define py(yp) (30 + DWIN_WIDTH - my - (yp) * sty)
  38. #define rm(z) ((((z) - minz) * 10 / _MAX(1, (maxz - minz))) + 10)
  39. #define DrawMeshValue(xp, yp, zv) DWINUI::Draw_Signed_Float(font6x12, 1, 2, px(xp) - 12, py(yp) - 6, zv)
  40. #define DrawMeshHLine(yp) DWIN_Draw_HLine(HMI_data.SplitLine_Color, px(0), py(yp), DWIN_WIDTH - 2 * mx)
  41. #define DrawMeshVLine(xp) DWIN_Draw_VLine(HMI_data.SplitLine_Color, px(xp), py(GRID_MAX_POINTS_Y - 1), DWIN_WIDTH - 2 * my)
  42. GRID_LOOP(x, y) {
  43. const float v = Z_VALUES(x,y) * 100;
  44. zmesh[x][y] = v;
  45. NOLESS(maxz, v);
  46. NOMORE(minz, v);
  47. }
  48. Title.ShowCaption(F("Mesh viewer"));
  49. DWINUI::ClearMenuArea();
  50. DWINUI::Draw_Icon(ICON_Continue_E, 86, 305);
  51. DWIN_Draw_Rectangle(0, HMI_data.SplitLine_Color, px(0), py(0), px(GRID_MAX_POINTS_X - 1), py(GRID_MAX_POINTS_Y - 1));
  52. LOOP_S_L_N(x, 1, GRID_MAX_POINTS_X - 1) DrawMeshVLine(x);
  53. LOOP_S_L_N(y, 1, GRID_MAX_POINTS_Y - 1) DrawMeshHLine(y);
  54. LOOP_L_N(y, GRID_MAX_POINTS_Y) {
  55. watchdog_refresh();
  56. LOOP_L_N(x, GRID_MAX_POINTS_X) {
  57. uint16_t color = DWINUI::RainbowInt(zmesh[x][y], _MIN(-5, minz), _MAX(5, maxz));
  58. DWINUI::Draw_FillCircle(color, px(x), py(y), rm(zmesh[x][y]));
  59. DrawMeshValue(x, y, Z_VALUES(x,y));
  60. }
  61. }
  62. char str_1[6], str_2[6] = "";
  63. ui.status_printf_P(0, PSTR("Mesh minZ: %s, maxZ: %s"),
  64. dtostrf((float)minz / 100, 1, 2, str_1),
  65. dtostrf((float)maxz / 100, 1, 2, str_2)
  66. );
  67. }
  68. #endif // DWIN_CREALITY_LCD_ENHANCED && HAS_MESH