Merge pull request #2870 from leptun/MK3_random_patches

cmdqueue: Patches to Serial communication, pausing and file completion check
This commit is contained in:
DRracer 2020-11-30 09:01:38 +01:00 committed by GitHub
commit d167b3bd78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 47 additions and 43 deletions

View File

@ -116,7 +116,6 @@ void serial_echopair_P(const char *s_P, unsigned long v);
void serialprintPGM(const char *str); void serialprintPGM(const char *str);
bool is_buffer_empty(); bool is_buffer_empty();
void get_command();
void process_commands(); void process_commands();
void ramming(); void ramming();
@ -241,23 +240,12 @@ void Stop();
bool IsStopped(); bool IsStopped();
void finishAndDisableSteppers(); void finishAndDisableSteppers();
//put an ASCII command at the end of the current buffer.
void enquecommand(const char *cmd, bool from_progmem = false);
//put an ASCII command at the end of the current buffer, read from flash //put an ASCII command at the end of the current buffer, read from flash
#define enquecommand_P(cmd) enquecommand(cmd, true) #define enquecommand_P(cmd) enquecommand(cmd, true)
//put an ASCII command at the begin of the current buffer
void enquecommand_front(const char *cmd, bool from_progmem = false);
//put an ASCII command at the begin of the current buffer, read from flash //put an ASCII command at the begin of the current buffer, read from flash
#define enquecommand_front_P(cmd) enquecommand_front(cmd, true) #define enquecommand_front_P(cmd) enquecommand_front(cmd, true)
void repeatcommand_front();
// Remove all lines from the command queue.
void cmdqueue_reset();
void prepare_arc_move(char isclockwise); void prepare_arc_move(char isclockwise);
void clamp_to_software_endstops(float target[3]); void clamp_to_software_endstops(float target[3]);
void refresh_cmd_timeout(void); void refresh_cmd_timeout(void);

View File

