Gracefully dump the queue + fixes to fancheck

This commit is contained in:
Alex Voinea 2020-10-26 09:42:26 +02:00 committed by Voinea Dragos
parent fdbbc7d62a
commit 4abf1f436a
10 changed files with 40 additions and 35 deletions

View File

@ -240,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();
} }
} }
@ -3678,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
@ -11459,7 +11457,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"

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,20 @@ bool cmdqueue_pop_front()
void cmdqueue_reset() void cmdqueue_reset()
{ {
bufindr = 0; while (buflen)
bufindw = 0; {
buflen = 0; uint8_t cmdqueue_current_type = *(cmdbuffer+bufindr);
// printf_P(PSTR("dumping: \"%s\" of type %hu\n"), cmdbuffer+bufindr+CMDHDRSIZE, cmdqueue_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 +400,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)

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;
@ -8780,27 +8782,29 @@ static void lcd_selftest_screen_step(int _row, int _col, int _state, const char
/** Menu action functions **/ /** Menu action functions **/
static bool check_file(const char* filename) { static bool check_file(const char* filename) {
if (farm_mode) return true; if (farm_mode)
return true;
bool result = false; bool result = false;
uint32_t filesize; uint32_t filesize;
card.openFile((char*)filename, true); card.openFile((char*)filename, true);
filesize = card.getFileSize(); filesize = card.getFileSize();
if (filesize > END_FILE_SECTION) { if (filesize > END_FILE_SECTION) {
card.setIndex(filesize - END_FILE_SECTION); card.setIndex(filesize - END_FILE_SECTION);
} }
cmdqueue_reset();
cmdqueue_serial_disabled = true;
while (!card.eof() && !result) { while (!card.eof() && !result) {
card.sdprinting = true; card.sdprinting = true;
get_command(); get_command();
result = check_commands(); result = check_commands();
} }
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)