void nc(String st) {
String xx, yy, zz;
int ok = 1;
st.toUpperCase();
// makelangelo sends "N[0-9]+" for the line number
// TODO Strip this out
if (st.indexOf("G28") >= 0) { // home - G28 [A] [B] [C] [L] [O] [R] [U] [V] [W] [X] [Y] [Z]
//teleport(0, 0); // home - should read which axises to home
return;
}
if (st.indexOf("M0") >= 0) { // stop M0 [P<ms>] [S<sec>] [string]
// ignore for now - should delay for P ms and S secs
return;
}
// TODO Read the feedrate from the F parameter -- F and A which are in motor steps per second.
float x, y, z;
int px, py, pz;
px = st.indexOf('X');
py = st.indexOf('Y');
pz = st.indexOf('Z');
if (px == -1 || py == -1) ok = 0;
if (pz == -1) {
pz = st.length();
} else {
zz = st.substring(pz + 1, st.length());
z = zz.toFloat();
//if (z > 0) pen_up();
//if (z <= 0) pen_down();
}
xx = st.substring(px + 1);
yy = st.substring(py + 1); // just change end to strlen it wll stop at the first non number
//xx.trim(); // no need for this.. toFloat will trim
//yy.trim();
//if (ok) line(xx.toFloat(), yy.toFloat());
if (ok) {
Serial.print("st: [");
Serial.print(st);
Serial.println("]");
float fx, fy;
fx = xx.toFloat();
Serial.print("xx: [");
Serial.print(xx);
Serial.println("]");
fy = yy.toFloat();
Serial.print("yy: [");
Serial.print(yy);
Serial.println("]");
Serial.println(px);
Serial.println(py);
Serial.println(st.length());
Serial.print("line(): x[");
Serial.print(st.substring(px+1));
Serial.print("]:");
Serial.print(fx);
Serial.print(" y: ");
Serial.println(fy);
//line(fx,fy);
/*
Serial.print("should be: ");
Serial.print(extractValue(st, 'X'));
Serial.print(" ");
Serial.println(extractValue(st, 'Y'));
*/
}
}
void setup() {
Serial.begin(115200);
delay(2000);
// put your setup code here, to run once:
nc("N17 G0 X-100.000 Y0.000 F3000.0*73");
}
void loop() {
// put your main code here, to run repeatedly:
}