From c305c2cc6bb71283bf675e92c120aa99ceb030b5 Mon Sep 17 00:00:00 2001
From: Jason Smith <jason.inet@gmail.com>
Date: Tue, 14 Jan 2020 23:55:26 -0800
Subject: [PATCH] Fix some warnings, Melzi pins

---
 Marlin/src/feature/dac/stepper_dac.cpp        |  2 +-
 Marlin/src/module/planner.cpp                 |  4 +-
 Marlin/src/module/temperature.cpp             | 14 +--
 Marlin/src/pins/mega/pins_CNCONTROLS_11.h     | 23 +++++
 Marlin/src/pins/mega/pins_CNCONTROLS_12.h     | 23 +++++
 Marlin/src/pins/mega/pins_CNCONTROLS_15.h     | 25 ++++-
 Marlin/src/pins/ramps/pins_RAMPS.h            |  4 +-
 .../src/pins/sanguino/pins_SANGUINOLOLU_11.h  | 95 ++++++++++---------
 Marlin/src/sd/cardreader.cpp                  |  2 +-
 9 files changed, 134 insertions(+), 58 deletions(-)

diff --git a/Marlin/src/feature/dac/stepper_dac.cpp b/Marlin/src/feature/dac/stepper_dac.cpp
index 565b62a392..320e88c69c 100644
--- a/Marlin/src/feature/dac/stepper_dac.cpp
+++ b/Marlin/src/feature/dac/stepper_dac.cpp
@@ -68,7 +68,7 @@ void dac_current_percent(uint8_t channel, float val) {
 void dac_current_raw(uint8_t channel, uint16_t val) {
   if (!dac_present) return;
 
-  NOMORE(val, DAC_STEPPER_MAX);
+  NOMORE(val, uint16_t(DAC_STEPPER_MAX));
 
   mcp4728_analogWrite(dac_order[channel], val);
   mcp4728_simpleCommand(UPDATE);
diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp
index cbd320e4c6..4c3513c20a 100644
--- a/Marlin/src/module/planner.cpp
+++ b/Marlin/src/module/planner.cpp
@@ -1395,7 +1395,7 @@ void Planner::check_axes_activity() {
 
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
         const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
-      #else
+      #elif DISABLED(MESH_BED_LEVELING)
         constexpr float fade_scaling_factor = 1.0;
       #endif
 
@@ -1432,7 +1432,7 @@ void Planner::check_axes_activity() {
 
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
           const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
-        #else
+        #elif DISABLED(MESH_BED_LEVELING)
           constexpr float fade_scaling_factor = 1.0;
         #endif
 
diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp
index 1ff818bd2b..b110afb85a 100644
--- a/Marlin/src/module/temperature.cpp
+++ b/Marlin/src/module/temperature.cpp
@@ -2912,6 +2912,7 @@ void Temperature::tick() {
     ) {
       #if TEMP_RESIDENCY_TIME > 0
         millis_t residency_start_ms = 0;
+        bool first_loop = true;
         // Loop until the temperature has stabilized
         #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
       #else
@@ -2929,7 +2930,7 @@ void Temperature::tick() {
       #endif
 
       float target_temp = -1.0, old_temp = 9999.0;
-      bool wants_to_cool = false, first_loop = true;
+      bool wants_to_cool = false;
       wait_for_heatup = true;
       millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
       do {
@@ -2982,6 +2983,8 @@ void Temperature::tick() {
             residency_start_ms = now;
           }
 
+          first_loop = false;
+
         #endif
 
         // Prevent a wait-forever situation if R is misused i.e. M109 R0
@@ -3002,8 +3005,6 @@ void Temperature::tick() {
           }
         #endif
 
-        first_loop = false;
-
       } while (wait_for_heatup && TEMP_CONDITIONS);
 
       if (wait_for_heatup) {
@@ -3151,6 +3152,7 @@ void Temperature::tick() {
     bool Temperature::wait_for_chamber(const bool no_wait_for_cooling/*=true*/) {
       #if TEMP_CHAMBER_RESIDENCY_TIME > 0
         millis_t residency_start_ms = 0;
+        bool first_loop = true;
         // Loop until the temperature has stabilized
         #define TEMP_CHAMBER_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_CHAMBER_RESIDENCY_TIME) * 1000UL))
       #else
@@ -3159,7 +3161,7 @@ void Temperature::tick() {
       #endif
 
       float target_temp = -1, old_temp = 9999;
-      bool wants_to_cool = false, first_loop = true;
+      bool wants_to_cool = false;
       wait_for_heatup = true;
       millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
 
@@ -3212,6 +3214,7 @@ void Temperature::tick() {
             residency_start_ms = now;
           }
 
+          first_loop = false;
         #endif // TEMP_CHAMBER_RESIDENCY_TIME > 0
 
         // Prevent a wait-forever situation if R is misused i.e. M191 R0
@@ -3224,9 +3227,6 @@ void Temperature::tick() {
             old_temp = temp;
           }
         }
-
-        first_loop = false;
-
       } while (wait_for_heatup && TEMP_CHAMBER_CONDITIONS);
 
       if (wait_for_heatup) ui.reset_status();
diff --git a/Marlin/src/pins/mega/pins_CNCONTROLS_11.h b/Marlin/src/pins/mega/pins_CNCONTROLS_11.h
index 3915c1cfed..d54fbb13b3 100644
--- a/Marlin/src/pins/mega/pins_CNCONTROLS_11.h
+++ b/Marlin/src/pins/mega/pins_CNCONTROLS_11.h
@@ -1,3 +1,26 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#pragma once
+
 /**
  * CartesioV11 pin assignments
  */
diff --git a/Marlin/src/pins/mega/pins_CNCONTROLS_12.h b/Marlin/src/pins/mega/pins_CNCONTROLS_12.h
index b9a96c410b..5628df7f10 100644
--- a/Marlin/src/pins/mega/pins_CNCONTROLS_12.h
+++ b/Marlin/src/pins/mega/pins_CNCONTROLS_12.h
@@ -1,3 +1,26 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#pragma once
+
 /**
  * CartesioV12 pin assignments
  */
diff --git a/Marlin/src/pins/mega/pins_CNCONTROLS_15.h b/Marlin/src/pins/mega/pins_CNCONTROLS_15.h
index 2fad8d576e..c62be6befc 100644
--- a/Marlin/src/pins/mega/pins_CNCONTROLS_15.h
+++ b/Marlin/src/pins/mega/pins_CNCONTROLS_15.h
@@ -1,3 +1,26 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#pragma once
+
 /**
  * CNControls V15 for HMS434 pin assignments
  */
@@ -64,7 +87,7 @@
 //
 // Fans
 //
-#define FAN0_PIN              8
+#define FAN_PIN               8
 #define ORIG_E0_AUTO_FAN_PIN 30
 #define ORIG_E1_AUTO_FAN_PIN 30
 #define ORIG_E2_AUTO_FAN_PIN 30
diff --git a/Marlin/src/pins/ramps/pins_RAMPS.h b/Marlin/src/pins/ramps/pins_RAMPS.h
index 676197b84d..f6ccff24f6 100644
--- a/Marlin/src/pins/ramps/pins_RAMPS.h
+++ b/Marlin/src/pins/ramps/pins_RAMPS.h
@@ -508,7 +508,9 @@
       #ifndef SD_DETECT_PIN
         #define SD_DETECT_PIN   49
       #endif
-      #define KILL_PIN          41
+      #ifndef KILL_PIN
+        #define KILL_PIN        41
+      #endif
 
       #if ENABLED(BQ_LCD_SMART_CONTROLLER)
         #define LCD_BACKLIGHT_PIN 39
diff --git a/Marlin/src/pins/sanguino/pins_SANGUINOLOLU_11.h b/Marlin/src/pins/sanguino/pins_SANGUINOLOLU_11.h
index 9fc7d6f1a2..d6d7efcf70 100644
--- a/Marlin/src/pins/sanguino/pins_SANGUINOLOLU_11.h
+++ b/Marlin/src/pins/sanguino/pins_SANGUINOLOLU_11.h
@@ -156,9 +156,21 @@
 //
 #if HAS_SPI_LCD
 
+  #define SD_DETECT_PIN         -1
+
   #if HAS_GRAPHICAL_LCD
 
-    #if ENABLED(U8GLIB_ST7920) // SPI GLCD 12864 ST7920 ( like [www.digole.com] ) For Melzi V2.0
+    #if ENABLED(LCD_FOR_MELZI)
+
+      #define LCD_PINS_RS       17
+      #define LCD_PINS_ENABLE   16
+      #define LCD_PINS_D4       11
+
+      #define BOARD_ST7920_DELAY_1 DELAY_NS(0)
+      #define BOARD_ST7920_DELAY_2 DELAY_NS(188)
+      #define BOARD_ST7920_DELAY_3 DELAY_NS(0)
+
+    #elif ENABLED(U8GLIB_ST7920) // SPI GLCD 12864 ST7920 ( like [www.digole.com] ) For Melzi V2.0
 
       #if IS_MELZI
         #define LCD_PINS_RS     30   // CS chip select /SS chip slave select
@@ -177,7 +189,7 @@
         #define LCD_PINS_D7     27
       #endif
 
-    #else // DOGM SPI LCD Support
+    #else
 
       #define DOGLCD_A0         30
 
@@ -201,71 +213,64 @@
     #endif
 
     // Uncomment screen orientation
-    #define LCD_SCREEN_ROT_0
+    //#define LCD_SCREEN_ROT_0
     //#define LCD_SCREEN_ROT_90
     //#define LCD_SCREEN_ROT_180
     //#define LCD_SCREEN_ROT_270
 
-  #else // !HAS_GRAPHICAL_LCD
-
-    #define LCD_PINS_RS          4
-    #define LCD_PINS_ENABLE     17
-    #define LCD_PINS_D4         30
-    #define LCD_PINS_D5         29
-    #define LCD_PINS_D6         28
-    #define LCD_PINS_D7         27
+  #elif ENABLED(ZONESTAR_LCD) // For the Tronxy Melzi boards
 
-  #endif // !HAS_GRAPHICAL_LCD
+    #define LCD_PINS_RS    28
+    #define LCD_PINS_ENABLE 29
+    #define LCD_PINS_D4    10
+    #define LCD_PINS_D5    11
+    #define LCD_PINS_D6    16
+    #define LCD_PINS_D7    17
 
-  #if ENABLED(LCD_I2C_PANELOLU2)
+  #else
 
-    #if IS_MELZI
-      #define BTN_ENC           29
-      #define LCD_SDSS          30   // Panelolu2 SD card reader rather than the Melzi
-    #else
-      #define BTN_ENC           30
-    #endif
+    #define LCD_PINS_RS     4
+    #define LCD_PINS_ENABLE 17
+    #define LCD_PINS_D4    30
+    #define LCD_PINS_D5    29
+    #define LCD_PINS_D6    28
+    #define LCD_PINS_D7    27
 
-  #elif ENABLED(LCD_FOR_MELZI)
+  #endif
 
-    #define LCD_PINS_RS         17
-    #define LCD_PINS_ENABLE     16
-    #define LCD_PINS_D4         11
-    #define BTN_ENC             28
-    #define BTN_EN1             29
-    #define BTN_EN2             30
+  #if ENABLED(LCD_FOR_MELZI)
 
-    #define BOARD_ST7920_DELAY_1 DELAY_NS(0)
-    #define BOARD_ST7920_DELAY_2 DELAY_NS(188)
-    #define BOARD_ST7920_DELAY_3 DELAY_NS(0)
+    #define BTN_ENC        28
+    #define BTN_EN1        29
+    #define BTN_EN2        30
 
   #elif ENABLED(ZONESTAR_LCD) // For the Tronxy Melzi boards
 
-    #define LCD_PINS_RS         28
-    #define LCD_PINS_ENABLE     29
-    #define LCD_PINS_D4         10
-    #define LCD_PINS_D5         11
-    #define LCD_PINS_D6         16
-    #define LCD_PINS_D7         17
-    #define ADC_KEYPAD_PIN       1
+    #define ADC_KEYPAD_PIN  1
+    #define BTN_EN1        -1
+    #define BTN_EN2        -1
 
-    #define BTN_EN1             -1
-    #define BTN_EN2             -1
+  #elif ENABLED(LCD_I2C_PANELOLU2)
 
-  #else  // !LCD_I2C_PANELOLU2 && !LCD_FOR_MELZI && !ZONESTAR_LCD
+    #if IS_MELZI
+      #define BTN_ENC      29
+      #define LCD_SDSS     30   // Panelolu2 SD card reader rather than the Melzi
+    #else
+      #define BTN_ENC      30
+    #endif
+
+  #else // !LCD_FOR_MELZI && !ZONESTAR_LCD && !LCD_I2C_PANELOLU2
 
-    #define BTN_ENC             16
-    #define LCD_SDSS            28   // Smart Controller SD card reader rather than the Melzi
+    #define BTN_ENC        16
+    #define LCD_SDSS       28   // Smart Controller SD card reader rather than the Melzi
 
   #endif
 
   #if ENABLED(NEWPANEL) && !defined(BTN_EN1)
-    #define BTN_EN1             11
-    #define BTN_EN2             10
+    #define BTN_EN1        11
+    #define BTN_EN2        10
   #endif
 
-  #define SD_DETECT_PIN         -1
-
 #endif // HAS_SPI_LCD
 
 //
diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp
index ec75206bd7..cb8310f179 100644
--- a/Marlin/src/sd/cardreader.cpp
+++ b/Marlin/src/sd/cardreader.cpp
@@ -678,7 +678,7 @@ void CardReader::selectFileByIndex(const uint16_t nr) {
 //
 void CardReader::selectFileByName(const char * const match) {
   #if ENABLED(SDSORT_CACHE_NAMES)
-    for (int nr = 0; nr < sort_count; nr++)
+    for (uint16_t nr = 0; nr < sort_count; nr++)
       if (strcasecmp(match, sortshort[nr]) == 0) {
         strcpy(filename, sortshort[nr]);
         strcpy(longFilename, sortnames[nr]);
-- 
GitLab