Skip to content

Commit

Permalink
Remove input_channel feature altogether
Browse files Browse the repository at this point in the history
This might break some transforms.
  • Loading branch information
mairas committed Jun 16, 2024
1 parent fa2bbef commit 3ff18d7
Show file tree
Hide file tree
Showing 63 changed files with 252 additions and 331 deletions.
7 changes: 3 additions & 4 deletions src/sensesp/controllers/smart_switch_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ SmartSwitchController::SmartSwitchController(bool auto_initialize,
}
}

void SmartSwitchController::set(bool new_value, uint8_t input_channel) {
void SmartSwitchController::set(bool new_value) {
is_on = new_value;
this->emit(is_on);
}

void SmartSwitchController::set(ClickTypes new_value,
uint8_t input_channel) {
void SmartSwitchController::set(ClickTypes new_value) {
if (!ClickType::is_click(new_value)) {
// Ignore button presses (we only want interpreted clicks)
return;
Expand All @@ -57,7 +56,7 @@ void SmartSwitchController::set(ClickTypes new_value,
}
}

void SmartSwitchController::set(String new_value, uint8_t input_channel) {
void SmartSwitchController::set(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, uint8_t input_channel = 0) override;
void set(String new_value, uint8_t input_channel = 0) override;
void set(ClickTypes new_value, uint8_t input_channel = 0) override;
void set(bool new_value) override;
void set(String new_value) override;
void set(ClickTypes new_value) override;

// For reading and writing the configuration of this transformation
virtual void get_configuration(JsonObject& doc) override;
Expand Down
6 changes: 2 additions & 4 deletions src/sensesp/controllers/system_status_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace sensesp {

void SystemStatusController::set(WiFiState new_value,
uint8_t input_channel) {
void SystemStatusController::set(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 @@ -23,8 +22,7 @@ void SystemStatusController::set(WiFiState new_value,
}
}

void SystemStatusController::set(SKWSConnectionState new_value,
uint8_t input_channel) {
void SystemStatusController::set(SKWSConnectionState new_value) {
switch (new_value) {
case SKWSConnectionState::kSKWSDisconnected:
if (current_state_ != SystemStatus::kWifiDisconnected &&
Expand Down
5 changes: 2 additions & 3 deletions src/sensesp/controllers/system_status_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ class SystemStatusController : public ValueConsumer<WiFiState>,

/// ValueConsumer interface for ValueConsumer<WiFiState> (Networking object
/// state updates)
virtual void set(WiFiState new_value, uint8_t input_channel = 0) override;
virtual void set(WiFiState new_value) override;
/// ValueConsumer interface for ValueConsumer<SKWSConnectionState>
/// (SKWSClient object state updates)
virtual void set(SKWSConnectionState new_value,
uint8_t input_channel = 0) override;
virtual void set(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, uint8_t inputChannel) {
void DigitalOutput::set(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, uint8_t input_channel = 0) override;
void set(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, uint8_t input_channel = 0) override {
virtual void set(T new_value) override {
this->ValueProducer<T>::emit(new_value);
}

Expand Down
3 changes: 1 addition & 2 deletions src/sensesp/signalk/signalk_put_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define _signalk_put_request_H_

#include <ArduinoJson.h>

#include <functional>
#include <map>

Expand Down Expand Up @@ -147,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, uint8_t input_channel = 0) override {
virtual void set(T new_value) override {
if (ignore_duplicates && new_value == value) {
return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/sensesp/system/lambda_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class LambdaConsumer : public ValueConsumer<IN> {
LambdaConsumer(std::function<void(IN)> function)
: ValueConsumer<IN>(), function{function} {}

void set(IN input, uint8_t input_channel = 0) override {
function(input);
}
void set(IN input) override { function(input); }

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

void set(T value, uint8_t input_channel = 0) override {
this->ValueProducer<T>::emit(value);
}
void set(T value) override { this->ValueProducer<T>::emit(value); }

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

virtual void set(T value, uint8_t input_channel = 0) override {
virtual void set(T value) override {
ObservableValue<T>::set(value);
this->save_configuration();
}
Expand Down
9 changes: 3 additions & 6 deletions src/sensesp/system/pwm_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ PWMOutput::PWMOutput(int pin, int pwm_channel) {
}
}

void PWMOutput::set(float new_value, uint8_t pwm_channel) {
if (pwm_channel == 0) {
// Use the default channel, as zero is the SensESP default
// input_channel for ValueConsumers
pwm_channel = default_channel_;
}
void PWMOutput::set(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, uint8_t pwm_channel = 0) override;
virtual void set(float new_value) override;

/**
* Assigns the specified GPIO pin to the specified pwm channel.
Expand Down
8 changes: 4 additions & 4 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, uint8_t input_channel) {
void RgbLed::set(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,11 +49,11 @@ void RgbLed::set(long new_value, uint8_t input_channel) {
}
}

void RgbLed::set(bool new_value, uint8_t input_channel) {
void RgbLed::set(bool new_value) {
if (new_value) {
set(led_on_rgb_, input_channel);
set(led_on_rgb_);
} else {
set(led_off_rgb_, input_channel);
set(led_off_rgb_);
}
}

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, uint8_t input_channel = 0) override;
virtual void set(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, uint8_t input_channel = 0) override;
virtual void set(bool new_value) override;

virtual void get_configuration(JsonObject& doc) override;
virtual bool set_configuration(const JsonObject& config) override;
Expand Down
6 changes: 2 additions & 4 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, uint8_t input_channel) {
void SystemStatusLed::set(SystemStatus new_value) {
switch (new_value) {
case SystemStatus::kWifiNoAP:
this->set_wifi_no_ap();
Expand All @@ -82,8 +82,6 @@ void SystemStatusLed::set(SystemStatus new_value, uint8_t input_channel) {
}
}

void SystemStatusLed::set(int new_value, uint8_t input_channel) {
blinker_->blip();
}
void SystemStatusLed::set(int new_value) { blinker_->blip(); }

} // namespace sensesp
5 changes: 2 additions & 3 deletions src/sensesp/system/system_status_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ class SystemStatusLed : public ValueConsumer<SystemStatus>,
public:
SystemStatusLed(int pin);

virtual void set(SystemStatus new_value,
uint8_t input_channel = 0) override;
virtual void set(int new_value, uint8_t input_channel = 0) override;
virtual void set(SystemStatus new_value) override;
virtual void set(int new_value) override;
};

} // namespace sensesp
Expand Down
10 changes: 6 additions & 4 deletions src/sensesp/system/task_queue_producer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ namespace sensesp {
template <class T>
class TaskQueueProducer : public ObservableValue<T> {
public:
TaskQueueProducer(const T& value, reactesp::ReactESP* consumer_app = ReactESP::app, int queue_size = 1,
unsigned int poll_rate = 990)
TaskQueueProducer(const T& value,
reactesp::ReactESP* consumer_app = ReactESP::app,
int queue_size = 1, unsigned int poll_rate = 990)
: ObservableValue<T>(value), queue_size_{queue_size} {
queue_ = xQueueCreate(queue_size, sizeof(T));
if (queue_ == NULL) {
Expand All @@ -39,10 +40,11 @@ class TaskQueueProducer : public ObservableValue<T> {
});
}

TaskQueueProducer(const T& value, int queue_size = 1, unsigned int poll_rate = 990)
TaskQueueProducer(const T& value, int queue_size = 1,
unsigned int poll_rate = 990)
: TaskQueueProducer(value, ReactESP::app, queue_size, poll_rate) {}

virtual void set(T value, uint8_t input_channel = 0) override {
virtual void set(T value) override {
int retval;
if (queue_size_ == 1) {
retval = xQueueOverwrite(queue_, &value);
Expand Down
22 changes: 7 additions & 15 deletions src/sensesp/system/valueconsumer.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef _value_consumer_H_
#define _value_consumer_H_

#include "sensesp.h"

#include <ArduinoJson.h>
#include <stdint.h>

#include "sensesp.h"

namespace sensesp {

template <typename T>
Expand All @@ -25,33 +25,25 @@ class ValueConsumer {
* Used to set an input of this consumer. It is usually called
* automatically by a ValueProducer.
* @param new_value the value of the input
* @param input_channel Consumers can have one or more inputs feeding them.
* This parameter allows you to specify which input number the producer
* is connecting to. For single input consumers, leave the index at zero.
*/
virtual void set(T new_value, uint8_t input_channel = 0) {}
virtual void set(T new_value) {}

virtual void set_input(T new_value, uint8_t input_channel = 0) {
virtual void set_input(T new_value) {
static bool warned = false;
if (!warned) {
warned = true;
debugW("set_input() is deprecated. Use set() instead.");
}
set(new_value, input_channel);
set(new_value);
}

/**
* Registers this consumer with the specified producer, letting it
* know that this consumer would like to receive notifications whenever
* its value changes.
* @param input_channel Consumers can have one or more inputs feeding them.
* This parameter allows you to specify which input number the producer
* is connecting to. For single input consumers, leave the index at zero.
*/
void connect_from(ValueProducer<T>* producer, uint8_t input_channel = 0) {
producer->attach([producer, this, input_channel]() {
this->set(producer->get(), input_channel);
});
void connect_from(ValueProducer<T>* producer) {
producer->attach([producer, this]() { this->set(producer->get()); });
}
};

Expand Down
Loading

0 comments on commit 3ff18d7

Please sign in to comment.