Fix pause/resume when using M25/M601

Remove the conflicting and mostly useless card.paused flag (the printing
is either paused, or not) and switch to isPrintPaused only which
accounts for both cases (SD/USB) correctly.

Fix M27/getStatus to show the current real status of the SD print.

Synchronize the queue on M601, as required to precisely pause the print
at the correct instruction.

Alias M25 to M601, which when combined with PR #1899 fixes issue #1614.

Guard against incorrect usage in M601, M602 and M603.
This commit is contained in:
Yuri D'Elia 2019-10-20 17:34:54 +02:00
parent 18eaf21baf
commit dbe2ed4150
6 changed files with 48 additions and 56 deletions

View File

@ -396,7 +396,7 @@ extern uint16_t gcode_in_progress;
extern LongTimer safetyTimer; extern LongTimer safetyTimer;
#define PRINT_PERCENT_DONE_INIT 0xff #define PRINT_PERCENT_DONE_INIT 0xff
#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || card.paused || mmu_print_saved) #define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || mmu_print_saved)
//! Beware - mcode_in_progress is set as soon as the command gets really processed, //! Beware - mcode_in_progress is set as soon as the command gets really processed,
//! which is not the same as posting the M600 command into the command queue //! which is not the same as posting the M600 command into the command queue

View File

@ -5377,19 +5377,17 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
card.openFile(strchr_pointer + 4,true); card.openFile(strchr_pointer + 4,true);
break; break;
//! ### M24 - Start SD print //! ### M24 - Start/resume SD print
// ---------------------------------- // ----------------------------------
case 24: case 24:
if (!card.paused) if (isPrintPaused)
lcd_resume_print();
else
{
failstats_reset_print(); failstats_reset_print();
card.startFileprint(); card.startFileprint();
starttime=_millis(); starttime=_millis();
break; }
//! ### M25 - Pause SD print
// ----------------------------------
case 25:
card.pauseSDPrint();
break; break;
//! ### M26 S\<index\> - Set SD index //! ### M26 S\<index\> - Set SD index
@ -7246,18 +7244,26 @@ Sigma_Exit:
break; break;
#endif //FILAMENTCHANGEENABLE #endif //FILAMENTCHANGEENABLE
//! ### M25 - Pause SD print
//! ### M601 - Pause print //! ### M601 - Pause print
//! ### M125 - Pause print (TODO: not implemented)
// ------------------------------- // -------------------------------
case 25:
case 601: case 601:
{ {
if (!isPrintPaused)
{
st_synchronize();
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();
} }
}
break; break;
//! ### M602 - Resume print //! ### M602 - Resume print
// ------------------------------- // -------------------------------
case 602: { case 602: {
if (isPrintPaused)
lcd_resume_print(); lcd_resume_print();
} }
break; break;
@ -7265,7 +7271,7 @@ Sigma_Exit:
//! ### M603 - Stop print //! ### M603 - Stop print
// ------------------------------- // -------------------------------
case 603: { case 603: {
lcd_print_stop(); Stop();
} }
break; break;

View File

