mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-08 21:30:54 +02:00
Fixed bug in enumitem parsing / string equals. Added unit test for yaml enums. Added some comments.
This commit is contained in:
@@ -163,6 +163,6 @@ namespace Configuration {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return e->value;
|
return e->value; // Terminal value is default.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Usage:
|
||||||
|
//
|
||||||
|
// EnumItem stepTypes[] = {
|
||||||
|
// { ST_TIMED, "Timed" }, { ST_RMT, "RMT" }, { ST_I2S_STATIC, "I2S_static" }, { ST_I2S_STREAM, "I2S_stream" }, EnumItem(ST_RMT)
|
||||||
|
// };
|
||||||
|
|
||||||
struct EnumItem {
|
struct EnumItem {
|
||||||
EnumItem() : value(0), name(nullptr) {}
|
// Used for brace initialization
|
||||||
|
EnumItem() {}
|
||||||
|
|
||||||
|
// Set enumItem with a default value as last item in the EnumItem array. This is the terminator.
|
||||||
|
EnumItem(int defaultValue) : value(defaultValue), name(nullptr) {}
|
||||||
|
|
||||||
|
// Other items are here.
|
||||||
EnumItem(int val, const char* n) : value(val), name(n) {}
|
EnumItem(int val, const char* n) : value(val), name(n) {}
|
||||||
|
|
||||||
int value;
|
int value;
|
||||||
|
@@ -127,7 +127,7 @@ typedef struct {
|
|||||||
static st_prep_t prep;
|
static st_prep_t prep;
|
||||||
|
|
||||||
EnumItem stepTypes[] = {
|
EnumItem stepTypes[] = {
|
||||||
{ ST_TIMED, "Timed" }, { ST_RMT, "RMT" }, { ST_I2S_STATIC, "I2S_static" }, { ST_I2S_STREAM, "I2S_stream" }, EnumItem()
|
{ ST_TIMED, "Timed" }, { ST_RMT, "RMT" }, { ST_I2S_STATIC, "I2S_static" }, { ST_I2S_STREAM, "I2S_stream" }, EnumItem(ST_RMT)
|
||||||
};
|
};
|
||||||
|
|
||||||
/* "The Stepper Driver Interrupt" - This timer interrupt is the workhorse of Grbl. Grbl employs
|
/* "The Stepper Driver Interrupt" - This timer interrupt is the workhorse of Grbl. Grbl employs
|
||||||
|
@@ -67,7 +67,7 @@ public:
|
|||||||
bool equals(const char* o) const {
|
bool equals(const char* o) const {
|
||||||
const char* c = start_;
|
const char* c = start_;
|
||||||
const char* oc = o;
|
const char* oc = o;
|
||||||
for (; *c != '\0' && *oc != '\0' && tolower(*c) == tolower(*oc); ++c, ++oc) {}
|
for (; c != end_ && *oc != '\0' && tolower(*c) == tolower(*oc); ++c, ++oc) {}
|
||||||
return c == end_ && *oc == '\0';
|
return c == end_ && *oc == '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,6 +34,25 @@ namespace Configuration {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum stepper_id_t {
|
||||||
|
ST_TIMED = 0,
|
||||||
|
ST_RMT,
|
||||||
|
ST_I2S_STREAM,
|
||||||
|
ST_I2S_STATIC,
|
||||||
|
};
|
||||||
|
|
||||||
|
EnumItem stepTypes[] = {
|
||||||
|
{ ST_TIMED, "Timed" }, { ST_RMT, "RMT" }, { ST_I2S_STATIC, "I2S_static" }, { ST_I2S_STREAM, "I2S_stream" }, EnumItem(ST_RMT)
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestBasicEnum : public Configurable {
|
||||||
|
public:
|
||||||
|
int value;
|
||||||
|
|
||||||
|
void validate() const {}
|
||||||
|
void handle(HandlerBase& handler) { handler.handle("type", value, stepTypes); }
|
||||||
|
};
|
||||||
|
|
||||||
class TestHierarchical : public Configurable {
|
class TestHierarchical : public Configurable {
|
||||||
public:
|
public:
|
||||||
TestBasic* n1 = nullptr;
|
TestBasic* n1 = nullptr;
|
||||||
@@ -196,4 +215,33 @@ namespace Configuration {
|
|||||||
}
|
}
|
||||||
Assert(test.foo == 2);
|
Assert(test.foo == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ST_TIMED, "Timed" }, { ST_RMT, "RMT" }, { ST_I2S_STATIC, "I2S_static" }, { ST_I2S_STREAM, "I2S_stream" }, EnumItem()
|
||||||
|
Test(YamlTreeBuilder, Enum1) {
|
||||||
|
{
|
||||||
|
const char* config = "type: Timed\n";
|
||||||
|
TestBasicEnum test;
|
||||||
|
Helper::Parse(config, test);
|
||||||
|
Assert(test.value == int(ST_TIMED));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char* config = "type: RMT\n";
|
||||||
|
TestBasicEnum test;
|
||||||
|
Helper::Parse(config, test);
|
||||||
|
Assert(test.value == int(ST_RMT));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const char* config = "type: I2S_static\n";
|
||||||
|
TestBasicEnum test;
|
||||||
|
Helper::Parse(config, test);
|
||||||
|
Assert(test.value == int(ST_I2S_STATIC));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const char* config = "type: I2S_stream\n";
|
||||||
|
TestBasicEnum test;
|
||||||
|
Helper::Parse(config, test);
|
||||||
|
Assert(test.value == int(ST_I2S_STREAM));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user