-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
temperature_mcu: Enhance "ADC out of range" error reports
Try to report which ADC is reporting out of range. Signed-off-by: Kevin O'Connor <[email protected]>
- Loading branch information
1 parent
2d73211
commit 6d70050
Showing
1 changed file
with
10 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
# Support for micro-controller chip based temperature sensors | ||
# | ||
# Copyright (C) 2020 Kevin O'Connor <[email protected]> | ||
# Copyright (C) 2020-2024 Kevin O'Connor <[email protected]> | ||
# | ||
# This file may be distributed under the terms of the GNU GPLv3 license. | ||
import logging | ||
import mcu | ||
from . import adc_temperature | ||
|
||
SAMPLE_TIME = 0.001 | ||
SAMPLE_COUNT = 8 | ||
|
@@ -31,8 +32,8 @@ def __init__(self, config): | |
self.mcu_adc = ppins.setup_pin('adc', | ||
'%s:ADC_TEMPERATURE' % (mcu_name,)) | ||
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.diag_helper = adc_temperature.HelperTemperatureDiagnostics( | ||
config, self.mcu_adc, self.calc_temp) | ||
# Register callbacks | ||
if self.printer.get_start_args().get('debugoutput') is not None: | ||
self.mcu_adc.setup_adc_sample(SAMPLE_TIME, SAMPLE_COUNT) | ||
|
@@ -51,6 +52,8 @@ def setup_minmax(self, min_temp, max_temp): | |
def adc_callback(self, read_time, read_value): | ||
temp = self.base_temperature + read_value * self.slope | ||
self.temperature_callback(read_time + SAMPLE_COUNT * SAMPLE_TIME, temp) | ||
def calc_temp(self, adc): | ||
return self.base_temperature + adc * self.slope | ||
def calc_adc(self, temp): | ||
return (temp - self.base_temperature) / self.slope | ||
def calc_base(self, temp, adc): | ||
|
@@ -91,9 +94,12 @@ def handle_mcu_identify(self): | |
self.base_temperature = self.calc_base(self.temp1, self.adc1) | ||
# Setup min/max checks | ||
arange = [self.calc_adc(t) for t in [self.min_temp, self.max_temp]] | ||
min_adc, max_adc = sorted(arange) | ||
self.mcu_adc.setup_adc_sample(SAMPLE_TIME, SAMPLE_COUNT, | ||
minval=min(arange), maxval=max(arange), | ||
minval=min_adc, maxval=max_adc, | ||
range_check_count=RANGE_CHECK_COUNT) | ||
self.diag_helper.setup_diag_minmax(self.min_temp, self.max_temp, | ||
min_adc, max_adc) | ||
def config_unknown(self): | ||
raise self.printer.config_error("MCU temperature not supported on %s" | ||
% (self.mcu_type,)) | ||
|