From 707f6539de1ecfd761f385e487fbcc94133e99c5 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sun, 19 Apr 2020 15:19:49 +0200 Subject: [PATCH] added support to change thresholds independently --- trigger.hh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/trigger.hh b/trigger.hh index bd5fb20..4fa0411 100644 --- a/trigger.hh +++ b/trigger.hh @@ -11,19 +11,22 @@ namespace DSP { template class SchmittTrigger { - TYPE threshold; + TYPE low, high; bool previous; public: - constexpr SchmittTrigger(TYPE threshold = TYPE(1)/TYPE(3), bool previous = false) : threshold(threshold), previous(previous) + constexpr SchmittTrigger(TYPE threshold = TYPE(1)/TYPE(3), bool previous = false) : low(-threshold), high(threshold), previous(previous) + { + } + constexpr SchmittTrigger(TYPE low, TYPE high, bool previous = false) : low(low), high(high), previous(previous) { } bool operator() (TYPE input) { if (previous) { - if (input < -threshold) + if (input < low) previous = false; } else { - if (input > threshold) + if (input > high) previous = true; } return previous;