From 877e10205b286a6c1b8da869c54b50db866c1db8 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <thinkyhead@users.noreply.github.com>
Date: Sun, 3 Apr 2022 20:13:11 -0500
Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Axis=20name=20arrays?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-Authored-By: DerAndere <26200979+DerAndere1@users.noreply.github.com>
---
 Marlin/src/HAL/AVR/pinsDebug.h           |  2 +-
 Marlin/src/core/serial.h                 |  3 +++
 Marlin/src/core/utility.cpp              |  2 +-
 Marlin/src/gcode/calibrate/M425.cpp      |  7 ++-----
 Marlin/src/gcode/control/M111.cpp        |  2 +-
 Marlin/src/gcode/control/M17_M18_M84.cpp |  2 +-
 Marlin/src/gcode/host/M114.cpp           | 10 +++-------
 Marlin/src/lcd/menu/menu_tramming.cpp    |  2 +-
 8 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/Marlin/src/HAL/AVR/pinsDebug.h b/Marlin/src/HAL/AVR/pinsDebug.h
index 0f564df987f..247ae32b8fa 100644
--- a/Marlin/src/HAL/AVR/pinsDebug.h
+++ b/Marlin/src/HAL/AVR/pinsDebug.h
@@ -74,7 +74,7 @@
 #define MULTI_NAME_PAD 26 // space needed to be pretty if not first name assigned to a pin
 
 void PRINT_ARRAY_NAME(uint8_t x) {
-  char *name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
+  char *name_mem_pointer = (PGM_P)pgm_read_ptr(&pin_array[x].name);
   LOOP_L_N(y, MAX_NAME_LENGTH) {
     char temp_char = pgm_read_byte(name_mem_pointer + y);
     if (temp_char != 0)
diff --git a/Marlin/src/core/serial.h b/Marlin/src/core/serial.h
index 2998fe803fd..b381f6f74f0 100644
--- a/Marlin/src/core/serial.h
+++ b/Marlin/src/core/serial.h
@@ -36,6 +36,9 @@ extern const char NUL_STR[], SP_P_STR[], SP_T_STR[],
                   X_STR[], Y_STR[], Z_STR[], I_STR[], J_STR[], K_STR[], U_STR[], V_STR[], W_STR[], E_STR[],
                   X_LBL[], Y_LBL[], Z_LBL[], I_LBL[], J_LBL[], K_LBL[], U_LBL[], V_LBL[], W_LBL[], E_LBL[];
 
+PGM_P const SP_AXIS_LBL[] PROGMEM = LOGICAL_AXIS_ARRAY(SP_E_LBL, SP_X_LBL, SP_Y_LBL, SP_Z_LBL, SP_I_LBL, SP_J_LBL, SP_K_LBL, SP_U_LBL, SP_V_LBL, SP_W_LBL);
+PGM_P const SP_AXIS_STR[] PROGMEM = LOGICAL_AXIS_ARRAY(SP_E_STR, SP_X_STR, SP_Y_STR, SP_Z_STR, SP_I_STR, SP_J_STR, SP_K_STR, SP_U_STR, SP_V_STR, SP_W_STR);
+
 //
 // Debugging flags for use by M111
 //
diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp
index d30511ae401..658ed6cd81a 100644
--- a/Marlin/src/core/utility.cpp
+++ b/Marlin/src/core/utility.cpp
@@ -126,7 +126,7 @@ void safe_delay(millis_t ms) {
         #if ABL_PLANAR
           SERIAL_ECHOPGM("ABL Adjustment");
           LOOP_NUM_AXES(a) {
-            SERIAL_CHAR(' ', AXIS_CHAR(a));
+            SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a]));
             serial_offset(planner.get_axis_position_mm(AxisEnum(a)) - current_position[a]);
           }
         #else
diff --git a/Marlin/src/gcode/calibrate/M425.cpp b/Marlin/src/gcode/calibrate/M425.cpp
index 65d368f5324..77e0e5c0945 100644
--- a/Marlin/src/gcode/calibrate/M425.cpp
+++ b/Marlin/src/gcode/calibrate/M425.cpp
@@ -92,9 +92,7 @@ void GcodeSuite::M425() {
     SERIAL_ECHOLNPGM("  Correction Amount/Fade-out:     F", backlash.get_correction(), " (F1.0 = full, F0.0 = none)");
     SERIAL_ECHOPGM("  Backlash Distance (mm):        ");
     LOOP_NUM_AXES(a) if (axis_can_calibrate(a)) {
-      SERIAL_CHAR(' ', AXIS_CHAR(a));
-      SERIAL_ECHO(backlash.get_distance_mm(AxisEnum(a)));
-      SERIAL_EOL();
+      SERIAL_ECHOLNPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a]), backlash.get_distance_mm((AxisEnum)a));
     }
 
     #ifdef BACKLASH_SMOOTHING_MM
