From 4486849df262b80c53277f63d548a47c1f272ec5 Mon Sep 17 00:00:00 2001 From: Stefan de Bruijn Date: Sun, 18 Jul 2021 21:01:15 +0200 Subject: [PATCH] Added variadic constructor arguments to handler. --- Grbl_Esp32/src/Configuration/HandlerBase.h | 6 +++--- Grbl_Esp32/src/Machine/Axes.cpp | 4 ++-- Grbl_Esp32/src/Machine/Axis.cpp | 4 ++-- Grbl_Esp32/src/Machine/Axis.h | 5 ++++- Grbl_Esp32/src/Machine/Gang.h | 3 ++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Grbl_Esp32/src/Configuration/HandlerBase.h b/Grbl_Esp32/src/Configuration/HandlerBase.h index 840eae13..e1705485 100644 --- a/Grbl_Esp32/src/Configuration/HandlerBase.h +++ b/Grbl_Esp32/src/Configuration/HandlerBase.h @@ -89,12 +89,12 @@ namespace Configuration { virtual HandlerType handlerType() = 0; - template - void section(const char* name, T*& value) { + template + void section(const char* name, T*& value, U... args) { if (handlerType() == HandlerType::Parser) { // For Parser, matchesUninitialized(name) resolves to _parser.is(name) if (value == nullptr && matchesUninitialized(name)) { - value = new T(); + value = new T(args...); enterSection(name, value); } } else { diff --git a/Grbl_Esp32/src/Machine/Axes.cpp b/Grbl_Esp32/src/Machine/Axes.cpp index aafe743e..631c9195 100644 --- a/Grbl_Esp32/src/Machine/Axes.cpp +++ b/Grbl_Esp32/src/Machine/Axes.cpp @@ -206,14 +206,14 @@ namespace Machine { tmp[0] = tolower(_names[i]); tmp[1] = '\0'; - handler.section(tmp, _axis[i]); + handler.section(tmp, _axis[i], i); } } void Axes::afterParse() { for (size_t i = 0; i < MAX_NUMBER_AXIS; ++i) { if (_axis[i] == nullptr) { - _axis[i] = new Axis(); + _axis[i] = new Axis(i); } } } diff --git a/Grbl_Esp32/src/Machine/Axis.cpp b/Grbl_Esp32/src/Machine/Axis.cpp index d1289ef4..acca250e 100644 --- a/Grbl_Esp32/src/Machine/Axis.cpp +++ b/Grbl_Esp32/src/Machine/Axis.cpp @@ -20,14 +20,14 @@ namespace Machine { tmp[4] = char(g + '0'); tmp[5] = '\0'; - handler.section(tmp, _gangs[g]); + handler.section(tmp, _gangs[g], g); } } void Axis::afterParse() { for (size_t i = 0; i < MAX_NUMBER_GANGED; ++i) { if (_gangs[i] == nullptr) { - _gangs[i] = new Gang(); + _gangs[i] = new Gang(i); } } } diff --git a/Grbl_Esp32/src/Machine/Axis.h b/Grbl_Esp32/src/Machine/Axis.h index 66cace76..31a55ac6 100644 --- a/Grbl_Esp32/src/Machine/Axis.h +++ b/Grbl_Esp32/src/Machine/Axis.h @@ -29,11 +29,12 @@ namespace Motors { namespace Machine { class Axis : public Configuration::Configurable { public: - Axis() { + Axis(int currentAxis): _index(currentAxis) { for (int i = 0; i < MAX_NUMBER_GANGED; ++i) { _gangs[i] = nullptr; } } + static const int MAX_NUMBER_GANGED = 2; Gang* _gangs[MAX_NUMBER_GANGED]; @@ -45,6 +46,8 @@ namespace Machine { float _maxTravel = 200.0f; bool _softLimits = false; + int _index; + // Configuration system helpers: void group(Configuration::HandlerBase& handler) override; void afterParse() override; diff --git a/Grbl_Esp32/src/Machine/Gang.h b/Grbl_Esp32/src/Machine/Gang.h index e718f77e..2d6cbf94 100644 --- a/Grbl_Esp32/src/Machine/Gang.h +++ b/Grbl_Esp32/src/Machine/Gang.h @@ -29,8 +29,9 @@ namespace Motors { namespace Machine { class Gang : public Configuration::Configurable { public: - Gang() = default; + Gang(int index) : _index(index) {} + int _index; Motors::Motor* _motor = nullptr; Endstops* _endstops = nullptr;