ClawMachineCosplay/src/ZCodeParser.h

45 lines
968 B
C
Raw Normal View History

2025-01-20 15:13:01 +01:00
#include <Arduino.h>
#include <vector>
typedef struct {
char Axis;
int time;
} MoveCommand;
class ZCodeParser
{
private:
public:
static void ParseString(String inString, MoveCommand *outMovecommands, int *numOfCommands);
};
void ZCodeParser::ParseString(String inString, MoveCommand *outMovecommands, int *numOfCommands){
// G0 = move, no block
// G1 = move, block
// ; = comments
// \n = new command
std::vector<String> stringCommands;
int startIndex = 0;
int endIndex;
while (true)
{
endIndex = inString.indexOf('\n', startIndex);
if (endIndex == -1){
break;
}
stringCommands.push_back(inString.substring(startIndex, endIndex));
startIndex = endIndex;
}
Serial.println("Parsed: ");
for (size_t i = 0; i < stringCommands.size(); i++)
{
Serial.print(stringCommands[i]);
Serial.print(", ");
}
Serial.println("\n");
}