hall_filament_width_sensor: Add config validation

Adds two checks to prevent config settings which could lead to div-by-zero errors in specific circumstances:

- `raw_dia1` and `raw_dia2` must be different to prevent a possible exception in `adc2_callback`

- `max_difference` must be less than `default_nominal_filament_diameter` to prevent a possible exception in `extrude_factor_update_event`

Doc is also updated.

Signed-off-by: Ben Lye ben@lye.co.nz
This commit is contained in:
Ben Lye authored and KevinOConnor committed 2026-04-08 14:57:04 -04:00
1 parent e75c281f52
commit 48446a5448
2 files changed
+12 -3

No files matched your search

+4 -3
View File
@@ -5095,15 +5095,16 @@ adc2:
# 1.50 for cal_dia1 and 2.00 for cal_dia2.
#raw_dia1: 9500
#raw_dia2: 10500
# The raw calibration values for the sensors. The default is 9500
# for raw_dia1 and 10500 for raw_dia2.
# The raw calibration values for the sensors. The values must be
# different. The default is 9500 for raw_dia1 and 10500 for raw_dia2.
#default_nominal_filament_diameter: 1.75
# The nominal filament diameter. This parameter must be provided.
#max_difference: 0.200
# Maximum allowed filament diameter difference in millimeters (mm).
# If difference between nominal filament diameter and sensor output
# is more than +- max_difference, extrusion multiplier is set back
# to %100. The default is 0.200.
# to 100%. Must be less than default_nominal_filament_diameter.
# The default is 0.200.
#measurement_delay: 70
# The distance from sensor to the melting chamber/hot-end in
# millimeters (mm). The filament between the sensor and the hot-end
@@ -39,6 +39,14 @@ class HallFilamentWidthSensor:
# measurement isn't in place
self.use_current_dia_while_delay = config.getboolean(
'use_current_dia_while_delay', False)
if self.rawdia1 == self.rawdia2:
raise config.error(
"hall_filament_width_sensor: raw_dia1 and raw_dia2 must be"
" different")
if self.min_diameter <= 0:
raise config.error(
"hall_filament_width_sensor: max_difference must be less than"
" default_nominal_filament_diameter")
# filament array [position, filamentWidth]
self.filament_array = []
self.lastFilamentWidthReading = 0