Skip to content

Commit

Permalink
Merge pull request #711 from SignalK/const_ref_set
Browse files Browse the repository at this point in the history
Make ValueConsumer::set argument a const ref
  • Loading branch information
mairas authored Aug 2, 2024
2 parents f8be186 + ea7f3bc commit 3529fe6
Show file tree
Hide file tree
Showing 62 changed files with 83 additions and 83 deletions.
6 changes: 3 additions & 3 deletions src/sensesp/controllers/smart_switch_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions src/sensesp/controllers/smart_switch_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/controllers/system_status_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 &&
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/controllers/system_status_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class SystemStatusController : public ValueConsumer<WiFiState>,

/// ValueConsumer interface for ValueConsumer<WiFiState> (Networking object
/// state updates)
virtual void set(WiFiState new_value) override;
virtual void set(const WiFiState& new_value) override;
/// ValueConsumer interface for ValueConsumer<SKWSConnectionState>
/// (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) {
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/sensors/digital_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/sensors/digital_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/signalk/signalk_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SKOutput : public SKEmitter, public SymmetricTransform<T> {

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<T>::emit(new_value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/signalk/signalk_put_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class SKPutRequest : public SKPutRequestBase, public ValueConsumer<T> {
: 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/system/lambda_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LambdaConsumer : public ValueConsumer<IN> {
LambdaConsumer(std::function<void(IN)> function)
: ValueConsumer<IN>(), function{function} {}

void set(IN input) override { function(input); }
void set(const IN& input) override { function(input); }

protected:
std::function<void(IN)> function;
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/system/observablevalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ObservableValue : public ValueConsumer<T>, public ValueProducer<T> {
ObservableValue(const T& value)
: ValueConsumer<T>(), ValueProducer<T>(value) {}

void set(T value) override { this->ValueProducer<T>::emit(value); }
void set(const T& value) override { this->ValueProducer<T>::emit(value); }

const T& operator=(const T& value) {
set(value);
Expand Down Expand Up @@ -65,7 +65,7 @@ class PersistingObservableValue : public ObservableValue<T>,
load_configuration();
}

virtual void set(T value) override {
virtual void set(const T& value) override {
ObservableValue<T>::set(value);
this->save_configuration();
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/system/pwm_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/system/pwm_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PWMOutput : public ValueConsumer<float> {
* 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.
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/system/rgb_led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/system/rgb_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/system/system_status_led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/sensesp/system/system_status_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class SystemStatusLed : public ValueConsumer<SystemStatus>,
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
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/system/task_queue_producer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TaskQueueProducer : public ObservableValue<T> {
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);
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/system/valueconsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/system/valueproducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/air_density.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/air_density.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/analogvoltage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/analogvoltage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/angle_correction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/angle_correction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/change_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/change_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/click_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/click_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ClickType : public Transform<bool, ClickTypes> {
*/
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;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/curveinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CurveInterpolator::CurveInterpolator(std::set<Sample>* defaults,
load_configuration();
}

void CurveInterpolator::set(float input) {
void CurveInterpolator::set(const float& input) {
float x0 = 0.0;
float y0 = 0.0;

Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/curveinterpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CurveInterpolator : public FloatTransform {
CurveInterpolator(std::set<Sample>* 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/debounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Debounce : public SymmetricTransform<T> {
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.

Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/dew_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/dew_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/difference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/difference.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 3529fe6

Please sign in to comment.