Skip to content

Commit

Permalink
Parse config.ini for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 21, 2022
1 parent d041633 commit 11461f2
Show file tree
Hide file tree
Showing 3 changed files with 316 additions and 1 deletion.
202 changes: 202 additions & 0 deletions Marlin/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#
# Marlin Firmware
# config.ini - Options to apply before the build
#
[marlin]
ini_use_config = none

motherboard = BOARD_RAMPS_14_EFB
serial_port = 0
baudrate = 250000

use_watchdog = on
thermal_protection_hotends = on
thermal_protection_hysteresis = 4
thermal_protection_period = 40

bufsize = 4
block_buffer_size = 16
max_cmd_size = 96

extruders = 1
temp_sensor_0 = 1

temp_hysteresis = 3
heater_0_mintemp = 5
heater_0_maxtemp = 275
preheat_1_temp_hotend = 180

bang_max = 255
pidtemp = on
pid_k1 = 0.95
pid_max = BANG_MAX
pid_functional_range = 10

default_kp = 22.20
default_ki = 1.08
default_kd = 114.00

x_driver_type = A4988
y_driver_type = A4988
z_driver_type = A4988
e0_driver_type = A4988

x_bed_size = 200
x_min_pos = 0
x_max_pos = X_BED_SIZE

y_bed_size = 200
y_min_pos = 0
y_max_pos = Y_BED_SIZE

z_min_pos = 0
z_max_pos = 200

x_home_dir = -1
y_home_dir = -1
z_home_dir = -1

use_xmin_plug = on
use_ymin_plug = on
use_zmin_plug = on

x_min_endstop_inverting = false
y_min_endstop_inverting = false
z_min_endstop_inverting = false

default_axis_steps_per_unit = { 80, 80, 400, 500 }
axis_relative_modes = { false, false, false, false }
default_max_feedrate = { 300, 300, 5, 25 }
default_max_acceleration = { 3000, 3000, 100, 10000 }

homing_feedrate_mm_m = { (50*60), (50*60), (4*60) }
homing_bump_divisor = { 2, 2, 4 }

x_enable_on = 0
y_enable_on = 0
z_enable_on = 0
e_enable_on = 0

invert_x_dir = false
invert_y_dir = true
invert_z_dir = false
invert_e0_dir = false

invert_e_step_pin = false
invert_x_step_pin = false
invert_y_step_pin = false
invert_z_step_pin = false

disable_x = false
disable_y = false
disable_z = false
disable_e = false

proportional_font_ratio = 1.0
default_nominal_filament_dia = 1.75

junction_deviation_mm = 0.013

default_acceleration = 3000
default_travel_acceleration = 3000
default_retract_acceleration = 3000

default_minimumfeedrate = 0.0
default_mintravelfeedrate = 0.0

minimum_planner_speed = 0.05
min_steps_per_segment = 6
default_minsegmenttime = 20000

[basic]
bed_overshoot = 10
busy_while_heating = on
default_ejerk = 5.0
default_keepalive_interval = 2
default_leveling_fade_height = 0.0
disable_inactive_extruder = on
display_charset_hd44780 = JAPANESE
eeprom_boot_silent = on
eeprom_chitchat = on
endstoppullups = on
extrude_maxlength = 200
extrude_mintemp = 170
host_keepalive_feature = on
hotend_overshoot = 15
jd_handle_small_segments = on
lcd_info_screen_style = 0
lcd_language = en
max_bed_power = 255
mesh_inset = 0
min_software_endstops = on
max_software_endstops = on
min_software_endstop_x = on
min_software_endstop_y = on
min_software_endstop_z = on
max_software_endstop_x = on
max_software_endstop_y = on
max_software_endstop_z = on
preheat_1_fan_speed = 0
preheat_1_label = "PLA"
preheat_1_temp_bed = 70
preheat_2_fan_speed = 0
preheat_2_label = "ABS"
preheat_2_temp_bed = 110
preheat_2_temp_hotend = 240
prevent_cold_extrusion = on
prevent_lengthy_extrude = on
printjob_timer_autostart = on
probing_margin = 10
show_bootscreen = on
soft_pwm_scale = 0
string_config_h_author = "(none, default config)"
temp_bed_hysteresis = 3
temp_bed_residency_time = 10
temp_bed_window = 1
temp_residency_time = 10
temp_window = 1
validate_homing_endstops = on
xy_probe_feedrate = (133*60)
z_clearance_between_probes = 5
z_clearance_deploy_probe = 10
z_clearance_multi_probe = 5

