Commit Graph

70 Commits

Author SHA1 Message Date
Yuri D'Elia
d37a2a173a Parenthesize IS_SD_PRINTING defensively 2022-12-19 10:47:10 +01:00
Yuri D'Elia
de20fc6a5a Replace two expressions with cmd_head 2022-12-19 10:46:58 +01:00
Yuri D'Elia
5ab0dcb4c5 Allow M310 to bypass the Stopped state for recovery
Since M310 cannot change the heaters, allowing M310 S0 (and changing
parameters) allows to recover a usb-controlled printer which has been
locked-out due to bad model settings.
2022-12-19 10:46:45 +01:00
Yuri D'Elia
42125b4bb2 Keep a pointer past the line number in cmdqueue
This allows to skip line numbers transparently and perform faster
checks on the actual command to process.
2022-12-19 10:46:33 +01:00
Yuri D'Elia
140961290d Do not reset line on serial commands without N
Fix regression introduced in fc10ca3146.

Accept incoming serial commands without line numbers (assumed to be
injected by the host), but do not reset the last line count when doing
so.
2022-09-21 15:05:21 +02:00
Guðni Már Gilbert
9bff10add5 Don't inline the function
Change in memory:
Flash: -44 bytes
SRAM: 0 bytes
2022-09-21 15:04:40 +02:00
Guðni Már Gilbert
b1bee597aa Remove atomic_update parameter
Change in memory:
Flash: +24 bytes
SRAM: -0 byte
2022-09-21 15:04:40 +02:00
Guðni Már Gilbert
b2530eeb13 Optimisation: Remove duplicated code in cmdqueue_could_enqueue_back()
Code is 28 lines shorter :)

Change in memory:
Flash: -42 bytes
SRAM: 0 bytes
2022-09-21 15:04:40 +02:00
Alex Voinea
bef7b086e3 Isolate the entire farm and statistics code 2022-08-30 13:57:43 +02:00
Alex Voinea
7d597eb8b0 Move farm mode to separate file 2022-08-30 13:57:43 +02:00
Alex Voinea
4ded6f195e Move string to progmem
flash: -52
RAM: -6
2022-08-26 18:59:53 +03:00
DRracer
0933fdb6fe
Merge pull request #3552 from wavexx/temp_model_check
Thermal Model protection
2022-08-24 19:16:48 +02:00
Yuri D'Elia
c0b5fea525 Prevent re-entry in EOF command processing
cmdqueue will run commands when EOF is reached without returning to the
main loop, which is already incorrect.

However, since it needs to ensure the queue is empty, an st_synchronize
call can result in a re-entrant call to get_command, which will
reprocess EOF again. Even if we removed st_synchronize, another command
could be picked by an unsuspecting manage_inactivity() somewhere else.

Short-circuit EOF processing by closing the file early and checking for
the file state early in get_command.

This should fix #3549
2022-07-29 15:55:54 +02:00
Yuri D'Elia
fc10ca3146 Change how "Stopped" is handled internally, do not inhibit motion
Do not inhibit motion when Stopped is set.

We actually do need to move to move away the extruder from the bed, and
setting Stopped breaks it without adding any sort of security (M*
commands, such as M600 could still perform moves and still pass
through, while M104 would still set heaters).

During a hard error the internal queue is cleared (and sd file closed,
if any), so no new "unforeseen" command can be read.

Handle "Stopped" instead as a flag to inhibit serial processing and
automatically switch to "paused for user" state. While in this state
simply drop any input without incrementing the processed gcode line
number, behaving as-if the last command was still being processed.

This allows "Stopped" to correctly handle a printer-initiated paused
state and recover as expected by requesting a resend when resuming.
2022-07-25 17:30:22 +02:00
Yuri D'Elia
e37435b53f Merge remote-tracking branch 'upstream/MK3_3.11.1' into mk311_sync 2022-07-04 16:14:23 +02:00
Alex Voinea
91c71da810 Convert some more suspicious timers to LongTimer 2022-02-17 08:48:29 +01:00
Alex Voinea
4ec8781df2 Fix usb print timer 2022-02-13 22:52:49 +01:00
Alex Voinea
ed8252527c Add a uart RX timeout 2022-02-11 12:49:11 +01:00
Alex Voinea
6ce7792045 Remove "hh" in fmt where it makes no difference 2022-02-02 20:58:21 +01:00
Guðni Már Gilbert
9bf45773f9 Merge remote-tracking branch 'upstream/MK3' into rebase-testing-ground-v2 2022-01-30 11:43:16 +00:00
Guðni Már Gilbert
d8723c0eac Use code_value_uint8() in get_command()
The if statement is simplified as the value is never negative
and we can get rid of one variable

