From 6be76af6176676828f69d559d41c02512f0baf74 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Thu, 7 May 2020 14:57:25 -0500
Subject: [PATCH] Overrideable CASE_LIGHT_PIN

---
 Marlin/src/pins/mega/pins_HJC2560C_REV2.h      | 5 ++++-
 Marlin/src/pins/mega/pins_MEGACONTROLLER.h     | 5 ++++-
 Marlin/src/pins/mega/pins_MEGATRONICS.h        | 5 ++++-
 Marlin/src/pins/mega/pins_MEGATRONICS_2.h      | 5 ++++-
 Marlin/src/pins/mega/pins_MEGATRONICS_3.h      | 5 ++++-
 Marlin/src/pins/mega/pins_SILVER_GATE.h        | 5 ++++-
 Marlin/src/pins/rambo/pins_EINSY_RAMBO.h       | 5 ++++-
 Marlin/src/pins/rambo/pins_EINSY_RETRO.h       | 5 ++++-
 Marlin/src/pins/rambo/pins_RAMBO.h             | 5 ++++-
 Marlin/src/pins/ramps/pins_3DRAG.h             | 4 +++-
 Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h    | 4 +++-
 Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h    | 4 +++-
 Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h | 4 +++-
 Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h     | 6 +++++-
 Marlin/src/pins/ramps/pins_MKS_BASE_14.h       | 6 +++++-
 Marlin/src/pins/ramps/pins_RAMPS_OLD.h         | 5 ++++-
 Marlin/src/pins/ramps/pins_RUMBA.h             | 5 ++++-
 Marlin/src/pins/ramps/pins_ULTIMAKER.h         | 5 ++++-
 Marlin/src/pins/sam/pins_ARCHIM2.h             | 4 +++-
 Marlin/src/pins/sanguino/pins_GEN6.h           | 5 ++++-
 Marlin/src/pins/sanguino/pins_GEN7_14.h        | 5 ++++-
 Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h    | 5 ++++-
 Marlin/src/pins/stm32f1/pins_CHITU3D.h         | 5 ++++-
 Marlin/src/pins/teensy2/pins_TEENSY2.h         | 5 ++++-
 Marlin/src/pins/teensy2/pins_TEENSYLU.h        | 5 ++++-
 25 files changed, 97 insertions(+), 25 deletions(-)

diff --git a/Marlin/src/pins/mega/pins_HJC2560C_REV2.h b/Marlin/src/pins/mega/pins_HJC2560C_REV2.h
index 66adfb2fa7..f296f1ba3e 100644
--- a/Marlin/src/pins/mega/pins_HJC2560C_REV2.h
+++ b/Marlin/src/pins/mega/pins_HJC2560C_REV2.h
@@ -103,7 +103,10 @@
 #define SDSS                                  53
 #define SD_DETECT_PIN                         39
 //#define LED_PIN                              8
-#define CASE_LIGHT_PIN                         8  // 8 默认挤出机风扇作为Case LED,如果需要PWM FAN,则需要将FAN_PIN置为7,LED_PIN置为8
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       8  // 8 默认挤出机风扇作为Case LED,如果需要PWM FAN,则需要将FAN_PIN置为7,LED_PIN置为8
+#endif
 
 //#define SAFETY_TRIGGERED_PIN                28  // PIN to detect the safety circuit has triggered
 //#define MAIN_VOLTAGE_MEASURE_PIN            14  // ANALOG PIN to measure the main voltage, with a 100k - 4k7 resitor divider.
diff --git a/Marlin/src/pins/mega/pins_MEGACONTROLLER.h b/Marlin/src/pins/mega/pins_MEGACONTROLLER.h
index 2d0db15825..bcb0f77570 100644
--- a/Marlin/src/pins/mega/pins_MEGACONTROLLER.h
+++ b/Marlin/src/pins/mega/pins_MEGACONTROLLER.h
@@ -128,7 +128,10 @@
 //
 #define SDSS                                  53
 #define LED_PIN                               13
-#define CASE_LIGHT_PIN                         2
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       2
+#endif
 
 //
 // LCD / Controller
diff --git a/Marlin/src/pins/mega/pins_MEGATRONICS.h b/Marlin/src/pins/mega/pins_MEGATRONICS.h
index 4d7a980050..db50dddc7d 100644
--- a/Marlin/src/pins/mega/pins_MEGATRONICS.h
+++ b/Marlin/src/pins/mega/pins_MEGATRONICS.h
@@ -98,7 +98,10 @@
 #define SDSS                                  53
 #define LED_PIN                               13
 #define PS_ON_PIN                             12
-#define CASE_LIGHT_PIN                         2
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       2
+#endif
 
 //
 // LCD / Controller
