cgnuino
|
Logs arbitrary boolean change in a similar way to CgnDI class. More...
#include <cgnuino.h>
Public Member Functions | |
CgnLogger (bool=false, byte=NULL, byte=0) | |
Constructor. More... | |
void | update (bool) |
Updates boolean buffer by current value. More... | |
bool | on () |
Checks whether current value is true . | |
bool | off () |
Checks whether current value is false . | |
bool | turnon () |
Checks whether the buffer turned on in current loop. | |
bool | turnoff () |
Checks whether the buffer turned off in current loop. | |
bool | change () |
Checks whether the buffer was changed from previous loop. | |
bool | keep () |
Checks whether the buffer kept unchanged from previous loop. | |
CgnLogger class provides an easy way to log and monitor changes of arbitrary boolean values in a similar way to CgnDI class. In case of CgnDI class, current states (high/low values) of digital-in pins are collected, while storing the previous values. This way not only the present values but also the changes of the pin states can be detected. CgnLogger class does the same thing to any boolean value that is provided once in each loop. You need to provide a boolean value to CgnLogger class by using update
method at the beginning of each loop in normal. Then you can use the same methods to CgnDI class to check the value changes.
For example, there are cases that you want to first get a value from an analog-in pin, judge the obtained value on your own arbitrary criteria, then monitor the changes of resulting boolean (true/false). This cannot be directly done by CgnDI class since the input value is not digitized. Thus you need CgnLogger class to utilize the same facility to CgnDI class in the case that a boolean variable is the target of tracking.
Like CgnDI, CgnLogger class also has a debounce mechanism that prevents secondary value change shortly after once a change has occured. Since CgnLogger class does not deal with actual digital inputs (which can have occasional mechanical noizes), debouncing is essentially nonsense for this class. This is why the length of debounce is set to 0
by default. However, it is possible that the logged boolean value is judged from some noizy signal (like the usage of analog-in pin in the example above), which can cause quick and repetitive true/false alternation at the time of changes. In such cases, you can use debouncing to prevent restless value changes also in CgnLogger class.
CgnLogger::CgnLogger | ( | bool | initBool = false , |
byte | relaidPin = NULL , |
||
byte | debounceMs = 0 |
||
) |
initBool | Initial value of the logged boolean. |
relaidPin | Pin number for relaied output pin. |
debounceMs | Delay intervened after a bit change in [ms]. |
void CgnLogger::update | ( | bool | newBool | ) |
newBool | New value of the logged boolean. |
loop
function.