diff --git a/Marlin/src/lcd/e3v2/enhanced/dwin.cpp b/Marlin/src/lcd/e3v2/enhanced/dwin.cpp index 923ecc76be79..f68d7f9ca5b2 100644 --- a/Marlin/src/lcd/e3v2/enhanced/dwin.cpp +++ b/Marlin/src/lcd/e3v2/enhanced/dwin.cpp @@ -78,7 +78,7 @@ #include "../../../feature/powerloss.h" #endif -#if HAS_LEVELING +#if HAS_MESH #include "meshviewer.h" #endif @@ -3201,7 +3201,7 @@ void Draw_AdvancedSettings_Menu() { ADDMENUITEM(ICON_Sound, F("Enable Sound"), onDrawEnableSound, SetEnableSound); #endif #if HAS_MESH - ADDMENUITEM(ICON_MeshViewer, F("Mesh Viewer"), onDrawSubMenu, DWIN_MeshViewer); + ADDMENUITEM(ICON_MeshViewer, F("View Mesh"), onDrawSubMenu, DWIN_MeshViewer); #endif ADDMENUITEM(ICON_Lock, F("Lock Screen"), onDrawMenuItem, Goto_LockScreen); } @@ -3421,7 +3421,7 @@ void Draw_Motion_Menu() { ADDMENUITEM(ICON_ManualMesh, GET_TEXT_F(MSG_LEVEL_BED), onDrawMenuItem, ManualMeshStart); MMeshMoveZItem = ADDMENUITEM_P(ICON_Zoffset, GET_TEXT_F(MSG_MOVE_Z), onDrawMMeshMoveZ, SetMMeshMoveZ, ¤t_position.z); ADDMENUITEM(ICON_Axis, GET_TEXT_F(MSG_UBL_CONTINUE_MESH), onDrawMenuItem, ManualMeshContinue); - ADDMENUITEM(ICON_MeshViewer, F("Mesh Viewer"), onDrawSubMenu, DWIN_MeshViewer); + ADDMENUITEM(ICON_MeshViewer, F("View Mesh"), onDrawSubMenu, DWIN_MeshViewer); ADDMENUITEM(ICON_MeshSave, GET_TEXT_F(MSG_UBL_SAVE_MESH), onDrawMenuItem, ManualMeshSave); } CurrentMenu->draw(); diff --git a/Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp b/Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp index bb4331ad41cd..6efc96f21b38 100644 --- a/Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp +++ b/Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp @@ -5,7 +5,7 @@ * Date: 2021/09/27 * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as + * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * @@ -21,57 +21,55 @@ #include "../../../inc/MarlinConfigPre.h" -#if HAS_LEVELING +#if BOTH(DWIN_CREALITY_LCD_ENHANCED, HAS_MESH) + +#include "meshviewer.h" #include "../../../core/types.h" #include "../../marlinui.h" #include "dwin_lcd.h" #include "dwinui.h" #include "dwin.h" -#include "meshviewer.h" #include "../../../feature/bedlevel/bedlevel.h" MeshViewerClass MeshViewer; void MeshViewerClass::Draw() { - const int8_t mx = 30; // Margins - const int8_t my = 30; - const int16_t stx = (DWIN_WIDTH - 2 * mx) / (GRID_MAX_POINTS_X - 1); // Steps - const int16_t sty = (DWIN_WIDTH - 2 * my) / (GRID_MAX_POINTS_Y - 1); - int8_t zmesh[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; - int8_t maxz =-127; - int8_t minz = 127; - #define px(xp) (mx + (xp)*stx) - #define py(yp) (30 + DWIN_WIDTH - my - (yp)*sty) + const int8_t mx = 30, my = 30; // Margins + const int16_t stx = (DWIN_WIDTH - 2 * mx) / (GRID_MAX_POINTS_X - 1), // Steps + sty = (DWIN_WIDTH - 2 * my) / (GRID_MAX_POINTS_Y - 1); + int8_t zmesh[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], maxz =-127, minz = 127; + #define px(xp) (mx + (xp) * stx) + #define py(yp) (30 + DWIN_WIDTH - my - (yp) * sty) #define rm(z) ((((z) - minz) * 10 / _MAX(1, (maxz - minz))) + 10) - #define DrawMeshValue(xp, yp, zv) DWINUI::Draw_Signed_Float(font6x12, 1, 2, px(xp) - 12, py(yp) - 6, zv); + #define DrawMeshValue(xp, yp, zv) DWINUI::Draw_Signed_Float(font6x12, 1, 2, px(xp) - 12, py(yp) - 6, zv) #define DrawMeshHLine(yp) DWIN_Draw_HLine(HMI_data.SplitLine_Color, px(0), py(yp), DWIN_WIDTH - 2 * mx) #define DrawMeshVLine(xp) DWIN_Draw_VLine(HMI_data.SplitLine_Color, px(xp), py(GRID_MAX_POINTS_Y - 1), DWIN_WIDTH - 2 * my) - for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { - for (uint8_t y = 0; y < GRID_MAX_POINTS_X; y++) { - zmesh[x][y] = Z_VALUES(x,y) * 100; - maxz = _MAX(zmesh[x][y], maxz); - minz = _MIN(zmesh[x][y], minz); - } + GRID_LOOP(x, y) { + const float v = Z_VALUES(x,y) * 100; + zmesh[x][y] = v; + NOLESS(maxz, v); + NOMORE(minz, v); } Title.ShowCaption(F("Mesh viewer")); DWINUI::ClearMenuArea(); DWINUI::Draw_Icon(ICON_Continue_E, 86, 305); DWIN_Draw_Rectangle(0, HMI_data.SplitLine_Color, px(0), py(0), px(GRID_MAX_POINTS_X - 1), py(GRID_MAX_POINTS_Y - 1)); - for (uint8_t x = 1; x < GRID_MAX_POINTS_X - 1; x++) DrawMeshVLine(x); - for (uint8_t y = 1; y < GRID_MAX_POINTS_Y - 1; y++) DrawMeshHLine(y); - for (uint8_t y = 0; y < GRID_MAX_POINTS_X; y++) { + LOOP_S_L_N(x, 1, GRID_MAX_POINTS_X - 1) DrawMeshVLine(x); + LOOP_S_L_N(y, 1, GRID_MAX_POINTS_Y - 1) DrawMeshHLine(y); + LOOP_L_N(y, GRID_MAX_POINTS_Y) { watchdog_refresh(); - for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { + LOOP_L_N(x, GRID_MAX_POINTS_X) { uint16_t color = DWINUI::RainbowInt(zmesh[x][y], _MIN(-5, minz), _MAX(5, maxz)); DWINUI::Draw_FillCircle(color, px(x), py(y), rm(zmesh[x][y])); DrawMeshValue(x, y, Z_VALUES(x,y)); } } char str_1[6], str_2[6] = ""; - ui.status_printf_P(0,PSTR("Mesh minZ: %s, maxZ: %s"), - dtostrf((float)minz/100, 1, 2, str_1), - dtostrf((float)maxz/100, 1, 2, str_2)); + ui.status_printf_P(0, PSTR("Mesh minZ: %s, maxZ: %s"), + dtostrf((float)minz / 100, 1, 2, str_1), + dtostrf((float)maxz / 100, 1, 2, str_2) + ); } -#endif // HAS_LEVELING +#endif // DWIN_CREALITY_LCD_ENHANCED && HAS_MESH diff --git a/Marlin/src/lcd/e3v2/enhanced/meshviewer.h b/Marlin/src/lcd/e3v2/enhanced/meshviewer.h index ab8de086f89b..4f7a6ae1d25f 100644 --- a/Marlin/src/lcd/e3v2/enhanced/meshviewer.h +++ b/Marlin/src/lcd/e3v2/enhanced/meshviewer.h @@ -5,7 +5,7 @@ * Date: 2021/09/27 * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as + * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * @@ -18,7 +18,6 @@ * along with this program. If not, see . * */ - #pragma once class MeshViewerClass { @@ -27,4 +26,3 @@ class MeshViewerClass { }; extern MeshViewerClass MeshViewer; - diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index eccbe8d141a3..987aca522738 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -3246,7 +3246,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; case LEVELING_VIEW: if (draw) - Draw_Menu_Item(row, ICON_Mesh, "Mesh Viewer", nullptr, true); + Draw_Menu_Item(row, ICON_Mesh, "View Mesh", nullptr, true); else { #if ENABLED(AUTO_BED_LEVELING_UBL) if (ubl.storage_slot < 0) { @@ -3319,7 +3319,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/ break; case LEVELING_VIEW_MESH: if (draw) - Draw_Menu_Item(row, ICON_PrintSize, "Mesh Viewer", nullptr, true); + Draw_Menu_Item(row, ICON_PrintSize, "View Mesh", nullptr, true); else Draw_Menu(MeshViewer); break; @@ -4072,7 +4072,7 @@ const char * CrealityDWINClass::Get_Menu_Title(uint8_t menu) { case Leveling: return "Leveling"; case LevelView: return "Mesh View"; case LevelSettings: return "Leveling Settings"; - case MeshViewer: return "Mesh Viewer"; + case MeshViewer: return "View Mesh"; case LevelManual: return "Manual Tuning"; #endif #if ENABLED(AUTO_BED_LEVELING_UBL) && !HAS_BED_PROBE