diff --git a/frontend/src/lib/_fbs/open-shock/serialization/configuration/estop-config.ts b/frontend/src/lib/_fbs/open-shock/serialization/configuration/estop-config.ts index 6eb9b148..ac41c7bd 100644 --- a/frontend/src/lib/_fbs/open-shock/serialization/configuration/estop-config.ts +++ b/frontend/src/lib/_fbs/open-shock/serialization/configuration/estop-config.ts @@ -43,8 +43,16 @@ active():boolean { return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; } +/** + * Set When EmergencyStop is a latching switch + */ +latching():boolean { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + static startEStopConfig(builder:flatbuffers.Builder) { - builder.startObject(3); + builder.startObject(4); } static addEnabled(builder:flatbuffers.Builder, enabled:boolean) { @@ -59,16 +67,21 @@ static addActive(builder:flatbuffers.Builder, active:boolean) { builder.addFieldInt8(2, +active, +false); } +static addLatching(builder:flatbuffers.Builder, latching:boolean) { + builder.addFieldInt8(3, +latching, +false); +} + static endEStopConfig(builder:flatbuffers.Builder):flatbuffers.Offset { const offset = builder.endObject(); return offset; } -static createEStopConfig(builder:flatbuffers.Builder, enabled:boolean, gpioPin:number, active:boolean):flatbuffers.Offset { +static createEStopConfig(builder:flatbuffers.Builder, enabled:boolean, gpioPin:number, active:boolean, latching:boolean):flatbuffers.Offset { EStopConfig.startEStopConfig(builder); EStopConfig.addEnabled(builder, enabled); EStopConfig.addGpioPin(builder, gpioPin); EStopConfig.addActive(builder, active); + EStopConfig.addLatching(builder, latching); return EStopConfig.endEStopConfig(builder); } } diff --git a/include/Common.h b/include/Common.h index 665acee7..a70a08d1 100644 --- a/include/Common.h +++ b/include/Common.h @@ -33,6 +33,10 @@ #define OPENSHOCK_ESTOP_PIN OPENSHOCK_GPIO_INVALID #endif +#ifndef OPENSHOCK_ESTOP_LATCHING +#define OPENSHOCK_ESTOP_LATCHING 0 +#endif + // Check if OPENSHOCK_FW_USERAGENT is overridden trough compiler flags, if not, generate a default useragent. #ifndef OPENSHOCK_FW_USERAGENT #define OPENSHOCK_FW_USERAGENT OPENSHOCK_FW_HOSTNAME "/" OPENSHOCK_FW_VERSION " (arduino-esp32; " OPENSHOCK_FW_BOARD "; " OPENSHOCK_FW_CHIP "; Espressif)" diff --git a/include/config/EStopConfig.h b/include/config/EStopConfig.h index de726734..87414c1d 100644 --- a/include/config/EStopConfig.h +++ b/include/config/EStopConfig.h @@ -7,10 +7,12 @@ namespace OpenShock::Config { struct EStopConfig : public ConfigBase { EStopConfig(); - EStopConfig(bool enabled, gpio_num_t gpioPin); + EStopConfig(bool enabled, gpio_num_t gpioPin, bool latching, bool active); bool enabled; gpio_num_t gpioPin; + bool latching; + bool active; void ToDefault() override; diff --git a/include/serialization/_fbs/HubConfig_generated.h b/include/serialization/_fbs/HubConfig_generated.h index 4ba0eff8..f499c6b4 100644 --- a/include/serialization/_fbs/HubConfig_generated.h +++ b/include/serialization/_fbs/HubConfig_generated.h @@ -190,7 +190,8 @@ struct EStopConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_ENABLED = 4, VT_GPIO_PIN = 6, - VT_ACTIVE = 8 + VT_ACTIVE = 8, + VT_LATCHING = 10 }; bool enabled() const { return GetField(VT_ENABLED, 0) != 0; @@ -203,11 +204,16 @@ struct EStopConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { bool active() const { return GetField(VT_ACTIVE, 0) != 0; } + /// Set When EmergencyStop is a latching switch + bool latching() const { + return GetField(VT_LATCHING, 0) != 0; + } bool Verify(::flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_ENABLED, 1) && VerifyField(verifier, VT_GPIO_PIN, 1) && VerifyField(verifier, VT_ACTIVE, 1) && + VerifyField(verifier, VT_LATCHING, 1) && verifier.EndTable(); } }; @@ -225,6 +231,9 @@ struct EStopConfigBuilder { void add_active(bool active) { fbb_.AddElement(EStopConfig::VT_ACTIVE, static_cast(active), 0); } + void add_latching(bool latching) { + fbb_.AddElement(EStopConfig::VT_LATCHING, static_cast(latching), 0); + } explicit EStopConfigBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -240,8 +249,10 @@ inline ::flatbuffers::Offset CreateEStopConfig( ::flatbuffers::FlatBufferBuilder &_fbb, bool enabled = false, int8_t gpio_pin = 0, - bool active = false) { + bool active = false, + bool latching = false) { EStopConfigBuilder builder_(_fbb); + builder_.add_latching(latching); builder_.add_active(active); builder_.add_gpio_pin(gpio_pin); builder_.add_enabled(enabled); diff --git a/src/config/EStopConfig.cpp b/src/config/EStopConfig.cpp index df78b092..bebdc00c 100644 --- a/src/config/EStopConfig.cpp +++ b/src/config/EStopConfig.cpp @@ -12,19 +12,25 @@ using namespace OpenShock::Config; EStopConfig::EStopConfig() : enabled(OpenShock::IsValidInputPin(OPENSHOCK_ESTOP_PIN)) , gpioPin(static_cast(OPENSHOCK_ESTOP_PIN)) + , latching(OPENSHOCK_ESTOP_LATCHING) + , active(false) { } -EStopConfig::EStopConfig(bool enabled, gpio_num_t gpioPin) +EStopConfig::EStopConfig(bool enabled, gpio_num_t gpioPin, bool latching, bool active) : enabled(enabled) , gpioPin(gpioPin) + , latching(latching) + , active(active) { } void EStopConfig::ToDefault() { - enabled = OpenShock::IsValidInputPin(OPENSHOCK_ESTOP_PIN); - gpioPin = static_cast(OPENSHOCK_ESTOP_PIN); + enabled = OpenShock::IsValidInputPin(OPENSHOCK_ESTOP_PIN); + gpioPin = static_cast(OPENSHOCK_ESTOP_PIN); + latching = OPENSHOCK_ESTOP_LATCHING; + active = false; } bool EStopConfig::FromFlatbuffers(const Serialization::Configuration::EStopConfig* config) @@ -42,12 +48,16 @@ bool EStopConfig::FromFlatbuffers(const Serialization::Configuration::EStopConfi enabled = false; } + latching = config->latching(); + + active = config->active(); + return true; } flatbuffers::Offset EStopConfig::ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const { - return Serialization::Configuration::CreateEStopConfig(builder, enabled, gpioPin); + return Serialization::Configuration::CreateEStopConfig(builder, enabled, gpioPin, active, latching); } bool EStopConfig::FromJSON(const cJSON* json) @@ -69,6 +79,16 @@ bool EStopConfig::FromJSON(const cJSON* json) return false; } + if (!Internal::Utils::FromJsonBool(latching, json, "latching", OPENSHOCK_ESTOP_LATCHING)) { + OS_LOGE(TAG, "Failed to parse latching"); + return false; + } + + if (!Internal::Utils::FromJsonBool(active, json, "active", false)) { + OS_LOGE(TAG, "Failed to parse active"); + return false; + } + return true; } @@ -78,6 +98,8 @@ cJSON* EStopConfig::ToJSON(bool withSensitiveData) const cJSON_AddBoolToObject(root, "enabled", enabled); cJSON_AddNumberToObject(root, "gpioPin", gpioPin); + cJSON_AddBoolToObject(root, "latching", latching); + cJSON_AddBoolToObject(root, "active", active); return root; }