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.

meshviewer.cpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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. /**
  23. * DWIN Mesh Viewer
  24. * Author: Miguel A. Risco-Castillo (MRISCOC)
  25. * Version: 3.9.1
  26. * Date: 2021/11/09
  27. *
  28. * Based on the original code provided by Creality under GPL
  29. */
  30. #include "../../../inc/MarlinConfigPre.h"
  31. #if BOTH(DWIN_LCD_PROUI, HAS_MESH)
  32. #include "meshviewer.h"
  33. #include "../../../core/types.h"
  34. #include "../../marlinui.h"
  35. #include "dwin_lcd.h"
  36. #include "dwinui.h"
  37. #include "dwin.h"
  38. #include "../../../feature/bedlevel/bedlevel.h"
  39. MeshViewerClass MeshViewer;
  40. void MeshViewerClass::Draw() {
  41. const int8_t mx = 25, my = 25; // Margins
  42. const int16_t stx = (DWIN_WIDTH - 2 * mx) / (GRID_MAX_POINTS_X - 1), // Steps
  43. sty = (DWIN_WIDTH - 2 * my) / (GRID_MAX_POINTS_Y - 1);
  44. const int8_t rmax = _MIN(mx - 2, stx / 2);
  45. const int8_t rmin = 7;
  46. int16_t zmesh[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], maxz =-32000, minz = 32000;
  47. #define px(xp) (mx + (xp) * stx)
  48. #define py(yp) (30 + DWIN_WIDTH - my - (yp) * sty)
  49. #define rm(z) ((z - minz) * (rmax - rmin) / _MAX(1, (maxz - minz)) + rmin)
  50. #define DrawMeshValue(xp, yp, zv) DWINUI::Draw_Signed_Float(font6x12, 1, 2, px(xp) - 12, py(yp) - 6, zv)
  51. #define DrawMeshHLine(yp) DWIN_Draw_HLine(HMI_data.SplitLine_Color, px(0), py(yp), DWIN_WIDTH - 2 * mx)
  52. #define DrawMeshVLine(xp) DWIN_Draw_VLine(HMI_data.SplitLine_Color, px(xp), py(GRID_MAX_POINTS_Y - 1), DWIN_WIDTH - 2 * my)
  53. GRID_LOOP(x, y) {
  54. const float v = isnan(Z_VALUES(x,y)) ? 0 : round(Z_VALUES(x,y) * 100);
  55. zmesh[x][y] = v;
  56. NOLESS(maxz, v);
  57. NOMORE(minz, v);
  58. }
  59. Title.ShowCaption(F("Mesh Viewer"));
  60. DWINUI::ClearMenuArea();
  61. DWINUI::Draw_Icon(ICON_Continue_E, 86, 305);
  62. DWIN_Draw_Rectangle(0, HMI_data.SplitLine_Color, px(0), py(0), px(GRID_MAX_POINTS_X - 1), py(GRID_MAX_POINTS_Y - 1));
  63. LOOP_S_L_N(x, 1, GRID_MAX_POINTS_X - 1) DrawMeshVLine(x);
  64. LOOP_S_L_N(y, 1, GRID_MAX_POINTS_Y - 1) DrawMeshHLine(y);
  65. LOOP_L_N(y, GRID_MAX_POINTS_Y) {
  66. watchdog_refresh();
  67. LOOP_L_N(x, GRID_MAX_POINTS_X) {
  68. uint16_t color = DWINUI::RainbowInt(zmesh[x][y], _MIN(-5, minz), _MAX(5, maxz));
  69. uint8_t radius = rm(zmesh[x][y]);
  70. DWINUI::Draw_FillCircle(color, px(x), py(y), radius);
  71. if (GRID_MAX_POINTS_X < 9)
  72. DWINUI::Draw_Signed_Float(font6x12, 1, 2, px(x) - 12, py(y) - 6, Z_VALUES(x,y));
  73. else {
  74. char str_1[9];
  75. str_1[0] = 0;
  76. switch (zmesh[x][y]) {
  77. case -999 ... -100:
  78. DWINUI::Draw_Signed_Float(font6x12, 1, 1, px(x) - 12, py(y) - 6, Z_VALUES(x,y));
  79. break;
  80. case -99 ... -1:
  81. sprintf_P(str_1, PSTR("-.%02i"), -zmesh[x][y]);
  82. break;
  83. case 0:
  84. DWIN_Draw_String(false, font6x12, DWINUI::textcolor, DWINUI::backcolor, px(x) - 4, py(y) - 6, "0");;
  85. break;
  86. case 1 ... 99:
  87. sprintf_P(str_1, PSTR(".%02i"), zmesh[x][y]);
  88. break;
  89. case 100 ... 999:
  90. DWINUI::Draw_Signed_Float(font6x12, 1, 1, px(x) - 12, py(y) - 6, Z_VALUES(x,y));
  91. break;
  92. }
  93. if (str_1[0])
  94. DWIN_Draw_String(false, font6x12, DWINUI::textcolor, DWINUI::backcolor, px(x) - 12, py(y) - 6, str_1);
  95. }
  96. }
  97. }
  98. char str_1[6], str_2[6] = "";
  99. ui.status_printf(0, F("Mesh minZ: %s, maxZ: %s"),
  100. dtostrf((float)minz / 100, 1, 2, str_1),
  101. dtostrf((float)maxz / 100, 1, 2, str_2)
  102. );
  103. }
  104. #endif // DWIN_LCD_PROUI && HAS_MESH