From b2cc27e5ea89510f0ff845827677652141f55a02 Mon Sep 17 00:00:00 2001 From: bkubicek Date: Tue, 22 Oct 2013 09:54:13 +0200 Subject: [PATCH] Added a magic character for sd buffering. if a '#' is read now the buffer will be emptied before reading ahead. This is so one can execute files from within gcode files, without messing the buffer with preread characters from the caller file. # can not occure in sd files imho, because it should only occure within checksums in ther serial communication. Yes, thats a lame argument. If you have a better idea please tell me. It has to be a character that one can type on a keyboard manually. --- Marlin/Marlin_main.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 932af1355..c53a5b583 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -620,11 +620,20 @@ void get_command() if(!card.sdprinting || serial_count!=0){ return; } - while( !card.eof() && buflen < BUFSIZE) { + + //'#' stops reading from sd to the buffer prematurely, so procedural macro calls are possible + // if it occures, stop_buffering is triggered and the buffer is ran dry. + // this character _can_ occure in serial com, due to checksums. however, no checksums are used in sd printing + + static bool stop_buffering=false; + if(buflen==0) stop_buffering=false; + + while( !card.eof() && buflen < BUFSIZE && !stop_buffering) { int16_t n=card.get(); - serial_char = (char)n; + serial_char = (char)n; if(serial_char == '\n' || serial_char == '\r' || + serial_char == '#' || (serial_char == ':' && comment_mode == false) || serial_count >= (MAX_CMD_SIZE - 1)||n==-1) { @@ -644,6 +653,9 @@ void get_command() card.checkautostart(true); } + if(serial_char=='#') + stop_buffering=true; + if(!serial_count) { comment_mode = false; //for new command