QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
EdgeTriggeredCounter.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5namespace QGC {
6
9template <typename CountT = uint8_t>
11{
12public:
13 explicit EdgeTriggeredCounter(CountT threshold) : _threshold(threshold) {}
14
16 bool record()
17 {
18 ++_count;
19 if (_count >= _threshold && !_armed) {
20 _armed = true;
21 return true;
22 }
23 return false;
24 }
25
26 void reset()
27 {
28 _count = 0;
29 _armed = false;
30 }
31
32 CountT count() const { return _count; }
33 bool armed() const { return _armed; }
34
35private:
36 const CountT _threshold;
37 CountT _count = 0;
38 bool _armed = false;
39};
40
41} // namespace QGC
bool record()
Returns true on the rising-edge crossing into >= threshold.
EdgeTriggeredCounter(CountT threshold)