From 9aade7f5df7551c62dfe95a2a3cbc896a7e27bbe Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 15 Dec 2025 02:03:57 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Reduce=20code=20for=20unused=20s?= =?UTF-8?q?hapers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followup to #28217 --- Marlin/src/lcd/menu/menu_motion.cpp | 34 ++++++++--- Marlin/src/module/ft_motion/shaping.cpp | 75 ++++++++++++++++--------- 2 files changed, 74 insertions(+), 35 deletions(-) diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 106646430c..ddc2f90a7b 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -315,15 +315,31 @@ void menu_move() { FSTR_P get_shaper_name(const AxisEnum axis) { switch (ftMotion.cfg.shaper[axis]) { default: return nullptr; - case ftMotionShaper_NONE: return GET_TEXT_F(MSG_LCD_OFF); - case ftMotionShaper_ZV: return GET_TEXT_F(MSG_FTM_ZV); - case ftMotionShaper_ZVD: return GET_TEXT_F(MSG_FTM_ZVD); - case ftMotionShaper_ZVDD: return GET_TEXT_F(MSG_FTM_ZVDD); - case ftMotionShaper_ZVDDD: return GET_TEXT_F(MSG_FTM_ZVDDD); - case ftMotionShaper_EI: return GET_TEXT_F(MSG_FTM_EI); - case ftMotionShaper_2HEI: return GET_TEXT_F(MSG_FTM_2HEI); - case ftMotionShaper_3HEI: return GET_TEXT_F(MSG_FTM_3HEI); - case ftMotionShaper_MZV: return GET_TEXT_F(MSG_FTM_MZV); + case ftMotionShaper_NONE: return GET_TEXT_F(MSG_LCD_OFF); + #if ENABLED(FTM_SHAPER_ZV) + case ftMotionShaper_ZV: return GET_TEXT_F(MSG_FTM_ZV); + #endif + #if ENABLED(FTM_SHAPER_ZVD) + case ftMotionShaper_ZVD: return GET_TEXT_F(MSG_FTM_ZVD); + #endif + #if ENABLED(FTM_SHAPER_ZVDD) + case ftMotionShaper_ZVDD: return GET_TEXT_F(MSG_FTM_ZVDD); + #endif + #if ENABLED(FTM_SHAPER_ZVDDD) + case ftMotionShaper_ZVDDD: return GET_TEXT_F(MSG_FTM_ZVDDD); + #endif + #if ENABLED(FTM_SHAPER_EI) + case ftMotionShaper_EI: return GET_TEXT_F(MSG_FTM_EI); + #endif + #if ENABLED(FTM_SHAPER_2HEI) + case ftMotionShaper_2HEI: return GET_TEXT_F(MSG_FTM_2HEI); + #endif + #if ENABLED(FTM_SHAPER_3HEI) + case ftMotionShaper_3HEI: return GET_TEXT_F(MSG_FTM_3HEI); + #endif + #if ENABLED(FTM_SHAPER_MZV) + case ftMotionShaper_MZV: return GET_TEXT_F(MSG_FTM_MZV); + #endif } } diff --git a/Marlin/src/module/ft_motion/shaping.cpp b/Marlin/src/module/ft_motion/shaping.cpp index f4f00a8589..e568aba791 100644 --- a/Marlin/src/module/ft_motion/shaping.cpp +++ b/Marlin/src/module/ft_motion/shaping.cpp @@ -90,7 +90,7 @@ void AxisShaping::set_axis_shaping_A( } break; #endif - #if ENABLED(FTM_SHAPER_H2EI) + #if ENABLED(FTM_SHAPER_2HEI) case ftMotionShaper_2HEI: { max_i = 3U; const float vtolx2 = sq(vtol); @@ -130,6 +130,7 @@ void AxisShaping::set_axis_shaping_A( break; #endif + default: case ftMotionShaper_NONE: max_i = 0; Ai[0] = 1.0f; // No echoes so the whole impulse is applied in the first tap @@ -144,31 +145,53 @@ void AxisShaping::set_axis_shaping_N(const ftMotionShaper_t shaper, const float // Note that protections are omitted for DBZ and for index exceeding array length. const float df = sqrt ( 1.f - sq(zeta) ); switch (shaper) { - case ftMotionShaper_ZV: - Ni[1] = LROUND((0.5f / f / df) * (FTM_FS)); - break; - case ftMotionShaper_ZVD: - case ftMotionShaper_EI: - Ni[1] = LROUND((0.5f / f / df) * (FTM_FS)); - Ni[2] = Ni[1] + Ni[1]; - break; - case ftMotionShaper_ZVDD: - case ftMotionShaper_2HEI: - Ni[1] = LROUND((0.5f / f / df) * (FTM_FS)); - Ni[2] = Ni[1] + Ni[1]; - Ni[3] = Ni[2] + Ni[1]; - break; - case ftMotionShaper_ZVDDD: - case ftMotionShaper_3HEI: - Ni[1] = LROUND((0.5f / f / df) * (FTM_FS)); - Ni[2] = Ni[1] + Ni[1]; - Ni[3] = Ni[2] + Ni[1]; - Ni[4] = Ni[3] + Ni[1]; - break; - case ftMotionShaper_MZV: - Ni[1] = LROUND((0.375f / f / df) * (FTM_FS)); - Ni[2] = Ni[1] + Ni[1]; - break; + #if ENABLED(FTM_SHAPER_ZV) + case ftMotionShaper_ZV: + Ni[1] = LROUND((0.5f / f / df) * (FTM_FS)); + break; + #endif + + #if ENABLED(FTM_SHAPER_ZVD) + case ftMotionShaper_ZVD: + #endif + #if ANY(FTM_SHAPER_ZVD, FTM_SHAPER_EI) + case ftMotionShaper_EI: + Ni[1] = LROUND((0.5f / f / df) * (FTM_FS)); + Ni[2] = Ni[1] + Ni[1]; + break; + #endif + + #if ENABLED(FTM_SHAPER_ZVDD) + case ftMotionShaper_ZVDD: + #endif + #if ANY(FTM_SHAPER_ZVDD, FTM_SHAPER_2HEI) + case ftMotionShaper_2HEI: + Ni[1] = LROUND((0.5f / f / df) * (FTM_FS)); + Ni[2] = Ni[1] + Ni[1]; + Ni[3] = Ni[2] + Ni[1]; + break; + #endif + + #if ENABLED(FTM_SHAPER_ZVDDD) + case ftMotionShaper_ZVDDD: + #endif + #if ANY(FTM_SHAPER_ZVDDD, FTM_SHAPER_3HEI) + case ftMotionShaper_3HEI: + Ni[1] = LROUND((0.5f / f / df) * (FTM_FS)); + Ni[2] = Ni[1] + Ni[1]; + Ni[3] = Ni[2] + Ni[1]; + Ni[4] = Ni[3] + Ni[1]; + break; + #endif + + #if ENABLED(FTM_SHAPER_MZV) + case ftMotionShaper_MZV: + Ni[1] = LROUND((0.375f / f / df) * (FTM_FS)); + Ni[2] = Ni[1] + Ni[1]; + break; + #endif + + default: case ftMotionShaper_NONE: // No echoes. // max_i is set to 0 by set_axis_shaping_A, so delay centroid (Ni[0]) will also correctly be 0