diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-07-02 13:47:22 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-07-02 13:56:34 -0400 |
commit | 0dbfa915de5495662102d17c7a11cea219354b91 (patch) | |
tree | 902109825fd2653ca7bd98a259e421522a69280c /src | |
parent | 5b3444c060a51b27fc19ec6386029f00385ba42a (diff) | |
download | kutter-0dbfa915de5495662102d17c7a11cea219354b91.tar.gz kutter-0dbfa915de5495662102d17c7a11cea219354b91.tar.xz kutter-0dbfa915de5495662102d17c7a11cea219354b91.zip |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/adccmds.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/adccmds.c b/src/adccmds.c index 41247a54..09db9b9d 100644 --- a/src/adccmds.c +++ b/src/adccmds.c @@ -15,6 +15,7 @@ struct analog_in { uint32_t rest_time, sample_time, next_begin_time; uint16_t value, min_value, max_value; struct gpio_adc pin; + uint8_t invalid_count, range_check_count; uint8_t state, sample_count; }; @@ -42,8 +43,15 @@ analog_in_event(struct timer *timer) a->timer.waketime += a->sample_time; return SF_RESCHEDULE; } - if (a->value < a->min_value || a->value > a->max_value) - try_shutdown("ADC out of range"); + 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); a->next_begin_time += a->rest_time; a->timer.waketime = a->next_begin_time; @@ -75,13 +83,14 @@ command_query_analog_in(uint32_t *args) a->rest_time = args[4]; a->min_value = args[5]; a->max_value = args[6]; + a->range_check_count = args[7]; if (! a->sample_count) return; sched_add_timer(&a->timer); } DECL_COMMAND(command_query_analog_in, "query_analog_in oid=%c clock=%u sample_ticks=%u sample_count=%c" - " rest_ticks=%u min_value=%hu max_value=%hu"); + " rest_ticks=%u min_value=%hu max_value=%hu range_check_count=%c"); void analog_in_task(void) |