Hysteresis: enable initializing arrays with default constructor initial state false

This commit is contained in:
Matthias Grob
2025-12-18 13:29:40 +01:00
parent f25997a15b
commit 3e425210e0
2 changed files with 15 additions and 17 deletions
+8 -6
View File
@@ -42,8 +42,12 @@
namespace systemlib
{
void
Hysteresis::set_hysteresis_time_from(const bool from_state, const hrt_abstime new_hysteresis_time_us)
Hysteresis::Hysteresis(bool initial_state)
{
_state = _requested_state = initial_state;
}
void Hysteresis::set_hysteresis_time_from(const bool from_state, const hrt_abstime new_hysteresis_time_us)
{
if (from_state) {
_time_from_true_us = new_hysteresis_time_us;
@@ -53,8 +57,7 @@ Hysteresis::set_hysteresis_time_from(const bool from_state, const hrt_abstime ne
}
}
void
Hysteresis::set_state_and_update(const bool new_state, const hrt_abstime &now_us)
void Hysteresis::set_state_and_update(const bool new_state, const hrt_abstime &now_us)
{
if (new_state != _state) {
if (new_state != _requested_state) {
@@ -69,8 +72,7 @@ Hysteresis::set_state_and_update(const bool new_state, const hrt_abstime &now_us
update(now_us);
}
void
Hysteresis::update(const hrt_abstime &now_us)
void Hysteresis::update(const hrt_abstime &now_us)
{
if (_requested_state != _state) {
+7 -11
View File
@@ -49,12 +49,8 @@ namespace systemlib
class Hysteresis
{
public:
explicit Hysteresis(bool init_state) :
_state(init_state),
_requested_state(init_state)
{}
Hysteresis() = delete; // no default constructor
Hysteresis() = default;
explicit Hysteresis(bool initial_state);
~Hysteresis() = default;
bool get_state() const { return _state; }
@@ -67,13 +63,13 @@ public:
private:
hrt_abstime _last_time_to_change_state{0};
hrt_abstime _last_time_to_change_state = 0;
hrt_abstime _time_from_true_us{0};
hrt_abstime _time_from_false_us{0};
hrt_abstime _time_from_true_us = 0;
hrt_abstime _time_from_false_us = 0;
bool _state;
bool _requested_state;
bool _state = false;
bool _requested_state = false;
};
} // namespace systemlib