diff --git a/TFT/src/User/API/Printing.c b/TFT/src/User/API/Printing.c index 1e5ca80900..309c366f4f 100644 --- a/TFT/src/User/API/Printing.c +++ b/TFT/src/User/API/Printing.c @@ -75,19 +75,13 @@ void resumeAndContinue(void) sendEmergencyCmd("M876 S1\n"); } -void abortAndTerminate(void) +static void sendPrintAbortCmd(void) { clearQueueAndMore(); if (infoMachineSettings.firmwareType != FW_REPRAPFW) { - // clear the command queue and send the M524 gcode immediately if there is an already pending gcode waiting for an ACK message. - // Otherwise, store the gcode on command queue to send it waiting for its related ACK message - // - if (isPendingCmd()) - sendEmergencyCmd("M524\n"); - else - mustStoreCmd("M524\n"); + sendEmergencyCmd("M524\n"); } else // if RepRap { @@ -98,14 +92,23 @@ void abortAndTerminate(void) } } -void loopBreakToCondition(CONDITION_CALLBACK condCallback) +void clearPendingGcodesAndAbortPrint(void) { + if (infoFile.source == FS_REMOTE_HOST) + // - forward a print cancel notification to all hosts (so also the one handling the print) asking to cancel the print + // - the host handling the print should respond to this notification with "M118 P0 A1 action:cancel" that will + // trigger setPrintAbort() in parseACK() once the following loop does its job (stopping all blocking operations) + mustStoreCmd("M118 P0 A1 action:notification remote cancel\n"); + else + // triggers setPrintAbort() in parseACK() once the following loop does its job (stopping all blocking operations) + mustStoreCmd("M118 P0 A1 action:cancel\n"); + // M108 is sent to Marlin because consecutive blocking operations such as heating bed, extruder may defer processing of other gcodes. // If there's any ongoing blocking command, "M108" will take that out from the closed loop and a response will be received // from that command. Than another "M108" will be sent to unlock a next possible blocking command. // This way enough "M108" will be sent to unlock all possible blocking command(s) (ongoing or enqueued) but not too much and - // not too fast one after another to overload/overrun the serial communication - TASK_LOOP_WHILE(condCallback(), if (infoHost.rx_ok[SERIAL_PORT] == true) sendEmergencyCmd("M108\n")) + // not too fast one after another to overload/overrun the serial communication. + TASK_LOOP_WHILE(infoPrinting.printing, if (infoHost.rx_ok[SERIAL_PORT] == true) sendEmergencyCmd("M108\n")) // remove any enqueued command that could come from a supplementary serial port or TFT media // (if printing from remote host or TFT media) during the loop above @@ -567,36 +570,19 @@ void abortPrint(void) { case FS_TFT_SD: case FS_TFT_USB: - loopBreakToCondition(&isPendingCmd); // break a pending gcode waiting for an ACK message, if any - setPrintAbort(); // finalize the print abort + clearPendingGcodesAndAbortPrint(); break; case FS_ONBOARD_MEDIA: case FS_ONBOARD_MEDIA_REMOTE: popupSplash(DIALOG_TYPE_INFO, LABEL_SCREEN_INFO, LABEL_BUSY); loopPopup(); // trigger the immediate draw of the above popup - - // clear the command queue and send the M524 gcode immediately if there is an already pending gcode waiting for an ACK message. - // Otherwise, store the gcode on command queue to send it waiting for its related ACK message. - // Furthermore, forward the print cancel action to all hosts (also TFT) to notify the print cancelation - // - // NOTE: the print cancel action received by the TFT always guarantees the invokation of setPrintAbort() in parseAck.c - // to finalize the print (e.g. stats) in case the ACK messages "Not SD printing" and/or "//action:cancel" - // are not received from Marlin - // - abortAndTerminate(); - mustStoreCmd("M118 P0 A1 action:cancel\n"); - - // loop on break until infoHost.status is set to "HOST_STATUS_IDLE" by setPrintAbort() in parseAck.c - loopBreakToCondition(&isPrintingFromOnboard); + sendPrintAbortCmd(); + clearPendingGcodesAndAbortPrint(); break; case FS_REMOTE_HOST: - loopBreakToCondition(&isPendingCmd); // break a pending gcode waiting for an ACK message, if any - - // forward a print cancel notification to all hosts (so also the one handling the print) asking to cancel the print - mustStoreCmd("M118 P0 A1 action:notification remote cancel\n"); - + clearPendingGcodesAndAbortPrint(); loopDetected = false; // finally, remove lock and exit return; } diff --git a/TFT/src/User/API/Printing.h b/TFT/src/User/API/Printing.h index 4e9804597e..cdf711f8a6 100644 --- a/TFT/src/User/API/Printing.h +++ b/TFT/src/User/API/Printing.h @@ -58,12 +58,6 @@ void breakAndContinue(void); void resumeAndPurge(void); void resumeAndContinue(void); -// -// commented because NOT externally invoked -// -//void abortAndTerminate(void); -//void loopBreakToCondition(CONDITION_CALLBACK condCallback); - void setPrintExpectedTime(uint32_t expectedTime); uint32_t getPrintExpectedTime(void); diff --git a/TFT/src/User/API/interfaceCmd.c b/TFT/src/User/API/interfaceCmd.c index cfe3522a92..d5a23f2f37 100644 --- a/TFT/src/User/API/interfaceCmd.c +++ b/TFT/src/User/API/interfaceCmd.c @@ -35,11 +35,6 @@ uint8_t cmd_index; WRITING_MODE writing_mode = NO_WRITING; FIL file; -bool isPendingCmd(void) -{ - return infoHost.wait; -} - bool isFullCmdQueue(void) { return (cmdQueue.count >= CMD_QUEUE_SIZE); diff --git a/TFT/src/User/API/interfaceCmd.h b/TFT/src/User/API/interfaceCmd.h index 31ce525422..7f9359dd84 100644 --- a/TFT/src/User/API/interfaceCmd.h +++ b/TFT/src/User/API/interfaceCmd.h @@ -18,7 +18,6 @@ extern "C" { typedef char CMD[CMD_MAX_SIZE]; -bool isPendingCmd(void); // also usable as condition callback for loopProcessToCondition() bool isFullCmdQueue(void); // also usable as condition callback for loopProcessToCondition() bool isNotEmptyCmdQueue(void); // also usable as condition callback for loopProcessToCondition() bool isEnqueued(const CMD cmd);