UniSet  2.7.0
Trigger.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // --------------------------------------------------------------------------
21 //--------------------------------------------------------------------------
22 #ifndef UNITRIGGER_H_
23 #define UNITRIGGER_H_
24 //--------------------------------------------------------------------------
25 namespace uniset
26 {
27 
29  class Trigger
30  {
31  public:
32  Trigger(bool initial = false) noexcept
33  {
34  oldstate = initial;
35  }
36 
38  bool hi(bool state) noexcept
39  {
40  if (oldstate != state)
41  {
42  oldstate = state;
43 
44  if (state)
45  return true;
46  }
47 
48  return false;
49  }
51  bool low(bool state) noexcept
52  {
53  if (oldstate != state)
54  {
55  oldstate = state;
56 
57  if (!state)
58  return true;
59  }
60 
61  return false;
62  }
64  bool change(bool state) noexcept
65  {
66  if (oldstate != state)
67  {
68  oldstate = state;
69  return true;
70  }
71 
72  return false;
73  }
74 
75  inline bool get() const noexcept
76  {
77  return oldstate;
78  }
79 
80  private:
81  bool oldstate;
82  };
83  // -------------------------------------------------------------------------
84 } // end of uniset namespace
85 // --------------------------------------------------------------------------
86 #endif
87 // --------------------------------------------------------------------------
Definition: CallbackTimer.h:29
bool change(bool state) noexcept
Definition: Trigger.h:64
Definition: Trigger.h:29
bool hi(bool state) noexcept
Definition: Trigger.h:38
bool low(bool state) noexcept
Definition: Trigger.h:51