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 5.1KB

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