Skip to content
This repository has been archived by the owner on Oct 25, 2020. It is now read-only.

Commit

Permalink
Merge branch 'Marlin_phoenix' into Marlin_phoenix_z_probe
Browse files Browse the repository at this point in the history
* Marlin_phoenix:
  Make sure a ROM is selected for ULTRA_LCD
  Remove M48 credits also
  Fix compile error in gcode_G29
  Minor typos in the README
  Undubble MSG_MIN &MSG MAX
  Fixed in-line comments and escaping
  Attempt to resolve MarlinFirmware#1568 and add basic escape character support
  • Loading branch information
avluis committed Mar 7, 2015
2 parents de1ec73 + c501cff commit 2092ac2
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 107 deletions.
22 changes: 22 additions & 0 deletions Documentation/GCodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,25 @@
* M908 - Control digital trimpot directly.
* M928 - Start SD logging (M928 filename.g) - ended by M29
* M999 - Restart after being stopped by error

# Comments

Comments start at a `;` (semicolon) and end with the end of the line:

N3 T0*57 ; This is a comment
N4 G92 E0*67
; So is this
N5 G28*22

(example taken from the [RepRap wiki](http://reprap.org/wiki/Gcode#Comments))

If you need to use a literal `;` somewhere (for example within `M117`), you can escape semicolons with a `\`
(backslash):

M117 Hello \;)

`\` can also be used to escape `\` itself, if you need a literal `\` in front of a `;`:

M117 backslash: \\;and a comment

Please note that hosts should strip any comments before sending GCODE to the printer in order to save bandwidth.
198 changes: 101 additions & 97 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,103 +730,113 @@ void get_command()
serial_char = MYSERIAL.read();
if(serial_char == '\n' ||
serial_char == '\r' ||
(serial_char == ':' && comment_mode == false) ||
serial_count >= (MAX_CMD_SIZE - 1) )
{
if(!serial_count) { //if empty line
comment_mode = false; //for new command
// end of line == end of comment
comment_mode = false;

if(!serial_count) {
// short cut for empty lines
return;
}
cmdbuffer[bufindw][serial_count] = 0; //terminate string
if(!comment_mode){
comment_mode = false; //for new command
fromsd[bufindw] = false;
if(strchr(cmdbuffer[bufindw], 'N') != NULL)

fromsd[bufindw] = false;
if(strchr(cmdbuffer[bufindw], 'N') != NULL)
{
strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
SERIAL_ERRORLN(gcode_LastN);
//Serial.println(gcode_N);
FlushSerialRequestResend();
serial_count = 0;
return;
}

if(strchr(cmdbuffer[bufindw], '*') != NULL)
{
strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
SERIAL_ERRORLN(gcode_LastN);
//Serial.println(gcode_N);
FlushSerialRequestResend();
serial_count = 0;
return;
}
byte checksum = 0;
byte count = 0;
while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
strchr_pointer = strchr(cmdbuffer[bufindw], '*');

if(strchr(cmdbuffer[bufindw], '*') != NULL)
{
byte checksum = 0;
byte count = 0;
while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
strchr_pointer = strchr(cmdbuffer[bufindw], '*');

if( (int)(strtod(strchr_pointer + 1, NULL)) != checksum) {
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return;
}
//if no errors, continue parsing
}
else
{
if( (int)(strtod(strchr_pointer + 1, NULL)) != checksum) {
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return;
}

gcode_LastN = gcode_N;
//if no errors, continue parsing
}
else // if we don't receive 'N' but still see '*'
else
{
if((strchr(cmdbuffer[bufindw], '*') != NULL))
{
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN);
serial_count = 0;
return;
}
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return;
}
if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
switch((int)((strtod(strchr_pointer + 1, NULL)))){
case 0:
case 1:
case 2:
case 3:
if (Stopped == true) {
SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
LCD_MESSAGEPGM(MSG_STOPPED);
}
break;
default:
break;
}

gcode_LastN = gcode_N;
//if no errors, continue parsing
}
else // if we don't receive 'N' but still see '*'
{
if((strchr(cmdbuffer[bufindw], '*') != NULL))
{
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN);
serial_count = 0;
return;
}
}
if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
switch((int)((strtod(strchr_pointer + 1, NULL)))){
case 0:
case 1:
case 2:
case 3:
if (Stopped == true) {
SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
LCD_MESSAGEPGM(MSG_STOPPED);
}
break;
default:
break;
}

//If command was e-stop process now
if(strcmp(cmdbuffer[bufindw], "M112") == 0)
kill();

bufindw = (bufindw + 1)%BUFSIZE;
buflen += 1;
}

//If command was e-stop process now
if(strcmp(cmdbuffer[bufindw], "M112") == 0)
kill();

bufindw = (bufindw + 1)%BUFSIZE;
buflen += 1;

serial_count = 0; //clear buffer
}
else
{
if(serial_char == ';') comment_mode = true;
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
else if(serial_char == '\\') { //Handle escapes

if(MYSERIAL.available() > 0 && buflen < BUFSIZE) {
// if we have one more character, copy it over
serial_char = MYSERIAL.read();
cmdbuffer[bufindw][serial_count++] = serial_char;
}

//otherwise do nothing
}
else { // its not a newline, carriage return or escape char
if(serial_char == ';') comment_mode = true;
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
}
}
#ifdef SDSUPPORT
Expand Down Expand Up @@ -1772,8 +1782,6 @@ inline void gcode_G28() {

inline void gcode_G29() {

float x_tmp, y_tmp, z_tmp, real_z;

// Prevent user from running a G29 without first homing in X and Y
if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
Expand All @@ -1782,27 +1790,25 @@ inline void gcode_G28() {
return;
}

int verbose_level = 1;
float x_tmp, y_tmp, z_tmp, real_z;

if (code_seen('V') || code_seen('v')) {
verbose_level = code_value_long();
if (verbose_level < 0 || verbose_level > 4) {
SERIAL_PROTOCOLPGM("?(V)erbose Level is implausible (0-4).\n");
return;
}
}

bool enhanced_g29 = code_seen('E') || code_seen('e');

#ifdef AUTO_BED_LEVELING_GRID

// Example Syntax: G29 N4 V2 E T
int verbose_level = 1;
bool topo_flag = verbose_level > 2 || code_seen('T') || code_seen('t');

bool topo_flag = code_seen('T') || code_seen('t');

if (code_seen('V') || code_seen('v')) {
verbose_level = code_value();
if (verbose_level < 0 || verbose_level > 4) {
SERIAL_PROTOCOLPGM("?(V)erbose Level is implausible (0-4).\n");
return;
}
if (verbose_level > 0) {
SERIAL_PROTOCOLPGM("G29 Enhanced Auto Bed Leveling Code V1.25:\n");
SERIAL_PROTOCOLPGM("Full support at: http://3dprintboard.com/forum.php\n");
if (verbose_level > 2) topo_flag = true;
}
}
if (verbose_level > 0)
SERIAL_PROTOCOLPGM("G29 Auto Bed Leveling\n");

int auto_bed_leveling_grid_points = code_seen('P') ? code_value_long() : AUTO_BED_LEVELING_GRID_POINTS;
if (auto_bed_leveling_grid_points < 2 || auto_bed_leveling_grid_points > AUTO_BED_LEVELING_GRID_POINTS) {
Expand Down Expand Up @@ -2418,10 +2424,8 @@ inline void gcode_M42() {
}
}

if (verbose_level > 0) {
SERIAL_PROTOCOLPGM("M48 Z-Probe Repeatability test. Version 2.00\n");
SERIAL_PROTOCOLPGM("Full support at: http://3dprintboard.com/forum.php\n");
}
if (verbose_level > 0)
SERIAL_PROTOCOLPGM("M48 Z-Probe Repeatability test\n");

if (code_seen('n')) {
n_samples = code_value();
Expand All @@ -2435,7 +2439,7 @@ inline void gcode_M42() {
Y_current = Y_probe_location = st_get_position_mm(Y_AXIS);
Z_current = st_get_position_mm(Z_AXIS);
Z_start_location = st_get_position_mm(Z_AXIS) + Z_RAISE_BEFORE_PROBING;
ext_position = st_get_position_mm(E_AXIS);
ext_position = st_get_position_mm(E_AXIS);

if (code_seen('E') || code_seen('e'))
engage_probe_for_each_reading++;
Expand Down
9 changes: 5 additions & 4 deletions Marlin/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@
#define MSG_PID_TIMEOUT MSG_PID_AUTOTUNE_FAILED " timeout"
#define MSG_BIAS " bias: "
#define MSG_D " d: "
#define MSG_MIN " min: "
#define MSG_MAX " max: "
#define MSG_T_MIN " min: "
#define MSG_T_MAX " max: "
#define MSG_KU " Ku: "
#define MSG_TU " Tu: "
#define MSG_CLASSIC_PID " Classic PID "
Expand Down Expand Up @@ -226,8 +226,7 @@
#define STR_h3 "3"
#define STR_Deg "\271"
#define STR_THERMOMETER "\002"
#endif
#ifdef DISPLAY_CHARSET_HD44780_WESTERN // HD44780 ROM Code: A02 (Western)
#elif defined(DISPLAY_CHARSET_HD44780_WESTERN) // HD44780 ROM Code: A02 (Western)
#define STR_Ae "\216"
#define STR_ae "\204"
#define STR_Oe "\211"
Expand All @@ -239,6 +238,8 @@
#define STR_h3 "\263"
#define STR_Deg "\337"
#define STR_THERMOMETER "\002"
#elif defined(ULTRA_LCD)
#error You must enable either DISPLAY_CHARSET_HD44780_JAPAN or DISPLAY_CHARSET_HD44780_WESTERN for your LCD controller.
#endif
#endif
/*
Expand Down
4 changes: 2 additions & 2 deletions Marlin/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ void PID_autotune(float temp, int extruder, int ncycles)

SERIAL_PROTOCOLPGM(MSG_BIAS); SERIAL_PROTOCOL(bias);
SERIAL_PROTOCOLPGM(MSG_D); SERIAL_PROTOCOL(d);
SERIAL_PROTOCOLPGM(MSG_MIN); SERIAL_PROTOCOL(min);
SERIAL_PROTOCOLPGM(MSG_MAX); SERIAL_PROTOCOLLN(max);
SERIAL_PROTOCOLPGM(MSG_T_MIN); SERIAL_PROTOCOL(min);
SERIAL_PROTOCOLPGM(MSG_T_MAX); SERIAL_PROTOCOLLN(max);
if (cycles > 2) {
Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0);
Tu = ((float)(t_low + t_high) / 1000.0);
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The current Marlin dev team consists of:

- Erik van der Zalm ([@ErikZalm](https://github.com/ErikZalm))
- [@daid](https://github.com/daid)

Sprinters lead developers are Kliment and caru.
Grbls lead developer is Simen Svale Skogsrud.
Sonney Jeon (Chamnit) improved some parts of grbl
Expand All @@ -57,9 +57,9 @@ More features have been added by:
- Bradley Feldman,
- and others...

## Licence
## License

Marlin is published unde the [GPL license](/Documentation/COPYING.md) because I believe in open development.
Marlin is published under the [GPL license](/Documentation/COPYING.md) because I believe in open development.
Please do not use this code in products (3D printers, CNC etc) that are closed source or are crippled by a patent.

[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=ErikZalm&url=https://github.com/MarlinFirmware/Marlin&title=Marlin&language=&tags=github&category=software)
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=ErikZalm&url=https://github.com/MarlinFirmware/Marlin&title=Marlin&language=&tags=github&category=software)

0 comments on commit 2092ac2

Please sign in to comment.