Skip to content

Commit

Permalink
Merge pull request #425 from blurfl/Add-G4-gcode
Browse files Browse the repository at this point in the history
Add G4 gcode, use maslowDelay() to remain responsive to GC during dwell time
  • Loading branch information
BarbourSmith authored Apr 9, 2018
2 parents 1871fba + d49eb6d commit d634adc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cnc_ctrl_v1/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ void executeGcodeLine(const String& gcodeLine){
G2(gcodeLine, gNumber);
sys.lastGCommand = gNumber; // remember G number for next time
break;
case 4:
G4(gcodeLine);
break;
case 10:
G10(gcodeLine);
break;
Expand Down Expand Up @@ -698,6 +701,35 @@ void G2(const String& readString, int G2orG3){
}
}

void G4(const String& readString){
/*
The G4() dwell function handles the G4 gcode which pauses for P milliseconds or S seconds.
Only one of the two is accepted, the other ignored.
Use maslowDelay() to remain responsive to GC during the dwell time.
Because maslowDelay() operates in milliseconds, round to the nearest millisecond.
Negative values are treated as positive (not a time machine).
*/
float dwellMS = abs(extractGcodeValue(readString, 'P', 0));
float dwellS = abs(extractGcodeValue(readString, 'S', 0));

if (dwellMS == 0) {
/*
ignore S parameter unless P is zero
*/
dwellMS = dwellS * 1000;
}
dwellMS = long(dwellMS + .5);
Serial.print(F("dwell time "));
if (dwellS > 0) {
Serial.print(dwellS);
Serial.println(F(" seconds"));
} else {
Serial.print(dwellMS, 0);
Serial.println(F(" ms."));
}
maslowDelay(dwellMS);
}

void G10(const String& readString){
/*The G10() function handles the G10 gcode which re-zeros one or all of the machine's axes.*/
float currentZPos = zAxis.read();
Expand Down
1 change: 1 addition & 0 deletions cnc_ctrl_v1/GCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void sanitizeCommandString(String&);
byte interpretCommandString(String&);
void G1(const String&, int);
void G2(const String&, int);
void G4(const String&);
void G10(const String&);
void G38(const String&);
void setInchesToMillimetersConversion(float);
Expand Down

0 comments on commit d634adc

Please sign in to comment.