@ -631,7 +631,7 @@ void crashdet_cancel()
lcd_print_stop(); lcd_print_stop();
}else if(saved_printing_type == PRINTING_TYPE_USB){ }else if(saved_printing_type == PRINTING_TYPE_USB){
SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); //for Octoprint: works the same as clicking "Abort" button in Octoprint GUI SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); //for Octoprint: works the same as clicking "Abort" button in Octoprint GUI
SERIAL_PROTOCOLLNRPGM(MSG_OK); cmdqueue_reset();
} }
} }
@ -2631,7 +2631,6 @@ void gcode_M105(uint8_t extruder)
} }
#endif #endif
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
KEEPALIVE_STATE(NOT_BUSY);
} }
#ifdef TMC2130 #ifdef TMC2130
@ -3679,14 +3678,12 @@ There are reasons why some G Codes aren't in numerical order.
void process_commands() void process_commands()
{ {
#ifdef FANCHECK #ifdef FANCHECK
if(fan_check_error){ if(fan_check_error == EFCE_DETECTED){
if(fan_check_error == EFCE_DETECTED){ fan_check_error = EFCE_REPORTED;
fan_check_error = EFCE_REPORTED; // SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED);
// SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); lcd_pause_print();
lcd_pause_print(); cmdqueue_serial_disabled = true;
} // otherwise it has already been reported, so just ignore further processing }
return; //ignore usb stream. It is reenabled by selecting resume from the lcd.
}
#endif #endif
if (!buflen) return; //empty command if (!buflen) return; //empty command
@ -6402,7 +6399,8 @@ Sigma_Exit:
SERIAL_PROTOCOLPGM("ok "); SERIAL_PROTOCOLPGM("ok ");
gcode_M105(extruder); gcode_M105(extruder);
return; cmdqueue_pop_front(); //prevent an ok after the command since this command uses an ok at the beginning.
break; break;
} }
@ -6864,12 +6862,10 @@ Sigma_Exit:
SERIAL_ECHOPGM(STRINGIFY(EXTRUDERS)); SERIAL_ECHOPGM(STRINGIFY(EXTRUDERS));
SERIAL_ECHOPGM(" UUID:"); SERIAL_ECHOPGM(" UUID:");
SERIAL_ECHOLNPGM(MACHINE_UUID); SERIAL_ECHOLNPGM(MACHINE_UUID);
}
#ifdef EXTENDED_CAPABILITIES_REPORT #ifdef EXTENDED_CAPABILITIES_REPORT
extended_capabilities_report(); extended_capabilities_report();
#endif //EXTENDED_CAPABILITIES_REPORT #endif //EXTENDED_CAPABILITIES_REPORT
}
break; break;
/*! /*!
@ -7995,6 +7991,7 @@ Sigma_Exit:
if (!isPrintPaused) if (!isPrintPaused)
{ {
st_synchronize(); st_synchronize();
ClearToSend(); //send OK even before the command finishes executing because we want to make sure it is not skipped because of cmdqueue_pop_front();
cmdqueue_pop_front(); //trick because we want skip this command (M601) after restore cmdqueue_pop_front(); //trick because we want skip this command (M601) after restore
lcd_pause_print(); lcd_pause_print();
} }
@ -9209,8 +9206,8 @@ void FlushSerialRequestResend()
// Execution of a command from a SD card will not be confirmed. // Execution of a command from a SD card will not be confirmed.
void ClearToSend() void ClearToSend()
{ {
previous_millis_cmd = _millis(); previous_millis_cmd = _millis();
if ((CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB) || (CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR)) if (buflen && ((CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB) || (CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR)))
SERIAL_PROTOCOLLNRPGM(MSG_OK); SERIAL_PROTOCOLLNRPGM(MSG_OK);
} }
@ -11461,7 +11458,6 @@ void restore_print_from_ram_and_continue(float e_move)
//not sd printing nor usb printing //not sd printing nor usb printing
} }
SERIAL_PROTOCOLLNRPGM(MSG_OK); //dummy response because of octoprint is waiting for this
lcd_setstatuspgm(_T(WELCOME_MSG)); lcd_setstatuspgm(_T(WELCOME_MSG));
saved_printing_type = PRINTING_TYPE_NONE; saved_printing_type = PRINTING_TYPE_NONE;
saved_printing = false; saved_printing = false;

View File

@ -1,4 +1,5 @@
#include "Marlin.h" #include "Marlin.h"
#include "cmdqueue.h"
#include "cardreader.h" #include "cardreader.h"
#include "ultralcd.h" #include "ultralcd.h"
#include "stepper.h" #include "stepper.h"
@ -498,7 +499,7 @@ void CardReader::getStatus()
SERIAL_PROTOCOLLNPGM("Print saved"); SERIAL_PROTOCOLLNPGM("Print saved");
} }
else { else {
SERIAL_PROTOCOLLN(longFilename); SERIAL_PROTOCOLLN(LONGEST_FILENAME);
SERIAL_PROTOCOLRPGM(_N("SD printing byte "));////MSG_SD_PRINTING_BYTE SERIAL_PROTOCOLRPGM(_N("SD printing byte "));////MSG_SD_PRINTING_BYTE
SERIAL_PROTOCOL(sdpos); SERIAL_PROTOCOL(sdpos);
SERIAL_PROTOCOL('/'); SERIAL_PROTOCOL('/');

View File

@ -18,6 +18,10 @@ int buflen = 0;
// Therefore don't remove the command from the queue in the loop() function. // Therefore don't remove the command from the queue in the loop() function.
bool cmdbuffer_front_already_processed = false; bool cmdbuffer_front_already_processed = false;
// Used for temporarely preventing accidental adding of Serial commands to the queue.
// For now only check_file and the fancheck pause use this.
bool cmdqueue_serial_disabled = false;
int serial_count = 0; //index of character read from serial line int serial_count = 0; //index of character read from serial line
boolean comment_mode = false; boolean comment_mode = false;
char *strchr_pointer; // just a pointer to find chars in the command string like X, Y, Z, E, etc char *strchr_pointer; // just a pointer to find chars in the command string like X, Y, Z, E, etc
@ -91,14 +95,19 @@ bool cmdqueue_pop_front()
void cmdqueue_reset() void cmdqueue_reset()
{ {
bufindr = 0; while (buflen)
bufindw = 0; {
buflen = 0; // printf_P(PSTR("dumping: \"%s\" of type %hu\n"), cmdbuffer+bufindr+CMDHDRSIZE, CMDBUFFER_CURRENT_TYPE);
ClearToSend();
cmdqueue_pop_front();
}
bufindr = 0;
bufindw = 0;
//commands are removed from command queue after process_command() function is finished //commands are removed from command queue after process_command() function is finished
//reseting command queue and enqueing new commands during some (usually long running) command processing would cause that new commands are immediately removed from queue (or damaged) //reseting command queue and enqueing new commands during some (usually long running) command processing would cause that new commands are immediately removed from queue (or damaged)
//this will ensure that all new commands which are enqueued after cmdqueue reset, will be always executed //this will ensure that all new commands which are enqueued after cmdqueue reset, will be always executed
cmdbuffer_front_already_processed = true; cmdbuffer_front_already_processed = true;
} }
// How long a string could be pushed to the front of the command queue? // How long a string could be pushed to the front of the command queue?
@ -390,7 +399,7 @@ void get_command()
} }
// start of serial line processing loop // start of serial line processing loop
while ((MYSERIAL.available() > 0 && !saved_printing) || (MYSERIAL.available() > 0 && isPrintPaused)) { //is print is saved (crash detection or filament detection), dont process data from serial line while (((MYSERIAL.available() > 0 && !saved_printing) || (MYSERIAL.available() > 0 && isPrintPaused)) && !cmdqueue_serial_disabled) { //is print is saved (crash detection or filament detection), dont process data from serial line
char serial_char = MYSERIAL.read(); char serial_char = MYSERIAL.read();
/* if (selectedSerialPort == 1) /* if (selectedSerialPort == 1)
@ -582,8 +591,6 @@ void get_command()
((serial_char == '#' || serial_char == ':') && comment_mode == false) || ((serial_char == '#' || serial_char == ':') && comment_mode == false) ||
serial_count >= (MAX_CMD_SIZE - 1) || n==-1) serial_count >= (MAX_CMD_SIZE - 1) || n==-1)
{ {
if(card.eof()) break;
if(serial_char=='#') if(serial_char=='#')
stop_buffering=true; stop_buffering=true;
@ -631,6 +638,9 @@ void get_command()
comment_mode = false; //for new command comment_mode = false; //for new command
serial_count = 0; //clear buffer serial_count = 0; //clear buffer
if(card.eof()) break;
// The following line will reserve buffer space if available. // The following line will reserve buffer space if available.
if (! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1, true)) if (! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1, true))
return; return;

View File

@ -35,6 +35,7 @@ extern char cmdbuffer[BUFSIZE * (MAX_CMD_SIZE + 1) + CMDBUFFER_RESERVE_FRONT];
extern size_t bufindr; extern size_t bufindr;
extern int buflen; extern int buflen;
extern bool cmdbuffer_front_already_processed; extern bool cmdbuffer_front_already_processed;
extern bool cmdqueue_serial_disabled;
// Type of a command, which is to be executed right now. // Type of a command, which is to be executed right now.
#define CMDBUFFER_CURRENT_TYPE (cmdbuffer[bufindr]) #define CMDBUFFER_CURRENT_TYPE (cmdbuffer[bufindr])
@ -65,8 +66,8 @@ extern void cmdqueue_dump_to_serial_single_line(int nr, const char *p);
extern void cmdqueue_dump_to_serial(); extern void cmdqueue_dump_to_serial();
#endif /* CMDBUFFER_DEBUG */ #endif /* CMDBUFFER_DEBUG */
extern bool cmd_buffer_empty(); extern bool cmd_buffer_empty();
extern void enquecommand(const char *cmd, bool from_progmem); extern void enquecommand(const char *cmd, bool from_progmem = false);
extern void enquecommand_front(const char *cmd, bool from_progmem); extern void enquecommand_front(const char *cmd, bool from_progmem = false);
extern void repeatcommand_front(); extern void repeatcommand_front();
extern bool is_buffer_empty(); extern bool is_buffer_empty();
extern void get_command(); extern void get_command();

