1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-31 10:01:48 +02:00

Added variadic constructor arguments to handler.

This commit is contained in:
Stefan de Bruijn
2021-07-18 21:01:15 +02:00
parent d33d6cf436
commit 4486849df2
5 changed files with 13 additions and 9 deletions

View File

@@ -89,12 +89,12 @@ namespace Configuration {
virtual HandlerType handlerType() = 0; virtual HandlerType handlerType() = 0;
template <typename T> template <typename T, typename... U>
void section(const char* name, T*& value) { void section(const char* name, T*& value, U... args) {
if (handlerType() == HandlerType::Parser) { if (handlerType() == HandlerType::Parser) {
// For Parser, matchesUninitialized(name) resolves to _parser.is(name) // For Parser, matchesUninitialized(name) resolves to _parser.is(name)
if (value == nullptr && matchesUninitialized(name)) { if (value == nullptr && matchesUninitialized(name)) {
value = new T(); value = new T(args...);
enterSection(name, value); enterSection(name, value);
} }
} else { } else {

View File

@@ -206,14 +206,14 @@ namespace Machine {
tmp[0] = tolower(_names[i]); tmp[0] = tolower(_names[i]);
tmp[1] = '\0'; tmp[1] = '\0';
handler.section(tmp, _axis[i]); handler.section(tmp, _axis[i], i);
} }
} }
void Axes::afterParse() { void Axes::afterParse() {
for (size_t i = 0; i < MAX_NUMBER_AXIS; ++i) { for (size_t i = 0; i < MAX_NUMBER_AXIS; ++i) {
if (_axis[i] == nullptr) { if (_axis[i] == nullptr) {
_axis[i] = new Axis(); _axis[i] = new Axis(i);
} }
} }
} }

View File

@@ -20,14 +20,14 @@ namespace Machine {
tmp[4] = char(g + '0'); tmp[4] = char(g + '0');
tmp[5] = '\0'; tmp[5] = '\0';
handler.section(tmp, _gangs[g]); handler.section(tmp, _gangs[g], g);
} }
} }
void Axis::afterParse() { void Axis::afterParse() {
for (size_t i = 0; i < MAX_NUMBER_GANGED; ++i) { for (size_t i = 0; i < MAX_NUMBER_GANGED; ++i) {
if (_gangs[i] == nullptr) { if (_gangs[i] == nullptr) {
_gangs[i] = new Gang(); _gangs[i] = new Gang(i);
} }
} }
} }

View File

@@ -29,11 +29,12 @@ namespace Motors {
namespace Machine { namespace Machine {
class Axis : public Configuration::Configurable { class Axis : public Configuration::Configurable {
public: public:
Axis() { Axis(int currentAxis): _index(currentAxis) {
for (int i = 0; i < MAX_NUMBER_GANGED; ++i) { for (int i = 0; i < MAX_NUMBER_GANGED; ++i) {
_gangs[i] = nullptr; _gangs[i] = nullptr;
} }
} }
static const int MAX_NUMBER_GANGED = 2; static const int MAX_NUMBER_GANGED = 2;
Gang* _gangs[MAX_NUMBER_GANGED]; Gang* _gangs[MAX_NUMBER_GANGED];
@@ -45,6 +46,8 @@ namespace Machine {
float _maxTravel = 200.0f; float _maxTravel = 200.0f;
bool _softLimits = false; bool _softLimits = false;
int _index;
// Configuration system helpers: // Configuration system helpers:
void group(Configuration::HandlerBase& handler) override; void group(Configuration::HandlerBase& handler) override;
void afterParse() override; void afterParse() override;

View File

@@ -29,8 +29,9 @@ namespace Motors {
namespace Machine { namespace Machine {
class Gang : public Configuration::Configurable { class Gang : public Configuration::Configurable {
public: public:
Gang() = default; Gang(int index) : _index(index) {}
int _index;
Motors::Motor* _motor = nullptr; Motors::Motor* _motor = nullptr;
Endstops* _endstops = nullptr; Endstops* _endstops = nullptr;