diff --git a/src/sensesp/transforms/repeat.h b/src/sensesp/transforms/repeat.h index 0fe0f592a..2da2c0e18 100644 --- a/src/sensesp/transforms/repeat.h +++ b/src/sensesp/transforms/repeat.h @@ -3,6 +3,7 @@ #include +#include "sensesp_base_app.h" #include "sensesp/types/nullable.h" #include "transform.h" @@ -23,29 +24,29 @@ namespace sensesp { * * @param config_path Path to configure this transform in the Config UI. */ -template -class Repeat : public SymmetricTransform { +template +class Repeat : public Transform { public: - Repeat(long interval) : SymmetricTransform(), interval_{interval} {} + Repeat(unsigned long interval) : Transform(), interval_{interval} {} - void set(T input) override { + virtual void set(const FROM& input) override { this->emit(input); if (repeat_event_ != nullptr) { // Delete the old repeat event - repeat_event_->remove(); + repeat_event_->remove(SensESPBaseApp::get_event_loop()); } repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( interval_, [this]() { this->notify(); }); } protected: - long interval_; + unsigned long interval_; reactesp::RepeatEvent* repeat_event_ = nullptr; }; // For compatibility with the old RepeatReport class template -class RepeatReport : public Repeat {}; +class RepeatReport : public Repeat {}; /** * @brief Repeat transform that stops emitting if the value age exceeds @@ -54,10 +55,10 @@ class RepeatReport : public Repeat {}; * @tparam T */ template -class RepeatStopping : public Repeat { +class RepeatStopping : public Repeat { public: - RepeatStopping(long interval, long max_age) - : Repeat(interval), max_age_{max_age} { + RepeatStopping(unsigned long interval, unsigned long max_age) + : Repeat(interval), max_age_{max_age} { age_ = max_age; if (this->repeat_event_ != nullptr) { @@ -81,7 +82,7 @@ class RepeatStopping : public Repeat { protected: elapsedMillis age_; - long max_age_; + unsigned long max_age_; protected: void repeat_function() { @@ -104,15 +105,15 @@ class RepeatStopping : public Repeat { * @tparam T */ template -class RepeatExpiring : public Repeat> { +class RepeatExpiring : public Repeat> { public: - RepeatExpiring(long interval, long max_age) - : Repeat(interval), max_age_{max_age} { + RepeatExpiring(unsigned long interval, unsigned long max_age) + : Repeat>(interval), max_age_{max_age} { age_ = max_age; if (this->repeat_event_ != nullptr) { // Delete the old repeat event - this->repeat_event_->remove(); + this->repeat_event_->remove(SensESPBaseApp::get_event_loop()); } this->repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( this->interval_, [this]() { this->repeat_function(); }); @@ -123,7 +124,7 @@ class RepeatExpiring : public Repeat> { age_ = 0; if (this->repeat_event_ != nullptr) { // Delete the old repeat event - this->repeat_event_->remove(); + this->repeat_event_->remove(SensESPBaseApp::get_event_loop()); } this->repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( this->interval_, [this]() { this->repeat_function(); }); @@ -131,7 +132,7 @@ class RepeatExpiring : public Repeat> { protected: elapsedMillis age_; - long max_age_; + unsigned long max_age_; protected: void repeat_function() { @@ -140,7 +141,7 @@ class RepeatExpiring : public Repeat> { if (age_ < max_age_) { this->notify(); } else { - this->emit(Nullable::invalid()); + this->emit(this->get().invalid()); } }; }; @@ -159,7 +160,7 @@ class RepeatExpiring : public Repeat> { template class RepeatConstantRate : public RepeatExpiring { public: - RepeatConstantRate(long interval, long max_age) + RepeatConstantRate(unsigned long interval, unsigned long max_age) : RepeatExpiring(interval, max_age) { if (this->repeat_event_ != nullptr) { // Delete the old repeat event diff --git a/src/sensesp/types/nullable.cpp b/src/sensesp/types/nullable.cpp index 0da4a40a4..86a124f44 100644 --- a/src/sensesp/types/nullable.cpp +++ b/src/sensesp/types/nullable.cpp @@ -1,14 +1,39 @@ #include "nullable.h" -#include #include +#include namespace sensesp { -template T Nullable::invalid_value_ = T{}; -template <> int Nullable::invalid_value_ = std::numeric_limits::lowest(); -template <> float Nullable::invalid_value_ = std::numeric_limits::lowest(); -template <> double Nullable::invalid_value_ = std::numeric_limits::lowest(); -template <> char Nullable::invalid_value_ = 255; +// Invalid values below are set equal to NMEA 2000 "missing data" values + +template +T Nullable::invalid_value_ = T{}; +template <> +float Nullable::invalid_value_ = -1e9; +template <> +double Nullable::invalid_value_ = -1e9; +template <> +char Nullable::invalid_value_ = 0xff; +template <> +uint8_t Nullable::invalid_value_ = 0xff; +template <> +int8_t Nullable::invalid_value_ = 0x7f; +template <> +uint16_t Nullable::invalid_value_ = 0xffff; +template <> +int16_t Nullable::invalid_value_ = 0x7fff; +template <> +uint32_t Nullable::invalid_value_ = 0xffffffff; +template <> +int32_t Nullable::invalid_value_ = 0x7fffffff; +template <> +uint64_t Nullable::invalid_value_ = 0xffffffffffffffffLL; +template <> +int64_t Nullable::invalid_value_ = 0x7fffffffffffffffLL; + +template <> +bool Nullable::invalid_value_ = false; + } // namespace sensesp diff --git a/src/sensesp/types/nullable.h b/src/sensesp/types/nullable.h index dbb422cf0..ba8cbfc7a 100644 --- a/src/sensesp/types/nullable.h +++ b/src/sensesp/types/nullable.h @@ -52,6 +52,7 @@ class Nullable { typedef Nullable NullableInt; typedef Nullable NullableFloat; typedef Nullable NullableDouble; +typedef Nullable NullableBool; template void convertFromJson(JsonVariantConst src, Nullable &dst) {