From 181739d0d1a54ab01c4f97678f04ae43ebb1facd Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Tue, 12 May 2020 00:09:18 -0500
Subject: [PATCH] Move inline laser state to fix EEPROM error

---
 Marlin/src/feature/spindle_laser.h | 10 +++++-----
 Marlin/src/module/planner.cpp      |  8 ++++++--
 Marlin/src/module/planner.h        |  9 +++++----
 Marlin/src/module/stepper.cpp      |  4 ++--
 4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h
index 0c2e569aa6f..2e863950983 100644
--- a/Marlin/src/feature/spindle_laser.h
+++ b/Marlin/src/feature/spindle_laser.h
@@ -137,7 +137,7 @@ public:
 
   #if ENABLED(LASER_POWER_INLINE)
     // Force disengage planner power control
-    static inline void inline_disable() { planner.settings.laser.status = 0; planner.settings.laser.power = 0; isOn = false;}
+    static inline void inline_disable() { planner.laser.status = 0; planner.laser.power = 0; isOn = false;}
 
     // Inline modes of all other functions; all enable planner inline power control
     static inline void inline_enabled(const bool enable) { enable ? inline_power(SPEED_POWER_STARTUP) : inline_ocr_power(0); }
@@ -146,8 +146,8 @@ public:
       #if ENABLED(SPINDLE_LASER_PWM)
         inline_ocr_power(translate_power(pwr));
       #else
-        planner.settings.laser.status = enabled(pwr) ? 0x03 : 0x01;
-        planner.settings.laser.power = pwr;
+        planner.laser.status = enabled(pwr) ? 0x03 : 0x01;
+        planner.laser.power = pwr;
       #endif
     }
 
@@ -155,8 +155,8 @@ public:
 
     #if ENABLED(SPINDLE_LASER_PWM)
       static inline void inline_ocr_power(const uint8_t pwr) {
-        planner.settings.laser.status = pwr ? 0x03 : 0x01;
-        planner.settings.laser.power = pwr;
+        planner.laser.status = pwr ? 0x03 : 0x01;
+        planner.laser.power = pwr;
       }
     #endif
   #endif
diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp
index 3d026c4daee..60584865109 100644
--- a/Marlin/src/module/planner.cpp
+++ b/Marlin/src/module/planner.cpp
@@ -128,6 +128,10 @@ uint8_t Planner::delay_before_delivering;       // This counter delays delivery
 
 planner_settings_t Planner::settings;           // Initialized by settings.load()
 
+#if ENABLED(LASER_POWER_INLINE)
+  laser_state_t Planner::laser;              // Current state for blocks
+#endif
+
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N]; // (steps/s^2) Derived from mm_per_s2
 
 float Planner::steps_to_mm[XYZE_N];             // (mm) Millimeters per step
@@ -1799,8 +1803,8 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
 
   // Update block laser power
   #if ENABLED(LASER_POWER_INLINE)
-    block->laser.status = settings.laser.status;
-    block->laser.power = settings.laser.power;
+    block->laser.status = laser.status;
+    block->laser.power = laser.power;
   #endif
 
   // Number of steps for each axis
diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h
index 0314758a1d2..6c5218cd6ff 100644
--- a/Marlin/src/module/planner.h
+++ b/Marlin/src/module/planner.h
@@ -248,7 +248,7 @@ typedef struct block_t {
      * as it avoids floating points during move loop
      */
     uint8_t power;
-  } settings_laser_t;
+  } laser_state_t;
 #endif
 
 typedef struct {
@@ -261,9 +261,6 @@ typedef struct {
             travel_acceleration;                // (mm/s^2) M204 T - Travel acceleration. DEFAULT ACCELERATION for all NON printing moves.
  feedRate_t min_feedrate_mm_s,                  // (mm/s) M205 S - Minimum linear feedrate
             min_travel_feedrate_mm_s;           // (mm/s) M205 T - Minimum travel feedrate
-  #if ENABLED(LASER_POWER_INLINE)
-    settings_laser_t laser;
-  #endif
 } planner_settings_t;
 
 #if DISABLED(SKEW_CORRECTION)
@@ -334,6 +331,10 @@ class Planner {
 
     static planner_settings_t settings;
 
+    #if ENABLED(LASER_POWER_INLINE)
+      static laser_state_t laser;
+    #endif
+
     static uint32_t max_acceleration_steps_per_s2[XYZE_N]; // (steps/s^2) Derived from mm_per_s2
     static float steps_to_mm[XYZE_N];           // Millimeters per step
 
diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp
index 68e75e36e35..4a40e3f22d4 100644
--- a/Marlin/src/module/stepper.cpp
+++ b/Marlin/src/module/stepper.cpp
@@ -2239,11 +2239,11 @@ uint32_t Stepper::block_phase_isr() {
     #if ENABLED(LASER_POWER_INLINE_CONTINUOUS)
       else { // No new block found; so apply inline laser parameters
         // This should mean ending file with 'M5 I' will stop the laser; thus the inline flag isn't needed
-        const uint8_t stat = planner.settings.laser.status;
+        const uint8_t stat = planner.laser.status;
         if (TEST(stat, 0)) {             // Planner controls the laser
           #if ENABLED(SPINDLE_LASER_PWM)
             if (TEST(stat, 1))           // Laser is on
-              cutter.set_ocr_power(planner.settings.laser.power);
+              cutter.set_ocr_power(planner.laser.power);
             else
               cutter.set_power(0);
           #else