From efaff241455e879b2bb7f3e499f3cadca1bcbb70 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <thinkyhead@users.noreply.github.com>
Date: Mon, 25 Jan 2021 08:32:58 -0600
Subject: [PATCH] Apply SEC_TO_MS and other fixes

---
 Marlin/src/MarlinCore.cpp                   | 1 +
 Marlin/src/core/macros.h                    | 1 +
 Marlin/src/gcode/control/M80_M81.cpp        | 3 ++-
 Marlin/src/gcode/feature/L6470/M916-918.cpp | 2 +-
 Marlin/src/gcode/parser.h                   | 2 +-
 Marlin/src/module/printcounter.cpp          | 7 ++++---
 Marlin/src/module/printcounter.h            | 5 +----
 Marlin/src/module/temperature.cpp           | 1 -
 Marlin/src/module/tool_change.cpp           | 4 ++--
 Marlin/src/pins/lpc1768/pins_MKS_SBASE.h    | 2 +-
 10 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp
index 31959dbda38..4732afbb87f 100644
--- a/Marlin/src/MarlinCore.cpp
+++ b/Marlin/src/MarlinCore.cpp
@@ -783,6 +783,7 @@ void minkill(const bool steppers_off/*=false*/) {
  */
 void stop() {
   thermalManager.disable_all_heaters(); // 'unpause' taken care of in here
+
   print_job_timer.stop();
 
   #if ENABLED(PROBING_FANS_OFF)
diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h
index d5b3342437e..63ef5970349 100644
--- a/Marlin/src/core/macros.h
+++ b/Marlin/src/core/macros.h
@@ -162,6 +162,7 @@
 #define _DO_12(W,C,A,V...) (_##W##_1(A) C _DO_11(W,C,V))
 #define _DO_13(W,C,A,V...) (_##W##_1(A) C _DO_12(W,C,V))
 #define _DO_14(W,C,A,V...) (_##W##_1(A) C _DO_13(W,C,V))
+#define _DO_15(W,C,A,V...) (_##W##_1(A) C _DO_14(W,C,V))
 #define __DO_N(W,C,N,V...) _DO_##N(W,C,V)
 #define _DO_N(W,C,N,V...)  __DO_N(W,C,N,V)
 #define DO(W,C,V...)       (_DO_N(W,C,NUM_ARGS(V),V))
diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp
index ea0f9c2b139..394b06d8ac3 100644
--- a/Marlin/src/gcode/control/M80_M81.cpp
+++ b/Marlin/src/gcode/control/M80_M81.cpp
@@ -89,9 +89,10 @@
  */
 void GcodeSuite::M81() {
   thermalManager.disable_all_heaters();
-  print_job_timer.stop();
   planner.finish_and_disable();
 
+  print_job_timer.stop();
+
   #if HAS_FAN
     thermalManager.zero_fan_speeds();
     #if ENABLED(PROBING_FANS_OFF)
diff --git a/Marlin/src/gcode/feature/L6470/M916-918.cpp b/Marlin/src/gcode/feature/L6470/M916-918.cpp
index 2672f912398..8a1ea483060 100644
--- a/Marlin/src/gcode/feature/L6470/M916-918.cpp
+++ b/Marlin/src/gcode/feature/L6470/M916-918.cpp
@@ -119,7 +119,7 @@ void GcodeSuite::M916() {
     M91x_counter_max = 256;  // KVAL_HOLD is 8 bits
 
   uint8_t M91x_delay_s = parser.byteval('D');   // get delay in seconds
-  millis_t M91x_delay_ms = M91x_delay_s * 60 * 1000;
+  millis_t M91x_delay_ms = SEC_TO_MS(M91x_delay_s * 60);
   millis_t M91x_delay_end;
 
   DEBUG_ECHOLNPGM(".\n.");
diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h
index 8633d2b1e9d..cf531c4e470 100644
--- a/Marlin/src/gcode/parser.h
+++ b/Marlin/src/gcode/parser.h
@@ -282,7 +282,7 @@ public:
 
   // Code value for use as time
   static inline millis_t value_millis() { return value_ulong(); }
-  static inline millis_t value_millis_from_seconds() { return (millis_t)(value_float() * 1000); }
+  static inline millis_t value_millis_from_seconds() { return (millis_t)SEC_TO_MS(value_float()); }
 
   // Reduce to fewer bits
   static inline int16_t value_int() { return (int16_t)value_long(); }
diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp
index ab87717f011..5da1d09c75b 100644
--- a/Marlin/src/module/printcounter.cpp
+++ b/Marlin/src/module/printcounter.cpp
@@ -224,9 +224,12 @@ void PrintCounter::tick() {
 
   millis_t now = millis();
 
-  static uint32_t update_next; // = 0
+  static millis_t update_next; // = 0
   if (ELAPSED(now, update_next)) {
+    update_next = now + updateInterval;
+
     TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("tick")));
+
     millis_t delta = deltaDuration();
     data.printTime += delta;
 
@@ -239,8 +242,6 @@ void PrintCounter::tick() {
     #if SERVICE_INTERVAL_3 > 0
       data.nextService3 -= _MIN(delta, data.nextService3);
     #endif
-
-    update_next = now + updateInterval * 1000;
   }
 
   static uint32_t eeprom_next; // = 0
diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h
index 66d8cbb7b38..f7fc96c579a 100644
--- a/Marlin/src/module/printcounter.h
+++ b/Marlin/src/module/printcounter.h
@@ -71,11 +71,8 @@ class PrintCounter: public Stopwatch {
      * @brief Interval in seconds between counter updates
      * @details This const value defines what will be the time between each
      * accumulator update. This is different from the EEPROM save interval.
-     *
-     * @note The max value for this option is 60(s), otherwise integer
-     * overflow will happen.
      */
-    static constexpr uint16_t updateInterval = 10;
+    static constexpr millis_t updateInterval = SEC_TO_MS(10);
 
     /**
      * @brief Interval in seconds between EEPROM saves
diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp
index 00a048736a6..589baf77962 100644
--- a/Marlin/src/module/temperature.cpp
+++ b/Marlin/src/module/temperature.cpp
@@ -2186,7 +2186,6 @@ void Temperature::disable_all_heaters() {
 
 #endif
 
-
 #if ENABLED(PROBING_HEATERS_OFF)
 
   void Temperature::pause(const bool p) {
diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp
index 052b8cd34a6..867ae5d9271 100644
--- a/Marlin/src/module/tool_change.cpp
+++ b/Marlin/src/module/tool_change.cpp
@@ -828,7 +828,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
       // Cool down with fan
       #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
         thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
-        gcode.dwell(toolchange_settings.fan_time * 1000);
+        gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
         thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
       #endif
 
@@ -1102,7 +1102,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
             // Cool down with fan
             #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
               thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
-              gcode.dwell(toolchange_settings.fan_time * 1000);
+              gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
               thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
             #endif
           }
diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h
index ea9748ca548..fbddc66e7ce 100644
--- a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h
+++ b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h
@@ -27,7 +27,7 @@
 
 #if defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1769)
   #error "Oops! Make sure you have the LPC1769 environment selected in your IDE."
-#elif NOT_TARGET(MKS_HAS_LPC1769, MCU_LPC1768)
+#elif !defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1768)
   #error "Oops! Make sure you have the LPC1768 environment selected in your IDE."
 #endif