diff --git a/src/kernel/Configuration.hpp b/src/kernel/Configuration.hpp index 95c3ef87..8d09510a 100644 --- a/src/kernel/Configuration.hpp +++ b/src/kernel/Configuration.hpp @@ -180,6 +180,14 @@ template 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& defaultValue, const bool secret = false) + : Property(parent, name, [defaultValue]() { return defaultValue.get(); }, secret) { + } + + Property(ConfigurationSection* parent, const String& name, const std::function defaultValue, const bool secret = false) : name(name) , secret(secret) , defaultValue(defaultValue) { @@ -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 { @@ -228,7 +236,7 @@ class Property : public ConfigurationEntry { const bool secret; bool configured = false; T value; - const T defaultValue; + const std::function defaultValue; }; template diff --git a/src/peripherals/chicken_door/ChickenDoor.hpp b/src/peripherals/chicken_door/ChickenDoor.hpp index 961960db..67bf8983 100644 --- a/src/peripherals/chicken_door/ChickenDoor.hpp +++ b/src/peripherals/chicken_door/ChickenDoor.hpp @@ -68,12 +68,28 @@ class ChickenDoorLightSensorConfig Property latencyInterval { this, "latencyInterval", 5s }; }; +class LimitConfig : public ConfigurationSection { +public: + LimitConfig(Property& fallbackPin) : fallbackPin(fallbackPin) { + } + + Property current { this, "current", 0.0 }; + Property pin { this, "pin", fallbackPin }; + +private: + Property& fallbackPin; +}; + class ChickenDoorDeviceConfig : public ConfigurationSection { public: Property motor { this, "motor" }; Property openPin { this, "openPin", GPIO_NUM_NC }; Property closedPin { this, "closedPin", GPIO_NUM_NC }; + + NamedConfigurationEntry open { this, "open", openPin }; + NamedConfigurationEntry close { this, "close", closedPin }; + Property movementTimeout { this, "movementTimeout", seconds(60) }; NamedConfigurationEntry lightSensor { this, "lightSensor" };