My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

meshviewer.cpp 4.1KB

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