Skip to content

Commit

Permalink
Add current limit as an open/close condition (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Aug 16, 2024
1 parent 973b89f commit d291d80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/kernel/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ template <typename T>
class Property : public ConfigurationEntry {
public:
Property(ConfigurationSection* parent, const String& name, const T& defaultValue = T(), const bool secret = false)
: Property(parent, name, [defaultValue]() { return defaultValue; }, secret) {
}

Property(ConfigurationSection* parent, const String& name, const Property<T>& defaultValue, const bool secret = false)
: Property(parent, name, [defaultValue]() { return defaultValue.get(); }, secret) {
}

Property(ConfigurationSection* parent, const String& name, const std::function<const T&(void)> defaultValue, const bool secret = false)
: name(name)
, secret(secret)
, defaultValue(defaultValue) {
Expand All @@ -192,7 +200,7 @@ class Property : public ConfigurationEntry {
}

const T& get() const {
return configured ? value : defaultValue;
return configured ? value : defaultValue();
}

void load(const JsonObject& json) override {
Expand Down Expand Up @@ -228,7 +236,7 @@ class Property : public ConfigurationEntry {
const bool secret;
bool configured = false;
T value;
const T defaultValue;
const std::function<const T&(void)> defaultValue;
};

template <typename T>
Expand Down
16 changes: 16 additions & 0 deletions src/peripherals/chicken_door/ChickenDoor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,28 @@ class ChickenDoorLightSensorConfig
Property<seconds> latencyInterval { this, "latencyInterval", 5s };
};

class LimitConfig : public ConfigurationSection {
public:
LimitConfig(Property<gpio_num_t>& fallbackPin) : fallbackPin(fallbackPin) {
}

Property<double> current { this, "current", 0.0 };
Property<gpio_num_t> pin { this, "pin", fallbackPin };

private:
Property<gpio_num_t>& fallbackPin;
};

class ChickenDoorDeviceConfig
: public ConfigurationSection {
public:
Property<String> motor { this, "motor" };
Property<gpio_num_t> openPin { this, "openPin", GPIO_NUM_NC };
Property<gpio_num_t> closedPin { this, "closedPin", GPIO_NUM_NC };

NamedConfigurationEntry<LimitConfig> open { this, "open", openPin };
NamedConfigurationEntry<LimitConfig> close { this, "close", closedPin };

Property<seconds> movementTimeout { this, "movementTimeout", seconds(60) };

NamedConfigurationEntry<ChickenDoorLightSensorConfig> lightSensor { this, "lightSensor" };
Expand Down

0 comments on commit d291d80

Please sign in to comment.