diff --git a/Marlin/src/pins/mega/pins_MEGATRONICS_2.h b/Marlin/src/pins/mega/pins_MEGATRONICS_2.h
index d976e09816..f3551114e2 100644
--- a/Marlin/src/pins/mega/pins_MEGATRONICS_2.h
+++ b/Marlin/src/pins/mega/pins_MEGATRONICS_2.h
@@ -113,7 +113,10 @@
 #define SDSS                                  53
 #define LED_PIN                               13
 #define PS_ON_PIN                             12
-#define CASE_LIGHT_PIN                         2
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       2
+#endif
 
 //
 // M3/M4/M5 - Spindle/Laser Control
diff --git a/Marlin/src/pins/mega/pins_MEGATRONICS_3.h b/Marlin/src/pins/mega/pins_MEGATRONICS_3.h
index 78dd88809f..3bee7e5f1a 100644
--- a/Marlin/src/pins/mega/pins_MEGATRONICS_3.h
+++ b/Marlin/src/pins/mega/pins_MEGATRONICS_3.h
@@ -132,7 +132,10 @@
 #define SDSS                                  53
 #define LED_PIN                               13
 #define PS_ON_PIN                             12
-#define CASE_LIGHT_PIN                        45  // Try the keypad connector
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      45  // Try the keypad connector
+#endif
 
 //
 // LCD / Controller
diff --git a/Marlin/src/pins/mega/pins_SILVER_GATE.h b/Marlin/src/pins/mega/pins_SILVER_GATE.h
index 351691a09e..dbe473ddb9 100644
--- a/Marlin/src/pins/mega/pins_SILVER_GATE.h
+++ b/Marlin/src/pins/mega/pins_SILVER_GATE.h
@@ -93,4 +93,7 @@
 
 #define STAT_LED_RED_PIN                      23
 #define STAT_LED_BLUE_PIN                     26
-#define CASE_LIGHT_PIN                        51
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      51
+#endif
diff --git a/Marlin/src/pins/rambo/pins_EINSY_RAMBO.h b/Marlin/src/pins/rambo/pins_EINSY_RAMBO.h
index 430fa170e1..630d993d21 100644
--- a/Marlin/src/pins/rambo/pins_EINSY_RAMBO.h
+++ b/Marlin/src/pins/rambo/pins_EINSY_RAMBO.h
@@ -129,7 +129,10 @@
 //
 #define SDSS                                  77
 #define LED_PIN                               13
-#define CASE_LIGHT_PIN                         9
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       9
+#endif
 
 //
 // M3/M4/M5 - Spindle/Laser Control
diff --git a/Marlin/src/pins/rambo/pins_EINSY_RETRO.h b/Marlin/src/pins/rambo/pins_EINSY_RETRO.h
index 6e8463d0bd..ed5b008bf8 100644
--- a/Marlin/src/pins/rambo/pins_EINSY_RETRO.h
+++ b/Marlin/src/pins/rambo/pins_EINSY_RETRO.h
@@ -143,7 +143,10 @@
 //
 #define SDSS                                  53
 #define LED_PIN                               13
-#define CASE_LIGHT_PIN                         9
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       9
+#endif
 
 //
 // M3/M4/M5 - Spindle/Laser Control
diff --git a/Marlin/src/pins/rambo/pins_RAMBO.h b/Marlin/src/pins/rambo/pins_RAMBO.h
index dec72b8ea7..7a61053069 100644
--- a/Marlin/src/pins/rambo/pins_RAMBO.h
+++ b/Marlin/src/pins/rambo/pins_RAMBO.h
@@ -144,7 +144,10 @@
 #define SDSS                                  53
 #define LED_PIN                               13
 #define PS_ON_PIN                              4
-#define CASE_LIGHT_PIN                        46
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      46
+#endif
 
 #ifndef FILWIDTH_PIN
   #define FILWIDTH_PIN                         3  // Analog Input
diff --git a/Marlin/src/pins/ramps/pins_3DRAG.h b/Marlin/src/pins/ramps/pins_3DRAG.h
index 69d2ac2088..974e9ad8b8 100644
--- a/Marlin/src/pins/ramps/pins_3DRAG.h
+++ b/Marlin/src/pins/ramps/pins_3DRAG.h
@@ -44,7 +44,9 @@
 #define RAMPS_D9_PIN                           8
 #define MOSFET_D_PIN                          12
 
-#define CASE_LIGHT_PIN                        -1  // Hardware PWM but one is not available on expansion header
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      -1  // Hardware PWM but one is not available on expansion header
+#endif
 
 #include "pins_RAMPS.h"
 
diff --git a/Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h b/Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h
index 454311b7cc..9939211796 100644
--- a/Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h
+++ b/Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h
@@ -102,7 +102,9 @@
 #undef PS_ON_PIN                                  // 12
 #define PS_ON_PIN                             81  // External Power Supply
 
