adccmds: Add support for min/max temperature check filtering

Extend the ADC out of range check so that it is possible to sample
multiple times before going into a shutdown state.  This reduces the
chance that measurement noise will cause an error.  In an actual over
temperature (or under temperature event) it is expected that the
sensor will consistently report the problem, so extra checks for an
additional second or two should not substantially increase risk.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-02 13:47:22 -04:00
parent 5b3444c060
commit 0dbfa915de
4 changed files with 25 additions and 9 deletions

View file

@ -350,17 +350,19 @@ class MCU_adc:
self._pin = pin_params['pin']
self._min_sample = self._max_sample = 0.
self._sample_time = self._report_time = 0.
self._sample_count = 0
self._sample_count = self._range_check_count = 0
self._report_clock = 0
self._oid = self._callback = None
self._inv_max_adc = 0.
def get_mcu(self):
return self._mcu
def setup_minmax(self, sample_time, sample_count, minval=0., maxval=1.):
def setup_minmax(self, sample_time, sample_count,
minval=0., maxval=1., range_check_count=0):
self._sample_time = sample_time
self._sample_count = sample_count
self._min_sample = minval
self._max_sample = maxval
self._range_check_count = range_check_count
def setup_adc_callback(self, report_time, callback):
self._report_time = report_time
self._callback = callback
@ -381,9 +383,10 @@ class MCU_adc:
math.ceil(self._max_sample * max_adc))))
self._mcu.add_config_cmd(
"query_analog_in oid=%d clock=%d sample_ticks=%d sample_count=%d"
" rest_ticks=%d min_value=%d max_value=%d" % (
" rest_ticks=%d min_value=%d max_value=%d range_check_count=%d" % (
self._oid, clock, sample_ticks, self._sample_count,
self._report_clock, min_sample, max_sample), is_init=True)
self._report_clock, min_sample, max_sample,
self._range_check_count), is_init=True)
self._mcu.register_msg(self._handle_analog_in_state, "analog_in_state"
, self._oid)
def _handle_analog_in_state(self, params):