diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..53ddc4a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "*.js": "javascript", + "*.h": "cpp", + "string": "cpp" + } +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index d8fdc80..eb1bbc1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [env:mega2560] -platform = atmelavr +platform = atmelave board = megaatmega2560 framework = arduino lib_extra_dirs = ~/Documents/Arduino/libraries diff --git a/src/ClawMachineOverhaul.ino b/src/ClawMachineOverhaul.ino index 780120e..35e9c80 100644 --- a/src/ClawMachineOverhaul.ino +++ b/src/ClawMachineOverhaul.ino @@ -1,14 +1,16 @@ #include #include #include "MotorControlPart.h" +#include "ZCodeParser.h" void setup() { Serial.begin(115200); - setupMotor(); + // setupMotor(); // Create tasks - xTaskCreate(MotorControlTask, "Motor", 200, NULL, 10, NULL); + // xTaskCreate(MotorControlTask, "Motor", 200, NULL, 10, NULL); + ZCodeParser::ParseString("G0 Z2 ", void, void); } void loop() { diff --git a/src/ZCodeParser.h b/src/ZCodeParser.h new file mode 100644 index 0000000..2a6d283 --- /dev/null +++ b/src/ZCodeParser.h @@ -0,0 +1,45 @@ +#include +#include + +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 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"); + +} \ No newline at end of file