Understanding Marlin March 29, 2016 01:56AM |
Registered: 8 years ago Posts: 2 |
void get_command(){ /* . . omitted lines 416-521 . . #ifdef SDSUPPORT if(!card.sdprinting || serial_count != 0){ return; } while( !card.eof() && buflen < BUFSIZE) { int16_t n=card.get(); serial_char = (char)n; if(serial_char == '\n' || serial_char == '\r' || (serial_char == ':' && comment_mode == false) || serial_count >= (MAX_CMD_SIZE - 1)||n==-1) { if(card.eof()){ SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED); stoptime=millis(); char time[30]; unsigned long t=(stoptime-starttime)/1000; int hours, minutes; minutes=(t/60)%60; hours=t/60/60; sprintf_P(time, PSTR("%i hours %i minutes"),hours, minutes); SERIAL_ECHO_START; SERIAL_ECHOLN(time); lcd_setstatus(time); card.printingHasFinished(); card.checkautostart(true); } if(!serial_count) { comment_mode = false; //for new command return; //if empty line } cmdbuffer[bufindw][serial_count] = 0; //terminate string // if(!comment_mode){ fromsd[bufindw] = true; buflen += 1; bufindw = (bufindw + 1)%BUFSIZE; // } comment_mode = false; //for new command serial_count = 0; //clear buffer } else { if(serial_char == ';') comment_mode = true; if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char; } } #endif //SDSUPPORT
if(!card.sdprinting || serial_count != 0){ return; }if serial_count is not zero, the code kicks us out of "void get_command()" and back into "void loop()", so we know if we got past this point that serial_count is equal to 0.
while( !card.eof() && buflen < BUFSIZE) {then another if statement, line 529:
if(serial_char == '\n' || serial_char == '\r' || (serial_char == ':' && comment_mode == false) || serial_count >= (MAX_CMD_SIZE - 1)||n==-1) {if we don't pass this conditionals for this if statement we are sent down to lines 566-567
if(serial_char == ';') comment_mode = true; if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;where serial_count gets advanced by 1 (serial_count++) and then used in the cmdbuffer array.
if(!serial_count) { comment_mode = false; //for new command return; //if empty line }so if serial_count equals 0, it will pass this conditional and hit the "return;" that will kick us back out to "void loop()"
Re: Understanding Marlin April 16, 2016 02:17PM |
Registered: 12 years ago Posts: 1,236 |
Quote
Jrodenba
where serial_count gets advanced by 1 (serial_count++) and then used in the cmdbuffer array.
then "void get_command()" ends and we are returned to "void loop()", but serial_count is now greater than 0, so the next time "void get_command()" is called it will automatically trigger the "return" on line 524
Re: Understanding Marlin April 17, 2016 09:11PM |
Registered: 8 years ago Posts: 2 |