Skip to content

Commit

Permalink
Merge pull request #694 from SignalK/constantsensor_get
Browse files Browse the repository at this point in the history
Rename ConstantSensor getters and setters
  • Loading branch information
mairas authored Jun 1, 2024
2 parents e195a0b + 60b49e2 commit 3746425
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/sensesp/sensors/constant_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ class ConstantSensor : public Sensor<T> {
: Sensor<T>(config_path), value_{value}, send_interval_{send_interval} {
this->load_configuration();

// Emit the initial value once to set the output
ReactESP::app->onDelay(0,
[this]() { this->emit(value_); });
// Then, emit the value at the specified interval
ReactESP::app->onRepeat(send_interval_ * 1000,
[this]() { this->emit(value_); });
}

void set_value(T value) { value_ = value; }
T get_value() { return value_; }
void set(T value) { value_ = value; }

protected:
virtual void get_configuration(JsonObject &doc) override {
Expand Down

0 comments on commit 3746425

Please sign in to comment.