[advanced]
arc_support = on
auto_report_temperatures = on
autotemp = on
autotemp_oldweight = 0.98
bed_check_interval = 5000
default_stepper_deactive_time = 120
default_volumetric_extruder_limit = 0.00
disable_inactive_e = true
disable_inactive_x = true
disable_inactive_y = true
disable_inactive_z = true
e0_auto_fan_pin = -1
encoder_100x_steps_per_sec = 80
encoder_10x_steps_per_sec = 30
encoder_rate_multiplier = on
extended_capabilities_report = on
extruder_auto_fan_speed = 255
extruder_auto_fan_temperature = 50
fanmux0_pin = -1
fanmux1_pin = -1
fanmux2_pin = -1
faster_gcode_parser = on
homing_bump_mm = { 5, 5, 2 }
max_arc_segment_mm = 1.0
min_arc_segment_mm = 0.1
min_circle_segments = 72
n_arc_correction = 25
serial_overrun_protection = on
slowdown = on
slowdown_divisor = 2
temp_sensor_bed = 0
thermal_protection_bed_hysteresis = 2
thermocouple_max_errors = 15
tx_buffer_size = 0
watch_bed_temp_increase = 2
watch_bed_temp_period = 60
watch_temp_increase = 2
watch_temp_period = 20
111 changes: 111 additions & 0 deletions buildroot/share/PlatformIO/scripts/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# configuration.py
# Apply options from config.ini to the existing Configuration headers
#
import pioutil
if pioutil.is_pio_build():

import subprocess,os,re
Import("env")

from platformio.project.config import ProjectConfig

verbose = 0
try:
verbose = int(env.GetProjectOption('custom_verbose'))
except:
pass

def blab(str,level=1):
if verbose >= level:
print("[config] %s" % str)

# apply a single name = on/off ; name = value ; etc.
# to the given (optional) configuration
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("^(\\s*)(//\\s*)?(#define\\s+)(" + name + "\\b)(\\s*)(.*?)(\\s*)(//.*)?$", re.IGNORECASE)

# Find and enable and/or update all matches
found = False
for file in ("Configuration.h", "Configuration_adv.h"):
fullpath = os.path.join("Marlin", file)
with open(fullpath, "r") as f:
lines = f.readlines()
for line in lines:
match = regex.match(line)
if match:
if match.group(4).upper() == name.upper():
# For boolean options un/comment the define
if val in ("on", "", None):
newline = line.replace("//#define", "#define")
elif val == "off":
newline = line.replace("#define", "//#define").replace("////#", "//#")

# For options with values, enable and set the value
else:
newline = match.group(1) + match.group(3) + match.group(4) + match.group(5) + val
if match.group(8):
sp = match.group(7) if match.group(7) else ' '
newline += sp + match.group(8)
newline += "\n"
lines[lines.index(line)] = newline
found = True
blab("Set %s to %s" % (name, val))

# If the option was found, write the modified lines
if found:
with open(fullpath, "w") as f:
f.writelines(lines)
break

# If the option didn't appear in either config file, add it
if not found:
added = name.upper() if name == name.lower() else name
if val != "on" and val != "" and val is not None:
added += " " + val

# Prepend the new option after the first set of #define lines
fullpath = os.path.join("Marlin", "Configuration.h")
with open(fullpath, "r") as f:
lines = f.readlines()
linenum = 0
gotdef = False
for line in lines:
isdef = line.startswith("#define")
if not gotdef:
gotdef = isdef
elif not isdef:
break
linenum += 1
lines.insert(linenum, "#define %s // Added by configuration.py\n" % added)
with open(fullpath, "w") as f:
f.writelines(lines)

# Get settings from config.ini sections
def apply_config_ini():
blab("========== Gather 'config.ini' entries...")
proceed = 'root'
for item in ProjectConfig().items('marlin'):
if item[0] == 'ini_use_config':
proceed = item[1]

if proceed in ('all', 'base', 'root'):
for item in ProjectConfig().items('marlin'):
if not item[0].startswith('ini_'):
apply_opt(item[0], item[1])
if proceed in ('all', 'basic'):
for item in ProjectConfig().items('basic'):
apply_opt(item[0], item[1], '')
if proceed in ('all', 'adv', 'advanced'):
for item in ProjectConfig().items('advanced'):
apply_opt(item[0], item[1], 'adv')

#
# Apply config.ini to the (base) configurations
#
apply_config_ini()
4 changes: 3 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ boards_dir = buildroot/share/PlatformIO/boards
default_envs = mega2560
include_dir = Marlin
extra_configs =
Marlin/config.ini
ini/avr.ini
ini/due.ini
ini/esp32.ini
Expand Down Expand Up @@ -44,12 +45,13 @@ extra_configs =
build_flags = -g3 -D__MARLIN_FIRMWARE__ -DNDEBUG
-fmax-errors=5
extra_scripts =
pre:buildroot/share/PlatformIO/scripts/configuration.py
pre:buildroot/share/PlatformIO/scripts/common-dependencies.py
pre:buildroot/share/PlatformIO/scripts/common-cxxflags.py
pre:buildroot/share/PlatformIO/scripts/preflight-checks.py
post:buildroot/share/PlatformIO/scripts/common-dependencies-post.py
lib_deps =
default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared> -<Marlin/Marlin.ino>
-<src/lcd/HD44780> -<src/lcd/TFTGLCD> -<src/lcd/dogm> -<src/lcd/tft> -<src/lcd/tft_io>
-<src/HAL/STM32/tft> -<src/HAL/STM32F1/tft>
-<src/lcd/e3v2/common> -<src/lcd/e3v2/creality> -<src/lcd/e3v2/proui> -<src/lcd/e3v2/jyersui> -<src/lcd/e3v2/marlinui>
Expand Down

0 comments on commit 11461f2

Please sign in to comment.