PR #2967 altered the way ``sdpos_atomic`` was set, causing issues in the
crashdetect/powerpanic recovery offset if the instruction being
recovered happens to contain a comment.
Previously ``sdpos`` was assumed to be a single byte prior to the last
read character. sdpos+1 would thus position the index to the next
instruction. With gcode-filtering in place, sdpos is left just before
the comment, while the actual read position is at the newline. This
causes to parser to resume in the middle of the comment.
Change the value returned by cardreader::get_sdpos() to always return
the last read position, as everybody expects (!!).
This avoids the +1, and correctly sets the resume position to the next
valid instruction without overhead.
This is an extension/optimization of PR #2956.
It uses the cached 512B block buffer to avoid heavy-weight read() in SdBaseFile.
Even though this principle allowed the AVR to skip ~600KB of data within ~5 seconds,
the impact on code base is huge, especially into well proven and long-term stable
parts like reading a file from the SD card.
The sole purpose of this PR is to show/verify the possibility of the AVR CPU
in relation to adding thumbnails into MK3 G-codes.
Moreover, this PR shall not be merged unless the missing/commented features
are restored - especially file seeking and M84 search.
PFW-1175
If there are large blocks of comments in the G-code,
the printer may get shot down by its own watchdog.
Watchdog is generally set to 4s and updated only
in manage_heaters (and some other spots in some specific cases).
So far, the code reading the file and feeding it into Marlin
cycles indefinitely until it finds valid G-code lines and fills up the
command queue.
If the block is large enough, the printer cannot read it completely
within those 4s.
A simple workaround - bail out after some consecutive empty/comment
lines to enable other parts of code do their job (especially
manage_heaters).
Tested on MK404, previous FW fails with 600KB of comment lines at the
beginning, this patch survives. The printer even draws some update
on its status screen before starting a real print.
Ensure card.printingHasFinished sees all the planned moves before
clearing sdprinting. To do that, we need to ensure all SD commands
exited the command queue.
Timing functions (millis, micros and delay) replaced in whole source, defined in Marlin.h.
This commit enables original implementation (SYSTEM_TIMER_2 undefined)
Verified with passed complete wizard process.
sketch/cmdqueue.cpp: In function 'bool cmdqueue_pop_front()':
sketch/cmdqueue.cpp:67:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (++ bufindr; bufindr < sizeof(cmdbuffer) && cmdbuffer[bufindr] == 0; ++ bufindr) ;
^
sketch/cmdqueue.cpp: In function 'bool cmdqueue_could_enqueue_back(int, bool)':
sketch/cmdqueue.cpp:170:63: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
endw + CMDBUFFER_RESERVE_FRONT <= sizeof(cmdbuffer) ||
^
sketch/cmdqueue.cpp:172:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
(endw <= sizeof(cmdbuffer) && CMDBUFFER_RESERVE_FRONT <= bufindr))
^
sketch/cmdqueue.cpp:196:63: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
endw + CMDBUFFER_RESERVE_FRONT <= sizeof(cmdbuffer) ||
^
sketch/cmdqueue.cpp:198:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
(endw <= sizeof(cmdbuffer) && CMDBUFFER_RESERVE_FRONT <= bufindr))
^
sketch/cmdqueue.cpp: In function 'void get_command()':
sketch/cmdqueue.cpp:380:10: warning: variable 'rx_buffer_full' set but not used [-Wunused-but-set-variable]
bool rx_buffer_full = false; //flag that serial rx buffer is full
^
sketch/cmdqueue.cpp: In function 'uint16_t cmdqueue_calc_sd_length()':
sketch/cmdqueue.cpp:697:54: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (++ _bufindr; _bufindr < sizeof(cmdbuffer) && cmdbuffer[_bufindr] == 0; ++ _bufindr) ;
^