1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-30 09:39:49 +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;
template <typename T>
void section(const char* name, T*& value) {
template <typename T, typename... U>
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 {

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;

View File

@@ -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;