Saves 12 bytes of flash memory
2022-01-30 11:39:27 +00:00
Guðni Már Gilbert
ac049c7e3c Use code_value_short() in get_command()
Same code but uses a defined function

Saves 28 bytes of flash memory
2022-01-30 11:39:27 +00:00
Voinea Dragos
a5f1f23fe2 TimeNow && TimeSent 2022-01-30 11:22:43 +00:00
Guðni Már Gilbert
3cfd706fff Remove useless extern in cmdqueue.cpp 2021-07-20 09:12:14 +02:00
Guðni Már Gilbert
16602f4003 change boolean to bool 2021-07-20 08:03:17 +02:00
Yuri D'Elia
23c75da727 Fix Crash/PP recovery position on instructions with comments
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.
2021-04-19 06:30:37 +02:00
Yuri D'Elia
461d3f6749 Remove duplicate function is_buffer_empty()
Use cmd_buffer_empty() instead
2021-02-19 17:06:00 +01:00
D.R.racer
c1ead75a73 Remove commented debug code
the whole PR is ready for review after successfull tests
2021-02-10 11:18:59 +01:00
D.R.racer
caf58b16b6 Fix handling EOF
+ save ~160B by using local variables
+ rename some of the vars to more descriptive names
+ remove consecutiveEmptyLines handling from cmdqueue
2021-01-29 08:29:51 +01:00
D.R.racer
c3758d350e Fast skipping of large comment blocks
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
2021-01-27 07:03:51 +01:00
D.R.racer
dcc6605809 Workaround for skipping large comment blocks
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.
2021-01-27 07:03:51 +01:00
Alex Voinea
0c305ee5f5 Fix warning 2020-11-09 21:49:56 +02:00
Alex Voinea
4abf1f436a Gracefully dump the queue + fixes to fancheck 2020-11-09 21:49:56 +02:00
Alex Voinea
fdbbc7d62a Terminate last line from the SD card even if it doesn't have a \n 2020-11-09 21:49:56 +02:00
Alex Voinea
e7f2577233
Fix kill messages 2019-11-29 22:49:22 +02:00
Yuri D'Elia
404802b5e6 Clear "sdprinting" state only when all SD moves are complete
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.
2019-11-28 15:57:20 +01:00
Marek Bel
3eb36ca194 Fix cmdqueue_dump_to_serial.
Header was historically made bigger to contain size of the command on SD card, but those debug functions wasn't updated.
2019-08-23 16:48:30 +02:00
Marek Bel
cbb92860d0 Use first letter capital camel case for enum class members. 2019-06-12 18:54:32 +02:00
DRracer
c7e1e73880 another almost 200B down by proper usage of smaller data types and enum
classes
2019-06-12 15:41:55 +02:00
Ondrej Tuma
b7fe43bf68 Deleted bad cols/rows definitions for translation. 2019-05-07 12:52:23 +02:00
PavelSindler
6ad5c07e6d comments 2019-02-21 14:28:05 +01:00
PavelSindler
1e729048dc cmdqueue_reset fix 2019-02-21 00:14:49 +01:00
Robert Pelnar
eea755496b Conditional translation for SYSTEM_TIMER_2 because we want to have posibility to switch between old/new implementation.
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.
2019-01-27 22:48:51 +01:00
PavelSindler
c1773c1aa4
Merge pull request #1356 from PavelSindler/MK3_for_merging
process serial line during pause
2018-11-22 23:07:07 +01:00
PavelSindler
85b23d1db6 process serial line during pause 2018-11-22 21:41:22 +01:00
Robert Pelnar
7426efac9b Lang - text "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)" removed from dictionary 2018-11-22 18:36:38 +01:00
Robert Pelnar
1568b94e87 Lang - text "No Checksum with line number, Last Line: " removed from dictionary 2018-11-22 18:09:07 +01:00
Robert Pelnar
fdf9734161 Lang - text "checksum mismatch, Last Line: " removed from dictionary 2018-11-22 17:59:43 +01:00
Robert Pelnar
46fba48173 Lang - text "enqueing \"" removed from dictionary 2018-11-22 17:38:52 +01:00
Marek Bel
716e6c209c Save 88B FLASH and fix compiler warnings:
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) ;
                                                      ^
2018-07-25 21:18:29 +02:00