From ea7f3bc57cb329af89e6c0d007ce66b961946252 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 29 Jun 2024 14:29:25 +0300 Subject: [PATCH] Make ValueConsumer::set argument a const ref --- src/sensesp/controllers/smart_switch_controller.cpp | 6 +++--- src/sensesp/controllers/smart_switch_controller.h | 6 +++--- src/sensesp/controllers/system_status_controller.cpp | 4 ++-- src/sensesp/controllers/system_status_controller.h | 4 ++-- src/sensesp/sensors/digital_output.cpp | 2 +- src/sensesp/sensors/digital_output.h | 2 +- src/sensesp/signalk/signalk_output.h | 2 +- src/sensesp/signalk/signalk_put_request.h | 2 +- src/sensesp/system/lambda_consumer.h | 2 +- src/sensesp/system/observablevalue.h | 4 ++-- src/sensesp/system/pwm_output.cpp | 2 +- src/sensesp/system/pwm_output.h | 2 +- src/sensesp/system/rgb_led.cpp | 4 ++-- src/sensesp/system/rgb_led.h | 4 ++-- src/sensesp/system/system_status_led.cpp | 4 ++-- src/sensesp/system/system_status_led.h | 4 ++-- src/sensesp/system/task_queue_producer.h | 2 +- src/sensesp/system/valueconsumer.h | 4 ++-- src/sensesp/system/valueproducer.h | 2 +- src/sensesp/transforms/air_density.cpp | 2 +- src/sensesp/transforms/air_density.h | 2 +- src/sensesp/transforms/analogvoltage.cpp | 2 +- src/sensesp/transforms/analogvoltage.h | 2 +- src/sensesp/transforms/angle_correction.cpp | 2 +- src/sensesp/transforms/angle_correction.h | 2 +- src/sensesp/transforms/change_filter.cpp | 2 +- src/sensesp/transforms/change_filter.h | 2 +- src/sensesp/transforms/click_type.cpp | 2 +- src/sensesp/transforms/click_type.h | 2 +- src/sensesp/transforms/curveinterpolator.cpp | 2 +- src/sensesp/transforms/curveinterpolator.h | 2 +- src/sensesp/transforms/debounce.h | 2 +- src/sensesp/transforms/dew_point.cpp | 2 +- src/sensesp/transforms/dew_point.h | 2 +- src/sensesp/transforms/difference.cpp | 2 +- src/sensesp/transforms/difference.h | 2 +- src/sensesp/transforms/frequency.cpp | 2 +- src/sensesp/transforms/frequency.h | 2 +- src/sensesp/transforms/heat_index.cpp | 4 ++-- src/sensesp/transforms/heat_index.h | 4 ++-- src/sensesp/transforms/integrator.h | 2 +- src/sensesp/transforms/lambda_transform.h | 2 +- src/sensesp/transforms/median.cpp | 2 +- src/sensesp/transforms/median.h | 2 +- src/sensesp/transforms/moving_average.cpp | 2 +- src/sensesp/transforms/moving_average.h | 2 +- src/sensesp/transforms/press_repeater.cpp | 4 ++-- src/sensesp/transforms/press_repeater.h | 4 ++-- src/sensesp/transforms/repeat.h | 4 ++-- src/sensesp/transforms/threshold.cpp | 2 +- src/sensesp/transforms/threshold.h | 2 +- src/sensesp/transforms/throttle.h | 2 +- src/sensesp/transforms/time_counter.h | 2 +- src/sensesp/transforms/timestring.cpp | 2 +- src/sensesp/transforms/timestring.h | 2 +- src/sensesp/transforms/truth_text.cpp | 4 ++-- src/sensesp/transforms/truth_text.h | 4 ++-- src/sensesp/transforms/voltage_multiplier.cpp | 2 +- src/sensesp/transforms/voltage_multiplier.h | 2 +- src/sensesp/transforms/voltagedivider.cpp | 4 ++-- src/sensesp/transforms/voltagedivider.h | 4 ++-- src/sensesp/ui/ui_output.h | 2 +- 62 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/sensesp/controllers/smart_switch_controller.cpp b/src/sensesp/controllers/smart_switch_controller.cpp index 685ec6262..dc9b18578 100644 --- a/src/sensesp/controllers/smart_switch_controller.cpp +++ b/src/sensesp/controllers/smart_switch_controller.cpp @@ -26,12 +26,12 @@ SmartSwitchController::SmartSwitchController(bool auto_initialize, } } -void SmartSwitchController::set(bool new_value) { +void SmartSwitchController::set(const bool& new_value) { is_on = new_value; this->emit(is_on); } -void SmartSwitchController::set(ClickTypes new_value) { +void SmartSwitchController::set(const ClickTypes& new_value) { if (!ClickType::is_click(new_value)) { // Ignore button presses (we only want interpreted clicks) return; @@ -56,7 +56,7 @@ void SmartSwitchController::set(ClickTypes new_value) { } } -void SmartSwitchController::set(String new_value) { +void SmartSwitchController::set(const String& new_value) { if (TextToTruth::is_valid_true(new_value)) { is_on = true; } else if (TextToTruth::is_valid_false(new_value)) { diff --git a/src/sensesp/controllers/smart_switch_controller.h b/src/sensesp/controllers/smart_switch_controller.h index ecc937f67..78b76dcc3 100644 --- a/src/sensesp/controllers/smart_switch_controller.h +++ b/src/sensesp/controllers/smart_switch_controller.h @@ -61,9 +61,9 @@ class SmartSwitchController : public BooleanTransform, */ SmartSwitchController(bool auto_initialize = true, String config_path = "", const char* sk_sync_paths[] = NULL); - void set(bool new_value) override; - void set(String new_value) override; - void set(ClickTypes new_value) override; + void set(const bool& new_value) override; + void set(const String& new_value) override; + void set(const ClickTypes& new_value) override; // For reading and writing the configuration of this transformation virtual void get_configuration(JsonObject& doc) override; diff --git a/src/sensesp/controllers/system_status_controller.cpp b/src/sensesp/controllers/system_status_controller.cpp index cd37a1f01..ac1141f11 100644 --- a/src/sensesp/controllers/system_status_controller.cpp +++ b/src/sensesp/controllers/system_status_controller.cpp @@ -2,7 +2,7 @@ namespace sensesp { -void SystemStatusController::set(WiFiState new_value) { +void SystemStatusController::set(const WiFiState& new_value) { // FIXME: If pointers to member functions would be held in an array, // this would be a simple array dereferencing switch (new_value) { @@ -22,7 +22,7 @@ void SystemStatusController::set(WiFiState new_value) { } } -void SystemStatusController::set(SKWSConnectionState new_value) { +void SystemStatusController::set(const SKWSConnectionState& new_value) { switch (new_value) { case SKWSConnectionState::kSKWSDisconnected: if (current_state_ != SystemStatus::kWifiDisconnected && diff --git a/src/sensesp/controllers/system_status_controller.h b/src/sensesp/controllers/system_status_controller.h index 8407ef35e..2dbf409f9 100644 --- a/src/sensesp/controllers/system_status_controller.h +++ b/src/sensesp/controllers/system_status_controller.h @@ -32,10 +32,10 @@ class SystemStatusController : public ValueConsumer, /// ValueConsumer interface for ValueConsumer (Networking object /// state updates) - virtual void set(WiFiState new_value) override; + virtual void set(const WiFiState& new_value) override; /// ValueConsumer interface for ValueConsumer /// (SKWSClient object state updates) - virtual void set(SKWSConnectionState new_value) override; + virtual void set(const SKWSConnectionState& new_value) override; protected: void update_state(const SystemStatus new_state) { diff --git a/src/sensesp/sensors/digital_output.cpp b/src/sensesp/sensors/digital_output.cpp index 9802103f6..25b88b96b 100644 --- a/src/sensesp/sensors/digital_output.cpp +++ b/src/sensesp/sensors/digital_output.cpp @@ -9,7 +9,7 @@ DigitalOutput::DigitalOutput(int pin) { pinMode(pin, OUTPUT); } -void DigitalOutput::set(bool new_value) { +void DigitalOutput::set(const bool& new_value) { digitalWrite(pin_number_, new_value); this->emit(new_value); } diff --git a/src/sensesp/sensors/digital_output.h b/src/sensesp/sensors/digital_output.h index 0c28970d0..a6175a55b 100644 --- a/src/sensesp/sensors/digital_output.h +++ b/src/sensesp/sensors/digital_output.h @@ -17,7 +17,7 @@ namespace sensesp { class DigitalOutput : public BooleanTransform { public: DigitalOutput(int pin); - void set(bool new_value) override; + void set(const bool& new_value) override; private: int pin_number_; diff --git a/src/sensesp/signalk/signalk_output.h b/src/sensesp/signalk/signalk_output.h index 1b692d579..5ab4cc37d 100644 --- a/src/sensesp/signalk/signalk_output.h +++ b/src/sensesp/signalk/signalk_output.h @@ -42,7 +42,7 @@ class SKOutput : public SKEmitter, public SymmetricTransform { SKOutput(String sk_path, SKMetadata* meta) : SKOutput(sk_path, "", meta) {} - virtual void set(T new_value) override { + virtual void set(const T& new_value) override { this->ValueProducer::emit(new_value); } diff --git a/src/sensesp/signalk/signalk_put_request.h b/src/sensesp/signalk/signalk_put_request.h index babdfef9c..1d00bf8b8 100644 --- a/src/sensesp/signalk/signalk_put_request.h +++ b/src/sensesp/signalk/signalk_put_request.h @@ -146,7 +146,7 @@ class SKPutRequest : public SKPutRequestBase, public ValueConsumer { : SKPutRequestBase(sk_path, config_path, timeout), ignore_duplicates{ignore_duplicates} {} - virtual void set(T new_value) override { + virtual void set(const T& new_value) override { if (ignore_duplicates && new_value == value) { return; } diff --git a/src/sensesp/system/lambda_consumer.h b/src/sensesp/system/lambda_consumer.h index bea5c2ae4..7719407d3 100644 --- a/src/sensesp/system/lambda_consumer.h +++ b/src/sensesp/system/lambda_consumer.h @@ -27,7 +27,7 @@ class LambdaConsumer : public ValueConsumer { LambdaConsumer(std::function function) : ValueConsumer(), function{function} {} - void set(IN input) override { function(input); } + void set(const IN& input) override { function(input); } protected: std::function function; diff --git a/src/sensesp/system/observablevalue.h b/src/sensesp/system/observablevalue.h index fef32b7ee..b62fce368 100644 --- a/src/sensesp/system/observablevalue.h +++ b/src/sensesp/system/observablevalue.h @@ -32,7 +32,7 @@ class ObservableValue : public ValueConsumer, public ValueProducer { ObservableValue(const T& value) : ValueConsumer(), ValueProducer(value) {} - void set(T value) override { this->ValueProducer::emit(value); } + void set(const T& value) override { this->ValueProducer::emit(value); } const T& operator=(const T& value) { set(value); @@ -65,7 +65,7 @@ class PersistingObservableValue : public ObservableValue, load_configuration(); } - virtual void set(T value) override { + virtual void set(const T& value) override { ObservableValue::set(value); this->save_configuration(); } diff --git a/src/sensesp/system/pwm_output.cpp b/src/sensesp/system/pwm_output.cpp index 2ed288636..d0f7220de 100644 --- a/src/sensesp/system/pwm_output.cpp +++ b/src/sensesp/system/pwm_output.cpp @@ -18,7 +18,7 @@ PWMOutput::PWMOutput(int pin, int pwm_channel) { } } -void PWMOutput::set(float new_value) { +void PWMOutput::set(const float& new_value) { uint8_t pwm_channel = default_channel_; set_pwm(pwm_channel, new_value); diff --git a/src/sensesp/system/pwm_output.h b/src/sensesp/system/pwm_output.h index 8f8299ba5..affcf3a04 100644 --- a/src/sensesp/system/pwm_output.h +++ b/src/sensesp/system/pwm_output.h @@ -48,7 +48,7 @@ class PWMOutput : public ValueConsumer { * pwm_channel is zero, the channel assigned when the PWMOutput instance * was instantiated will be used. */ - virtual void set(float new_value) override; + virtual void set(const float& new_value) override; /** * Assigns the specified GPIO pin to the specified pwm channel. diff --git a/src/sensesp/system/rgb_led.cpp b/src/sensesp/system/rgb_led.cpp index c65fa50fd..2ee374124 100644 --- a/src/sensesp/system/rgb_led.cpp +++ b/src/sensesp/system/rgb_led.cpp @@ -32,7 +32,7 @@ static float get_pwm(long rgb, int shift_right, bool common_anode) { } } -void RgbLed::set(long new_value) { +void RgbLed::set(const long& new_value) { if (led_r_channel_ >= 0) { float r = get_pwm(new_value, 16, common_anode_); PWMOutput::set_pwm(led_r_channel_, r); @@ -49,7 +49,7 @@ void RgbLed::set(long new_value) { } } -void RgbLed::set(bool new_value) { +void RgbLed::set(const bool& new_value) { if (new_value) { set(led_on_rgb_); } else { diff --git a/src/sensesp/system/rgb_led.h b/src/sensesp/system/rgb_led.h index 43c312c30..8145bd280 100644 --- a/src/sensesp/system/rgb_led.h +++ b/src/sensesp/system/rgb_led.h @@ -55,14 +55,14 @@ class RgbLed : public Configurable, * Used to set the current display state of the LED. * @param new_value The RGB color to display. */ - virtual void set(long new_value) override; + virtual void set(const long& new_value) override; /** * Used to set the current display state of the LED with a simple on/off * boolean value. Using TRUE for new_value sets the color to the ON color. * Using FALSE uses the OFF color. */ - virtual void set(bool new_value) override; + virtual void set(const bool& new_value) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; diff --git a/src/sensesp/system/system_status_led.cpp b/src/sensesp/system/system_status_led.cpp index 5bf32c2c2..d27410fae 100644 --- a/src/sensesp/system/system_status_led.cpp +++ b/src/sensesp/system/system_status_led.cpp @@ -56,7 +56,7 @@ void SystemStatusLed::set_ws_connected() { blinker_->set_pattern(ws_connected_pattern); } -void SystemStatusLed::set(SystemStatus new_value) { +void SystemStatusLed::set(const SystemStatus& new_value) { switch (new_value) { case SystemStatus::kWifiNoAP: this->set_wifi_no_ap(); @@ -82,6 +82,6 @@ void SystemStatusLed::set(SystemStatus new_value) { } } -void SystemStatusLed::set(int new_value) { blinker_->blip(); } +void SystemStatusLed::set(const int& new_value) { blinker_->blip(); } } // namespace sensesp diff --git a/src/sensesp/system/system_status_led.h b/src/sensesp/system/system_status_led.h index e6aaba29c..f5b186d8d 100644 --- a/src/sensesp/system/system_status_led.h +++ b/src/sensesp/system/system_status_led.h @@ -29,8 +29,8 @@ class SystemStatusLed : public ValueConsumer, public: SystemStatusLed(int pin); - virtual void set(SystemStatus new_value) override; - virtual void set(int new_value) override; + virtual void set(const SystemStatus& new_value) override; + virtual void set(const int& new_value) override; }; } // namespace sensesp diff --git a/src/sensesp/system/task_queue_producer.h b/src/sensesp/system/task_queue_producer.h index fa6e919c9..208c5b952 100644 --- a/src/sensesp/system/task_queue_producer.h +++ b/src/sensesp/system/task_queue_producer.h @@ -44,7 +44,7 @@ class TaskQueueProducer : public ObservableValue { unsigned int poll_rate = 990) : TaskQueueProducer(value, ReactESP::app, queue_size, poll_rate) {} - virtual void set(T value) override { + virtual void set(const T& value) override { int retval; if (queue_size_ == 1) { retval = xQueueOverwrite(queue_, &value); diff --git a/src/sensesp/system/valueconsumer.h b/src/sensesp/system/valueconsumer.h index b6e79032c..f89aa775f 100644 --- a/src/sensesp/system/valueconsumer.h +++ b/src/sensesp/system/valueconsumer.h @@ -26,9 +26,9 @@ class ValueConsumer { * automatically by a ValueProducer. * @param new_value the value of the input */ - virtual void set(T new_value) {} + virtual void set(const T& new_value) {} - virtual void set_input(T new_value) { + virtual void set_input(const T& new_value) { static bool warned = false; if (!warned) { warned = true; diff --git a/src/sensesp/system/valueproducer.h b/src/sensesp/system/valueproducer.h index 2e848b546..422ae6494 100644 --- a/src/sensesp/system/valueproducer.h +++ b/src/sensesp/system/valueproducer.h @@ -109,7 +109,7 @@ class ValueProducer : virtual public Observable { /* * Set a new output value and notify consumers about it */ - void emit(T new_value) { + void emit(const T& new_value) { this->output = new_value; Observable::notify(); } diff --git a/src/sensesp/transforms/air_density.cpp b/src/sensesp/transforms/air_density.cpp index c1cdf2859..c6db418f6 100644 --- a/src/sensesp/transforms/air_density.cpp +++ b/src/sensesp/transforms/air_density.cpp @@ -8,7 +8,7 @@ namespace sensesp { AirDensity::AirDensity() : FloatTransform() {} -void AirDensity::set(float input) { +void AirDensity::set(const float& input) { // For more info on the calculation see // https://en.wikipedia.org/wiki/Density_of_air diff --git a/src/sensesp/transforms/air_density.h b/src/sensesp/transforms/air_density.h index e54b2561d..6dbecfc53 100644 --- a/src/sensesp/transforms/air_density.h +++ b/src/sensesp/transforms/air_density.h @@ -14,7 +14,7 @@ namespace sensesp { class AirDensity : public FloatTransform { public: AirDensity(); - virtual void set(float input) override; + virtual void set(const float& input) override; private: float inputs[3]; diff --git a/src/sensesp/transforms/analogvoltage.cpp b/src/sensesp/transforms/analogvoltage.cpp index 80a4d30df..fc9f1f515 100644 --- a/src/sensesp/transforms/analogvoltage.cpp +++ b/src/sensesp/transforms/analogvoltage.cpp @@ -11,7 +11,7 @@ AnalogVoltage::AnalogVoltage(float max_voltage, float multiplier, float offset, load_configuration(); } -void AnalogVoltage::set(float input) { +void AnalogVoltage::set(const float& input) { this->emit(((input * (max_voltage_ / MAX_ANALOG_OUTPUT)) * multiplier_) + offset_); } diff --git a/src/sensesp/transforms/analogvoltage.h b/src/sensesp/transforms/analogvoltage.h index b760cdae8..ea1d87361 100644 --- a/src/sensesp/transforms/analogvoltage.h +++ b/src/sensesp/transforms/analogvoltage.h @@ -42,7 +42,7 @@ class AnalogVoltage : public FloatTransform { public: AnalogVoltage(float max_voltage = 3.3, float multiplier = 1.0, float offset = 0.0, String config_path = ""); - virtual void set(float input) override; + virtual void set(const float& input) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; virtual String get_config_schema() override; diff --git a/src/sensesp/transforms/angle_correction.cpp b/src/sensesp/transforms/angle_correction.cpp index e1d56d29a..757047e42 100644 --- a/src/sensesp/transforms/angle_correction.cpp +++ b/src/sensesp/transforms/angle_correction.cpp @@ -10,7 +10,7 @@ AngleCorrection::AngleCorrection(float offset, float min_angle, load_configuration(); } -void AngleCorrection::set(float input) { +void AngleCorrection::set(const float& input) { // first the correction float x = input + offset_; diff --git a/src/sensesp/transforms/angle_correction.h b/src/sensesp/transforms/angle_correction.h index b259c7e74..b087b16b8 100644 --- a/src/sensesp/transforms/angle_correction.h +++ b/src/sensesp/transforms/angle_correction.h @@ -20,7 +20,7 @@ namespace sensesp { class AngleCorrection : public FloatTransform { public: AngleCorrection(float offset, float min_angle = 0, String config_path = ""); - virtual void set(float input) override; + virtual void set(const float& input) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; virtual String get_config_schema() override; diff --git a/src/sensesp/transforms/change_filter.cpp b/src/sensesp/transforms/change_filter.cpp index 78bb66051..6638a2cc4 100644 --- a/src/sensesp/transforms/change_filter.cpp +++ b/src/sensesp/transforms/change_filter.cpp @@ -20,7 +20,7 @@ ChangeFilter::ChangeFilter(float min_delta, float max_delta, int max_skips, skips_ = max_skips_ + 1; } -void ChangeFilter::set(float new_value) { +void ChangeFilter::set(const float& new_value) { float delta = absf(new_value - output); if ((delta >= min_delta_ && delta <= max_delta_) || skips_ > max_skips_) { skips_ = 0; diff --git a/src/sensesp/transforms/change_filter.h b/src/sensesp/transforms/change_filter.h index c598e1b25..6096a5d30 100644 --- a/src/sensesp/transforms/change_filter.h +++ b/src/sensesp/transforms/change_filter.h @@ -35,7 +35,7 @@ class ChangeFilter : public FloatTransform { ChangeFilter(float min_delta = 0.0, float max_delta = 9999.0, int max_skips = 99, String config_path = ""); - virtual void set(float new_value) override; + virtual void set(const float& new_value) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; virtual String get_config_schema() override; diff --git a/src/sensesp/transforms/click_type.cpp b/src/sensesp/transforms/click_type.cpp index 8c3b08ac0..2d88d4fb1 100644 --- a/src/sensesp/transforms/click_type.cpp +++ b/src/sensesp/transforms/click_type.cpp @@ -16,7 +16,7 @@ ClickType::ClickType(String config_path, uint16_t long_click_delay, load_configuration(); } -void ClickType::set(bool input) { +void ClickType::set(const bool& input) { if (input) { on_button_press(); } else { diff --git a/src/sensesp/transforms/click_type.h b/src/sensesp/transforms/click_type.h index 4dd3cc01a..8c252cdbf 100644 --- a/src/sensesp/transforms/click_type.h +++ b/src/sensesp/transforms/click_type.h @@ -58,7 +58,7 @@ class ClickType : public Transform { */ static bool is_click(ClickTypes value); - virtual void set(bool input) override; + virtual void set(const bool& input) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; virtual String get_config_schema() override; diff --git a/src/sensesp/transforms/curveinterpolator.cpp b/src/sensesp/transforms/curveinterpolator.cpp index 09f3684b8..f84d62a97 100644 --- a/src/sensesp/transforms/curveinterpolator.cpp +++ b/src/sensesp/transforms/curveinterpolator.cpp @@ -32,7 +32,7 @@ CurveInterpolator::CurveInterpolator(std::set* defaults, load_configuration(); } -void CurveInterpolator::set(float input) { +void CurveInterpolator::set(const float& input) { float x0 = 0.0; float y0 = 0.0; diff --git a/src/sensesp/transforms/curveinterpolator.h b/src/sensesp/transforms/curveinterpolator.h index 1f190c32a..e3f312d9d 100644 --- a/src/sensesp/transforms/curveinterpolator.h +++ b/src/sensesp/transforms/curveinterpolator.h @@ -55,7 +55,7 @@ class CurveInterpolator : public FloatTransform { CurveInterpolator(std::set* defaults = NULL, String config_path = ""); // Set and retrieve the transformed value - void set(float input) override; + void set(const float& input) override; // Web UI configuration methods CurveInterpolator* set_input_title(String input_title) { diff --git a/src/sensesp/transforms/debounce.h b/src/sensesp/transforms/debounce.h index 0be90051e..b2575c967 100644 --- a/src/sensesp/transforms/debounce.h +++ b/src/sensesp/transforms/debounce.h @@ -42,7 +42,7 @@ class Debounce : public SymmetricTransform { this->load_configuration(); } - virtual void set(T input) override { + virtual void set(const T& input) override { // Input has changed since the last emit, or this is the first // input since the program started to run. diff --git a/src/sensesp/transforms/dew_point.cpp b/src/sensesp/transforms/dew_point.cpp index 82f277b08..e49364e04 100644 --- a/src/sensesp/transforms/dew_point.cpp +++ b/src/sensesp/transforms/dew_point.cpp @@ -6,7 +6,7 @@ namespace sensesp { DewPoint::DewPoint() : FloatTransform() {} -void DewPoint::set(float input) { +void DewPoint::set(const float& input) { // Dew point is calculated with Arden Buck Equation and Arden Buck valuation // sets For more info on the calculation see // https://en.wikipedia.org/wiki/Dew_point#Calculating_the_dew_point diff --git a/src/sensesp/transforms/dew_point.h b/src/sensesp/transforms/dew_point.h index a42e6a65c..cadc431e9 100644 --- a/src/sensesp/transforms/dew_point.h +++ b/src/sensesp/transforms/dew_point.h @@ -15,7 +15,7 @@ namespace sensesp { class DewPoint : public FloatTransform { public: DewPoint(); - virtual void set(float input) override; + virtual void set(const float& input) override; private: float inputs[2]; diff --git a/src/sensesp/transforms/difference.cpp b/src/sensesp/transforms/difference.cpp index b69d68fee..6ae33ed39 100644 --- a/src/sensesp/transforms/difference.cpp +++ b/src/sensesp/transforms/difference.cpp @@ -9,7 +9,7 @@ Difference::Difference(float k1, float k2, String config_path) load_configuration(); } -void Difference::set(float input) { +void Difference::set(const float& input) { this->emit(k1 * inputs[0] - k2 * inputs[1]); } diff --git a/src/sensesp/transforms/difference.h b/src/sensesp/transforms/difference.h index 880e77429..e81394c6f 100644 --- a/src/sensesp/transforms/difference.h +++ b/src/sensesp/transforms/difference.h @@ -9,7 +9,7 @@ namespace sensesp { class Difference : public FloatTransform { public: Difference(float k1, float k2, String config_path = ""); - virtual void set(float input) override; + virtual void set(const float& input) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; virtual String get_config_schema() override; diff --git a/src/sensesp/transforms/frequency.cpp b/src/sensesp/transforms/frequency.cpp index 8938f5dee..ebdf0db09 100644 --- a/src/sensesp/transforms/frequency.cpp +++ b/src/sensesp/transforms/frequency.cpp @@ -11,7 +11,7 @@ Frequency::Frequency(float multiplier, String config_path) last_update_ = millis(); } -void Frequency::set(int input) { +void Frequency::set(const int& input) { unsigned long cur_millis = millis(); unsigned long elapsed_millis = cur_millis - last_update_; last_update_ = cur_millis; diff --git a/src/sensesp/transforms/frequency.h b/src/sensesp/transforms/frequency.h index d43553cde..63d724215 100644 --- a/src/sensesp/transforms/frequency.h +++ b/src/sensesp/transforms/frequency.h @@ -21,7 +21,7 @@ namespace sensesp { class Frequency : public Transform { public: Frequency(float multiplier = 1, String config_path = ""); - virtual void set(int input) override; + virtual void set(const int& input) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; virtual String get_config_schema() override; diff --git a/src/sensesp/transforms/heat_index.cpp b/src/sensesp/transforms/heat_index.cpp index d2b78c220..f1a2e10e5 100644 --- a/src/sensesp/transforms/heat_index.cpp +++ b/src/sensesp/transforms/heat_index.cpp @@ -6,7 +6,7 @@ namespace sensesp { HeatIndexTemperature::HeatIndexTemperature() : FloatTransform() {} -void HeatIndexTemperature::set(float input) { +void HeatIndexTemperature::set(const float& input) { // The following equation approximate the heat index // using both Steadman's and Rothfusz equations // See https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3801457/ @@ -77,7 +77,7 @@ void HeatIndexTemperature::set(float input) { HeatIndexEffect::HeatIndexEffect() : Transform() {} -void HeatIndexEffect::set(float input) { +void HeatIndexEffect::set(const float& input) { float heat_index_temperature = input - 273.15; // celsius = kelvin - 273.15 String heat_index_effect = ""; if (heat_index_temperature > 54) { diff --git a/src/sensesp/transforms/heat_index.h b/src/sensesp/transforms/heat_index.h index 7171bea95..d105a3cd2 100644 --- a/src/sensesp/transforms/heat_index.h +++ b/src/sensesp/transforms/heat_index.h @@ -16,7 +16,7 @@ namespace sensesp { class HeatIndexTemperature : public FloatTransform { public: HeatIndexTemperature(); - virtual void set(float input) override; + virtual void set(const float& input) override; private: float inputs[2]; @@ -32,7 +32,7 @@ class HeatIndexTemperature : public FloatTransform { class HeatIndexEffect : public Transform { public: HeatIndexEffect(); - virtual void set(float input) override; + virtual void set(const float& input) override; }; } // namespace sensesp diff --git a/src/sensesp/transforms/integrator.h b/src/sensesp/transforms/integrator.h index 9d0d8e57e..0b967e552 100644 --- a/src/sensesp/transforms/integrator.h +++ b/src/sensesp/transforms/integrator.h @@ -37,7 +37,7 @@ class Integrator : public Transform { this->emit(value); } - virtual void set(C input) override final { + virtual void set(const C& input) override final { value += input * k; this->emit(value); } diff --git a/src/sensesp/transforms/lambda_transform.h b/src/sensesp/transforms/lambda_transform.h index cd1884541..b578ca2a2 100644 --- a/src/sensesp/transforms/lambda_transform.h +++ b/src/sensesp/transforms/lambda_transform.h @@ -177,7 +177,7 @@ class LambdaTransform : public Transform { this->load_configuration(); } - void set(IN input) override { + void set(const IN& input) override { switch (num_params) { case 0: this->output = function0(input); diff --git a/src/sensesp/transforms/median.cpp b/src/sensesp/transforms/median.cpp index 6623e4b72..5bda3202e 100644 --- a/src/sensesp/transforms/median.cpp +++ b/src/sensesp/transforms/median.cpp @@ -9,7 +9,7 @@ Median::Median(unsigned int sample_size, String config_path) buf_.clear(); } -void Median::set(float input) { +void Median::set(const float& input) { buf_.push_back(input); if (buf_.size() >= sample_size_) { // Its time to output a value diff --git a/src/sensesp/transforms/median.h b/src/sensesp/transforms/median.h index 2a8d5d20e..469a7cf2c 100644 --- a/src/sensesp/transforms/median.h +++ b/src/sensesp/transforms/median.h @@ -20,7 +20,7 @@ namespace sensesp { class Median : public FloatTransform { public: Median(unsigned int sample_size = 10, String config_path = ""); - virtual void set(float input) override; + virtual void set(const float& input) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; virtual String get_config_schema() override; diff --git a/src/sensesp/transforms/moving_average.cpp b/src/sensesp/transforms/moving_average.cpp index 1e9f4f720..8b26ccc56 100644 --- a/src/sensesp/transforms/moving_average.cpp +++ b/src/sensesp/transforms/moving_average.cpp @@ -14,7 +14,7 @@ MovingAverage::MovingAverage(int sample_size, float multiplier, load_configuration(); } -void MovingAverage::set(float input) { +void MovingAverage::set(const float& input) { // So the first value to be included in the average doesn't default to 0.0 if (!initialized_) { buf_.assign(sample_size_, input); diff --git a/src/sensesp/transforms/moving_average.h b/src/sensesp/transforms/moving_average.h index 7d1b6d491..94cd01801 100644 --- a/src/sensesp/transforms/moving_average.h +++ b/src/sensesp/transforms/moving_average.h @@ -34,7 +34,7 @@ class MovingAverage : public FloatTransform { * */ MovingAverage(int sample_size, float multiplier = 1.0, String config_path = ""); - virtual void set(float input) override; + virtual void set(const float& input) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; virtual String get_config_schema() override; diff --git a/src/sensesp/transforms/press_repeater.cpp b/src/sensesp/transforms/press_repeater.cpp index 5cfae78d9..64e21e686 100644 --- a/src/sensesp/transforms/press_repeater.cpp +++ b/src/sensesp/transforms/press_repeater.cpp @@ -31,11 +31,11 @@ PressRepeater::PressRepeater(String config_path, int integer_false, }); } -void PressRepeater::set(int new_value) { +void PressRepeater::set(const int& new_value) { this->set(new_value != integer_false_); } -void PressRepeater::set(bool new_value) { +void PressRepeater::set(const bool& new_value) { if (new_value != pushed_) { pushed_ = new_value; diff --git a/src/sensesp/transforms/press_repeater.h b/src/sensesp/transforms/press_repeater.h index 8cf03abfd..3d9e0f537 100644 --- a/src/sensesp/transforms/press_repeater.h +++ b/src/sensesp/transforms/press_repeater.h @@ -43,8 +43,8 @@ class PressRepeater : public BooleanTransform, public IntConsumer { PressRepeater(String config_path = "", int integer_false = 0, int repeat_start_interval = 1500, int repeat_interval = 250); - virtual void set(bool new_value) override; - virtual void set(int new_value) override; + virtual void set(const bool& new_value) override; + virtual void set(const int& new_value) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; diff --git a/src/sensesp/transforms/repeat.h b/src/sensesp/transforms/repeat.h index debaecc52..22a13a626 100644 --- a/src/sensesp/transforms/repeat.h +++ b/src/sensesp/transforms/repeat.h @@ -67,7 +67,7 @@ class RepeatStopping : public Repeat { this->interval_, [this]() { this->repeat_function(); }); } - virtual void set(T input) override { + virtual void set(const T& input) override { this->emit(input); age_ = 0; if (this->repeat_reaction_ != nullptr) { @@ -117,7 +117,7 @@ class RepeatExpiring : public Repeat { this->interval_, [this]() { this->repeat_function(); }); } - virtual void set(T input) override { + virtual void set(const T& input) override { this->emit(input); age_ = 0; if (this->repeat_reaction_ != nullptr) { diff --git a/src/sensesp/transforms/threshold.cpp b/src/sensesp/transforms/threshold.cpp index c7256acb3..ab85f6106 100644 --- a/src/sensesp/transforms/threshold.cpp +++ b/src/sensesp/transforms/threshold.cpp @@ -3,7 +3,7 @@ namespace sensesp { template -void ThresholdTransform::set(C input) { +void ThresholdTransform::set(const C& input) { if (input >= min_value_ && input <= max_value_) { this->output = in_range_; } else { diff --git a/src/sensesp/transforms/threshold.h b/src/sensesp/transforms/threshold.h index 8eb666d9c..f7e90c60f 100644 --- a/src/sensesp/transforms/threshold.h +++ b/src/sensesp/transforms/threshold.h @@ -27,7 +27,7 @@ class ThresholdTransform : public Transform { in_range_{in_range} { this->load_configuration(); }; - virtual void set(C new_value) override; + virtual void set(const C& new_value) override; protected: C min_value_; diff --git a/src/sensesp/transforms/throttle.h b/src/sensesp/transforms/throttle.h index c6b5bfc59..6cb7f21c1 100644 --- a/src/sensesp/transforms/throttle.h +++ b/src/sensesp/transforms/throttle.h @@ -31,7 +31,7 @@ class Throttle : public SymmetricTransform { Throttle(long min_interval) : SymmetricTransform(), min_interval_{min_interval} {} - void set(T input) override { + void set(const T& input) override { if (age_ < min_interval_) { return; } diff --git a/src/sensesp/transforms/time_counter.h b/src/sensesp/transforms/time_counter.h index 702bd4596..f90484589 100644 --- a/src/sensesp/transforms/time_counter.h +++ b/src/sensesp/transforms/time_counter.h @@ -35,7 +35,7 @@ class TimeCounter : public Transform { this->load_configuration(); } - virtual void set(T input) override { + virtual void set(const T& input) override { if (previous_state_ == -1) { // Initialize the previous state previous_state_ = (bool)input; diff --git a/src/sensesp/transforms/timestring.cpp b/src/sensesp/transforms/timestring.cpp index 1f6b735f5..a672e1c40 100644 --- a/src/sensesp/transforms/timestring.cpp +++ b/src/sensesp/transforms/timestring.cpp @@ -6,7 +6,7 @@ namespace sensesp { TimeString::TimeString(String config_path) : Transform(config_path) {} -void TimeString::set(time_t input) { +void TimeString::set(const time_t& input) { char buf[sizeof "2011-10-08T07:07:09Z"]; strftime(buf, sizeof buf, "%FT%TZ", gmtime(&input)); this->emit(String(buf)); diff --git a/src/sensesp/transforms/timestring.h b/src/sensesp/transforms/timestring.h index ad16fa965..8a3f3bc89 100644 --- a/src/sensesp/transforms/timestring.h +++ b/src/sensesp/transforms/timestring.h @@ -15,7 +15,7 @@ namespace sensesp { class TimeString : public Transform { public: TimeString(String config_path = ""); - virtual void set(time_t input) override; + virtual void set(const time_t& input) override; }; } // namespace sensesp diff --git a/src/sensesp/transforms/truth_text.cpp b/src/sensesp/transforms/truth_text.cpp index 491608386..7469fba8f 100644 --- a/src/sensesp/transforms/truth_text.cpp +++ b/src/sensesp/transforms/truth_text.cpp @@ -35,7 +35,7 @@ bool TextToTruth::is_valid_false(String input) { return false; } -void TextToTruth::set(String input) { +void TextToTruth::set(const String& input) { this->emit(TextToTruth::is_valid_true(input)); } @@ -46,7 +46,7 @@ TruthToText::TruthToText(String true_value, String false_value) truth_value_[1] = true_value; } -void TruthToText::set(bool input) { +void TruthToText::set(const bool& input) { if (input) { this->emit(truth_value_[1]); } else { diff --git a/src/sensesp/transforms/truth_text.h b/src/sensesp/transforms/truth_text.h index 6bece8549..549770266 100644 --- a/src/sensesp/transforms/truth_text.h +++ b/src/sensesp/transforms/truth_text.h @@ -23,7 +23,7 @@ namespace sensesp { */ class TextToTruth : public Transform { public: - virtual void set(String input) override; + virtual void set(const String& input) override; /** * Returns TRUE if `value` represents one of the truth values recognized by @@ -49,7 +49,7 @@ class TruthToText : public Transform { public: TruthToText(String true_value = "ON", String false_value = "OFF"); - virtual void set(bool input) override; + virtual void set(const bool& input) override; protected: String* truth_value_; diff --git a/src/sensesp/transforms/voltage_multiplier.cpp b/src/sensesp/transforms/voltage_multiplier.cpp index f3fa24c7a..85f42a251 100644 --- a/src/sensesp/transforms/voltage_multiplier.cpp +++ b/src/sensesp/transforms/voltage_multiplier.cpp @@ -6,7 +6,7 @@ VoltageMultiplier::VoltageMultiplier(uint16_t R1, uint16_t R2, String config_path) : FloatTransform(config_path), R1_{R1}, R2_{R2} {} -void VoltageMultiplier::set(float input) { +void VoltageMultiplier::set(const float& input) { // Ohms Law at work! this->emit(input * (((float)R1_ + (float)R2_) / (float)R2_)); } diff --git a/src/sensesp/transforms/voltage_multiplier.h b/src/sensesp/transforms/voltage_multiplier.h index e26fc0820..94ab90523 100644 --- a/src/sensesp/transforms/voltage_multiplier.h +++ b/src/sensesp/transforms/voltage_multiplier.h @@ -31,7 +31,7 @@ class VoltageMultiplier : public FloatTransform { public: VoltageMultiplier(uint16_t R1, uint16_t R2, String config_path = ""); - virtual void set(float input); + virtual void set(const float& input); private: uint16_t R1_; diff --git a/src/sensesp/transforms/voltagedivider.cpp b/src/sensesp/transforms/voltagedivider.cpp index 5b9a59ca5..3a3fc3919 100644 --- a/src/sensesp/transforms/voltagedivider.cpp +++ b/src/sensesp/transforms/voltagedivider.cpp @@ -7,7 +7,7 @@ VoltageDividerR1::VoltageDividerR1(float R2, float Vin, String config_path) load_configuration(); } -void VoltageDividerR1::set(float Vout) { +void VoltageDividerR1::set(const float& Vout) { this->emit((Vin_ - Vout) * R2_ / Vout); } @@ -48,7 +48,7 @@ VoltageDividerR2::VoltageDividerR2(float R1, float Vin, String config_path) load_configuration(); } -void VoltageDividerR2::set(float Vout) { +void VoltageDividerR2::set(const float& Vout) { this->emit((Vout * R1_) / (Vin_ - Vout)); } diff --git a/src/sensesp/transforms/voltagedivider.h b/src/sensesp/transforms/voltagedivider.h index 86f0c59f9..1f6c59146 100644 --- a/src/sensesp/transforms/voltagedivider.h +++ b/src/sensesp/transforms/voltagedivider.h @@ -34,7 +34,7 @@ class VoltageDividerR1 : public SymmetricTransform { public: VoltageDividerR1(float R2, float Vin = 3.3, String config_path = ""); - virtual void set(float Vout) override; + virtual void set(const float& Vout) override; virtual void get_configuration(JsonObject& doc) override; virtual bool set_configuration(const JsonObject& config) override; @@ -74,7 +74,7 @@ class VoltageDividerR2 : public SymmetricTransform { public: VoltageDividerR2(float R1, float Vin = 3.3, String config_path = ""); - virtual void set(float Vout) override; + virtual void set(const float& Vout) override; // For reading and writing the configuration of this transformation virtual void get_configuration(JsonObject& doc) override; diff --git a/src/sensesp/ui/ui_output.h b/src/sensesp/ui/ui_output.h index cadf32fd0..254757bb6 100644 --- a/src/sensesp/ui/ui_output.h +++ b/src/sensesp/ui/ui_output.h @@ -83,7 +83,7 @@ class UIOutput : public UIOutputBase, public ObservableValue { return obj; } - void set(T new_value) override { this->ValueProducer::emit(new_value); } + void set(const T& new_value) override { this->ValueProducer::emit(new_value); } }; } // namespace sensesp