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

meshviewer.cpp 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. * Mesh Viewer for PRO UI
  24. * Author: Miguel A. Risco-Castillo (MRISCOC)
  25. * version: 3.12.1
  26. * Date: 2022/02/24
  27. */
  28. #include "../../../inc/MarlinConfigPre.h"
  29. #if BOTH(DWIN_LCD_PROUI, 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 "dwin_popup.h"
  37. #include "../../../feature/bedlevel/bedlevel.h"
  38. MeshViewerClass MeshViewer;
  39. void MeshViewerClass::DrawMesh(bed_mesh_t zval, const uint8_t sizex, const uint8_t sizey) {
  40. const int8_t mx = 25, my = 25; // Margins
  41. const int16_t stx = (DWIN_WIDTH - 2 * mx) / (sizex - 1), // Steps
  42. sty = (DWIN_WIDTH - 2 * my) / (sizey - 1);
  43. const int8_t rmax = _MIN(mx - 2, stx / 2);
  44. const int8_t rmin = 7;
  45. int16_t zmesh[sizex][sizey];
  46. #define px(xp) (mx + (xp) * stx)
  47. #define py(yp) (30 + DWIN_WIDTH - my - (yp) * sty)
  48. #define rm(z) ((z - minz) * (rmax - rmin) / _MAX(1, (maxz - minz)) + rmin)
  49. #define DrawMeshValue(xp, yp, zv) DWINUI::Draw_Signed_Float(font6x12, 1, 2, px(xp) - 18, py(yp) - 6, zv)
  50. #define DrawMeshHLine(yp) DWIN_Draw_HLine(HMI_data.SplitLine_Color, px(0), py(yp), DWIN_WIDTH - 2 * mx)
  51. #define DrawMeshVLine(xp) DWIN_Draw_VLine(HMI_data.SplitLine_Color, px(xp), py(sizey - 1), DWIN_WIDTH - 2 * my)
  52. int16_t maxz =-32000; int16_t minz = 32000; avg = 0;
  53. LOOP_L_N(y, sizey) LOOP_L_N(x, sizex) {
  54. const float v = isnan(zval[x][y]) ? 0 : round(zval[x][y] * 100);
  55. zmesh[x][y] = v;
  56. avg += v;
  57. NOLESS(maxz, v);
  58. NOMORE(minz, v);
  59. }
  60. max = (float)maxz / 100;
  61. min = (float)minz / 100;
  62. avg = avg / (100 * sizex * sizey);
  63. DWINUI::ClearMainArea();
  64. DWIN_Draw_Rectangle(0, HMI_data.SplitLine_Color, px(0), py(0), px(sizex - 1), py(sizey - 1));
  65. LOOP_S_L_N(x, 1, sizex - 1) DrawMeshVLine(x);
  66. LOOP_S_L_N(y, 1, sizey - 1) DrawMeshHLine(y);
  67. LOOP_L_N(y, sizey) {
  68. watchdog_refresh();
  69. LOOP_L_N(x, sizex) {
  70. uint16_t color = DWINUI::RainbowInt(zmesh[x][y], _MIN(-5, minz), _MAX(5, maxz));
  71. uint8_t radius = rm(zmesh[x][y]);
  72. DWINUI::Draw_FillCircle(color, px(x), py(y), radius);
  73. if (sizex < 9)
  74. DWINUI::Draw_Signed_Float(font6x12, 1, 2, px(x) - 18, py(y) - 6, zval[x][y]);
  75. else {
  76. char str_1[9];
  77. str_1[0] = 0;
  78. switch (zmesh[x][y]) {
  79. case -999 ... -100:
  80. DWINUI::Draw_Signed_Float(font6x12, 1, 1, px(x) - 18, py(y) - 6, zval[x][y]);
  81. break;
  82. case -99 ... -1:
  83. sprintf_P(str_1, PSTR("-.%02i"), -zmesh[x][y]);
  84. break;
  85. case 0:
  86. DWIN_Draw_String(false, font6x12, DWINUI::textcolor, DWINUI::backcolor, px(x) - 4, py(y) - 6, "0");
  87. break;
  88. case 1 ... 99:
  89. sprintf_P(str_1, PSTR(".%02i"), zmesh[x][y]);
  90. break;
  91. case 100 ... 999:
  92. DWINUI::Draw_Signed_Float(font6x12, 1, 1, px(x) - 18, py(y) - 6, zval[x][y]);
  93. break;
  94. }
  95. if (str_1[0])
  96. DWIN_Draw_String(false, font6x12, DWINUI::textcolor, DWINUI::backcolor, px(x) - 12, py(y) - 6, str_1);
  97. }
  98. }
  99. }
  100. }
  101. void MeshViewerClass::Draw(bool withsave /*= false*/) {
  102. Title.ShowCaption(GET_TEXT_F(MSG_MESH_VIEWER));
  103. DrawMesh(Z_VALUES_ARR, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y);
  104. if (withsave) {
  105. DWINUI::Draw_Button(BTN_Save, 26, 305);
  106. DWINUI::Draw_Button(BTN_Continue, 146, 305);
  107. Draw_Select_Highlight(HMI_flag.select_flag, 305);
  108. }
  109. else
  110. DWINUI::Draw_Button(BTN_Continue, 86, 305);
  111. char str_1[6], str_2[6] = "";
  112. ui.status_printf(0, F("Mesh minZ: %s, maxZ: %s"),
  113. dtostrf(min, 1, 2, str_1),
  114. dtostrf(max, 1, 2, str_2)
  115. );
  116. }
  117. void Draw_MeshViewer() { MeshViewer.Draw(true); }
  118. void onClick_MeshViewer() { if (HMI_flag.select_flag) WriteEeprom(); HMI_ReturnScreen(); }
  119. void Goto_MeshViewer() { if (leveling_is_valid()) Goto_Popup(Draw_MeshViewer, onClick_MeshViewer); else HMI_ReturnScreen(); }
  120. #endif // DWIN_LCD_PROUI && HAS_MESH