-#define CASE_LIGHT_PIN                        44  // Hardware PWM
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      44  // Hardware PWM
+#endif
 
 // This board has headers for Z-min, Z-max and IND_S_5V *but* as the bq team
 // decided to ship the printer only with the probe and no additional Z-min
diff --git a/Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h b/Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h
index 8993d0ff57..c95db793c1 100644
--- a/Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h
+++ b/Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h
@@ -172,7 +172,9 @@
   #define PS_ON_PIN                           12
 #endif
 
-#define CASE_LIGHT_PIN                         5
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       5
+#endif
 
 //
 // LCD / Controller
diff --git a/Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h b/Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h
index 4e62c67aaf..d9286e4a01 100644
--- a/Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h
+++ b/Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h
@@ -175,7 +175,9 @@
   #define PS_ON_PIN                           12
 #endif
 
-#define CASE_LIGHT_PIN                         8
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       8
+#endif
 
 //
 // LCD / Controller
diff --git a/Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h b/Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h
index 3846a7649e..2a789a2167 100644
--- a/Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h
+++ b/Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h
@@ -134,12 +134,16 @@
 //
 // Misc. Functions
 //
-#define CASE_LIGHT_PIN                         5
 #define SDSS                                  53
+
 #ifndef LED_PIN
   #define LED_PIN                             13
 #endif
 
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       5
+#endif
+
 #define SPINDLE_LASER_PWM_PIN                 -1  // Hardware PWM
 #define SPINDLE_LASER_ENA_PIN                  4  // Pullup!
 
diff --git a/Marlin/src/pins/ramps/pins_MKS_BASE_14.h b/Marlin/src/pins/ramps/pins_MKS_BASE_14.h
index 057b51a584..0d5929b714 100644
--- a/Marlin/src/pins/ramps/pins_MKS_BASE_14.h
+++ b/Marlin/src/pins/ramps/pins_MKS_BASE_14.h
@@ -38,7 +38,7 @@
 #define FAN_PIN                                9  // PH6 ** Pin18 ** PWM9
 
 // Other Mods
-#define CASE_LIGHT_PIN                        11  // PB5 ** Pin24 ** PWM11
+
 #define SERVO3_PIN                            12  // PB6 ** Pin25 ** D12
 #define PS_ON_PIN                              2  // X+ // PE4 ** Pin6  ** PWM2       **MUST BE HARDWARE PWM
 #define FILWIDTH_PIN                          15  // Y+ // PJ0 ** Pin63 ** USART3_RX  **Pin should have a pullup!