@@ -105,8 +103,7 @@ void GcodeSuite::M425() {
       SERIAL_ECHOPGM("  Average measured backlash (mm):");
       if (backlash.has_any_measurement()) {
         LOOP_NUM_AXES(a) if (axis_can_calibrate(a) && backlash.has_measurement(AxisEnum(a))) {
-          SERIAL_CHAR(' ', AXIS_CHAR(a));
-          SERIAL_ECHO(backlash.get_measurement(AxisEnum(a)));
+          SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a]), backlash.get_measurement((AxisEnum)a));
         }
       }
       else
diff --git a/Marlin/src/gcode/control/M111.cpp b/Marlin/src/gcode/control/M111.cpp
index d6aeb774108..a92d334ae9d 100644
--- a/Marlin/src/gcode/control/M111.cpp
+++ b/Marlin/src/gcode/control/M111.cpp
@@ -49,7 +49,7 @@ void GcodeSuite::M111() {
     LOOP_L_N(i, COUNT(debug_strings)) {
       if (TEST(marlin_debug_flags, i)) {
         if (comma++) SERIAL_CHAR(',');
-        SERIAL_ECHOPGM_P((char*)pgm_read_ptr(&debug_strings[i]));
+        SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&debug_strings[i]));
       }
     }
   }
diff --git a/Marlin/src/gcode/control/M17_M18_M84.cpp b/Marlin/src/gcode/control/M17_M18_M84.cpp
index b3315a385a5..7a16121c0b8 100644
--- a/Marlin/src/gcode/control/M17_M18_M84.cpp
+++ b/Marlin/src/gcode/control/M17_M18_M84.cpp
@@ -184,7 +184,7 @@ void try_to_disable(const stepper_flags_t to_disable) {
 
   auto overlap_warning = [](const ena_mask_t axis_bits) {
     SERIAL_ECHOPGM(" not disabled. Shared with");
-    LOOP_NUM_AXES(a) if (TEST(axis_bits, a)) SERIAL_CHAR(' ', axis_codes[a]);
+    LOOP_NUM_AXES(a) if (TEST(axis_bits, a)) SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a]));
     #if HAS_EXTRUDERS
       #define _EN_STILLON(N) if (TEST(axis_bits, INDEX_OF_AXIS(E_AXIS, N))) SERIAL_CHAR(' ', 'E', '0' + N);
       REPEAT(EXTRUDERS, _EN_STILLON)
diff --git a/Marlin/src/gcode/host/M114.cpp b/Marlin/src/gcode/host/M114.cpp
index fc1c7f9e4b1..8ea300b5e05 100644
--- a/Marlin/src/gcode/host/M114.cpp
+++ b/Marlin/src/gcode/host/M114.cpp
@@ -37,7 +37,7 @@
   void report_all_axis_pos(const xyze_pos_t &pos, const uint8_t n=LOGICAL_AXES, const uint8_t precision=3) {
     char str[12];
     LOOP_L_N(a, n) {
-      SERIAL_CHAR(' ', axis_codes[a], ':');
+      SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_LBL[a]));
       if (pos[a] >= 0) SERIAL_CHAR(' ');
       SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
     }
@@ -47,10 +47,7 @@
 
   void report_linear_axis_pos(const xyz_pos_t &pos, const uint8_t precision=3) {
     char str[12];
-    LOOP_NUM_AXES(a) {
-      SERIAL_CHAR(' ', AXIS_CHAR(a), ':');
-      SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
-    }
+    LOOP_NUM_AXES(a) SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_LBL[a]), dtostrf(pos[a], 1, precision, str));
     SERIAL_EOL();
   }
 
@@ -172,8 +169,7 @@
 
     SERIAL_ECHOPGM("Stepper:");
     LOOP_LOGICAL_AXES(i) {
-      SERIAL_CHAR(' ', axis_codes[i], ':');
-      SERIAL_ECHO(stepper.position((AxisEnum)i));
+      SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_LBL[i]), stepper.position((AxisEnum)i));
     }
     SERIAL_EOL();
 
diff --git a/Marlin/src/lcd/menu/menu_tramming.cpp b/Marlin/src/lcd/menu/menu_tramming.cpp
index cd7a4c677a1..0789044d7d8 100644
--- a/Marlin/src/lcd/menu/menu_tramming.cpp
+++ b/Marlin/src/lcd/menu/menu_tramming.cpp
@@ -83,7 +83,7 @@ static void tramming_wizard_menu() {
 
   // Draw a menu item for each tramming point
   for (tram_index = 0; tram_index < G35_PROBE_COUNT; tram_index++)
-    SUBMENU_P((char*)pgm_read_ptr(&tramming_point_name[tram_index]), _menu_single_probe);
+    SUBMENU_P((PGM_P)pgm_read_ptr(&tramming_point_name[tram_index]), _menu_single_probe);
 
   ACTION_ITEM(MSG_BUTTON_DONE, []{
     probe.stow(); // Stow before exiting Tramming Wizard