diff --git a/src/lib/hysteresis/hysteresis.cpp b/src/lib/hysteresis/hysteresis.cpp index 22593b2d6e..3cadc7b7ea 100644 --- a/src/lib/hysteresis/hysteresis.cpp +++ b/src/lib/hysteresis/hysteresis.cpp @@ -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) { diff --git a/src/lib/hysteresis/hysteresis.h b/src/lib/hysteresis/hysteresis.h index 9c16ce4933..850d204825 100644 --- a/src/lib/hysteresis/hysteresis.h +++ b/src/lib/hysteresis/hysteresis.h @@ -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