View File

@ -7,6 +7,7 @@
#include "Configuration_prusa.h" #include "Configuration_prusa.h"
#include "language.h" #include "language.h"
#include "Marlin.h" #include "Marlin.h"
#include "cmdqueue.h"
#include "mmu.h" #include "mmu.h"
#include <avr/pgmspace.h> #include <avr/pgmspace.h>

View File

@ -8,6 +8,7 @@
#include "lcd.h" #include "lcd.h"
#include "Configuration.h" #include "Configuration.h"
#include "Marlin.h" #include "Marlin.h"
#include "cmdqueue.h"
#include "ultralcd.h" #include "ultralcd.h"
#include "language.h" #include "language.h"
#include "static_assert.h" #include "static_assert.h"

View File

@ -9,6 +9,7 @@
#include "Configuration_prusa.h" #include "Configuration_prusa.h"
#include "fsensor.h" #include "fsensor.h"
#include "cardreader.h" #include "cardreader.h"
#include "cmdqueue.h"
#include "ultralcd.h" #include "ultralcd.h"
#include "sound.h" #include "sound.h"
#include "printers.h" #include "printers.h"

View File

@ -30,6 +30,7 @@
#include "Marlin.h" #include "Marlin.h"
#include "cmdqueue.h"
#include "ultralcd.h" #include "ultralcd.h"
#include "sound.h" #include "sound.h"
#include "temperature.h" #include "temperature.h"
@ -632,7 +633,6 @@ void fanSpeedError(unsigned char _fan) {
fanSpeedErrorBeep(PSTR("Print fan speed is lower than expected"), MSG_FANCHECK_PRINT); fanSpeedErrorBeep(PSTR("Print fan speed is lower than expected"), MSG_FANCHECK_PRINT);
break; break;
} }
// SERIAL_PROTOCOLLNRPGM(MSG_OK); //This ok messes things up with octoprint.
} }
#endif //(defined(TACH_0) && TACH_0 >-1) || (defined(TACH_1) && TACH_1 > -1) #endif //(defined(TACH_0) && TACH_0 >-1) || (defined(TACH_1) && TACH_1 > -1)

