still errors but im falling asleep :(
This commit is contained in:
parent
44aa5576d5
commit
b26d8ec771
|
@ -2,6 +2,56 @@
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"*.js": "javascript",
|
"*.js": "javascript",
|
||||||
"*.h": "cpp",
|
"*.h": "cpp",
|
||||||
"string": "cpp"
|
"string": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"associative_base": "cpp",
|
||||||
|
"basic_definitions": "cpp",
|
||||||
|
"bitset": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"char_traits": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"complex": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"func_exception": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"ios": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"iostream": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"istream_helpers": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"iterator_base": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"locale": "cpp",
|
||||||
|
"map": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"ostream_helpers": "cpp",
|
||||||
|
"queue": "cpp",
|
||||||
|
"serstream": "cpp",
|
||||||
|
"set": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stack": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"string_iostream": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"valarray": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,9 +10,10 @@
|
||||||
|
|
||||||
|
|
||||||
[env:mega2560]
|
[env:mega2560]
|
||||||
platform = atmelave
|
platform = atmelavr
|
||||||
board = megaatmega2560
|
board = megaatmega2560
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_extra_dirs = ~/Documents/Arduino/libraries
|
lib_extra_dirs = ~/Documents/Arduino/libraries
|
||||||
lib_deps =
|
lib_deps =
|
||||||
FreeRTOS
|
FreeRTOS
|
||||||
|
upload_speed = 115200
|
|
@ -1,16 +1,18 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Arduino_FreeRTOS.h>
|
// #include <Arduino_FreeRTOS.h>
|
||||||
#include "MotorControlPart.h"
|
#include "MotorControlPart.h"
|
||||||
#include "ZCodeParser.h"
|
#include "ZCodeParser.h"
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
delayMicroseconds(1000);
|
||||||
|
|
||||||
// setupMotor();
|
// setupMotor();
|
||||||
|
|
||||||
// Create tasks
|
// Create tasks
|
||||||
// xTaskCreate(MotorControlTask, "Motor", 200, NULL, 10, NULL);
|
// xTaskCreate(MotorControlTask, "Motor", 200, NULL, 10, NULL);
|
||||||
ZCodeParser::ParseString("G0 Z2 ", void, void);
|
ZCodeParser::ParseString("G0 E20 X40; Comment test\nG1 Y50 X69\nG0 Y235 E5532");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
|
@ -2,44 +2,73 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char Axis;
|
String command;
|
||||||
int time;
|
std::vector<String> params;
|
||||||
} MoveCommand;
|
} GCommand;
|
||||||
|
|
||||||
class ZCodeParser
|
class ZCodeParser // Variant of GCode, but made by Zhen. Lol
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
static std::vector<String> splitString(const String &input, char delimiter);
|
||||||
public:
|
public:
|
||||||
static void ParseString(String inString, MoveCommand *outMovecommands, int *numOfCommands);
|
static std::vector<GCommand> ParseString(const String inString);
|
||||||
};
|
};
|
||||||
|
|
||||||
void ZCodeParser::ParseString(String inString, MoveCommand *outMovecommands, int *numOfCommands){
|
std::vector<String> ZCodeParser::splitString(const String &input, char delimiter) {
|
||||||
// G0 = move, no block
|
std::vector<String> result;
|
||||||
// G1 = move, block
|
|
||||||
// ; = comments
|
|
||||||
// \n = new command
|
|
||||||
|
|
||||||
std::vector<String> stringCommands;
|
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
int endIndex;
|
int endIndex;
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
endIndex = inString.indexOf('\n', startIndex);
|
|
||||||
|
|
||||||
if (endIndex == -1){
|
while (true) {
|
||||||
|
endIndex = input.indexOf(delimiter, startIndex);
|
||||||
|
if (endIndex == -1) {
|
||||||
|
result.push_back(input.substring(startIndex)); // Get the rest of the string
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
result.push_back(input.substring(startIndex, endIndex));
|
||||||
|
startIndex = endIndex + 1;
|
||||||
|
}
|
||||||
|
|
||||||
stringCommands.push_back(inString.substring(startIndex, endIndex));
|
return result;
|
||||||
startIndex = endIndex;
|
}
|
||||||
|
|
||||||
|
std::vector<GCommand> ZCodeParser::ParseString(const String inString){
|
||||||
|
// G0 = move, no block
|
||||||
|
// G1 = move, block
|
||||||
|
// M17 = Enable Stepper
|
||||||
|
// M18 = Disable Stepper
|
||||||
|
// ; = comments
|
||||||
|
// \n = new command
|
||||||
|
|
||||||
|
std::vector<String> stringCommands = ZCodeParser::splitString(inString, '\n');
|
||||||
|
|
||||||
|
// Remove comments
|
||||||
|
for (size_t i = 0; i < stringCommands.size(); i++)
|
||||||
|
{
|
||||||
|
int commentIndex = stringCommands[i].indexOf(';');
|
||||||
|
if (commentIndex == -1) continue; // Continue if no comments
|
||||||
|
|
||||||
|
stringCommands[i] = stringCommands[i].substring(0, commentIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract function name and params
|
||||||
|
std::vector<GCommand> commnads;
|
||||||
|
for (size_t i = 0; i < stringCommands.size(); i++)
|
||||||
|
{
|
||||||
|
std::vector<String> seperatedStrings = ZCodeParser::splitString(stringCommands[i], ' ');
|
||||||
|
GCommand commnad;
|
||||||
|
commnad.command = seperatedStrings[0];
|
||||||
|
stringCommands.erase(stringCommands.begin());
|
||||||
|
commnad.params = stringCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("Parsed: ");
|
Serial.println("Parsed: ");
|
||||||
for (size_t i = 0; i < stringCommands.size(); i++)
|
for (size_t i = 0; i < commnads.size(); i++)
|
||||||
{
|
{
|
||||||
Serial.print(stringCommands[i]);
|
Serial.print(commnads[i].command);
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
}
|
}
|
||||||
Serial.println("\n");
|
Serial.println("\n");
|
||||||
|
|
||||||
|
// return ;
|
||||||
}
|
}
|
Loading…
Reference in New Issue