Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error when saving configuration for FloatThreshold #649

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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