Skip to content

Commit

Permalink
Fixed error when saving configuration for FloatThreshold
Browse files Browse the repository at this point in the history
Removed unused `out_range_` parameter from ThresholdTransform
  • Loading branch information
rogerlittin committed Apr 3, 2023
1 parent 0203ca0 commit d655ba6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/sensesp/transforms/threshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void ThresholdTransform<C, P>::set_input(C input, uint8_t input_channel) {
if (input >= min_value_ && input <= max_value_) {
this->output = in_range_;
} else {
this->output = out_range_;
this->output = !in_range_;
}

this->notify();
Expand All @@ -29,7 +29,7 @@ static const char FLOAT_SCHEMA[] PROGMEM = R"({
})";

bool FloatThreshold::set_configuration(const JsonObject& config) {
String expected[] = {"min", "max", "in_range", "value"};
String expected[] = {"min", "max", "in_range"};
for (auto str : expected) {
if (!config.containsKey(str)) {
return false;
Expand Down
15 changes: 4 additions & 11 deletions src/sensesp/transforms/threshold.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ namespace sensesp {
* in_range.
*
* @param in_range Output value if input value is in range.
*
* @param out_range Output value if input value is out of the range.
*/
template <typename C, typename P>
class ThresholdTransform : public Transform<C, P> {
public:
ThresholdTransform(C min_value, C max_value, P in_range, P out_range,
String config_path = "")
ThresholdTransform(C min_value, C max_value, P in_range, String config_path = "")
: Transform<C, P>(config_path),
min_value_{min_value},
max_value_{max_value},
in_range_{in_range},
out_range_{out_range} {
in_range_{in_range} {
this->load_configuration();
};
virtual void set_input(C new_value, uint8_t input_channel = 0) override;
Expand All @@ -36,7 +32,6 @@ class ThresholdTransform : public Transform<C, P> {
C min_value_;
C max_value_;
P in_range_;
P out_range_;
};

/**
Expand All @@ -59,8 +54,7 @@ class FloatThreshold : public ThresholdTransform<float, bool> {
public:
FloatThreshold(float min_value, float max_value, bool in_range = true,
String config_path = "")
: ThresholdTransform<float, bool>(min_value, max_value, in_range,
!in_range, config_path) {}
: ThresholdTransform<float, bool>(min_value, max_value, in_range, config_path) {}

virtual void get_configuration(JsonObject& doc) override;
virtual bool set_configuration(const JsonObject& config) override;
Expand All @@ -87,8 +81,7 @@ class IntThreshold : public ThresholdTransform<int, bool> {
public:
IntThreshold(int min_value, int max_value, bool in_range = true,
String config_path = "")
: ThresholdTransform<int, bool>(min_value, max_value, in_range, !in_range,
config_path) {}
: ThresholdTransform<int, bool>(min_value, max_value, in_range, config_path) {}

virtual void get_configuration(JsonObject& doc) override;
virtual bool set_configuration(const JsonObject& config) override;
Expand Down

0 comments on commit d655ba6

Please sign in to comment.