@ -25,7 +25,6 @@ CardReader::CardReader()
sdpos = 0; sdpos = 0;
sdprinting = false; sdprinting = false;
cardOK = false; cardOK = false;
paused = false;
saving = false; saving = false;
logging = false; logging = false;
autostart_atmillis=0; autostart_atmillis=0;
@ -242,7 +241,6 @@ void CardReader::startFileprint()
if(cardOK) if(cardOK)
{ {
sdprinting = true; sdprinting = true;
paused = false;
Stopped = false; Stopped = false;
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
//flush_presort(); //flush_presort();
@ -250,16 +248,6 @@ void CardReader::startFileprint()
} }
} }
void CardReader::pauseSDPrint()
{
if(sdprinting)
{
sdprinting = false;
paused = true;
}
}
void CardReader::openLogFile(const char* name) void CardReader::openLogFile(const char* name)
{ {
logging = true; logging = true;
@ -408,8 +396,6 @@ void CardReader::openFile(const char* name,bool read, bool replace_current/*=tru
SERIAL_ECHOLN(name); SERIAL_ECHOLN(name);
} }
sdprinting = false; sdprinting = false;
paused = false;
SdFile myDir; SdFile myDir;
const char *fname=name; const char *fname=name;
@ -492,7 +478,15 @@ uint32_t CardReader::getFileSize()
void CardReader::getStatus() void CardReader::getStatus()
{ {
if(sdprinting){ if(sdprinting)
{
if (isPrintPaused) {
SERIAL_PROTOCOLLNPGM("SD print paused");
}
else if (saved_printing) {
SERIAL_PROTOCOLLNPGM("Print saved");
}
else {
SERIAL_PROTOCOL(longFilename); SERIAL_PROTOCOL(longFilename);
SERIAL_PROTOCOLPGM("\n"); SERIAL_PROTOCOLPGM("\n");
SERIAL_PROTOCOLRPGM(_N("SD printing byte "));////MSG_SD_PRINTING_BYTE SERIAL_PROTOCOLRPGM(_N("SD printing byte "));////MSG_SD_PRINTING_BYTE
@ -505,11 +499,6 @@ void CardReader::getStatus()
SERIAL_PROTOCOL(itostr2(time%60)); SERIAL_PROTOCOL(itostr2(time%60));
SERIAL_PROTOCOLPGM("\n"); SERIAL_PROTOCOLPGM("\n");
} }
else if (paused) {
SERIAL_PROTOCOLLNPGM("SD print paused");
}
else if (saved_printing) {
SERIAL_PROTOCOLLNPGM("Print saved");
} }
else { else {
SERIAL_PROTOCOLLNPGM("Not SD printing"); SERIAL_PROTOCOLLNPGM("Not SD printing");

View File

@ -25,7 +25,6 @@ public:
void closefile(bool store_location=false); void closefile(bool store_location=false);
void release(); void release();
void startFileprint(); void startFileprint();
void pauseSDPrint();
uint32_t getFileSize(); uint32_t getFileSize();
void getStatus(); void getStatus();
void printingHasFinished(); void printingHasFinished();
@ -75,7 +74,6 @@ public:
bool logging; bool logging;
bool sdprinting ; bool sdprinting ;
bool cardOK ; bool cardOK ;
bool paused ;
char filename[13]; char filename[13];
uint16_t modificationTime, modificationDate; uint16_t modificationTime, modificationDate;
uint32_t cluster, position; uint32_t cluster, position;

View File

@ -4108,7 +4108,7 @@ void prusa_statistics(int _message, uint8_t _fil_nr) {
{ {
prusa_statistics_case0(15); prusa_statistics_case0(15);
} }
else if (isPrintPaused || card.paused) else if (isPrintPaused)
{ {
prusa_statistics_case0(14); prusa_statistics_case0(14);
} }

View File

@ -198,7 +198,7 @@ void prusa_statistics(int _message, uint8_t _fil_nr) {
SERIAL_ECHOLN("}"); SERIAL_ECHOLN("}");
status_number = 15; status_number = 15;
} }
else if (isPrintPaused || card.paused) else if (isPrintPaused)
{ {
SERIAL_ECHO("{"); SERIAL_ECHO("{");
prusa_stat_printerstatus(14); prusa_stat_printerstatus(14);
@ -490,7 +490,7 @@ void prusa_statistics(int _message, uint8_t _fil_nr) {
{ {
prusa_statistics_case0(15); prusa_statistics_case0(15);
} }
else if (isPrintPaused || card.paused) else if (isPrintPaused)
{ {
prusa_statistics_case0(14); prusa_statistics_case0(14);
} }
@ -753,7 +753,6 @@ TEST_CASE("Prusa_statistics test", "[prusa_stats]")
SERIALS_RESET(); SERIALS_RESET();
isPrintPaused = 0; isPrintPaused = 0;
card.paused = 0;
IS_SD_PRINTING = 1; IS_SD_PRINTING = 1;
old_code::prusa_statistics(test_codes[i],0); old_code::prusa_statistics(test_codes[i],0);
new_code::prusa_statistics(test_codes[i],0); new_code::prusa_statistics(test_codes[i],0);