From eee101b9dd35f3bbfee7d941e8b6f82baba408d9 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <thinkyhead@users.noreply.github.com>
Date: Thu, 13 Aug 2020 21:30:12 -0500
Subject: [PATCH] Clean up M80/M81, DWIN

---
 Marlin/src/gcode/control/M80_M81.cpp | 14 +++++---------
 Marlin/src/lcd/dwin/dwin.cpp         |  8 +++++---
 Marlin/src/lcd/fontutils.h           |  2 +-
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp
index 0dede7ea644..3498bfbc39f 100644
--- a/Marlin/src/gcode/control/M80_M81.cpp
+++ b/Marlin/src/gcode/control/M80_M81.cpp
@@ -22,15 +22,11 @@
 
 #include "../gcode.h"
 #include "../../module/temperature.h"
-#include "../../module/stepper.h"
-#include "../../module/printcounter.h" // for print_job_timer
+#include "../../module/printcounter.h"  // for print_job_timer
+#include "../../lcd/ultralcd.h"         // for LCD_MESSAGEPGM_P
 
 #include "../../inc/MarlinConfig.h"
 
-#if HAS_LCD_MENU
-  #include "../../lcd/ultralcd.h"
-#endif
-
 #if HAS_SUICIDE
   #include "../../MarlinCore.h"
 #endif
@@ -39,6 +35,8 @@
 
   #if ENABLED(AUTO_POWER_CONTROL)
     #include "../../feature/power.h"
+  #else
+    void restore_stepper_drivers();
   #endif
 
   // Could be moved to a feature, but this is all the data
@@ -108,7 +106,5 @@ void GcodeSuite::M81() {
     PSU_OFF();
   #endif
 
-  #if HAS_LCD_MENU
-    LCD_MESSAGEPGM_P(PSTR(MACHINE_NAME " " STR_OFF "."));
-  #endif
+  LCD_MESSAGEPGM_P(PSTR(MACHINE_NAME " " STR_OFF "."));
 }
diff --git a/Marlin/src/lcd/dwin/dwin.cpp b/Marlin/src/lcd/dwin/dwin.cpp
index 1aa2656dcfd..8cd7af15747 100644
--- a/Marlin/src/lcd/dwin/dwin.cpp
+++ b/Marlin/src/lcd/dwin/dwin.cpp
@@ -935,7 +935,8 @@ void Goto_PrintProcess(void) {
 
   // Copy into filebuf string before entry
   char * const name = card.longest_filename();
-  DWIN_Draw_String(false, false, font8x16, White, Background_black, (DWIN_WIDTH - strlen(name) * MENU_CHR_W) / 2, 60, name);
+  const int8_t npos = _MAX(0, DWIN_WIDTH - strlen(name) * MENU_CHR_W) / 2;
+  DWIN_Draw_String(false, false, font8x16, White, Background_black, npos, 60, name);
 
   DWIN_ICON_Show(ICON, ICON_PrintTime, 17, 193);
   DWIN_ICON_Show(ICON, ICON_RemainTime, 150, 191);
@@ -1523,7 +1524,7 @@ inline void make_name_without_ext(char *dst, char *src, int maxlen=MENU_CHAR_LIM
   if (!card.flag.filenameIsDir)
     while (pos && src[pos] != '.') pos--; // find last '.' (stop at 0)
 
-  int len = pos;      // nul or '.'
+  size_t len = pos;   // nul or '.'
   if (len > maxlen) { // Keep the name short
     pos        = len = maxlen; // move nul down
     dst[--pos] = '.'; // insert dots
@@ -3436,7 +3437,8 @@ void EachMomentUpdate(void) {
         Popup_Window_Resume();
         draw_first_option(false);
         char * const name = card.longest_filename();
-        DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, (DWIN_WIDTH - strlen(name) * MENU_CHR_W) / 2, 252, name);
+        const int8_t npos = _MAX(0, DWIN_WIDTH - strlen(name) * (MENU_CHR_W)) / 2;
+        DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, npos, 252, name);
         DWIN_UpdateLCD();
         break;
       }
diff --git a/Marlin/src/lcd/fontutils.h b/Marlin/src/lcd/fontutils.h
index 8839e36a2bd..74c4a87fb9d 100644
--- a/Marlin/src/lcd/fontutils.h
+++ b/Marlin/src/lcd/fontutils.h
@@ -38,6 +38,6 @@ int pf_bsearch_r(void *userdata, size_t num_data, pf_bsearch_cb_comp_t cb_comp,
 /* Get the character, decoding multibyte UTF8 characters and returning a pointer to the start of the next UTF8 character */
 uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t *pval);
 
-/* Returns lenght of string in CHARACTERS, NOT BYTES */
+/* Returns length of string in CHARACTERS, NOT BYTES */
 uint8_t utf8_strlen(const char *pstart);
 uint8_t utf8_strlen_P(PGM_P pstart);