diff --git a/Marlin/src/lcd/e3v2/enhanced/dwin.cpp b/Marlin/src/lcd/e3v2/enhanced/dwin.cpp index 847073c52eca..6edfc81c609b 100644 --- a/Marlin/src/lcd/e3v2/enhanced/dwin.cpp +++ b/Marlin/src/lcd/e3v2/enhanced/dwin.cpp @@ -62,7 +62,7 @@ #include "../../../feature/host_actions.h" #endif -#if HAS_ONESTEP_LEVELING +#if HAS_MESH || HAS_ONESTEP_LEVELING #include "../../../feature/bedlevel/bedlevel.h" #endif @@ -78,6 +78,10 @@ #include "../../../feature/powerloss.h" #endif +#if HAS_MESH + #include "meshviewer.h" +#endif + #include #include #include @@ -1661,7 +1665,7 @@ void DWIN_MeshLevelingStart() { #endif } -void DWIN_CompletedLeveling() { HMI_ReturnScreen(); } +void DWIN_CompletedLeveling() { DWIN_MeshViewer(); } #if HAS_MESH void DWIN_MeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) { @@ -1921,6 +1925,17 @@ void DWIN_Redraw_screen() { #endif // ADVANCED_PAUSE_FEATURE +#if HAS_MESH + void DWIN_MeshViewer() { + if (!leveling_is_valid()) + DWIN_Popup_Continue(ICON_BLTouch, "Mesh viewer", "No valid mesh"); + else { + HMI_SaveProcessID(WaitResponse); + MeshViewer.Draw(); + } + } +#endif + void HMI_LockScreen() { EncoderState encoder_diffState = get_encoder_state(); if (encoder_diffState == ENCODER_DIFF_NO) return; @@ -3185,6 +3200,9 @@ void Draw_AdvancedSettings_Menu() { #if ENABLED(SOUND_MENU_ITEM) ADDMENUITEM(ICON_Sound, F("Enable Sound"), onDrawEnableSound, SetEnableSound); #endif + #if HAS_MESH + ADDMENUITEM(ICON_MeshViewer, GET_TEXT_F(MSG_MESH_VIEW), onDrawSubMenu, DWIN_MeshViewer); + #endif ADDMENUITEM(ICON_Lock, F("Lock Screen"), onDrawMenuItem, Goto_LockScreen); } CurrentMenu->draw(); @@ -3403,6 +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, GET_TEXT_F(MSG_MESH_VIEW), 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/dwin.h b/Marlin/src/lcd/e3v2/enhanced/dwin.h index 8d138df7f7b9..6b131592a81d 100644 --- a/Marlin/src/lcd/e3v2/enhanced/dwin.h +++ b/Marlin/src/lcd/e3v2/enhanced/dwin.h @@ -222,6 +222,9 @@ void DWIN_RebootScreen(); // Utility and extensions void HMI_LockScreen(); void DWIN_LockScreen(const bool flag = true); +#if HAS_MESH + void DWIN_MeshViewer(); +#endif // HMI user control functions void HMI_Menu(); diff --git a/Marlin/src/lcd/e3v2/enhanced/dwinui.h b/Marlin/src/lcd/e3v2/enhanced/dwinui.h index ce56c98e5b4a..8cbb66fdf041 100644 --- a/Marlin/src/lcd/e3v2/enhanced/dwinui.h +++ b/Marlin/src/lcd/e3v2/enhanced/dwinui.h @@ -50,6 +50,7 @@ #define ICON_ManualMesh ICON_HotendTemp #define ICON_MeshNext ICON_Axis #define ICON_MeshSave ICON_WriteEEPROM +#define ICON_MeshViewer ICON_HotendTemp #define ICON_MoveZ0 ICON_HotendTemp #define ICON_Park ICON_Motion #define ICON_PIDcycles ICON_ResumeEEPROM diff --git a/Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp b/Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp new file mode 100644 index 000000000000..6efc96f21b38 --- /dev/null +++ b/Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp @@ -0,0 +1,75 @@ +/** + * DWIN Mesh Viewer + * Author: Miguel A. Risco-Castillo + * version: 2.5 + * 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 + * published by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + */ + +#include "../../../inc/MarlinConfigPre.h" + +#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 "../../../feature/bedlevel/bedlevel.h" + +MeshViewerClass MeshViewer; + +void MeshViewerClass::Draw() { + 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 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) + 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)); + 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(); + 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) + ); +} + +#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 new file mode 100644 index 000000000000..4f7a6ae1d25f --- /dev/null +++ b/Marlin/src/lcd/e3v2/enhanced/meshviewer.h @@ -0,0 +1,28 @@ +/** + * DWIN Mesh Viewer + * Author: Miguel A. Risco-Castillo + * version: 2.5 + * 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 + * published by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + */ +#pragma once + +class MeshViewerClass { +public: + void Draw(); +}; + +extern MeshViewerClass MeshViewer; diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index eccbe8d141a3..a48987e68ddf 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, GET_TEXT_F(MSG_MESH_VIEW), 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, GET_TEXT_F(MSG_MESH_VIEW), nullptr, true); else Draw_Menu(MeshViewer); break; @@ -4070,9 +4070,9 @@ const char * CrealityDWINClass::Get_Menu_Title(uint8_t menu) { case InfoMain: return "Info"; #if HAS_MESH case Leveling: return "Leveling"; - case LevelView: return "Mesh View"; + case LevelView: return GET_TEXT_F(MSG_MESH_VIEW); case LevelSettings: return "Leveling Settings"; - case MeshViewer: return "Mesh Viewer"; + case MeshViewer: return GET_TEXT_F(MSG_MESH_VIEW); case LevelManual: return "Manual Tuning"; #endif #if ENABLED(AUTO_BED_LEVELING_UBL) && !HAS_BED_PROBE diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/leveling_menu.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/leveling_menu.cpp index 2e3472987eb3..3636b5da6cf3 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/leveling_menu.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/leveling_menu.cpp @@ -61,7 +61,7 @@ void LevelingMenu::onRedraw(draw_mode_t what) { .font(font_medium).colors(normal_btn) .tag(2).button(PROBE_BED_POS, GET_TEXT_F(MSG_PROBE_BED)) .enabled(ENABLED(HAS_MESH)) - .tag(3).button(SHOW_MESH_POS, GET_TEXT_F(MSG_SHOW_MESH)) + .tag(3).button(SHOW_MESH_POS, GET_TEXT_F(MSG_MESH_VIEW)) .enabled(ENABLED(HAS_MESH)) .tag(4).button(EDIT_MESH_POS, GET_TEXT_F(MSG_EDIT_MESH)) #undef GRID_COLS diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/leveling_menu.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/leveling_menu.cpp index 9bc2f56ab97b..05845a975521 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/leveling_menu.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/leveling_menu.cpp @@ -86,7 +86,7 @@ void LevelingMenu::onRedraw(draw_mode_t what) { .enabled(ENABLED(HAS_BED_PROBE)) .tag(3).button(PROBE_BED_POS, GET_TEXT_F(MSG_PROBE_BED)) .enabled(ENABLED(HAS_MESH)) - .tag(4).button(SHOW_MESH_POS, GET_TEXT_F(MSG_SHOW_MESH)) + .tag(4).button(SHOW_MESH_POS, GET_TEXT_F(MSG_MESH_VIEW)) .enabled(ENABLED(HAS_MESH)) .tag(5).button(EDIT_MESH_POS, GET_TEXT_F(MSG_EDIT_MESH)) .enabled(ENABLED(G26_MESH_VALIDATION)) diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/language/language_en.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/language/language_en.h index 0d883d8d02c0..2e2597aec435 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/language/language_en.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/language/language_en.h @@ -145,7 +145,7 @@ namespace Language_en { PROGMEM Language_Str MSG_LEVELING = u8"Leveling"; PROGMEM Language_Str MSG_AXIS_LEVELING = u8"Axis Leveling"; PROGMEM Language_Str MSG_PROBE_BED = u8"Probe Mesh"; - PROGMEM Language_Str MSG_SHOW_MESH = u8"View Mesh"; + PROGMEM Language_Str MSG_MESH_VIEW = u8"View Mesh"; PROGMEM Language_Str MSG_PRINT_TEST = u8"Print Test (PLA)"; PROGMEM Language_Str MSG_MOVE_Z_TO_TOP = u8"Raise Z to Top"; diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index b23d0bfa00b6..8c7a78cd4688 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -157,6 +157,7 @@ namespace Language_en { LSTR MSG_NEXT_CORNER = _UxGT("Next Corner"); LSTR MSG_MESH_EDITOR = _UxGT("Mesh Editor"); LSTR MSG_EDIT_MESH = _UxGT("Edit Mesh"); + LSTR MSG_MESH_VIEW = _UxGT("View Mesh"); LSTR MSG_EDITING_STOPPED = _UxGT("Mesh Editing Stopped"); LSTR MSG_PROBING_POINT = _UxGT("Probing Point"); LSTR MSG_MESH_X = _UxGT("Index X");