@@ -54,6 +54,10 @@
   #define RGB_LED_B_PIN                       52
 #endif
 
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      11  // PB5 ** Pin24 ** PWM11
+#endif
+
 #include "pins_MKS_BASE_common.h"
 
 /*
diff --git a/Marlin/src/pins/ramps/pins_RAMPS_OLD.h b/Marlin/src/pins/ramps/pins_RAMPS_OLD.h
index 0323366944..b3d1a7ca63 100644
--- a/Marlin/src/pins/ramps/pins_RAMPS_OLD.h
+++ b/Marlin/src/pins/ramps/pins_RAMPS_OLD.h
@@ -106,7 +106,10 @@
 #define SDPOWER_PIN                           48
 #define SDSS                                  53
 #define LED_PIN                               13
-#define CASE_LIGHT_PIN                        45  // Hardware PWM
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      45  // Hardware PWM
+#endif
 
 //
 // M3/M4/M5 - Spindle/Laser Control
diff --git a/Marlin/src/pins/ramps/pins_RUMBA.h b/Marlin/src/pins/ramps/pins_RUMBA.h
index 4bf10d7399..fd220dc5b7 100644
--- a/Marlin/src/pins/ramps/pins_RUMBA.h
+++ b/Marlin/src/pins/ramps/pins_RUMBA.h
@@ -153,7 +153,10 @@
 #define LED_PIN                               13
 #define PS_ON_PIN                             45
 #define KILL_PIN                              46
-#define CASE_LIGHT_PIN                        45
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      45
+#endif
 
 //
 // M3/M4/M5 - Spindle/Laser Control
diff --git a/Marlin/src/pins/ramps/pins_ULTIMAKER.h b/Marlin/src/pins/ramps/pins_ULTIMAKER.h
index 8cc588a2f9..4e666b78ce 100644
--- a/Marlin/src/pins/ramps/pins_ULTIMAKER.h
+++ b/Marlin/src/pins/ramps/pins_ULTIMAKER.h
@@ -111,7 +111,10 @@
 #define LED_PIN                               13
 #define PS_ON_PIN                             12
 #define SUICIDE_PIN                           54  // PIN that has to be turned on right after start, to keep power flowing.
-#define CASE_LIGHT_PIN                         8
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       8
+#endif
 
 //
 // LCD / Controller
diff --git a/Marlin/src/pins/sam/pins_ARCHIM2.h b/Marlin/src/pins/sam/pins_ARCHIM2.h
index d2114ea433..03d5ebef19 100644
--- a/Marlin/src/pins/sam/pins_ARCHIM2.h
+++ b/Marlin/src/pins/sam/pins_ARCHIM2.h
@@ -216,7 +216,9 @@
 
 // Case Light
 
-#define CASE_LIGHT_PIN            GPIO_PB1_J20_5
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN          GPIO_PB1_J20_5
+#endif
 
 // 2MB SPI Flash
 #define SPI_FLASH_SS                          52  // D52 PB21
diff --git a/Marlin/src/pins/sanguino/pins_GEN6.h b/Marlin/src/pins/sanguino/pins_GEN6.h
index 0d2449ae6e..dd00e6f42b 100644
--- a/Marlin/src/pins/sanguino/pins_GEN6.h
+++ b/Marlin/src/pins/sanguino/pins_GEN6.h
@@ -106,7 +106,10 @@
 //
 #define SDSS                                  17
 #define DEBUG_PIN                              0
-#define CASE_LIGHT_PIN                        16  // Hardware PWM
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      16  // Hardware PWM
+#endif
 
 // RS485 pins
 #define TX_ENABLE_PIN                         12
diff --git a/Marlin/src/pins/sanguino/pins_GEN7_14.h b/Marlin/src/pins/sanguino/pins_GEN7_14.h
index 9dc9f2808b..f53563cdec 100644
--- a/Marlin/src/pins/sanguino/pins_GEN7_14.h
+++ b/Marlin/src/pins/sanguino/pins_GEN7_14.h
@@ -102,7 +102,10 @@
 // Misc. Functions
 //
 #define PS_ON_PIN                             15
-#define CASE_LIGHT_PIN                        15  // Hardware PWM
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      15  // Hardware PWM
+#endif
 
 // A pin for debugging
 #define DEBUG_PIN                              0
diff --git a/Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h b/Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h
index 67a9762fa0..a3279eb8e6 100644
--- a/Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h
+++ b/Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h
@@ -104,7 +104,10 @@
 //
 #define SDSS                                  31  // SCL pin of I2C header || CS Pin for SD Card support
 #define PS_ON_PIN                             19
-#define CASE_LIGHT_PIN                        15  // Hardware PWM
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                      15  // Hardware PWM
+#endif
 
 // A pin for debugging
 #define DEBUG_PIN                             -1
diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D.h b/Marlin/src/pins/stm32f1/pins_CHITU3D.h
index b9272c7211..810d916ccf 100644
--- a/Marlin/src/pins/stm32f1/pins_CHITU3D.h
+++ b/Marlin/src/pins/stm32f1/pins_CHITU3D.h
@@ -84,7 +84,10 @@
 //
 #define SDSS                                -1
 #define LED_PIN                             -1
-#define CASE_LIGHT_PIN                      PA8   // 8
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                    PA8   // 8
+#endif
 
 #define PS_ON_PIN                           -1
 #define KILL_PIN                            PD6   // LED strip 24v
diff --git a/Marlin/src/pins/teensy2/pins_TEENSY2.h b/Marlin/src/pins/teensy2/pins_TEENSY2.h
index eb116ee3e8..f72cb2bfd3 100644
--- a/Marlin/src/pins/teensy2/pins_TEENSY2.h
+++ b/Marlin/src/pins/teensy2/pins_TEENSY2.h
@@ -160,7 +160,10 @@
 #define SDSS                                  20  // B0
 #define LED_PIN                                6  // D6
 #define PS_ON_PIN                             27  // B7
-#define CASE_LIGHT_PIN                         1  // D1 PWM2B  MUST BE HARDWARE PWM
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       1  // D1 PWM2B  MUST BE HARDWARE PWM
+#endif
 
 //
 // LCD / Controller
diff --git a/Marlin/src/pins/teensy2/pins_TEENSYLU.h b/Marlin/src/pins/teensy2/pins_TEENSYLU.h
index 05f433cb89..5061b849cf 100644
--- a/Marlin/src/pins/teensy2/pins_TEENSYLU.h
+++ b/Marlin/src/pins/teensy2/pins_TEENSYLU.h
@@ -134,7 +134,10 @@
 // Misc. Functions
 //
 #define SDSS                                  20  // B0 JP31-6
-#define CASE_LIGHT_PIN                         0  // D0 IO-14  PWM0B
+
+#ifndef CASE_LIGHT_PIN
+  #define CASE_LIGHT_PIN                       0  // D0 IO-14  PWM0B
+#endif
 
 //
 // LCD / Controller