From d291d80457350f7bff3631e07ee94a1ce07ec88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Pint=C3=A9r?= Date: Wed, 17 Jul 2024 20:47:52 +0200 Subject: [PATCH] Add current limit as an open/close condition (WIP) --- src/kernel/Configuration.hpp | 12 ++++++++++-- src/peripherals/chicken_door/ChickenDoor.hpp | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) 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" };