Line |
Branch |
Decision |
Exec |
Source |
1 |
|
|
|
// |
2 |
|
|
|
// Created by kifir on 8/23/24. |
3 |
|
|
|
// |
4 |
|
|
|
|
5 |
|
|
|
#pragma once |
6 |
|
|
|
|
7 |
|
|
|
#include <cmath> |
8 |
|
|
|
|
9 |
|
|
|
class StrictChecker { |
10 |
|
|
|
public: |
11 |
|
|
5008 |
static bool isBefore(float x, float y) { return std::isless(x, y); } |
12 |
|
|
|
}; |
13 |
|
|
|
|
14 |
|
|
|
class UnstrictChecker { |
15 |
|
|
|
public: |
16 |
|
|
262 |
static bool isBefore(float x, float y) { return std::islessequal(x, y); } |
17 |
|
|
|
}; |
18 |
|
|
|
|
19 |
|
|
|
class Hysteresis { |
20 |
|
|
|
public: |
21 |
|
|
|
// returns true if value > rising, false if value < falling, previous if falling < value < rising. |
22 |
|
|
|
template <typename RisingChecker = StrictChecker, typename FallingChecker = StrictChecker> |
23 |
|
|
|
bool test(float value, float rising, float falling); |
24 |
|
|
|
|
25 |
|
|
|
bool test(bool risingCondition, bool fallingCondition); |
26 |
|
|
|
private: |
27 |
|
|
|
bool m_state = false; |
28 |
|
|
|
}; |
29 |
|
|
|
|
30 |
|
|
|
template <typename RisingChecker, typename FallingChecker> |
31 |
|
|
2635 |
bool Hysteresis::test(const float value, const float rising, const float falling) { |
32 |
|
|
2635 |
return test(RisingChecker::isBefore(rising, value), FallingChecker::isBefore(value, falling)); |
33 |
|
|
|
} |
34 |
|
|
|
|