View File

@ -1582,6 +1582,7 @@ void lcd_return_to_status()
//! @brief Pause print, disable nozzle heater, move to park position //! @brief Pause print, disable nozzle heater, move to park position
void lcd_pause_print() void lcd_pause_print()
{ {
SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //pause for octoprint
stop_and_save_print_to_ram(0.0, -default_retraction); stop_and_save_print_to_ram(0.0, -default_retraction);
lcd_return_to_status(); lcd_return_to_status();
isPrintPaused = true; isPrintPaused = true;
@ -1589,7 +1590,6 @@ void lcd_pause_print()
{ {
lcd_commands_type = LcdCommands::LongPause; lcd_commands_type = LcdCommands::LongPause;
} }
SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //pause for octoprint
} }
@ -6740,6 +6740,7 @@ void lcd_resume_print()
lcd_return_to_status(); lcd_return_to_status();
lcd_reset_alert_level(); //for fan speed error lcd_reset_alert_level(); //for fan speed error
if (fan_error_selftest()) return; //abort if error persists if (fan_error_selftest()) return; //abort if error persists
cmdqueue_serial_disabled = false;
lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS)); lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
st_synchronize(); st_synchronize();
@ -7352,6 +7353,7 @@ void lcd_print_stop()
if (!card.sdprinting) { if (!card.sdprinting) {
SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
} }
cmdqueue_serial_disabled = false; //for when canceling a print with a fancheck
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
@ -8791,6 +8793,8 @@ static bool check_file(const char* filename) {
startPos = filesize - END_FILE_SECTION; startPos = filesize - END_FILE_SECTION;
card.setIndex(startPos); card.setIndex(startPos);
} }
cmdqueue_reset();
cmdqueue_serial_disabled = true;
lcd_clear(); lcd_clear();
lcd_puts_at_P(0, 1, _i("Checking file"));////c=20 r=1 lcd_puts_at_P(0, 1, _i("Checking file"));////c=20 r=1
@ -8808,12 +8812,13 @@ static bool check_file(const char* filename) {
lcd_print('\xFF'); //simple progress bar lcd_print('\xFF'); //simple progress bar
_delay(100); //for the user to see the end of the progress bar. _delay(100); //for the user to see the end of the progress bar.
cmdqueue_serial_disabled = false;
card.printingHasFinished(); card.printingHasFinished();
strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH); strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
lcd_finishstatus(); lcd_finishstatus();
return result; return result;
} }
static void menu_action_sdfile(const char* filename) static void menu_action_sdfile(const char* filename)