From 51da02b7f8b4a691154b9c5c8f982d35beac9883 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 19 Sep 2022 14:20:18 -0400 Subject: thermocouple: Only shutdown on multiple consecutive sensor errors Signed-off-by: Kevin O'Connor --- src/thermocouple.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/thermocouple.c b/src/thermocouple.c index 2022686a..0a06d2a4 100644 --- a/src/thermocouple.c +++ b/src/thermocouple.c @@ -28,6 +28,7 @@ struct thermocouple_spi { uint32_t min_value; // Min allowed ADC value uint32_t max_value; // Max allowed ADC value struct spidev_s *spi; + uint8_t max_invalid, invalid_count; uint8_t chip_type, flags; }; @@ -75,11 +76,13 @@ command_query_thermocouple(uint32_t *args) return; spi->min_value = args[3]; spi->max_value = args[4]; + spi->max_invalid = args[5]; + spi->invalid_count = 0; sched_add_timer(&spi->timer); } DECL_COMMAND(command_query_thermocouple, "query_thermocouple oid=%c clock=%u rest_ticks=%u" - " min_value=%u max_value=%u"); + " min_value=%u max_value=%u max_invalid_count=%c"); static void thermocouple_respond(struct thermocouple_spi *spi, uint32_t next_begin_time @@ -88,10 +91,13 @@ thermocouple_respond(struct thermocouple_spi *spi, uint32_t next_begin_time sendf("thermocouple_result oid=%c next_clock=%u value=%u fault=%c", oid, next_begin_time, value, fault); /* check the result and stop if below or above allowed range */ - if (value < spi->min_value || value > spi->max_value) - try_shutdown("Thermocouple ADC out of range"); - if (fault) + if (fault || value < spi->min_value || value > spi->max_value) { + spi->invalid_count++; + if (spi->invalid_count < spi->max_invalid) + return; try_shutdown("Thermocouple reader fault"); + } + spi->invalid_count = 0; } static void -- cgit v1.2.3-70-g09d2