aboutsummaryrefslogtreecommitdiffstats
path: root/src/thermocouple.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2022-09-19 14:20:18 -0400
committerKevin O'Connor <kevin@koconnor.net>2022-09-23 11:56:20 -0400
commit51da02b7f8b4a691154b9c5c8f982d35beac9883 (patch)
treebcee33febfda0e9703215e8e5cd6459b1af37dec /src/thermocouple.c
parentec5719585e022492ba89f8f409a2c96740eb16d5 (diff)
downloadkutter-51da02b7f8b4a691154b9c5c8f982d35beac9883.tar.gz
kutter-51da02b7f8b4a691154b9c5c8f982d35beac9883.tar.xz
kutter-51da02b7f8b4a691154b9c5c8f982d35beac9883.zip
thermocouple: Only shutdown on multiple consecutive sensor errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/thermocouple.c')
-rw-r--r--src/thermocouple.c14
1 files changed, 10 insertions, 4 deletions
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