Has errors but sync

This commit is contained in:
BOTAlex 2025-01-20 15:13:01 +01:00
parent 4903d45e4b
commit 44aa5576d5
4 changed files with 57 additions and 3 deletions

7
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"files.associations": {
"*.js": "javascript",
"*.h": "cpp",
"string": "cpp"
}
}

View File

@ -10,7 +10,7 @@
[env:mega2560]
platform = atmelavr
platform = atmelave
board = megaatmega2560
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries

View File

@ -1,14 +1,16 @@
#include <Arduino.h>
#include <Arduino_FreeRTOS.h>
#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() {

45
src/ZCodeParser.h Normal file
View File

@ -0,0 +1,45 @@
#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");
}