Skip to content

Commit

Permalink
Merge pull request #763 from SignalK/rename_output
Browse files Browse the repository at this point in the history
Rename ValueProducer::output
  • Loading branch information
mairas authored Oct 8, 2024
2 parents 1a4e192 + 9a982e9 commit 982f8fd
Show file tree
Hide file tree
Showing 24 changed files with 144 additions and 145 deletions.
41 changes: 20 additions & 21 deletions src/sensesp/controllers/smart_switch_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ SmartSwitchController::SmartSwitchController(bool auto_initialize,
const char* sk_sync_paths[])
: BooleanTransform(config_path), auto_initialize_{auto_initialize} {
if (sk_sync_paths != NULL) {
sync_paths.clear();
sync_paths_.clear();
int i = 0;
while (strlen(sk_sync_paths[i]) > 0) {
SyncPath path(sk_sync_paths[i]);
sync_paths.insert(path);
sync_paths_.insert(path);
i++;
} // while
}
Expand All @@ -23,14 +23,13 @@ SmartSwitchController::SmartSwitchController(bool auto_initialize,

// Emit the initial state once the event loop starts
if (auto_initialize_) {
event_loop()->onDelay(0,
[this]() { this->emit(is_on); });
event_loop()->onDelay(0, [this]() { this->emit(is_on_); });
}
}

void SmartSwitchController::set(const bool& new_value) {
is_on = new_value;
this->emit(is_on);
is_on_ = new_value;
this->emit(is_on_);
}

void SmartSwitchController::set(const ClickTypes& new_value) {
Expand All @@ -46,45 +45,45 @@ void SmartSwitchController::set(const ClickTypes& new_value) {
}

// All other click types toggle the current state...
is_on = !is_on;
this->emit(is_on);
is_on_ = !is_on_;
this->emit(is_on_);

if (new_value == ClickTypes::DoubleClick) {
// Sync any specified sync paths...
for (auto& path : sync_paths) {
ESP_LOGD(__FILENAME__, "Sync status to %s", path.sk_sync_path.c_str());
path.put_request->set(is_on);
for (auto& path : sync_paths_) {
ESP_LOGD(__FILENAME__, "Sync status to %s", path.sk_sync_path_.c_str());
path.put_request_->set(is_on_);
}
}
}

void SmartSwitchController::set(const String& new_value) {
if (TextToTruth::is_valid_true(new_value)) {
is_on = true;
is_on_ = true;
} else if (TextToTruth::is_valid_false(new_value)) {
is_on = false;
is_on_ = false;
} else {
// All other values simply toggle...
is_on = !is_on;
is_on_ = !is_on_;
}
this->emit(is_on);
this->emit(is_on_);
}

bool SmartSwitchController::to_json(JsonObject& root) {
JsonArray jPaths = root["sync_paths"].to<JsonArray>();
for (auto& path : sync_paths) {
jPaths.add(path.sk_sync_path);
for (auto& path : sync_paths_) {
jPaths.add(path.sk_sync_path_);
}
return true;
}

bool SmartSwitchController::from_json(const JsonObject& config) {
JsonArray arr = config["sync_paths"];
if (arr.size() > 0) {
sync_paths.clear();
sync_paths_.clear();
for (String sk_path : arr) {
SyncPath path(sk_path);
sync_paths.insert(path);
sync_paths_.insert(path);
}
}

Expand All @@ -94,9 +93,9 @@ bool SmartSwitchController::from_json(const JsonObject& config) {
SmartSwitchController::SyncPath::SyncPath() {}

SmartSwitchController::SyncPath::SyncPath(String sk_sync_path)
: sk_sync_path{sk_sync_path} {
: sk_sync_path_{sk_sync_path} {
ESP_LOGD(__FILENAME__, "DoubleClick will also sync %s", sk_sync_path.c_str());
this->put_request = new BoolSKPutRequest(sk_sync_path, "", false);
this->put_request_ = new BoolSKPutRequest(sk_sync_path, "", false);
}

} // namespace sensesp
10 changes: 5 additions & 5 deletions src/sensesp/controllers/smart_switch_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ class SmartSwitchController : public BooleanTransform,
/// Used to store configuration internally.
class SyncPath {
public:
String sk_sync_path;
BoolSKPutRequest* put_request;
BoolSKPutRequest* put_request_;
String sk_sync_path_;

SyncPath();
SyncPath(String sk_sync_path);

friend bool operator<(const SyncPath& lhs, const SyncPath& rhs) {
return lhs.sk_sync_path < rhs.sk_sync_path;
return lhs.sk_sync_path_ < rhs.sk_sync_path_;
}
};

protected:
bool is_on = false;
bool is_on_ = false;
bool auto_initialize_;
std::set<SyncPath> sync_paths;
std::set<SyncPath> sync_paths_;
};

const String ConfigSchema(const SmartSwitchController& obj) {
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/net/networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class WiFiStateProducer : public ValueProducer<WiFiState> {

protected:
WiFiStateProducer() {
this->output = WiFiState::kWifiNoAP;
this->output_ = WiFiState::kWifiNoAP;

setup_wifi_callbacks();

// Emit the current state as soon as the event loop starts
event_loop()->onDelay(0, [this]() { this->emit(this->output); });
event_loop()->onDelay(0, [this]() { this->emit(this->output_); });
}

void setup_wifi_callbacks() {
Expand Down
6 changes: 3 additions & 3 deletions src/sensesp/sensors/analog_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ AnalogInput::AnalogInput(uint8_t pin, unsigned int read_delay,
pin{pin},
read_delay{read_delay},
output_scale{output_scale} {
analog_reader = new AnalogReader(pin);
analog_reader_ = new AnalogReader(pin);
load();

if (this->analog_reader->configure()) {
if (this->analog_reader_->configure()) {
event_loop()->onRepeat(read_delay, [this]() { this->update(); });
}
}

void AnalogInput::update() { this->emit(output_scale * analog_reader->read()); }
void AnalogInput::update() { this->emit(output_scale * analog_reader_->read()); }

bool AnalogInput::to_json(JsonObject& root) {
root["read_delay"] = read_delay;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/sensors/analog_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AnalogInput : public FloatSensor {
uint8_t pin{};
unsigned int read_delay;
float output_scale;
BaseAnalogReader* analog_reader{};
BaseAnalogReader* analog_reader_;
void update();
};

Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/sensors/analog_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BaseAnalogReader {
};

class ESP32AnalogReader : public BaseAnalogReader {
private:
protected:
int pin_;
adc_atten_t attenuation_ = ADC_ATTEN_DB_12;
// This should work with ESP32 and newer variants, ADCs are different
Expand Down
12 changes: 6 additions & 6 deletions src/sensesp/sensors/digital_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class DigitalInputCounter : public DigitalInput, public Sensor<int> {

event_loop()->onRepeat(read_delay_, [this]() {
noInterrupts();
output = counter_;
output_ = counter_;
counter_ = 0;
interrupts();
notify();
Expand Down Expand Up @@ -206,19 +206,19 @@ class DigitalInputChange : public DigitalInput, public Sensor<bool> {
interrupt_type_{interrupt_type},
triggered_{true} {
load();
output = (bool)digitalRead(pin_);
last_output_ = !output; // ensure that we always send the first output
output_ = (bool)digitalRead(pin_);
last_output_ = !output_; // ensure that we always send the first output_

event_loop()->onInterrupt(pin_, interrupt_type_, [this]() {
output = (bool)digitalRead(pin_);
output_ = (bool)digitalRead(pin_);
triggered_ = true;
});

event_loop()->onTick([this]() {
if (triggered_ && (output != last_output_)) {
if (triggered_ && (output_ != last_output_)) {
noInterrupts();
triggered_ = false;
last_output_ = output;
last_output_ = output_;
interrupts();
notify();
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/sensors/system_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void SystemHz::update() {
return;
}

output = (tick_count_ * 1000) / elapsed_millis_;
output_ = (tick_count_ * 1000) / elapsed_millis_;

tick_count_ = 0;
elapsed_millis_ = 0;
Expand Down
4 changes: 2 additions & 2 deletions 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> {

virtual void as_signalk_json(JsonDocument& doc) override {
doc["path"] = this->get_sk_path();
doc["value"] = ValueProducer<T>::output;
doc["value"] = ValueProducer<T>::output_;
}

virtual bool to_json(JsonObject& root) override {
Expand Down Expand Up @@ -93,7 +93,7 @@ class SKOutputRawJson : public SKOutput<String> {

virtual void as_signalk_json(JsonDocument& doc) override {
doc["path"] = this->get_sk_path();
doc["value"] = serialized(ValueProducer<String>::output);
doc["value"] = serialized(ValueProducer<String>::output_);
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/sensesp/signalk/signalk_put_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ class SKPutRequest : public SKPutRequestBase,
SKPutRequest(String sk_path, String config_path = "",
bool ignore_duplicates = true, uint32_t timeout = 5000)
: SKPutRequestBase(sk_path, config_path, timeout),
ignore_duplicates{ignore_duplicates} {}
ignore_duplicates_{ignore_duplicates} {}

virtual void set(const T& new_value) override {
if (ignore_duplicates && new_value == value) {
if (ignore_duplicates_ && new_value == value_) {
return;
}
if (!request_pending()) {
this->value = new_value;
this->value_ = new_value;
send_put_request();
} else {
ESP_LOGW(__FILENAME__,
Expand All @@ -161,12 +161,12 @@ class SKPutRequest : public SKPutRequestBase,
};

virtual void set_put_value(JsonObject& put_data) override {
put_data["value"] = value;
put_data["value"] = value_;
};

protected:
T value;
bool ignore_duplicates;
T value_;
bool ignore_duplicates_;
};

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/signalk/signalk_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SKOutputTime::SKOutputTime(const String& sk_path, const String& config_path)

void SKOutputTime::as_signalk_json(JsonDocument& doc){
doc["path"] = this->sk_path_;
doc["value"] = output;
doc["value"] = output_;
}

bool SKOutputTime::to_json(JsonObject& doc) {
Expand Down
22 changes: 11 additions & 11 deletions src/sensesp/signalk/signalk_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ template <>
void SKOutput<Position>::as_signalk_json(JsonDocument& doc) {
doc["path"] = this->get_sk_path();
JsonObject value = doc["value"].to<JsonObject>();
value["latitude"] = output.latitude;
value["longitude"] = output.longitude;
if (output.altitude != kPositionInvalidAltitude) {
value["altitude"] = output.altitude;
value["latitude"] = output_.latitude;
value["longitude"] = output_.longitude;
if (output_.altitude != kPositionInvalidAltitude) {
value["altitude"] = output_.altitude;
}
}

template <>
void SKOutput<ENUVector>::as_signalk_json(JsonDocument& doc) {
doc["path"] = this->get_sk_path();
JsonObject value = doc["value"].to<JsonObject>();
value["east"] = output.east;
value["north"] = output.north;
if (output.up != kPositionInvalidAltitude) {
value["up"] = output.up;
value["east"] = output_.east;
value["north"] = output_.north;
if (output_.up != kPositionInvalidAltitude) {
value["up"] = output_.up;
}
}

template <>
void SKOutput<AttitudeVector>::as_signalk_json(JsonDocument& doc) {
doc["path"] = this->get_sk_path();
JsonObject value = doc["value"].to<JsonObject>();
value["roll"] = output.roll;
value["pitch"] = output.pitch;
value["yaw"] = output.yaw;
value["roll"] = output_.roll;
value["pitch"] = output_.pitch;
value["yaw"] = output_.yaw;
}

} // namespace sensesp
2 changes: 1 addition & 1 deletion src/sensesp/signalk/signalk_ws_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SKWSClient : virtual public FileSystemSaveable,
*/
void sendTXT(String& payload);

private:
protected:
// these are the actually used values
String server_address_ = "";
uint16_t server_port_ = 80;
Expand Down
Loading

0 comments on commit 982f8fd

Please sign in to comment.