From 97e9c95f4722de6e15899aeb4efa7359f0b34f82 Mon Sep 17 00:00:00 2001
From: Ludy <Ludy87@users.noreply.github.com>
Date: Sun, 28 Jul 2019 05:44:05 +0200
Subject: [PATCH] Fix & clean up ExtUI (#14748)

---
 .../bedlevel/mbl/mesh_bed_leveling.cpp        |  4 ++
 Marlin/src/gcode/bedlevel/mbl/G29.cpp         |  4 ++
 Marlin/src/lcd/extui_malyan_lcd.cpp           | 49 +++++++++----------
 Marlin/src/module/configuration_store.cpp     |  4 +-
 4 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
index f929f048b1..f65a9c595d 100644
--- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
+++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
@@ -28,6 +28,10 @@
 
   #include "../../../module/motion.h"
   #include "../../../feature/bedlevel/bedlevel.h"
+  
+  #if ENABLED(EXTENSIBLE_UI)
+    #include "../../../lcd/extensible_ui/ui_api.h"
+  #endif
 
   mesh_bed_leveling mbl;
 
diff --git a/Marlin/src/gcode/bedlevel/mbl/G29.cpp b/Marlin/src/gcode/bedlevel/mbl/G29.cpp
index 6b4b6ed630..773098a443 100644
--- a/Marlin/src/gcode/bedlevel/mbl/G29.cpp
+++ b/Marlin/src/gcode/bedlevel/mbl/G29.cpp
@@ -37,6 +37,10 @@
 #include "../../../lcd/ultralcd.h"
 #include "../../../module/motion.h"
 #include "../../../module/stepper.h"
+  
+#if ENABLED(EXTENSIBLE_UI)
+  #include "../../../lcd/extensible_ui/ui_api.h"
+#endif
 
 // Save 130 bytes with non-duplication of PSTR
 inline void echo_not_entered(const char c) { SERIAL_CHAR(c); SERIAL_ECHOLNPGM(" not entered."); }
diff --git a/Marlin/src/lcd/extui_malyan_lcd.cpp b/Marlin/src/lcd/extui_malyan_lcd.cpp
index 6b83827382..dde1a4c8ff 100644
--- a/Marlin/src/lcd/extui_malyan_lcd.cpp
+++ b/Marlin/src/lcd/extui_malyan_lcd.cpp
@@ -114,20 +114,18 @@ void write_to_lcd(const char * const message) {
 void process_lcd_c_command(const char* command) {
   switch (command[0]) {
     case 'C': // Cope with both V1 early rev and later LCDs.
-    case 'S': {
+    case 'S':
       feedrate_percentage = atoi(command + 1) * 10;
       LIMIT(feedrate_percentage, 10, 999);
-    } break;
-    case 'T': {
-      thermalManager.setTargetHotend(atoi(command + 1), 0);
-    } break;
-    case 'P': {
-      thermalManager.setTargetBed(atoi(command + 1));
-    } break;
+      break;
 
-    default:
-      SERIAL_ECHOLNPAIR("UNKNOWN C COMMAND", command);
-      return;
+    case 'T': thermalManager.setTargetHotend(atoi(command + 1), 0); break;
+
+    #if HAS_HEATED_BED
+      case 'P': thermalManager.setTargetBed(atoi(command + 1)); break;
+    #endif
+
+    default: SERIAL_ECHOLNPAIR("UNKNOWN C COMMAND", command);
   }
 }
 
@@ -148,21 +146,20 @@ void process_lcd_eb_command(const char* command) {
 
       char message_buffer[MAX_CURLY_COMMAND];
       sprintf_P(message_buffer,
-              PSTR("{T0:%03.0f/%03i}{T1:000/000}{TP:%03.0f/%03i}{TQ:%03i}{TT:%s}"),
-              thermalManager.degHotend(0),
-              thermalManager.degTargetHotend(0),
-              #if HAS_HEATED_BED
-                thermalManager.degBed(),
-                thermalManager.degTargetBed(),
-              #else
-                0, 0,
-              #endif
-              #if ENABLED(SDSUPPORT)
-                card.percentDone(),
-              #else
-                0,
-              #endif
-              elapsed_buffer);
+        PSTR("{T0:%03.0f/%03i}{T1:000/000}{TP:%03.0f/%03i}{TQ:%03i}{TT:%s}"),
+        thermalManager.degHotend(0), thermalManager.degTargetHotend(0),
+        #if HAS_HEATED_BED
+          thermalManager.degBed(), thermalManager.degTargetBed(),
+        #else
+          0, 0,
+        #endif
+        #if ENABLED(SDSUPPORT)
+          card.percentDone(),
+        #else
+          0,
+        #endif
+        elapsed_buffer
+      );
       write_to_lcd(message_buffer);
     } break;
 
diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp
index 8af5146eb3..8143b27994 100644
--- a/Marlin/src/module/configuration_store.cpp
+++ b/Marlin/src/module/configuration_store.cpp
@@ -98,10 +98,8 @@
   #include "../feature/runout.h"
 #endif
 
-#include "../lcd/extensible_ui/ui_api.h"
-
 #if ENABLED(EXTRA_LIN_ADVANCE_K)
-extern float saved_extruder_advance_K[EXTRUDERS];
+  extern float saved_extruder_advance_K[EXTRUDERS];
 #endif
 
 #if EXTRUDERS > 1