making it so we dont have to parse for more than one newline

pull/41/head
Connor Rigby 2016-09-09 10:18:16 -07:00
parent 2487efc4ad
commit f7f33d4c0d
22 changed files with 66 additions and 67 deletions

View File

@ -41,7 +41,7 @@ Command::Command(String commandString) {
}
while (charPointer != NULL) {
getParameter(charPointer);
charPointer = strtok(NULL, " \n\r");
charPointer = strtok(NULL, " \r\n");
}
}
@ -189,7 +189,7 @@ void Command::print() {
Serial.print(element);
Serial.print(", M: ");
Serial.print(mode);
Serial.print("\n");
Serial.print("\r\n");
}
CommandCodeEnum Command::getCodeEnum() {
@ -243,4 +243,3 @@ long Command::getE() {
long Command::getM() {
return mode;
}

View File

@ -78,7 +78,7 @@ void CurrentState::printPosition() {
Serial.print(y);
Serial.print(" Z");
Serial.print(z);
Serial.print("\n");
Serial.print("\r\n");
}
void CurrentState::printBool(bool value)
@ -107,7 +107,7 @@ void CurrentState::printEndStops() {
printBool(endStopState[2][0]);
Serial.print(" ZB");
printBool(endStopState[2][1]);
Serial.print("\n");
Serial.print("\r\n");
}
void CurrentState::print() {

View File

@ -25,7 +25,7 @@ F11Handler::F11Handler() {
int F11Handler::execute(Command* command) {
if (LOGGING) {
Serial.print("R99 HOME X\n");
Serial.print("R99 HOME X\r\n");
}
StepperControl::getInstance()->moveToCoords(0,0,0, 0,0,0, true, false, false);

View File

@ -25,7 +25,7 @@ F12Handler::F12Handler() {
int F12Handler::execute(Command* command) {
if (LOGGING) {
Serial.print("R99 HOME Y\n");
Serial.print("R99 HOME Y\r\n");
}
StepperControl::getInstance()->moveToCoords(0,0,0, 0,0,0, false, true, false);

View File

@ -25,7 +25,7 @@ F13Handler::F13Handler() {
int F13Handler::execute(Command* command) {
if (LOGGING) {
Serial.print("R99 HOME Z\n");
Serial.print("R99 HOME Z\r\n");
}
StepperControl::getInstance()->moveToCoords(0,0,0, 0,0,0, false, false, true);

View File

@ -27,7 +27,7 @@ int F14Handler::execute(Command* command) {
int ret = 0;
if (LOGGING) {
Serial.print("R99 CALIBRATE X\n");
Serial.print("R99 CALIBRATE X\r\n");
}
ret = StepperControl::getInstance()->calibrateAxis(0);

View File

@ -25,7 +25,7 @@ F15Handler::F15Handler() {
int F15Handler::execute(Command* command) {
if (LOGGING) {
Serial.print("R99 HOME Z\n");
Serial.print("R99 HOME Z\r\n");
}
StepperControl::getInstance()->calibrateAxis(1);

View File

@ -25,7 +25,7 @@ F16Handler::F16Handler() {
int F16Handler::execute(Command* command) {
if (LOGGING) {
Serial.print("R99 HOME Z\n");
Serial.print("R99 HOME Z\r\n");
}
StepperControl::getInstance()->calibrateAxis(2);

View File

@ -39,7 +39,7 @@ Serial.print(" ");
Serial.print(command->getV());
Serial.print(" ");
Serial.print("\n");
Serial.print("\r\n");
*/
ParameterList::getInstance()->writeValue(command->getP(), command->getV());

View File

@ -25,10 +25,10 @@ F81Handler::F81Handler() {
int F81Handler::execute(Command* command) {
Serial.print("home\n");
Serial.print("home\r\n");
if (LOGGING) {
Serial.print("R99 Report end stops\n");
Serial.print("R99 Report end stops\r\n");
}
// Report back the end stops

View File

@ -26,7 +26,7 @@ F82Handler::F82Handler() {
int F82Handler::execute(Command* command) {
if (LOGGING) {
Serial.print("R99 Report current position\n");
Serial.print("R99 Report current position\r\n");
}
CurrentState::getInstance()->printPosition();

View File

@ -26,12 +26,12 @@ F83Handler::F83Handler() {
int F83Handler::execute(Command* command) {
if (LOGGING) {
Serial.print("R99 Report server version\n");
Serial.print("R99 Report server version\r\n");
}
Serial.print("R83 ");
Serial.print(SOFTWARE_VERSION);
Serial.print("\n");
Serial.print("\r\n");
return 0;
}

View File

@ -37,7 +37,7 @@ int G00Handler::execute(Command* command) {
// Serial.print(command->getB());
// Serial.print(" C ");
// Serial.print(command->getC());
// Serial.print("\n");
// Serial.print("\r\n");
StepperControl::getInstance()->moveToCoords(

View File

@ -23,7 +23,7 @@ G28Handler::G28Handler() {
int G28Handler::execute(Command* command) {
Serial.print("home\n");
Serial.print("home\r\n");
StepperControl::getInstance()->moveToCoords(0,0,0, 0,0,0, false, false, true);
StepperControl::getInstance()->moveToCoords(0,0,0, 0,0,0, true, true, false);

View File

@ -40,9 +40,9 @@ int ParameterList::readValue(int id) {
Serial.print(" ");
Serial.print("V");
Serial.print(value);
Serial.print("\n");
Serial.print("\r\n");
} else {
Serial.print("R99 Error: invalid parameter id\n");
Serial.print("R99 Error: invalid parameter id\r\n");
}
return 0;
@ -56,7 +56,7 @@ int ParameterList::writeValue(int id, int value) {
paramValues[id] = value;
writeValueEeprom(id, value);
} else {
Serial.print("R99 Error: invalid parameter id\n");
Serial.print("R99 Error: invalid parameter id\r\n");
}
// Debugging output
@ -71,7 +71,7 @@ int ParameterList::writeValue(int id, int value) {
Serial.print("V");
Serial.print(" ");
Serial.print(value);
Serial.print("\n");
Serial.print("\r\n");
// If any value is written,
// trigger the loading of the new configuration in all other modules
@ -92,7 +92,7 @@ int ParameterList::readAllValues() {
Serial.print("R99");
Serial.print(" ");
Serial.print("reading all values");
Serial.print("\n");
Serial.print("\r\n");
// Make a dump of all values
// Check if it's a valid value to keep the junk out of the list

View File

@ -53,7 +53,7 @@ int PinControl::readValue(int pinNr, int mode) {
Serial.print(" ");
Serial.print("V");
Serial.print(value);
Serial.print("\n");
Serial.print("\r\n");
return 0;
}

View File

@ -42,7 +42,7 @@ int ServoControl::setAngle(int pin, int angle) {
Serial.print(" ");
Serial.print(angle);
Serial.print(" ");
Serial.print("\n");
Serial.print("\r\n");
*/
switch(pin) {

View File

@ -34,7 +34,7 @@ int StatusList::readValue(int id) {
Serial.print(" ");
Serial.print("V");
Serial.print(value);
Serial.print("\n");
Serial.print("\r\n");
return 0;
@ -51,7 +51,7 @@ long StatusList::getValue(int id) {
Serial.print(id);
Serial.print(" value");
Serial.print(paramValues[id]);
Serial.print("\n");
Serial.print("\r\n");
*/
return statusValues[id];

View File

@ -15,7 +15,7 @@ void StepperControl::reportStatus(StepperControlAxis* axis, int axisStatus) {
Serial.print(" ");
Serial.print(axis->label);
Serial.print(axisStatus);
Serial.print("\n");
Serial.print("\r\n");
}
void StepperControl::reportCalib(StepperControlAxis* axis, int calibStatus) {
@ -23,7 +23,7 @@ void StepperControl::reportCalib(StepperControlAxis* axis, int calibStatus) {
Serial.print(" ");
Serial.print(axis->label);
Serial.print(calibStatus);
Serial.print("\n");
Serial.print("\r\n");
}
void StepperControl::checkAxisSubStatus(StepperControlAxis* axis, int* axisSubStatus) {
@ -252,14 +252,14 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
axisX.deactivateAxis();
Serial.print("R99");
Serial.print(" deactivate motor X due to missed steps");
Serial.print("\n");
Serial.print("\r\n");
if (axisX.movingToHome()) {
encoderX.setPosition(0);
axisX.setCurrentPosition(0);
Serial.print("R99");
Serial.print(" home position X axis detected with encoder");
Serial.print("\n");
Serial.print("\r\n");
}
}
@ -268,14 +268,14 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
axisY.deactivateAxis();
Serial.print("R99");
Serial.print(" deactivate motor Y due to missed steps");
Serial.print("\n");
Serial.print("\r\n");
if (axisY.movingToHome()) {
encoderY.setPosition(0);
axisY.setCurrentPosition(0);
Serial.print("R99");
Serial.print(" home position Y axis detected with encoder");
Serial.print("\n");
Serial.print("\r\n");
}
}
@ -283,14 +283,14 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
axisZ.deactivateAxis();
Serial.print("R99");
Serial.print(" deactivate motor Z due to missed steps");
Serial.print("\n");
Serial.print("\r\n");
if (axisZ.movingToHome()) {
encoderZ.setPosition(0);
axisZ.setCurrentPosition(0);
Serial.print("R99");
Serial.print(" home position Z axis detected with encoder");
Serial.print("\n");
Serial.print("\r\n");
}
}
@ -326,21 +326,21 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
// Check timeouts
if (axisActive[0] == true && ((millis() >= timeStart && millis() - timeStart > timeOut[0] * 1000) || (millis() < timeStart && millis() > timeOut[0] * 1000))) {
Serial.print("R99 timeout X axis\n");
Serial.print("R99 timeout X axis\r\n");
error = 1;
}
if (axisActive[1] == true && ((millis() >= timeStart && millis() - timeStart > timeOut[0] * 1000) || (millis() < timeStart && millis() > timeOut[0] * 1000))) {
Serial.print("R99 timeout Y axis\n");
Serial.print("R99 timeout Y axis\r\n");
error = 1;
}
if (axisActive[2] == true && ((millis() >= timeStart && millis() - timeStart > timeOut[0] * 1000) || (millis() < timeStart && millis() > timeOut[0] * 1000))) {
Serial.print("R99 timeout Z axis\n");
Serial.print("R99 timeout Z axis\r\n");
error = 1;
}
// Check if there is an emergency stop command
if (Serial.available() > 0) {
Serial.print("R99 emergency stop\n");
Serial.print("R99 emergency stop\r\n");
incomingByte = Serial.read();
if (incomingByte == 69 || incomingByte == 101) {
error = 1;
@ -348,7 +348,7 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
}
if (error == 1) {
Serial.print("R99 error\n");
Serial.print("R99 error\r\n");
axisActive[0] = false;
axisActive[1] = false;
@ -363,7 +363,7 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
//if (1 == 1)
{
Serial.print(COMM_REPORT_CMD_BUSY);
Serial.print("\n");
Serial.print("\r\n");
reportPosition();
/*
Serial.print("R99");
@ -371,7 +371,7 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
Serial.print(encoderX.currentPosition());
Serial.print(" axis pos ");
Serial.print(axisX.currentPosition());
Serial.print("\n");
Serial.print("\r\n");
Serial.print("R99");
Serial.print(" missed step ");
@ -380,7 +380,7 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
Serial.print(encoderX.currentPosition());
Serial.print(" axis pos ");
Serial.print(axisX.currentPosition());
Serial.print("\n");
Serial.print("\r\n");
*/
//Serial.print("R99");
@ -390,13 +390,13 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
//Serial.print(encoderX.currentPosition());
//Serial.print(" axis pos ");
//Serial.print(axisX.currentPosition());
//Serial.print("\n");
//Serial.print("\r\n");
}
}
Serial.print("R99 stopped\n");
Serial.print("R99 stopped\r\n");
// Stop motors
@ -523,7 +523,7 @@ int StepperControl::calibrateAxis(int axis) {
axisStatus = &axisSubStep[2];
break;
default:
Serial.print("R99 Calibration error: invalid axis selected\n");
Serial.print("R99 Calibration error: invalid axis selected\r\n");
return 1;
}
@ -531,7 +531,7 @@ int StepperControl::calibrateAxis(int axis) {
// Preliminary checks
if (calibAxis->endStopMin() || calibAxis->endStopMax()) {
Serial.print("R99 Calibration error: end stop active before start\n");
Serial.print("R99 Calibration error: end stop active before start\r\n");
return 1;
}
@ -539,7 +539,7 @@ int StepperControl::calibrateAxis(int axis) {
Serial.print(" axis ");
Serial.print(calibAxis->label);
Serial.print(" move to start for calibration");
Serial.print("\n");
Serial.print("\r\n");
*axisStatus = COMM_REPORT_MOVE_STATUS_START_MOTOR;
reportStatus(&axisX, axisSubStep[0]);
@ -570,7 +570,7 @@ int StepperControl::calibrateAxis(int axis) {
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == 69 || incomingByte == 101) {
Serial.print("R99 emergency stop\n");
Serial.print("R99 emergency stop\r\n");
movementDone = true;
error = 1;
}
@ -593,7 +593,7 @@ int StepperControl::calibrateAxis(int axis) {
{
// Periodically send message still active
Serial.print(COMM_REPORT_CMD_BUSY);
Serial.print("\n");
Serial.print("\r\n");
}
if (stepsCount % (speedMin[axis] / 6) == 0 /*|| *missedSteps > 3*/)
@ -609,7 +609,7 @@ int StepperControl::calibrateAxis(int axis) {
Serial.print(calibAxis->currentPosition());
Serial.print(" cur pos enc ");
Serial.print(calibEncoder->currentPosition());
Serial.print("\n");
Serial.print("\r\n");
}
calibAxis->resetMotorStep();
@ -617,7 +617,7 @@ int StepperControl::calibrateAxis(int axis) {
} else {
movementDone = true;
Serial.print("R99 movement done\n");
Serial.print("R99 movement done\r\n");
// If end stop for home is active, set the position to zero
if (calibAxis->endStopMax())
@ -633,7 +633,7 @@ int StepperControl::calibrateAxis(int axis) {
Serial.print(" axis ");
Serial.print(calibAxis->label);
Serial.print(" at starting point");
Serial.print("\n");
Serial.print("\r\n");
// Report back the end stop setting
@ -651,7 +651,7 @@ int StepperControl::calibrateAxis(int axis) {
Serial.print(" ");
Serial.print("V");
Serial.print(paramValueInt);
Serial.print("\n");
Serial.print("\r\n");
}
// Store the status of the system
@ -665,7 +665,7 @@ int StepperControl::calibrateAxis(int axis) {
Serial.print(" axis ");
Serial.print(calibAxis->label);
Serial.print(" calibrating length");
Serial.print("\n");
Serial.print("\r\n");
stepsCount = 0;
movementDone = false;
@ -686,7 +686,7 @@ int StepperControl::calibrateAxis(int axis) {
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == 69 || incomingByte == 101) {
Serial.print("R99 emergency stop\n");
Serial.print("R99 emergency stop\r\n");
movementDone = true;
error = 1;
}
@ -712,7 +712,7 @@ int StepperControl::calibrateAxis(int axis) {
{
// Periodically send message still active
Serial.print(COMM_REPORT_CMD_BUSY);
Serial.print("\n");
Serial.print("\r\n");
}
/*
if (stepsCount % (speedMin[axis] / 6) == 0)
@ -728,7 +728,7 @@ int StepperControl::calibrateAxis(int axis) {
Serial.print(calibAxis->currentPosition());
Serial.print(" cur pos enc ");
Serial.print(calibEncoder->currentPosition());
Serial.print("\n");
Serial.print("\r\n");
}
*/
@ -736,7 +736,7 @@ int StepperControl::calibrateAxis(int axis) {
delayMicroseconds(100000 / speedMin[axis] /2);
} else {
Serial.print("R99 movement done\n");
Serial.print("R99 movement done\r\n");
movementDone = true;
}
}
@ -746,7 +746,7 @@ int StepperControl::calibrateAxis(int axis) {
Serial.print(" axis ");
Serial.print(calibAxis->label);
Serial.print(" at end point");
Serial.print("\n");
Serial.print("\r\n");
encoderEndPoint = calibEncoder->currentPosition();
@ -766,7 +766,7 @@ int StepperControl::calibrateAxis(int axis) {
Serial.print(" ");
Serial.print("V");
Serial.print(stepsCount);
Serial.print("\n");
Serial.print("\r\n");
}
*axisStatus = COMM_REPORT_MOVE_STATUS_STOP_MOTOR;
@ -855,7 +855,7 @@ void StepperControl::checkAxisVsEncoder(StepperControlAxis* axis, StepperControl
Serial.print(*encoderStepDecay);
Serial.print(" enabled ");
Serial.print(*encoderEnabled);
Serial.print("\n");
Serial.print("\r\n");
}
*/

View File

@ -35,7 +35,7 @@ void StepperControlAxis::test() {
//Serial.print(" cons steps missed = ");
//Serial.print(label);
//Serial.print(consMissedSteps);
Serial.print("\n");
Serial.print("\r\n");
}
unsigned int StepperControlAxis::calculateSpeed(long sourcePosition, long currentPosition, long destinationPosition, long minSpeed, long maxSpeed, long stepsAccDec) {
@ -125,7 +125,7 @@ unsigned int StepperControlAxis::calculateSpeed(long sourcePosition, long curren
Serial.print(" ");
Serial.print(newSpeed);
Serial.print("\n");
Serial.print("\r\n");
}

View File

@ -21,7 +21,7 @@ void StepperControlEncoder::test() {
Serial.print(prvValChannelB);
Serial.print(" -> ");
Serial.print(curValChannelB);
Serial.print("\n");
Serial.print("\r\n");
}
void StepperControlEncoder::loadPinNumbers(int channelA, int channelB) {

View File

@ -135,7 +135,7 @@ void loop() {
if ((currentTime - lastAction) > 5000) {
// After an idle time, send the idle message
Serial.print("R00\r\n");
Serial.print("R00\r\r\n");
CurrentState::getInstance()->printPosition();
CurrentState::getInstance()->printEndStops();
lastAction = millis();