modm API documentation
debounce.hpp
1 /*
2  * Copyright (c) 2009, Thorsten Lajewski
3  * Copyright (c) 2009-2010, Fabian Greif
4  * Copyright (c) 2012, Niklas Hauser
5  *
6  * This file is part of the modm project.
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11  */
12 // ----------------------------------------------------------------------------
13 
14 #ifndef MODM_FILTER_DEBOUNCE_HPP
15 #define MODM_FILTER_DEBOUNCE_HPP
16 
17 #include <stdint.h>
18 
19 namespace modm
20 {
21  namespace filter
22  {
23  /**
24  * \brief Debouncing binary signals
25  *
26  * \ingroup modm_math_filter
27  */
28  template<typename T = uint8_t>
29  class Debounce
30  {
31  public:
32  /**
33  * \brief Constructor
34  *
35  * \param maxValue maximal value of the sum
36  * \param lowerBound lower bound for the schmitt-trigger
37  * \param upperBound upper bound for the schmitt-trigger. If
38  * set to zero, the value of maxValue is used.
39  */
40  Debounce(const T& maxValue,
41  const T& lowerBound = 0,
42  const T& upperBound = 0);
43 
44  void
45  update(bool input);
46 
47  bool
48  getValue() const;
49 
50  void
51  reset(const bool state);
52 
53  private:
54  const T maxValue;
55  T sum;
56 
57  const T lowerBound;
58  const T upperBound;
59  bool state;
60  };
61  }
62 }
63 
64 #include "debounce_impl.hpp"
65 
66 #endif // MODM_FILTER_DEBOUNCE_HPP
Debounce(const T &maxValue, const T &lowerBound=0, const T &upperBound=0)
Constructor.
Debouncing binary signals.
Definition: debounce.hpp:29