diff --git a/README.md b/README.md index a96190078..2378e4825 100644 --- a/README.md +++ b/README.md @@ -54,12 +54,16 @@ If I want my printer to light itself on fire, I should be able to make my printe - [danger_options: option to configure the homing elapsed distance tolerance](https://github.com/DangerKlippers/danger-klipper/pull/110) +- [danger_options: option to ignore ADC out of range](https://github.com/DangerKlippers/danger-klipper/pull/129) + - [temperature_mcu: add reference_voltage](https://github.com/DangerKlippers/danger-klipper/pull/99) ([klipper#5713](https://github.com/Klipper3d/klipper/pull/5713)) - [stepper: current_change_dwell_time](https://github.com/DangerKlippers/danger-klipper/pull/90) - [homing: min_home_dist](https://github.com/DangerKlippers/danger-klipper/pull/90) +- [adxl345: improve ACCELEROMETER_QUERY command](https://github.com/DangerKlippers/danger-klipper/pull/124) + If you're feeling adventurous, take a peek at the extra features in the bleeding-edge branch: - [dmbutyugin's advanced-features branch](https://github.com/DangerKlippers/danger-klipper/pull/69) [dmbutyugin/advanced-features](https://github.com/dmbutyugin/klipper/commits/advanced-features) @@ -74,8 +78,6 @@ If you're feeling adventurous, take a peek at the extra features in the bleeding - [input_shaper: new print_ringing_tower utility](https://github.com/DangerKlippers/danger-klipper/pull/69) -- [adxl345: improve ACCELEROMETER_QUERY command](https://github.com/DangerKlippers/danger-klipper/pull/124) - ## Switch to Danger Klipper > [!NOTE] diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 57c1d42f0..122f3c3a1 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -110,6 +110,11 @@ A collection of DangerKlipper-specific system options # Tolerance (in mm) for distance moved in the second homing. Ensures the # second homing distance closely matches the `min_home_dist` when using # sensorless homing. The default is 0.5mm. +#adc_ignore_limits: False +# When set to true, this parameter ignores the min_value and max_value +# limits for ADC temperature sensors. It prevents shutdowns due to +# 'ADC out of range' errors by allowing readings outside the specified +# range without triggering a shutdown. Default is False. ``` ## Common kinematic settings diff --git a/klippy/extras/adc_temperature.py b/klippy/extras/adc_temperature.py index 29faf3097..9164f78bd 100644 --- a/klippy/extras/adc_temperature.py +++ b/klippy/extras/adc_temperature.py @@ -15,6 +15,7 @@ REPORT_TIME = 0.300 RANGE_CHECK_COUNT = 4 + # Interface between ADC and heater temperature callbacks class PrinterADCtoTemperature: def __init__(self, config, adc_convert): @@ -24,6 +25,9 @@ def __init__(self, config, adc_convert): self.mcu_adc.setup_adc_callback(REPORT_TIME, self.adc_callback) query_adc = config.get_printer().load_object(config, "query_adc") query_adc.register_adc(config.get_name(), self.mcu_adc) + self.danger_options = config.get_printer().lookup_object( + "danger_options" + ) def setup_callback(self, temperature_callback): self.temperature_callback = temperature_callback @@ -36,13 +40,19 @@ def adc_callback(self, read_time, read_value): self.temperature_callback(read_time + SAMPLE_COUNT * SAMPLE_TIME, temp) def setup_minmax(self, min_temp, max_temp): + if self.danger_options.adc_ignore_limits: + danger_check_count = 0 + else: + danger_check_count = RANGE_CHECK_COUNT + adc_range = [self.adc_convert.calc_adc(t) for t in [min_temp, max_temp]] + self.mcu_adc.setup_minmax( SAMPLE_TIME, SAMPLE_COUNT, minval=min(adc_range), maxval=max(adc_range), - range_check_count=RANGE_CHECK_COUNT, + range_check_count=danger_check_count, ) @@ -50,6 +60,7 @@ def setup_minmax(self, min_temp, max_temp): # Linear interpolation ###################################################################### + # Helper code to perform linear interpolation class LinearInterpolate: def __init__(self, samples): @@ -98,6 +109,7 @@ def reverse_interpolate(self, value): # Linear voltage to temperature converter ###################################################################### + # Linear style conversion chips calibrated from temperature measurements class LinearVoltage: def __init__(self, config, params): @@ -146,6 +158,7 @@ def create(self, config): # Linear resistance to temperature converter ###################################################################### + # Linear resistance calibrated from temperature measurements class LinearResistance: def __init__(self, config, samples): diff --git a/klippy/extras/danger_options.py b/klippy/extras/danger_options.py index 71774a278..7c838f8d2 100644 --- a/klippy/extras/danger_options.py +++ b/klippy/extras/danger_options.py @@ -22,6 +22,7 @@ def __init__(self, config): self.homing_elapsed_distance_tolerance = config.getfloat( "homing_elapsed_distance_tolerance", 0.5, minval=0.0 ) + self.adc_ignore_limits = config.getboolean("adc_ignore_limits", False) def load_config(config): diff --git a/src/adccmds.c b/src/adccmds.c index a27dc8c06..5a443aea2 100644 --- a/src/adccmds.c +++ b/src/adccmds.c @@ -43,13 +43,15 @@ analog_in_event(struct timer *timer) a->timer.waketime += a->sample_time; return SF_RESCHEDULE; } - if (likely(a->value >= a->min_value && a->value <= a->max_value)) { - a->invalid_count = 0; - } else { - a->invalid_count++; - if (a->invalid_count >= a->range_check_count) { - try_shutdown("ADC out of range"); + if (a->range_check_count > 0) { + if (likely(a->value >= a->min_value && a->value <= a->max_value)) { a->invalid_count = 0; + } else { + a->invalid_count++; + if (a->invalid_count >= a->range_check_count) { + try_shutdown("ADC out of range"); + a->invalid_count = 0; + } } } sched_wake_task(&analog_wake); diff --git a/test/klippy/danger_options.cfg b/test/klippy/danger_options.cfg index 84bfd7c29..d7c1ad731 100644 --- a/test/klippy/danger_options.cfg +++ b/test/klippy/danger_options.cfg @@ -8,6 +8,7 @@ log_bed_mesh_at_startup: False log_shutdown_info: False allow_plugin_override: True multi_mcu_trsync_timeout: 0.05 +adc_ignore_limits: True [stepper_x] step_pin: PF0