From e41dc273c9d9ee05947ecd66c44c7c7a91868545 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <thinkyhead@users.noreply.github.com>
Date: Fri, 12 May 2023 20:13:12 -0500
Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Update=20config.ini=20and=20scri?=
 =?UTF-8?q?pt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Marlin/config.ini                             | 10 +++++-----
 .../share/PlatformIO/scripts/configuration.py | 20 ++++++++++++++-----
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/Marlin/config.ini b/Marlin/config.ini
index 6d2a49c2edf..17ff3bec7ef 100644
--- a/Marlin/config.ini
+++ b/Marlin/config.ini
@@ -42,7 +42,7 @@ preheat_1_temp_hotend                    = 180
 bang_max                                 = 255
 pidtemp                                  = on
 pid_k1                                   = 0.95
-pid_max                                  = BANG_MAX
+pid_max                                  = 255
 pid_functional_range                     = 10
 
 default_kp                               = 22.20
@@ -96,10 +96,10 @@ step_state_x                             = HIGH
 step_state_y                             = HIGH
 step_state_z                             = HIGH
 
-disable_x                                = false
-disable_y                                = false
-disable_z                                = false
-disable_e                                = false
+disable_x                                = off
+disable_y                                = off
+disable_z                                = off
+disable_e                                = off
 
 proportional_font_ratio                  = 1.0
 default_nominal_filament_dia             = 1.75
diff --git a/buildroot/share/PlatformIO/scripts/configuration.py b/buildroot/share/PlatformIO/scripts/configuration.py
index 3fc43ed6d89..250d9bbd7f1 100644
--- a/buildroot/share/PlatformIO/scripts/configuration.py
+++ b/buildroot/share/PlatformIO/scripts/configuration.py
@@ -18,7 +18,16 @@ def apply_opt(name, val, conf=None):
     if name == "lcd": name, val = val, "on"
 
     # Create a regex to match the option and capture parts of the line
-    regex = re.compile(rf'^(\s*)(//\s*)?(#define\s+)({name}\b)(\s*)(.*?)(\s*)(//.*)?$', re.IGNORECASE)
+    # 1: Indentation
+    # 2: Comment
+    # 3: #define and whitespace
+    # 4: Option name
+    # 5: First space after name
+    # 6: Remaining spaces between name and value
+    # 7: Option value
+    # 8: Whitespace after value
+    # 9: End comment
+    regex = re.compile(rf'^(\s*)(//\s*)?(#define\s+)({name}\b)(\s?)(\s*)(.*?)(\s*)(//.*)?$', re.IGNORECASE)
 
     # Find and enable and/or update all matches
     for file in ("Configuration.h", "Configuration_adv.h"):
@@ -37,10 +46,11 @@ def apply_opt(name, val, conf=None):
                     newline = re.sub(r'^(\s*)(#define)(\s{1,3})?(\s*)', r'\1//\2 \4', line)
                 else:
                     # For options with values, enable and set the value
-                    newline = match[1] + match[3] + match[4] + match[5] + val
-                    if match[8]:
-                        sp = match[7] if match[7] else ' '
-                        newline += sp + match[8]
+                    addsp = '' if match[5] else ' '
+                    newline = match[1] + match[3] + match[4] + match[5] + addsp + val + match[6]
+                    if match[9]:
+                        sp = match[8] if match[8] else ' '
+                        newline += sp + match[9]
                 lines[i] = newline
                 blab(f"Set {name} to {val}")